@things-factory/integration-base 6.2.118 → 6.2.120
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/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/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-type.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/openapi/unstable/scenario.yaml +100 -100
- package/openapi/unstable.yaml +11 -11
- package/package.json +7 -7
- package/server/controllers/index.ts +1 -0
- package/server/controllers/scenario-controller.ts +116 -0
- 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/scenario-instance/scenario-instance-mutation.ts +10 -121
- package/server/service/scenario-instance/scenario-instance-type.ts +5 -8
@@ -1,35 +1,14 @@
|
|
1
1
|
import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { ScalarObject } from '@things-factory/shell'
|
4
4
|
|
5
|
-
import { ScenarioEngine } from '../../engine'
|
6
|
-
import { Scenario } from '../scenario/scenario'
|
7
5
|
import { ScenarioInstance } from './scenario-instance-type'
|
8
|
-
import { PrivilegeObject, User, checkPermission } from '@things-factory/auth-base'
|
9
|
-
import { Step } from '../step/step-type'
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
): Promise<{ name: string; steps: Step[]; domain: Domain; privilege?: PrivilegeObject }> {
|
17
|
-
var repository = getRepository(Scenario)
|
18
|
-
|
19
|
-
var scenario = await repository.findOne({
|
20
|
-
where: { domain: { id: domain.id }, name: scenarioName },
|
21
|
-
relations: ['domain', 'steps', 'creator', 'updater']
|
22
|
-
})
|
23
|
-
|
24
|
-
if (!scenario && domain.parentId) {
|
25
|
-
scenario = await repository.findOne({
|
26
|
-
where: { domain: { id: domain.parentId }, name: scenarioName },
|
27
|
-
relations: ['domain', 'steps', 'creator', 'updater']
|
28
|
-
})
|
29
|
-
}
|
30
|
-
|
31
|
-
return scenario as any
|
32
|
-
}
|
7
|
+
import {
|
8
|
+
runScenario as controllerRunScenario,
|
9
|
+
startScenario as controllerStartScenario,
|
10
|
+
stopScenario as controllerStopScenario
|
11
|
+
} from '../../controllers/scenario-controller'
|
33
12
|
|
34
13
|
@Resolver(ScenarioInstance)
|
35
14
|
export class ScenarioInstanceMutation {
|
@@ -42,42 +21,7 @@ export class ScenarioInstanceMutation {
|
|
42
21
|
@Arg('variables', type => ScalarObject, { nullable: true }) variables: any,
|
43
22
|
@Ctx() context: ResolverContext
|
44
23
|
): Promise<ScenarioInstance> {
|
45
|
-
|
46
|
-
|
47
|
-
debug('runScenario', scenarioName, instanceName, variables)
|
48
|
-
|
49
|
-
var scenario = await findScenario(scenarioName, domain)
|
50
|
-
|
51
|
-
if (!scenario) {
|
52
|
-
throw new Error(
|
53
|
-
context.t('error.scenario not found', {
|
54
|
-
scenario: scenarioName
|
55
|
-
})
|
56
|
-
)
|
57
|
-
}
|
58
|
-
|
59
|
-
if (!(await checkPermission(scenario.privilege, user, domain, unsafeIP, prohibitedPrivileges))) {
|
60
|
-
const { category, privilege } = scenario.privilege || {}
|
61
|
-
throw new Error(
|
62
|
-
`Unauthorized! ${
|
63
|
-
category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'
|
64
|
-
} required`
|
65
|
-
)
|
66
|
-
}
|
67
|
-
|
68
|
-
/* 시나리오 인스턴스를 생성한다. */
|
69
|
-
instanceName = instanceName || scenarioName + '-' + String(Date.now())
|
70
|
-
var instance = new ScenarioInstance(instanceName, scenario, {
|
71
|
-
domain,
|
72
|
-
user,
|
73
|
-
lng,
|
74
|
-
variables,
|
75
|
-
client: GraphqlLocalClient.client
|
76
|
-
})
|
77
|
-
|
78
|
-
await instance.run()
|
79
|
-
|
80
|
-
return instance
|
24
|
+
return await controllerRunScenario(instanceName, scenarioName, variables, context)
|
81
25
|
}
|
82
26
|
|
83
27
|
@Mutation(returns => ScenarioInstance, { description: 'To start new scenario instance' })
|
@@ -87,66 +31,11 @@ export class ScenarioInstanceMutation {
|
|
87
31
|
@Arg('variables', type => ScalarObject, { nullable: true }) variables: any,
|
88
32
|
@Ctx() context: ResolverContext
|
89
33
|
): Promise<ScenarioInstance> {
|
90
|
-
|
91
|
-
|
92
|
-
debug('startScenario', instanceName, scenarioName, variables)
|
93
|
-
|
94
|
-
var scenario = await findScenario(scenarioName, domain)
|
95
|
-
|
96
|
-
if (!scenario) {
|
97
|
-
throw new Error(
|
98
|
-
context.t('error.scenario not found', {
|
99
|
-
scenario: scenarioName
|
100
|
-
})
|
101
|
-
)
|
102
|
-
}
|
103
|
-
|
104
|
-
if (!(await checkPermission(scenario.privilege, user, domain, unsafeIP, prohibitedPrivileges))) {
|
105
|
-
const { category, privilege } = scenario.privilege || {}
|
106
|
-
throw new Error(
|
107
|
-
`Unauthorized! ${
|
108
|
-
category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'
|
109
|
-
} required`
|
110
|
-
)
|
111
|
-
}
|
112
|
-
|
113
|
-
instanceName = instanceName || scenarioName
|
114
|
-
return await ScenarioEngine.load(instanceName, scenario, { domain, user, lng, variables })
|
34
|
+
return await controllerStartScenario(instanceName, scenarioName, variables, context)
|
115
35
|
}
|
116
36
|
|
117
37
|
@Mutation(returns => ScenarioInstance, { nullable: true, description: 'To start new scenario instance' })
|
118
|
-
async stopScenario(
|
119
|
-
|
120
|
-
@Ctx() context: ResolverContext
|
121
|
-
): Promise<ScenarioInstance | undefined> {
|
122
|
-
const { domain, user, unsafeIP, prohibitedPrivileges } = context.state
|
123
|
-
|
124
|
-
debug('stopScenario', instanceName)
|
125
|
-
|
126
|
-
var scenarioInstance = ScenarioEngine.getScenarioInstance(domain, instanceName)
|
127
|
-
|
128
|
-
if (!scenarioInstance) {
|
129
|
-
debug('stopScenario', `ScenarioInstance(${instanceName}) Not Found.`)
|
130
|
-
throw new Error(
|
131
|
-
context.t('error.scenario instance not found', {
|
132
|
-
instance: instanceName
|
133
|
-
})
|
134
|
-
)
|
135
|
-
}
|
136
|
-
|
137
|
-
var scenario = await findScenario(scenarioInstance.scenarioName, domain)
|
138
|
-
|
139
|
-
if (!(await checkPermission(scenario.privilege, user, domain, unsafeIP, prohibitedPrivileges))) {
|
140
|
-
const { category, privilege } = scenario.privilege || {}
|
141
|
-
throw new Error(
|
142
|
-
`Unauthorized! ${
|
143
|
-
category && privilege ? category + ':' + privilege + ' privilege' : 'ownership granted'
|
144
|
-
} required`
|
145
|
-
)
|
146
|
-
}
|
147
|
-
|
148
|
-
await ScenarioEngine.unload(domain, instanceName)
|
149
|
-
|
150
|
-
return scenarioInstance
|
38
|
+
async stopScenario(@Arg('instanceName', { nullable: true }) instanceName: string, @Ctx() context: ResolverContext): Promise<ScenarioInstance | undefined> {
|
39
|
+
return await controllerStopScenario(instanceName, context)
|
151
40
|
}
|
152
41
|
}
|
@@ -125,7 +125,7 @@ export class ScenarioInstance {
|
|
125
125
|
timestamp: Date
|
126
126
|
|
127
127
|
@Field({ nullable: true })
|
128
|
-
|
128
|
+
public message: string
|
129
129
|
|
130
130
|
private steps: Step[]
|
131
131
|
private rounds: number = 0
|
@@ -267,10 +267,7 @@ export class ScenarioInstance {
|
|
267
267
|
this.context.logger.error(ex.message ? ex.message : ex)
|
268
268
|
|
269
269
|
debug('failed to run ', `[ Domain: ${domain.name}, Scenario: ${scenarioName} ]\n`, ex)
|
270
|
-
this.setState(
|
271
|
-
ScenarioInstanceStatus.HALTED,
|
272
|
-
typeof message == 'object' ? JSON.stringify(message, null, 2) : message
|
273
|
-
)
|
270
|
+
this.setState(ScenarioInstanceStatus.HALTED, typeof message == 'object' ? JSON.stringify(message, null, 2) : message)
|
274
271
|
|
275
272
|
throw ex
|
276
273
|
}
|
@@ -376,9 +373,9 @@ export class ScenarioInstance {
|
|
376
373
|
return
|
377
374
|
}
|
378
375
|
|
379
|
-
this.message = `${this.instanceName}:[state changed] ${ScenarioInstanceStatus[this.getState()]} => ${
|
380
|
-
|
381
|
-
}
|
376
|
+
this.message = `${this.instanceName}:[state changed] ${ScenarioInstanceStatus[this.getState()]} => ${ScenarioInstanceStatus[state]}${
|
377
|
+
message ? ' caused by ' + util.inspect(message, false, 2, true) : ''
|
378
|
+
}`
|
382
379
|
|
383
380
|
this.context.state = state
|
384
381
|
|