aboutsummaryrefslogtreecommitdiffstats
path: root/ms/py-executor/resource_resolution/README.md
diff options
context:
space:
mode:
authorMichal Jagiello <michal.jagiello@t-mobile.pl>2020-03-27 12:16:22 +0000
committerMichal Jagiello <michal.jagiello@t-mobile.pl>2020-04-28 08:26:32 +0000
commitdaf7bf3b0726c9574f9f1b7aa34af4f199ee32c3 (patch)
tree023d8ce4a7a2e599cdc7a7c9d1a38e57e6d73b79 /ms/py-executor/resource_resolution/README.md
parent4dccd00d6b1399596ed6f1e0c7f08cdb98cbec4f (diff)
PyExecutor ResourceResolution store/retrieve templates
Issue-ID: CCSDK-2156 Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl> Change-Id: I59df2772d004e349532a1b42c4e4abd367c13256
Diffstat (limited to 'ms/py-executor/resource_resolution/README.md')
-rw-r--r--ms/py-executor/resource_resolution/README.md180
1 files changed, 180 insertions, 0 deletions
diff --git a/ms/py-executor/resource_resolution/README.md b/ms/py-executor/resource_resolution/README.md
new file mode 100644
index 000000000..3920338ae
--- /dev/null
+++ b/ms/py-executor/resource_resolution/README.md
@@ -0,0 +1,180 @@
+# Resource resolution GRPC client
+
+## How to use examples
+
+### Insecure channel
+
+```
+from proto.BluePrintCommon_pb2_grpc import ActionIdentifiers, CommonHeader
+from proto.BluePrintProcessing_pb2_grpc import ExecutionServiceInput
+from resource_resolution.grpc.client import Client as ResourceResolutionClient
+
+
+def generate_messages():
+ commonHeader = CommonHeader()
+ commonHeader.requestId = "1234"
+ commonHeader.subRequestId = "1234-1"
+ commonHeader.originatorId = "CDS"
+
+ actionIdentifiers = ActionIdentifiers()
+ actionIdentifiers.blueprintName = "sample-cba"
+ actionIdentifiers.blueprintVersion = "1.0.0"
+ actionIdentifiers.actionName = "SampleScript"
+
+ input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
+
+ commonHeader2 = CommonHeader()
+ commonHeader2.requestId = "1235"
+ commonHeader2.subRequestId = "1234-2"
+ commonHeader2.originatorId = "CDS"
+
+ input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
+
+ yield from [input, input2]
+
+
+if __name__ == "__main__":
+ with ResourceResolutionClient("localhost:50052") as client:
+ for response in client.process(generate_messages()):
+ print(response)
+
+```
+
+### Secure channel
+
+```
+from proto.BluePrintCommon_pb2_grpc import ActionIdentifiers, CommonHeader
+from proto.BluePrintProcessing_pb2_grpc import ExecutionServiceInput
+from resource_resolution.grpc.client import Client as ResourceResolutionClient
+
+
+def generate_messages():
+ commonHeader = CommonHeader()
+ commonHeader.requestId = "1234"
+ commonHeader.subRequestId = "1234-1"
+ commonHeader.originatorId = "CDS"
+
+ actionIdentifiers = ActionIdentifiers()
+ actionIdentifiers.blueprintName = "sample-cba"
+ actionIdentifiers.blueprintVersion = "1.0.0"
+ actionIdentifiers.actionName = "SampleScript"
+
+ input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
+
+ commonHeader2 = CommonHeader()
+ commonHeader2.requestId = "1235"
+ commonHeader2.subRequestId = "1234-2"
+ commonHeader2.originatorId = "CDS"
+
+ input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
+
+ yield from [input, input2]
+
+
+if __name__ == "__main__":
+ with open("certs/py-executor/py-executor-chain.pem", "rb") as f:
+ with ResourceResolutionClient("localhost:50052", use_ssl=True, root_certificates=f.read()) as client:
+ for response in client.process(generate_messages()):
+ print(response)
+
+```
+
+### Authorizarion header
+
+```
+from proto.BluePrintCommon_pb2 import ActionIdentifiers, CommonHeader
+from proto.BluePrintProcessing_pb2 import ExecutionServiceInput
+from resource_resolution.grpc.client import Client as ResourceResolutionClient
+
+
+def generate_messages():
+ commonHeader = CommonHeader()
+ commonHeader.requestId = "1234"
+ commonHeader.subRequestId = "1234-1"
+ commonHeader.originatorId = "CDS"
+
+ actionIdentifiers = ActionIdentifiers()
+ actionIdentifiers.blueprintName = "sample-cba"
+ actionIdentifiers.blueprintVersion = "1.0.0"
+ actionIdentifiers.actionName = "SampleScript"
+
+ input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
+
+ commonHeader2 = CommonHeader()
+ commonHeader2.requestId = "1235"
+ commonHeader2.subRequestId = "1234-2"
+ commonHeader2.originatorId = "CDS"
+
+ input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
+
+ yield from [input, input2]
+
+
+if __name__ == "__main__":
+ with ResourceResolutionClient("127.0.0.1:9111", use_header_auth=True, header_auth_token="Token test") as client:
+ for response in client.process(generate_messages()):
+ print(response)
+
+```
+
+# ResourceResoulution helper class
+
+## How to use examples
+
+### GRPC insecure channel
+
+```
+from resource_resolution.resource_resolution import ResourceResolution, WorkflowExecution, WorkflowExecutionResult
+
+
+if __name__ == "__main__":
+ with ResourceResolution(use_header_auth=True, header_auth_token="Basic token") as rr:
+ for response in rr.execute_workflows( # type: WorkflowExecutionResult
+ WorkflowExecution(
+ blueprint_name="blueprintName",
+ blueprint_version="1.0",
+ workflow_name="resource-assignment"
+ )
+ ):
+ if response.has_error:
+ print(response.error_message)
+ else:
+ print(response.payload)
+```
+
+### HTTP retrieve/store template
+
+```
+from resource_resolution.resource_resolution import ResourceResolution
+
+if __name__ == "__main__":
+ # If you want to use only HTTP you don't have to use context manager
+ r = ResourceResolution(
+ http_server_port=8081,
+ http_auth_user="ccsdkapps",
+ http_auth_pass="ccsdkapps",
+ http_use_tls=False
+ )
+ r.store_template(
+ blueprint_name="blueprintName",
+ blueprint_version="1.0.0",
+ artifact_name="test",
+ resolution_key="test",
+ result="test")
+ template = r.retrieve_template(
+ blueprint_name="blueprintName",
+ blueprint_version="1.0.0",
+ artifact_name="test",
+ resolution_key="test",
+ )
+ assert template.result == "test"
+ template.result = "another value"
+ template.store()
+ another_template = r.retrieve_template(
+ blueprint_name="blueprintName",
+ blueprint_version="1.0.0",
+ artifact_name="test",
+ resolution_key="test",
+ )
+ assert another_template.result == "another_value"
+``` \ No newline at end of file