summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYang (Gabriel) Yu <Gabriel.yuyang@huawei.com>2018-09-04 10:52:37 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-09-04 10:52:37 +0000
commit2f20d0921293d4ad5778f93c66613fcdcd7e2218 (patch)
tree36e904197e6e2200efa083dec7fd1c10e9b1edfc
parent480c3c51a0a2bcc67ac5ca1d96cb63153bf9fff8 (diff)
parentc61a6f1e178b97dca06a56b4fad3fd00404c16ae (diff)
Merge "conductor module in server part of testing-scheduler."
-rw-r--r--testing-scheduler/server/conductorclient/__init__.py8
-rw-r--r--testing-scheduler/server/conductorclient/mock_tasks.json13
-rw-r--r--testing-scheduler/server/conductorclient/mock_workflow.json24
-rw-r--r--testing-scheduler/server/conductorclient/run_new_workflow.py71
4 files changed, 116 insertions, 0 deletions
diff --git a/testing-scheduler/server/conductorclient/__init__.py b/testing-scheduler/server/conductorclient/__init__.py
new file mode 100644
index 0000000..bb02be1
--- /dev/null
+++ b/testing-scheduler/server/conductorclient/__init__.py
@@ -0,0 +1,8 @@
+##############################################################################
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd. and others
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
diff --git a/testing-scheduler/server/conductorclient/mock_tasks.json b/testing-scheduler/server/conductorclient/mock_tasks.json
new file mode 100644
index 0000000..4fea48b
--- /dev/null
+++ b/testing-scheduler/server/conductorclient/mock_tasks.json
@@ -0,0 +1,13 @@
+{
+ "task_group_1":[
+ {
+ "name": "http_yardstick_test",
+ "retryCount": 3,
+ "timeOutSeconds": 1200,
+ "timeOutPolicy": "TIME_OUT_WF",
+ "retryLogic": "FIXED",
+ "retryDelaySeconds": 600,
+ "responseTimeOutSeconds": 3600
+ }
+ ]
+} \ No newline at end of file
diff --git a/testing-scheduler/server/conductorclient/mock_workflow.json b/testing-scheduler/server/conductorclient/mock_workflow.json
new file mode 100644
index 0000000..8f6251c
--- /dev/null
+++ b/testing-scheduler/server/conductorclient/mock_workflow.json
@@ -0,0 +1,24 @@
+{
+ "name": "workflow_demo_05",
+ "description": "run a workflow of yardstick test service",
+ "version": 1,
+ "tasks": [
+ {
+ "name": "http_yardstick_test",
+ "taskReferenceName": "ping_test",
+ "inputParameters": {
+ "http_request": {
+ "uri": "http://192.168.199.105:8080/greet",
+ "method": "GET"
+ }
+ },
+ "type": "HTTP"
+ }
+ ],
+ "outputParameters": {
+ "header": "${ping_test.output.response.headers}",
+ "response": "${ping_test.output.response.body}",
+ "status": "${ping_test.output.response.statusCode}"
+ },
+ "schemaVersion": 2
+} \ No newline at end of file
diff --git a/testing-scheduler/server/conductorclient/run_new_workflow.py b/testing-scheduler/server/conductorclient/run_new_workflow.py
new file mode 100644
index 0000000..0acb96a
--- /dev/null
+++ b/testing-scheduler/server/conductorclient/run_new_workflow.py
@@ -0,0 +1,71 @@
+##############################################################################
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd. and others
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+from conductor import conductor
+import json
+
+
+class WorkflowMgr(object):
+ def __init__(self, serverAddr):
+ self._serverAddr = serverAddr + '/api'
+ self._metaDataClient = conductor.MetadataClient(self._serverAddr)
+ self._workflowClient = conductor.WorkflowClient(self._serverAddr)
+ self._tasksDefined = False
+ self._workflowDefined = False
+ self._workflowName = ""
+
+ def setTaskDef(self, taskJson):
+ jsonObj = json.loads(taskJson)
+ print "define tasks:\n", taskJson
+ for (k, v) in jsonObj.items():
+ self._metaDataClient.registerTaskDefs(v)
+ self._tasksDefined = True
+
+ def setWorkflowDef(self, workflowJson):
+ jsonObj = json.loads(workflowJson)
+ print "define workflow:\n", workflowJson
+ try:
+ self._metaDataClient.createWorkflowDef(jsonObj)
+ except Exception as e:
+ print e
+ self._workflowName = jsonObj['name']
+ self._workflowDefined = True
+
+ def startWorkflow(self, param={}):
+ workflowId = ''
+ if not self._tasksDefined:
+ print "error: please define the task at first\n"
+ elif not self._workflowDefined:
+ print "error: please define the workflow at first\n"
+ else:
+ workflowId = self._workflowClient.startWorkflow(
+ self._workflowName, param)
+ return workflowId
+
+ def setTaskDefFromFile(self, taskFilePath):
+ with open(taskFilePath, 'r') as f:
+ self.setTaskDef(f.read())
+
+ def setWorkflowFromFile(self, workflowFilePath):
+ with open(workflowFilePath, 'r') as f:
+ self.setWorkflowDef(f.read())
+
+
+# test demo
+def main():
+ serverAddr = "http://192.168.199.131:8080"
+ wfMgr = WorkflowMgr(serverAddr)
+ wfMgr.setTaskDefFromFile('mock_tasks.json')
+ wfMgr.setWorkflowFromFile('mock_workflow.json')
+ inputParam = {'input': 'fake'}
+ wfMgr.startWorkflow(inputParam)
+
+
+if __name__ == "__main__":
+ main()