-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathworkflow.js
169 lines (143 loc) · 5.15 KB
/
workflow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* webMethods.io CLI
* Copyright 2022 Software AG
* Apache-2.0
*/
const rest = require('./rest-fetch.js');
var domainName, username, password, timeout, prettyprint;
var url;
function debug(message) {
logger.debug("<WORKFLOW> " + message);
}
function help() {
return `
\x1b[4mWorkflow\x1b[0m
\x1b[32mExport Workflow from a given project (identified from URL in webMethods.io when in workflow canvas,
i.e. https://tenant.int-aws-us.webmethods.io/#/projects/\x1b[1mfl65d3aa87fc1783ea5cf8c8\x1b[0m\x1b[32m/workflows/\x1b[1mfl52232a2dfafbd6536963d7\x1b[0m\x1b[32m/edit):\x1b[0m\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
workflow-export fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7 export.zip
\x1b[32mImport Workflow from a given file into a project \x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
workflow-import fl65d3aa87fc1783ea5cf8c8 export.zip
\x1b[32mCreate a blank workflow\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
workflow-create fl65d3aa87fc1783ea5cf8c8 "name" "description"
\x1b[32mDelete Workflow from a given project\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
workflow-delete fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7
\x1b[32mExecute a Workflow from a given project\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
workflow-execute fl65d3aa87fc1783ea5cf8c8 fl52232a2dfafbd6536963d7
\x1b[32mGet Workflow execution status from a given project\x1b[0m
$ node wmiocli.js
-d tenant.int-aws-us.webmethods.io
-u user
-p password
workflow-status fl65d3aa87fc1783ea5cf8c8 vbid3d247cd26aa5e19354e1fc6951766a3d19c049bee11d
`;
}
function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyPrint, projectId) {
domainName = inDomainName;
username = inUsername;
password = inPassword;
timeout = inTimeout;
prettyprint = inPrettyPrint;
url = "https://" + domainName + "/apis/v1/rest/projects/" + projectId;
debug("Username [" + username + "]");
debug("URL [" + url + "]");
debug("Timeout [" + timeout + "]");
}
/**
* Call back function to process REST response
* @param {return data from REST request} data
* @param {status} status
*/
function processResponse(restEndPointUrl, err, data, response) {
if(response===undefined || response === null){
console.error("No response received");
console.error(err);
process.exit(1);
}
let status = response.status;
if (prettyprint == true) {
console.log(JSON.stringify(data, null, 4));
}
else {
console.log(JSON.stringify(data));
}
if (status != 0) {
process.exit(status);
}
}
function downloadExport(restEndPoint,err,data,response,filename) {
let status=response.status;
debug("Downloading Export (Status=" + status + ")");
if (status != 200) {
console.log(JSON.stringify(data));
process.exit(status);
}
else {
rest.downloadFile(data, filename, downloadCompleted);
}
}
function downloadCompleted(data, status, filename) {
debug("Download Completed");
if (status != 0) {
console.log('{');
console.log(' workflow-export":"error", "filename":"' + filename + ',');
console.log(JSON.stringifydata);
console.log('}');
process.exit(status);
}
else {
console.log('{"workflow-export":"success", "filename":"' + filename + '"}');
}
}
function exportwf(wfId, filename) {
debug("Exporting Workflow");
url += "/workflows/" + wfId + "/export";
var data = {};
rest.postDownloadFile(url, username, password, timeout, data, filename, downloadExport);
}
function importwf(filename) {
debug("Importing Workflow");
url += "/workflow-import";
rest.postUploadFile(url, username, password, timeout, undefined, filename,"recipe", processResponse);
}
function runwf(workflowId) {
debug("Running Workflow with ID [" + workflowId + "]");
url += "/workflows/" + workflowId + "/run";
rest.post(url, username, password, timeout, undefined, processResponse);
}
function statuswf(runId) {
debug("Getting Workflow Status with run id [" + runId + "]");
url += "/workflow-run/" + runId;
debug("URL is: " + url);
rest.get(url, username, password, timeout, processResponse);
}
function deletewf(workflowId) {
debug("Deleting Workflow with ID [" + workflowId + "]");
url += "/workflows/" + workflowId;
rest.del(url, username, password, timeout, {}, processResponse);
}
function createwf(workflowName,workflowDesc) {
debug("Creating Workflow with Name [" + workflowName + "]");
url += "/workflows/";
rest.post(url, username, password, timeout, {"name":workflowName,"description":workflowDesc}, processResponse);
}
module.exports = { help, init, exportwf, importwf, runwf, statuswf, deletewf, createwf };