From 35ab81bb9ff203e14116de10bc2735ffb2883f67 Mon Sep 17 00:00:00 2001 From: Serge Simard Date: Thu, 24 Oct 2019 01:42:27 -0400 Subject: Improve Remote Python Executor error handling and allow for structured response Issue-ID: CCSDK-1855 Signed-off-by: Serge Simard Change-Id: I924918fb06a5a0f118772dedaa41c536c7eca9e7 Signed-off-by: Serge Simard --- .../remote_scripts/Definitions/node_types.json | 8 ++++++++ .../remote_scripts/Definitions/remote_scripts.json | 8 ++++++++ .../remote_scripts/Scripts/python/SamplePython.py | 12 +++++++++++- .../test-blueprint/remote_scripts/TOSCA-Metadata/TOSCA.meta | 3 ++- .../node_type/component-remote-python-executor.json | 4 ++++ .../proto-definition/proto/CommandExecutor.proto | 2 ++ 6 files changed, 35 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Definitions/node_types.json b/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Definitions/node_types.json index 4945da889..a47c13c47 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Definitions/node_types.json +++ b/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Definitions/node_types.json @@ -14,6 +14,14 @@ "entry_schema": { "type": "string" } + }, + "status": { + "required": true, + "type": "string" + }, + "response-data": { + "required": false, + "type": "json" } }, "capabilities" : { diff --git a/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Definitions/remote_scripts.json b/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Definitions/remote_scripts.json index 192106e95..fe0f59243 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Definitions/remote_scripts.json +++ b/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Definitions/remote_scripts.json @@ -83,6 +83,14 @@ "execute-command-logs" ] } + }, + "execute-command-status": { + "type": "string", + "value": { "get_attribute": ["execute-remote-python", "status"]} + }, + "execute-command-payload": { + "type": "json", + "value": { "get_attribute": ["execute-remote-python", "response-data"]} } } }, diff --git a/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Scripts/python/SamplePython.py b/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Scripts/python/SamplePython.py index 5e20e2291..fae5855cf 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Scripts/python/SamplePython.py +++ b/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/Scripts/python/SamplePython.py @@ -2,4 +2,14 @@ import sys -print(sys.argv[1]) \ No newline at end of file +#Optional : import this utility class if returning payload +from cds_utils.payload_coder import send_response_data_payload + +# Do your work... using try .. except to handle errors and return False if error +print(sys.argv[1]) + +# Optional : return a JSON payload to the be published under the response-data output attribute +send_response_data_payload({"étudiant": ["Mélanie", "Joséphine"]}) + +# Always return a boolean indicating success or not.. +sys.exit(True) \ No newline at end of file diff --git a/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/TOSCA-Metadata/TOSCA.meta b/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/TOSCA-Metadata/TOSCA.meta index 5ca8aa031..2c3a91f28 100644 --- a/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/TOSCA-Metadata/TOSCA.meta +++ b/components/model-catalog/blueprint-model/test-blueprint/remote_scripts/TOSCA-Metadata/TOSCA.meta @@ -2,4 +2,5 @@ TOSCA-Meta-File-Version: 1.0.0 CSAR-Version: 1.0 Created-By: Brinda Santh Entry-Definitions: Definitions/remote_scripts.json -Template-Tags: Brinda Santh, remote_scripts \ No newline at end of file +Template-Tags: Brinda Santh, remote_scripts +Content-Type: application/vnd.oasis.bpmn diff --git a/components/model-catalog/definition-type/starter-type/node_type/component-remote-python-executor.json b/components/model-catalog/definition-type/starter-type/node_type/component-remote-python-executor.json index 1c8011382..acaea4e7b 100644 --- a/components/model-catalog/definition-type/starter-type/node_type/component-remote-python-executor.json +++ b/components/model-catalog/definition-type/starter-type/node_type/component-remote-python-executor.json @@ -2,6 +2,10 @@ "description": "This is Remote Python Execution Component.", "version": "1.0.0", "attributes": { + "status": { + "required": true, + "type": "string" + }, "prepare-environment-logs": { "required": false, "type": "string" diff --git a/components/model-catalog/proto-definition/proto/CommandExecutor.proto b/components/model-catalog/proto-definition/proto/CommandExecutor.proto index fd2d4f305..ac6921965 100644 --- a/components/model-catalog/proto-definition/proto/CommandExecutor.proto +++ b/components/model-catalog/proto-definition/proto/CommandExecutor.proto @@ -40,6 +40,7 @@ message ExecutionOutput { repeated string response = 2; ResponseStatus status = 3; google.protobuf.Timestamp timestamp = 4; + string payload = 5; } enum ResponseStatus { @@ -55,6 +56,7 @@ message Packages { enum PackageType { pip = 0; ansible_galaxy = 1; + utilities = 2; } service CommandExecutorService { -- cgit 1.2.3-korg