@itentialopensource/adapter-meraki 0.7.2 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- package/AUTH.md +40 -0
- package/CALLS.md +100 -0
- package/CHANGELOG.md +24 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +247 -0
- package/README.md +113 -470
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +911 -64
- package/adapterBase.js +294 -271
- package/entities/.generic/action.json +5 -5
- package/error.json +12 -0
- package/package.json +18 -13
- package/pronghorn.json +289 -104
- package/propertiesSchema.json +238 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1642739939352.json +95 -0
- package/sampleProperties.json +4 -1
- package/test/integration/adapterTestBasicGet.js +1 -1
- package/test/integration/adapterTestIntegration.js +11 -2
- package/test/unit/adapterBaseTestUnit.js +27 -26
- package/test/unit/adapterTestUnit.js +632 -11
- package/utils/addAuth.js +94 -0
- package/utils/basicGet.js +1 -14
- package/utils/entitiesToDB.js +224 -0
- package/utils/modify.js +1 -1
- package/utils/packModificationScript.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +14 -8
- package/utils/tbUtils.js +98 -19
- package/utils/troubleshootingAdapter.js +2 -26
package/adapterBase.js
CHANGED
@@ -22,6 +22,7 @@ const AjvCl = require('ajv');
|
|
22
22
|
const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
|
23
23
|
const RequestHandlerCl = require('@itentialopensource/adapter-utils').RequestHandler;
|
24
24
|
|
25
|
+
const entitiesToDB = require(path.join(__dirname, 'utils/entitiesToDB'));
|
25
26
|
const troubleshootingAdapter = require(path.join(__dirname, 'utils/troubleshootingAdapter'));
|
26
27
|
const tbUtils = require(path.join(__dirname, 'utils/tbUtils'));
|
27
28
|
|
@@ -276,129 +277,6 @@ class AdapterBase extends EventEmitterCl {
|
|
276
277
|
}
|
277
278
|
}
|
278
279
|
|
279
|
-
/**
|
280
|
-
* updateAdapterConfiguration is used to update any of the adapter configuration files. This
|
281
|
-
* allows customers to make changes to adapter configuration without having to be on the
|
282
|
-
* file system.
|
283
|
-
*
|
284
|
-
* @function updateAdapterConfiguration
|
285
|
-
* @param {string} configFile - the name of the file being updated (required)
|
286
|
-
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
287
|
-
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
288
|
-
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
289
|
-
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
290
|
-
* @param {Callback} callback - The results of the call
|
291
|
-
*/
|
292
|
-
updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
293
|
-
const meth = 'adapterBase-updateAdapterConfiguration';
|
294
|
-
const origin = `${this.id}-${meth}`;
|
295
|
-
log.trace(origin);
|
296
|
-
|
297
|
-
// verify the parameters are valid
|
298
|
-
if (changes === undefined || changes === null || typeof changes !== 'object'
|
299
|
-
|| Object.keys(changes).length === 0) {
|
300
|
-
const result = {
|
301
|
-
response: 'No configuration updates to make'
|
302
|
-
};
|
303
|
-
log.info(result.response);
|
304
|
-
return callback(result, null);
|
305
|
-
}
|
306
|
-
if (configFile === undefined || configFile === null || configFile === '') {
|
307
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
308
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
309
|
-
return callback(null, errorObj);
|
310
|
-
}
|
311
|
-
|
312
|
-
// take action based on configFile being changed
|
313
|
-
if (configFile === 'package.json') {
|
314
|
-
const pres = updatePackage(changes);
|
315
|
-
if (pres) {
|
316
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
317
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
318
|
-
return callback(null, errorObj);
|
319
|
-
}
|
320
|
-
const result = {
|
321
|
-
response: 'Package updates completed - restarting adapter'
|
322
|
-
};
|
323
|
-
log.info(result.response);
|
324
|
-
forceFail(true);
|
325
|
-
return callback(result, null);
|
326
|
-
}
|
327
|
-
if (entity === undefined || entity === null || entity === '') {
|
328
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
329
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
330
|
-
return callback(null, errorObj);
|
331
|
-
}
|
332
|
-
|
333
|
-
// this means we are changing an entity file so type is required
|
334
|
-
if (type === undefined || type === null || type === '') {
|
335
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
336
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
337
|
-
return callback(null, errorObj);
|
338
|
-
}
|
339
|
-
|
340
|
-
// if the entity does not exist - error
|
341
|
-
const epath = `${__dirname}/entities/${entity}`;
|
342
|
-
if (!fs.existsSync(epath)) {
|
343
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
344
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
345
|
-
return callback(null, errorObj);
|
346
|
-
}
|
347
|
-
|
348
|
-
// take action based on type of file being changed
|
349
|
-
if (type === 'action') {
|
350
|
-
// BACKUP???
|
351
|
-
const ares = updateAction(epath, action, changes);
|
352
|
-
if (ares) {
|
353
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
354
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
355
|
-
return callback(null, errorObj);
|
356
|
-
}
|
357
|
-
// AJV CHECK???
|
358
|
-
// RESTORE IF NEEDED???
|
359
|
-
const result = {
|
360
|
-
response: `Action updates completed to entity: ${entity} - ${action}`
|
361
|
-
};
|
362
|
-
log.info(result.response);
|
363
|
-
return callback(result, null);
|
364
|
-
}
|
365
|
-
if (type === 'schema') {
|
366
|
-
const sres = updateSchema(epath, configFile, changes);
|
367
|
-
if (sres) {
|
368
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
369
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
370
|
-
return callback(null, errorObj);
|
371
|
-
}
|
372
|
-
const result = {
|
373
|
-
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
374
|
-
};
|
375
|
-
log.info(result.response);
|
376
|
-
return callback(result, null);
|
377
|
-
}
|
378
|
-
if (type === 'mock') {
|
379
|
-
// if the mock directory does not exist - error
|
380
|
-
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
381
|
-
if (!fs.existsSync(mpath)) {
|
382
|
-
fs.mkdirSync(mpath);
|
383
|
-
}
|
384
|
-
|
385
|
-
const mres = updateMock(mpath, configFile, changes);
|
386
|
-
if (mres) {
|
387
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
388
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
389
|
-
return callback(null, errorObj);
|
390
|
-
}
|
391
|
-
const result = {
|
392
|
-
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
393
|
-
};
|
394
|
-
log.info(result.response);
|
395
|
-
return callback(result, null);
|
396
|
-
}
|
397
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
398
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
399
|
-
return callback(null, errorObj);
|
400
|
-
}
|
401
|
-
|
402
280
|
/**
|
403
281
|
* @summary Connect function is used during Pronghorn startup to provide instantiation feedback.
|
404
282
|
*
|
@@ -467,7 +345,7 @@ class AdapterBase extends EventEmitterCl {
|
|
467
345
|
}
|
468
346
|
|
469
347
|
// call to the healthcheck in connector
|
470
|
-
return this.requestHandlerInst.identifyHealthcheck(
|
348
|
+
return this.requestHandlerInst.identifyHealthcheck(myRequest, (res, error) => {
|
471
349
|
// unhealthy
|
472
350
|
if (error) {
|
473
351
|
// if we were healthy, toggle health
|
@@ -500,98 +378,12 @@ class AdapterBase extends EventEmitterCl {
|
|
500
378
|
}
|
501
379
|
|
502
380
|
/**
|
503
|
-
*
|
504
|
-
* @param {Callback} callback - The adapater suspension status
|
505
|
-
* @function suspend
|
506
|
-
*/
|
507
|
-
suspend(mode, callback) {
|
508
|
-
const origin = `${this.id}-adapterBase-suspend`;
|
509
|
-
if (this.suspended) {
|
510
|
-
throw new Error(`${origin}: Adapter is already suspended`);
|
511
|
-
}
|
512
|
-
try {
|
513
|
-
this.suspended = true;
|
514
|
-
this.suspendMode = mode;
|
515
|
-
if (this.suspendMode === 'pause') {
|
516
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
517
|
-
// To suspend adapter, enable throttling and set concurrent max to 0
|
518
|
-
props.throttle.throttle_enabled = true;
|
519
|
-
props.throttle.concurrent_max = 0;
|
520
|
-
this.refreshProperties(props);
|
521
|
-
}
|
522
|
-
return callback({ suspended: true });
|
523
|
-
} catch (error) {
|
524
|
-
return callback(null, error);
|
525
|
-
}
|
526
|
-
}
|
527
|
-
|
528
|
-
/**
|
529
|
-
* @summary Unsuspends the adapter
|
530
|
-
* @param {Callback} callback - The adapater suspension status
|
531
|
-
*
|
532
|
-
* @function unsuspend
|
533
|
-
*/
|
534
|
-
unsuspend(callback) {
|
535
|
-
const origin = `${this.id}-adapterBase-unsuspend`;
|
536
|
-
if (!this.suspended) {
|
537
|
-
throw new Error(`${origin}: Adapter is not suspended`);
|
538
|
-
}
|
539
|
-
if (this.suspendMode === 'pause') {
|
540
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
541
|
-
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
542
|
-
props.throttle.throttle_enabled = true;
|
543
|
-
props.throttle.concurrent_max = 1;
|
544
|
-
this.refreshProperties(props);
|
545
|
-
setTimeout(() => {
|
546
|
-
this.getQueue((q, error) => {
|
547
|
-
// console.log("Items in queue: " + String(q.length))
|
548
|
-
if (q.length === 0) {
|
549
|
-
// if queue is empty, return to initial properties state
|
550
|
-
this.refreshProperties(this.initProps);
|
551
|
-
this.suspended = false;
|
552
|
-
return callback({ suspended: false });
|
553
|
-
}
|
554
|
-
// recursive call to check queue again every second
|
555
|
-
return this.unsuspend(callback);
|
556
|
-
});
|
557
|
-
}, 1000);
|
558
|
-
} else {
|
559
|
-
this.suspended = false;
|
560
|
-
callback({ suspend: false });
|
561
|
-
}
|
562
|
-
}
|
563
|
-
|
564
|
-
/**
|
565
|
-
* getAllFunctions is used to get all of the exposed function in the adapter
|
566
|
-
*
|
567
|
-
* @function getAllFunctions
|
568
|
-
*/
|
569
|
-
getAllFunctions() {
|
570
|
-
let myfunctions = [];
|
571
|
-
let obj = this;
|
572
|
-
|
573
|
-
// find the functions in this class
|
574
|
-
do {
|
575
|
-
const l = Object.getOwnPropertyNames(obj)
|
576
|
-
.concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString()))
|
577
|
-
.sort()
|
578
|
-
.filter((p, i, arr) => typeof obj[p] === 'function' && p !== 'constructor' && (i === 0 || p !== arr[i - 1]) && myfunctions.indexOf(p) === -1);
|
579
|
-
myfunctions = myfunctions.concat(l);
|
580
|
-
}
|
581
|
-
while (
|
582
|
-
(obj = Object.getPrototypeOf(obj)) && Object.getPrototypeOf(obj)
|
583
|
-
);
|
584
|
-
|
585
|
-
return myfunctions;
|
586
|
-
}
|
587
|
-
|
588
|
-
/**
|
589
|
-
* getWorkflowFunctions is used to get all of the workflow function in the adapter
|
381
|
+
* iapGetAdapterWorkflowFunctions is used to get all of the workflow function in the adapter
|
590
382
|
* @param {array} ignoreThese - additional methods to ignore (optional)
|
591
383
|
*
|
592
|
-
* @function
|
384
|
+
* @function iapGetAdapterWorkflowFunctions
|
593
385
|
*/
|
594
|
-
|
386
|
+
iapGetAdapterWorkflowFunctions(ignoreThese) {
|
595
387
|
const myfunctions = this.getAllFunctions();
|
596
388
|
const wffunctions = [];
|
597
389
|
|
@@ -601,8 +393,9 @@ class AdapterBase extends EventEmitterCl {
|
|
601
393
|
// got to the second tier (adapterBase)
|
602
394
|
break;
|
603
395
|
}
|
604
|
-
if (myfunctions[m] !== '
|
605
|
-
&& myfunctions[m] !== '
|
396
|
+
if (myfunctions[m] !== 'iapHasAdapterEntity' && myfunctions[m] !== 'iapVerifyAdapterCapability'
|
397
|
+
&& myfunctions[m] !== 'iapUpdateAdapterEntityCache' && myfunctions[m] !== 'healthCheck'
|
398
|
+
&& myfunctions[m] !== 'iapGetAdapterWorkflowFunctions'
|
606
399
|
&& !(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
|
607
400
|
let found = false;
|
608
401
|
if (ignoreThese && Array.isArray(ignoreThese)) {
|
@@ -622,30 +415,136 @@ class AdapterBase extends EventEmitterCl {
|
|
622
415
|
}
|
623
416
|
|
624
417
|
/**
|
625
|
-
*
|
418
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
419
|
+
* allows customers to make changes to adapter configuration without having to be on the
|
420
|
+
* file system.
|
626
421
|
*
|
627
|
-
* @function
|
422
|
+
* @function iapUpdateAdapterConfiguration
|
423
|
+
* @param {string} configFile - the name of the file being updated (required)
|
424
|
+
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
425
|
+
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
426
|
+
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
427
|
+
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
428
|
+
* @param {Callback} callback - The results of the call
|
628
429
|
*/
|
629
|
-
|
630
|
-
const
|
430
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
431
|
+
const meth = 'adapterBase-iapUpdateAdapterConfiguration';
|
432
|
+
const origin = `${this.id}-${meth}`;
|
631
433
|
log.trace(origin);
|
632
434
|
|
633
|
-
//
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
435
|
+
// verify the parameters are valid
|
436
|
+
if (changes === undefined || changes === null || typeof changes !== 'object'
|
437
|
+
|| Object.keys(changes).length === 0) {
|
438
|
+
const result = {
|
439
|
+
response: 'No configuration updates to make'
|
440
|
+
};
|
441
|
+
log.info(result.response);
|
442
|
+
return callback(result, null);
|
443
|
+
}
|
444
|
+
if (configFile === undefined || configFile === null || configFile === '') {
|
445
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
446
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
447
|
+
return callback(null, errorObj);
|
638
448
|
}
|
449
|
+
|
450
|
+
// take action based on configFile being changed
|
451
|
+
if (configFile === 'package.json') {
|
452
|
+
const pres = updatePackage(changes);
|
453
|
+
if (pres) {
|
454
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
455
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
456
|
+
return callback(null, errorObj);
|
457
|
+
}
|
458
|
+
const result = {
|
459
|
+
response: 'Package updates completed - restarting adapter'
|
460
|
+
};
|
461
|
+
log.info(result.response);
|
462
|
+
forceFail(true);
|
463
|
+
return callback(result, null);
|
464
|
+
}
|
465
|
+
if (entity === undefined || entity === null || entity === '') {
|
466
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
467
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
468
|
+
return callback(null, errorObj);
|
469
|
+
}
|
470
|
+
|
471
|
+
// this means we are changing an entity file so type is required
|
472
|
+
if (type === undefined || type === null || type === '') {
|
473
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
474
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
475
|
+
return callback(null, errorObj);
|
476
|
+
}
|
477
|
+
|
478
|
+
// if the entity does not exist - error
|
479
|
+
const epath = `${__dirname}/entities/${entity}`;
|
480
|
+
if (!fs.existsSync(epath)) {
|
481
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
482
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
483
|
+
return callback(null, errorObj);
|
484
|
+
}
|
485
|
+
|
486
|
+
// take action based on type of file being changed
|
487
|
+
if (type === 'action') {
|
488
|
+
// BACKUP???
|
489
|
+
const ares = updateAction(epath, action, changes);
|
490
|
+
if (ares) {
|
491
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
492
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
493
|
+
return callback(null, errorObj);
|
494
|
+
}
|
495
|
+
// AJV CHECK???
|
496
|
+
// RESTORE IF NEEDED???
|
497
|
+
const result = {
|
498
|
+
response: `Action updates completed to entity: ${entity} - ${action}`
|
499
|
+
};
|
500
|
+
log.info(result.response);
|
501
|
+
return callback(result, null);
|
502
|
+
}
|
503
|
+
if (type === 'schema') {
|
504
|
+
const sres = updateSchema(epath, configFile, changes);
|
505
|
+
if (sres) {
|
506
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
507
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
508
|
+
return callback(null, errorObj);
|
509
|
+
}
|
510
|
+
const result = {
|
511
|
+
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
512
|
+
};
|
513
|
+
log.info(result.response);
|
514
|
+
return callback(result, null);
|
515
|
+
}
|
516
|
+
if (type === 'mock') {
|
517
|
+
// if the mock directory does not exist - error
|
518
|
+
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
519
|
+
if (!fs.existsSync(mpath)) {
|
520
|
+
fs.mkdirSync(mpath);
|
521
|
+
}
|
522
|
+
|
523
|
+
const mres = updateMock(mpath, configFile, changes);
|
524
|
+
if (mres) {
|
525
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
526
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
527
|
+
return callback(null, errorObj);
|
528
|
+
}
|
529
|
+
const result = {
|
530
|
+
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
531
|
+
};
|
532
|
+
log.info(result.response);
|
533
|
+
return callback(result, null);
|
534
|
+
}
|
535
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
536
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
537
|
+
return callback(null, errorObj);
|
639
538
|
}
|
640
539
|
|
641
540
|
/**
|
642
541
|
* See if the API path provided is found in this adapter
|
643
542
|
*
|
644
|
-
* @function
|
543
|
+
* @function iapFindAdapterPath
|
645
544
|
* @param {string} apiPath - the api path to check on
|
646
545
|
* @param {Callback} callback - The results of the call
|
647
546
|
*/
|
648
|
-
|
547
|
+
iapFindAdapterPath(apiPath, callback) {
|
649
548
|
const result = {
|
650
549
|
apiPath
|
651
550
|
};
|
@@ -687,7 +586,7 @@ class AdapterBase extends EventEmitterCl {
|
|
687
586
|
log.info(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
|
688
587
|
const fitem = {
|
689
588
|
entity: entities[e],
|
690
|
-
action: actions[a].name,
|
589
|
+
action: actions.actions[a].name,
|
691
590
|
method: actions.actions[a].method,
|
692
591
|
path: actions.actions[a].entitypath
|
693
592
|
};
|
@@ -722,66 +621,90 @@ class AdapterBase extends EventEmitterCl {
|
|
722
621
|
}
|
723
622
|
|
724
623
|
/**
|
725
|
-
*
|
726
|
-
*
|
727
|
-
* @function
|
728
|
-
* @param {Object} properties - an object containing all of the properties
|
624
|
+
* @summary Suspends the adapter
|
625
|
+
* @param {Callback} callback - The adapater suspension status
|
626
|
+
* @function iapSuspendAdapter
|
729
627
|
*/
|
730
|
-
|
731
|
-
const origin = `${this.
|
732
|
-
|
733
|
-
|
734
|
-
|
628
|
+
iapSuspendAdapter(mode, callback) {
|
629
|
+
const origin = `${this.id}-adapterBase-iapSuspendAdapter`;
|
630
|
+
if (this.suspended) {
|
631
|
+
throw new Error(`${origin}: Adapter is already suspended`);
|
632
|
+
}
|
735
633
|
try {
|
736
|
-
|
737
|
-
|
738
|
-
|
634
|
+
this.suspended = true;
|
635
|
+
this.suspendMode = mode;
|
636
|
+
if (this.suspendMode === 'pause') {
|
637
|
+
const props = JSON.parse(JSON.stringify(this.initProps));
|
638
|
+
// To suspend adapter, enable throttling and set concurrent max to 0
|
639
|
+
props.throttle.throttle_enabled = true;
|
640
|
+
props.throttle.concurrent_max = 0;
|
641
|
+
this.refreshProperties(props);
|
642
|
+
}
|
643
|
+
return callback({ suspended: true });
|
644
|
+
} catch (error) {
|
645
|
+
return callback(null, error);
|
739
646
|
}
|
740
647
|
}
|
741
648
|
|
742
649
|
/**
|
743
|
-
*
|
650
|
+
* @summary Unsuspends the adapter
|
651
|
+
* @param {Callback} callback - The adapater suspension status
|
744
652
|
*
|
745
|
-
* @function
|
746
|
-
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
653
|
+
* @function iapUnsuspendAdapter
|
747
654
|
*/
|
748
|
-
|
749
|
-
const origin = `${this.id}-adapterBase-
|
750
|
-
|
751
|
-
|
752
|
-
|
655
|
+
iapUnsuspendAdapter(callback) {
|
656
|
+
const origin = `${this.id}-adapterBase-iapUnsuspendAdapter`;
|
657
|
+
if (!this.suspended) {
|
658
|
+
throw new Error(`${origin}: Adapter is not suspended`);
|
659
|
+
}
|
660
|
+
if (this.suspendMode === 'pause') {
|
661
|
+
const props = JSON.parse(JSON.stringify(this.initProps));
|
662
|
+
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
663
|
+
props.throttle.throttle_enabled = true;
|
664
|
+
props.throttle.concurrent_max = 1;
|
665
|
+
this.refreshProperties(props);
|
666
|
+
setTimeout(() => {
|
667
|
+
this.getQueue((q, error) => {
|
668
|
+
// console.log("Items in queue: " + String(q.length))
|
669
|
+
if (q.length === 0) {
|
670
|
+
// if queue is empty, return to initial properties state
|
671
|
+
this.refreshProperties(this.initProps);
|
672
|
+
this.suspended = false;
|
673
|
+
return callback({ suspended: false });
|
674
|
+
}
|
675
|
+
// recursive call to check queue again every second
|
676
|
+
return this.iapUnsuspendAdapter(callback);
|
677
|
+
});
|
678
|
+
}, 1000);
|
679
|
+
} else {
|
680
|
+
this.suspended = false;
|
681
|
+
callback({ suspend: false });
|
682
|
+
}
|
753
683
|
}
|
754
684
|
|
755
685
|
/**
|
756
|
-
*
|
757
|
-
* encoded/encrypted string
|
686
|
+
* iapGetAdapterQueue is used to get information for all of the requests currently in the queue.
|
758
687
|
*
|
759
|
-
* @function
|
760
|
-
* @param {
|
761
|
-
* @param {String} technique - the technique to use to encrypt
|
762
|
-
*
|
763
|
-
* @param {Callback} callback - a callback function to return the result
|
764
|
-
* Encrypted String or the Error
|
688
|
+
* @function iapGetAdapterQueue
|
689
|
+
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
765
690
|
*/
|
766
|
-
|
767
|
-
const origin = `${this.id}-adapterBase-
|
691
|
+
iapGetAdapterQueue(callback) {
|
692
|
+
const origin = `${this.id}-adapterBase-iapGetAdapterQueue`;
|
768
693
|
log.trace(origin);
|
769
694
|
|
770
|
-
|
771
|
-
// encryptProperty(property, technique, callback)
|
772
|
-
return this.requestHandlerInst.encryptProperty(property, technique, callback);
|
695
|
+
return this.requestHandlerInst.getQueue(callback);
|
773
696
|
}
|
774
697
|
|
775
698
|
/**
|
776
699
|
* @summary runs troubleshoot scripts for adapter
|
777
700
|
*
|
778
|
-
* @function
|
701
|
+
* @function iapTroubleshootAdapter
|
779
702
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
780
703
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
781
704
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
782
705
|
* @param {Callback} callback - callback function to return troubleshoot results
|
783
706
|
*/
|
784
|
-
async
|
707
|
+
async iapTroubleshootAdapter(props, persistFlag, adapter, callback) {
|
785
708
|
try {
|
786
709
|
const result = await troubleshootingAdapter.troubleshoot(props, false, persistFlag, adapter);
|
787
710
|
if (result.healthCheck && result.connectivity.failCount === 0 && result.basicGet.failCount === 0) {
|
@@ -796,11 +719,11 @@ class AdapterBase extends EventEmitterCl {
|
|
796
719
|
/**
|
797
720
|
* @summary runs healthcheck script for adapter
|
798
721
|
*
|
799
|
-
* @function
|
722
|
+
* @function iapRunAdapterHealthcheck
|
800
723
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
801
724
|
* @param {Callback} callback - callback function to return healthcheck status
|
802
725
|
*/
|
803
|
-
async
|
726
|
+
async iapRunAdapterHealthcheck(adapter, callback) {
|
804
727
|
try {
|
805
728
|
const result = await tbUtils.healthCheck(adapter);
|
806
729
|
if (result) {
|
@@ -815,15 +738,15 @@ class AdapterBase extends EventEmitterCl {
|
|
815
738
|
/**
|
816
739
|
* @summary runs connectivity check script for adapter
|
817
740
|
*
|
818
|
-
* @function
|
741
|
+
* @function iapRunAdapterConnectivity
|
819
742
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
820
743
|
* @param {Callback} callback - callback function to return connectivity status
|
821
744
|
*/
|
822
|
-
async
|
745
|
+
async iapRunAdapterConnectivity(callback) {
|
823
746
|
try {
|
824
|
-
const { serviceItem } = await
|
747
|
+
const { serviceItem } = await tbUtils.getAdapterConfig();
|
825
748
|
const { host } = serviceItem.properties.properties;
|
826
|
-
const result = tbUtils.
|
749
|
+
const result = tbUtils.iapRunAdapterConnectivity(host, false);
|
827
750
|
if (result.failCount > 0) {
|
828
751
|
return callback(null, result);
|
829
752
|
}
|
@@ -836,12 +759,12 @@ class AdapterBase extends EventEmitterCl {
|
|
836
759
|
/**
|
837
760
|
* @summary runs basicGet script for adapter
|
838
761
|
*
|
839
|
-
* @function
|
762
|
+
* @function iapRunAdapterBasicGet
|
840
763
|
* @param {Callback} callback - callback function to return basicGet result
|
841
764
|
*/
|
842
|
-
|
765
|
+
iapRunAdapterBasicGet(callback) {
|
843
766
|
try {
|
844
|
-
const result = tbUtils.
|
767
|
+
const result = tbUtils.iapRunAdapterBasicGet(false);
|
845
768
|
if (result.failCount > 0) {
|
846
769
|
return callback(null, result);
|
847
770
|
}
|
@@ -851,6 +774,106 @@ class AdapterBase extends EventEmitterCl {
|
|
851
774
|
}
|
852
775
|
}
|
853
776
|
|
777
|
+
/**
|
778
|
+
* @summary moves entities to mongo database
|
779
|
+
*
|
780
|
+
* @function iapMoveAdapterEntitiesToDB
|
781
|
+
*
|
782
|
+
* @return {Callback} - containing the response from the mongo transaction
|
783
|
+
*/
|
784
|
+
iapMoveAdapterEntitiesToDB(callback) {
|
785
|
+
const meth = 'adapterBase-iapMoveAdapterEntitiesToDB';
|
786
|
+
const origin = `${this.id}-${meth}`;
|
787
|
+
log.trace(origin);
|
788
|
+
|
789
|
+
try {
|
790
|
+
return callback(entitiesToDB.iapMoveAdapterEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
|
791
|
+
} catch (err) {
|
792
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
|
793
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
794
|
+
return callback(null, errorObj);
|
795
|
+
}
|
796
|
+
}
|
797
|
+
|
798
|
+
/**
|
799
|
+
* getAllFunctions is used to get all of the exposed function in the adapter
|
800
|
+
*
|
801
|
+
* @function getAllFunctions
|
802
|
+
*/
|
803
|
+
getAllFunctions() {
|
804
|
+
let myfunctions = [];
|
805
|
+
let obj = this;
|
806
|
+
|
807
|
+
// find the functions in this class
|
808
|
+
do {
|
809
|
+
const l = Object.getOwnPropertyNames(obj)
|
810
|
+
.concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString()))
|
811
|
+
.sort()
|
812
|
+
.filter((p, i, arr) => typeof obj[p] === 'function' && p !== 'constructor' && (i === 0 || p !== arr[i - 1]) && myfunctions.indexOf(p) === -1);
|
813
|
+
myfunctions = myfunctions.concat(l);
|
814
|
+
}
|
815
|
+
while (
|
816
|
+
(obj = Object.getPrototypeOf(obj)) && Object.getPrototypeOf(obj)
|
817
|
+
);
|
818
|
+
|
819
|
+
return myfunctions;
|
820
|
+
}
|
821
|
+
|
822
|
+
/**
|
823
|
+
* checkActionFiles is used to update the validation of the action files.
|
824
|
+
*
|
825
|
+
* @function checkActionFiles
|
826
|
+
*/
|
827
|
+
checkActionFiles() {
|
828
|
+
const origin = `${this.id}-adapterBase-checkActionFiles`;
|
829
|
+
log.trace(origin);
|
830
|
+
|
831
|
+
// validate the action files for the adapter
|
832
|
+
try {
|
833
|
+
return this.requestHandlerInst.checkActionFiles();
|
834
|
+
} catch (e) {
|
835
|
+
return ['Exception increase log level'];
|
836
|
+
}
|
837
|
+
}
|
838
|
+
|
839
|
+
/**
|
840
|
+
* checkProperties is used to validate the adapter properties.
|
841
|
+
*
|
842
|
+
* @function checkProperties
|
843
|
+
* @param {Object} properties - an object containing all of the properties
|
844
|
+
*/
|
845
|
+
checkProperties(properties) {
|
846
|
+
const origin = `${this.myid}-adapterBase-checkProperties`;
|
847
|
+
log.trace(origin);
|
848
|
+
|
849
|
+
// validate the properties for the adapter
|
850
|
+
try {
|
851
|
+
return this.requestHandlerInst.checkProperties(properties);
|
852
|
+
} catch (e) {
|
853
|
+
return { exception: 'Exception increase log level' };
|
854
|
+
}
|
855
|
+
}
|
856
|
+
|
857
|
+
/**
|
858
|
+
* @summary Takes in property text and an encoding/encryption and returns the resulting
|
859
|
+
* encoded/encrypted string
|
860
|
+
*
|
861
|
+
* @function encryptProperty
|
862
|
+
* @param {String} property - the property to encrypt
|
863
|
+
* @param {String} technique - the technique to use to encrypt
|
864
|
+
*
|
865
|
+
* @param {Callback} callback - a callback function to return the result
|
866
|
+
* Encrypted String or the Error
|
867
|
+
*/
|
868
|
+
encryptProperty(property, technique, callback) {
|
869
|
+
const origin = `${this.id}-adapterBase-encryptProperty`;
|
870
|
+
log.trace(origin);
|
871
|
+
|
872
|
+
// Make the call -
|
873
|
+
// encryptProperty(property, technique, callback)
|
874
|
+
return this.requestHandlerInst.encryptProperty(property, technique, callback);
|
875
|
+
}
|
876
|
+
|
854
877
|
/**
|
855
878
|
* @summary take the entities and add them to the cache
|
856
879
|
*
|