@things-factory/edge-client 7.0.0-alpha.18
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/CHANGELOG.md +8 -0
- package/dist-server/controllers/connect-connections.js +9 -0
- package/dist-server/controllers/connect-connections.js.map +1 -0
- package/dist-server/controllers/disconnect-connections.js +9 -0
- package/dist-server/controllers/disconnect-connections.js.map +1 -0
- package/dist-server/controllers/index.js +6 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/controllers/run-task.js +32 -0
- package/dist-server/controllers/run-task.js.map +1 -0
- package/dist-server/controllers/sync-connections.js +9 -0
- package/dist-server/controllers/sync-connections.js.map +1 -0
- package/dist-server/engine/connector/edge-connector.js +38 -0
- package/dist-server/engine/connector/edge-connector.js.map +1 -0
- package/dist-server/engine/index.js +4 -0
- package/dist-server/engine/index.js.map +1 -0
- package/dist-server/index.js +19 -0
- package/dist-server/index.js.map +1 -0
- package/dist-server/service/appliance/edge-client-mutation.js +28 -0
- package/dist-server/service/appliance/edge-client-mutation.js.map +1 -0
- package/dist-server/service/appliance/edge-client-subscription.js +210 -0
- package/dist-server/service/appliance/edge-client-subscription.js.map +1 -0
- package/dist-server/service/appliance/edge-client-type.js +71 -0
- package/dist-server/service/appliance/edge-client-type.js.map +1 -0
- package/dist-server/service/appliance/index.js +9 -0
- package/dist-server/service/appliance/index.js.map +1 -0
- package/dist-server/service/index.js +21 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -0
- package/helps/edge-client/edge-client.md +160 -0
- package/helps/integration/connector/edge-connector.ja.md +9 -0
- package/helps/integration/connector/edge-connector.ko.md +9 -0
- package/helps/integration/connector/edge-connector.md +9 -0
- package/helps/integration/connector/edge-connector.ms.md +9 -0
- package/helps/integration/connector/edge-connector.zh.md +9 -0
- package/package.json +31 -0
- package/server/controllers/connect-connections.ts +6 -0
- package/server/controllers/disconnect-connections.ts +6 -0
- package/server/controllers/index.ts +2 -0
- package/server/controllers/run-task.ts +33 -0
- package/server/controllers/sync-connections.ts +6 -0
- package/server/engine/connector/edge-connector.ts +45 -0
- package/server/engine/index.ts +1 -0
- package/server/index.ts +17 -0
- package/server/service/appliance/edge-client-mutation.ts +18 -0
- package/server/service/appliance/edge-client-subscription.ts +239 -0
- package/server/service/appliance/edge-client-type.ts +46 -0
- package/server/service/appliance/index.ts +6 -0
- package/server/service/index.ts +21 -0
- package/server/tsconfig.json +10 -0
- package/things-factory.config.js +1 -0
- package/translations/en.json +1 -0
- package/translations/ja.json +1 -0
- package/translations/ko.json +1 -0
- package/translations/ms.json +1 -0
- package/translations/zh.json +1 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# EdgeClient
|
|
2
|
+
|
|
3
|
+
Paragraphs are separated by a blank line.
|
|
4
|
+
|
|
5
|
+
2nd paragraph. _Italic_, **bold**, and `monospace`. Itemized lists
|
|
6
|
+
look like:
|
|
7
|
+
|
|
8
|
+
- this one
|
|
9
|
+
- that one
|
|
10
|
+
- the other one
|
|
11
|
+
|
|
12
|
+
Note that --- not considering the asterisk --- the actual text
|
|
13
|
+
content starts at 4-columns in.
|
|
14
|
+
|
|
15
|
+
> Block quotes are
|
|
16
|
+
> written like so.
|
|
17
|
+
>
|
|
18
|
+
> They can span multiple paragraphs,
|
|
19
|
+
> if you like.
|
|
20
|
+
|
|
21
|
+
Use 3 dashes for an em-dash. Use 2 dashes for ranges (ex., "it's all
|
|
22
|
+
in chapters 12--14"). Three dots ... will be converted to an ellipsis.
|
|
23
|
+
Unicode is supported. ☺
|
|
24
|
+
|
|
25
|
+
## An h2 header
|
|
26
|
+
|
|
27
|
+
Here's a numbered list:
|
|
28
|
+
|
|
29
|
+
1. first item
|
|
30
|
+
2. second item
|
|
31
|
+
3. third item
|
|
32
|
+
|
|
33
|
+
Note again how the actual text starts at 4 columns in (4 characters
|
|
34
|
+
from the left side). Here's a code sample:
|
|
35
|
+
|
|
36
|
+
# Let me re-iterate ...
|
|
37
|
+
|
|
38
|
+
for i in 1 .. 10 { do-something(i) }
|
|
39
|
+
|
|
40
|
+
As you probably guessed, indented 4 spaces. By the way, instead of
|
|
41
|
+
indenting the block, you can use delimited blocks, if you like:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
define foobar() {
|
|
45
|
+
print "Welcome to flavor country!";
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
(which makes copying & pasting easier). You can optionally mark the
|
|
50
|
+
delimited block for Pandoc to syntax highlight it:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import time
|
|
54
|
+
# Quick, count to ten!
|
|
55
|
+
for i in range(10):
|
|
56
|
+
# (but not *too* quick)
|
|
57
|
+
time.sleep(0.5)
|
|
58
|
+
print(i)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### An h3 header
|
|
62
|
+
|
|
63
|
+
Now a nested list:
|
|
64
|
+
|
|
65
|
+
1. First, get these ingredients:
|
|
66
|
+
|
|
67
|
+
- carrots
|
|
68
|
+
- celery
|
|
69
|
+
- lentils
|
|
70
|
+
|
|
71
|
+
2. Boil some water.
|
|
72
|
+
|
|
73
|
+
3. Dump everything in the pot and follow
|
|
74
|
+
this algorithm:
|
|
75
|
+
|
|
76
|
+
find wooden spoon
|
|
77
|
+
uncover pot
|
|
78
|
+
stir
|
|
79
|
+
cover pot
|
|
80
|
+
balance wooden spoon precariously on pot handle
|
|
81
|
+
wait 10 minutes
|
|
82
|
+
goto first step (or shut off burner when done)
|
|
83
|
+
|
|
84
|
+
Do not bump wooden spoon or it will fall.
|
|
85
|
+
|
|
86
|
+
Notice again how text always lines up on 4-space indents (including
|
|
87
|
+
that last line which continues item 3 above).
|
|
88
|
+
|
|
89
|
+
Here's a link to [a website](http://foo.bar), to a [local
|
|
90
|
+
doc](local-doc.html), and to a [section heading in the current
|
|
91
|
+
doc](#an-h2-header). Here's a footnote [^1].
|
|
92
|
+
|
|
93
|
+
[^1]: Some footnote text.
|
|
94
|
+
|
|
95
|
+
Tables can look like this:
|
|
96
|
+
|
|
97
|
+
Name Size Material Color
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
All Business 9 leather brown
|
|
102
|
+
Roundabout 10 hemp canvas natural
|
|
103
|
+
Cinderella 11 glass transparent
|
|
104
|
+
|
|
105
|
+
Table: Shoes sizes, materials, and colors.
|
|
106
|
+
|
|
107
|
+
(The above is the caption for the table.) Pandoc also supports
|
|
108
|
+
multi-line tables:
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
Keyword Text
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
red Sunsets, apples, and
|
|
117
|
+
other red or reddish
|
|
118
|
+
things.
|
|
119
|
+
|
|
120
|
+
green Leaves, grass, frogs
|
|
121
|
+
and other things it's
|
|
122
|
+
not easy being.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
A horizontal rule follows.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
Here's a definition list:
|
|
131
|
+
|
|
132
|
+
apples
|
|
133
|
+
: Good for making applesauce.
|
|
134
|
+
|
|
135
|
+
oranges
|
|
136
|
+
: Citrus!
|
|
137
|
+
|
|
138
|
+
tomatoes
|
|
139
|
+
: There's no "e" in tomatoe.
|
|
140
|
+
|
|
141
|
+
Again, text is indented 4 spaces. (Put a blank line between each
|
|
142
|
+
term and its definition to spread things out more.)
|
|
143
|
+
|
|
144
|
+
Here's a "line block" (note how whitespace is honored):
|
|
145
|
+
|
|
146
|
+
| Line one
|
|
147
|
+
| Line too
|
|
148
|
+
| Line tree
|
|
149
|
+
|
|
150
|
+
and images can be specified like so:
|
|
151
|
+
|
|
152
|
+

|
|
153
|
+
|
|
154
|
+
Inline math equation: $\omega = d\phi / dt$. Display
|
|
155
|
+
math should get its own line like so:
|
|
156
|
+
|
|
157
|
+
$$I = \int \rho R^{2} dV$$
|
|
158
|
+
|
|
159
|
+
And note that you can backslash-escape any punctuation characters
|
|
160
|
+
which you wish to be displayed literally, ex.: \`foo\`, \*bar\*, etc.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# エッジコネクタ
|
|
2
|
+
|
|
3
|
+
シナリオは複数のステップで構成され、各ステップは接続、その接続に基づいて実行されるタスク、およびタスクの実行のためのパラメータによって定義されます。
|
|
4
|
+
|
|
5
|
+
これらのステップは、接続が設定されたサーバー(エッジサーバー)で実行されますが、特にエッジサーバーに設定されていない接続は、シナリオが定義されたサーバー自体に設定され、関連するシナリオステップも同じサーバーで実行されます。
|
|
6
|
+
|
|
7
|
+
接続なしでタスクをエッジサーバーで実行したい場合は、ステップの接続としてエッジコネクタを使用できます。
|
|
8
|
+
|
|
9
|
+
エッジコネクタはこの目的のみに使用され、実際には実装された機能がない、タグ付け専用のコネクタです。
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Edge Connector
|
|
2
|
+
|
|
3
|
+
시나리오는 여러개의 스텝으로 구성되며, 각 스텝은 커넥션과 해당 커넥션을 기반으로 실행되는 태스크 그리고 태스크 실행을 위한 파라미터들로 정의된다.
|
|
4
|
+
|
|
5
|
+
그 스텝은 커넥션이 설정된 (에지)서버에서 실행되게 되는데, 특별히 에지서버가 설정되지 않은 커넥션은 시나리오가 정의된 서버 자신에 설정되고 관련된 시나리오 스텝도 동일한 서버에서 실행된다.
|
|
6
|
+
|
|
7
|
+
그런데, 커넥션이 없이 실행되는 태스크들을 에지서버에서 실행하고자 할 때는 Edge Connector라는 커넥터를 이용해서 그 스텝의 커넥션으로 설정할 수 있도록 한다.
|
|
8
|
+
|
|
9
|
+
Edge Connector는 이런 목적으로만 사용되기 때문에, 실질적으로 구현된 기능은 없는 태깅 전용 커넥터이다.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Edge Connector
|
|
2
|
+
|
|
3
|
+
Scenario consists of multiple steps, each defined by a connection, tasks based on that connection, and parameters for executing the tasks.
|
|
4
|
+
|
|
5
|
+
These steps are executed on the server where the connection is set (edge server), but connections not specifically set to an edge server will have the scenario defined on the server itself, and related scenario steps will also be executed on the same server.
|
|
6
|
+
|
|
7
|
+
When you want to execute tasks without a connection on an edge server, you can use the Edge Connector as the step's connection.
|
|
8
|
+
|
|
9
|
+
The Edge Connector is used only for this purpose and is essentially a tagging-only connector without any implemented features.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Penyambung Tepi
|
|
2
|
+
|
|
3
|
+
Skenario terdiri daripada beberapa langkah, setiap langkah didefinisikan oleh sambungan, tugas berdasarkan sambungan tersebut, dan parameter untuk melaksanakan tugas.
|
|
4
|
+
|
|
5
|
+
Langkah-langkah ini dilaksanakan pada pelayan di mana sambungan ditetapkan (pelayan tepi), tetapi sambungan yang tidak khusus ditetapkan kepada pelayan tepi akan memiliki skenario yang didefinisikan pada pelayan itu sendiri, dan langkah skenario yang berkaitan juga akan dilaksanakan pada pelayan yang sama.
|
|
6
|
+
|
|
7
|
+
Apabila anda ingin melaksanakan tugas tanpa sambungan pada pelayan tepi, anda boleh menggunakan Penyambung Tepi sebagai sambungan langkah.
|
|
8
|
+
|
|
9
|
+
Penyambung Tepi hanya digunakan untuk tujuan ini dan pada dasarnya adalah penyambung hanya penandaan tanpa ciri yang dilaksanakan.
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@things-factory/edge-client",
|
|
3
|
+
"version": "7.0.0-alpha.18",
|
|
4
|
+
"main": "dist-server/index.js",
|
|
5
|
+
"things-factory": true,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "heartyoh <heartyoh@hatiolab.com>",
|
|
8
|
+
"description": "edge client module",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public",
|
|
11
|
+
"@things-factory:registry": "https://registry.npmjs.org"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/hatiolab/things-factory.git",
|
|
16
|
+
"directory": "packages/edge-client"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "npm run build:server",
|
|
20
|
+
"build:server": "npx tsc --p ./server/tsconfig.json",
|
|
21
|
+
"clean:server": "npx rimraf dist-server",
|
|
22
|
+
"clean": "npm run clean:server"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@things-factory/auth-base": "^7.0.0-alpha.18",
|
|
26
|
+
"@things-factory/integration-base": "^7.0.0-alpha.18",
|
|
27
|
+
"@things-factory/lock-client": "^7.0.0-alpha.18",
|
|
28
|
+
"@things-factory/shell": "^7.0.0-alpha.18"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "f695ce9c0e3a8f2d715d27a2e7674c9b9c6b1ee1"
|
|
31
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { pubsub } from '@things-factory/shell'
|
|
2
|
+
import { Connection } from '@things-factory/integration-base'
|
|
3
|
+
|
|
4
|
+
export async function connectConnections(connections: Connection[], context: ResolverContext): Promise<any> {
|
|
5
|
+
pubsub.publish('connect-connections', connections)
|
|
6
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { pubsub } from '@things-factory/shell'
|
|
2
|
+
import { Connection } from '@things-factory/integration-base'
|
|
3
|
+
|
|
4
|
+
export async function disconnectConnections(connections: Connection[], context: ResolverContext): Promise<any> {
|
|
5
|
+
pubsub.publish('disconnect-connections', connections)
|
|
6
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { pubsub } from '@things-factory/shell'
|
|
2
|
+
import { Context, Step, TaskHandler } from '@things-factory/integration-base'
|
|
3
|
+
import { requestLock, tryLock } from '@things-factory/lock-client'
|
|
4
|
+
|
|
5
|
+
export const runTask: TaskHandler = async (step: Step, scenarioContext: Context) => {
|
|
6
|
+
const { logger }: { logger: any } = scenarioContext
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
const id = await requestLock()
|
|
10
|
+
|
|
11
|
+
pubsub.publish('run-task', {
|
|
12
|
+
id,
|
|
13
|
+
step,
|
|
14
|
+
context: scenarioContext
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const result = await tryLock({ id })
|
|
18
|
+
const { out, logs, error } = result || {}
|
|
19
|
+
|
|
20
|
+
if (logger.transports?.length > 0) {
|
|
21
|
+
/* 강제로 시나리오 인스턴스가 종료된 경우에는 logger도 닫힌 상태가 된다. 이 경우에는 transports가 설정되지 않게된다. */
|
|
22
|
+
logs && logs.map(log => logger.log(log))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (error) {
|
|
26
|
+
throw new Error(error)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return out
|
|
30
|
+
} catch (err) {
|
|
31
|
+
throw new Error(err)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { pubsub } from '@things-factory/shell'
|
|
2
|
+
import { Connection } from '@things-factory/integration-base'
|
|
3
|
+
|
|
4
|
+
export async function syncConnections(connections: Connection[], context: ResolverContext): Promise<any> {
|
|
5
|
+
pubsub.publish('sync-connections', connections)
|
|
6
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Connector, ConnectionManager, InputConnection } from '@things-factory/integration-base'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This connector only serves the role of a tag specifying that a particular step of the task will be performed on the Edge Server,
|
|
5
|
+
* and therefore, contains no special logic.
|
|
6
|
+
*/
|
|
7
|
+
export class EdgeConnector implements Connector {
|
|
8
|
+
async ready(connectionConfigs: InputConnection[]) {
|
|
9
|
+
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
|
10
|
+
|
|
11
|
+
ConnectionManager.logger.info('edge-connector connections are ready')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async connect(connection: InputConnection) {
|
|
15
|
+
const edge = {}
|
|
16
|
+
|
|
17
|
+
ConnectionManager.addConnectionInstance(connection, edge)
|
|
18
|
+
|
|
19
|
+
ConnectionManager.logger.info(`edge-connector connection(${connection.name}:${connection.endpoint}) is connected`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async disconnect(connection: InputConnection) {
|
|
23
|
+
ConnectionManager.removeConnectionInstance(connection)
|
|
24
|
+
|
|
25
|
+
ConnectionManager.logger.info(`edge-connector connection(${connection.name}) is disconnected`)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get parameterSpec() {
|
|
29
|
+
return []
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get taskPrefixes() {
|
|
33
|
+
return [] // intentionally empty
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get help() {
|
|
37
|
+
return 'integration/connector/edge-connector'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get description() {
|
|
41
|
+
return 'Operato Edge Connector'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
ConnectionManager.registerConnector('edge-connector', new EdgeConnector())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './connector/edge-connector'
|
package/server/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './service'
|
|
2
|
+
|
|
3
|
+
import { setEdgeClient } from '@things-factory/integration-base'
|
|
4
|
+
import { runTask } from './controllers/run-task'
|
|
5
|
+
import { syncConnections } from './controllers/sync-connections'
|
|
6
|
+
import { connectConnections } from './controllers/connect-connections'
|
|
7
|
+
import { disconnectConnections } from './controllers/disconnect-connections'
|
|
8
|
+
import './engine' // for registering edge-connector
|
|
9
|
+
|
|
10
|
+
process.on('bootstrap-module-start' as any, async ({ app, config, client }: any) => {
|
|
11
|
+
setEdgeClient({
|
|
12
|
+
handler: runTask,
|
|
13
|
+
syncConnections,
|
|
14
|
+
connectConnections,
|
|
15
|
+
disconnectConnections
|
|
16
|
+
})
|
|
17
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Appliance } from '@things-factory/auth-base'
|
|
4
|
+
import { releaseLock } from '@things-factory/lock-client'
|
|
5
|
+
|
|
6
|
+
import { RunTaskCallbackInput } from './edge-client-type'
|
|
7
|
+
|
|
8
|
+
@Resolver(Appliance)
|
|
9
|
+
export class EdgeClientMutation {
|
|
10
|
+
@Mutation(returns => Boolean, { description: 'To receive the result of runTask' })
|
|
11
|
+
async runTaskCallback(@Arg('result', type => RunTaskCallbackInput) result: RunTaskCallbackInput, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
12
|
+
const { id, out, logs, error } = result
|
|
13
|
+
|
|
14
|
+
await releaseLock({ id, payload: { out, logs, error } })
|
|
15
|
+
|
|
16
|
+
return true
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { filter, pipe } from 'graphql-yoga'
|
|
2
|
+
import { Resolver, Subscription, Root, Arg } from 'type-graphql'
|
|
3
|
+
|
|
4
|
+
import { pubsub, getRepository, Domain } from '@things-factory/shell'
|
|
5
|
+
import { Appliance, User } from '@things-factory/auth-base'
|
|
6
|
+
import { ConnectionManager, Connection, Step } from '@things-factory/integration-base'
|
|
7
|
+
|
|
8
|
+
import { EdgeContext, RunTaskPayload } from './edge-client-type'
|
|
9
|
+
|
|
10
|
+
@Resolver(Appliance)
|
|
11
|
+
export class EdgeClientSubscription {
|
|
12
|
+
@Subscription(type => [Connection], {
|
|
13
|
+
subscribe: async ({ args, context, info }) => {
|
|
14
|
+
const { domain, user }: { domain: Domain; user: User } = context.state
|
|
15
|
+
const subdomain = domain?.subdomain
|
|
16
|
+
|
|
17
|
+
if (!domain) {
|
|
18
|
+
throw new Error('domain required')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
22
|
+
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const appliance =
|
|
26
|
+
user.reference &&
|
|
27
|
+
(await getRepository(Appliance).findOne({
|
|
28
|
+
where: {
|
|
29
|
+
id: user.reference
|
|
30
|
+
}
|
|
31
|
+
}))
|
|
32
|
+
|
|
33
|
+
if (!appliance) {
|
|
34
|
+
throw new Error('Appliance not found')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
process.nextTick(async () => {
|
|
38
|
+
const connections = Object.values(ConnectionManager.getConnectionInstanceEntities(domain)).filter(({ edgeId }) => edgeId == appliance.id)
|
|
39
|
+
|
|
40
|
+
if (connections.length > 0) {
|
|
41
|
+
pubsub.publish('sync-connections', connections)
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
return pipe(
|
|
46
|
+
pubsub.subscribe('sync-connections'),
|
|
47
|
+
filter(async (payload: Connection[]) => {
|
|
48
|
+
const connections = payload
|
|
49
|
+
const { edgeId } = connections[0]
|
|
50
|
+
|
|
51
|
+
if (connections.find(connection => connection.domain?.subdomain !== subdomain)) {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!edgeId || appliance?.id !== edgeId) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return true
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
syncConnections(@Root() payload: Connection[]): Connection[] {
|
|
65
|
+
return payload.map(connection => {
|
|
66
|
+
return {
|
|
67
|
+
...connection,
|
|
68
|
+
params: JSON.stringify(connection.params)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Subscription(type => [Connection], {
|
|
74
|
+
subscribe: async ({ args, context, info }) => {
|
|
75
|
+
const { domain, user }: { domain: Domain; user: User } = context.state
|
|
76
|
+
const subdomain = domain?.subdomain
|
|
77
|
+
|
|
78
|
+
if (!domain) {
|
|
79
|
+
throw new Error('domain required')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
83
|
+
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const appliance =
|
|
87
|
+
user.reference &&
|
|
88
|
+
(await getRepository(Appliance).findOne({
|
|
89
|
+
where: {
|
|
90
|
+
id: user.reference
|
|
91
|
+
}
|
|
92
|
+
}))
|
|
93
|
+
|
|
94
|
+
if (!appliance) {
|
|
95
|
+
throw new Error('Appliance not found')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return pipe(
|
|
99
|
+
pubsub.subscribe('connect-connections'),
|
|
100
|
+
filter(async (payload: Connection[]) => {
|
|
101
|
+
const connections = payload
|
|
102
|
+
const { edgeId } = connections[0]
|
|
103
|
+
|
|
104
|
+
if (connections.find(connection => connection.domain?.subdomain !== subdomain)) {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (!edgeId || appliance?.id !== edgeId) {
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return true
|
|
113
|
+
})
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
connectConnections(@Root() payload: Connection[]): Connection[] {
|
|
118
|
+
return payload.map(connection => {
|
|
119
|
+
return {
|
|
120
|
+
...connection,
|
|
121
|
+
params: JSON.stringify(connection.params)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@Subscription(type => [Connection], {
|
|
127
|
+
subscribe: async ({ args, context, info }) => {
|
|
128
|
+
const { domain, user }: { domain: Domain; user: User } = context.state
|
|
129
|
+
const subdomain = domain?.subdomain
|
|
130
|
+
|
|
131
|
+
if (!domain) {
|
|
132
|
+
throw new Error('domain required')
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
136
|
+
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const appliance =
|
|
140
|
+
user.reference &&
|
|
141
|
+
(await getRepository(Appliance).findOne({
|
|
142
|
+
where: {
|
|
143
|
+
id: user.reference
|
|
144
|
+
}
|
|
145
|
+
}))
|
|
146
|
+
|
|
147
|
+
if (!appliance) {
|
|
148
|
+
throw new Error('Appliance not found')
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return pipe(
|
|
152
|
+
pubsub.subscribe('disconnect-connections'),
|
|
153
|
+
filter(async (payload: Connection[]) => {
|
|
154
|
+
const connections = payload
|
|
155
|
+
const { edgeId } = connections[0]
|
|
156
|
+
|
|
157
|
+
if (connections.find(connection => connection.domain?.subdomain !== subdomain)) {
|
|
158
|
+
return false
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (!edgeId || appliance?.id !== edgeId) {
|
|
162
|
+
return false
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return true
|
|
166
|
+
})
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
disconnectConnections(@Root() payload: Connection): Connection[] {
|
|
171
|
+
return payload.map(connection => {
|
|
172
|
+
return {
|
|
173
|
+
...connection,
|
|
174
|
+
params: JSON.stringify(connection.params)
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@Subscription({
|
|
180
|
+
subscribe: async ({ args, context, info }) => {
|
|
181
|
+
const { domain, user }: { domain: Domain; user: User } = context.state
|
|
182
|
+
|
|
183
|
+
const subdomain = domain?.subdomain
|
|
184
|
+
if (!domain) {
|
|
185
|
+
throw new Error('domain required')
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!user.domains?.find(d => d.subdomain === subdomain) && !process.superUserGranted(domain, user)) {
|
|
189
|
+
throw new Error(`domain(${subdomain}) is not working for user(${user.email}).`)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const appliance =
|
|
193
|
+
user.reference &&
|
|
194
|
+
(await getRepository(Appliance).findOne({
|
|
195
|
+
where: {
|
|
196
|
+
id: user.reference
|
|
197
|
+
}
|
|
198
|
+
}))
|
|
199
|
+
|
|
200
|
+
if (!appliance) {
|
|
201
|
+
throw new Error('Appliance not found')
|
|
202
|
+
}
|
|
203
|
+
return pipe(
|
|
204
|
+
pubsub.subscribe('run-task'),
|
|
205
|
+
filter(async (payload: { id: string; step: Step; context: EdgeContext }) => {
|
|
206
|
+
const { domainId, connection } = payload.step
|
|
207
|
+
|
|
208
|
+
if (domainId !== domain.id) {
|
|
209
|
+
return false
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const { edgeId } = connection && ConnectionManager.getConnectionInstanceEntityByName(domain, connection)
|
|
213
|
+
|
|
214
|
+
if (!edgeId || appliance?.id !== edgeId) {
|
|
215
|
+
return false
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return true
|
|
219
|
+
})
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
runTask(@Root() payload: RunTaskPayload): RunTaskPayload {
|
|
224
|
+
const { id, step, context } = payload
|
|
225
|
+
const { name, task, description, connection, params } = step
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
id, // requestId
|
|
229
|
+
step: {
|
|
230
|
+
name,
|
|
231
|
+
task,
|
|
232
|
+
description,
|
|
233
|
+
connection,
|
|
234
|
+
params: JSON.stringify(params)
|
|
235
|
+
},
|
|
236
|
+
context
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { InputType, ObjectType, Field } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { Domain, ScalarObject } from '@things-factory/shell'
|
|
4
|
+
import { Step } from '@things-factory/integration-base'
|
|
5
|
+
|
|
6
|
+
@ObjectType()
|
|
7
|
+
export class EdgeContext {
|
|
8
|
+
@Field(type => Domain, { nullable: true })
|
|
9
|
+
domain: any
|
|
10
|
+
|
|
11
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
12
|
+
data: any
|
|
13
|
+
|
|
14
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
15
|
+
variables: any
|
|
16
|
+
|
|
17
|
+
@Field({ nullable: true })
|
|
18
|
+
lng: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@ObjectType()
|
|
22
|
+
export class RunTaskPayload {
|
|
23
|
+
@Field()
|
|
24
|
+
id: string
|
|
25
|
+
|
|
26
|
+
@Field()
|
|
27
|
+
step: Step
|
|
28
|
+
|
|
29
|
+
@Field()
|
|
30
|
+
context: EdgeContext
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@InputType()
|
|
34
|
+
export class RunTaskCallbackInput {
|
|
35
|
+
@Field({ nullable: true })
|
|
36
|
+
id: string
|
|
37
|
+
|
|
38
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
39
|
+
out: any
|
|
40
|
+
|
|
41
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
42
|
+
logs: any
|
|
43
|
+
|
|
44
|
+
@Field(type => ScalarObject, { nullable: true })
|
|
45
|
+
error: any
|
|
46
|
+
}
|