conductor module in server part of testing-scheduler. 03/60003/2
authorZheng Qibin <QibinZheng2014@tongji.edu.cn>
Thu, 19 Jul 2018 18:18:16 +0000 (02:18 +0800)
committerLeoQi <QibinZheng2014@tongji.edu.cn>
Thu, 30 Aug 2018 10:45:55 +0000 (18:45 +0800)
JIRA: BOTTLENECK-232

encapusulate the invoking methods to conductor server in a module.

Change-Id: I718c6eed5e75ac01f267688b5694ec35db175b48
Signed-off-by: Zheng Qibin <QibinZheng2014@tongji.edu.cn>
testing-scheduler/server/conductorclient/__init__.py [new file with mode: 0644]
testing-scheduler/server/conductorclient/mock_tasks.json [new file with mode: 0644]
testing-scheduler/server/conductorclient/mock_workflow.json [new file with mode: 0644]
testing-scheduler/server/conductorclient/run_new_workflow.py [new file with mode: 0644]

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