@things-factory/integration-base 7.0.0-alpha.0 → 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/dist-server/controllers/index.js +5 -0
- package/dist-server/controllers/index.js.map +1 -0
- package/dist-server/controllers/scenario-controller.js +87 -0
- package/dist-server/controllers/scenario-controller.js.map +1 -0
- package/dist-server/engine/connection-manager.js +37 -6
- package/dist-server/engine/connection-manager.js.map +1 -1
- package/dist-server/engine/connector/echo-back-connector.js +1 -1
- package/dist-server/engine/connector/echo-back-connector.js.map +1 -1
- package/dist-server/engine/connector/echo-back-server.js +1 -1
- package/dist-server/engine/connector/echo-back-server.js.map +1 -1
- package/dist-server/engine/connector/graphql-connector.js +6 -6
- package/dist-server/engine/connector/graphql-connector.js.map +1 -1
- package/dist-server/engine/connector/http-connector.js.map +1 -1
- package/dist-server/engine/connector/mqtt-connector.js.map +1 -1
- package/dist-server/engine/connector/mssql-connector.js.map +1 -1
- package/dist-server/engine/connector/mysql-connector.js +3 -3
- package/dist-server/engine/connector/mysql-connector.js.map +1 -1
- package/dist-server/engine/connector/operato-connector.js +19 -22
- package/dist-server/engine/connector/operato-connector.js.map +1 -1
- package/dist-server/engine/connector/oracle-connector.js +113 -17
- package/dist-server/engine/connector/oracle-connector.js.map +1 -1
- package/dist-server/engine/connector/postgresql-connector.js.map +1 -1
- package/dist-server/engine/connector/proxy-connector.js +44 -0
- package/dist-server/engine/connector/proxy-connector.js.map +1 -0
- package/dist-server/engine/connector/socket-server.js +1 -1
- package/dist-server/engine/connector/socket-server.js.map +1 -1
- package/dist-server/engine/connector/sqlite-connector.js.map +1 -1
- package/dist-server/engine/edge-client.js +38 -0
- package/dist-server/engine/edge-client.js.map +1 -0
- package/dist-server/engine/index.js +1 -0
- package/dist-server/engine/index.js.map +1 -1
- package/dist-server/engine/task/book-up-scenario.js.map +1 -1
- package/dist-server/engine/task/csv-readline.js.map +1 -1
- package/dist-server/engine/task/data-accessor.js.map +1 -1
- package/dist-server/engine/task/data-mapper.js.map +1 -1
- package/dist-server/engine/task/database-query.js.map +1 -1
- package/dist-server/engine/task/echo-receive.js.map +1 -1
- package/dist-server/engine/task/echo-send.js.map +1 -1
- package/dist-server/engine/task/empty-check.js.map +1 -1
- package/dist-server/engine/task/end.js.map +1 -1
- package/dist-server/engine/task/floating-point.js.map +1 -1
- package/dist-server/engine/task/goto.js.map +1 -1
- package/dist-server/engine/task/graphql-mutate.js.map +1 -1
- package/dist-server/engine/task/graphql-query.js.map +1 -1
- package/dist-server/engine/task/headless-post.js.map +1 -1
- package/dist-server/engine/task/headless-scrap.js.map +1 -1
- package/dist-server/engine/task/http-get.js.map +1 -1
- package/dist-server/engine/task/http-post.js.map +1 -1
- package/dist-server/engine/task/jsonata.js +1 -1
- package/dist-server/engine/task/jsonata.js.map +1 -1
- package/dist-server/engine/task/local-graphql-mutate.js.map +1 -1
- package/dist-server/engine/task/local-graphql-query.js.map +1 -1
- package/dist-server/engine/task/log.js.map +1 -1
- package/dist-server/engine/task/mqtt-publish.js.map +1 -1
- package/dist-server/engine/task/mqtt-subscribe.js.map +1 -1
- package/dist-server/engine/task/oracle-procedure.js +1 -15
- package/dist-server/engine/task/oracle-procedure.js.map +1 -1
- package/dist-server/engine/task/pick-pending-scenario.js.map +1 -1
- package/dist-server/engine/task/publish.js.map +1 -1
- package/dist-server/engine/task/random.js.map +1 -1
- package/dist-server/engine/task/reset-pending-queue.js.map +1 -1
- package/dist-server/engine/task/script.js +1 -0
- package/dist-server/engine/task/script.js.map +1 -1
- package/dist-server/engine/task/set-domain.js.map +1 -1
- package/dist-server/engine/task/sleep.js.map +1 -1
- package/dist-server/engine/task/socket-listener.js.map +1 -1
- package/dist-server/engine/task/state-read.js.map +1 -1
- package/dist-server/engine/task/state-write.js.map +1 -1
- package/dist-server/engine/task/stop-scenario.js.map +1 -1
- package/dist-server/engine/task/sub-scenario.js.map +1 -1
- package/dist-server/engine/task/switch-goto.js.map +1 -1
- package/dist-server/engine/task/switch-range-goto.js.map +1 -1
- package/dist-server/engine/task/switch-range-scenario.js.map +1 -1
- package/dist-server/engine/task/switch-range-set.js.map +1 -1
- package/dist-server/engine/task/switch-scenario.js.map +1 -1
- package/dist-server/engine/task/switch-set.js.map +1 -1
- package/dist-server/engine/task/throw.js.map +1 -1
- package/dist-server/engine/task/utils/headless-pool-for-scenario.js +1 -1
- package/dist-server/engine/task/utils/headless-pool-for-scenario.js.map +1 -1
- package/dist-server/engine/task/variables.js.map +1 -1
- package/dist-server/engine/types.js.map +1 -1
- package/dist-server/index.js +1 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/restful/unstable/run-scenario.js.map +1 -1
- package/dist-server/restful/unstable/start-scenario.js +1 -1
- package/dist-server/restful/unstable/start-scenario.js.map +1 -1
- package/dist-server/restful/unstable/stop-scenario.js +1 -1
- package/dist-server/restful/unstable/stop-scenario.js.map +1 -1
- package/dist-server/service/connection/connection-mutation.js +4 -8
- package/dist-server/service/connection/connection-mutation.js.map +1 -1
- package/dist-server/service/connection/connection-query.js +17 -14
- package/dist-server/service/connection/connection-query.js.map +1 -1
- package/dist-server/service/connection/connection-subscription.js +11 -14
- package/dist-server/service/connection/connection-subscription.js.map +1 -1
- package/dist-server/service/connection/connection-type.js +66 -13
- package/dist-server/service/connection/connection-type.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-mutation.js +4 -71
- package/dist-server/service/scenario-instance/scenario-instance-mutation.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-subscription.js +8 -9
- package/dist-server/service/scenario-instance/scenario-instance-subscription.js.map +1 -1
- package/dist-server/service/scenario-instance/scenario-instance-type.js +18 -5
- package/dist-server/service/scenario-instance/scenario-instance-type.js.map +1 -1
- package/dist-server/service/scenario-queue/scenario-queue-subscription.js +4 -4
- package/dist-server/service/scenario-queue/scenario-queue-subscription.js.map +1 -1
- package/dist-server/service/step/step-type.js +41 -28
- package/dist-server/service/step/step-type.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/helps/integration/concept/script-internal-variables.ja.md +21 -1
- package/helps/integration/concept/script-internal-variables.ko.md +17 -0
- package/helps/integration/concept/script-internal-variables.md +18 -0
- package/helps/integration/concept/script-internal-variables.ms.md +19 -1
- package/helps/integration/concept/script-internal-variables.zh.md +18 -0
- package/helps/integration/connector/oracle-connector.ja.md +90 -0
- package/helps/integration/connector/oracle-connector.ko.md +87 -0
- package/helps/integration/connector/oracle-connector.md +46 -25
- package/helps/integration/connector/oracle-connector.ms.md +87 -0
- package/helps/integration/connector/oracle-connector.zh.md +87 -0
- package/helps/integration/task/script.ja.md +1 -1
- package/helps/integration/task/script.ko.md +1 -1
- package/helps/integration/task/script.md +1 -1
- package/helps/integration/task/script.ms.md +1 -1
- package/helps/integration/task/script.zh.md +1 -1
- package/openapi/unstable/scenario.yaml +100 -100
- package/openapi/unstable.yaml +11 -11
- package/package.json +8 -11
- package/server/controllers/index.ts +1 -0
- package/server/controllers/scenario-controller.ts +116 -0
- package/server/engine/connection-manager.ts +49 -7
- package/server/engine/connector/echo-back-connector.ts +4 -3
- package/server/engine/connector/echo-back-server.ts +5 -4
- package/server/engine/connector/graphql-connector.ts +12 -13
- package/server/engine/connector/http-connector.ts +4 -3
- package/server/engine/connector/mqtt-connector.ts +4 -3
- package/server/engine/connector/mssql-connector.ts +4 -3
- package/server/engine/connector/mysql-connector.ts +8 -6
- package/server/engine/connector/operato-connector.ts +27 -35
- package/server/engine/connector/oracle-connector.ts +136 -23
- package/server/engine/connector/postgresql-connector.ts +4 -3
- package/server/engine/connector/proxy-connector.ts +53 -0
- package/server/engine/connector/socket-server.ts +5 -4
- package/server/engine/connector/sqlite-connector.ts +5 -3
- package/server/engine/edge-client.ts +45 -0
- package/server/engine/index.ts +1 -0
- package/server/engine/task/book-up-scenario.ts +3 -1
- package/server/engine/task/csv-readline.ts +4 -1
- package/server/engine/task/data-accessor.ts +4 -1
- package/server/engine/task/data-mapper.ts +4 -1
- package/server/engine/task/database-query.ts +3 -1
- package/server/engine/task/echo-receive.ts +4 -1
- package/server/engine/task/echo-send.ts +3 -1
- package/server/engine/task/empty-check.ts +4 -1
- package/server/engine/task/end.ts +4 -1
- package/server/engine/task/floating-point.ts +4 -1
- package/server/engine/task/goto.ts +4 -1
- package/server/engine/task/graphql-mutate.ts +3 -1
- package/server/engine/task/graphql-query.ts +3 -1
- package/server/engine/task/headless-post.ts +4 -1
- package/server/engine/task/headless-scrap.ts +3 -1
- package/server/engine/task/http-get.ts +3 -1
- package/server/engine/task/http-post.ts +3 -1
- package/server/engine/task/jsonata.ts +5 -2
- package/server/engine/task/local-graphql-mutate.ts +5 -1
- package/server/engine/task/local-graphql-query.ts +3 -1
- package/server/engine/task/log.ts +3 -1
- package/server/engine/task/mqtt-publish.ts +3 -1
- package/server/engine/task/mqtt-subscribe.ts +3 -1
- package/server/engine/task/oracle-procedure.ts +4 -17
- package/server/engine/task/pick-pending-scenario.ts +3 -1
- package/server/engine/task/publish.ts +3 -1
- package/server/engine/task/random.ts +4 -1
- package/server/engine/task/reset-pending-queue.ts +3 -1
- package/server/engine/task/script.ts +5 -1
- package/server/engine/task/set-domain.ts +4 -1
- package/server/engine/task/sleep.ts +3 -1
- package/server/engine/task/socket-listener.ts +3 -1
- package/server/engine/task/state-read.ts +3 -1
- package/server/engine/task/state-write.ts +3 -1
- package/server/engine/task/stop-scenario.ts +3 -1
- package/server/engine/task/sub-scenario.ts +3 -1
- package/server/engine/task/switch-goto.ts +4 -1
- package/server/engine/task/switch-range-goto.ts +3 -1
- package/server/engine/task/switch-range-scenario.ts +3 -1
- package/server/engine/task/switch-range-set.ts +3 -1
- package/server/engine/task/switch-scenario.ts +3 -1
- package/server/engine/task/switch-set.ts +3 -1
- package/server/engine/task/throw.ts +3 -1
- package/server/engine/task/utils/headless-pool-for-scenario.ts +1 -1
- package/server/engine/task/variables.ts +3 -1
- package/server/engine/types.ts +80 -4
- package/server/index.ts +1 -0
- package/server/restful/unstable/run-scenario.ts +0 -1
- package/server/restful/unstable/start-scenario.ts +1 -1
- package/server/restful/unstable/stop-scenario.ts +1 -1
- package/server/service/connection/connection-mutation.ts +9 -29
- package/server/service/connection/connection-query.ts +13 -12
- package/server/service/connection/connection-subscription.ts +18 -24
- package/server/service/connection/connection-type.ts +100 -21
- package/server/service/scenario-instance/scenario-instance-mutation.ts +10 -121
- package/server/service/scenario-instance/scenario-instance-subscription.ts +16 -23
- package/server/service/scenario-instance/scenario-instance-type.ts +24 -13
- package/server/service/scenario-queue/scenario-queue-subscription.ts +7 -7
- package/server/service/step/step-type.ts +78 -22
@@ -3,6 +3,7 @@ import PromiseSocket from 'promise-socket'
|
|
3
3
|
|
4
4
|
import { Connector } from '../types'
|
5
5
|
import { ConnectionManager } from '../connection-manager'
|
6
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
6
7
|
|
7
8
|
export class EchoBack implements Connector {
|
8
9
|
async ready(connectionConfigs) {
|
@@ -11,12 +12,12 @@ export class EchoBack implements Connector {
|
|
11
12
|
ConnectionManager.logger.info('echo-back connections are ready')
|
12
13
|
}
|
13
14
|
|
14
|
-
async connect(connection) {
|
15
|
+
async connect(connection: InputConnection) {
|
15
16
|
let socket = new PromiseSocket(new net.Socket())
|
16
17
|
let [host, port = 8124] = connection.endpoint.split(':')
|
17
18
|
|
18
19
|
try {
|
19
|
-
await socket.connect(port, host)
|
20
|
+
await socket.connect(Number(port), host)
|
20
21
|
ConnectionManager.addConnectionInstance(connection, socket)
|
21
22
|
|
22
23
|
ConnectionManager.logger.info(
|
@@ -29,7 +30,7 @@ export class EchoBack implements Connector {
|
|
29
30
|
}
|
30
31
|
}
|
31
32
|
|
32
|
-
async disconnect(connection) {
|
33
|
+
async disconnect(connection: InputConnection) {
|
33
34
|
let socket = ConnectionManager.removeConnectionInstance(connection)
|
34
35
|
|
35
36
|
await socket.destroy()
|
@@ -3,15 +3,16 @@ import PromiseSocket from 'promise-socket'
|
|
3
3
|
|
4
4
|
import { Connector } from '../types'
|
5
5
|
import { ConnectionManager } from '../connection-manager'
|
6
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
6
7
|
|
7
8
|
export class EchoBack implements Connector {
|
8
|
-
async ready(connectionConfigs) {
|
9
|
+
async ready(connectionConfigs: InputConnection[]) {
|
9
10
|
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
10
11
|
|
11
12
|
ConnectionManager.logger.info('echo-back-servers are ready')
|
12
13
|
}
|
13
14
|
|
14
|
-
async connect(config): Promise<void> {
|
15
|
+
async connect(config: InputConnection): Promise<void> {
|
15
16
|
var [host = '0.0.0.0', port = 8124] = config.endpoint.split(':')
|
16
17
|
|
17
18
|
return new Promise((resolve, reject) => {
|
@@ -35,7 +36,7 @@ export class EchoBack implements Connector {
|
|
35
36
|
|
36
37
|
try {
|
37
38
|
let promiseSocket = new PromiseSocket(socket)
|
38
|
-
await promiseSocket.connect(port, 'localhost')
|
39
|
+
await promiseSocket.connect(Number(port), 'localhost')
|
39
40
|
promiseSocket['__server__'] = server
|
40
41
|
|
41
42
|
ConnectionManager.addConnectionInstance(config, promiseSocket)
|
@@ -53,7 +54,7 @@ export class EchoBack implements Connector {
|
|
53
54
|
})
|
54
55
|
}
|
55
56
|
|
56
|
-
async disconnect(connection) {
|
57
|
+
async disconnect(connection: InputConnection) {
|
57
58
|
let socket = ConnectionManager.removeConnectionInstance(connection)
|
58
59
|
var server = socket['__server__']
|
59
60
|
|
@@ -7,6 +7,7 @@ import { getRepository } from '@things-factory/shell'
|
|
7
7
|
|
8
8
|
import { ConnectionManager } from '../connection-manager'
|
9
9
|
import { Connector } from '../types'
|
10
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
10
11
|
|
11
12
|
const defaultOptions: any = {
|
12
13
|
watchQuery: {
|
@@ -22,24 +23,20 @@ const defaultOptions: any = {
|
|
22
23
|
}
|
23
24
|
}
|
24
25
|
|
25
|
-
const cache = new InMemoryCache({
|
26
|
-
addTypename: false
|
27
|
-
})
|
28
|
-
|
29
26
|
export class GraphqlConnector implements Connector {
|
30
|
-
async ready(connectionConfigs) {
|
27
|
+
async ready(connectionConfigs: InputConnection[]) {
|
31
28
|
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
32
29
|
|
33
30
|
ConnectionManager.logger.info('graphql-connector connections are ready')
|
34
31
|
}
|
35
32
|
|
36
|
-
async connect(connection) {
|
37
|
-
|
33
|
+
async connect(connection: InputConnection) {
|
34
|
+
const {
|
38
35
|
endpoint: uri,
|
39
36
|
params: { authClient }
|
40
37
|
} = connection
|
41
38
|
|
42
|
-
|
39
|
+
const ERROR_HANDLER: any = ({ graphQLErrors, networkError }) => {
|
43
40
|
if (graphQLErrors)
|
44
41
|
graphQLErrors.map(({ message, locations, path }) => {
|
45
42
|
ConnectionManager.logger.error(`[GraphQL error] Message: ${message}, Location: ${locations}, Path: ${path}`)
|
@@ -64,6 +61,10 @@ export class GraphqlConnector implements Connector {
|
|
64
61
|
return forward(operation)
|
65
62
|
})
|
66
63
|
|
64
|
+
const cache = new InMemoryCache({
|
65
|
+
addTypename: false
|
66
|
+
})
|
67
|
+
|
67
68
|
ConnectionManager.addConnectionInstance(
|
68
69
|
connection,
|
69
70
|
new ApolloClient({
|
@@ -80,13 +81,11 @@ export class GraphqlConnector implements Connector {
|
|
80
81
|
})
|
81
82
|
)
|
82
83
|
|
83
|
-
ConnectionManager.logger.info(
|
84
|
-
`graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`
|
85
|
-
)
|
84
|
+
ConnectionManager.logger.info(`graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`)
|
86
85
|
}
|
87
86
|
|
88
|
-
async disconnect(connection) {
|
89
|
-
|
87
|
+
async disconnect(connection: InputConnection) {
|
88
|
+
const client = ConnectionManager.getConnectionInstance(connection)
|
90
89
|
client.stop()
|
91
90
|
ConnectionManager.removeConnectionInstance(connection)
|
92
91
|
|
@@ -3,15 +3,16 @@ import { getRepository } from '@things-factory/shell'
|
|
3
3
|
|
4
4
|
import { ConnectionManager } from '../connection-manager'
|
5
5
|
import { Connector } from '../types'
|
6
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
6
7
|
|
7
8
|
export class HttpConnector implements Connector {
|
8
|
-
async ready(connectionConfigs) {
|
9
|
+
async ready(connectionConfigs: InputConnection[]) {
|
9
10
|
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
10
11
|
|
11
12
|
ConnectionManager.logger.info('http-connector connections are ready')
|
12
13
|
}
|
13
14
|
|
14
|
-
async connect(connection) {
|
15
|
+
async connect(connection: InputConnection) {
|
15
16
|
var { params } = connection
|
16
17
|
params.rejectUnauthorized = (params.rejectUnauthorized || 'Y') === 'Y'
|
17
18
|
|
@@ -29,7 +30,7 @@ export class HttpConnector implements Connector {
|
|
29
30
|
ConnectionManager.logger.info(`http-connector connection(${connection.name}:${connection.endpoint}) is connected`)
|
30
31
|
}
|
31
32
|
|
32
|
-
async disconnect(connection) {
|
33
|
+
async disconnect(connection: InputConnection) {
|
33
34
|
ConnectionManager.removeConnectionInstance(connection)
|
34
35
|
|
35
36
|
ConnectionManager.logger.info(`http-connector connection(${connection.name}) is disconnected`)
|
@@ -1,16 +1,17 @@
|
|
1
1
|
import { Connector } from '../types'
|
2
2
|
import { ConnectionManager } from '../connection-manager'
|
3
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
3
4
|
|
4
5
|
import mqtt from 'async-mqtt'
|
5
6
|
|
6
7
|
export class MqttConnector implements Connector {
|
7
|
-
async ready(connectionConfigs) {
|
8
|
+
async ready(connectionConfigs: InputConnection[]) {
|
8
9
|
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
9
10
|
|
10
11
|
ConnectionManager.logger.info('mqtt-connector connections are ready')
|
11
12
|
}
|
12
13
|
|
13
|
-
async connect(connection) {
|
14
|
+
async connect(connection: InputConnection) {
|
14
15
|
const {
|
15
16
|
endpoint: uri,
|
16
17
|
params: { user, password }
|
@@ -43,7 +44,7 @@ export class MqttConnector implements Connector {
|
|
43
44
|
}
|
44
45
|
}
|
45
46
|
|
46
|
-
async disconnect(connection) {
|
47
|
+
async disconnect(connection: InputConnection) {
|
47
48
|
const { client } = ConnectionManager.removeConnectionInstance(connection)
|
48
49
|
|
49
50
|
client && (await client.end())
|
@@ -2,6 +2,7 @@ import { logger } from '@things-factory/env'
|
|
2
2
|
|
3
3
|
import { ConnectionManager } from '../connection-manager'
|
4
4
|
import { Connector } from '../types'
|
5
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
5
6
|
|
6
7
|
try {
|
7
8
|
var Client = require('mssql')
|
@@ -10,13 +11,13 @@ try {
|
|
10
11
|
}
|
11
12
|
|
12
13
|
export class MssqlConnector implements Connector {
|
13
|
-
async ready(connectionConfigs) {
|
14
|
+
async ready(connectionConfigs: InputConnection[]) {
|
14
15
|
await Promise.all(connectionConfigs.map(this.connect))
|
15
16
|
|
16
17
|
ConnectionManager.logger.info('mssql-connector connections are ready')
|
17
18
|
}
|
18
19
|
|
19
|
-
async connect(connection) {
|
20
|
+
async connect(connection: InputConnection) {
|
20
21
|
const {
|
21
22
|
endpoint,
|
22
23
|
params: { user, password, database, encrypt = 'Y' }
|
@@ -50,7 +51,7 @@ export class MssqlConnector implements Connector {
|
|
50
51
|
ConnectionManager.logger.info(`MSSql Database(${connection.name}:${database}) at ${endpoint} connected.`)
|
51
52
|
}
|
52
53
|
|
53
|
-
async disconnect(connection) {
|
54
|
+
async disconnect(connection: InputConnection) {
|
54
55
|
var client = ConnectionManager.getConnectionInstance(connection)
|
55
56
|
try {
|
56
57
|
await client.close()
|
@@ -1,20 +1,22 @@
|
|
1
|
+
import Mysql from "mysql2/promise";
|
2
|
+
|
1
3
|
import { Connector } from '../types'
|
2
4
|
import { ConnectionManager } from '../connection-manager'
|
3
|
-
import
|
5
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
4
6
|
|
5
7
|
export class mysqlConnector implements Connector {
|
6
|
-
async ready(connectionConfigs) {
|
8
|
+
async ready(connectionConfigs: InputConnection[]) {
|
7
9
|
await Promise.all(connectionConfigs.map(this.connect));
|
8
10
|
ConnectionManager.logger.info("mysql-connector connections are ready");
|
9
11
|
}
|
10
12
|
|
11
|
-
async connect(connection) {
|
13
|
+
async connect(connection: InputConnection) {
|
12
14
|
const {
|
13
15
|
endpoint,
|
14
16
|
params: { user, password, database },
|
15
17
|
} = connection;
|
16
18
|
|
17
|
-
|
19
|
+
let [host, port = '3306'] = endpoint.split(":");
|
18
20
|
|
19
21
|
if (!Mysql) {
|
20
22
|
throw new Error("mysql module loading failed");
|
@@ -24,7 +26,7 @@ export class mysqlConnector implements Connector {
|
|
24
26
|
user,
|
25
27
|
password,
|
26
28
|
host,
|
27
|
-
port,
|
29
|
+
port: Number(port),
|
28
30
|
database,
|
29
31
|
});
|
30
32
|
|
@@ -50,7 +52,7 @@ export class mysqlConnector implements Connector {
|
|
50
52
|
);
|
51
53
|
}
|
52
54
|
|
53
|
-
async disconnect(connection) {
|
55
|
+
async disconnect(connection: InputConnection) {
|
54
56
|
var client = ConnectionManager.getConnectionInstance(connection);
|
55
57
|
try {
|
56
58
|
await client.close();
|
@@ -3,7 +3,6 @@ import 'cross-fetch/polyfill'
|
|
3
3
|
import { ApolloClient, InMemoryCache, createHttpLink, split } from '@apollo/client/core'
|
4
4
|
import { setContext } from '@apollo/client/link/context'
|
5
5
|
|
6
|
-
// for subscription
|
7
6
|
import WebSocket from 'ws'
|
8
7
|
import { createClient } from 'graphql-ws'
|
9
8
|
import { GraphQLWsLink } from '@apollo/client/link/subscriptions'
|
@@ -12,13 +11,15 @@ import gql from 'graphql-tag'
|
|
12
11
|
|
13
12
|
import { ConnectionManager } from '../connection-manager'
|
14
13
|
import { Connector } from '../types'
|
14
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
15
|
+
|
15
16
|
import { Scenario } from '../../service/scenario/scenario'
|
16
17
|
import { ScenarioInstance } from '../../service/scenario-instance/scenario-instance-type'
|
17
18
|
|
18
19
|
import { getRepository, GraphqlLocalClient, Domain } from '@things-factory/shell'
|
19
20
|
import { User, checkPermission } from '@things-factory/auth-base'
|
20
21
|
|
21
|
-
const debug = require('debug')('things-factory:integration-base:operato-connector
|
22
|
+
const debug = require('debug')('things-factory:integration-base:operato-connector')
|
22
23
|
|
23
24
|
const defaultOptions: any = {
|
24
25
|
watchQuery: {
|
@@ -34,10 +35,6 @@ const defaultOptions: any = {
|
|
34
35
|
}
|
35
36
|
}
|
36
37
|
|
37
|
-
const cache = new InMemoryCache({
|
38
|
-
addTypename: false
|
39
|
-
})
|
40
|
-
|
41
38
|
export const GRAPHQL_URI = '/graphql'
|
42
39
|
export const SUBSCRIPTION_URI = GRAPHQL_URI
|
43
40
|
|
@@ -46,19 +43,18 @@ interface SubscriberData {
|
|
46
43
|
scenario: any
|
47
44
|
subscriptionObserver: any
|
48
45
|
}
|
49
|
-
;``
|
50
46
|
|
51
47
|
export class OperatoConnector implements Connector {
|
52
48
|
private context: any
|
53
49
|
|
54
|
-
async ready(connectionConfigs) {
|
50
|
+
async ready(connectionConfigs: InputConnection[]) {
|
55
51
|
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
56
52
|
|
57
|
-
ConnectionManager.logger.info('
|
53
|
+
ConnectionManager.logger.info('operato-connector connections are ready')
|
58
54
|
}
|
59
55
|
|
60
|
-
async connect(connection) {
|
61
|
-
|
56
|
+
async connect(connection: InputConnection) {
|
57
|
+
const {
|
62
58
|
endpoint: uri,
|
63
59
|
params: { authKey, domain, subscriptionHandlers = {} }
|
64
60
|
} = connection
|
@@ -67,7 +63,7 @@ export class OperatoConnector implements Connector {
|
|
67
63
|
throw new Error('some connection paramter missing.')
|
68
64
|
}
|
69
65
|
|
70
|
-
|
66
|
+
const domainOwner = await getRepository(User).findOne({
|
71
67
|
where: {
|
72
68
|
id: connection.domain.owner
|
73
69
|
}
|
@@ -123,20 +119,24 @@ export class OperatoConnector implements Connector {
|
|
123
119
|
}).concat(httpLink)
|
124
120
|
)
|
125
121
|
|
126
|
-
|
122
|
+
const cache = new InMemoryCache({
|
123
|
+
addTypename: false
|
124
|
+
})
|
125
|
+
|
126
|
+
const client = new ApolloClient({
|
127
127
|
defaultOptions,
|
128
128
|
cache,
|
129
129
|
link: splitLink
|
130
130
|
})
|
131
131
|
|
132
|
-
|
132
|
+
const subscriptions: SubscriberData[] = []
|
133
133
|
Object.keys(subscriptionHandlers).forEach(async tag => {
|
134
134
|
if (!tag || !subscriptionHandlers[tag]) return
|
135
135
|
|
136
|
-
|
136
|
+
const scenarioName = subscriptionHandlers[tag]
|
137
137
|
|
138
138
|
// fetch a scenario
|
139
|
-
|
139
|
+
const selectedScenario = await getRepository(Scenario).findOne({
|
140
140
|
where: {
|
141
141
|
name: scenarioName
|
142
142
|
},
|
@@ -154,7 +154,7 @@ export class OperatoConnector implements Connector {
|
|
154
154
|
`
|
155
155
|
})
|
156
156
|
|
157
|
-
|
157
|
+
const subscriptionObserver = subscription.subscribe({
|
158
158
|
next: async data => {
|
159
159
|
debug('received pubsub msg.:', data?.data)
|
160
160
|
await this.runScenario(subscriptions, data?.data?.data)
|
@@ -167,9 +167,7 @@ export class OperatoConnector implements Connector {
|
|
167
167
|
}
|
168
168
|
})
|
169
169
|
|
170
|
-
ConnectionManager.logger.info(
|
171
|
-
`(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`
|
172
|
-
)
|
170
|
+
ConnectionManager.logger.info(`(${connection.name}:${connection.endpoint}) subscription closed flag: ${subscriptionObserver.closed}`)
|
173
171
|
|
174
172
|
subscriptions.push({
|
175
173
|
tag,
|
@@ -182,19 +180,17 @@ export class OperatoConnector implements Connector {
|
|
182
180
|
client['subscriptions'] = subscriptions
|
183
181
|
ConnectionManager.addConnectionInstance(connection, client)
|
184
182
|
|
185
|
-
ConnectionManager.logger.info(
|
186
|
-
`graphql-connector connection(${connection.name}:${connection.endpoint}) is connected`
|
187
|
-
)
|
183
|
+
ConnectionManager.logger.info(`operato-connector connection(${connection.name}:${connection.endpoint}) is connected`)
|
188
184
|
}
|
189
185
|
|
190
|
-
async disconnect(connection) {
|
191
|
-
|
192
|
-
|
186
|
+
async disconnect(connection: InputConnection) {
|
187
|
+
const client = ConnectionManager.getConnectionInstance(connection)
|
188
|
+
const subscriptions: SubscriberData[] = client['subscriptions']
|
193
189
|
subscriptions.forEach(subscription => subscription.subscriptionObserver.unsubscribe())
|
194
190
|
client.stop()
|
195
191
|
ConnectionManager.removeConnectionInstance(connection)
|
196
192
|
|
197
|
-
ConnectionManager.logger.info(`
|
193
|
+
ConnectionManager.logger.info(`operato-connector connection(${connection.name}) is disconnected`)
|
198
194
|
}
|
199
195
|
|
200
196
|
async runScenario(subscriptions: SubscriberData[], variables: any): Promise<ScenarioInstance> {
|
@@ -205,23 +201,19 @@ export class OperatoConnector implements Connector {
|
|
205
201
|
throw new Error(`tag is invalid - ${tag}`)
|
206
202
|
}
|
207
203
|
|
208
|
-
|
204
|
+
const scenario = subscriptions.find(subscription => subscription.tag === tag)?.scenario
|
209
205
|
if (!scenario) {
|
210
206
|
throw new Error(`scenario is not found - ${tag}`)
|
211
207
|
}
|
212
208
|
|
213
209
|
if (!(await checkPermission(scenario.privilege, user, domain, unsafeIP, prohibitedPrivileges))) {
|
214
210
|
const { category, privilege } = scenario.privilege || {}
|
215
|
-
throw new Error(
|
216
|
-
`Unauthorized! ${
|
217
|
-
category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'
|
218
|
-
} required`
|
219
|
-
)
|
211
|
+
throw new Error(`Unauthorized! ${category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'} required`)
|
220
212
|
}
|
221
213
|
|
222
214
|
/* create a scenario instance */
|
223
|
-
|
224
|
-
|
215
|
+
const instanceName = scenario.name + '-' + String(Date.now())
|
216
|
+
const instance = new ScenarioInstance(instanceName, scenario, {
|
225
217
|
user,
|
226
218
|
domain,
|
227
219
|
variables,
|
@@ -2,63 +2,155 @@ import { logger } from '@things-factory/env'
|
|
2
2
|
|
3
3
|
import { ConnectionManager } from '../connection-manager'
|
4
4
|
import { Connector } from '../types'
|
5
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
5
6
|
|
6
7
|
try {
|
7
|
-
var
|
8
|
+
var oracledb = require('oracledb')
|
8
9
|
} catch (err) {
|
9
10
|
logger.error('oracledb module loading failed')
|
10
11
|
}
|
11
12
|
|
12
13
|
export class OracleConnector implements Connector {
|
13
|
-
async ready(connectionConfigs) {
|
14
|
+
async ready(connectionConfigs: InputConnection[]) {
|
14
15
|
await Promise.all(connectionConfigs.map(this.connect))
|
15
16
|
|
16
17
|
ConnectionManager.logger.info('oracle-connector connections are ready')
|
17
18
|
}
|
18
19
|
|
19
|
-
async
|
20
|
+
async recreatePool(connection: InputConnection) {
|
20
21
|
const {
|
22
|
+
name,
|
21
23
|
endpoint,
|
22
|
-
params: { user, password, database }
|
24
|
+
params: { user, password, database, poolMin, poolMax, poolIncrement },
|
25
|
+
domain
|
23
26
|
} = connection
|
24
27
|
|
25
|
-
if (!
|
28
|
+
if (!oracledb) {
|
26
29
|
throw new Error('oracledb module loading failed')
|
27
30
|
}
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
const poolAlias = `${domain.name}-${name}`
|
33
|
+
await oracledb.getPool(poolAlias).close(10)
|
34
|
+
await oracledb.createPool({
|
31
35
|
user,
|
32
36
|
password,
|
33
|
-
|
37
|
+
// when oracle not using default port must add connection string with port like localhost:port
|
38
|
+
connectString: `${endpoint.trim()}/${database}`,
|
39
|
+
poolMin,
|
40
|
+
poolMax,
|
41
|
+
poolIncrement,
|
42
|
+
poolAlias
|
34
43
|
})
|
35
44
|
|
45
|
+
ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} recreated.`)
|
46
|
+
}
|
47
|
+
|
48
|
+
async connect(connection: InputConnection) {
|
49
|
+
const {
|
50
|
+
name,
|
51
|
+
endpoint,
|
52
|
+
params: { user, password, database, poolMin, poolMax, poolIncrement },
|
53
|
+
domain
|
54
|
+
} = connection
|
55
|
+
|
56
|
+
if (!oracledb) {
|
57
|
+
throw new Error('oracledb module loading failed')
|
58
|
+
}
|
59
|
+
|
60
|
+
const poolAlias = `${domain.name}-${name}`
|
61
|
+
|
62
|
+
var enableStatistics = true
|
63
|
+
const pool = await oracledb.createPool({
|
64
|
+
user,
|
65
|
+
password,
|
66
|
+
// when oracle not using default port must add connection string with port like localhost:port
|
67
|
+
connectString: `${endpoint.trim()}/${database}`,
|
68
|
+
poolMin,
|
69
|
+
poolMax,
|
70
|
+
poolIncrement,
|
71
|
+
poolAlias,
|
72
|
+
enableStatistics
|
73
|
+
})
|
74
|
+
|
36
75
|
ConnectionManager.addConnectionInstance(connection, {
|
37
76
|
query: async (query, params) => {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
77
|
+
let dbConnection: any = {}
|
78
|
+
let taskResult: any = {}
|
79
|
+
try {
|
80
|
+
dbConnection = await oracledb.getConnection(poolAlias)
|
81
|
+
|
82
|
+
taskResult = (
|
83
|
+
await dbConnection.execute(query, params, {
|
84
|
+
outFormat: oracledb.OBJECT
|
85
|
+
})
|
86
|
+
).rows
|
87
|
+
} catch (e) {
|
88
|
+
if (e.name === 'Error' && e.message.includes('NJS-040')) {
|
89
|
+
await this.recreatePool(connection)
|
90
|
+
}
|
91
|
+
throw e
|
92
|
+
}
|
93
|
+
finally {
|
94
|
+
await dbConnection.close()
|
95
|
+
}
|
96
|
+
return taskResult
|
97
|
+
|
43
98
|
},
|
44
99
|
execute: async (procedure, params) => {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
100
|
+
let dbConnection: any = {}
|
101
|
+
let taskResult: any = {}
|
102
|
+
try {
|
103
|
+
// TODO: need to check if this is available when procedure string is a common query.
|
104
|
+
procedure = `BEGIN
|
105
|
+
${procedure}
|
106
|
+
END;`
|
107
|
+
dbConnection = await oracledb.getConnection(poolAlias)
|
108
|
+
|
109
|
+
// console.log('\n************* stat after get ****************')
|
110
|
+
// await oracledb.getPool(poolAlias).logStatistics()
|
111
|
+
|
112
|
+
const result = await dbConnection.execute(procedure, params, {
|
113
|
+
outFormat: oracledb.OBJECT
|
114
|
+
})
|
115
|
+
|
116
|
+
let paramKeys = Object.keys(params)
|
117
|
+
|
118
|
+
for (const paramKey of paramKeys) {
|
119
|
+
if (params[paramKey].dir === oracledb?.BIND_OUT) {
|
120
|
+
if (params[paramKey].type === oracledb?.CURSOR) {
|
121
|
+
const resultSetTemp = result.outBinds[paramKey]
|
122
|
+
taskResult[paramKey] = await resultSetTemp.getRows()
|
123
|
+
await resultSetTemp.close()
|
124
|
+
} else {
|
125
|
+
taskResult[paramKey] = result.outBinds[paramKey]
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
} catch (e) {
|
130
|
+
if (e.name === 'Error' && e.message.includes('NJS-040')) {
|
131
|
+
await this.recreatePool(connection)
|
132
|
+
}
|
133
|
+
throw e
|
134
|
+
}
|
135
|
+
finally {
|
136
|
+
await dbConnection.close()
|
137
|
+
|
138
|
+
// console.log('\n************* stat after close ****************')
|
139
|
+
// await oracledb.getPool(poolAlias).logStatistics()
|
140
|
+
}
|
141
|
+
return taskResult
|
53
142
|
},
|
54
|
-
close:
|
143
|
+
close: async () => {
|
144
|
+
await oracledb.getPool(poolAlias).close(10)
|
145
|
+
}
|
55
146
|
})
|
56
147
|
|
57
148
|
ConnectionManager.logger.info(`Oracle Database(${connection.name}:${database}) at ${endpoint} connected.`)
|
58
149
|
}
|
59
150
|
|
60
|
-
async disconnect(connection) {
|
151
|
+
async disconnect(connection: InputConnection) {
|
61
152
|
var client = ConnectionManager.getConnectionInstance(connection)
|
153
|
+
|
62
154
|
try {
|
63
155
|
await client.close()
|
64
156
|
ConnectionManager.logger.info(`Oracle Database(${connection.name}) closed.`)
|
@@ -86,6 +178,27 @@ export class OracleConnector implements Connector {
|
|
86
178
|
name: 'database',
|
87
179
|
placeholder: 'SID',
|
88
180
|
label: 'database'
|
181
|
+
},
|
182
|
+
{
|
183
|
+
type: 'number',
|
184
|
+
name: 'poolMin',
|
185
|
+
placeholder: 'minimum connection-pool size',
|
186
|
+
label: 'pool-min',
|
187
|
+
value: 0
|
188
|
+
},
|
189
|
+
{
|
190
|
+
type: 'number',
|
191
|
+
name: 'poolMax',
|
192
|
+
placeholder: 'maximum connection-pool size',
|
193
|
+
label: 'pool-max',
|
194
|
+
value: 4
|
195
|
+
},
|
196
|
+
{
|
197
|
+
type: 'number',
|
198
|
+
name: 'poolIncrement',
|
199
|
+
placeholder: 'connection incremental size',
|
200
|
+
label: 'pool-increment',
|
201
|
+
value: 1
|
89
202
|
}
|
90
203
|
]
|
91
204
|
}
|
@@ -2,6 +2,7 @@ import { logger } from '@things-factory/env'
|
|
2
2
|
|
3
3
|
import { ConnectionManager } from '../connection-manager'
|
4
4
|
import { Connector } from '../types'
|
5
|
+
import { InputConnection } from '../../service/connection/connection-type'
|
5
6
|
|
6
7
|
try {
|
7
8
|
var { Client } = require('pg')
|
@@ -10,13 +11,13 @@ try {
|
|
10
11
|
}
|
11
12
|
|
12
13
|
export class PostgresqlConnector implements Connector {
|
13
|
-
async ready(connectionConfigs) {
|
14
|
+
async ready(connectionConfigs: InputConnection[]) {
|
14
15
|
await Promise.all(connectionConfigs.map(this.connect.bind(this)))
|
15
16
|
|
16
17
|
ConnectionManager.logger.info('postgresql-connector connections are ready')
|
17
18
|
}
|
18
19
|
|
19
|
-
async connect(connection) {
|
20
|
+
async connect(connection: InputConnection) {
|
20
21
|
const {
|
21
22
|
endpoint,
|
22
23
|
params: { user, password, database }
|
@@ -59,7 +60,7 @@ export class PostgresqlConnector implements Connector {
|
|
59
60
|
}
|
60
61
|
}
|
61
62
|
|
62
|
-
async disconnect(connection) {
|
63
|
+
async disconnect(connection: InputConnection) {
|
63
64
|
var client = ConnectionManager.getConnectionInstance(connection)
|
64
65
|
try {
|
65
66
|
await client.close()
|