diff --git a/mupifDB/test_scheduler.py b/mupifDB/test_scheduler.py index ed2f545..1a3d8c2 100644 --- a/mupifDB/test_scheduler.py +++ b/mupifDB/test_scheduler.py @@ -26,7 +26,7 @@ def anyPort(): #mupifExamplesDir=mp.__path__[0]+'/examples/' sys.path.append(mupifDB.__path__[0]+'/..') -import workflows.workflowdemo01 as wfdemo01 +import workflows.mini01 as wfmini01 @pytest.fixture def nameserver(xprocess): @@ -123,15 +123,19 @@ def test_suite_cleanup(): class TestFoo: def test_workflowdemo01(self,scheduler): - wf=wfdemo01.workflowdemo() + wf=wfmini01.MiniWorkflow1() md=lambda k: wf.getMetadata(k) wid=md('ID') - id=mupifDB.workflowmanager.insertWorkflowDefinition(wid=wid,description=md('Description'),source=wfdemo01.__file__,useCase='useCase1',workflowInputs=md('Inputs'),workflowOutputs=md('Outputs'),modulename=wf.__module__.split('.')[-1],classname=wf.__class__.__name__,models_md=md('Models')) + id=mupifDB.workflowmanager.insertWorkflowDefinition(wid=wid,description=md('Description'),source=wfmini01.__file__,useCase='useCase1',workflowInputs=md('Inputs'),workflowOutputs=md('Outputs'),modulename=wf.__module__.split('.')[-1],classname=wf.__class__.__name__,models_md=md('Models')) print(f'Workflow inserted, {id=}') wrec=restApiControl.getWorkflowRecord(wid) assert wrec['wid']==wid # print_json(data=wrec) weid=restApiControl.createExecution(wid,version='1',ip='localhost') + #for inp in [ + # mp.ConstantProperty(value=16., propID=DataID.PID_Concentration,valueType=ValueType.Scalar,unit=mp.U['m']) + #]: + # restApiControl.setExecutionInputObject(weid, print(f'Execution created, {weid=}') restApiControl.scheduleExecution(weid) print(f'Execution scheduled, {weid=}') @@ -139,7 +143,7 @@ def test_workflowdemo01(self,scheduler): data=restApiControl.getExecutionRecord(weid) print(f'Execution status: {data["Status"]}') time.sleep(1) - assert data['Status'] in ('Failed',) + assert data['Status']=='Finished' # time.sleep(10) diff --git a/workflows/mini01.py b/workflows/mini01.py new file mode 100644 index 0000000..c95b933 --- /dev/null +++ b/workflows/mini01.py @@ -0,0 +1,58 @@ +import mupif +import mupif as mp +import logging +log = logging.getLogger() + +class MiniWorkflow1 (mupif.workflow.Workflow): + def __init__(self, metadata={}): + """ + Initializes the workflow. + """ + MD = { + 'Name': 'Minimal Workflow', + 'ID': '1', + 'Description': 'Demo thermal problem using finite elements on rectangular domain', + 'Model_refs_ID': [], + 'Inputs': [ + ], + 'Outputs': [ + {'Name':'Length', 'Type': 'mupif.Property', 'Required':True, 'Type_ID':'mupif.DataID.PID_Length','Units':'m'} + ], + 'Models': [], + } + super().__init__(metadata=MD) + self.updateMetadata(metadata) + + + def initialize(self, workdir='', metadata=None, validateMetaData=True, **kwargs): + super().initialize(workdir=workdir, metadata=metadata, validateMetaData=validateMetaData, **kwargs) + + def set(self, obj, objectID=''): + raise mp.APIError('This workflow has no inputs') + + def get(self, objectTypeID, time=None, objectID=''): + md = { + 'Execution': { + 'ID': self.getMetadata('Execution.ID'), + 'Use_case_ID': self.getMetadata('Execution.Use_case_ID'), + 'Task_ID': self.getMetadata('Execution.Task_ID') + } + } + if objectTypeID == mp.DataID.PID_Length: + return mp.ConstantProperty(value=42, propID=mp.DataID.PID_Length, valueType=mp.ValueType.Scalar, unit=mp.U.m, time=time, metadata=md) + else: + raise mp.APIError('Unknown property ID') + + def solveStep(self, istep, stageID=0, runInBackground=False): + log.info ('MiniWorkflow1.solveStep') + pass + + def getCriticalTimeStep(self): + return 1.*mp.U.s + + def getApplicationSignature(self): + return "thermal 1.0" + + def getAPIVersion(self): + return "1.0" +