aboutsummaryrefslogtreecommitdiffstats
path: root/ms/py-executor/resource_resolution/README.md
blob: 3920338ae2103fd40d5ab510a71471f991f9df57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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"
```