1 # Resource resolution GRPC client
8 from proto.BluePrintCommon_pb2_grpc import ActionIdentifiers, CommonHeader
9 from proto.BluePrintProcessing_pb2_grpc import ExecutionServiceInput
10 from resource_resolution.grpc.client import Client as ResourceResolutionClient
13 def generate_messages():
14 commonHeader = CommonHeader()
15 commonHeader.requestId = "1234"
16 commonHeader.subRequestId = "1234-1"
17 commonHeader.originatorId = "CDS"
19 actionIdentifiers = ActionIdentifiers()
20 actionIdentifiers.blueprintName = "sample-cba"
21 actionIdentifiers.blueprintVersion = "1.0.0"
22 actionIdentifiers.actionName = "SampleScript"
24 input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
26 commonHeader2 = CommonHeader()
27 commonHeader2.requestId = "1235"
28 commonHeader2.subRequestId = "1234-2"
29 commonHeader2.originatorId = "CDS"
31 input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
33 yield from [input, input2]
36 if __name__ == "__main__":
37 with ResourceResolutionClient("localhost:50052") as client:
38 for response in client.process(generate_messages()):
46 from proto.BluePrintCommon_pb2_grpc import ActionIdentifiers, CommonHeader
47 from proto.BluePrintProcessing_pb2_grpc import ExecutionServiceInput
48 from resource_resolution.grpc.client import Client as ResourceResolutionClient
51 def generate_messages():
52 commonHeader = CommonHeader()
53 commonHeader.requestId = "1234"
54 commonHeader.subRequestId = "1234-1"
55 commonHeader.originatorId = "CDS"
57 actionIdentifiers = ActionIdentifiers()
58 actionIdentifiers.blueprintName = "sample-cba"
59 actionIdentifiers.blueprintVersion = "1.0.0"
60 actionIdentifiers.actionName = "SampleScript"
62 input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
64 commonHeader2 = CommonHeader()
65 commonHeader2.requestId = "1235"
66 commonHeader2.subRequestId = "1234-2"
67 commonHeader2.originatorId = "CDS"
69 input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
71 yield from [input, input2]
74 if __name__ == "__main__":
75 with open("certs/py-executor/py-executor-chain.pem", "rb") as f:
76 with ResourceResolutionClient("localhost:50052", use_ssl=True, root_certificates=f.read()) as client:
77 for response in client.process(generate_messages()):
82 ### Authorizarion header
85 from proto.BluePrintCommon_pb2 import ActionIdentifiers, CommonHeader
86 from proto.BluePrintProcessing_pb2 import ExecutionServiceInput
87 from resource_resolution.grpc.client import Client as ResourceResolutionClient
90 def generate_messages():
91 commonHeader = CommonHeader()
92 commonHeader.requestId = "1234"
93 commonHeader.subRequestId = "1234-1"
94 commonHeader.originatorId = "CDS"
96 actionIdentifiers = ActionIdentifiers()
97 actionIdentifiers.blueprintName = "sample-cba"
98 actionIdentifiers.blueprintVersion = "1.0.0"
99 actionIdentifiers.actionName = "SampleScript"
101 input = ExecutionServiceInput(commonHeader=commonHeader, actionIdentifiers=actionIdentifiers)
103 commonHeader2 = CommonHeader()
104 commonHeader2.requestId = "1235"
105 commonHeader2.subRequestId = "1234-2"
106 commonHeader2.originatorId = "CDS"
108 input2 = ExecutionServiceInput(commonHeader=commonHeader2, actionIdentifiers=actionIdentifiers)
110 yield from [input, input2]
113 if __name__ == "__main__":
114 with ResourceResolutionClient("127.0.0.1:9111", use_header_auth=True, header_auth_token="Token test") as client:
115 for response in client.process(generate_messages()):
120 # ResourceResoulution helper class
122 ## How to use examples
124 ### GRPC insecure channel
127 from resource_resolution.resource_resolution import ResourceResolution, WorkflowExecution, WorkflowExecutionResult
130 if __name__ == "__main__":
131 with ResourceResolution(use_header_auth=True, header_auth_token="Basic token") as rr:
132 for response in rr.execute_workflows( # type: WorkflowExecutionResult
134 blueprint_name="blueprintName",
135 blueprint_version="1.0",
136 workflow_name="resource-assignment"
139 if response.has_error:
140 print(response.error_message)
142 print(response.payload)
145 ### HTTP retrieve/store template
148 from resource_resolution.resource_resolution import ResourceResolution
150 if __name__ == "__main__":
151 # If you want to use only HTTP you don't have to use context manager
152 r = ResourceResolution(
153 http_server_port=8081,
154 http_auth_user="ccsdkapps",
155 http_auth_pass="ccsdkapps",
159 blueprint_name="blueprintName",
160 blueprint_version="1.0.0",
161 artifact_name="test",
162 resolution_key="test",
164 template = r.retrieve_template(
165 blueprint_name="blueprintName",
166 blueprint_version="1.0.0",
167 artifact_name="test",
168 resolution_key="test",
170 assert template.result == "test"
171 template.result = "another value"
173 another_template = r.retrieve_template(
174 blueprint_name="blueprintName",
175 blueprint_version="1.0.0",
176 artifact_name="test",
177 resolution_key="test",
179 assert another_template.result == "another_value"