@uns-kit/cli 0.0.34 → 0.0.36
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/LICENSE +21 -21
- package/README.md +128 -128
- package/dist/index.js +181 -6
- package/package.json +2 -2
- package/templates/api/src/examples/api-example.ts +62 -61
- package/templates/azure-pipelines.yml +21 -21
- package/templates/codegen/codegen.ts +15 -15
- package/templates/codegen/src/uns/uns-tags.ts +1 -1
- package/templates/codegen/src/uns/uns-topics.ts +1 -1
- package/templates/config-files/config-docker.json +27 -0
- package/templates/config-files/config-localhost.json +27 -0
- package/templates/cron/src/examples/cron-example.ts +46 -45
- package/templates/default/README.md +30 -30
- package/templates/default/config.json +27 -27
- package/templates/default/gitignore +51 -48
- package/templates/default/package.json +19 -19
- package/templates/default/src/config/project.config.extension.example +23 -23
- package/templates/default/src/config/project.config.extension.ts +6 -6
- package/templates/default/src/examples/data-example.ts +68 -68
- package/templates/default/src/examples/load-test-data.ts +108 -108
- package/templates/default/src/examples/table-example.ts +66 -66
- package/templates/default/src/examples/uns-gateway-cli.ts +7 -7
- package/templates/default/src/index.ts +15 -15
- package/templates/default/src/uns/uns-tags.ts +2 -2
- package/templates/default/src/uns/uns-topics.ts +2 -2
- package/templates/default/tsconfig.json +16 -16
- package/templates/python/app/README.md +8 -0
- package/templates/python/app/__init__.py +0 -0
- package/templates/python/examples/README.md +134 -84
- package/templates/python/examples/__init__.py +0 -0
- package/templates/python/examples/api_handler.py +28 -101
- package/templates/python/examples/data_publish.py +11 -0
- package/templates/python/examples/data_subscribe.py +8 -124
- package/templates/python/examples/data_transformer.py +17 -147
- package/templates/python/examples/table_transformer.py +16 -163
- package/templates/python/gateway/__init__.py +0 -0
- package/templates/python/gateway/cli.py +75 -0
- package/templates/python/gateway/client.py +155 -0
- package/templates/python/gateway/manager.py +97 -0
- package/templates/python/gen/__init__.py +1 -0
- package/templates/python/gen/uns_gateway_pb2.py +70 -0
- package/templates/python/gen/uns_gateway_pb2_grpc.py +312 -0
- package/templates/python/main.py +1 -0
- package/templates/python/proto/uns-gateway.proto +102 -102
- package/templates/python/pyproject.toml +5 -0
- package/templates/python/scripts/setup.sh +87 -64
- package/templates/temporal/src/examples/temporal-example.ts +35 -34
- package/templates/vscode/.vscode/launch.json +164 -164
- package/templates/vscode/.vscode/settings.json +9 -9
- package/templates/vscode/uns-kit.code-workspace +13 -13
- package/templates/python/examples/api_register_and_serve.py +0 -159
- package/templates/python/examples/data_publish_once.py +0 -140
- package/templates/python/examples/data_publisher_loop.py +0 -142
- package/templates/python/gateway_client.py +0 -242
- package/templates/python/local/README.md +0 -8
- package/templates/python/local/__init__.py +0 -2
- package/templates/python/requirements.txt +0 -3
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Change this file according to your specifications and rename it to index.ts
|
|
3
|
-
*/
|
|
4
|
-
import { UnsProxyProcess, ConfigFile, logger } from "@uns-kit/core";
|
|
5
|
-
import { ITemporalTopic } from "@uns-kit/temporal";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
await
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Change this file according to your specifications and rename it to index.ts
|
|
3
|
+
*/
|
|
4
|
+
import { UnsProxyProcess, ConfigFile, logger } from "@uns-kit/core.js";
|
|
5
|
+
import { ITemporalTopic } from "@uns-kit/temporal.js";
|
|
6
|
+
import "@uns-kit/temporal";
|
|
7
|
+
import { type UnsProxyProcessWithTemporal } from "@uns-kit/temporal.js";
|
|
8
|
+
import { UnsAttributeType } from "@uns-kit/core/graphql/schema.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Load the configuration from a file.
|
|
12
|
+
* On the server, this file is provided by the `uns-datahub-controller`.
|
|
13
|
+
* In the development environment, you are responsible for creating and maintaining this file and its contents.
|
|
14
|
+
*/
|
|
15
|
+
const config = await ConfigFile.loadConfig();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Connect to the temporal and register uns topic for temporal
|
|
19
|
+
*/
|
|
20
|
+
const unsProxyProcess = new UnsProxyProcess(config.infra.host!, {processName:config.uns.processName}) as UnsProxyProcessWithTemporal;
|
|
21
|
+
const temporalTopic: ITemporalTopic = {
|
|
22
|
+
attribute: "temporal-data",
|
|
23
|
+
topic: "example/",
|
|
24
|
+
attributeType: UnsAttributeType.Data,
|
|
25
|
+
attributeNeedsPersistence: true,
|
|
26
|
+
dataGroup: "temporal",
|
|
27
|
+
description: "Temporal data example",
|
|
28
|
+
tags: ["temporal"],
|
|
29
|
+
}
|
|
30
|
+
const temporalProxy = await unsProxyProcess.createTemporalProxy("templateUnsTemporal", "temporal.example.local:7233", "line-namespace");
|
|
31
|
+
await temporalProxy.initializeTemporalProxy(temporalTopic);
|
|
32
|
+
|
|
33
|
+
// Start temporal workflow
|
|
34
|
+
const result = await temporalProxy.startWorkflow("TransformLineData", {'coil_id': "42"}, "ETL_LINE_TASK_QUEUE");
|
|
35
|
+
logger.info(`Workflow result: ${JSON.stringify(result)}`);
|
|
@@ -1,164 +1,164 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "0.2.0",
|
|
3
|
-
"configurations": [
|
|
4
|
-
{
|
|
5
|
-
"type": "node",
|
|
6
|
-
"request": "launch",
|
|
7
|
-
"name": "index",
|
|
8
|
-
"runtimeArgs": [
|
|
9
|
-
"--enable-source-maps",
|
|
10
|
-
"--import",
|
|
11
|
-
"tsx",
|
|
12
|
-
],
|
|
13
|
-
"program": "${workspaceFolder}/src/index.ts",
|
|
14
|
-
"console": "internalConsole",
|
|
15
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
16
|
-
"outputCapture": "std",
|
|
17
|
-
"cwd": "${workspaceFolder}",
|
|
18
|
-
"sourceMaps": true,
|
|
19
|
-
"skipFiles": ["<node_internals>/**"],
|
|
20
|
-
"resolveSourceMapLocations": [
|
|
21
|
-
"${workspaceFolder}/**"
|
|
22
|
-
]
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"type": "node",
|
|
26
|
-
"request": "launch",
|
|
27
|
-
"name": "demo: data-example",
|
|
28
|
-
"runtimeArgs": [
|
|
29
|
-
"--enable-source-maps",
|
|
30
|
-
"--import",
|
|
31
|
-
"tsx",
|
|
32
|
-
],
|
|
33
|
-
"program": "${workspaceFolder}/src/examples/data-example.ts",
|
|
34
|
-
"console": "internalConsole",
|
|
35
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
36
|
-
"outputCapture": "std",
|
|
37
|
-
"cwd": "${workspaceFolder}",
|
|
38
|
-
"sourceMaps": true,
|
|
39
|
-
"skipFiles": ["<node_internals>/**"],
|
|
40
|
-
"resolveSourceMapLocations": [
|
|
41
|
-
"${workspaceFolder}/**"
|
|
42
|
-
]
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"type": "node",
|
|
46
|
-
"request": "launch",
|
|
47
|
-
"name": "demo: table-example",
|
|
48
|
-
"runtimeArgs": [
|
|
49
|
-
"--enable-source-maps",
|
|
50
|
-
"--import",
|
|
51
|
-
"tsx",
|
|
52
|
-
],
|
|
53
|
-
"program": "${workspaceFolder}/src/examples/table-example.ts",
|
|
54
|
-
"console": "internalConsole",
|
|
55
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
56
|
-
"outputCapture": "std",
|
|
57
|
-
"cwd": "${workspaceFolder}",
|
|
58
|
-
"sourceMaps": true,
|
|
59
|
-
"skipFiles": ["<node_internals>/**"],
|
|
60
|
-
"resolveSourceMapLocations": [
|
|
61
|
-
"${workspaceFolder}/**"
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
"type": "node",
|
|
66
|
-
"request": "launch",
|
|
67
|
-
"name": "demo: load-test-data",
|
|
68
|
-
"runtimeArgs": [
|
|
69
|
-
"--enable-source-maps",
|
|
70
|
-
"--import",
|
|
71
|
-
"tsx",
|
|
72
|
-
],
|
|
73
|
-
"program": "${workspaceFolder}/src/examples/load-test-data.ts",
|
|
74
|
-
"console": "integratedTerminal",
|
|
75
|
-
"outputCapture": "std",
|
|
76
|
-
"cwd": "${workspaceFolder}",
|
|
77
|
-
"sourceMaps": true,
|
|
78
|
-
"skipFiles": ["<node_internals>/**"],
|
|
79
|
-
"resolveSourceMapLocations": [
|
|
80
|
-
"${workspaceFolder}/**"
|
|
81
|
-
]
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
"type": "node",
|
|
85
|
-
"request": "launch",
|
|
86
|
-
"name": "demo: api-example-example",
|
|
87
|
-
"runtimeArgs": [
|
|
88
|
-
"--enable-source-maps",
|
|
89
|
-
"--import",
|
|
90
|
-
"tsx",
|
|
91
|
-
],
|
|
92
|
-
"program": "${workspaceFolder}/src/examples/api-example.ts",
|
|
93
|
-
"console": "internalConsole",
|
|
94
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
95
|
-
"outputCapture": "std",
|
|
96
|
-
"cwd": "${workspaceFolder}",
|
|
97
|
-
"sourceMaps": true,
|
|
98
|
-
"skipFiles": ["<node_internals>/**"],
|
|
99
|
-
"resolveSourceMapLocations": [
|
|
100
|
-
"${workspaceFolder}/**"
|
|
101
|
-
]
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
"type": "node",
|
|
105
|
-
"request": "launch",
|
|
106
|
-
"name": "demo: cron-example",
|
|
107
|
-
"runtimeArgs": [
|
|
108
|
-
"--enable-source-maps",
|
|
109
|
-
"--import",
|
|
110
|
-
"tsx",
|
|
111
|
-
],
|
|
112
|
-
"program": "${workspaceFolder}/src/examples/cron-example.ts",
|
|
113
|
-
"console": "internalConsole",
|
|
114
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
115
|
-
"outputCapture": "std",
|
|
116
|
-
"cwd": "${workspaceFolder}",
|
|
117
|
-
"sourceMaps": true,
|
|
118
|
-
"skipFiles": ["<node_internals>/**"],
|
|
119
|
-
"resolveSourceMapLocations": [
|
|
120
|
-
"${workspaceFolder}/**"
|
|
121
|
-
]
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
"type": "node",
|
|
125
|
-
"request": "launch",
|
|
126
|
-
"name": "demo: temporal-example",
|
|
127
|
-
"runtimeArgs": [
|
|
128
|
-
"--enable-source-maps",
|
|
129
|
-
"--import",
|
|
130
|
-
"tsx",
|
|
131
|
-
],
|
|
132
|
-
"program": "${workspaceFolder}/src/examples/temporal-example.ts",
|
|
133
|
-
"console": "internalConsole",
|
|
134
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
135
|
-
"outputCapture": "std",
|
|
136
|
-
"cwd": "${workspaceFolder}",
|
|
137
|
-
"sourceMaps": true,
|
|
138
|
-
"skipFiles": ["<node_internals>/**"],
|
|
139
|
-
"resolveSourceMapLocations": [
|
|
140
|
-
"${workspaceFolder}/**"
|
|
141
|
-
]
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
"type": "node",
|
|
145
|
-
"request": "launch",
|
|
146
|
-
"name": "demo: start uns-gateway-server",
|
|
147
|
-
"runtimeArgs": [
|
|
148
|
-
"--enable-source-maps",
|
|
149
|
-
"--import",
|
|
150
|
-
"tsx",
|
|
151
|
-
],
|
|
152
|
-
"program": "${workspaceFolder}/src/examples/uns-gateway-cli.ts",
|
|
153
|
-
"console": "internalConsole",
|
|
154
|
-
"internalConsoleOptions": "openOnSessionStart",
|
|
155
|
-
"outputCapture": "std",
|
|
156
|
-
"cwd": "${workspaceFolder}",
|
|
157
|
-
"sourceMaps": true,
|
|
158
|
-
"skipFiles": ["<node_internals>/**"],
|
|
159
|
-
"resolveSourceMapLocations": [
|
|
160
|
-
"${workspaceFolder}/**"
|
|
161
|
-
]
|
|
162
|
-
}
|
|
163
|
-
]
|
|
164
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2.0",
|
|
3
|
+
"configurations": [
|
|
4
|
+
{
|
|
5
|
+
"type": "node",
|
|
6
|
+
"request": "launch",
|
|
7
|
+
"name": "index",
|
|
8
|
+
"runtimeArgs": [
|
|
9
|
+
"--enable-source-maps",
|
|
10
|
+
"--import",
|
|
11
|
+
"tsx",
|
|
12
|
+
],
|
|
13
|
+
"program": "${workspaceFolder}/src/index.ts",
|
|
14
|
+
"console": "internalConsole",
|
|
15
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
16
|
+
"outputCapture": "std",
|
|
17
|
+
"cwd": "${workspaceFolder}",
|
|
18
|
+
"sourceMaps": true,
|
|
19
|
+
"skipFiles": ["<node_internals>/**"],
|
|
20
|
+
"resolveSourceMapLocations": [
|
|
21
|
+
"${workspaceFolder}/**"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"type": "node",
|
|
26
|
+
"request": "launch",
|
|
27
|
+
"name": "demo: data-example",
|
|
28
|
+
"runtimeArgs": [
|
|
29
|
+
"--enable-source-maps",
|
|
30
|
+
"--import",
|
|
31
|
+
"tsx",
|
|
32
|
+
],
|
|
33
|
+
"program": "${workspaceFolder}/src/examples/data-example.ts",
|
|
34
|
+
"console": "internalConsole",
|
|
35
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
36
|
+
"outputCapture": "std",
|
|
37
|
+
"cwd": "${workspaceFolder}",
|
|
38
|
+
"sourceMaps": true,
|
|
39
|
+
"skipFiles": ["<node_internals>/**"],
|
|
40
|
+
"resolveSourceMapLocations": [
|
|
41
|
+
"${workspaceFolder}/**"
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"type": "node",
|
|
46
|
+
"request": "launch",
|
|
47
|
+
"name": "demo: table-example",
|
|
48
|
+
"runtimeArgs": [
|
|
49
|
+
"--enable-source-maps",
|
|
50
|
+
"--import",
|
|
51
|
+
"tsx",
|
|
52
|
+
],
|
|
53
|
+
"program": "${workspaceFolder}/src/examples/table-example.ts",
|
|
54
|
+
"console": "internalConsole",
|
|
55
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
56
|
+
"outputCapture": "std",
|
|
57
|
+
"cwd": "${workspaceFolder}",
|
|
58
|
+
"sourceMaps": true,
|
|
59
|
+
"skipFiles": ["<node_internals>/**"],
|
|
60
|
+
"resolveSourceMapLocations": [
|
|
61
|
+
"${workspaceFolder}/**"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "node",
|
|
66
|
+
"request": "launch",
|
|
67
|
+
"name": "demo: load-test-data",
|
|
68
|
+
"runtimeArgs": [
|
|
69
|
+
"--enable-source-maps",
|
|
70
|
+
"--import",
|
|
71
|
+
"tsx",
|
|
72
|
+
],
|
|
73
|
+
"program": "${workspaceFolder}/src/examples/load-test-data.ts",
|
|
74
|
+
"console": "integratedTerminal",
|
|
75
|
+
"outputCapture": "std",
|
|
76
|
+
"cwd": "${workspaceFolder}",
|
|
77
|
+
"sourceMaps": true,
|
|
78
|
+
"skipFiles": ["<node_internals>/**"],
|
|
79
|
+
"resolveSourceMapLocations": [
|
|
80
|
+
"${workspaceFolder}/**"
|
|
81
|
+
]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"type": "node",
|
|
85
|
+
"request": "launch",
|
|
86
|
+
"name": "demo: api-example-example",
|
|
87
|
+
"runtimeArgs": [
|
|
88
|
+
"--enable-source-maps",
|
|
89
|
+
"--import",
|
|
90
|
+
"tsx",
|
|
91
|
+
],
|
|
92
|
+
"program": "${workspaceFolder}/src/examples/api-example.ts",
|
|
93
|
+
"console": "internalConsole",
|
|
94
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
95
|
+
"outputCapture": "std",
|
|
96
|
+
"cwd": "${workspaceFolder}",
|
|
97
|
+
"sourceMaps": true,
|
|
98
|
+
"skipFiles": ["<node_internals>/**"],
|
|
99
|
+
"resolveSourceMapLocations": [
|
|
100
|
+
"${workspaceFolder}/**"
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"type": "node",
|
|
105
|
+
"request": "launch",
|
|
106
|
+
"name": "demo: cron-example",
|
|
107
|
+
"runtimeArgs": [
|
|
108
|
+
"--enable-source-maps",
|
|
109
|
+
"--import",
|
|
110
|
+
"tsx",
|
|
111
|
+
],
|
|
112
|
+
"program": "${workspaceFolder}/src/examples/cron-example.ts",
|
|
113
|
+
"console": "internalConsole",
|
|
114
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
115
|
+
"outputCapture": "std",
|
|
116
|
+
"cwd": "${workspaceFolder}",
|
|
117
|
+
"sourceMaps": true,
|
|
118
|
+
"skipFiles": ["<node_internals>/**"],
|
|
119
|
+
"resolveSourceMapLocations": [
|
|
120
|
+
"${workspaceFolder}/**"
|
|
121
|
+
]
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"type": "node",
|
|
125
|
+
"request": "launch",
|
|
126
|
+
"name": "demo: temporal-example",
|
|
127
|
+
"runtimeArgs": [
|
|
128
|
+
"--enable-source-maps",
|
|
129
|
+
"--import",
|
|
130
|
+
"tsx",
|
|
131
|
+
],
|
|
132
|
+
"program": "${workspaceFolder}/src/examples/temporal-example.ts",
|
|
133
|
+
"console": "internalConsole",
|
|
134
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
135
|
+
"outputCapture": "std",
|
|
136
|
+
"cwd": "${workspaceFolder}",
|
|
137
|
+
"sourceMaps": true,
|
|
138
|
+
"skipFiles": ["<node_internals>/**"],
|
|
139
|
+
"resolveSourceMapLocations": [
|
|
140
|
+
"${workspaceFolder}/**"
|
|
141
|
+
]
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"type": "node",
|
|
145
|
+
"request": "launch",
|
|
146
|
+
"name": "demo: start uns-gateway-server",
|
|
147
|
+
"runtimeArgs": [
|
|
148
|
+
"--enable-source-maps",
|
|
149
|
+
"--import",
|
|
150
|
+
"tsx",
|
|
151
|
+
],
|
|
152
|
+
"program": "${workspaceFolder}/src/examples/uns-gateway-cli.ts",
|
|
153
|
+
"console": "internalConsole",
|
|
154
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
155
|
+
"outputCapture": "std",
|
|
156
|
+
"cwd": "${workspaceFolder}",
|
|
157
|
+
"sourceMaps": true,
|
|
158
|
+
"skipFiles": ["<node_internals>/**"],
|
|
159
|
+
"resolveSourceMapLocations": [
|
|
160
|
+
"${workspaceFolder}/**"
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
{
|
|
2
|
-
"npm.packageManager": "pnpm",
|
|
3
|
-
"json.schemas": [
|
|
4
|
-
{
|
|
5
|
-
"fileMatch": ["config.json"],
|
|
6
|
-
"url": "./config.schema.json"
|
|
7
|
-
}
|
|
8
|
-
]
|
|
9
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"npm.packageManager": "pnpm",
|
|
3
|
+
"json.schemas": [
|
|
4
|
+
{
|
|
5
|
+
"fileMatch": ["config.json"],
|
|
6
|
+
"url": "./config.schema.json"
|
|
7
|
+
}
|
|
8
|
+
]
|
|
9
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"folders": [
|
|
3
|
-
{
|
|
4
|
-
"path": "."
|
|
5
|
-
}
|
|
6
|
-
],
|
|
7
|
-
"settings": {
|
|
8
|
-
"files.exclude": {
|
|
9
|
-
"dist": true,
|
|
10
|
-
"node_modules": true
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"folders": [
|
|
3
|
+
{
|
|
4
|
+
"path": "."
|
|
5
|
+
}
|
|
6
|
+
],
|
|
7
|
+
"settings": {
|
|
8
|
+
"files.exclude": {
|
|
9
|
+
"dist": true,
|
|
10
|
+
"node_modules": true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
import argparse
|
|
5
|
-
import json
|
|
6
|
-
import os
|
|
7
|
-
import queue
|
|
8
|
-
import time
|
|
9
|
-
from typing import Dict
|
|
10
|
-
import socket
|
|
11
|
-
|
|
12
|
-
import grpc
|
|
13
|
-
|
|
14
|
-
import sys, os
|
|
15
|
-
# Ensure generated stubs (python/gen) are importable as top-level modules
|
|
16
|
-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'gen')))
|
|
17
|
-
import uns_gateway_pb2 as pb2
|
|
18
|
-
import uns_gateway_pb2_grpc as gw
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def make_channel(addr: str) -> grpc.Channel:
|
|
22
|
-
return grpc.insecure_channel(addr)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
import atexit, signal, subprocess
|
|
26
|
-
_AUTO_GATEWAY_PROC = None
|
|
27
|
-
def _cleanup_gateway():
|
|
28
|
-
global _AUTO_GATEWAY_PROC
|
|
29
|
-
if _AUTO_GATEWAY_PROC and _AUTO_GATEWAY_PROC.poll() is None:
|
|
30
|
-
try:
|
|
31
|
-
if os.name == 'nt':
|
|
32
|
-
_AUTO_GATEWAY_PROC.terminate()
|
|
33
|
-
else:
|
|
34
|
-
os.killpg(os.getpgid(_AUTO_GATEWAY_PROC.pid), signal.SIGTERM)
|
|
35
|
-
try:
|
|
36
|
-
_AUTO_GATEWAY_PROC.wait(timeout=3)
|
|
37
|
-
except Exception:
|
|
38
|
-
if os.name == 'nt':
|
|
39
|
-
_AUTO_GATEWAY_PROC.kill()
|
|
40
|
-
else:
|
|
41
|
-
os.killpg(os.getpgid(_AUTO_GATEWAY_PROC.pid), signal.SIGKILL)
|
|
42
|
-
except Exception:
|
|
43
|
-
pass
|
|
44
|
-
_AUTO_GATEWAY_PROC = None
|
|
45
|
-
|
|
46
|
-
def _default_addr() -> str:
|
|
47
|
-
if os.name == 'nt':
|
|
48
|
-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
49
|
-
s.bind(('127.0.0.1', 0))
|
|
50
|
-
port = s.getsockname()[1]
|
|
51
|
-
return f"127.0.0.1:{port}"
|
|
52
|
-
else:
|
|
53
|
-
return f"unix:/tmp/uns-gateway-api-register-and-serve-{os.getpid()}.sock"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def ensure_gateway_running(addr: str | None, *, auto: bool, timeout_s: int = 20) -> str:
|
|
57
|
-
if not addr:
|
|
58
|
-
addr = _default_addr()
|
|
59
|
-
ch = make_channel(addr)
|
|
60
|
-
try:
|
|
61
|
-
grpc.channel_ready_future(ch).result(timeout=2)
|
|
62
|
-
ch.close(); return addr
|
|
63
|
-
except Exception:
|
|
64
|
-
ch.close()
|
|
65
|
-
if not auto:
|
|
66
|
-
return addr
|
|
67
|
-
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
|
|
68
|
-
cli_path = os.path.join(repo_root, "dist", "uns-grpc", "uns-gateway-cli")
|
|
69
|
-
popen_kwargs = {}
|
|
70
|
-
creationflags = 0
|
|
71
|
-
if os.name != 'nt':
|
|
72
|
-
popen_kwargs['preexec_fn'] = os.setsid
|
|
73
|
-
else:
|
|
74
|
-
creationflags = getattr(subprocess, 'CREATE_NEW_PROCESS_GROUP', 0)
|
|
75
|
-
suffix = f"py-{os.path.basename(__file__).replace('.py','')}-{os.getpid()}"
|
|
76
|
-
proc = subprocess.Popen(["node", cli_path, "--addr", addr, "--instanceSuffix", suffix, "--instanceMode", "force"], cwd=repo_root, creationflags=creationflags, **popen_kwargs)
|
|
77
|
-
global _AUTO_GATEWAY_PROC
|
|
78
|
-
_AUTO_GATEWAY_PROC = proc
|
|
79
|
-
atexit.register(_cleanup_gateway)
|
|
80
|
-
start = time.time()
|
|
81
|
-
while time.time() - start < timeout_s:
|
|
82
|
-
ch2 = make_channel(addr)
|
|
83
|
-
try:
|
|
84
|
-
grpc.channel_ready_future(ch2).result(timeout=2)
|
|
85
|
-
ch2.close();
|
|
86
|
-
try:
|
|
87
|
-
wait_s = int(os.environ.get("UNS_GATEWAY_HANDOVER_WAIT", "11"))
|
|
88
|
-
except Exception:
|
|
89
|
-
wait_s = 11
|
|
90
|
-
if wait_s > 0:
|
|
91
|
-
time.sleep(wait_s)
|
|
92
|
-
return addr
|
|
93
|
-
except Exception:
|
|
94
|
-
ch2.close(); time.sleep(0.5)
|
|
95
|
-
raise RuntimeError("Gateway did not become ready in time")
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def register(stub: gw.UnsGatewayStub) -> None:
|
|
99
|
-
qp = [
|
|
100
|
-
pb2.ApiQueryParam(name="filter", type="string", required=True, description="Filter za podatke"),
|
|
101
|
-
pb2.ApiQueryParam(name="limit", type="number", required=False, description="Koliko podatkov želiš"),
|
|
102
|
-
]
|
|
103
|
-
for idx, tag in [(1, "Tag1"), (2, "Tag2")]:
|
|
104
|
-
res = stub.RegisterApiGet(pb2.RegisterApiGetRequest(
|
|
105
|
-
topic="example/",
|
|
106
|
-
attribute=f"summary-{idx}",
|
|
107
|
-
api_description=f"Test API endpoint {idx}",
|
|
108
|
-
tags=[tag],
|
|
109
|
-
query_params=qp,
|
|
110
|
-
))
|
|
111
|
-
if not res.ok:
|
|
112
|
-
raise RuntimeError(f"Register failed: {res.error}")
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def serve(stub: gw.UnsGatewayStub, echo: bool) -> None:
|
|
116
|
-
q: "queue.Queue[pb2.ApiEventResponse|None]" = queue.Queue()
|
|
117
|
-
|
|
118
|
-
def req_iter():
|
|
119
|
-
while True:
|
|
120
|
-
item = q.get()
|
|
121
|
-
if item is None:
|
|
122
|
-
break
|
|
123
|
-
yield item
|
|
124
|
-
|
|
125
|
-
stream = stub.ApiEventStream(req_iter())
|
|
126
|
-
try:
|
|
127
|
-
for ev in stream:
|
|
128
|
-
if echo:
|
|
129
|
-
q.put(pb2.ApiEventResponse(id=ev.id, status=200, body="OK"))
|
|
130
|
-
continue
|
|
131
|
-
# Build JSON response
|
|
132
|
-
path = ev.path
|
|
133
|
-
query: Dict[str, str] = dict(ev.query)
|
|
134
|
-
body = {
|
|
135
|
-
"status": "OK",
|
|
136
|
-
"endpoint": path,
|
|
137
|
-
"query": query,
|
|
138
|
-
}
|
|
139
|
-
q.put(pb2.ApiEventResponse(id=ev.id, status=200, headers={"Content-Type": "application/json"}, body=json.dumps(body)))
|
|
140
|
-
except KeyboardInterrupt:
|
|
141
|
-
q.put(None)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def main():
|
|
145
|
-
parser = argparse.ArgumentParser(description="Register and serve API endpoints via gateway")
|
|
146
|
-
parser.add_argument("--addr", default=None)
|
|
147
|
-
parser.add_argument("--auto", action="store_true")
|
|
148
|
-
parser.add_argument("--echo", action="store_true")
|
|
149
|
-
args = parser.parse_args()
|
|
150
|
-
|
|
151
|
-
addr = ensure_gateway_running(args.addr, auto=args.auto)
|
|
152
|
-
with make_channel(addr) as ch:
|
|
153
|
-
stub = gw.UnsGatewayStub(ch)
|
|
154
|
-
register(stub)
|
|
155
|
-
serve(stub, args.echo)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if __name__ == "__main__":
|
|
159
|
-
main()
|