@itentialopensource/adapter-utils 5.10.21 → 5.10.23
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/connectorRest.js +3 -1
- package/lib/restHandler.js +20 -10
- package/lib/throttle.js +80 -30
- package/package.json +1 -1
package/lib/connectorRest.js
CHANGED
|
@@ -789,7 +789,9 @@ function makeRequest(request, entitySchema, callProperties, startTrip, attempt,
|
|
|
789
789
|
healthy = true;
|
|
790
790
|
doneH2(true);
|
|
791
791
|
}, (retH2) => {
|
|
792
|
-
|
|
792
|
+
// COMMENTING OUT THE COMPLETE LOG until we figure out how to handle scrubbing
|
|
793
|
+
// log.debug(`${origin}: CALL RETURN ${JSON.stringify(propUtilInst.scrubSensitiveInfo(callResp, addSensitiveItems))}`);
|
|
794
|
+
log.debug(`${origin}: CALL RETURNED`);
|
|
793
795
|
useProt = undefined;
|
|
794
796
|
callResp.reqHdr = request.header.headers;
|
|
795
797
|
return callback(callResp);
|
package/lib/restHandler.js
CHANGED
|
@@ -343,7 +343,8 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
343
343
|
|
|
344
344
|
// if id, log response (if all - too much to log all)
|
|
345
345
|
if (entityId === 'nomap') {
|
|
346
|
-
log.debug(`${origin}: RESPONSE: ${resObj.response}`);
|
|
346
|
+
// log.debug(`${origin}: RESPONSE: ${resObj.response}`);
|
|
347
|
+
log.debug(`${origin}: RESPONSE NO MAP`);
|
|
347
348
|
|
|
348
349
|
// if no mapping (do not care about response just that we did not
|
|
349
350
|
// error) set response
|
|
@@ -353,20 +354,23 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
353
354
|
|
|
354
355
|
// if the data is not json we can not perform the extended capabilities so just return it
|
|
355
356
|
if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'PLAIN') {
|
|
356
|
-
log.debug(`${origin}: RESPONSE: ${resObj.response}`);
|
|
357
|
+
// log.debug(`${origin}: RESPONSE: ${resObj.response}`);
|
|
358
|
+
log.debug(`${origin}: RESPONSE PLAIN`);
|
|
357
359
|
|
|
358
360
|
// return the response
|
|
359
361
|
return callback(retObject);
|
|
360
362
|
}
|
|
361
363
|
if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'XML') {
|
|
362
|
-
log.debug(`${origin}: RESPONSE: ${resObj.response}`);
|
|
364
|
+
// log.debug(`${origin}: RESPONSE: ${resObj.response}`);
|
|
365
|
+
log.debug(`${origin}: RESPONSE XML`);
|
|
363
366
|
|
|
364
367
|
// return the response
|
|
365
368
|
return callback(retObject);
|
|
366
369
|
}
|
|
367
370
|
|
|
368
371
|
if (entitySchema && entitySchema.responseDatatype && entitySchema.responseDatatype.toUpperCase() === 'XML2JSON') {
|
|
369
|
-
log.debug(`${origin}: RESPONSE: ${resObj.response}`);
|
|
372
|
+
// log.debug(`${origin}: RESPONSE: ${resObj.response}`);
|
|
373
|
+
log.debug(`${origin}: RESPONSE XML2JSON`);
|
|
370
374
|
|
|
371
375
|
try {
|
|
372
376
|
const parser = new xml2js.Parser({ explicitArray: false, attrkey: '_attr' });
|
|
@@ -410,12 +414,14 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
410
414
|
const responseBody = unzipresponse.toString('utf8'); // Convert buffer to string
|
|
411
415
|
if (responseDatatype === 'GZIP2PLAIN') {
|
|
412
416
|
retObject.response = responseBody;
|
|
413
|
-
log.debug(`${origin}: RESPONSE: ${retObject.response}`);
|
|
417
|
+
// log.debug(`${origin}: RESPONSE: ${retObject.response}`);
|
|
418
|
+
log.debug(`${origin}: RESPONSE GZIP2PLAIN`);
|
|
414
419
|
return callback(retObject);
|
|
415
420
|
} if (responseDatatype === 'GZIP2JSON') {
|
|
416
421
|
try {
|
|
417
422
|
retObject.response = JSON.parse(responseBody);
|
|
418
|
-
log.debug(`${origin}: RESPONSE: ${retObject.response}`);
|
|
423
|
+
// log.debug(`${origin}: RESPONSE: ${retObject.response}`);
|
|
424
|
+
log.debug(`${origin}: RESPONSE GZIP2JSON`);
|
|
419
425
|
return callback(retObject); // Parse responseBody as JSON
|
|
420
426
|
} catch (jsonErr) {
|
|
421
427
|
log.warn(`${origin}: Error parsing JSON response: ${jsonErr}`);
|
|
@@ -459,9 +465,11 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
459
465
|
|
|
460
466
|
// if the response is an array, log the first item
|
|
461
467
|
if (Array.isArray(returnFieldData)) {
|
|
462
|
-
log.debug(`${origin}: RESPONSE (FIRST): ${JSON.stringify(returnFieldData[0])}`);
|
|
468
|
+
// log.debug(`${origin}: RESPONSE (FIRST): ${JSON.stringify(returnFieldData[0])}`);
|
|
469
|
+
log.debug(`${origin}: RESPONSE KEY FOUND`);
|
|
463
470
|
} else {
|
|
464
|
-
log.debug(`${origin}: RESPONSE: ${JSON.stringify(returnFieldData)}`);
|
|
471
|
+
// log.debug(`${origin}: RESPONSE: ${JSON.stringify(returnFieldData)}`);
|
|
472
|
+
log.debug(`${origin}: RESPONSE KEY FOUND`);
|
|
465
473
|
}
|
|
466
474
|
|
|
467
475
|
// if the data is not an object - just return what it is
|
|
@@ -482,9 +490,11 @@ function handleRestRequest(request, entityId, entitySchema, callProperties, filt
|
|
|
482
490
|
|
|
483
491
|
if (Array.isArray(retResponse)) {
|
|
484
492
|
// if the response is an array, log the first item
|
|
485
|
-
log.debug(`${origin}: RESPONSE (FIRST): ${JSON.stringify(retResponse[0])}`);
|
|
493
|
+
// log.debug(`${origin}: RESPONSE (FIRST): ${JSON.stringify(retResponse[0])}`);
|
|
494
|
+
log.debug(`${origin}: RESPONSE NO KEY`);
|
|
486
495
|
} else {
|
|
487
|
-
log.debug(`${origin}: RESPONSE: ${JSON.stringify(retResponse)}`);
|
|
496
|
+
// log.debug(`${origin}: RESPONSE: ${JSON.stringify(retResponse)}`);
|
|
497
|
+
log.debug(`${origin}: RESPONSE NO KEY`);
|
|
488
498
|
}
|
|
489
499
|
|
|
490
500
|
// if the data is not an object - just return what it is
|
package/lib/throttle.js
CHANGED
|
@@ -51,7 +51,7 @@ let qlock = null;
|
|
|
51
51
|
*/
|
|
52
52
|
function getQueueItems(dbUI, collectionName, filter, callback) {
|
|
53
53
|
const origin = `${id}-throttle-getQueueItems`;
|
|
54
|
-
log.
|
|
54
|
+
log.trace(origin);
|
|
55
55
|
|
|
56
56
|
try {
|
|
57
57
|
let myFilter = filter;
|
|
@@ -164,7 +164,7 @@ function getQueueItems(dbUI, collectionName, filter, callback) {
|
|
|
164
164
|
*/
|
|
165
165
|
function claimTurn(dbUI, collectionName, queueItem, callback) {
|
|
166
166
|
const origin = `${id}-throttle-claimTurn`;
|
|
167
|
-
log.
|
|
167
|
+
log.trace(origin);
|
|
168
168
|
|
|
169
169
|
try {
|
|
170
170
|
const cur = new Date();
|
|
@@ -233,7 +233,7 @@ function claimTurn(dbUI, collectionName, queueItem, callback) {
|
|
|
233
233
|
*/
|
|
234
234
|
function freeQueueItem(dbUI, collectionName, queueItem, callback) {
|
|
235
235
|
const origin = `${id}-throttle-freeQueueItem`;
|
|
236
|
-
log.
|
|
236
|
+
log.trace(origin);
|
|
237
237
|
|
|
238
238
|
try {
|
|
239
239
|
// If the number of Pronghorns is greater than 1, the queue is in the database
|
|
@@ -277,6 +277,60 @@ function freeQueueItem(dbUI, collectionName, queueItem, callback) {
|
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
+
/*
|
|
281
|
+
* INTERNAL FUNCTION: freeMultipleQueueItem is used to free the turn from the given request.
|
|
282
|
+
* This is done by deleting the items from the database or removing them from the
|
|
283
|
+
* queue.
|
|
284
|
+
*/
|
|
285
|
+
function freeMultipleQueueItem(dbUI, collectionName, queueItems, callback) {
|
|
286
|
+
const origin = `${id}-throttle-freeMultipleQueueItem`;
|
|
287
|
+
log.trace(origin);
|
|
288
|
+
|
|
289
|
+
try {
|
|
290
|
+
// If the number of Pronghorns is greater than 1, the queue is in the database
|
|
291
|
+
if (numberPhs > 1) {
|
|
292
|
+
const idsToDelete = [];
|
|
293
|
+
for (let i = 0; i < queueItems.length; i += 1) {
|
|
294
|
+
idsToDelete.push(queueItems[i]._id);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// actual call to remove the requests from the queue in the database
|
|
298
|
+
// return MONGOQ.deleteOne({ _id: queueItem._id }, (error, result) => {
|
|
299
|
+
return dbUI.deleteMany(collectionName, { _id: { $in: idsToDelete } }, {}, false, null, false, (error, result) => {
|
|
300
|
+
if (error) {
|
|
301
|
+
const errorObj = transUtilInst.formatErrorObject(origin, 'Unable To Free Turn', [queueItems[0].request_id, queueItems[0].transNum, error], null, null, null);
|
|
302
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
303
|
+
return callback(null, errorObj);
|
|
304
|
+
}
|
|
305
|
+
return callback(result);
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// If the number of Pronghorns is 1, the queue is in memory
|
|
310
|
+
// Lock the memQueue while finding and removing the item
|
|
311
|
+
return qlock.acquire(memQlock, (done) => {
|
|
312
|
+
for (let i = 0; i < queueItems.length; i += 1) {
|
|
313
|
+
const index = memQueue.indexOf(queueItems[i]);
|
|
314
|
+
if (index >= 0) {
|
|
315
|
+
log.debug(`${origin}: Free Queue Item ${queueItems[i].request_id} - ${queueItems[i].transNum}`);
|
|
316
|
+
memQueue.splice(index, 1);
|
|
317
|
+
} else {
|
|
318
|
+
log.warn(`${origin}: Queue Item Not Found ${queueItems[i].request_id} - ${queueItems[i].transNum}: May have been already removed`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
done('finished removing items from queue');
|
|
323
|
+
}, (ret) => {
|
|
324
|
+
log.info(ret);
|
|
325
|
+
return callback(ret);
|
|
326
|
+
});
|
|
327
|
+
} catch (e) {
|
|
328
|
+
// handle any exception
|
|
329
|
+
const errorObj = transUtilInst.checkAndReturn(e, origin, 'Issue freeing queue items');
|
|
330
|
+
return callback(null, errorObj);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
280
334
|
/*
|
|
281
335
|
* INTERNAL FUNCTION: freeExpiredQueueItems goes through the current active usage to
|
|
282
336
|
* determine if any have finished running long enough ago that the turn has expired.
|
|
@@ -287,7 +341,7 @@ function freeQueueItem(dbUI, collectionName, queueItem, callback) {
|
|
|
287
341
|
*/
|
|
288
342
|
function freeExpiredQueueItems(callback) {
|
|
289
343
|
const origin = `${id}-throttle-freeExpiredQueueItems`;
|
|
290
|
-
log.
|
|
344
|
+
log.trace(origin);
|
|
291
345
|
|
|
292
346
|
try {
|
|
293
347
|
const status = 'success';
|
|
@@ -310,35 +364,31 @@ function freeExpiredQueueItems(callback) {
|
|
|
310
364
|
return callback(status);
|
|
311
365
|
}
|
|
312
366
|
|
|
313
|
-
|
|
314
|
-
|
|
367
|
+
const freelist = [];
|
|
315
368
|
// go through the queue items to see if any have expired
|
|
316
369
|
for (let i = 0; i < currentUse.length; i += 1) {
|
|
317
370
|
// if the transaction finished and the end + timeout is less than the current time
|
|
318
371
|
if (currentUse[i].end !== null
|
|
319
372
|
&& (Number(currentUse[i].end) + Number(expireTimeout) < cur.getTime())) {
|
|
320
|
-
|
|
321
|
-
if (ferror) {
|
|
322
|
-
return callback(null, ferror);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
handled += 1;
|
|
326
|
-
// when we have handled everything - return
|
|
327
|
-
if (handled === currentUse.length) {
|
|
328
|
-
log.spam(`${origin}: ${flic}`);
|
|
329
|
-
return callback(status);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
} else {
|
|
333
|
-
handled += 1;
|
|
334
|
-
}
|
|
335
|
-
// when we have handled everything - return
|
|
336
|
-
if (handled === currentUse.length) {
|
|
337
|
-
return callback(status);
|
|
373
|
+
freelist.push(currentUse[i]);
|
|
338
374
|
}
|
|
339
375
|
}
|
|
340
376
|
|
|
341
|
-
return
|
|
377
|
+
// if there is nothing to free just return
|
|
378
|
+
if (freelist.length === 0) {
|
|
379
|
+
log.info(`${origin}: Nothing to be freed`);
|
|
380
|
+
return callback(status);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return freeMultipleQueueItem(dbUtilInst, queueColl, freelist, (flic, ferror) => {
|
|
384
|
+
if (ferror) {
|
|
385
|
+
log.warn(`Error received on FreeQueueItem: ${JSON.stringify(ferror)}`);
|
|
386
|
+
return callback(null, ferror);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
log.info(`${origin}: Expired Queue Item Freed: ${flic}`);
|
|
390
|
+
return callback(status);
|
|
391
|
+
});
|
|
342
392
|
});
|
|
343
393
|
} catch (e) {
|
|
344
394
|
// handle any exception
|
|
@@ -354,7 +404,7 @@ function freeExpiredQueueItems(callback) {
|
|
|
354
404
|
*/
|
|
355
405
|
function checkTurnAvailable(myRequest, myTransNum, callback) {
|
|
356
406
|
const origin = `${id}-throttle-checkTurnAvailable`;
|
|
357
|
-
log.
|
|
407
|
+
log.trace(origin);
|
|
358
408
|
|
|
359
409
|
try {
|
|
360
410
|
return freeExpiredQueueItems((freeRes, ferror) => {
|
|
@@ -362,7 +412,7 @@ function checkTurnAvailable(myRequest, myTransNum, callback) {
|
|
|
362
412
|
return callback(null, ferror);
|
|
363
413
|
}
|
|
364
414
|
|
|
365
|
-
log.
|
|
415
|
+
log.trace(`${origin}: ${freeRes}`);
|
|
366
416
|
|
|
367
417
|
// only want to set filter if using DB - if memory want the entire queue so we get all priorities
|
|
368
418
|
let useFilter = null;
|
|
@@ -438,7 +488,7 @@ function checkTurnAvailable(myRequest, myTransNum, callback) {
|
|
|
438
488
|
*/
|
|
439
489
|
function gettingCloseInterval(myRequest, transNum, callback) {
|
|
440
490
|
const origin = `${id}-throttle-gettingCloseInterval`;
|
|
441
|
-
log.
|
|
491
|
+
log.trace(origin);
|
|
442
492
|
|
|
443
493
|
try {
|
|
444
494
|
let intRun = false;
|
|
@@ -648,7 +698,7 @@ class SystemXThrottle {
|
|
|
648
698
|
|
|
649
699
|
// Connection URL
|
|
650
700
|
let murl = prongo.properties.url;
|
|
651
|
-
log.
|
|
701
|
+
log.trace(`${origin}: ${murl}`);
|
|
652
702
|
const dbName = prongo.properties.db;
|
|
653
703
|
|
|
654
704
|
// define some local variables to help in validating the properties.json file
|
|
@@ -1117,7 +1167,7 @@ class SystemXThrottle {
|
|
|
1117
1167
|
return callback(null, gerror);
|
|
1118
1168
|
}
|
|
1119
1169
|
|
|
1120
|
-
log.
|
|
1170
|
+
log.trace(`${origin}: ${waitEnd}`);
|
|
1121
1171
|
return claimTurn(this.dbUtil, queueColl, queueItem, callback);
|
|
1122
1172
|
});
|
|
1123
1173
|
}
|