Skip to content

Commit 74c3d61

Browse files
committed
experimental updates
10.15 API updates
1 parent 3388741 commit 74c3d61

File tree

5 files changed

+394
-15
lines changed

5 files changed

+394
-15
lines changed

experimental.js

Lines changed: 288 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const request = require('request');
1313
const rest = require('./rest.js');
1414
const fs = require('fs');
1515
const { findSourceMap } = require('module');
16+
const { brotliDecompress, brotliCompressSync } = require('zlib');
1617

1718

1819
var domainName, username,password,timeout;
@@ -23,11 +24,22 @@ var authtoken="";
2324
var uid="";
2425
var csrf="";
2526
var projectId;
27+
var workflowId;
2628
var projectName ;
29+
var executionStatus;
30+
var startDate;
31+
var endDate;
32+
var startOrResume;
2733
var nextUrl,formUrl;
2834
var finalCall;
2935
var loginStageCounter = 0;
36+
const maxRunningWorkflows = 20;
3037

38+
39+
function info(message){
40+
message = "<EXPERIMENTAL> INFO: \x1b[32m" + message + "\x1b[0m"
41+
console.log(message);
42+
}
3143
function debug(message){
3244
dbg.message("<EXPERIMENTAL> " + message);
3345
}
@@ -101,6 +113,281 @@ function searchProject(inProjectName)
101113
loginPhase1();
102114
}
103115

116+
function getMonitorInfo(inExecutionStatus,inStartDate,inEndDate,inProjectId,inWorkflowId,)
117+
{
118+
projectId = inProjectId;
119+
workflowId = inWorkflowId;
120+
executionStatus = inExecutionStatus;
121+
startDate = inStartDate;
122+
endDate = inEndDate;
123+
finalCall = getLogs;
124+
loginPhase1();
125+
}
126+
127+
function workflowResubmit(instartOrResume, inStartDate,inEndDate, inProjectId,inWorkflowId,)
128+
{
129+
projectId = inProjectId;
130+
workflowId = inWorkflowId;
131+
startDate = inStartDate;
132+
endDate = inEndDate;
133+
startOrResume = instartOrResume;
134+
finalCall = checkResubmissions;
135+
loginPhase1();
136+
}
137+
138+
function debugMonitorInfo()
139+
{
140+
debug("Monitor Project: [" + projectName + "]");
141+
debug("Monitor workflowId: [" + workflowId + "]");
142+
debug("Monitor executionStatus: [" + executionStatus + "]");
143+
debug("Monitor startDate: [" + startDate + "]");
144+
debug("Monitor endDate: [" + endDate + "]");
145+
}
146+
147+
function processMonitorBody()
148+
{
149+
var body={};
150+
151+
if(endDate)body.end_date = endDate;
152+
if(startDate)body.start_date = startDate;
153+
else
154+
{
155+
startDate = new Date();
156+
startDate.setHours(0);
157+
startDate.setMinutes(0);
158+
startDate.setSeconds(0);
159+
startDate.setMilliseconds(0);
160+
161+
if(!endDate)
162+
{
163+
endDate = new Date;
164+
endDate.setHours(23);
165+
endDate.setMinutes(59);
166+
endDate.setSeconds(59);
167+
endDate.setMilliseconds(999);
168+
}
169+
body.start_date=startDate;
170+
body.end_date=endDate;
171+
}
172+
173+
if(projectId)body.projects=[projectId]
174+
if(workflowId)body.workflows = [workflowId];
175+
if(executionStatus)body.execution_status = [executionStatus];
176+
body.skip=0;
177+
body.limit=20;
178+
return body;
179+
}
180+
181+
function setHeaders()
182+
{
183+
var headers = [
184+
{name:"authtoken",value:authtoken},
185+
{name:"accept",value:"application/json"},
186+
{name:"x-csrf-token",value:csrf},
187+
];
188+
return headers;
189+
}
190+
191+
function checkResubmissions()
192+
{
193+
debug("Check Resubmissions")
194+
debugMonitorInfo();
195+
//Check running
196+
var endPoint = "https://" + domainName + "/enterprise/v1/metrics/workflowexecutions/logs";
197+
debug("Next URL [" + endPoint + "]");
198+
var body=processMonitorBody();
199+
body.execution_status=["running"];
200+
var headers = setHeaders();
201+
rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processRunningResponse,undefined,headers,true,false);
202+
}
203+
204+
function processResubmissions(reprocessCount)
205+
{
206+
debug("Process Resubmissions")
207+
debugMonitorInfo();
208+
//Check running
209+
var endPoint = "https://" + domainName + "/enterprise/v1/metrics/workflowexecutions/logs";
210+
debug("Next URL [" + endPoint + "]");
211+
var body=processMonitorBody();
212+
body.limit=reprocessCount;
213+
body.execution_status=["failed"];
214+
var headers = setHeaders();
215+
rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processListResponse,undefined,headers,true,false);
216+
}
217+
218+
function processSingleResubmission(a,b, vbid)
219+
{
220+
info("Processing Resubmission [" + a + " of " + b + "] Action [" + startOrResume + "] VBID [" + vbid + "]");
221+
var endPoint = "https://cpointegrationdev.int-aws-de.webmethods.io/enterprise/v1/tenant/account/billlogs/" + vbid;
222+
debug("Next URL [" + endPoint + "]");
223+
//var body=processMonitorBody();
224+
//body.limit=reprocessCount;
225+
//body.execution_status=["failed"];
226+
var headers = setHeaders();
227+
rest.custom(endPoint,undefined,undefined,60,undefined,undefined,"GET",processSingleResubmissionResponse,undefined,headers,true,false);
228+
}
229+
230+
function finishProcessSingleResubmission(vbid,wfuid,payloaduid,projectuid,flowname,stoptime)
231+
{
232+
info("Actioning Resubmission Action [" + startOrResume + "] VBID [" + vbid + "]");
233+
var endPoint = "https://" + domainName + "/enterprise/v1/execute/" + wfuid + "/resume"
234+
debug("Next URL [" + endPoint + "]");
235+
//var body=processMonitorBody();
236+
//body.limit=reprocessCount;
237+
//body.execution_status=["failed"];
238+
var headers = [
239+
{name:"authtoken",value:authtoken},
240+
{name:"accept",value:"application/json"},
241+
{name:"x-csrf-token",value:csrf},
242+
{name:"project_uid",value:projectuid},
243+
];
244+
var body = {"bill_uid":vbid,"__is_checkpoint_run__":true,"payload_uid":payloaduid,"checkpointLogs":[]};
245+
rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processFinalSingleResubmissionResponse,undefined,headers,true,false);
246+
}
247+
248+
function processFinalSingleResubmissionResponse(url,err,body,res){
249+
if(res.statusCode==200)
250+
{
251+
info("Processed");
252+
}
253+
else
254+
{
255+
info("Failed to Resubmit entry")
256+
console.log(body);
257+
process.exit(99);
258+
}
259+
}
260+
261+
function processSingleResubmissionResponse(url,err,body,res){
262+
if(res.statusCode==200)
263+
{
264+
if(body.output.uid)
265+
{
266+
info("Found Monitor Entry");
267+
info("VBID [" + body.output.uid + "]");
268+
info("Flow UID [" + body.output.flow_uid + "]");
269+
info("Payload UID [" + body.output.payload_uid + "]");
270+
info("Project_UID [" + body.output.project_uid + "]");
271+
info("Flow Name [" + body.output.flow_name + "]");
272+
info("Stop time [" + body.output.stop_time + "]");
273+
finishProcessSingleResubmission(body.output.uid,body.output.flow_uid,body.output.payload_uid,body.output.project_uid,body.output.flow_name,body.output.stop_time);
274+
}
275+
else{
276+
277+
info("Not able to find monitor entry");
278+
}
279+
}
280+
else
281+
{
282+
info("Failed to get Monitor entry")
283+
console.log(body);
284+
process.exit(99);
285+
}
286+
}
287+
288+
function processRunningResponse(url,err,body,res){
289+
//console.log(body);
290+
if(res.statusCode==200)
291+
{
292+
//... do something next
293+
if(body.output.count==0)
294+
{
295+
info("No Workflows Running")
296+
info("Can Resubmit [" + (maxRunningWorkflows - body.output.count) + "] executions");
297+
}
298+
else{
299+
info("Workflows Running [" +body.output.count + "]")
300+
if(body.output.count<maxRunningWorkflows)
301+
{
302+
info("Can Resubmit [" + (maxRunningWorkflows - body.output.count) + "] executions");
303+
}
304+
else
305+
{
306+
info("Maximum Workflows Currently in progress");
307+
process.exit(0);
308+
}
309+
}
310+
processResubmissions(maxRunningWorkflows - body.output.count);
311+
}
312+
else
313+
{
314+
info("Failed to get Running Workflows")
315+
console.log(err);
316+
process.exit(99);
317+
}
318+
}
319+
320+
function processListResponse(url,err,body,res){
321+
//console.log(body);
322+
if(res.statusCode==200)
323+
{
324+
resubmitExecutions = maxRunningWorkflows;
325+
//... do something next
326+
if(body.output.count==0)
327+
{
328+
info("No Workflows To Resubmit");
329+
process.exit(0);
330+
}
331+
else{
332+
333+
info("Workflows To Resubmit [" + body.output.logs.length + " of " + body.output.count + "]");
334+
for(var i=0;i<body.output.logs.length;i++)
335+
{
336+
processSingleResubmission(i,body.output.logs.length,body.output.logs[i].uid);
337+
}
338+
339+
}
340+
}
341+
else
342+
{
343+
info("Failed to get Running Workflows")
344+
console.log(err);
345+
process.exit(99);
346+
}
347+
}
348+
349+
function processRunningResponse(url,err,body,res){
350+
//console.log(body);
351+
if(res.statusCode==200)
352+
{
353+
//... do something next
354+
if(body.output.count==0)
355+
{
356+
console.log("No Workflows Running")
357+
debug("Can Resubmit [" + (maxRunningWorkflows - body.output.count) + "] executions");
358+
}
359+
else{
360+
debug("Workflows Running [" +body.output.count + "]")
361+
if(body.output.count<maxRunningWorkflows)
362+
{
363+
debug("Can Resubmit [" + (maxRunningWorkflows - body.output.count) + "] executions");
364+
}
365+
else
366+
{
367+
debug("Maximum Workflows Currently in progress");
368+
process.exit(0);
369+
}
370+
}
371+
processResubmissions(maxRunningWorkflows - body.output.count);
372+
}
373+
else
374+
{
375+
debug("Failed to get Running Workflows")
376+
console.log(err);
377+
process.exit(99);
378+
}
379+
}
380+
381+
function getLogs()
382+
{
383+
debugMonitorInfo();
384+
var endPoint = "https://" + domainName + "/enterprise/v1/metrics/workflowexecutions/logs";
385+
debug("Next URL [" + endPoint + "]");
386+
var body=processMonitorBody();
387+
var headers = setHeaders();
388+
rest.custom(endPoint,undefined,undefined,60,body,undefined,"POST",processResponse,undefined,headers,true,false);
389+
}
390+
104391

105392
function searchProjectsByName()
106393
{
@@ -484,4 +771,4 @@ function loginResponse(url,err,body,res){
484771
}
485772

486773

487-
module.exports = {init,user,stages,projectWorkflows,projectFlowservices,connectorAccounts,getProjectAccountConfig,searchProject,projectDeployments};
774+
module.exports = {init,user,stages,projectWorkflows,projectFlowservices,connectorAccounts,getProjectAccountConfig,searchProject,getMonitorInfo,workflowResubmit,projectDeployments};

projects.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ $ node wmiocli.js
144144
e.g.
145145
node wmiocli.js -d env -u user -p pass project-webhooks-auth flf1111 flf2222 login
146146
147+
\x1b[32mList triggers in project\x1b[0m
148+
$ node wmiocli.js
149+
-d tenant.int-aws-us.webmethods.io
150+
-u user
151+
-p password
152+
project-triggers-list project-uid
153+
154+
\x1b[32mDelete trigger in project\x1b[0m
155+
$ node wmiocli.js
156+
-d tenant.int-aws-us.webmethods.io
157+
-u user
158+
-p password
159+
project-triggers-delete project-uid trigger-uid
147160
`;
148161
}
149162
function init(inDomainName, inUsername, inPassword, inTimeout, inPrettyprint) {
@@ -315,9 +328,26 @@ function deploy(projectName, version) {
315328
request.post(url, username, password, timeout, data, processResponse);
316329
}
317330

331+
function listTriggers(projectId) {
332+
debug("List Triggers for ProjectId [" + projectId + "]");
333+
if (projectId) url += "/" + projectId + "/trigger-flows";
334+
request.get(url, username, password, timeout, processResponse);
335+
}
336+
337+
function deleteTrigger(projectId,triggerId) {
338+
debug("Deete Triggers for ProjectId [" + projectId + "] with triggerID [" + triggerId + "]");
339+
if (projectId) url += "/" + projectId + "/trigger-flows";
340+
if(triggerId) url += "/" + triggerId;
341+
var data;
342+
request.httpDelete(url, username, password, timeout, data, processResponse);
343+
}
344+
345+
346+
318347
module.exports = {
319348
help, init, list, create, update, del,
320349
listAssets, listAssetsDetailed, pub, deploy,
321350
createParam, updateParam, listParam, deleteParam,
322-
listWebhooks, regenWebhook, setWebhookAuth
351+
listWebhooks, regenWebhook, setWebhookAuth,
352+
listTriggers, deleteTrigger
323353
};

rest.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,14 @@ function custom(restEndPoint,user,pass,timeout,jsonBody,formBody,type,callback,c
354354
}
355355

356356
//Body Content
357-
if(jsonBody!==undefined)options.body=jsonBody;
357+
if(jsonBody!==undefined)
358+
{
359+
debug("Processing JSON Body");
360+
debug("Body is [" + JSON.stringify(jsonBody) + "]");
361+
options.body=jsonBody;
362+
363+
}
364+
358365
if(formBody!==undefined)
359366
{
360367
debug("Processing Form");

0 commit comments

Comments
 (0)