Skip to content

Commit 54a78c3

Browse files
authored
cleanup + update parts of README (#78)
1 parent 91cfca9 commit 54a78c3

File tree

5 files changed

+48
-28
lines changed

5 files changed

+48
-28
lines changed

README.md

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# GreySwan
22

3-
## Config frontend project
4-
Run `yarn` in `./frontend` to install dependencies.
5-
6-
## Run locally
3+
## Run project locally
74
```
85
// From frontend directory
96
yarn local
@@ -12,6 +9,34 @@ mvn appengine:run
129
// From python directory
1310
python3.7 main.py
1411
```
12+
*See `key.json` section if you don't already have the key locally.
13+
14+
## Project set up
15+
### Frontend
16+
1) Install Node v10.21.0.
17+
```
18+
nvm install v10.21.0
19+
nvm list // Make sure v10.21.0 is included.
20+
nvm use 10.21.0
21+
```
22+
2) Make sure you have `yarn` installed.
23+
3) Run `yarn` in `./frontend` to install dependencies.
24+
### Java Backend
25+
1) Follow [instructions](https://cloud.google.com/sdk/docs/downloads-apt-ge) to install gCloud SDK.
26+
2) Run `gcloud init` in root directory of our repository. Provide `greyswan` as gCloud project ID.
27+
3) Install Maven locally.
28+
```
29+
sudo apt update
30+
sudo apt install maven
31+
mvn -version // Check if maven is installed.
32+
```
33+
4) Make sure you have Java 8 installed locally. If not, follow instructions [here](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html).
34+
### Python Microservice
35+
1) Make sure you have Python 3.7 and pip3 installed.
36+
2) To install dependencies:
37+
```
38+
pip3 install -r requirements.txt
39+
```
1540

1641
## Testing
1742
```
@@ -21,18 +46,8 @@ mvn test
2146
yarn test
2247
```
2348

24-
## Setting up and running Python code
25-
To install dependencies: (Only need to run once.)
26-
```
27-
pip3 install -r requirements.txt
28-
```
29-
To run server locally (make sure you're in `python` directory and `key.json` is present):
30-
```
31-
python3.7 main.py
32-
```
33-
34-
## Deploy to gcloud
35-
Only need to do for first time. If you're using cloud shell, should not need following commands.
49+
## Deploy to gCloud
50+
Only need to do for first time in project root directory. If you're using cloud shell, should not need following commands.
3651
```
3752
gcloud init
3853
gcloud config set project greyswan

backend/src/main/java/com/google/blackswan/mock/Constant.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
/** Constants used throughout the blackswan mock classes. */
2424
public final class Constant {
25+
// Only set to false, when you're pushing to Github or do
26+
// not have access to key.json.
27+
public static final boolean USE_CLOUD_STORAGE = false;
28+
2529
// Constants used to filenames.
2630
private static final String FILE_DELIMITER = "-";
2731
private static final String FILE_END = "--data.csv";

backend/src/main/java/com/google/blackswan/mock/SimpleAnomalyGenerator.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public class SimpleAnomalyGenerator implements AnomalyGenerator {
4141
private static final int THRESHOLD = 13;
4242
private static final int NUM_POINTS = 5;
4343
/** Ideally the FileSystem should be injected. */
44-
private static final FileSystem FILE_SYSTEM = LocalFileSystem.createSystem();
44+
private static final FileSystem FILE_SYSTEM = Constant.USE_CLOUD_STORAGE ?
45+
CloudFileSystem.createSystem() : LocalFileSystem.createSystem();
4546

4647
private final ImmutableList<Anomaly> anomalies;
4748
private final DataInfo topic;
@@ -50,8 +51,6 @@ public class SimpleAnomalyGenerator implements AnomalyGenerator {
5051
public static SimpleAnomalyGenerator createGenerator(DataInfo topic) {
5152
return new SimpleAnomalyGenerator(
5253
topic,
53-
// For [push] to git, always use LocalFileSystem, as CloudFileSystem will fail
54-
// unit test without access to key.json.
5554
FILE_SYSTEM.getDataAsStream(topic),
5655
THRESHOLD,
5756
NUM_POINTS
@@ -101,10 +100,6 @@ private ImmutableList<Anomaly> generateAnomalies(int threshold, int numDataPoint
101100
.collect(ImmutableList.toImmutableList());
102101
}
103102

104-
/**
105-
* TODO: Depending on size of future data, alter algorithm of finding
106-
* associated data points.
107-
*/
108103
private Anomaly createAnomalyFromDataPoint(Timestamp time, int numDataPoints) {
109104

110105
// Convert keys into ArrayList.
@@ -133,7 +128,8 @@ private Anomaly createAnomalyFromDataPoint(Timestamp time, int numDataPoints) {
133128
listKeys.get(firstDataPointIndex),
134129
listKeys.get(lastDataPointIndex));
135130

136-
return new Anomaly(time, topic.getMetricName(), topic.getDimensionName(), dataPoints, relatedDataList);
131+
return new Anomaly(time, topic.getMetricName(), topic.getDimensionName(),
132+
dataPoints, relatedDataList);
137133
}
138134

139135
}

backend/src/main/java/com/google/blackswan/mock/SimpleRelatedDataGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
public class SimpleRelatedDataGenerator implements RelatedDataGenerator {
3737
private static final String CONFIG_USERNAME = "catyu@";
3838
/** Ideally should be injected. Currently, putting as class variable. */
39-
private static final FileSystem FILE_SYSTEM = LocalFileSystem.createSystem();
40-
private static final SimpleRelatedDataGenerator INSTANCE = new SimpleRelatedDataGenerator();
39+
private static final FileSystem FILE_SYSTEM = Constant.USE_CLOUD_STORAGE ?
40+
CloudFileSystem.createSystem() : LocalFileSystem.createSystem();
41+
private static final SimpleRelatedDataGenerator INSTANCE
42+
= new SimpleRelatedDataGenerator();
4143

4244
private Multimap<DataInfo, DataInfoUser> relatedDataMap;
4345
private Map<DataInfo, Map<Timestamp, Integer>> csvDataCache;

dispatch.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Rules for dispatch file...
22
dispatch:
3-
# Route the urls that point to the Java backend's API calls
3+
# Route the urls that point to the Java backend's API calls.
44
- url: "*/api/v1/*"
55
service: backend
66
- url: "*/blackswan/*"
77
service: backend
8-
# Route all other urls to the React.js frontend
8+
# Route the urls that point to Python backend's API calls.
9+
- url: "*/python/*"
10+
service: python
11+
# Route all other urls to the React.js frontend.
912
- url: "*/*"
1013
service: default

0 commit comments

Comments
 (0)