Skip to content

Commit

Permalink
cleanups, handle workflow not being found (catch "exception", add cus…
Browse files Browse the repository at this point in the history
…tom exception just for 404)
  • Loading branch information
eudoxos committed Oct 13, 2024
1 parent 2472988 commit 49951a4
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 147 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ TASKS=ns mongo rest web browse scheduler
.PHONY: $(TASKS)
run: $(TASKS)


# if any task fails, use kill -TERM $(MAKPID) to teminate everything immediately
MAKEPID:= $(shell echo $$PPID)


ns:
python3 -m Pyro5.nameserver --port 11001
mongo:
mkdir -p mongodb-tmp~ && /usr/bin/mongod --port 11002 --noauth --dbpath=./mongodb-tmp~ --logpath=/dev/null --logappend
mkdir -p mongodb-tmp~ && /usr/bin/mongod --port 11002 --noauth --dbpath=./mongodb-tmp~ --logpath=/dev/null --logappend || kill -TERM $(MAKEPID)
rest:
# MUPIFDB_DRY_RUN=1
sleep 2 && cd mupifDB/api && MUPIFDB_MONGODB_PORT=11002 MUPIFDB_REST_SERVER=http://127.0.0.1:11003 MUPIFDB_LOG_LEVEL=DEBUG MUPIFDB_RESTAPI_HOST=localhost MUPIFDB_RESTAPI_PORT=11003 PYTHONPATH=../.. python3 main.py
sleep 2 && cd mupifDB/api && MUPIFDB_MONGODB_PORT=11002 MUPIFDB_REST_SERVER=http://127.0.0.1:11003 MUPIFDB_LOG_LEVEL=DEBUG MUPIFDB_RESTAPI_HOST=localhost MUPIFDB_RESTAPI_PORT=11003 PYTHONPATH=../.. python3 main.py || kill -TERM $(MAKEPID)
web:
sleep 7 && cd webapi && MUPIFDB_MONGODB_PORT=11002 MUPIFDB_REST_SERVER=http://127.0.0.1:11003 MUPIFDB_WEB_FAKE_AUTH=1 FLASK_APP=index.py PYTHONPATH=.. python3 -m flask run --debug --no-reload --host 127.0.0.1 --port 11004
sleep 7 && cd webapi && MUPIFDB_MONGODB_PORT=11002 MUPIFDB_REST_SERVER=http://127.0.0.1:11003 MUPIFDB_WEB_FAKE_AUTH=1 FLASK_APP=index.py PYTHONPATH=.. python3 -m flask run --debug --no-reload --host 127.0.0.1 --port 11004 || kill -TERM $(MAKEPID)
browse:
sleep 9 # && xdg-open http://127.0.0.1:11004
scheduler:
sleep 7 && MUPIF_LOG_LEVEL=DEBUG MUPIFDB_REST_SERVER=http://127.0.0.1:11003 MUPIF_NS=localhost:11001 PYTHONPATH=.. python3 -c 'from mupifDB import workflowscheduler as ws; ws.LOOP_SLEEP_SEC=5; ws.schedulerStatFile="./sched-stat.json"; ws.main()'
sleep 7 && MUPIF_LOG_LEVEL=DEBUG MUPIFDB_REST_SERVER=http://127.0.0.1:11003 MUPIF_NS=localhost:11001 PYTHONPATH=.. python3 -c 'from mupifDB import workflowscheduler as ws; ws.LOOP_SLEEP_SEC=5; ws.schedulerStatFile="./sched-stat.json"; ws.main()' || kill -TERM $(MAKEPID)
2 changes: 1 addition & 1 deletion mupifDB/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from rich import print_json
from rich.pretty import pprint

from .client_util import api_type
from .client_util import api_type, NotFoundResponse

if api_type=='granta':
from .client_granta import *
Expand Down
27 changes: 4 additions & 23 deletions mupifDB/api/client_mupif.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,26 @@ def insertUsecaseRecord(ucid, description):
# Workflows
# --------------------------------------------------

def getWorkflowRecords():
def getWorkflowRecords() -> List[models.Workflow_Model]:
response = rGet("workflows/")
return [models.Workflow_Model.model_validate(record) for record in response.json()]

def getWorkflowRecordsWithUsecase(usecase):
data = []
def getWorkflowRecordsWithUsecase(usecase) -> List[models.Workflow_Model]:
response = rGet(f"usecases/{usecase}/workflows")
for record in response.json():
data.append(record)
return data
return [models.Workflow_Model.model_validate(record) for record in response.json()]

@pydantic.validate_call
def getWorkflowRecord(wid: str) -> models.Workflow_Model:
response = rGet(f"workflows/{wid}")
#print('AAA')
#print_json(data=response.json())
#print('BBB',response.json())
# if response.json() is None: return None
# print(response)
#if response.json() is None: return None
return models.Workflow_Model.model_validate(response.json())

@pydantic.validate_call
def insertWorkflow(wf: models.Workflow_Model):
#print('QQQQ')
#print_json(data=wf.model_dump())
response = rPost("workflows/", data=wf.model_dump_json())
return response.json()

@pydantic.validate_call
def updateWorkflow(wf: models.Workflow_Model):
def updateWorkflow(wf: models.Workflow_Model) -> models.Workflow_Model:
response = rPatch("workflows/", data=wf.model_dump_json())
return models.Workflow_Model.model_validate(response.json())

Expand All @@ -77,14 +66,6 @@ def getWorkflowRecordGeneral(wid, version: int) -> models.Workflow_Model:
@pydantic.validate_call
def getWorkflowRecordFromHistory(wid: str, version: int) -> models.Workflow_Model:
response = rGet(f"workflows_history/{wid}/{version}")
# if response.json() is None: return None
#print('GGG')
#print_json(data=response.text)
#print('HHH')
#print_json(data=response.json())
#print('III')
#print_json(data=models.Workflow_Model.model_validate(response.json()).model_dump())
#print('KKK')
return models.Workflow_Model.model_validate(response.json())

@pydantic.validate_call
Expand Down
20 changes: 10 additions & 10 deletions mupifDB/api/client_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ def setRESTserver(r: str) -> None:
global RESTserver, RestServerMuPIF
RESTserver=RESTserverMuPIF=r+'/'

class NotFoundResponse(Exception):
"""
Custom exception being raised if the API reports 404 exception (not found).
"""

def _check(resp: Response) -> Response:
(log.info if 200<=resp.status_code<300 else log.error)(f'{resp.request.method} {resp.request.url}, status {resp.status_code} ({resp.reason}): {resp.text}')
msg=f'{resp.request.method} {resp.request.url}, status {resp.status_code} ({resp.reason}): {resp.text}'
(log.info if (200<=resp.status_code<300 and resp.status_code!=404) else log.error)(msg)
if 200 <= resp.status_code <= 299: return resp
if resp.status_code==422: # Unprocessable entity
log.error(100*'*'+'\nUnprocessable entity\n'+100*'*')
txt=json.loads(resp.text)
Expand All @@ -37,15 +44,8 @@ def _check(resp: Response) -> Response:
import ast
print_json(data=ast.literal_eval(txt['message']))
except: print('(not renderable as JSON)')
#try:
# txt=json.loads(resp.text)
# print_json(txt['message'])
# #if isinstance(B:=resp.request.body,bytes): print_json(B.decode('utf-8'))
# #elif isinstance(B,str): print_json(B)
# #else: print_json("null")
#except: pass
if 200 <= resp.status_code <= 299: return resp
raise RuntimeError(f'Error: {resp.request.method} {resp.request.url}, status {resp.status_code} ({resp.reason}): {resp.text}.')
elif resp.status_code==404: raise NotFoundResponse(msg)
else: raise RuntimeError(f'Error: {resp.request.method} {resp.request.url}, status {resp.status_code} ({resp.reason}): {resp.text}.')

_defaultTimeout=4

Expand Down
Loading

0 comments on commit 49951a4

Please sign in to comment.