@colabo-flow/s-go 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEVELOPMENT.md +38 -0
- package/README.md +110 -0
- package/__init__.py +0 -0
- package/__pycache__/__init__.cpython-39.pyc +0 -0
- package/create_client.py +84 -0
- package/create_host.py +91 -0
- package/create_host_terra.py +103 -0
- package/demo/__init__.py +0 -0
- package/demo/create-client.ts +51 -0
- package/demo/create-host.ts +136 -0
- package/demo/send-simple-recommended.py +26 -0
- package/demo/send-simple.py +50 -0
- package/demo/send.py +352 -0
- package/demo/send.ts +40 -0
- package/demo/threading/README.md +14 -0
- package/demo/threading/basic_consumer_connection_threaded.png +0 -0
- package/demo/threading/basic_consumer_connection_threaded.py +135 -0
- package/demo/threading/basic_consumer_threaded.py +100 -0
- package/demo/threading/long-running-publisher.py +68 -0
- package/docs/ColaboFlow-infrastructure-diagram.png +0 -0
- package/docs/workflow.md +35 -0
- package/index.ts +4 -0
- package/jest.config.ts +172 -0
- package/lib/__init__.py +0 -0
- package/lib/__pycache__/__init__.cpython-39.pyc +0 -0
- package/lib/__pycache__/config.cpython-39.pyc +0 -0
- package/lib/__pycache__/executor_operators.cpython-39.pyc +0 -0
- package/lib/__pycache__/executor_vos.cpython-39.pyc +0 -0
- package/lib/__pycache__/go_amqp_client.cpython-39.pyc +0 -0
- package/lib/__pycache__/go_amqp_client_threaded.cpython-39.pyc +0 -0
- package/lib/__pycache__/go_amqp_host.cpython-39.pyc +0 -0
- package/lib/__pycache__/operators.cpython-39.pyc +0 -0
- package/lib/__pycache__/vos.cpython-39.pyc +0 -0
- package/lib/config.py +21 -0
- package/lib/config.ts +22 -0
- package/lib/executor_operators.py +23 -0
- package/lib/executor_vos.py +318 -0
- package/lib/go.amqp.client-old-basic.py +50 -0
- package/lib/go.amqp.client.ts +100 -0
- package/lib/go.amqp.host-old-basic.py +48 -0
- package/lib/go.amqp.host.ts +269 -0
- package/lib/go.amqp.host_status.ts +81 -0
- package/lib/go.amqp.service.ts +272 -0
- package/lib/go_amqp_client.py +263 -0
- package/lib/go_amqp_client_non_threaded.py +152 -0
- package/lib/go_amqp_host.py +348 -0
- package/lib/operators.py +16 -0
- package/lib/operators.ts +17 -0
- package/lib/params.ts +1 -0
- package/lib/vos.py +232 -0
- package/lib/vos.ts +212 -0
- package/package.json +36 -0
- package/requirements.txt +4 -0
- package/tests/units/README.md +12 -0
- package/tests/units/chalk/index.ts +41 -0
- package/tests/units/go.amqp.host.test.ts +116 -0
- package/tests/units/tests-vos/tasks-and-flows.vos.ts +128 -0
- package/tsconfig.json +45 -0
- package/v1 - GRPC/README.md +18 -0
- package/v1 - GRPC/node/README.md +13 -0
- package/v1 - GRPC/node/colaboflow_go_actionhost_client.ts +91 -0
- package/v1 - GRPC/node/colaboflow_go_actionhost_server.ts +84 -0
- package/v1 - GRPC/node/colaboflow_go_client.ts +82 -0
- package/v1 - GRPC/node/colaboflow_go_server.ts +84 -0
- package/v1 - GRPC/node/demos/demo-colaboflow_go_actionhost_client.ts +21 -0
- package/v1 - GRPC/node/index.ts +3 -0
- package/v1 - GRPC/node/package-lock.json +770 -0
- package/v1 - GRPC/node/package.json +30 -0
- package/v1 - GRPC/node/tsconfig.json +32 -0
- package/v1 - GRPC/node/yarn.lock +642 -0
- package/v1 - GRPC/protos/colabo/flow/go/go.proto +135 -0
- package/v1 - GRPC/python/DEVELOPMENT.md +86 -0
- package/v1 - GRPC/python/DISCUSSION.md +8 -0
- package/v1 - GRPC/python/LICENSE.txt +21 -0
- package/v1 - GRPC/python/README.md +45 -0
- package/v1 - GRPC/python/__init__.py +1 -0
- package/v1 - GRPC/python/colabo/__init__.py +3 -0
- package/v1 - GRPC/python/colabo/flow/__init__.py +3 -0
- package/v1 - GRPC/python/colabo/flow/go/__init__.py +12 -0
- package/v1 - GRPC/python/colabo/flow/go/basic/PuzzleImporter.py +77 -0
- package/v1 - GRPC/python/colabo/flow/go/basic/__init__.py +5 -0
- package/v1 - GRPC/python/colabo/flow/go/basic/colaboflow_go_basic.py +66 -0
- package/v1 - GRPC/python/colabo/flow/go/basic/parseFlowJSON.py +32 -0
- package/v1 - GRPC/python/colabo/flow/go/colaboflow_go_actionhost.py +44 -0
- package/v1 - GRPC/python/colabo/flow/go/colaboflow_go_client.py +48 -0
- package/v1 - GRPC/python/colabo/flow/go/colaboflow_go_demo.py +168 -0
- package/v1 - GRPC/python/colabo/flow/go/go_pb2.py +976 -0
- package/v1 - GRPC/python/colabo/flow/go/go_pb2_grpc.py +139 -0
- package/v1 - GRPC/python/colabo.flow.go.egg-info/PKG-INFO +58 -0
- package/v1 - GRPC/python/colabo.flow.go.egg-info/SOURCES.txt +16 -0
- package/v1 - GRPC/python/colabo.flow.go.egg-info/dependency_links.txt +1 -0
- package/v1 - GRPC/python/colabo.flow.go.egg-info/requires.txt +3 -0
- package/v1 - GRPC/python/colabo.flow.go.egg-info/top_level.txt +2 -0
- package/v1 - GRPC/python/demo-0.py +69 -0
- package/v1 - GRPC/python/demo-1.py +146 -0
- package/v1 - GRPC/python/demo-actionhost.py +47 -0
- package/v1 - GRPC/python/demo-basic.md +13 -0
- package/v1 - GRPC/python/demo-basic.py +38 -0
- package/v1 - GRPC/python/demo-executeActionSync.py +32 -0
- package/v1 - GRPC/python/demo-flows/flow-demo.json +36 -0
- package/v1 - GRPC/python/demo-puzzles/puzzles/puzzle-a.py +19 -0
- package/v1 - GRPC/python/demo-puzzles/puzzles/puzzle-b.py +21 -0
- package/v1 - GRPC/python/demo-puzzles/puzzles/puzzle-c.py +20 -0
- package/v1 - GRPC/python/requirements.txt +7 -0
- package/v1 - GRPC/python/setup.py +39 -0
- package/v1 - GRPC/python/use-cases/__init__.py +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
|
|
3
|
+
package colabo.flow;
|
|
4
|
+
|
|
5
|
+
service ActionsHost {
|
|
6
|
+
// FlowsHost asks the ActionsHost to execute the action
|
|
7
|
+
rpc executeAction (ActionExecuteRequest) returns (ActionExecuteReply) {}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
service FlowsHost {
|
|
11
|
+
// client registers particular flow description at the FlowsHost that can be later instantiated and executed
|
|
12
|
+
rpc registerFlowDescription (FlowRegisterRequestV1) returns (FlowRegisterReplyV1) {}
|
|
13
|
+
|
|
14
|
+
// (ActionsHost) client registers particular action description at the FlowsHost that can be later executed at the originating ActionsHost
|
|
15
|
+
rpc registerActionDescription (ActionRegisterRequestV1) returns (ActionRegisterReplyV1) {}
|
|
16
|
+
|
|
17
|
+
// client asks the host to execute (wherever is expected) the flow
|
|
18
|
+
rpc startFlowInstance (FlowInstanceRequest) returns (FlowInstanceReply) {}
|
|
19
|
+
|
|
20
|
+
// client asks the host to execute (wherever is expected) the action
|
|
21
|
+
rpc executeActionSync (ActionExecuteRequest) returns (ActionExecuteReply) {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
message FlowInstanceRequest{
|
|
25
|
+
string flowId = 1; // (required) name of the flow the action belongs to
|
|
26
|
+
repeated DataSet initialDatasets = 2;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
message FlowInstanceReply{
|
|
30
|
+
string id = 1; // unique insance id of the executing flow
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
message ActionExecuteRequest{
|
|
34
|
+
string flowId = 2; // (required) name of the flow the action belongs to
|
|
35
|
+
string name = 1; // (required) name of the action (inside the flow)
|
|
36
|
+
|
|
37
|
+
string flowInstanceId = 3; // (required) id of the flow instance that started
|
|
38
|
+
|
|
39
|
+
string dataIn = 4;
|
|
40
|
+
string params = 5;
|
|
41
|
+
|
|
42
|
+
string implementationId = 54; // id of the implementation used for performing the action (i.e. if it is a person performing it, (s)he has been using a tool implemented and identified with implementationID) ('oven Smederevka')
|
|
43
|
+
string implementerId = 55; // id of the person or component performing the action ('baker', or 'oven')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
message ActionExecuteReply{
|
|
47
|
+
string id = 1; // unique id of the executing action
|
|
48
|
+
string dataOut = 2;
|
|
49
|
+
string params = 3;
|
|
50
|
+
string error = 4;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
message DataSet{
|
|
54
|
+
string name = 1; // dataset name
|
|
55
|
+
string data = 2; // serialized data
|
|
56
|
+
string properties = 3; // serialized properties
|
|
57
|
+
string schemaId = 4; // namespace, id of schema
|
|
58
|
+
string error = 5; // any error occured in the regard of the dataset
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
enum PortDirection {
|
|
62
|
+
IN = 0;
|
|
63
|
+
OUT = 1;
|
|
64
|
+
INOUT = 2;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
message Port{
|
|
68
|
+
string name = 1;
|
|
69
|
+
PortDirection direction = 2;
|
|
70
|
+
repeated DataSet datasets = 3;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
message ActionExecuteRequestV2{
|
|
74
|
+
string flowId = 2; // (required) name of the flow the action belongs to
|
|
75
|
+
string name = 1; // (required) name of the action (inside the flow)
|
|
76
|
+
|
|
77
|
+
string flowInstanceId = 3; // (required) id of the flow instance that started
|
|
78
|
+
|
|
79
|
+
repeated Port ports = 4;
|
|
80
|
+
|
|
81
|
+
string implementationId = 54; // id of the implementation used for performing the action (i.e. if it is a person performing it, (s)he has been using a tool implemented and identified with implementationID) ('oven Smederevka')
|
|
82
|
+
string implementerId = 55; // id of the person or component performing the action ('baker', or 'oven')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
message ActionExecuteReplyV2{
|
|
86
|
+
string id = 1; // unique id of the executing action
|
|
87
|
+
repeated DataSet dataIn = 2;
|
|
88
|
+
string error = 4;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
message DataSetDescription{
|
|
92
|
+
string name = 1; // dataset name
|
|
93
|
+
string schemaId = 2; // namespace, id of schema
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
message PortDescription{
|
|
97
|
+
string name = 1;
|
|
98
|
+
PortDirection direction = 2;
|
|
99
|
+
repeated DataSetDescription data = 3;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
message ActionRegisterRequestV1{
|
|
103
|
+
string name = 1; // (required) name of the action
|
|
104
|
+
string namespace = 2;
|
|
105
|
+
|
|
106
|
+
string providerPath = 3; // usually "host:port" where the ActionsHost service is sitting
|
|
107
|
+
|
|
108
|
+
repeated PortDescription ports = 4;
|
|
109
|
+
|
|
110
|
+
string implementationId = 54; // id of the implementation used for performing the action (i.e. if it is a person performing it, (s)he has been using a tool implemented and identified with implementationID) ('oven Smederevka')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
message ActionRegisterReplyV1{
|
|
114
|
+
string id = 1; // unique registration id of the action
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
message FlowDescription{
|
|
118
|
+
string name = 1;
|
|
119
|
+
string flowDescription = 2;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
message FlowRegisterRequestV1{
|
|
123
|
+
string name = 1; // (required) name of the action
|
|
124
|
+
string namespace = 2;
|
|
125
|
+
|
|
126
|
+
string providerPath = 3; // usually "host:port" where the FlowsHost service is sitting
|
|
127
|
+
|
|
128
|
+
repeated PortDescription ports = 4;
|
|
129
|
+
|
|
130
|
+
string implementationId = 54; // id of the implementation used for performing the action (i.e. if it is a person performing it, (s)he has been using a tool implemented and identified with implementationID) ('oven Smederevka')
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
message FlowRegisterReplyV1{
|
|
134
|
+
string id = 1; // unique registration id of the action
|
|
135
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Initial
|
|
2
|
+
|
|
3
|
+
```sh
|
|
4
|
+
python3 -m pip install --upgrade -r requirements.txt
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
# Build Proto
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
cd python/colabo/flow/go
|
|
11
|
+
|
|
12
|
+
# activate environment
|
|
13
|
+
source /Users/sasha/Documents/data/development/colabo.space/python3_env/bin/activate
|
|
14
|
+
|
|
15
|
+
# [Inline comments for Bash?](https://stackoverflow.com/questions/2524367/inline-comments-for-bash)
|
|
16
|
+
# build
|
|
17
|
+
python -m grpc_tools.protoc `# use grpc_tools.protoc plugin` \
|
|
18
|
+
-I../protos `# include folder with other necessary proto files (I guess)` \
|
|
19
|
+
--python_out=. `# python output folder (*_pb2.py file)` \
|
|
20
|
+
--grpc_python_out=. `# grpc python output folder (*_pb2_grpc.py file)` \
|
|
21
|
+
../protos/colabo/flow/go/go.proto `# path to the *.proto file with the description of gRPC service and messages`
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
# Build Package
|
|
25
|
+
|
|
26
|
+
## In Test Repo
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
# build source distribution
|
|
30
|
+
python3 setup.py sdist
|
|
31
|
+
|
|
32
|
+
# upload package (witch config file)
|
|
33
|
+
twine upload --repository testpypi --config-file ../../../../../../../colabo.space-infrastructure/publishing/python/.pypirc dist/*
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Check: https://test.pypi.org/project/colabo.flow.go/
|
|
37
|
+
|
|
38
|
+
Test install:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
# create a test environment
|
|
42
|
+
python3 -m virtualenv p3test_env
|
|
43
|
+
# get to the test environment
|
|
44
|
+
source p3test_env/bin/activate
|
|
45
|
+
|
|
46
|
+
# the latest
|
|
47
|
+
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple colabo.flow.go
|
|
48
|
+
|
|
49
|
+
# upgrade AFTER installing
|
|
50
|
+
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --upgrade colabo.flow.go
|
|
51
|
+
|
|
52
|
+
# a speciffic one
|
|
53
|
+
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple colabo.flow.go==0.0.4
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## In The Real Repo
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
# build source distribution
|
|
60
|
+
python3 setup.py sdist
|
|
61
|
+
|
|
62
|
+
# upload package (witch config file)
|
|
63
|
+
twine upload --repository pypi --config-file ../../../../../../../colabo.space-infrastructure/publishing/python/.pypirc dist/*
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Check: https://pypi.org/project/colabo.flow.go/
|
|
67
|
+
|
|
68
|
+
Test install:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
# get to the test environment
|
|
72
|
+
source <test_env>/bin/activate
|
|
73
|
+
|
|
74
|
+
# the latest
|
|
75
|
+
pip install
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# check version
|
|
79
|
+
pip show colabo.flow.go
|
|
80
|
+
|
|
81
|
+
# upgrade AFTER installing
|
|
82
|
+
pip install --upgrade colabo.flow.go
|
|
83
|
+
|
|
84
|
+
# a speciffic one
|
|
85
|
+
pip install colabo.flow.go==0.0.4
|
|
86
|
+
```
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Fluent interface
|
|
2
|
+
|
|
3
|
+
+ [Designing an Python API: Fluent interface or arguments](https://stackoverflow.com/questions/3883907/designing-an-python-api-fluent-interface-or-arguments)
|
|
4
|
+
+ [Multi-line Statement in Python](https://www.techbeamers.com/understand-python-statement-indentation/#how-to-use-multiline-statement)
|
|
5
|
+
|
|
6
|
+
# Parameters passing
|
|
7
|
+
|
|
8
|
+
+ [Call a function with argument list in python](https://stackoverflow.com/questions/817087/call-a-function-with-argument-list-in-python)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 ChaOS NGO (http://cha-os.ngo)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Install
|
|
2
|
+
|
|
3
|
+
```sh
|
|
4
|
+
# the latest
|
|
5
|
+
pip install colabo.flow.go
|
|
6
|
+
|
|
7
|
+
# upgrade AFTER installing
|
|
8
|
+
pip install --upgrade colabo.flow.go
|
|
9
|
+
|
|
10
|
+
# a speciffic one
|
|
11
|
+
pip install colabo.flow.go==0.0.4
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
# Use
|
|
15
|
+
|
|
16
|
+
```py
|
|
17
|
+
# import
|
|
18
|
+
from colabo.flow.go import go_pb2
|
|
19
|
+
from colabo.flow.go import ColaboFlowGo
|
|
20
|
+
|
|
21
|
+
# create an ColaboFlowGo object
|
|
22
|
+
colaboFlowGo = ColaboFlowGo()
|
|
23
|
+
|
|
24
|
+
create an execute request object
|
|
25
|
+
request = go_pb2.ActionExecuteRequest(
|
|
26
|
+
flowId='search-sounds', name='mediator', flowInstanceId='fa23', dataIn='hello from client', params='quick')
|
|
27
|
+
|
|
28
|
+
# send the go object to the go service
|
|
29
|
+
response = colaboFlowGo.executeActionSync(request)
|
|
30
|
+
|
|
31
|
+
# print the respons from the go service
|
|
32
|
+
print("response = %s" % (response))
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
# More Details
|
|
36
|
+
|
|
37
|
+
+ [Github Colabo repository](https://github.com/Cha-OS/colabo)
|
|
38
|
+
+ [This package inside the Colabo repo](https://github.com/Cha-OS/colabo/tree/master/src/services/puzzles/flow/go/python)
|
|
39
|
+
+ [DEVELOPMENT.md](https://github.com/Cha-OS/colabo/blob/master/src/services/puzzles/flow/go/python/DEVELOPMENT.md)
|
|
40
|
+
+ Relevant Colabo Puzzles
|
|
41
|
+
+ [Python](https://github.com/Cha-OS/colabo/tree/master/src/services/puzzles/flow/go/python)
|
|
42
|
+
+ [ColaboFlow Go Services](https://github.com/Cha-OS/colabo/tree/master/src/services/puzzles/flow/go)
|
|
43
|
+
+ [Backend](https://github.com/Cha-OS/colabo/tree/master/src/backend/dev_puzzles/flow/go)
|
|
44
|
+
+ [Frontend](https://github.com/Cha-OS/colabo/tree/master/src/frontend/dev_puzzles/flow/go)
|
|
45
|
+
+ [Isomorphic](https://github.com/Cha-OS/colabo/tree/master/src/isomorphic/dev_puzzles/flow/go)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# __all__ = ['colabo']
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# NOTE: In general we should be carefull with importing additional modules in __init__.py because
|
|
2
|
+
# they are imported any time any module or sub-module is required
|
|
3
|
+
# import `ColaboFlowGo` class from the local (notice: `.`) file `colaboflow_go`
|
|
4
|
+
from .colaboflow_go_client import ColaboFlowGo
|
|
5
|
+
from .colaboflow_go_actionhost import ColaboFlowGoActionHost
|
|
6
|
+
from .colaboflow_go_demo import ColaboFlowGoDemo
|
|
7
|
+
from .basic.colaboflow_go_basic import ColaboFlowGoBasic
|
|
8
|
+
|
|
9
|
+
# provide the `ColaboFlowGo` class directly importable from the `go` namespace
|
|
10
|
+
# __all__ = ['basic', 'ColaboFlowGo', 'ColaboFlowGoActionHost', 'ColaboFlowGoDemo', 'ColaboFlowGoBasic']
|
|
11
|
+
__all__ = ['ColaboFlowGo', 'ColaboFlowGoActionHost',
|
|
12
|
+
'ColaboFlowGoDemo', 'ColaboFlowGoBasic']
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# http://www.python.org/dev/peps/pep-0263/
|
|
4
|
+
from __future__ import division
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
#from BeautifulSoup import BeautifulStoneSoup, PageElement, NavigableString, Tag
|
|
9
|
+
# Installing BeautifulSoup in Debian/Ubuntu:
|
|
10
|
+
# sudo aptitude install python-beautifulsoup
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class PuzzleImporter():
|
|
14
|
+
"""
|
|
15
|
+
@author: Sasha Mile Rudan
|
|
16
|
+
|
|
17
|
+
This class imports puzzle by text reference
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self):
|
|
21
|
+
"""
|
|
22
|
+
Initialization function of the class
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def GetPuzzleRefFromPuzlePath(puzzlePath):
|
|
27
|
+
"""
|
|
28
|
+
Loads puzzle reference (class, method, etc) from a puzzle path
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
puzzleRef = {
|
|
32
|
+
puzzlePath: puzzlePath
|
|
33
|
+
}
|
|
34
|
+
print("getting module path for NsN %s" % (puzzlePath))
|
|
35
|
+
nsNParts = puzzlePath.split(':')
|
|
36
|
+
moduleName = nsNParts[0]
|
|
37
|
+
puzzleRef["moduleName"] = moduleName
|
|
38
|
+
print("moduleName: %s" % (moduleName))
|
|
39
|
+
|
|
40
|
+
print("loading module %s" % (moduleName))
|
|
41
|
+
try:
|
|
42
|
+
module = __import__(moduleName)
|
|
43
|
+
except ImportError as err:
|
|
44
|
+
print("Error importing moduleName %s: %s" % (moduleName, err))
|
|
45
|
+
return None
|
|
46
|
+
puzzleRef["module"] = module
|
|
47
|
+
print("loaded module %s: %s" % (moduleName, module))
|
|
48
|
+
|
|
49
|
+
print("traversing down the module %s" % (moduleName))
|
|
50
|
+
moduleNameParts = moduleName.split('.')
|
|
51
|
+
moduleLeaf = module
|
|
52
|
+
for comp in moduleNameParts[1:]:
|
|
53
|
+
moduleLeaf = getattr(moduleLeaf, comp)
|
|
54
|
+
print("reached the module %s: %s" % (moduleName, moduleLeaf))
|
|
55
|
+
|
|
56
|
+
classOrModuleLeaf = moduleLeaf
|
|
57
|
+
# parsing class part
|
|
58
|
+
if len(nsNParts)>1 and len(nsNParts[1])>0:
|
|
59
|
+
className = nsNParts[1]
|
|
60
|
+
puzzleRef["className"] = className
|
|
61
|
+
classReference = getattr(moduleLeaf, className)
|
|
62
|
+
classOrModuleLeaf = classReference
|
|
63
|
+
puzzleRef["classReference"] = classReference
|
|
64
|
+
print("class for NsN:%s is %s" % (puzzlePath, classReference))
|
|
65
|
+
|
|
66
|
+
# parsing method part
|
|
67
|
+
if len(nsNParts)>2 and len(nsNParts[2])>0:
|
|
68
|
+
methodName = nsNParts[2]
|
|
69
|
+
else:
|
|
70
|
+
methodName = "process"
|
|
71
|
+
|
|
72
|
+
puzzleRef["methodName"] = methodName
|
|
73
|
+
methodReference = getattr(classOrModuleLeaf, methodName)
|
|
74
|
+
puzzleRef["methodReference"] = methodReference
|
|
75
|
+
print("method for NsN:%s is %s" % (puzzlePath, methodReference))
|
|
76
|
+
|
|
77
|
+
return puzzleRef
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# NOTE: In general we should be carefull with importing additional modules in __init__.py because
|
|
2
|
+
# they are imported any time any module or sub-module is required
|
|
3
|
+
|
|
4
|
+
# provide the `ColaboFlowGo` class directly importable from the `go` namespace
|
|
5
|
+
# __all__ = ['basic']
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#!/usr/bin/python
|
|
3
|
+
|
|
4
|
+
from __future__ import print_function
|
|
5
|
+
|
|
6
|
+
import random
|
|
7
|
+
import site
|
|
8
|
+
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
# import dateutil.parser
|
|
11
|
+
from argparse import ArgumentParser
|
|
12
|
+
|
|
13
|
+
from .parseFlowJSON import ParseFlowJSON
|
|
14
|
+
from .PuzzleImporter import PuzzleImporter
|
|
15
|
+
|
|
16
|
+
class ColaboFlowGoBasic():
|
|
17
|
+
goRequestDefault = None
|
|
18
|
+
stubDefault = None
|
|
19
|
+
|
|
20
|
+
def __init__(self, flowName="basic-flow"):
|
|
21
|
+
|
|
22
|
+
print("[ColaboFlowGoBasic] new flow created: %s" % (flowName))
|
|
23
|
+
self.flow = []
|
|
24
|
+
self.flowPointer = 0
|
|
25
|
+
self.parseFlowJSON = ParseFlowJSON()
|
|
26
|
+
self.puzzleImporter = PuzzleImporter()
|
|
27
|
+
|
|
28
|
+
parser = ArgumentParser(description='This ColaboFlow.Go Orchestrator')
|
|
29
|
+
parser.add_argument("-tf", "--taskfile", dest="task_filename",
|
|
30
|
+
help="JSON file with the task description", default=None, metavar="<TASK_FILE>")
|
|
31
|
+
parser.add_argument("-f", "--flow", dest="flow_filename",
|
|
32
|
+
help="JSON file with the flow description", default=None, metavar="<FLOW_FILE>")
|
|
33
|
+
parser.add_argument("-t", "--taskname", dest="task_name",
|
|
34
|
+
help="name of the task in flow to be executed", default=None, metavar="<TASK_NAME>")
|
|
35
|
+
parser.add_argument("-p", "--puzzles", dest="puzzles_folder",
|
|
36
|
+
help="Folder containing puzzles", default=None, metavar="<PUZZLES_FOLDER>")
|
|
37
|
+
|
|
38
|
+
self.args = parser.parse_args()
|
|
39
|
+
|
|
40
|
+
def loadFlow(self, flowFilename=None):
|
|
41
|
+
if flowFilename == None:
|
|
42
|
+
flowFilename = self.args.flow_filename
|
|
43
|
+
self.parseFlowJSON.loadFlow(flowFilename)
|
|
44
|
+
self.parseFlowJSON.printFlow()
|
|
45
|
+
|
|
46
|
+
def execute(self):
|
|
47
|
+
if self.args.puzzles_folder:
|
|
48
|
+
print("Adding puzzles folder: %s" % (self.args.puzzles_folder))
|
|
49
|
+
site.addsitedir(self.args.puzzles_folder)
|
|
50
|
+
flow = self.parseFlowJSON.getFlow()
|
|
51
|
+
print("Task to execute: %s" % (self.args.task_name))
|
|
52
|
+
for task in flow:
|
|
53
|
+
if self.args.task_name and self.args.task_name != task["name"]:
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
print("\ntask name: %s" % (task["name"]))
|
|
57
|
+
print("\t puzzle: %s" % (task["puzzle"]))
|
|
58
|
+
puzzleRef = PuzzleImporter.GetPuzzleRefFromPuzlePath(task["puzzle"])
|
|
59
|
+
if "classReference" in puzzleRef:
|
|
60
|
+
puzzleClass = puzzleRef["classReference"]
|
|
61
|
+
puzzleObj = puzzleClass(task["name"])
|
|
62
|
+
puzzleObj.process(task)
|
|
63
|
+
|
|
64
|
+
elif "methodReference" in puzzleRef:
|
|
65
|
+
puzzleMethod = puzzleRef["methodReference"]
|
|
66
|
+
puzzleMethod(task)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#!/usr/bin/python
|
|
3
|
+
|
|
4
|
+
from __future__ import print_function
|
|
5
|
+
|
|
6
|
+
import random
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
from datetime import datetime
|
|
10
|
+
# import dateutil.parser
|
|
11
|
+
|
|
12
|
+
class ParseFlowJSON():
|
|
13
|
+
|
|
14
|
+
def __init__(self, flowName="basic-flow"):
|
|
15
|
+
|
|
16
|
+
print("[ColaboFlowGoBasic] new flow created: %s" % (flowName))
|
|
17
|
+
self.flow = []
|
|
18
|
+
self.flowPointer = 0
|
|
19
|
+
|
|
20
|
+
def loadFlow(self, flowFilename):
|
|
21
|
+
print("flowFilename: %s" % (flowFilename))
|
|
22
|
+
with open(flowFilename, 'r') as fn:
|
|
23
|
+
tasksObj = json.load(fn)
|
|
24
|
+
print("tasksObj: %s" % (tasksObj))
|
|
25
|
+
for task in tasksObj["tasks"]:
|
|
26
|
+
self.flow.append(task)
|
|
27
|
+
|
|
28
|
+
def printFlow(self):
|
|
29
|
+
print("flow: %s" % (self.flow))
|
|
30
|
+
|
|
31
|
+
def getFlow(self):
|
|
32
|
+
return self.flow
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#!/usr/bin/python
|
|
3
|
+
|
|
4
|
+
from __future__ import print_function
|
|
5
|
+
import time
|
|
6
|
+
import random
|
|
7
|
+
from concurrent import futures
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
# import dateutil.parser
|
|
10
|
+
|
|
11
|
+
import grpc
|
|
12
|
+
|
|
13
|
+
from . import go_pb2
|
|
14
|
+
from . import go_pb2_grpc
|
|
15
|
+
|
|
16
|
+
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
|
|
17
|
+
|
|
18
|
+
class ColaboFlowGoActionHost():
|
|
19
|
+
def __init__(self, actionsHostServicerImplementationClass, socketUrl=None, concurrentThreadsNo=10):
|
|
20
|
+
|
|
21
|
+
print("ColaboFlowGoActionHost::__init__")
|
|
22
|
+
|
|
23
|
+
if not socketUrl:
|
|
24
|
+
socketUrl = 'localhost:50801'
|
|
25
|
+
self.socketUrl = socketUrl
|
|
26
|
+
|
|
27
|
+
self.concurrentThreadsNo = concurrentThreadsNo
|
|
28
|
+
|
|
29
|
+
# Start server with 10 concurrent threads
|
|
30
|
+
self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=self.concurrentThreadsNo))
|
|
31
|
+
go_pb2_grpc.add_ActionsHostServicer_to_server(
|
|
32
|
+
actionsHostServicerImplementationClass(), self.server)
|
|
33
|
+
self.server.add_insecure_port(self.socketUrl)
|
|
34
|
+
|
|
35
|
+
def startService(self):
|
|
36
|
+
global _ONE_DAY_IN_SECONDS
|
|
37
|
+
self.server.start()
|
|
38
|
+
print("ColaboFlowGoActionHost::startService: started listening on: %s" % (
|
|
39
|
+
self.socketUrl))
|
|
40
|
+
try:
|
|
41
|
+
while True:
|
|
42
|
+
time.sleep(_ONE_DAY_IN_SECONDS)
|
|
43
|
+
except KeyboardInterrupt:
|
|
44
|
+
self.server.stop(0)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
#!/usr/bin/python
|
|
3
|
+
|
|
4
|
+
from __future__ import print_function
|
|
5
|
+
|
|
6
|
+
import random
|
|
7
|
+
|
|
8
|
+
from datetime import datetime
|
|
9
|
+
# import dateutil.parser
|
|
10
|
+
|
|
11
|
+
import grpc
|
|
12
|
+
|
|
13
|
+
from . import go_pb2
|
|
14
|
+
from . import go_pb2_grpc
|
|
15
|
+
|
|
16
|
+
class ColaboFlowGo():
|
|
17
|
+
goRequestDefault = None
|
|
18
|
+
stubDefault = None
|
|
19
|
+
|
|
20
|
+
def __init__(self, socketUrl=None, reuseClient=True):
|
|
21
|
+
|
|
22
|
+
print("ColaboFlowGo::__init__")
|
|
23
|
+
|
|
24
|
+
if not socketUrl:
|
|
25
|
+
socketUrl = 'localhost:50506'
|
|
26
|
+
self.socketUrl = socketUrl
|
|
27
|
+
|
|
28
|
+
# create new stub client only if requested or
|
|
29
|
+
# there is no defualt stub client one yet
|
|
30
|
+
if not reuseClient or not ColaboFlowGo.stubDefault:
|
|
31
|
+
print("Initializing gRPC at: %s" % (socketUrl))
|
|
32
|
+
self.channel = grpc.insecure_channel(socketUrl)
|
|
33
|
+
# to call service methods, we first need to create a stub.
|
|
34
|
+
print(go_pb2_grpc)
|
|
35
|
+
self.stub = go_pb2_grpc.FlowsHostStub(self.channel)
|
|
36
|
+
ColaboFlowGo.stubDefault = self.stub
|
|
37
|
+
else:
|
|
38
|
+
self.stub = ColaboFlowGo.stubDefault
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def executeActionSync(self, actionExecuteRequest):
|
|
43
|
+
actionExecuteReply = self.stub.executeActionSync(actionExecuteRequest)
|
|
44
|
+
if not actionExecuteReply.id:
|
|
45
|
+
print("Server returned incomplete actionExecuteReply")
|
|
46
|
+
else:
|
|
47
|
+
print("actionExecuteReply is %s" % (actionExecuteReply))
|
|
48
|
+
return actionExecuteReply
|