@itentialopensource/adapter-meraki 0.8.0 → 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 +8 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +247 -0
- package/README.md +112 -542
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +583 -204
- package/adapterBase.js +291 -290
- package/error.json +6 -0
- package/package.json +1 -1
- package/pronghorn.json +106 -113
- package/propertiesSchema.json +223 -0
- package/refs?service=git-upload-pack +0 -0
- package/test/integration/adapterTestIntegration.js +1 -0
- package/test/unit/adapterBaseTestUnit.js +22 -24
- package/test/unit/adapterTestUnit.js +57 -51
package/adapterBase.js
CHANGED
@@ -277,129 +277,6 @@ class AdapterBase extends EventEmitterCl {
|
|
277
277
|
}
|
278
278
|
}
|
279
279
|
|
280
|
-
/**
|
281
|
-
* updateAdapterConfiguration is used to update any of the adapter configuration files. This
|
282
|
-
* allows customers to make changes to adapter configuration without having to be on the
|
283
|
-
* file system.
|
284
|
-
*
|
285
|
-
* @function updateAdapterConfiguration
|
286
|
-
* @param {string} configFile - the name of the file being updated (required)
|
287
|
-
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
288
|
-
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
289
|
-
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
290
|
-
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
291
|
-
* @param {Callback} callback - The results of the call
|
292
|
-
*/
|
293
|
-
updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
294
|
-
const meth = 'adapterBase-updateAdapterConfiguration';
|
295
|
-
const origin = `${this.id}-${meth}`;
|
296
|
-
log.trace(origin);
|
297
|
-
|
298
|
-
// verify the parameters are valid
|
299
|
-
if (changes === undefined || changes === null || typeof changes !== 'object'
|
300
|
-
|| Object.keys(changes).length === 0) {
|
301
|
-
const result = {
|
302
|
-
response: 'No configuration updates to make'
|
303
|
-
};
|
304
|
-
log.info(result.response);
|
305
|
-
return callback(result, null);
|
306
|
-
}
|
307
|
-
if (configFile === undefined || configFile === null || configFile === '') {
|
308
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
309
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
310
|
-
return callback(null, errorObj);
|
311
|
-
}
|
312
|
-
|
313
|
-
// take action based on configFile being changed
|
314
|
-
if (configFile === 'package.json') {
|
315
|
-
const pres = updatePackage(changes);
|
316
|
-
if (pres) {
|
317
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
318
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
319
|
-
return callback(null, errorObj);
|
320
|
-
}
|
321
|
-
const result = {
|
322
|
-
response: 'Package updates completed - restarting adapter'
|
323
|
-
};
|
324
|
-
log.info(result.response);
|
325
|
-
forceFail(true);
|
326
|
-
return callback(result, null);
|
327
|
-
}
|
328
|
-
if (entity === undefined || entity === null || entity === '') {
|
329
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
330
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
331
|
-
return callback(null, errorObj);
|
332
|
-
}
|
333
|
-
|
334
|
-
// this means we are changing an entity file so type is required
|
335
|
-
if (type === undefined || type === null || type === '') {
|
336
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
337
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
338
|
-
return callback(null, errorObj);
|
339
|
-
}
|
340
|
-
|
341
|
-
// if the entity does not exist - error
|
342
|
-
const epath = `${__dirname}/entities/${entity}`;
|
343
|
-
if (!fs.existsSync(epath)) {
|
344
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
345
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
346
|
-
return callback(null, errorObj);
|
347
|
-
}
|
348
|
-
|
349
|
-
// take action based on type of file being changed
|
350
|
-
if (type === 'action') {
|
351
|
-
// BACKUP???
|
352
|
-
const ares = updateAction(epath, action, changes);
|
353
|
-
if (ares) {
|
354
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
355
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
356
|
-
return callback(null, errorObj);
|
357
|
-
}
|
358
|
-
// AJV CHECK???
|
359
|
-
// RESTORE IF NEEDED???
|
360
|
-
const result = {
|
361
|
-
response: `Action updates completed to entity: ${entity} - ${action}`
|
362
|
-
};
|
363
|
-
log.info(result.response);
|
364
|
-
return callback(result, null);
|
365
|
-
}
|
366
|
-
if (type === 'schema') {
|
367
|
-
const sres = updateSchema(epath, configFile, changes);
|
368
|
-
if (sres) {
|
369
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
370
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
371
|
-
return callback(null, errorObj);
|
372
|
-
}
|
373
|
-
const result = {
|
374
|
-
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
375
|
-
};
|
376
|
-
log.info(result.response);
|
377
|
-
return callback(result, null);
|
378
|
-
}
|
379
|
-
if (type === 'mock') {
|
380
|
-
// if the mock directory does not exist - error
|
381
|
-
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
382
|
-
if (!fs.existsSync(mpath)) {
|
383
|
-
fs.mkdirSync(mpath);
|
384
|
-
}
|
385
|
-
|
386
|
-
const mres = updateMock(mpath, configFile, changes);
|
387
|
-
if (mres) {
|
388
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
389
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
390
|
-
return callback(null, errorObj);
|
391
|
-
}
|
392
|
-
const result = {
|
393
|
-
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
394
|
-
};
|
395
|
-
log.info(result.response);
|
396
|
-
return callback(result, null);
|
397
|
-
}
|
398
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
399
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
400
|
-
return callback(null, errorObj);
|
401
|
-
}
|
402
|
-
|
403
280
|
/**
|
404
281
|
* @summary Connect function is used during Pronghorn startup to provide instantiation feedback.
|
405
282
|
*
|
@@ -468,7 +345,7 @@ class AdapterBase extends EventEmitterCl {
|
|
468
345
|
}
|
469
346
|
|
470
347
|
// call to the healthcheck in connector
|
471
|
-
return this.requestHandlerInst.identifyHealthcheck(
|
348
|
+
return this.requestHandlerInst.identifyHealthcheck(myRequest, (res, error) => {
|
472
349
|
// unhealthy
|
473
350
|
if (error) {
|
474
351
|
// if we were healthy, toggle health
|
@@ -501,98 +378,12 @@ class AdapterBase extends EventEmitterCl {
|
|
501
378
|
}
|
502
379
|
|
503
380
|
/**
|
504
|
-
*
|
505
|
-
* @param {Callback} callback - The adapater suspension status
|
506
|
-
* @function suspend
|
507
|
-
*/
|
508
|
-
suspend(mode, callback) {
|
509
|
-
const origin = `${this.id}-adapterBase-suspend`;
|
510
|
-
if (this.suspended) {
|
511
|
-
throw new Error(`${origin}: Adapter is already suspended`);
|
512
|
-
}
|
513
|
-
try {
|
514
|
-
this.suspended = true;
|
515
|
-
this.suspendMode = mode;
|
516
|
-
if (this.suspendMode === 'pause') {
|
517
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
518
|
-
// To suspend adapter, enable throttling and set concurrent max to 0
|
519
|
-
props.throttle.throttle_enabled = true;
|
520
|
-
props.throttle.concurrent_max = 0;
|
521
|
-
this.refreshProperties(props);
|
522
|
-
}
|
523
|
-
return callback({ suspended: true });
|
524
|
-
} catch (error) {
|
525
|
-
return callback(null, error);
|
526
|
-
}
|
527
|
-
}
|
528
|
-
|
529
|
-
/**
|
530
|
-
* @summary Unsuspends the adapter
|
531
|
-
* @param {Callback} callback - The adapater suspension status
|
532
|
-
*
|
533
|
-
* @function unsuspend
|
534
|
-
*/
|
535
|
-
unsuspend(callback) {
|
536
|
-
const origin = `${this.id}-adapterBase-unsuspend`;
|
537
|
-
if (!this.suspended) {
|
538
|
-
throw new Error(`${origin}: Adapter is not suspended`);
|
539
|
-
}
|
540
|
-
if (this.suspendMode === 'pause') {
|
541
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
542
|
-
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
543
|
-
props.throttle.throttle_enabled = true;
|
544
|
-
props.throttle.concurrent_max = 1;
|
545
|
-
this.refreshProperties(props);
|
546
|
-
setTimeout(() => {
|
547
|
-
this.getQueue((q, error) => {
|
548
|
-
// console.log("Items in queue: " + String(q.length))
|
549
|
-
if (q.length === 0) {
|
550
|
-
// if queue is empty, return to initial properties state
|
551
|
-
this.refreshProperties(this.initProps);
|
552
|
-
this.suspended = false;
|
553
|
-
return callback({ suspended: false });
|
554
|
-
}
|
555
|
-
// recursive call to check queue again every second
|
556
|
-
return this.unsuspend(callback);
|
557
|
-
});
|
558
|
-
}, 1000);
|
559
|
-
} else {
|
560
|
-
this.suspended = false;
|
561
|
-
callback({ suspend: false });
|
562
|
-
}
|
563
|
-
}
|
564
|
-
|
565
|
-
/**
|
566
|
-
* getAllFunctions is used to get all of the exposed function in the adapter
|
567
|
-
*
|
568
|
-
* @function getAllFunctions
|
569
|
-
*/
|
570
|
-
getAllFunctions() {
|
571
|
-
let myfunctions = [];
|
572
|
-
let obj = this;
|
573
|
-
|
574
|
-
// find the functions in this class
|
575
|
-
do {
|
576
|
-
const l = Object.getOwnPropertyNames(obj)
|
577
|
-
.concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString()))
|
578
|
-
.sort()
|
579
|
-
.filter((p, i, arr) => typeof obj[p] === 'function' && p !== 'constructor' && (i === 0 || p !== arr[i - 1]) && myfunctions.indexOf(p) === -1);
|
580
|
-
myfunctions = myfunctions.concat(l);
|
581
|
-
}
|
582
|
-
while (
|
583
|
-
(obj = Object.getPrototypeOf(obj)) && Object.getPrototypeOf(obj)
|
584
|
-
);
|
585
|
-
|
586
|
-
return myfunctions;
|
587
|
-
}
|
588
|
-
|
589
|
-
/**
|
590
|
-
* 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
|
591
382
|
* @param {array} ignoreThese - additional methods to ignore (optional)
|
592
383
|
*
|
593
|
-
* @function
|
384
|
+
* @function iapGetAdapterWorkflowFunctions
|
594
385
|
*/
|
595
|
-
|
386
|
+
iapGetAdapterWorkflowFunctions(ignoreThese) {
|
596
387
|
const myfunctions = this.getAllFunctions();
|
597
388
|
const wffunctions = [];
|
598
389
|
|
@@ -602,8 +393,9 @@ class AdapterBase extends EventEmitterCl {
|
|
602
393
|
// got to the second tier (adapterBase)
|
603
394
|
break;
|
604
395
|
}
|
605
|
-
if (myfunctions[m] !== '
|
606
|
-
&& myfunctions[m] !== '
|
396
|
+
if (myfunctions[m] !== 'iapHasAdapterEntity' && myfunctions[m] !== 'iapVerifyAdapterCapability'
|
397
|
+
&& myfunctions[m] !== 'iapUpdateAdapterEntityCache' && myfunctions[m] !== 'healthCheck'
|
398
|
+
&& myfunctions[m] !== 'iapGetAdapterWorkflowFunctions'
|
607
399
|
&& !(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
|
608
400
|
let found = false;
|
609
401
|
if (ignoreThese && Array.isArray(ignoreThese)) {
|
@@ -623,30 +415,136 @@ class AdapterBase extends EventEmitterCl {
|
|
623
415
|
}
|
624
416
|
|
625
417
|
/**
|
626
|
-
*
|
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.
|
627
421
|
*
|
628
|
-
* @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
|
629
429
|
*/
|
630
|
-
|
631
|
-
const
|
430
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
431
|
+
const meth = 'adapterBase-iapUpdateAdapterConfiguration';
|
432
|
+
const origin = `${this.id}-${meth}`;
|
632
433
|
log.trace(origin);
|
633
434
|
|
634
|
-
//
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
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);
|
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);
|
639
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);
|
640
538
|
}
|
641
539
|
|
642
540
|
/**
|
643
541
|
* See if the API path provided is found in this adapter
|
644
542
|
*
|
645
|
-
* @function
|
543
|
+
* @function iapFindAdapterPath
|
646
544
|
* @param {string} apiPath - the api path to check on
|
647
545
|
* @param {Callback} callback - The results of the call
|
648
546
|
*/
|
649
|
-
|
547
|
+
iapFindAdapterPath(apiPath, callback) {
|
650
548
|
const result = {
|
651
549
|
apiPath
|
652
550
|
};
|
@@ -723,66 +621,90 @@ class AdapterBase extends EventEmitterCl {
|
|
723
621
|
}
|
724
622
|
|
725
623
|
/**
|
726
|
-
*
|
727
|
-
*
|
728
|
-
* @function
|
729
|
-
* @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
|
730
627
|
*/
|
731
|
-
|
732
|
-
const origin = `${this.
|
733
|
-
|
734
|
-
|
735
|
-
|
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
|
+
}
|
736
633
|
try {
|
737
|
-
|
738
|
-
|
739
|
-
|
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);
|
740
646
|
}
|
741
647
|
}
|
742
648
|
|
743
649
|
/**
|
744
|
-
*
|
650
|
+
* @summary Unsuspends the adapter
|
651
|
+
* @param {Callback} callback - The adapater suspension status
|
745
652
|
*
|
746
|
-
* @function
|
747
|
-
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
653
|
+
* @function iapUnsuspendAdapter
|
748
654
|
*/
|
749
|
-
|
750
|
-
const origin = `${this.id}-adapterBase-
|
751
|
-
|
752
|
-
|
753
|
-
|
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
|
+
}
|
754
683
|
}
|
755
684
|
|
756
685
|
/**
|
757
|
-
*
|
758
|
-
* encoded/encrypted string
|
686
|
+
* iapGetAdapterQueue is used to get information for all of the requests currently in the queue.
|
759
687
|
*
|
760
|
-
* @function
|
761
|
-
* @param {
|
762
|
-
* @param {String} technique - the technique to use to encrypt
|
763
|
-
*
|
764
|
-
* @param {Callback} callback - a callback function to return the result
|
765
|
-
* Encrypted String or the Error
|
688
|
+
* @function iapGetAdapterQueue
|
689
|
+
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
766
690
|
*/
|
767
|
-
|
768
|
-
const origin = `${this.id}-adapterBase-
|
691
|
+
iapGetAdapterQueue(callback) {
|
692
|
+
const origin = `${this.id}-adapterBase-iapGetAdapterQueue`;
|
769
693
|
log.trace(origin);
|
770
694
|
|
771
|
-
|
772
|
-
// encryptProperty(property, technique, callback)
|
773
|
-
return this.requestHandlerInst.encryptProperty(property, technique, callback);
|
695
|
+
return this.requestHandlerInst.getQueue(callback);
|
774
696
|
}
|
775
697
|
|
776
698
|
/**
|
777
699
|
* @summary runs troubleshoot scripts for adapter
|
778
700
|
*
|
779
|
-
* @function
|
701
|
+
* @function iapTroubleshootAdapter
|
780
702
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
781
703
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
782
704
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
783
705
|
* @param {Callback} callback - callback function to return troubleshoot results
|
784
706
|
*/
|
785
|
-
async
|
707
|
+
async iapTroubleshootAdapter(props, persistFlag, adapter, callback) {
|
786
708
|
try {
|
787
709
|
const result = await troubleshootingAdapter.troubleshoot(props, false, persistFlag, adapter);
|
788
710
|
if (result.healthCheck && result.connectivity.failCount === 0 && result.basicGet.failCount === 0) {
|
@@ -797,11 +719,11 @@ class AdapterBase extends EventEmitterCl {
|
|
797
719
|
/**
|
798
720
|
* @summary runs healthcheck script for adapter
|
799
721
|
*
|
800
|
-
* @function
|
722
|
+
* @function iapRunAdapterHealthcheck
|
801
723
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
802
724
|
* @param {Callback} callback - callback function to return healthcheck status
|
803
725
|
*/
|
804
|
-
async
|
726
|
+
async iapRunAdapterHealthcheck(adapter, callback) {
|
805
727
|
try {
|
806
728
|
const result = await tbUtils.healthCheck(adapter);
|
807
729
|
if (result) {
|
@@ -816,15 +738,15 @@ class AdapterBase extends EventEmitterCl {
|
|
816
738
|
/**
|
817
739
|
* @summary runs connectivity check script for adapter
|
818
740
|
*
|
819
|
-
* @function
|
741
|
+
* @function iapRunAdapterConnectivity
|
820
742
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
821
743
|
* @param {Callback} callback - callback function to return connectivity status
|
822
744
|
*/
|
823
|
-
async
|
745
|
+
async iapRunAdapterConnectivity(callback) {
|
824
746
|
try {
|
825
747
|
const { serviceItem } = await tbUtils.getAdapterConfig();
|
826
748
|
const { host } = serviceItem.properties.properties;
|
827
|
-
const result = tbUtils.
|
749
|
+
const result = tbUtils.iapRunAdapterConnectivity(host, false);
|
828
750
|
if (result.failCount > 0) {
|
829
751
|
return callback(null, result);
|
830
752
|
}
|
@@ -837,12 +759,12 @@ class AdapterBase extends EventEmitterCl {
|
|
837
759
|
/**
|
838
760
|
* @summary runs basicGet script for adapter
|
839
761
|
*
|
840
|
-
* @function
|
762
|
+
* @function iapRunAdapterBasicGet
|
841
763
|
* @param {Callback} callback - callback function to return basicGet result
|
842
764
|
*/
|
843
|
-
|
765
|
+
iapRunAdapterBasicGet(callback) {
|
844
766
|
try {
|
845
|
-
const result = tbUtils.
|
767
|
+
const result = tbUtils.iapRunAdapterBasicGet(false);
|
846
768
|
if (result.failCount > 0) {
|
847
769
|
return callback(null, result);
|
848
770
|
}
|
@@ -852,6 +774,106 @@ class AdapterBase extends EventEmitterCl {
|
|
852
774
|
}
|
853
775
|
}
|
854
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
|
+
|
855
877
|
/**
|
856
878
|
* @summary take the entities and add them to the cache
|
857
879
|
*
|
@@ -1002,27 +1024,6 @@ class AdapterBase extends EventEmitterCl {
|
|
1002
1024
|
return [];
|
1003
1025
|
}
|
1004
1026
|
}
|
1005
|
-
|
1006
|
-
/**
|
1007
|
-
* @summary moves entities to mongo database
|
1008
|
-
*
|
1009
|
-
* @function moveEntitiesToDB
|
1010
|
-
*
|
1011
|
-
* @return {Callback} - containing the response from the mongo transaction
|
1012
|
-
*/
|
1013
|
-
moveEntitiesToDB(callback) {
|
1014
|
-
const meth = 'adapterBase-moveEntitiesToDB';
|
1015
|
-
const origin = `${this.id}-${meth}`;
|
1016
|
-
log.trace(origin);
|
1017
|
-
|
1018
|
-
try {
|
1019
|
-
return callback(entitiesToDB.moveEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
|
1020
|
-
} catch (err) {
|
1021
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
|
1022
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
1023
|
-
return callback(null, errorObj);
|
1024
|
-
}
|
1025
|
-
}
|
1026
1027
|
}
|
1027
1028
|
|
1028
1029
|
module.exports = AdapterBase;
|