@itentialopensource/adapter-nokia_altiplano 0.5.1 → 0.6.0
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/BROKER.md +6 -2
- package/CALLS.md +144 -0
- package/CHANGELOG.md +24 -8
- package/CONTRIBUTING.md +1 -160
- package/ENHANCE.md +2 -2
- package/README.md +32 -23
- package/adapter.js +159 -330
- package/adapterBase.js +555 -852
- package/changelogs/changelog.md +72 -0
- package/metadata.json +47 -0
- package/package.json +25 -25
- package/pronghorn.json +485 -146
- package/propertiesSchema.json +478 -37
- package/refs?service=git-upload-pack +0 -0
- package/report/adapter-openapi.json +1546 -0
- package/report/adapter-openapi.yaml +1392 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1652620670443.json +120 -0
- package/report/updateReport1691507619656.json +120 -0
- package/report/updateReport1692202622632.json +120 -0
- package/report/updateReport1694462147618.json +120 -0
- package/report/updateReport1698421046815.json +120 -0
- package/sampleProperties.json +77 -9
- package/test/integration/adapterTestBasicGet.js +3 -5
- package/test/integration/adapterTestConnectivity.js +91 -42
- package/test/integration/adapterTestIntegration.js +154 -110
- package/test/unit/adapterBaseTestUnit.js +388 -313
- package/test/unit/adapterTestUnit.js +366 -224
- package/utils/adapterInfo.js +1 -1
- package/utils/addAuth.js +1 -1
- package/utils/artifactize.js +1 -1
- package/utils/checkMigrate.js +1 -1
- package/utils/entitiesToDB.js +12 -57
- package/utils/findPath.js +1 -1
- package/utils/methodDocumentor.js +273 -0
- package/utils/modify.js +13 -15
- package/utils/packModificationScript.js +1 -1
- package/utils/pre-commit.sh +2 -0
- package/utils/taskMover.js +309 -0
- package/utils/tbScript.js +123 -53
- package/utils/tbUtils.js +84 -59
- package/utils/testRunner.js +17 -17
- package/utils/troubleshootingAdapter.js +9 -6
- package/workflows/README.md +0 -3
package/adapterBase.js
CHANGED
|
@@ -11,13 +11,18 @@
|
|
|
11
11
|
/* eslint prefer-destructuring: warn */
|
|
12
12
|
|
|
13
13
|
/* Required libraries. */
|
|
14
|
-
const fs = require('fs-extra');
|
|
15
14
|
const path = require('path');
|
|
16
|
-
const EventEmitterCl = require('events').EventEmitter;
|
|
17
15
|
const { execSync } = require('child_process');
|
|
16
|
+
const { spawnSync } = require('child_process');
|
|
17
|
+
const EventEmitterCl = require('events').EventEmitter;
|
|
18
|
+
const fs = require('fs-extra');
|
|
19
|
+
const jsonQuery = require('json-query');
|
|
20
|
+
|
|
21
|
+
const sampleProperties = require(`${__dirname}/sampleProperties.json`).properties;
|
|
18
22
|
|
|
19
23
|
/* The schema validator */
|
|
20
24
|
const AjvCl = require('ajv');
|
|
25
|
+
const { Test } = require('mocha');
|
|
21
26
|
|
|
22
27
|
/* Fetch in the other needed components for the this Adaptor */
|
|
23
28
|
const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
|
|
@@ -26,8 +31,10 @@ const RequestHandlerCl = require('@itentialopensource/adapter-utils').RequestHan
|
|
|
26
31
|
const entitiesToDB = require(path.join(__dirname, 'utils/entitiesToDB'));
|
|
27
32
|
const troubleshootingAdapter = require(path.join(__dirname, 'utils/troubleshootingAdapter'));
|
|
28
33
|
const tbUtils = require(path.join(__dirname, 'utils/tbUtils'));
|
|
34
|
+
const taskMover = require(path.join(__dirname, 'utils/taskMover'));
|
|
29
35
|
|
|
30
36
|
let propUtil = null;
|
|
37
|
+
let choosepath = null;
|
|
31
38
|
|
|
32
39
|
/*
|
|
33
40
|
* INTERNAL FUNCTION: force fail the adapter - generally done to cause restart
|
|
@@ -100,7 +107,7 @@ function updateSchema(entityPath, configFile, changes) {
|
|
|
100
107
|
/*
|
|
101
108
|
* INTERNAL FUNCTION: update the mock data file
|
|
102
109
|
*/
|
|
103
|
-
function updateMock(mockPath, configFile, changes) {
|
|
110
|
+
function updateMock(mockPath, configFile, changes, replace) {
|
|
104
111
|
// if the mock file does not exist - create it
|
|
105
112
|
const mockFile = path.join(mockPath, `/${configFile}`);
|
|
106
113
|
if (!fs.existsSync(mockFile)) {
|
|
@@ -112,7 +119,11 @@ function updateMock(mockPath, configFile, changes) {
|
|
|
112
119
|
let mock = require(path.resolve(mockPath, configFile));
|
|
113
120
|
|
|
114
121
|
// merge the changes into the mock file
|
|
115
|
-
|
|
122
|
+
if (replace === true) {
|
|
123
|
+
mock = changes;
|
|
124
|
+
} else {
|
|
125
|
+
mock = propUtil.mergeProperties(changes, mock);
|
|
126
|
+
}
|
|
116
127
|
|
|
117
128
|
fs.writeFileSync(mockFile, JSON.stringify(mock, null, 2));
|
|
118
129
|
return null;
|
|
@@ -144,44 +155,6 @@ function updatePackage(changes) {
|
|
|
144
155
|
return null;
|
|
145
156
|
}
|
|
146
157
|
|
|
147
|
-
/*
|
|
148
|
-
* INTERNAL FUNCTION: get data from source(s) - nested
|
|
149
|
-
*/
|
|
150
|
-
function getDataFromSources(loopField, sources) {
|
|
151
|
-
const loopArray = loopField.split('.');
|
|
152
|
-
let fieldValue = loopField;
|
|
153
|
-
|
|
154
|
-
// go through the sources to find the field
|
|
155
|
-
for (let s = 0; s < sources.length; s += 1) {
|
|
156
|
-
let nestedValue = sources[s];
|
|
157
|
-
let found = false;
|
|
158
|
-
|
|
159
|
-
// loops through incase the field is nested
|
|
160
|
-
for (let i = 0; i < loopArray.length; i += 1) {
|
|
161
|
-
// if not nested finds it first pass - otherwise set to new level and loop
|
|
162
|
-
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
|
163
|
-
nestedValue = nestedValue[loopArray[i]];
|
|
164
|
-
|
|
165
|
-
// set found if we are at the leaf (going to stop looping)
|
|
166
|
-
if (i + 1 === loopArray.length) {
|
|
167
|
-
found = true;
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
// not found in source - check next one
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// if we found in source - set and no need to check other sources
|
|
176
|
-
if (found) {
|
|
177
|
-
fieldValue = nestedValue;
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return fieldValue;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
158
|
/* GENERAL ADAPTER FUNCTIONS THESE SHOULD NOT BE DIRECTLY MODIFIED */
|
|
186
159
|
/* IF YOU NEED MODIFICATIONS, REDEFINE THEM IN adapter.js!!! */
|
|
187
160
|
class AdapterBase extends EventEmitterCl {
|
|
@@ -194,7 +167,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
194
167
|
super();
|
|
195
168
|
|
|
196
169
|
// IAP home directory injected by core when running the adapter within IAP
|
|
197
|
-
process.env.iap_home = process.argv
|
|
170
|
+
[, , , process.env.iap_home] = process.argv;
|
|
198
171
|
|
|
199
172
|
try {
|
|
200
173
|
// Capture the adapter id
|
|
@@ -271,7 +244,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
271
244
|
this.allProps = this.propUtilInst.mergeProperties(properties, defProps);
|
|
272
245
|
|
|
273
246
|
// validate the entity against the schema
|
|
274
|
-
const ajvInst = new AjvCl();
|
|
247
|
+
const ajvInst = new AjvCl({ strictSchema: false, allowUnionTypes: true });
|
|
275
248
|
const validate = ajvInst.compile(propertiesSchema);
|
|
276
249
|
const result = validate(this.allProps);
|
|
277
250
|
|
|
@@ -395,9 +368,15 @@ class AdapterBase extends EventEmitterCl {
|
|
|
395
368
|
this.emit('OFFLINE', { id: this.id });
|
|
396
369
|
this.emit('DEGRADED', { id: this.id });
|
|
397
370
|
this.healthy = false;
|
|
398
|
-
|
|
399
|
-
|
|
371
|
+
if (typeof error === 'object') {
|
|
372
|
+
log.error(`${origin}: HEALTH CHECK - Error ${JSON.stringify(error)}`);
|
|
373
|
+
} else {
|
|
374
|
+
log.error(`${origin}: HEALTH CHECK - Error ${error}`);
|
|
375
|
+
}
|
|
376
|
+
} else if (typeof error === 'object') {
|
|
400
377
|
// still log but set the level to trace
|
|
378
|
+
log.trace(`${origin}: HEALTH CHECK - Still Errors ${JSON.stringify(error)}`);
|
|
379
|
+
} else {
|
|
401
380
|
log.trace(`${origin}: HEALTH CHECK - Still Errors ${error}`);
|
|
402
381
|
}
|
|
403
382
|
|
|
@@ -443,6 +422,40 @@ class AdapterBase extends EventEmitterCl {
|
|
|
443
422
|
return myfunctions;
|
|
444
423
|
}
|
|
445
424
|
|
|
425
|
+
/**
|
|
426
|
+
* iapGetAdapterWorkflowFunctions is used to get all of the workflow function in the adapter
|
|
427
|
+
* @param {array} ignoreThese - additional methods to ignore (optional)
|
|
428
|
+
*
|
|
429
|
+
* @function iapGetAdapterWorkflowFunctions
|
|
430
|
+
*/
|
|
431
|
+
iapGetAdapterWorkflowFunctions(ignoreThese) {
|
|
432
|
+
const myfunctions = this.getAllFunctions();
|
|
433
|
+
const wffunctions = [];
|
|
434
|
+
|
|
435
|
+
// remove the functions that should not be in a Workflow
|
|
436
|
+
for (let m = 0; m < myfunctions.length; m += 1) {
|
|
437
|
+
if (myfunctions[m] === 'checkActionFiles') {
|
|
438
|
+
// got to the second tier (adapterBase)
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
if (!(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
|
|
442
|
+
let found = false;
|
|
443
|
+
if (ignoreThese && Array.isArray(ignoreThese)) {
|
|
444
|
+
for (let i = 0; i < ignoreThese.length; i += 1) {
|
|
445
|
+
if (myfunctions[m].toUpperCase() === ignoreThese[i].toUpperCase()) {
|
|
446
|
+
found = true;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (!found) {
|
|
451
|
+
wffunctions.push(myfunctions[m]);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return wffunctions;
|
|
457
|
+
}
|
|
458
|
+
|
|
446
459
|
/**
|
|
447
460
|
* checkActionFiles is used to update the validation of the action files.
|
|
448
461
|
*
|
|
@@ -498,40 +511,6 @@ class AdapterBase extends EventEmitterCl {
|
|
|
498
511
|
return this.requestHandlerInst.encryptProperty(property, technique, callback);
|
|
499
512
|
}
|
|
500
513
|
|
|
501
|
-
/**
|
|
502
|
-
* iapGetAdapterWorkflowFunctions is used to get all of the workflow function in the adapter
|
|
503
|
-
* @param {array} ignoreThese - additional methods to ignore (optional)
|
|
504
|
-
*
|
|
505
|
-
* @function iapGetAdapterWorkflowFunctions
|
|
506
|
-
*/
|
|
507
|
-
iapGetAdapterWorkflowFunctions(ignoreThese) {
|
|
508
|
-
const myfunctions = this.getAllFunctions();
|
|
509
|
-
const wffunctions = [];
|
|
510
|
-
|
|
511
|
-
// remove the functions that should not be in a Workflow
|
|
512
|
-
for (let m = 0; m < myfunctions.length; m += 1) {
|
|
513
|
-
if (myfunctions[m] === 'addEntityCache') {
|
|
514
|
-
// got to the second tier (adapterBase)
|
|
515
|
-
break;
|
|
516
|
-
}
|
|
517
|
-
if (!(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
|
|
518
|
-
let found = false;
|
|
519
|
-
if (ignoreThese && Array.isArray(ignoreThese)) {
|
|
520
|
-
for (let i = 0; i < ignoreThese.length; i += 1) {
|
|
521
|
-
if (myfunctions[m].toUpperCase() === ignoreThese[i].toUpperCase()) {
|
|
522
|
-
found = true;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
if (!found) {
|
|
527
|
-
wffunctions.push(myfunctions[m]);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
return wffunctions;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
514
|
/**
|
|
536
515
|
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
537
516
|
* allows customers to make changes to adapter configuration without having to be on the
|
|
@@ -543,16 +522,17 @@ class AdapterBase extends EventEmitterCl {
|
|
|
543
522
|
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
544
523
|
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
|
545
524
|
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
525
|
+
* @param {boolean} replace - true to replace entire mock data, false to merge/append (optional)
|
|
546
526
|
* @param {Callback} callback - The results of the call
|
|
547
527
|
*/
|
|
548
|
-
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
528
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
|
|
549
529
|
const meth = 'adapterBase-iapUpdateAdapterConfiguration';
|
|
550
530
|
const origin = `${this.id}-${meth}`;
|
|
551
531
|
log.trace(origin);
|
|
552
532
|
|
|
553
533
|
// verify the parameters are valid
|
|
554
534
|
if (changes === undefined || changes === null || typeof changes !== 'object'
|
|
555
|
-
|
|
535
|
+
|| Object.keys(changes).length === 0) {
|
|
556
536
|
const result = {
|
|
557
537
|
response: 'No configuration updates to make'
|
|
558
538
|
};
|
|
@@ -637,8 +617,14 @@ class AdapterBase extends EventEmitterCl {
|
|
|
637
617
|
if (!fs.existsSync(mpath)) {
|
|
638
618
|
fs.mkdirSync(mpath);
|
|
639
619
|
}
|
|
620
|
+
// this means we are changing a mock data file so replace is required
|
|
621
|
+
if (replace === undefined || replace === null || replace === '') {
|
|
622
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['replace'], null, null, null);
|
|
623
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
624
|
+
return callback(null, errorObj);
|
|
625
|
+
}
|
|
626
|
+
const mres = updateMock(mpath, configFile, changes, replace);
|
|
640
627
|
|
|
641
|
-
const mres = updateMock(mpath, configFile, changes);
|
|
642
628
|
if (mres) {
|
|
643
629
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
|
644
630
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
@@ -655,6 +641,86 @@ class AdapterBase extends EventEmitterCl {
|
|
|
655
641
|
return callback(null, errorObj);
|
|
656
642
|
}
|
|
657
643
|
|
|
644
|
+
/**
|
|
645
|
+
* @summary Suspends the adapter
|
|
646
|
+
* @param {Callback} callback - The adapater suspension status
|
|
647
|
+
* @function iapSuspendAdapter
|
|
648
|
+
*/
|
|
649
|
+
iapSuspendAdapter(mode, callback) {
|
|
650
|
+
const origin = `${this.id}-adapterBase-iapSuspendAdapter`;
|
|
651
|
+
if (this.suspended) {
|
|
652
|
+
throw new Error(`${origin}: Adapter is already suspended`);
|
|
653
|
+
}
|
|
654
|
+
try {
|
|
655
|
+
this.suspended = true;
|
|
656
|
+
this.suspendMode = mode;
|
|
657
|
+
if (this.suspendMode === 'pause') {
|
|
658
|
+
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
659
|
+
// To suspend adapter, enable throttling and set concurrent max to 0
|
|
660
|
+
props.throttle.throttle_enabled = true;
|
|
661
|
+
props.throttle.concurrent_max = 0;
|
|
662
|
+
this.refreshProperties(props);
|
|
663
|
+
}
|
|
664
|
+
return callback({ suspended: true });
|
|
665
|
+
} catch (error) {
|
|
666
|
+
return callback(null, error);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* @summary Unsuspends the adapter
|
|
672
|
+
* @param {Callback} callback - The adapater suspension status
|
|
673
|
+
*
|
|
674
|
+
* @function iapUnsuspendAdapter
|
|
675
|
+
*/
|
|
676
|
+
iapUnsuspendAdapter(callback) {
|
|
677
|
+
const origin = `${this.id}-adapterBase-iapUnsuspendAdapter`;
|
|
678
|
+
if (!this.suspended) {
|
|
679
|
+
throw new Error(`${origin}: Adapter is not suspended`);
|
|
680
|
+
}
|
|
681
|
+
if (this.suspendMode === 'pause') {
|
|
682
|
+
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
683
|
+
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
|
684
|
+
props.throttle.throttle_enabled = true;
|
|
685
|
+
props.throttle.concurrent_max = 1;
|
|
686
|
+
this.refreshProperties(props);
|
|
687
|
+
setTimeout(() => {
|
|
688
|
+
this.getQueue((q, error) => {
|
|
689
|
+
// console.log("Items in queue: " + String(q.length))
|
|
690
|
+
if (q.length === 0) {
|
|
691
|
+
// if queue is empty, return to initial properties state
|
|
692
|
+
this.refreshProperties(this.initProps);
|
|
693
|
+
this.suspended = false;
|
|
694
|
+
return callback({ suspended: false });
|
|
695
|
+
}
|
|
696
|
+
// recursive call to check queue again every second
|
|
697
|
+
return this.iapUnsuspendAdapter(callback);
|
|
698
|
+
});
|
|
699
|
+
}, 1000);
|
|
700
|
+
} else {
|
|
701
|
+
this.suspended = false;
|
|
702
|
+
callback({ suspend: false });
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* iapGetAdapterQueue is used to get information for all of the requests currently in the queue.
|
|
708
|
+
*
|
|
709
|
+
* @function iapGetAdapterQueue
|
|
710
|
+
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
|
711
|
+
*/
|
|
712
|
+
iapGetAdapterQueue(callback) {
|
|
713
|
+
const origin = `${this.id}-adapterBase-iapGetAdapterQueue`;
|
|
714
|
+
log.trace(origin);
|
|
715
|
+
|
|
716
|
+
return this.requestHandlerInst.getQueue(callback);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/* ********************************************** */
|
|
720
|
+
/* */
|
|
721
|
+
/* EXPOSES ADAPTER SCRIPTS */
|
|
722
|
+
/* */
|
|
723
|
+
/* ********************************************** */
|
|
658
724
|
/**
|
|
659
725
|
* See if the API path provided is found in this adapter
|
|
660
726
|
*
|
|
@@ -675,6 +741,10 @@ class AdapterBase extends EventEmitterCl {
|
|
|
675
741
|
return callback(null, result);
|
|
676
742
|
}
|
|
677
743
|
|
|
744
|
+
if (typeof this.allProps.choosepath === 'string') {
|
|
745
|
+
choosepath = this.allProps.choosepath;
|
|
746
|
+
}
|
|
747
|
+
|
|
678
748
|
// make sure the entities directory exists
|
|
679
749
|
const entitydir = path.join(__dirname, 'entities');
|
|
680
750
|
if (!fs.statSync(entitydir).isDirectory()) {
|
|
@@ -699,7 +769,25 @@ class AdapterBase extends EventEmitterCl {
|
|
|
699
769
|
|
|
700
770
|
// go through all of the actions set the appropriate info in the newActions
|
|
701
771
|
for (let a = 0; a < actions.actions.length; a += 1) {
|
|
702
|
-
if (actions.actions[a].entitypath.
|
|
772
|
+
if (actions.actions[a].entitypath && typeof actions.actions[a].entitypath === 'object') {
|
|
773
|
+
const entityKeys = Object.keys(actions.actions[a].entitypath);
|
|
774
|
+
if (entityKeys.length > 0) {
|
|
775
|
+
for (let entityKey = 0; entityKey < entityKeys.length; entityKey += 1) {
|
|
776
|
+
if (choosepath && entityKeys[entityKey] === choosepath && actions.actions[a].entitypath[entityKeys[entityKey]].indexOf(apiPath) >= 0) {
|
|
777
|
+
log.info(` Found - entity: ${entities[e]} action: ${actions.actions[a].name}`);
|
|
778
|
+
log.info(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath[entityKeys[entityKey]]}`);
|
|
779
|
+
const fitem = {
|
|
780
|
+
entity: entities[e],
|
|
781
|
+
action: actions.actions[a].name,
|
|
782
|
+
method: actions.actions[a].method,
|
|
783
|
+
path: actions.actions[a].entitypath[entityKeys[entityKey]]
|
|
784
|
+
};
|
|
785
|
+
fitems.push(fitem);
|
|
786
|
+
break;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
} else if (actions.actions[a].entitypath.indexOf(apiPath) >= 0) {
|
|
703
791
|
log.info(` Found - entity: ${entities[e]} action: ${actions.actions[a].name}`);
|
|
704
792
|
log.info(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
|
|
705
793
|
const fitem = {
|
|
@@ -738,81 +826,6 @@ class AdapterBase extends EventEmitterCl {
|
|
|
738
826
|
return callback(result, null);
|
|
739
827
|
}
|
|
740
828
|
|
|
741
|
-
/**
|
|
742
|
-
* @summary Suspends the adapter
|
|
743
|
-
* @param {Callback} callback - The adapater suspension status
|
|
744
|
-
* @function iapSuspendAdapter
|
|
745
|
-
*/
|
|
746
|
-
iapSuspendAdapter(mode, callback) {
|
|
747
|
-
const origin = `${this.id}-adapterBase-iapSuspendAdapter`;
|
|
748
|
-
if (this.suspended) {
|
|
749
|
-
throw new Error(`${origin}: Adapter is already suspended`);
|
|
750
|
-
}
|
|
751
|
-
try {
|
|
752
|
-
this.suspended = true;
|
|
753
|
-
this.suspendMode = mode;
|
|
754
|
-
if (this.suspendMode === 'pause') {
|
|
755
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
756
|
-
// To suspend adapter, enable throttling and set concurrent max to 0
|
|
757
|
-
props.throttle.throttle_enabled = true;
|
|
758
|
-
props.throttle.concurrent_max = 0;
|
|
759
|
-
this.refreshProperties(props);
|
|
760
|
-
}
|
|
761
|
-
return callback({ suspended: true });
|
|
762
|
-
} catch (error) {
|
|
763
|
-
return callback(null, error);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* @summary Unsuspends the adapter
|
|
769
|
-
* @param {Callback} callback - The adapater suspension status
|
|
770
|
-
*
|
|
771
|
-
* @function iapUnsuspendAdapter
|
|
772
|
-
*/
|
|
773
|
-
iapUnsuspendAdapter(callback) {
|
|
774
|
-
const origin = `${this.id}-adapterBase-iapUnsuspendAdapter`;
|
|
775
|
-
if (!this.suspended) {
|
|
776
|
-
throw new Error(`${origin}: Adapter is not suspended`);
|
|
777
|
-
}
|
|
778
|
-
if (this.suspendMode === 'pause') {
|
|
779
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
780
|
-
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
|
781
|
-
props.throttle.throttle_enabled = true;
|
|
782
|
-
props.throttle.concurrent_max = 1;
|
|
783
|
-
this.refreshProperties(props);
|
|
784
|
-
setTimeout(() => {
|
|
785
|
-
this.getQueue((q, error) => {
|
|
786
|
-
// console.log("Items in queue: " + String(q.length))
|
|
787
|
-
if (q.length === 0) {
|
|
788
|
-
// if queue is empty, return to initial properties state
|
|
789
|
-
this.refreshProperties(this.initProps);
|
|
790
|
-
this.suspended = false;
|
|
791
|
-
return callback({ suspended: false });
|
|
792
|
-
}
|
|
793
|
-
// recursive call to check queue again every second
|
|
794
|
-
return this.iapUnsuspendAdapter(callback);
|
|
795
|
-
});
|
|
796
|
-
}, 1000);
|
|
797
|
-
} else {
|
|
798
|
-
this.suspended = false;
|
|
799
|
-
callback({ suspend: false });
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* iapGetAdapterQueue is used to get information for all of the requests currently in the queue.
|
|
805
|
-
*
|
|
806
|
-
* @function iapGetAdapterQueue
|
|
807
|
-
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
|
808
|
-
*/
|
|
809
|
-
iapGetAdapterQueue(callback) {
|
|
810
|
-
const origin = `${this.id}-adapterBase-iapGetAdapterQueue`;
|
|
811
|
-
log.trace(origin);
|
|
812
|
-
|
|
813
|
-
return this.requestHandlerInst.getQueue(callback);
|
|
814
|
-
}
|
|
815
|
-
|
|
816
829
|
/**
|
|
817
830
|
* @summary runs troubleshoot scripts for adapter
|
|
818
831
|
*
|
|
@@ -847,7 +860,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
847
860
|
if (result) {
|
|
848
861
|
return callback(result);
|
|
849
862
|
}
|
|
850
|
-
return callback(null,
|
|
863
|
+
return callback(null, 'Healthcheck failed');
|
|
851
864
|
} catch (error) {
|
|
852
865
|
return callback(null, error);
|
|
853
866
|
}
|
|
@@ -862,8 +875,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
862
875
|
*/
|
|
863
876
|
async iapRunAdapterConnectivity(callback) {
|
|
864
877
|
try {
|
|
865
|
-
const {
|
|
866
|
-
const { host } = serviceItem.properties.properties;
|
|
878
|
+
const { host } = this.allProps;
|
|
867
879
|
const result = tbUtils.runConnectivity(host, false);
|
|
868
880
|
if (result.failCount > 0) {
|
|
869
881
|
return callback(null, result);
|
|
@@ -899,171 +911,105 @@ class AdapterBase extends EventEmitterCl {
|
|
|
899
911
|
*
|
|
900
912
|
* @return {Callback} - containing the response from the mongo transaction
|
|
901
913
|
*/
|
|
902
|
-
iapMoveAdapterEntitiesToDB(callback) {
|
|
914
|
+
async iapMoveAdapterEntitiesToDB(callback) {
|
|
903
915
|
const meth = 'adapterBase-iapMoveAdapterEntitiesToDB';
|
|
904
916
|
const origin = `${this.id}-${meth}`;
|
|
905
917
|
log.trace(origin);
|
|
906
918
|
|
|
907
919
|
try {
|
|
908
|
-
|
|
920
|
+
const result = await entitiesToDB.moveEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id });
|
|
921
|
+
return callback(result, null);
|
|
909
922
|
} catch (err) {
|
|
910
923
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
|
|
911
924
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
912
|
-
return callback(null,
|
|
925
|
+
return callback(null, err.message);
|
|
913
926
|
}
|
|
914
927
|
}
|
|
915
928
|
|
|
916
929
|
/**
|
|
917
|
-
* @
|
|
918
|
-
*
|
|
919
|
-
* @function addEntityCache
|
|
920
|
-
* @param {String} entityType - the type of the entities
|
|
921
|
-
* @param {Array} data - the list of entities
|
|
922
|
-
* @param {String} key - unique key for the entities
|
|
930
|
+
* @function iapDeactivateTasks
|
|
923
931
|
*
|
|
924
|
-
* @param {
|
|
925
|
-
*
|
|
932
|
+
* @param {Array} tasks - List of tasks to deactivate
|
|
933
|
+
* @param {Callback} callback
|
|
926
934
|
*/
|
|
927
|
-
|
|
928
|
-
const meth = 'adapterBase-
|
|
935
|
+
iapDeactivateTasks(tasks, callback) {
|
|
936
|
+
const meth = 'adapterBase-iapDeactivateTasks';
|
|
929
937
|
const origin = `${this.id}-${meth}`;
|
|
930
938
|
log.trace(origin);
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
// add the entities to the cache
|
|
943
|
-
return this.requestHandlerInst.addEntityCache(entityType, entityIds, (loaded, error) => {
|
|
944
|
-
if (error) {
|
|
945
|
-
return callback(null, error);
|
|
946
|
-
}
|
|
947
|
-
if (!loaded) {
|
|
948
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Entity Cache Not Loading', [entityType], null, null, null);
|
|
949
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
950
|
-
return callback(null, errorObj);
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
return callback(loaded);
|
|
954
|
-
});
|
|
955
|
-
}
|
|
939
|
+
let data;
|
|
940
|
+
try {
|
|
941
|
+
data = taskMover.deactivateTasks(__dirname, tasks);
|
|
942
|
+
} catch (ex) {
|
|
943
|
+
taskMover.rollbackChanges(__dirname);
|
|
944
|
+
taskMover.deleteBackups(__dirname);
|
|
945
|
+
return callback(null, ex);
|
|
946
|
+
}
|
|
947
|
+
taskMover.deleteBackups(__dirname);
|
|
948
|
+
return callback(data, null);
|
|
949
|
+
}
|
|
956
950
|
|
|
957
951
|
/**
|
|
958
|
-
* @
|
|
959
|
-
*
|
|
960
|
-
* @function entityInList
|
|
961
|
-
* @param {String/Array} entityId - the specific entity we are looking for
|
|
962
|
-
* @param {Array} data - the list of entities
|
|
952
|
+
* @function iapActivateTasks
|
|
963
953
|
*
|
|
964
|
-
* @param {
|
|
965
|
-
*
|
|
954
|
+
* @param {Array} tasks - List of tasks to deactivate
|
|
955
|
+
* @param {Callback} callback
|
|
966
956
|
*/
|
|
967
|
-
|
|
968
|
-
const
|
|
957
|
+
iapActivateTasks(tasks, callback) {
|
|
958
|
+
const meth = 'adapterBase-iapActivateTasks';
|
|
959
|
+
const origin = `${this.id}-${meth}`;
|
|
969
960
|
log.trace(origin);
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
resEntity.push(true);
|
|
978
|
-
} else {
|
|
979
|
-
resEntity.push(false);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
return resEntity;
|
|
961
|
+
let data;
|
|
962
|
+
try {
|
|
963
|
+
data = taskMover.activateTasks(__dirname, tasks);
|
|
964
|
+
} catch (ex) {
|
|
965
|
+
taskMover.rollbackChanges(__dirname);
|
|
966
|
+
taskMover.deleteBackups(__dirname);
|
|
967
|
+
return callback(null, ex);
|
|
984
968
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
return [data.includes(entityId)];
|
|
969
|
+
taskMover.deleteBackups(__dirname);
|
|
970
|
+
return callback(data, null);
|
|
988
971
|
}
|
|
989
972
|
|
|
973
|
+
/* ********************************************** */
|
|
974
|
+
/* */
|
|
975
|
+
/* EXPOSES CACHE CALLS */
|
|
976
|
+
/* */
|
|
977
|
+
/* ********************************************** */
|
|
990
978
|
/**
|
|
991
|
-
* @summary
|
|
992
|
-
*
|
|
993
|
-
* @function capabilityResults
|
|
994
|
-
* @param {Array} results - the results from the capability check
|
|
979
|
+
* @summary Populate the cache for the given entities
|
|
995
980
|
*
|
|
996
|
-
* @
|
|
997
|
-
*
|
|
981
|
+
* @function iapPopulateEntityCache
|
|
982
|
+
* @param {String/Array of Strings} entityType - the entity type(s) to populate
|
|
983
|
+
* @param {Callback} callback - whether the cache was updated or not for each entity type
|
|
984
|
+
* @returns return of the callback
|
|
998
985
|
*/
|
|
999
|
-
|
|
1000
|
-
const
|
|
1001
|
-
const origin = `${this.id}-${meth}`;
|
|
986
|
+
iapPopulateEntityCache(entityTypes, callback) {
|
|
987
|
+
const origin = `${this.myid}-adapterBase-iapPopulateEntityCache`;
|
|
1002
988
|
log.trace(origin);
|
|
1003
|
-
let locResults = results;
|
|
1004
|
-
|
|
1005
|
-
if (locResults && locResults[0] === 'needupdate') {
|
|
1006
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Entity Cache Not Loading', ['unknown'], null, null, null);
|
|
1007
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1008
|
-
this.repeatCacheCount += 1;
|
|
1009
|
-
return callback(null, errorObj);
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
// if an error occured, return the error
|
|
1013
|
-
if (locResults && locResults[0] === 'error') {
|
|
1014
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Error Verifying Entity Cache', null, null, null, null);
|
|
1015
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1016
|
-
return callback(null, errorObj);
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
// go through the response and change to true/false
|
|
1020
|
-
if (locResults) {
|
|
1021
|
-
// if not an array, just convert the return
|
|
1022
|
-
if (!Array.isArray(locResults)) {
|
|
1023
|
-
if (locResults === 'found') {
|
|
1024
|
-
locResults = [true];
|
|
1025
|
-
} else {
|
|
1026
|
-
locResults = [false];
|
|
1027
|
-
}
|
|
1028
|
-
} else {
|
|
1029
|
-
const temp = [];
|
|
1030
|
-
|
|
1031
|
-
// go through each element in the array to convert
|
|
1032
|
-
for (let r = 0; r < locResults.length; r += 1) {
|
|
1033
|
-
if (locResults[r] === 'found') {
|
|
1034
|
-
temp.push(true);
|
|
1035
|
-
} else {
|
|
1036
|
-
temp.push(false);
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
locResults = temp;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
989
|
|
|
1043
|
-
|
|
1044
|
-
return callback(locResults);
|
|
990
|
+
return this.requestHandlerInst.populateEntityCache(entityTypes, callback);
|
|
1045
991
|
}
|
|
1046
992
|
|
|
1047
993
|
/**
|
|
1048
|
-
* @summary
|
|
1049
|
-
* all of the capabilities for the current adapter
|
|
994
|
+
* @summary Retrieves data from cache for specified entity type
|
|
1050
995
|
*
|
|
1051
|
-
* @function
|
|
1052
|
-
*
|
|
1053
|
-
* @
|
|
996
|
+
* @function iapRetrieveEntitiesCache
|
|
997
|
+
* @param {String} entityType - entity of which to retrieve
|
|
998
|
+
* @param {Object} options - settings of which data to return and how to return it
|
|
999
|
+
* @param {Callback} callback - the data if it was retrieved
|
|
1054
1000
|
*/
|
|
1055
|
-
|
|
1056
|
-
const origin = `${this.
|
|
1001
|
+
iapRetrieveEntitiesCache(entityType, options, callback) {
|
|
1002
|
+
const origin = `${this.myid}-adapterBase-iapRetrieveEntitiesCache`;
|
|
1057
1003
|
log.trace(origin);
|
|
1058
1004
|
|
|
1059
|
-
|
|
1060
|
-
try {
|
|
1061
|
-
return this.requestHandlerInst.getAllCapabilities();
|
|
1062
|
-
} catch (e) {
|
|
1063
|
-
return [];
|
|
1064
|
-
}
|
|
1005
|
+
return this.requestHandlerInst.retrieveEntitiesCache(entityType, options, callback);
|
|
1065
1006
|
}
|
|
1066
1007
|
|
|
1008
|
+
/* ********************************************** */
|
|
1009
|
+
/* */
|
|
1010
|
+
/* EXPOSES BROKER CALLS */
|
|
1011
|
+
/* */
|
|
1012
|
+
/* ********************************************** */
|
|
1067
1013
|
/**
|
|
1068
1014
|
* @summary Determines if this adapter supports any in a list of entities
|
|
1069
1015
|
*
|
|
@@ -1075,348 +1021,61 @@ class AdapterBase extends EventEmitterCl {
|
|
|
1075
1021
|
* value is true or false
|
|
1076
1022
|
*/
|
|
1077
1023
|
hasEntities(entityType, entityList, callback) {
|
|
1078
|
-
const origin = `${this.id}-
|
|
1024
|
+
const origin = `${this.id}-adapterBase-hasEntities`;
|
|
1079
1025
|
log.trace(origin);
|
|
1080
1026
|
|
|
1081
|
-
|
|
1082
|
-
case 'Device':
|
|
1083
|
-
return this.hasDevices(entityList, callback);
|
|
1084
|
-
default:
|
|
1085
|
-
return callback(null, `${this.id} does not support entity ${entityType}`);
|
|
1086
|
-
}
|
|
1027
|
+
return this.requestHandlerInst.hasEntities(entityType, entityList, callback);
|
|
1087
1028
|
}
|
|
1088
1029
|
|
|
1089
1030
|
/**
|
|
1090
|
-
* @summary
|
|
1031
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
1091
1032
|
*
|
|
1092
|
-
* @
|
|
1093
|
-
* @param {
|
|
1033
|
+
* @function hasEntitiesAuth
|
|
1034
|
+
* @param {String} entityType - the entity type to check for
|
|
1035
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
1036
|
+
* @param {Object} callOptions - Additional options used to make request, including auth headers, AWS service, or datatypes
|
|
1037
|
+
*
|
|
1038
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
1094
1039
|
* value is true or false
|
|
1095
1040
|
*/
|
|
1096
|
-
|
|
1097
|
-
const origin = `${this.id}-
|
|
1041
|
+
hasEntitiesAuth(entityType, entityList, callOptions, callback) {
|
|
1042
|
+
const origin = `${this.id}-adapterBase-hasEntitiesAuth`;
|
|
1098
1043
|
log.trace(origin);
|
|
1099
1044
|
|
|
1100
|
-
|
|
1101
|
-
// eslint-disable-next-line no-param-reassign
|
|
1102
|
-
map[device] = false;
|
|
1103
|
-
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
|
1104
|
-
return map;
|
|
1105
|
-
}, {});
|
|
1106
|
-
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
|
1107
|
-
this.getDevice(device, (result, error) => {
|
|
1108
|
-
if (error) {
|
|
1109
|
-
log.debug(`In map error: ${JSON.stringify(device)}`);
|
|
1110
|
-
return resolve({ name: device, found: false });
|
|
1111
|
-
}
|
|
1112
|
-
log.debug(`In map: ${JSON.stringify(device)}`);
|
|
1113
|
-
return resolve({ name: device, found: true });
|
|
1114
|
-
});
|
|
1115
|
-
}));
|
|
1116
|
-
Promise.all(apiCalls).then((results) => {
|
|
1117
|
-
results.forEach((device) => {
|
|
1118
|
-
findings[device.name] = device.found;
|
|
1119
|
-
});
|
|
1120
|
-
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
|
1121
|
-
return callback(findings);
|
|
1122
|
-
}).catch((errors) => {
|
|
1123
|
-
log.error('Unable to do device lookup.');
|
|
1124
|
-
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
|
1125
|
-
});
|
|
1045
|
+
return this.requestHandlerInst.hasEntitiesAuth(entityType, entityList, callOptions, callback);
|
|
1126
1046
|
}
|
|
1127
1047
|
|
|
1128
1048
|
/**
|
|
1129
|
-
* @summary
|
|
1049
|
+
* @summary Get Appliance that match the deviceName
|
|
1130
1050
|
*
|
|
1131
|
-
* @function
|
|
1132
|
-
* @param {
|
|
1133
|
-
* @param {object} callProps - the proeprties for the broker call (required)
|
|
1134
|
-
* @param {object} devResp - the device details to extract needed inputs (required)
|
|
1135
|
-
* @param {string} filterName - any filter to search on (required)
|
|
1051
|
+
* @function getDevice
|
|
1052
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
1136
1053
|
*
|
|
1137
|
-
* @param {getCallback} callback - a callback function to return the result
|
|
1054
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1055
|
+
* (appliance) or the error
|
|
1138
1056
|
*/
|
|
1139
|
-
|
|
1140
|
-
const
|
|
1141
|
-
const origin = `${this.id}-${meth}`;
|
|
1057
|
+
getDevice(deviceName, callback) {
|
|
1058
|
+
const origin = `${this.id}-adapterBase-getDevice`;
|
|
1142
1059
|
log.trace(origin);
|
|
1143
1060
|
|
|
1144
|
-
|
|
1145
|
-
let uriPath = '';
|
|
1146
|
-
let uriMethod = 'GET';
|
|
1147
|
-
let callQuery = {};
|
|
1148
|
-
let callBody = {};
|
|
1149
|
-
let callHeaders = {};
|
|
1150
|
-
let handleFail = 'fail';
|
|
1151
|
-
let ostypePrefix = '';
|
|
1152
|
-
let statusValue = 'true';
|
|
1153
|
-
if (callProps.path) {
|
|
1154
|
-
uriPath = `${callProps.path}`;
|
|
1155
|
-
|
|
1156
|
-
// make any necessary changes to the path
|
|
1157
|
-
if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
|
|
1158
|
-
const rqKeys = Object.keys(callProps.requestFields);
|
|
1159
|
-
|
|
1160
|
-
// get the field from the provided device
|
|
1161
|
-
for (let rq = 0; rq < rqKeys.length; rq += 1) {
|
|
1162
|
-
const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
|
|
1163
|
-
|
|
1164
|
-
// put the value into the path - if it has been specified in the path
|
|
1165
|
-
uriPath = uriPath.replace(`{${rqKeys[rq]}}`, fieldValue);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
if (callProps.method) {
|
|
1170
|
-
uriMethod = callProps.method;
|
|
1171
|
-
}
|
|
1172
|
-
if (callProps.query) {
|
|
1173
|
-
callQuery = callProps.query;
|
|
1174
|
-
|
|
1175
|
-
// go through the query params to check for variable values
|
|
1176
|
-
const cpKeys = Object.keys(callQuery);
|
|
1177
|
-
for (let cp = 0; cp < cpKeys.length; cp += 1) {
|
|
1178
|
-
if (callQuery[cpKeys[cp]].startsWith('{') && callQuery[cpKeys[cp]].endsWith('}')) {
|
|
1179
|
-
// make any necessary changes to the query params
|
|
1180
|
-
if (devResp !== null && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
|
|
1181
|
-
const rqKeys = Object.keys(callProps.requestFields);
|
|
1182
|
-
|
|
1183
|
-
// get the field from the provided device
|
|
1184
|
-
for (let rq = 0; rq < rqKeys.length; rq += 1) {
|
|
1185
|
-
if (cpKeys[cp] === rqKeys[rq]) {
|
|
1186
|
-
const fieldValue = getDataFromSources(callProps.requestFields[rqKeys[rq]], devResp);
|
|
1187
|
-
|
|
1188
|
-
// put the value into the query - if it has been specified in the query
|
|
1189
|
-
callQuery[cpKeys[cp]] = fieldValue;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
if (callProps.body) {
|
|
1197
|
-
callBody = callProps.body;
|
|
1198
|
-
}
|
|
1199
|
-
if (callProps.headers) {
|
|
1200
|
-
callHeaders = callProps.headers;
|
|
1201
|
-
}
|
|
1202
|
-
if (callProps.handleFailure) {
|
|
1203
|
-
handleFail = callProps.handleFailure;
|
|
1204
|
-
}
|
|
1205
|
-
if (callProps.responseFields && callProps.responseFields.ostypePrefix) {
|
|
1206
|
-
ostypePrefix = callProps.responseFields.ostypePrefix;
|
|
1207
|
-
}
|
|
1208
|
-
if (callProps.responseFields && callProps.responseFields.statusValue) {
|
|
1209
|
-
statusValue = callProps.responseFields.statusValue;
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
1213
|
-
// !! you can also replace with a specific call if that is easier
|
|
1214
|
-
return this.genericAdapterRequest(uriPath, uriMethod, callQuery, callBody, callHeaders, (result, error) => {
|
|
1215
|
-
// if we received an error or their is no response on the results return an error
|
|
1216
|
-
if (error) {
|
|
1217
|
-
if (handleFail === 'fail') {
|
|
1218
|
-
return callback(null, error);
|
|
1219
|
-
}
|
|
1220
|
-
return callback({}, null);
|
|
1221
|
-
}
|
|
1222
|
-
if (!result.response) {
|
|
1223
|
-
if (handleFail === 'fail') {
|
|
1224
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', [brokCall], null, null, null);
|
|
1225
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1226
|
-
return callback(null, errorObj);
|
|
1227
|
-
}
|
|
1228
|
-
return callback({}, null);
|
|
1229
|
-
}
|
|
1230
|
-
|
|
1231
|
-
// get the keys for the response fields
|
|
1232
|
-
let rfKeys = [];
|
|
1233
|
-
if (callProps.responseFields && Object.keys(callProps.responseFields).length > 0) {
|
|
1234
|
-
rfKeys = Object.keys(callProps.responseFields);
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1237
|
-
// if we got an array returned (e.g. getDevicesFitered)
|
|
1238
|
-
if (Array.isArray(result.response)) {
|
|
1239
|
-
const listDevices = [];
|
|
1240
|
-
for (let a = 0; a < result.response.length; a += 1) {
|
|
1241
|
-
const thisDevice = result.response[a];
|
|
1242
|
-
for (let rf = 0; rf < rfKeys.length; rf += 1) {
|
|
1243
|
-
if (rfKeys[rf] !== 'ostypePrefix') {
|
|
1244
|
-
let fieldValue = getDataFromSources(callProps.responseFields[rfKeys[rf]], [thisDevice, devResp, callProps.requestFields]);
|
|
1245
|
-
|
|
1246
|
-
// if the field is ostype - need to add prefix
|
|
1247
|
-
if (rfKeys[rf] === 'ostype' && typeof fieldValue === 'string') {
|
|
1248
|
-
fieldValue = ostypePrefix + fieldValue;
|
|
1249
|
-
}
|
|
1250
|
-
// if there is a status to set, set it
|
|
1251
|
-
if (rfKeys[rf] === 'status') {
|
|
1252
|
-
// if really looking for just a good response
|
|
1253
|
-
if (callProps.responseFields[rfKeys[rf]] === 'return2xx' && result.icode === statusValue.toString()) {
|
|
1254
|
-
thisDevice.isAlive = true;
|
|
1255
|
-
} else if (fieldValue.toString() === statusValue.toString()) {
|
|
1256
|
-
thisDevice.isAlive = true;
|
|
1257
|
-
} else {
|
|
1258
|
-
thisDevice.isAlive = false;
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
// if we found a good value
|
|
1262
|
-
thisDevice[rfKeys[rf]] = fieldValue;
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
// if there is no filter - add the device to the list
|
|
1267
|
-
if (!filterName || filterName.length === 0) {
|
|
1268
|
-
listDevices.push(thisDevice);
|
|
1269
|
-
} else {
|
|
1270
|
-
// if we have to match a filter
|
|
1271
|
-
let found = false;
|
|
1272
|
-
for (let f = 0; f < filterName.length; f += 1) {
|
|
1273
|
-
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
1274
|
-
found = true;
|
|
1275
|
-
break;
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
// matching device
|
|
1279
|
-
if (found) {
|
|
1280
|
-
listDevices.push(thisDevice);
|
|
1281
|
-
}
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
// return the array of devices
|
|
1286
|
-
return callback(listDevices, null);
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
// if this is not an array - just about everything else, just handle as a single object
|
|
1290
|
-
let thisDevice = result.response;
|
|
1291
|
-
for (let rf = 0; rf < rfKeys.length; rf += 1) {
|
|
1292
|
-
// skip ostypePrefix since it is not a field
|
|
1293
|
-
if (rfKeys[rf] !== 'ostypePrefix') {
|
|
1294
|
-
let fieldValue = getDataFromSources(callProps.responseFields[rfKeys[rf]], [thisDevice, devResp, callProps.requestFields]);
|
|
1295
|
-
|
|
1296
|
-
// if the field is ostype - need to add prefix
|
|
1297
|
-
if (rfKeys[rf] === 'ostype' && typeof fieldValue === 'string') {
|
|
1298
|
-
fieldValue = ostypePrefix + fieldValue;
|
|
1299
|
-
}
|
|
1300
|
-
// if there is a status to set, set it
|
|
1301
|
-
if (rfKeys[rf] === 'status') {
|
|
1302
|
-
// if really looking for just a good response
|
|
1303
|
-
if (callProps.responseFields[rfKeys[rf]] === 'return2xx' && result.icode === statusValue.toString()) {
|
|
1304
|
-
thisDevice.isAlive = true;
|
|
1305
|
-
} else if (fieldValue.toString() === statusValue.toString()) {
|
|
1306
|
-
thisDevice.isAlive = true;
|
|
1307
|
-
} else {
|
|
1308
|
-
thisDevice.isAlive = false;
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
// if we found a good value
|
|
1312
|
-
thisDevice[rfKeys[rf]] = fieldValue;
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
// if there is a filter - check the device is in the list
|
|
1317
|
-
if (filterName && filterName.length > 0) {
|
|
1318
|
-
let found = false;
|
|
1319
|
-
for (let f = 0; f < filterName.length; f += 1) {
|
|
1320
|
-
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
1321
|
-
found = true;
|
|
1322
|
-
break;
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
// no matching device - clear the device
|
|
1326
|
-
if (!found) {
|
|
1327
|
-
thisDevice = {};
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
return callback(thisDevice, null);
|
|
1332
|
-
});
|
|
1333
|
-
} catch (e) {
|
|
1334
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, e);
|
|
1335
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1336
|
-
return callback(null, errorObj);
|
|
1337
|
-
}
|
|
1061
|
+
return this.requestHandlerInst.getDevice(deviceName, callback);
|
|
1338
1062
|
}
|
|
1339
1063
|
|
|
1340
1064
|
/**
|
|
1341
1065
|
* @summary Get Appliance that match the deviceName
|
|
1342
1066
|
*
|
|
1343
|
-
* @function
|
|
1067
|
+
* @function getDeviceAuth
|
|
1344
1068
|
* @param {String} deviceName - the deviceName to find (required)
|
|
1069
|
+
* @param {Object} callOptions - Additional options used to make request, including auth headers, AWS service, or datatypes
|
|
1345
1070
|
*
|
|
1346
1071
|
* @param {getCallback} callback - a callback function to return the result
|
|
1347
1072
|
* (appliance) or the error
|
|
1348
1073
|
*/
|
|
1349
|
-
|
|
1350
|
-
const
|
|
1351
|
-
const origin = `${this.id}-${meth}`;
|
|
1074
|
+
getDeviceAuth(deviceName, callOptions, callback) {
|
|
1075
|
+
const origin = `${this.id}-adapterBase-getDeviceAuth`;
|
|
1352
1076
|
log.trace(origin);
|
|
1353
1077
|
|
|
1354
|
-
|
|
1355
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevice || this.allProps.devicebroker.getDevice.length === 0 || !this.allProps.devicebroker.getDevice[0].path) {
|
|
1356
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevice.path'], null, null, null);
|
|
1357
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1358
|
-
return callback(null, errorObj);
|
|
1359
|
-
}
|
|
1360
|
-
|
|
1361
|
-
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
1362
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
1363
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
1364
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1365
|
-
return callback(null, errorObj);
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
try {
|
|
1369
|
-
// need to get the device so we can convert the deviceName to an id
|
|
1370
|
-
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
1371
|
-
const opts = {
|
|
1372
|
-
filter: {
|
|
1373
|
-
name: deviceName
|
|
1374
|
-
}
|
|
1375
|
-
};
|
|
1376
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
1377
|
-
// if we received an error or their is no response on the results return an error
|
|
1378
|
-
if (ferr) {
|
|
1379
|
-
return callback(null, ferr);
|
|
1380
|
-
}
|
|
1381
|
-
if (devs.list.length < 1) {
|
|
1382
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
1383
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1384
|
-
return callback(null, errorObj);
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
const callPromises = [];
|
|
1388
|
-
for (let i = 0; i < this.allProps.devicebroker.getDevice.length; i += 1) {
|
|
1389
|
-
// Perform component calls here.
|
|
1390
|
-
callPromises.push(
|
|
1391
|
-
new Promise((resolve, reject) => {
|
|
1392
|
-
this.iapMakeBrokerCall('getDevice', this.allProps.devicebroker.getDevice[i], [devs.list[0]], null, (callRet, callErr) => {
|
|
1393
|
-
// return an error
|
|
1394
|
-
if (callErr) {
|
|
1395
|
-
reject(callErr);
|
|
1396
|
-
} else {
|
|
1397
|
-
// return the data
|
|
1398
|
-
resolve(callRet);
|
|
1399
|
-
}
|
|
1400
|
-
});
|
|
1401
|
-
})
|
|
1402
|
-
);
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
// return an array of repsonses
|
|
1406
|
-
return Promise.all(callPromises).then((results) => {
|
|
1407
|
-
let myResult = {};
|
|
1408
|
-
results.forEach((result) => {
|
|
1409
|
-
myResult = { ...myResult, ...result };
|
|
1410
|
-
});
|
|
1411
|
-
|
|
1412
|
-
return callback(myResult, null);
|
|
1413
|
-
});
|
|
1414
|
-
});
|
|
1415
|
-
} catch (ex) {
|
|
1416
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1417
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1418
|
-
return callback(null, errorObj);
|
|
1419
|
-
}
|
|
1078
|
+
return this.requestHandlerInst.getDeviceAuth(deviceName, callOptions, callback);
|
|
1420
1079
|
}
|
|
1421
1080
|
|
|
1422
1081
|
/**
|
|
@@ -1429,89 +1088,27 @@ class AdapterBase extends EventEmitterCl {
|
|
|
1429
1088
|
* (appliances) or the error
|
|
1430
1089
|
*/
|
|
1431
1090
|
getDevicesFiltered(options, callback) {
|
|
1432
|
-
const
|
|
1433
|
-
const origin = `${this.id}-${meth}`;
|
|
1091
|
+
const origin = `${this.id}-adapterBase-getDevicesFiltered`;
|
|
1434
1092
|
log.trace(origin);
|
|
1435
1093
|
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevicesFiltered.path'], null, null, null);
|
|
1439
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1440
|
-
return callback(null, errorObj);
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
// verify the required fields have been provided
|
|
1444
|
-
if (options === undefined || options === null || options === '' || options.length === 0) {
|
|
1445
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
|
1446
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1447
|
-
return callback(null, errorObj);
|
|
1448
|
-
}
|
|
1449
|
-
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
|
1450
|
-
|
|
1451
|
-
try {
|
|
1452
|
-
// TODO - get pagination working
|
|
1453
|
-
// const nextToken = options.start;
|
|
1454
|
-
// const maxResults = options.limit;
|
|
1455
|
-
|
|
1456
|
-
// set up the filter of Device Names
|
|
1457
|
-
let filterName = [];
|
|
1458
|
-
if (options && options.filter && options.filter.name) {
|
|
1459
|
-
// when this hack is removed, remove the lint ignore above
|
|
1460
|
-
if (Array.isArray(options.filter.name)) {
|
|
1461
|
-
// eslint-disable-next-line prefer-destructuring
|
|
1462
|
-
filterName = options.filter.name;
|
|
1463
|
-
} else {
|
|
1464
|
-
filterName = [options.filter.name];
|
|
1465
|
-
}
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
// TODO - get sort and order working
|
|
1469
|
-
/*
|
|
1470
|
-
if (options && options.sort) {
|
|
1471
|
-
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
|
1472
|
-
}
|
|
1473
|
-
if (options && options.order) {
|
|
1474
|
-
reqObj.uriOptions.order = options.order;
|
|
1475
|
-
}
|
|
1476
|
-
*/
|
|
1477
|
-
const callPromises = [];
|
|
1478
|
-
for (let i = 0; i < this.allProps.devicebroker.getDevicesFiltered.length; i += 1) {
|
|
1479
|
-
// Perform component calls here.
|
|
1480
|
-
callPromises.push(
|
|
1481
|
-
new Promise((resolve, reject) => {
|
|
1482
|
-
this.iapMakeBrokerCall('getDevicesFiltered', this.allProps.devicebroker.getDevicesFiltered[i], [{ fake: 'fakedata' }], filterName, (callRet, callErr) => {
|
|
1483
|
-
// return an error
|
|
1484
|
-
if (callErr) {
|
|
1485
|
-
reject(callErr);
|
|
1486
|
-
} else {
|
|
1487
|
-
// return the data
|
|
1488
|
-
resolve(callRet);
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
})
|
|
1492
|
-
);
|
|
1493
|
-
}
|
|
1094
|
+
return this.requestHandlerInst.getDevicesFiltered(options, callback);
|
|
1095
|
+
}
|
|
1494
1096
|
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1097
|
+
/**
|
|
1098
|
+
* @summary Get Appliances that match the filter
|
|
1099
|
+
*
|
|
1100
|
+
* @function getDevicesFilteredAuth
|
|
1101
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
1102
|
+
* @param {Object} callOptions - Additional options used to make request, including auth headers, AWS service, or datatypes
|
|
1103
|
+
*
|
|
1104
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1105
|
+
* (appliances) or the error
|
|
1106
|
+
*/
|
|
1107
|
+
getDevicesFilteredAuth(options, callOptions, callback) {
|
|
1108
|
+
const origin = `${this.id}-adapterBase-getDevicesFilteredAuth`;
|
|
1109
|
+
log.trace(origin);
|
|
1505
1110
|
|
|
1506
|
-
|
|
1507
|
-
log.debug(`Devices: ${JSON.stringify(myResult)}`);
|
|
1508
|
-
return callback({ total: myResult.length, list: myResult });
|
|
1509
|
-
});
|
|
1510
|
-
} catch (ex) {
|
|
1511
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1512
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1513
|
-
return callback(null, errorObj);
|
|
1514
|
-
}
|
|
1111
|
+
return this.requestHandlerInst.getDevicesFilteredAuth(options, callOptions, callback);
|
|
1515
1112
|
}
|
|
1516
1113
|
|
|
1517
1114
|
/**
|
|
@@ -1524,80 +1121,27 @@ class AdapterBase extends EventEmitterCl {
|
|
|
1524
1121
|
* (appliance isAlive) or the error
|
|
1525
1122
|
*/
|
|
1526
1123
|
isAlive(deviceName, callback) {
|
|
1527
|
-
const
|
|
1528
|
-
const origin = `${this.id}-${meth}`;
|
|
1124
|
+
const origin = `${this.id}-adapterBase-isAlive`;
|
|
1529
1125
|
log.trace(origin);
|
|
1530
1126
|
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.isAlive.path'], null, null, null);
|
|
1534
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1535
|
-
return callback(null, errorObj);
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
// verify the required fields have been provided
|
|
1539
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
1540
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
1541
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1542
|
-
return callback(null, errorObj);
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
try {
|
|
1546
|
-
// need to get the device so we can convert the deviceName to an id
|
|
1547
|
-
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
1548
|
-
const opts = {
|
|
1549
|
-
filter: {
|
|
1550
|
-
name: deviceName
|
|
1551
|
-
}
|
|
1552
|
-
};
|
|
1553
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
1554
|
-
// if we received an error or their is no response on the results return an error
|
|
1555
|
-
if (ferr) {
|
|
1556
|
-
return callback(null, ferr);
|
|
1557
|
-
}
|
|
1558
|
-
if (devs.list.length < 1) {
|
|
1559
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
1560
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1561
|
-
return callback(null, errorObj);
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
const callPromises = [];
|
|
1565
|
-
for (let i = 0; i < this.allProps.devicebroker.isAlive.length; i += 1) {
|
|
1566
|
-
// Perform component calls here.
|
|
1567
|
-
callPromises.push(
|
|
1568
|
-
new Promise((resolve, reject) => {
|
|
1569
|
-
this.iapMakeBrokerCall('isAlive', this.allProps.devicebroker.isAlive[i], [devs.list[0]], null, (callRet, callErr) => {
|
|
1570
|
-
// return an error
|
|
1571
|
-
if (callErr) {
|
|
1572
|
-
reject(callErr);
|
|
1573
|
-
} else {
|
|
1574
|
-
// return the data
|
|
1575
|
-
resolve(callRet);
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1578
|
-
})
|
|
1579
|
-
);
|
|
1580
|
-
}
|
|
1127
|
+
return this.requestHandlerInst.isAlive(deviceName, callback);
|
|
1128
|
+
}
|
|
1581
1129
|
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1130
|
+
/**
|
|
1131
|
+
* @summary Gets the status for the provided appliance
|
|
1132
|
+
*
|
|
1133
|
+
* @function isAliveAuth
|
|
1134
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
1135
|
+
* @param {Object} callOptions - Additional options used to make request, including auth headers, AWS service, or datatypes
|
|
1136
|
+
*
|
|
1137
|
+
* @param {configCallback} callback - callback function to return the result
|
|
1138
|
+
* (appliance isAliveAuth) or the error
|
|
1139
|
+
*/
|
|
1140
|
+
isAliveAuth(deviceName, callOptions, callback) {
|
|
1141
|
+
const origin = `${this.id}-adapterBase-isAliveAuth`;
|
|
1142
|
+
log.trace(origin);
|
|
1588
1143
|
|
|
1589
|
-
|
|
1590
|
-
if (myResult.isAlive !== null && myResult.isAlive !== undefined && myResult.isAlive === false) {
|
|
1591
|
-
response = false;
|
|
1592
|
-
}
|
|
1593
|
-
return callback(response);
|
|
1594
|
-
});
|
|
1595
|
-
});
|
|
1596
|
-
} catch (ex) {
|
|
1597
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1598
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1599
|
-
return callback(null, errorObj);
|
|
1600
|
-
}
|
|
1144
|
+
return this.requestHandlerInst.isAliveAuth(deviceName, callOptions, callback);
|
|
1601
1145
|
}
|
|
1602
1146
|
|
|
1603
1147
|
/**
|
|
@@ -1611,80 +1155,28 @@ class AdapterBase extends EventEmitterCl {
|
|
|
1611
1155
|
* (appliance config) or the error
|
|
1612
1156
|
*/
|
|
1613
1157
|
getConfig(deviceName, format, callback) {
|
|
1614
|
-
const
|
|
1615
|
-
const origin = `${this.id}-${meth}`;
|
|
1158
|
+
const origin = `${this.id}-adapterBase-getConfig`;
|
|
1616
1159
|
log.trace(origin);
|
|
1617
1160
|
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getConfig.path'], null, null, null);
|
|
1621
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1622
|
-
return callback(null, errorObj);
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
// verify the required fields have been provided
|
|
1626
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
1627
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
1628
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1629
|
-
return callback(null, errorObj);
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
try {
|
|
1633
|
-
// need to get the device so we can convert the deviceName to an id
|
|
1634
|
-
// !! if we can do a lookup by name the getDevicesFiltered may not be necessary
|
|
1635
|
-
const opts = {
|
|
1636
|
-
filter: {
|
|
1637
|
-
name: deviceName
|
|
1638
|
-
}
|
|
1639
|
-
};
|
|
1640
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
1641
|
-
// if we received an error or their is no response on the results return an error
|
|
1642
|
-
if (ferr) {
|
|
1643
|
-
return callback(null, ferr);
|
|
1644
|
-
}
|
|
1645
|
-
if (devs.list.length < 1) {
|
|
1646
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
1647
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1648
|
-
return callback(null, errorObj);
|
|
1649
|
-
}
|
|
1161
|
+
return this.requestHandlerInst.getConfig(deviceName, format, callback);
|
|
1162
|
+
}
|
|
1650
1163
|
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
})
|
|
1666
|
-
);
|
|
1667
|
-
}
|
|
1164
|
+
/**
|
|
1165
|
+
* @summary Gets a config for the provided Appliance
|
|
1166
|
+
*
|
|
1167
|
+
* @function getConfigAuth
|
|
1168
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
1169
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
1170
|
+
* @param {Object} callOptions - Additional options used to make request, including auth headers, AWS service, or datatypes
|
|
1171
|
+
*
|
|
1172
|
+
* @param {configCallback} callback - callback function to return the result
|
|
1173
|
+
* (appliance config) or the error
|
|
1174
|
+
*/
|
|
1175
|
+
getConfigAuth(deviceName, format, callOptions, callback) {
|
|
1176
|
+
const origin = `${this.id}-adapterBase-getConfigAuth`;
|
|
1177
|
+
log.trace(origin);
|
|
1668
1178
|
|
|
1669
|
-
|
|
1670
|
-
return Promise.all(callPromises).then((results) => {
|
|
1671
|
-
let myResult = {};
|
|
1672
|
-
results.forEach((result) => {
|
|
1673
|
-
myResult = { ...myResult, ...result };
|
|
1674
|
-
});
|
|
1675
|
-
|
|
1676
|
-
// return the result
|
|
1677
|
-
const newResponse = {
|
|
1678
|
-
response: JSON.stringify(myResult, null, 2)
|
|
1679
|
-
};
|
|
1680
|
-
return callback(newResponse, null);
|
|
1681
|
-
});
|
|
1682
|
-
});
|
|
1683
|
-
} catch (ex) {
|
|
1684
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1685
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1686
|
-
return callback(null, errorObj);
|
|
1687
|
-
}
|
|
1179
|
+
return this.requestHandlerInst.getConfigAuth(deviceName, format, callOptions, callback);
|
|
1688
1180
|
}
|
|
1689
1181
|
|
|
1690
1182
|
/**
|
|
@@ -1696,47 +1188,258 @@ class AdapterBase extends EventEmitterCl {
|
|
|
1696
1188
|
* (count) or the error
|
|
1697
1189
|
*/
|
|
1698
1190
|
iapGetDeviceCount(callback) {
|
|
1699
|
-
const
|
|
1191
|
+
const origin = `${this.id}-adapterBase-iapGetDeviceCount`;
|
|
1192
|
+
log.trace(origin);
|
|
1193
|
+
|
|
1194
|
+
return this.requestHandlerInst.iapGetDeviceCount(callback);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* @summary Gets the device count from the system
|
|
1199
|
+
*
|
|
1200
|
+
* @function iapGetDeviceCountAuth
|
|
1201
|
+
* @param {Object} callOptions - Additional options used to make request, including auth headers, AWS service, or datatypes
|
|
1202
|
+
*
|
|
1203
|
+
* @param {getCallback} callback - callback function to return the result
|
|
1204
|
+
* (count) or the error
|
|
1205
|
+
*/
|
|
1206
|
+
iapGetDeviceCountAuth(callOptions, callback) {
|
|
1207
|
+
const origin = `${this.id}-adapterBase-iapGetDeviceCountAuth`;
|
|
1208
|
+
log.trace(origin);
|
|
1209
|
+
|
|
1210
|
+
return this.requestHandlerInst.iapGetDeviceCountAuth(callOptions, callback);
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
/* ********************************************** */
|
|
1214
|
+
/* */
|
|
1215
|
+
/* EXPOSES GENERIC HANDLER */
|
|
1216
|
+
/* */
|
|
1217
|
+
/* ********************************************** */
|
|
1218
|
+
/**
|
|
1219
|
+
* Makes the requested generic call
|
|
1220
|
+
*
|
|
1221
|
+
* @function iapExpandedGenericAdapterRequest
|
|
1222
|
+
* @param {Object} metadata - metadata for the call (optional).
|
|
1223
|
+
* Can be a stringified Object.
|
|
1224
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (optional)
|
|
1225
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (optional)
|
|
1226
|
+
* @param {Object} pathVars - the parameters to be put within the url path (optional).
|
|
1227
|
+
* Can be a stringified Object.
|
|
1228
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
1229
|
+
* Can be a stringified Object.
|
|
1230
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
1231
|
+
* Can be a stringified Object.
|
|
1232
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
1233
|
+
* Can be a stringified Object.
|
|
1234
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
1235
|
+
* or the error
|
|
1236
|
+
*/
|
|
1237
|
+
iapExpandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback) {
|
|
1238
|
+
const origin = `${this.myid}-adapterBase-iapExpandedGenericAdapterRequest`;
|
|
1239
|
+
log.trace(origin);
|
|
1240
|
+
|
|
1241
|
+
return this.requestHandlerInst.expandedGenericAdapterRequest(metadata, uriPath, restMethod, pathVars, queryData, requestBody, addlHeaders, callback);
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* Makes the requested generic call
|
|
1246
|
+
*
|
|
1247
|
+
* @function genericAdapterRequest
|
|
1248
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
|
1249
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
|
1250
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
1251
|
+
* Can be a stringified Object.
|
|
1252
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
1253
|
+
* Can be a stringified Object.
|
|
1254
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
1255
|
+
* Can be a stringified Object.
|
|
1256
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
1257
|
+
* or the error
|
|
1258
|
+
*/
|
|
1259
|
+
genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
|
1260
|
+
const origin = `${this.myid}-adapterBase-genericAdapterRequest`;
|
|
1261
|
+
log.trace(origin);
|
|
1262
|
+
|
|
1263
|
+
return this.requestHandlerInst.genericAdapterRequest(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
/**
|
|
1267
|
+
* Makes the requested generic call with no base path or version
|
|
1268
|
+
*
|
|
1269
|
+
* @function genericAdapterRequestNoBasePath
|
|
1270
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
|
1271
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
|
1272
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
1273
|
+
* Can be a stringified Object.
|
|
1274
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
1275
|
+
* Can be a stringified Object.
|
|
1276
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
1277
|
+
* Can be a stringified Object.
|
|
1278
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
1279
|
+
* or the error
|
|
1280
|
+
*/
|
|
1281
|
+
genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
|
1282
|
+
const origin = `${this.myid}-adapterBase-genericAdapterRequestNoBasePath`;
|
|
1283
|
+
log.trace(origin);
|
|
1284
|
+
|
|
1285
|
+
return this.requestHandlerInst.genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback);
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/* ********************************************** */
|
|
1289
|
+
/* */
|
|
1290
|
+
/* EXPOSES INVENTORY CALLS */
|
|
1291
|
+
/* */
|
|
1292
|
+
/* ********************************************** */
|
|
1293
|
+
/**
|
|
1294
|
+
* @summary run the adapter lint script to return the results.
|
|
1295
|
+
*
|
|
1296
|
+
* @function iapRunAdapterLint
|
|
1297
|
+
*
|
|
1298
|
+
* @return {Object} - containing the results of the lint call.
|
|
1299
|
+
*/
|
|
1300
|
+
iapRunAdapterLint(callback) {
|
|
1301
|
+
const meth = 'adapterBase-iapRunAdapterLint';
|
|
1700
1302
|
const origin = `${this.id}-${meth}`;
|
|
1701
1303
|
log.trace(origin);
|
|
1304
|
+
let command = null;
|
|
1702
1305
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1306
|
+
if (fs.existsSync('package.json')) {
|
|
1307
|
+
const packageData = require('./package.json');
|
|
1308
|
+
|
|
1309
|
+
// check if 'test', 'test:unit', 'test:integration' exists in package.json file
|
|
1310
|
+
if (!packageData.scripts || !packageData.scripts['lint:errors']) {
|
|
1311
|
+
log.error('The required script does not exist in the package.json file');
|
|
1312
|
+
return callback(null, 'The required script does not exist in the package.json file');
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
// execute 'npm run lint:errors' command
|
|
1316
|
+
command = spawnSync('npm', ['run', 'lint:errors'], { cwd: __dirname, encoding: 'utf-8' });
|
|
1317
|
+
|
|
1318
|
+
// analyze and format the response
|
|
1319
|
+
const result = {
|
|
1320
|
+
status: 'SUCCESS'
|
|
1321
|
+
};
|
|
1322
|
+
if (command.status !== 0) {
|
|
1323
|
+
result.status = 'FAILED';
|
|
1324
|
+
result.output = command.stdout;
|
|
1325
|
+
}
|
|
1326
|
+
return callback(result);
|
|
1708
1327
|
}
|
|
1709
1328
|
|
|
1710
|
-
|
|
1329
|
+
log.error('Package Not Found');
|
|
1330
|
+
return callback(null, 'Package Not Found');
|
|
1331
|
+
}
|
|
1711
1332
|
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1333
|
+
/**
|
|
1334
|
+
* @summary run the adapter test scripts (baseunit and unit) to return the results.
|
|
1335
|
+
* can not run integration as there can be implications with that.
|
|
1336
|
+
*
|
|
1337
|
+
* @function iapRunAdapterTests
|
|
1338
|
+
*
|
|
1339
|
+
* @return {Object} - containing the results of the baseunit and unit tests.
|
|
1340
|
+
*/
|
|
1341
|
+
iapRunAdapterTests(callback) {
|
|
1342
|
+
const meth = 'adapterBase-iapRunAdapterTests';
|
|
1343
|
+
const origin = `${this.id}-${meth}`;
|
|
1344
|
+
log.trace(origin);
|
|
1345
|
+
let basecommand = null;
|
|
1346
|
+
let command = null;
|
|
1347
|
+
|
|
1348
|
+
if (fs.existsSync('package.json')) {
|
|
1349
|
+
const packageData = require('./package.json');
|
|
1350
|
+
|
|
1351
|
+
// check if 'test', 'test:unit', 'test:integration' exists in package.json file
|
|
1352
|
+
if (!packageData.scripts || !packageData.scripts['test:baseunit'] || !packageData.scripts['test:unit']) {
|
|
1353
|
+
log.error('The required scripts do not exist in the package.json file');
|
|
1354
|
+
return callback(null, 'The required scripts do not exist in the package.json file');
|
|
1729
1355
|
}
|
|
1730
1356
|
|
|
1731
|
-
//
|
|
1732
|
-
|
|
1733
|
-
let myResult = {};
|
|
1734
|
-
results.forEach((result) => {
|
|
1735
|
-
myResult = { ...myResult, ...result };
|
|
1736
|
-
});
|
|
1357
|
+
// run baseunit test
|
|
1358
|
+
basecommand = spawnSync('npm', ['run', 'test:baseunit'], { cwd: __dirname, encoding: 'utf-8' });
|
|
1737
1359
|
|
|
1738
|
-
|
|
1739
|
-
|
|
1360
|
+
// analyze and format the response to baseunit
|
|
1361
|
+
const baseresult = {
|
|
1362
|
+
status: 'SUCCESS'
|
|
1363
|
+
};
|
|
1364
|
+
if (basecommand.status !== 0) {
|
|
1365
|
+
baseresult.status = 'FAILED';
|
|
1366
|
+
baseresult.output = basecommand.stdout;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
// run unit test
|
|
1370
|
+
command = spawnSync('npm', ['run', 'test:unit'], { cwd: __dirname, encoding: 'utf-8' });
|
|
1371
|
+
|
|
1372
|
+
// analyze and format the response to unit
|
|
1373
|
+
const unitresult = {
|
|
1374
|
+
status: 'SUCCESS'
|
|
1375
|
+
};
|
|
1376
|
+
if (command.status !== 0) {
|
|
1377
|
+
unitresult.status = 'FAILED';
|
|
1378
|
+
unitresult.output = command.stdout;
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// format the response and return it
|
|
1382
|
+
const result = {
|
|
1383
|
+
base: baseresult,
|
|
1384
|
+
unit: unitresult
|
|
1385
|
+
};
|
|
1386
|
+
return callback(result);
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
log.error('Package Not Found');
|
|
1390
|
+
return callback(null, 'Package Not Found');
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* @summary provide inventory information abbout the adapter
|
|
1395
|
+
*
|
|
1396
|
+
* @function iapGetAdapterInventory
|
|
1397
|
+
*
|
|
1398
|
+
* @return {Object} - containing the adapter inventory information
|
|
1399
|
+
*/
|
|
1400
|
+
iapGetAdapterInventory(callback) {
|
|
1401
|
+
const meth = 'adapterBase-iapGetAdapterInventory';
|
|
1402
|
+
const origin = `${this.id}-${meth}`;
|
|
1403
|
+
log.trace(origin);
|
|
1404
|
+
|
|
1405
|
+
try {
|
|
1406
|
+
// call to the adapter utils to get inventory
|
|
1407
|
+
return this.requestHandlerInst.getAdapterInventory((res, error) => {
|
|
1408
|
+
const adapterInv = res;
|
|
1409
|
+
|
|
1410
|
+
// get all of the tasks
|
|
1411
|
+
const allTasks = this.getAllFunctions();
|
|
1412
|
+
adapterInv.totalTasks = allTasks.length;
|
|
1413
|
+
|
|
1414
|
+
// get all of the possible workflow tasks
|
|
1415
|
+
const myIgnore = [
|
|
1416
|
+
'healthCheck',
|
|
1417
|
+
'iapGetAdapterWorkflowFunctions',
|
|
1418
|
+
'hasEntities'
|
|
1419
|
+
];
|
|
1420
|
+
adapterInv.totalWorkflowTasks = this.iapGetAdapterWorkflowFunctions(myIgnore).length;
|
|
1421
|
+
|
|
1422
|
+
// TODO: CACHE
|
|
1423
|
+
// CONFIRM CACHE
|
|
1424
|
+
// GET CACHE ENTITIES
|
|
1425
|
+
|
|
1426
|
+
// get the Device Count
|
|
1427
|
+
return this.iapGetDeviceCount((devres, deverror) => {
|
|
1428
|
+
// if call failed assume not broker integrated
|
|
1429
|
+
if (deverror) {
|
|
1430
|
+
adapterInv.brokerDefined = false;
|
|
1431
|
+
adapterInv.deviceCount = -1;
|
|
1432
|
+
} else {
|
|
1433
|
+
// broker confirmed
|
|
1434
|
+
adapterInv.brokerDefined = true;
|
|
1435
|
+
adapterInv.deviceCount = 0;
|
|
1436
|
+
if (devres && devres.count) {
|
|
1437
|
+
adapterInv.deviceCount = devres.count;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
return callback(adapterInv);
|
|
1442
|
+
});
|
|
1740
1443
|
});
|
|
1741
1444
|
} catch (ex) {
|
|
1742
1445
|
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|