@contrail/cli 1.0.23 → 1.0.25
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/lib/apps/deploy-app/app-deployer.js +3 -0
- package/lib/apps/deploy-app/docker-action-builder.d.ts +10 -0
- package/lib/apps/deploy-app/docker-action-builder.js +97 -0
- package/lib/apps/deploy-app/interfaces.d.ts +2 -41
- package/lib/interfaces.d.ts +3 -0
- package/lib/workflows/workflow-template-deployer.js +0 -2
- package/package.json +1 -1
- package/src/apps/deploy-app/app-deployer.ts +3 -0
- package/src/interfaces.ts +4 -1
- package/src/workflows/workflow-template-deployer.ts +0 -2
- package/templates/typescript/app.yml +1 -0
|
@@ -57,6 +57,8 @@ export class AppDeployer {
|
|
|
57
57
|
keywords: appDeclaration.keywords,
|
|
58
58
|
configProperties,
|
|
59
59
|
triggerKeyDefinitions,
|
|
60
|
+
isDockerBased: appDeclaration.isDockerBased,
|
|
61
|
+
dockerImageRef: appDeclaration.dockerImageRef,
|
|
60
62
|
};
|
|
61
63
|
const app = await new Entities().create({ entityName: 'app', object: newApp });
|
|
62
64
|
console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
@@ -81,6 +83,7 @@ export class AppDeployer {
|
|
|
81
83
|
keywords: appDeclaration.keywords,
|
|
82
84
|
configProperties,
|
|
83
85
|
triggerKeyDefinitions,
|
|
86
|
+
isDockerBased: appDeclaration.isDockerBased,
|
|
84
87
|
};
|
|
85
88
|
const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
|
|
86
89
|
console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { App, AppDeclaration, AppActionDeclaration } from '../../interfaces';
|
|
2
|
+
export declare class ActionsDeployer {
|
|
3
|
+
deployActions(appDeclaration: AppDeclaration, app: App): Promise<void>;
|
|
4
|
+
getActionsForApp(app: App): Promise<any>;
|
|
5
|
+
deployAction(actionKey: string, actionDeclaration: AppActionDeclaration, app: App, existingActions: Array<any>): Promise<void>;
|
|
6
|
+
private createNewActionDefinition;
|
|
7
|
+
private updateActionDefinition;
|
|
8
|
+
getActionDeclarationIdentifier(actionKey: any, app: App): string;
|
|
9
|
+
getFunction(actionDeclaration: AppActionDeclaration): Promise<string>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Entities } from '@contrail/sdk';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { ConfigPropertiesParser } from './app-template-parsers';
|
|
4
|
+
import { getSeparatorByPlatform } from '../../common';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
export class ActionsDeployer {
|
|
7
|
+
async deployActions(appDeclaration, app) {
|
|
8
|
+
// FETCH ALL ACTIONS FROM THE API.
|
|
9
|
+
const existingActions = await this.getActionsForApp(app);
|
|
10
|
+
// UPSERT / DELETE BASED ON ACTION IDENTIFIER
|
|
11
|
+
console.log('%s \tDeploying actions.', chalk.yellow.bold('ACTION'));
|
|
12
|
+
for (const actionKey of Object.keys(appDeclaration.actions)) {
|
|
13
|
+
await this.deployAction(actionKey, appDeclaration.actions[actionKey], app, existingActions);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async getActionsForApp(app) {
|
|
17
|
+
return await new Entities().get({
|
|
18
|
+
entityName: 'event-workflow-action-definition',
|
|
19
|
+
criteria: { ownerKey: `app:${app.id}` },
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async deployAction(actionKey, actionDeclaration, app, existingActions) {
|
|
23
|
+
console.log(`%s \tDeploying action: ${actionKey}`, chalk.yellow.bold('ACTION'));
|
|
24
|
+
const identifier = this.getActionDeclarationIdentifier(actionKey, app);
|
|
25
|
+
const existingDefinition = existingActions.find(ad => ad.identifier === identifier);
|
|
26
|
+
if (!existingDefinition) {
|
|
27
|
+
await this.createNewActionDefinition(actionKey, actionDeclaration, app);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
await this.updateActionDefinition(existingDefinition, actionDeclaration);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async createNewActionDefinition(actionKey, actionDeclaration, app) {
|
|
34
|
+
let configProperties;
|
|
35
|
+
if (actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) {
|
|
36
|
+
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
37
|
+
}
|
|
38
|
+
const newObject = {
|
|
39
|
+
identifier: this.getActionDeclarationIdentifier(actionKey, app),
|
|
40
|
+
name: actionDeclaration.name,
|
|
41
|
+
ownerKey: `app:${app.id}`,
|
|
42
|
+
public: app.public,
|
|
43
|
+
configProperties,
|
|
44
|
+
};
|
|
45
|
+
const functionString = await this.getFunction(actionDeclaration);
|
|
46
|
+
if (functionString) {
|
|
47
|
+
newObject.executeFunctionString = functionString;
|
|
48
|
+
}
|
|
49
|
+
const actionDefinition = await new Entities().create({
|
|
50
|
+
entityName: 'event-workflow-action-definition',
|
|
51
|
+
object: newObject,
|
|
52
|
+
});
|
|
53
|
+
console.log(`%s Created new action definition: ${actionKey}`, chalk.yellow.bold('APP'));
|
|
54
|
+
return actionDefinition;
|
|
55
|
+
}
|
|
56
|
+
async updateActionDefinition(existingActionDefinition, actionDeclaration) {
|
|
57
|
+
let configProperties;
|
|
58
|
+
if (actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) {
|
|
59
|
+
configProperties = ConfigPropertiesParser.getConfigProperties(actionDeclaration.actionConfiguration);
|
|
60
|
+
}
|
|
61
|
+
else if (!(actionDeclaration === null || actionDeclaration === void 0 ? void 0 : actionDeclaration.actionConfiguration) && existingActionDefinition.configProperties) {
|
|
62
|
+
configProperties = null;
|
|
63
|
+
}
|
|
64
|
+
const updates = {
|
|
65
|
+
name: actionDeclaration.name,
|
|
66
|
+
// public: actionDeclaration.public, // TODO - an actions visibility is allowed to change
|
|
67
|
+
configProperties,
|
|
68
|
+
};
|
|
69
|
+
const functionString = await this.getFunction(actionDeclaration);
|
|
70
|
+
if (functionString) {
|
|
71
|
+
updates.executeFunctionString = functionString;
|
|
72
|
+
}
|
|
73
|
+
const actionDefinition = await new Entities().update({
|
|
74
|
+
entityName: 'event-workflow-action-definition',
|
|
75
|
+
id: existingActionDefinition.id,
|
|
76
|
+
object: updates,
|
|
77
|
+
});
|
|
78
|
+
console.log(`%s Updated existing action definition: ${actionDefinition.identifier}`, chalk.yellow.bold('APP'));
|
|
79
|
+
return actionDefinition;
|
|
80
|
+
}
|
|
81
|
+
getActionDeclarationIdentifier(actionKey, app) {
|
|
82
|
+
return app.identifier + ':' + actionKey;
|
|
83
|
+
}
|
|
84
|
+
async getFunction(actionDeclaration) {
|
|
85
|
+
if (!actionDeclaration.handler) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!actionDeclaration.handler.endsWith('.js')) {
|
|
89
|
+
throw new Error('Action handler must be a .js file.');
|
|
90
|
+
}
|
|
91
|
+
const CURRENT_DIR = process.cwd();
|
|
92
|
+
const separator = getSeparatorByPlatform();
|
|
93
|
+
const functionLocation = CURRENT_DIR + separator + actionDeclaration.handler;
|
|
94
|
+
const content = fs.readFileSync(functionLocation);
|
|
95
|
+
return content.toString();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -18,9 +18,7 @@ export interface AppDeclaration {
|
|
|
18
18
|
triggers: {
|
|
19
19
|
[key: string]: AppTriggerDeclaration;
|
|
20
20
|
};
|
|
21
|
-
|
|
22
|
-
[key: string]: WorkflowDefinitionDeclaration | WorkflowTemplateDeclaration;
|
|
23
|
-
};
|
|
21
|
+
isDockerBased?: boolean;
|
|
24
22
|
}
|
|
25
23
|
export interface ConfigPropertyElements {
|
|
26
24
|
[key: string]: ConfigPropertyElement;
|
|
@@ -42,44 +40,6 @@ export interface AppTriggerDeclaration {
|
|
|
42
40
|
external?: boolean;
|
|
43
41
|
description?: string;
|
|
44
42
|
}
|
|
45
|
-
export interface WorkflowDefinitionDeclaration {
|
|
46
|
-
id?: string;
|
|
47
|
-
identifier: string;
|
|
48
|
-
name: string;
|
|
49
|
-
triggerKey: string;
|
|
50
|
-
workflowDefinition: WorkflowDefinition;
|
|
51
|
-
ownerKey: string;
|
|
52
|
-
isActive: boolean;
|
|
53
|
-
public: boolean;
|
|
54
|
-
supportingAppId?: string;
|
|
55
|
-
}
|
|
56
|
-
export interface WorkflowTemplateDeclaration {
|
|
57
|
-
id?: string;
|
|
58
|
-
identifier: string;
|
|
59
|
-
name: string;
|
|
60
|
-
triggerKey: string;
|
|
61
|
-
workflowDefinition: WorkflowDefinition;
|
|
62
|
-
ownerKey: string;
|
|
63
|
-
isActive: boolean;
|
|
64
|
-
supportingAppId?: string;
|
|
65
|
-
messageGroupId?: string;
|
|
66
|
-
parallelWorkerCount?: number;
|
|
67
|
-
}
|
|
68
|
-
export interface WorkflowDefinition {
|
|
69
|
-
paths: WorkflowConditional[];
|
|
70
|
-
}
|
|
71
|
-
export interface WorkflowConditional {
|
|
72
|
-
conditional: string;
|
|
73
|
-
actionDefinitionConfigs: ActionDefinitionConfig[];
|
|
74
|
-
}
|
|
75
|
-
export interface ActionDefinitionConfig {
|
|
76
|
-
name: string;
|
|
77
|
-
action: string;
|
|
78
|
-
config?: {
|
|
79
|
-
[key: string]: any;
|
|
80
|
-
};
|
|
81
|
-
id?: string;
|
|
82
|
-
}
|
|
83
43
|
export interface App {
|
|
84
44
|
id: string;
|
|
85
45
|
identifier: string;
|
|
@@ -106,6 +66,7 @@ export interface EventWorkflowActionDefinition {
|
|
|
106
66
|
ownerKey?: string;
|
|
107
67
|
public?: boolean;
|
|
108
68
|
configProperties?: ConfigProperty[];
|
|
69
|
+
isDockerBased?: boolean;
|
|
109
70
|
}
|
|
110
71
|
export declare class TriggerKeyDefinition {
|
|
111
72
|
name: string;
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface AppDeclaration {
|
|
|
21
21
|
workflows?: {
|
|
22
22
|
[key: string]: WorkflowDefinition | WorkflowTemplateDeclaration;
|
|
23
23
|
};
|
|
24
|
+
isDockerBased?: boolean;
|
|
25
|
+
dockerImageRef?: string;
|
|
24
26
|
}
|
|
25
27
|
export interface ConfigPropertyElements {
|
|
26
28
|
[key: string]: ConfigPropertyElement;
|
|
@@ -113,6 +115,7 @@ export interface EventWorkflowActionDefinition {
|
|
|
113
115
|
ownerKey?: string;
|
|
114
116
|
public?: boolean;
|
|
115
117
|
configProperties?: ConfigProperty[];
|
|
118
|
+
isDockerBased?: boolean;
|
|
116
119
|
}
|
|
117
120
|
export declare class TriggerKeyDefinition {
|
|
118
121
|
name: string;
|
|
@@ -56,9 +56,7 @@ export class WorkflowTemplateDeployer {
|
|
|
56
56
|
const actionKey = actionConfiguration.action;
|
|
57
57
|
try {
|
|
58
58
|
const actionEntity = await getActionByIdentifier(actionKey);
|
|
59
|
-
console.log("response for action find:", actionEntity);
|
|
60
59
|
actionConfiguration.id = actionEntity.id;
|
|
61
|
-
console.log("found action id:", actionEntity.id);
|
|
62
60
|
}
|
|
63
61
|
catch (e) {
|
|
64
62
|
console.log(e);
|
package/package.json
CHANGED
|
@@ -65,6 +65,8 @@ export class AppDeployer {
|
|
|
65
65
|
keywords: appDeclaration.keywords,
|
|
66
66
|
configProperties,
|
|
67
67
|
triggerKeyDefinitions,
|
|
68
|
+
isDockerBased: appDeclaration.isDockerBased,
|
|
69
|
+
dockerImageRef: appDeclaration.dockerImageRef,
|
|
68
70
|
};
|
|
69
71
|
const app = await new Entities().create({ entityName: 'app', object: newApp });
|
|
70
72
|
console.log(`%s Created new app: ${app.name}`, chalk.yellow.bold('APP'));
|
|
@@ -93,6 +95,7 @@ export class AppDeployer {
|
|
|
93
95
|
keywords: appDeclaration.keywords,
|
|
94
96
|
configProperties,
|
|
95
97
|
triggerKeyDefinitions,
|
|
98
|
+
isDockerBased: appDeclaration.isDockerBased,
|
|
96
99
|
};
|
|
97
100
|
const app = await new Entities().update({ entityName: 'app', id: existingApp.id, object: updates });
|
|
98
101
|
console.log(`%s Updated app: ${app.name}`, chalk.yellow.bold('APP'));
|
package/src/interfaces.ts
CHANGED
|
@@ -14,7 +14,9 @@ export interface AppDeclaration {
|
|
|
14
14
|
actions?: { [key: string]: AppActionDeclaration };
|
|
15
15
|
appConfiguration: ConfigPropertyElements;
|
|
16
16
|
triggers: { [key: string]: AppTriggerDeclaration };
|
|
17
|
-
workflows?: { [key: string]: WorkflowDefinition|WorkflowTemplateDeclaration }
|
|
17
|
+
workflows?: { [key: string]: WorkflowDefinition|WorkflowTemplateDeclaration };
|
|
18
|
+
isDockerBased?: boolean;
|
|
19
|
+
dockerImageRef?: string;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export interface ConfigPropertyElements {
|
|
@@ -116,6 +118,7 @@ export interface EventWorkflowActionDefinition {
|
|
|
116
118
|
ownerKey?: string;
|
|
117
119
|
public?: boolean;
|
|
118
120
|
configProperties?: ConfigProperty[];
|
|
121
|
+
isDockerBased?: boolean;
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
export class TriggerKeyDefinition {
|
|
@@ -75,9 +75,7 @@ export class WorkflowTemplateDeployer {
|
|
|
75
75
|
const actionKey = actionConfiguration.action;
|
|
76
76
|
try {
|
|
77
77
|
const actionEntity: any = await getActionByIdentifier(actionKey);
|
|
78
|
-
console.log("response for action find:", actionEntity)
|
|
79
78
|
actionConfiguration.id = actionEntity.id;
|
|
80
|
-
console.log("found action id:", actionEntity.id)
|
|
81
79
|
} catch (e) {
|
|
82
80
|
console.log(e)
|
|
83
81
|
}
|
|
@@ -4,6 +4,7 @@ appDescription: "Your app description."
|
|
|
4
4
|
visibility: public
|
|
5
5
|
publisher: "Your company name"
|
|
6
6
|
version: 1.0
|
|
7
|
+
isDockerBased: true # this flag should be deprecated since all apps should be docker-based anyway
|
|
7
8
|
|
|
8
9
|
# eventWorkflowTriggerKeyMapping will be used to parse an incoming event into a key that can trigger workflows
|
|
9
10
|
# {} indicates a field on the event. You can use nested fields by separating the levels with a '.'
|