Skip to content

Commit dba88ec

Browse files
acrellinbnaul
authored andcommitted
Fill config file templates with port values from yaml file (#228)
* Parse template config files before running app; add ports section to config.yaml * Return file names in response after creating new dataset * Add generate_token script and use it to fix test_predict_specific_ts_name * Update Makefile
1 parent e4ba23d commit dba88ec

File tree

6 files changed

+44
-35
lines changed

6 files changed

+44
-35
lines changed

Makefile

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ paths:
4242
@mkdir -p log/sv_child
4343
@mkdir -p ~/.local/cesium/logs
4444

45+
fill_conf_values:
46+
PYTHONPATH=. ./baselayer/tools/fill_conf_values.py
47+
4548
log: paths
4649
./baselayer/tools/watch_logs.py
4750

48-
run: paths dependencies
49-
@echo "Supervisor will now fire up various services."
51+
run: paths dependencies fill_conf_values
52+
@echo "Supervisor will now fire up various micro-services."
5053
@echo
5154
@echo " - Run \`make log\` in another terminal to view logs"
5255
@echo " - Run \`make monitor\` in another terminal to restart services"
@@ -71,7 +74,6 @@ run_testing: paths dependencies
7174
$(ENV_SUMMARY) && \
7275
$(SUPERVISORD)
7376

74-
7577
monitor:
7678
@echo "Entering supervisor control panel."
7779
@echo " - Type \`status\` too see microservice status"
@@ -81,31 +83,13 @@ monitor:
8183
attach:
8284
$(SUPERVISORCTL) fg app
8385

84-
run_production:
85-
export FLAGS="--config config.yaml" && \
86-
$(ENV_SUMMARY) && \
87-
$(SUPERVISORD)
88-
89-
run_testing: paths dependencies
90-
export FLAGS="--config _test_config.yaml" && \
91-
$(ENV_SUMMARY) && \
92-
$(SUPERVISORD)
93-
94-
debug:
95-
@echo "Starting web service in debug mode"
96-
@echo "Press Ctrl-D to stop"
97-
@echo
98-
@export FLAGS="--debug" && $(SUPERVISORD) &
99-
@sleep 1 && $(SUPERVISORCTL) -i status
100-
@$(SUPERVISORCTL) shutdown
101-
10286
clean:
10387
rm $(bundle)
10488

105-
test_headless: paths dependencies
89+
test_headless: paths dependencies fill_conf_values
10690
PYTHONPATH='.' xvfb-run ./tools/test_frontend.py
10791

108-
test: paths dependencies
92+
test: paths dependencies fill_conf_values
10993
PYTHONPATH='.' ./tools/test_frontend.py
11094

11195
stop:

cesium_app/handlers/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def post(self):
7979
DBSession().add(d)
8080
DBSession().commit()
8181

82-
return self.success(d, 'cesium/FETCH_DATASETS')
82+
return self.success(d.display_info(), 'cesium/FETCH_DATASETS')
8383

8484
@auth_or_token
8585
def get(self, dataset_id=None):

cesium_app/model_util.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import textwrap
22

3-
from baselayer.app.config import load_env
3+
from baselayer.app.env import load_env
44
from baselayer.app.model_util import status, create_tables, drop_tables
55
from cesium_app import models
66

@@ -58,6 +58,16 @@ def insert_test_data():
5858
models.DBSession().commit()
5959

6060

61+
def create_token_user(bot_name, project_ids):
62+
u = models.User(username=bot_name)
63+
p = models.Project.query.filter(models.Project.id.in_(project_ids)).all()
64+
u.projects.extend(p)
65+
t = models.Token(user=u)
66+
models.DBSession().add_all([u, t])
67+
models.DBSession().commit()
68+
return t.id
69+
70+
6171
if __name__ == "__main__":
6272
env, cfg = load_env()
6373

cesium_app/tests/frontend/test_predict.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import numpy.testing as npt
1010
import pandas as pd
1111
import json
12+
import subprocess
13+
from cesium_app.model_util import create_token_user
1214

1315

1416
def _add_prediction(proj_id, driver):
@@ -221,27 +223,30 @@ def test_download_prediction_csv_regr(driver, project, dataset, featureset, mode
221223

222224

223225
def test_predict_specific_ts_name(driver, project, dataset, featureset, model):
226+
auth_token = create_token_user(uuid.uuid4(), [project.id])
227+
224228
ts_data = [[1, 2, 3, 4], [32.2, 53.3, 32.3, 32.52], [0.2, 0.3, 0.6, 0.3]]
225229
impute_kwargs = {'strategy': 'constant', 'value': None}
226230
data = {'datasetID': dataset.id,
227231
'ts_names': ['217801'],
228-
'modelID': model.id}
232+
'modelID': model.id,
233+
'token': auth_token}
229234
response = driver.request(
230235
'POST', '{}/predictions'.format(driver.server_url),
231-
data=json.dumps(data)).json()
236+
json=data).json()
237+
print(response)
232238
assert response['status'] == 'success'
233239

234-
driver.request('GET', f'{driver.server_url}') # ensure login
235-
236240
for i in range(10):
237241
pred_info = driver.request('GET', '{}/predictions/{}'.format(
238-
driver.server_url, response['data']['id'])).json()
242+
driver.server_url, response['data']['id']),
243+
json={'token': auth_token}).json()
239244
if pred_info['status'] == 'success' and pred_info['data']['finished']:
240-
assert isinstance(pred_info['data']['results']['217801']
241-
['features']['total_time'],
242-
float)
243-
assert 'Mira' in pred_info['data']['results']['217801']['prediction']
244245
break
245246
time.sleep(1)
246247
else:
247248
raise Exception('test_predict_specific_ts_name timed out')
249+
assert isinstance(pred_info['data']['results']['217801']
250+
['features']['total_time'],
251+
float)
252+
assert 'Mira' in pred_info['data']['results']['217801']['prediction']

config.yaml.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,13 @@ server:
4444
debug_login: True
4545
google_oauth2_key:
4646
google_oauth2_secret:
47+
48+
ports:
49+
websocket: 64000
50+
fake_oauth: 63000
51+
app: 5000
52+
app_http_proxy: 5001
53+
app_internal: 65000
54+
dask: 63500
55+
websocket_path_in: 'ipc:///tmp/message_flow_in'
56+
websocket_path_out: 'ipc:///tmp/message_flow_out'

0 commit comments

Comments
 (0)