@itentialopensource/adapter-adtran_mosaic_devicemanager 0.1.1 → 0.2.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/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +169 -0
- package/CHANGELOG.md +9 -2
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +88 -74
- package/ENHANCE.md +14 -14
- package/PROPERTIES.md +483 -89
- package/README.md +131 -51
- package/SUMMARY.md +2 -2
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +4 -3
- package/adapter.js +176 -394
- package/adapterBase.js +648 -165
- package/entities/.generic/action.json +105 -0
- package/entities/.generic/schema.json +6 -1
- package/package.json +5 -3
- package/pronghorn.json +642 -563
- package/propertiesSchema.json +68 -11
- package/refs?service=git-upload-pack +0 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1653138377421.json +120 -0
- package/sampleProperties.json +90 -1
- package/test/integration/adapterTestBasicGet.js +1 -1
- package/test/integration/adapterTestIntegration.js +1919 -2575
- package/test/unit/adapterBaseTestUnit.js +10 -3
- package/test/unit/adapterTestUnit.js +33 -126
- package/utils/adapterInfo.js +206 -0
- package/utils/entitiesToDB.js +12 -57
- package/utils/pre-commit.sh +3 -0
- package/utils/tbScript.js +35 -20
- package/utils/tbUtils.js +44 -39
- package/utils/testRunner.js +16 -16
package/adapter.js
CHANGED
|
@@ -83,7 +83,15 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
83
83
|
* @iapGetAdapterWorkflowFunctions
|
|
84
84
|
*/
|
|
85
85
|
iapGetAdapterWorkflowFunctions(inIgnore) {
|
|
86
|
-
let myIgnore = [
|
|
86
|
+
let myIgnore = [
|
|
87
|
+
'healthCheck',
|
|
88
|
+
'iapGetAdapterWorkflowFunctions',
|
|
89
|
+
'iapHasAdapterEntity',
|
|
90
|
+
'iapVerifyAdapterCapability',
|
|
91
|
+
'iapUpdateAdapterEntityCache',
|
|
92
|
+
'hasEntities',
|
|
93
|
+
'getAuthorization'
|
|
94
|
+
];
|
|
87
95
|
if (!inIgnore && Array.isArray(inIgnore)) {
|
|
88
96
|
myIgnore = inIgnore;
|
|
89
97
|
} else if (!inIgnore && typeof inIgnore === 'string') {
|
|
@@ -111,8 +119,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
111
119
|
* @param {Callback} callback - The results of the call
|
|
112
120
|
*/
|
|
113
121
|
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
114
|
-
const
|
|
122
|
+
const meth = 'adapter-iapUpdateAdapterConfiguration';
|
|
123
|
+
const origin = `${this.id}-${meth}`;
|
|
115
124
|
log.trace(origin);
|
|
125
|
+
|
|
116
126
|
super.iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback);
|
|
117
127
|
}
|
|
118
128
|
|
|
@@ -124,8 +134,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
124
134
|
* @param {Callback} callback - The results of the call
|
|
125
135
|
*/
|
|
126
136
|
iapFindAdapterPath(apiPath, callback) {
|
|
127
|
-
const
|
|
137
|
+
const meth = 'adapter-iapFindAdapterPath';
|
|
138
|
+
const origin = `${this.id}-${meth}`;
|
|
128
139
|
log.trace(origin);
|
|
140
|
+
|
|
129
141
|
super.iapFindAdapterPath(apiPath, callback);
|
|
130
142
|
}
|
|
131
143
|
|
|
@@ -136,8 +148,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
136
148
|
* @param {Callback} callback - callback function
|
|
137
149
|
*/
|
|
138
150
|
iapSuspendAdapter(mode, callback) {
|
|
139
|
-
const
|
|
151
|
+
const meth = 'adapter-iapSuspendAdapter';
|
|
152
|
+
const origin = `${this.id}-${meth}`;
|
|
140
153
|
log.trace(origin);
|
|
154
|
+
|
|
141
155
|
try {
|
|
142
156
|
return super.iapSuspendAdapter(mode, callback);
|
|
143
157
|
} catch (error) {
|
|
@@ -153,8 +167,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
153
167
|
* @param {Callback} callback - callback function
|
|
154
168
|
*/
|
|
155
169
|
iapUnsuspendAdapter(callback) {
|
|
156
|
-
const
|
|
170
|
+
const meth = 'adapter-iapUnsuspendAdapter';
|
|
171
|
+
const origin = `${this.id}-${meth}`;
|
|
157
172
|
log.trace(origin);
|
|
173
|
+
|
|
158
174
|
try {
|
|
159
175
|
return super.iapUnsuspendAdapter(callback);
|
|
160
176
|
} catch (error) {
|
|
@@ -170,8 +186,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
170
186
|
* @param {Callback} callback - callback function
|
|
171
187
|
*/
|
|
172
188
|
iapGetAdapterQueue(callback) {
|
|
173
|
-
const
|
|
189
|
+
const meth = 'adapter-iapGetAdapterQueue';
|
|
190
|
+
const origin = `${this.id}-${meth}`;
|
|
174
191
|
log.trace(origin);
|
|
192
|
+
|
|
175
193
|
return super.iapGetAdapterQueue(callback);
|
|
176
194
|
}
|
|
177
195
|
|
|
@@ -185,8 +203,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
185
203
|
* @param {Callback} callback - The results of the call
|
|
186
204
|
*/
|
|
187
205
|
iapTroubleshootAdapter(props, persistFlag, callback) {
|
|
188
|
-
const
|
|
206
|
+
const meth = 'adapter-iapTroubleshootAdapter';
|
|
207
|
+
const origin = `${this.id}-${meth}`;
|
|
189
208
|
log.trace(origin);
|
|
209
|
+
|
|
190
210
|
try {
|
|
191
211
|
return super.iapTroubleshootAdapter(props, persistFlag, this, callback);
|
|
192
212
|
} catch (error) {
|
|
@@ -203,8 +223,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
203
223
|
* @param {Callback} callback - callback function
|
|
204
224
|
*/
|
|
205
225
|
iapRunAdapterHealthcheck(callback) {
|
|
206
|
-
const
|
|
226
|
+
const meth = 'adapter-iapRunAdapterHealthcheck';
|
|
227
|
+
const origin = `${this.id}-${meth}`;
|
|
207
228
|
log.trace(origin);
|
|
229
|
+
|
|
208
230
|
try {
|
|
209
231
|
return super.iapRunAdapterHealthcheck(this, callback);
|
|
210
232
|
} catch (error) {
|
|
@@ -220,8 +242,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
220
242
|
* @param {Callback} callback - callback function
|
|
221
243
|
*/
|
|
222
244
|
iapRunAdapterConnectivity(callback) {
|
|
223
|
-
const
|
|
245
|
+
const meth = 'adapter-iapRunAdapterConnectivity';
|
|
246
|
+
const origin = `${this.id}-${meth}`;
|
|
224
247
|
log.trace(origin);
|
|
248
|
+
|
|
225
249
|
try {
|
|
226
250
|
return super.iapRunAdapterConnectivity(callback);
|
|
227
251
|
} catch (error) {
|
|
@@ -237,8 +261,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
237
261
|
* @param {Callback} callback - callback function
|
|
238
262
|
*/
|
|
239
263
|
iapRunAdapterBasicGet(callback) {
|
|
240
|
-
const
|
|
264
|
+
const meth = 'adapter-iapRunAdapterBasicGet';
|
|
265
|
+
const origin = `${this.id}-${meth}`;
|
|
241
266
|
log.trace(origin);
|
|
267
|
+
|
|
242
268
|
try {
|
|
243
269
|
return super.iapRunAdapterBasicGet(callback);
|
|
244
270
|
} catch (error) {
|
|
@@ -255,8 +281,10 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
255
281
|
* or the error
|
|
256
282
|
*/
|
|
257
283
|
iapMoveAdapterEntitiesToDB(callback) {
|
|
258
|
-
const
|
|
284
|
+
const meth = 'adapter-iapMoveAdapterEntitiesToDB';
|
|
285
|
+
const origin = `${this.id}-${meth}`;
|
|
259
286
|
log.trace(origin);
|
|
287
|
+
|
|
260
288
|
try {
|
|
261
289
|
return super.iapMoveAdapterEntitiesToDB(callback);
|
|
262
290
|
} catch (err) {
|
|
@@ -446,56 +474,18 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
446
474
|
* value is true or false
|
|
447
475
|
*/
|
|
448
476
|
hasEntities(entityType, entityList, callback) {
|
|
449
|
-
const
|
|
477
|
+
const meth = 'adapter-hasEntities';
|
|
478
|
+
const origin = `${this.id}-${meth}`;
|
|
450
479
|
log.trace(origin);
|
|
451
480
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
481
|
+
try {
|
|
482
|
+
return super.hasEntities(entityType, entityList, callback);
|
|
483
|
+
} catch (err) {
|
|
484
|
+
log.error(`${origin}: ${err}`);
|
|
485
|
+
return callback(null, err);
|
|
457
486
|
}
|
|
458
487
|
}
|
|
459
488
|
|
|
460
|
-
/**
|
|
461
|
-
* @summary Helper method for hasEntities for the specific device case
|
|
462
|
-
*
|
|
463
|
-
* @param {Array} deviceList - array of unique device identifiers
|
|
464
|
-
* @param {Callback} callback - A map where the device is the key and the
|
|
465
|
-
* value is true or false
|
|
466
|
-
*/
|
|
467
|
-
hasDevices(deviceList, callback) {
|
|
468
|
-
const origin = `${this.id}-adapter-hasDevices`;
|
|
469
|
-
log.trace(origin);
|
|
470
|
-
|
|
471
|
-
const findings = deviceList.reduce((map, device) => {
|
|
472
|
-
// eslint-disable-next-line no-param-reassign
|
|
473
|
-
map[device] = false;
|
|
474
|
-
log.debug(`In reduce: ${JSON.stringify(map)}`);
|
|
475
|
-
return map;
|
|
476
|
-
}, {});
|
|
477
|
-
const apiCalls = deviceList.map((device) => new Promise((resolve) => {
|
|
478
|
-
this.getDevice(device, (result, error) => {
|
|
479
|
-
if (error) {
|
|
480
|
-
log.debug(`In map error: ${JSON.stringify(device)}`);
|
|
481
|
-
return resolve({ name: device, found: false });
|
|
482
|
-
}
|
|
483
|
-
log.debug(`In map: ${JSON.stringify(device)}`);
|
|
484
|
-
return resolve({ name: device, found: true });
|
|
485
|
-
});
|
|
486
|
-
}));
|
|
487
|
-
Promise.all(apiCalls).then((results) => {
|
|
488
|
-
results.forEach((device) => {
|
|
489
|
-
findings[device.name] = device.found;
|
|
490
|
-
});
|
|
491
|
-
log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
|
|
492
|
-
return callback(findings);
|
|
493
|
-
}).catch((errors) => {
|
|
494
|
-
log.error('Unable to do device lookup.');
|
|
495
|
-
return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
|
|
499
489
|
/**
|
|
500
490
|
* @summary Get Appliance that match the deviceName
|
|
501
491
|
*
|
|
@@ -510,75 +500,11 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
510
500
|
const origin = `${this.id}-${meth}`;
|
|
511
501
|
log.trace(origin);
|
|
512
502
|
|
|
513
|
-
// make sure we are set up for device broker getDevice
|
|
514
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevice || this.allProps.devicebroker.getDevice.length === 0 || !this.allProps.devicebroker.getDevice[0].path) {
|
|
515
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevice.path'], null, null, null);
|
|
516
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
517
|
-
return callback(null, errorObj);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
521
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
522
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
523
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
524
|
-
return callback(null, errorObj);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
503
|
try {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
name: deviceName
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
536
|
-
// if we received an error or their is no response on the results return an error
|
|
537
|
-
if (ferr) {
|
|
538
|
-
return callback(null, ferr);
|
|
539
|
-
}
|
|
540
|
-
if (devs.list.length < 1) {
|
|
541
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
542
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
543
|
-
return callback(null, errorObj);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
const callPromises = [];
|
|
547
|
-
for (let i = 0; i < this.allProps.devicebroker.getDevice.length; i += 1) {
|
|
548
|
-
// Perform component calls here.
|
|
549
|
-
callPromises.push(
|
|
550
|
-
new Promise((resolve, reject) => {
|
|
551
|
-
this.iapMakeBrokerCall('getDevice', this.allProps.devicebroker.getDevice[i], devs.list[0], null, (callRet, callErr) => {
|
|
552
|
-
// return an error
|
|
553
|
-
if (callErr) {
|
|
554
|
-
reject(callErr);
|
|
555
|
-
} else {
|
|
556
|
-
// return the data
|
|
557
|
-
resolve(callRet);
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
})
|
|
561
|
-
);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
// return an array of repsonses
|
|
565
|
-
return Promise.all(callPromises).then((results) => {
|
|
566
|
-
let myResult = {};
|
|
567
|
-
results.forEach((result) => {
|
|
568
|
-
myResult = { ...myResult, ...result };
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
return callback(myResult, null);
|
|
572
|
-
})
|
|
573
|
-
.catch((error) => {
|
|
574
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
575
|
-
return callback(null, error);
|
|
576
|
-
});
|
|
577
|
-
});
|
|
578
|
-
} catch (ex) {
|
|
579
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
580
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
581
|
-
return callback(null, errorObj);
|
|
504
|
+
return super.getDevice(deviceName, callback);
|
|
505
|
+
} catch (err) {
|
|
506
|
+
log.error(`${origin}: ${err}`);
|
|
507
|
+
return callback(null, err);
|
|
582
508
|
}
|
|
583
509
|
}
|
|
584
510
|
|
|
@@ -596,88 +522,11 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
596
522
|
const origin = `${this.id}-${meth}`;
|
|
597
523
|
log.trace(origin);
|
|
598
524
|
|
|
599
|
-
// make sure we are set up for device broker getDevicesFiltered
|
|
600
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getDevicesFiltered || this.allProps.devicebroker.getDevicesFiltered.length === 0 || !this.allProps.devicebroker.getDevicesFiltered[0].path) {
|
|
601
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getDevicesFiltered.path'], null, null, null);
|
|
602
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
603
|
-
return callback(null, errorObj);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
// verify the required fields have been provided
|
|
607
|
-
if (options === undefined || options === null || options === '' || options.length === 0) {
|
|
608
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
|
|
609
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
610
|
-
return callback(null, errorObj);
|
|
611
|
-
}
|
|
612
|
-
log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
|
|
613
|
-
|
|
614
525
|
try {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
// set up the filter of Device Names
|
|
620
|
-
let filterName = [];
|
|
621
|
-
if (options && options.filter && options.filter.name) {
|
|
622
|
-
// when this hack is removed, remove the lint ignore above
|
|
623
|
-
if (Array.isArray(options.filter.name)) {
|
|
624
|
-
// eslint-disable-next-line prefer-destructuring
|
|
625
|
-
filterName = options.filter.name;
|
|
626
|
-
} else {
|
|
627
|
-
filterName = [options.filter.name];
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
// TODO - get sort and order working
|
|
632
|
-
/*
|
|
633
|
-
if (options && options.sort) {
|
|
634
|
-
reqObj.uriOptions.sort = JSON.stringify(options.sort);
|
|
635
|
-
}
|
|
636
|
-
if (options && options.order) {
|
|
637
|
-
reqObj.uriOptions.order = options.order;
|
|
638
|
-
}
|
|
639
|
-
*/
|
|
640
|
-
const callPromises = [];
|
|
641
|
-
for (let i = 0; i < this.allProps.devicebroker.getDevicesFiltered.length; i += 1) {
|
|
642
|
-
// Perform component calls here.
|
|
643
|
-
callPromises.push(
|
|
644
|
-
new Promise((resolve, reject) => {
|
|
645
|
-
this.iapMakeBrokerCall('getDevicesFiltered', this.allProps.devicebroker.getDevicesFiltered[i], {}, filterName, (callRet, callErr) => {
|
|
646
|
-
// return an error
|
|
647
|
-
if (callErr) {
|
|
648
|
-
reject(callErr);
|
|
649
|
-
} else {
|
|
650
|
-
// return the data
|
|
651
|
-
resolve(callRet);
|
|
652
|
-
}
|
|
653
|
-
});
|
|
654
|
-
})
|
|
655
|
-
);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
// return an array of repsonses
|
|
659
|
-
return Promise.all(callPromises).then((results) => {
|
|
660
|
-
let myResult = [];
|
|
661
|
-
results.forEach((result) => {
|
|
662
|
-
if (Array.isArray(result)) {
|
|
663
|
-
myResult = [...myResult, ...result];
|
|
664
|
-
} else if (Object.keys(result).length > 0) {
|
|
665
|
-
myResult.push(result);
|
|
666
|
-
}
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
log.debug(`${origin}: Found #${myResult.length} devices.`);
|
|
670
|
-
log.debug(`Devices: ${JSON.stringify(myResult)}`);
|
|
671
|
-
return callback({ total: myResult.length, list: myResult });
|
|
672
|
-
})
|
|
673
|
-
.catch((error) => {
|
|
674
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
675
|
-
return callback(null, error);
|
|
676
|
-
});
|
|
677
|
-
} catch (ex) {
|
|
678
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
679
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
680
|
-
return callback(null, errorObj);
|
|
526
|
+
return super.getDevicesFiltered(options, callback);
|
|
527
|
+
} catch (err) {
|
|
528
|
+
log.error(`${origin}: ${err}`);
|
|
529
|
+
return callback(null, err);
|
|
681
530
|
}
|
|
682
531
|
}
|
|
683
532
|
|
|
@@ -695,79 +544,11 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
695
544
|
const origin = `${this.id}-${meth}`;
|
|
696
545
|
log.trace(origin);
|
|
697
546
|
|
|
698
|
-
// make sure we are set up for device broker isAlive
|
|
699
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.isAlive || this.allProps.devicebroker.isAlive.length === 0 || !this.allProps.devicebroker.isAlive[0].path) {
|
|
700
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.isAlive.path'], null, null, null);
|
|
701
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
702
|
-
return callback(null, errorObj);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
// verify the required fields have been provided
|
|
706
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
707
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
708
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
709
|
-
return callback(null, errorObj);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
547
|
try {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
name: deviceName
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
721
|
-
// if we received an error or their is no response on the results return an error
|
|
722
|
-
if (ferr) {
|
|
723
|
-
return callback(null, ferr);
|
|
724
|
-
}
|
|
725
|
-
if (devs.list.length < 1) {
|
|
726
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
727
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
728
|
-
return callback(null, errorObj);
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
const callPromises = [];
|
|
732
|
-
for (let i = 0; i < this.allProps.devicebroker.isAlive.length; i += 1) {
|
|
733
|
-
// Perform component calls here.
|
|
734
|
-
callPromises.push(
|
|
735
|
-
new Promise((resolve, reject) => {
|
|
736
|
-
this.iapMakeBrokerCall('isAlive', this.allProps.devicebroker.isAlive[i], devs.list[0], null, (callRet, callErr) => {
|
|
737
|
-
// return an error
|
|
738
|
-
if (callErr) {
|
|
739
|
-
reject(callErr);
|
|
740
|
-
} else {
|
|
741
|
-
// return the data
|
|
742
|
-
resolve(callRet);
|
|
743
|
-
}
|
|
744
|
-
});
|
|
745
|
-
})
|
|
746
|
-
);
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
// return an array of repsonses
|
|
750
|
-
return Promise.all(callPromises).then((results) => {
|
|
751
|
-
let myResult = {};
|
|
752
|
-
results.forEach((result) => {
|
|
753
|
-
myResult = { ...myResult, ...result };
|
|
754
|
-
});
|
|
755
|
-
|
|
756
|
-
let response = true;
|
|
757
|
-
if (myResult.isAlive !== null && myResult.isAlive !== undefined && myResult.isAlive === false) {
|
|
758
|
-
response = false;
|
|
759
|
-
}
|
|
760
|
-
return callback(response);
|
|
761
|
-
})
|
|
762
|
-
.catch((error) => {
|
|
763
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
764
|
-
return callback(null, error);
|
|
765
|
-
});
|
|
766
|
-
});
|
|
767
|
-
} catch (ex) {
|
|
768
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
769
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
770
|
-
return callback(null, errorObj);
|
|
548
|
+
return super.isAlive(deviceName, callback);
|
|
549
|
+
} catch (err) {
|
|
550
|
+
log.error(`${origin}: ${err}`);
|
|
551
|
+
return callback(null, err);
|
|
771
552
|
}
|
|
772
553
|
}
|
|
773
554
|
|
|
@@ -786,79 +567,11 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
786
567
|
const origin = `${this.id}-${meth}`;
|
|
787
568
|
log.trace(origin);
|
|
788
569
|
|
|
789
|
-
// make sure we are set up for device broker getConfig
|
|
790
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getConfig || this.allProps.devicebroker.getConfig.length === 0 || !this.allProps.devicebroker.getConfig[0].path) {
|
|
791
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getConfig.path'], null, null, null);
|
|
792
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
793
|
-
return callback(null, errorObj);
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
// verify the required fields have been provided
|
|
797
|
-
if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
|
|
798
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
|
|
799
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
800
|
-
return callback(null, errorObj);
|
|
801
|
-
}
|
|
802
|
-
|
|
803
570
|
try {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
name: deviceName
|
|
809
|
-
}
|
|
810
|
-
};
|
|
811
|
-
return this.getDevicesFiltered(opts, (devs, ferr) => {
|
|
812
|
-
// if we received an error or their is no response on the results return an error
|
|
813
|
-
if (ferr) {
|
|
814
|
-
return callback(null, ferr);
|
|
815
|
-
}
|
|
816
|
-
if (devs.list.length < 1) {
|
|
817
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
|
|
818
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
819
|
-
return callback(null, errorObj);
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
const callPromises = [];
|
|
823
|
-
for (let i = 0; i < this.allProps.devicebroker.getConfig.length; i += 1) {
|
|
824
|
-
// Perform component calls here.
|
|
825
|
-
callPromises.push(
|
|
826
|
-
new Promise((resolve, reject) => {
|
|
827
|
-
this.iapMakeBrokerCall('getConfig', this.allProps.devicebroker.getConfig[i], devs.list[0], null, (callRet, callErr) => {
|
|
828
|
-
// return an error
|
|
829
|
-
if (callErr) {
|
|
830
|
-
reject(callErr);
|
|
831
|
-
} else {
|
|
832
|
-
// return the data
|
|
833
|
-
resolve(callRet);
|
|
834
|
-
}
|
|
835
|
-
});
|
|
836
|
-
})
|
|
837
|
-
);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
// return an array of repsonses
|
|
841
|
-
return Promise.all(callPromises).then((results) => {
|
|
842
|
-
let myResult = {};
|
|
843
|
-
results.forEach((result) => {
|
|
844
|
-
myResult = { ...myResult, ...result };
|
|
845
|
-
});
|
|
846
|
-
|
|
847
|
-
// return the result
|
|
848
|
-
const newResponse = {
|
|
849
|
-
response: JSON.stringify(myResult, null, 2)
|
|
850
|
-
};
|
|
851
|
-
return callback(newResponse, null);
|
|
852
|
-
})
|
|
853
|
-
.catch((error) => {
|
|
854
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
855
|
-
return callback(null, error);
|
|
856
|
-
});
|
|
857
|
-
});
|
|
858
|
-
} catch (ex) {
|
|
859
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
860
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
861
|
-
return callback(null, errorObj);
|
|
571
|
+
return super.getConfig(deviceName, format, callback);
|
|
572
|
+
} catch (err) {
|
|
573
|
+
log.error(`${origin}: ${err}`);
|
|
574
|
+
return callback(null, err);
|
|
862
575
|
}
|
|
863
576
|
}
|
|
864
577
|
|
|
@@ -875,52 +588,11 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
875
588
|
const origin = `${this.id}-${meth}`;
|
|
876
589
|
log.trace(origin);
|
|
877
590
|
|
|
878
|
-
// make sure we are set up for device broker getCount
|
|
879
|
-
if (!this.allProps.devicebroker || !this.allProps.devicebroker.getCount || this.allProps.devicebroker.getCount.length === 0 || !this.allProps.devicebroker.getCount[0].path) {
|
|
880
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Properties', ['devicebroker.getCount.path'], null, null, null);
|
|
881
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
882
|
-
return callback(null, errorObj);
|
|
883
|
-
}
|
|
884
|
-
|
|
885
|
-
// verify the required fields have been provided
|
|
886
|
-
|
|
887
591
|
try {
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
new Promise((resolve, reject) => {
|
|
893
|
-
this.iapMakeBrokerCall('getCount', this.allProps.devicebroker.getCount[i], null, null, (callRet, callErr) => {
|
|
894
|
-
// return an error
|
|
895
|
-
if (callErr) {
|
|
896
|
-
reject(callErr);
|
|
897
|
-
} else {
|
|
898
|
-
// return the data
|
|
899
|
-
resolve(callRet);
|
|
900
|
-
}
|
|
901
|
-
});
|
|
902
|
-
})
|
|
903
|
-
);
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
// return an array of repsonses
|
|
907
|
-
return Promise.all(callPromises).then((results) => {
|
|
908
|
-
let myResult = {};
|
|
909
|
-
results.forEach((result) => {
|
|
910
|
-
myResult = { ...myResult, ...result };
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
// return the result
|
|
914
|
-
return callback({ count: myResult.length });
|
|
915
|
-
})
|
|
916
|
-
.catch((error) => {
|
|
917
|
-
log.debug(`Caught ${JSON.stringify(error)}`);
|
|
918
|
-
return callback(null, error);
|
|
919
|
-
});
|
|
920
|
-
} catch (ex) {
|
|
921
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
922
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
923
|
-
return callback(null, errorObj);
|
|
592
|
+
return super.iapGetDeviceCount(callback);
|
|
593
|
+
} catch (err) {
|
|
594
|
+
log.error(`${origin}: ${err}`);
|
|
595
|
+
return callback(null, err);
|
|
924
596
|
}
|
|
925
597
|
}
|
|
926
598
|
|
|
@@ -1035,6 +707,116 @@ class AdtranMosaicDeviceManager extends AdapterBaseCl {
|
|
|
1035
707
|
}
|
|
1036
708
|
}
|
|
1037
709
|
|
|
710
|
+
/**
|
|
711
|
+
* Makes the requested generic call with no base path or version
|
|
712
|
+
*
|
|
713
|
+
* @function genericAdapterRequestNoBasePath
|
|
714
|
+
* @param {String} uriPath - the path of the api call - do not include the host, port, base path or version (required)
|
|
715
|
+
* @param {String} restMethod - the rest method (GET, POST, PUT, PATCH, DELETE) (required)
|
|
716
|
+
* @param {Object} queryData - the parameters to be put on the url (optional).
|
|
717
|
+
* Can be a stringified Object.
|
|
718
|
+
* @param {Object} requestBody - the body to add to the request (optional).
|
|
719
|
+
* Can be a stringified Object.
|
|
720
|
+
* @param {Object} addlHeaders - additional headers to be put on the call (optional).
|
|
721
|
+
* Can be a stringified Object.
|
|
722
|
+
* @param {getCallback} callback - a callback function to return the result (Generics)
|
|
723
|
+
* or the error
|
|
724
|
+
*/
|
|
725
|
+
genericAdapterRequestNoBasePath(uriPath, restMethod, queryData, requestBody, addlHeaders, callback) {
|
|
726
|
+
const meth = 'adapter-genericAdapterRequestNoBasePath';
|
|
727
|
+
const origin = `${this.id}-${meth}`;
|
|
728
|
+
log.trace(origin);
|
|
729
|
+
|
|
730
|
+
if (this.suspended && this.suspendMode === 'error') {
|
|
731
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
|
|
732
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
733
|
+
return callback(null, errorObj);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/* HERE IS WHERE YOU VALIDATE DATA */
|
|
737
|
+
if (uriPath === undefined || uriPath === null || uriPath === '') {
|
|
738
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
|
|
739
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
740
|
+
return callback(null, errorObj);
|
|
741
|
+
}
|
|
742
|
+
if (restMethod === undefined || restMethod === null || restMethod === '') {
|
|
743
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
|
|
744
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
745
|
+
return callback(null, errorObj);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
|
|
749
|
+
// remove any leading / and split the uripath into path variables
|
|
750
|
+
let myPath = uriPath;
|
|
751
|
+
while (myPath.indexOf('/') === 0) {
|
|
752
|
+
myPath = myPath.substring(1);
|
|
753
|
+
}
|
|
754
|
+
const pathVars = myPath.split('/');
|
|
755
|
+
const queryParamsAvailable = queryData;
|
|
756
|
+
const queryParams = {};
|
|
757
|
+
const bodyVars = requestBody;
|
|
758
|
+
|
|
759
|
+
// loop in template. long callback arg name to avoid identifier conflicts
|
|
760
|
+
Object.keys(queryParamsAvailable).forEach((thisKeyInQueryParamsAvailable) => {
|
|
761
|
+
if (queryParamsAvailable[thisKeyInQueryParamsAvailable] !== undefined && queryParamsAvailable[thisKeyInQueryParamsAvailable] !== null
|
|
762
|
+
&& queryParamsAvailable[thisKeyInQueryParamsAvailable] !== '') {
|
|
763
|
+
queryParams[thisKeyInQueryParamsAvailable] = queryParamsAvailable[thisKeyInQueryParamsAvailable];
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
// set up the request object - payload, uriPathVars, uriQuery, uriOptions, addlHeaders
|
|
768
|
+
const reqObj = {
|
|
769
|
+
payload: bodyVars,
|
|
770
|
+
uriPathVars: pathVars,
|
|
771
|
+
uriQuery: queryParams,
|
|
772
|
+
uriOptions: {}
|
|
773
|
+
};
|
|
774
|
+
// add headers if provided
|
|
775
|
+
if (addlHeaders) {
|
|
776
|
+
reqObj.addlHeaders = addlHeaders;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// determine the call and return flag
|
|
780
|
+
let action = 'getGenericsNoBase';
|
|
781
|
+
let returnF = true;
|
|
782
|
+
if (restMethod.toUpperCase() === 'POST') {
|
|
783
|
+
action = 'createGenericNoBase';
|
|
784
|
+
} else if (restMethod.toUpperCase() === 'PUT') {
|
|
785
|
+
action = 'updateGenericNoBase';
|
|
786
|
+
} else if (restMethod.toUpperCase() === 'PATCH') {
|
|
787
|
+
action = 'patchGenericNoBase';
|
|
788
|
+
} else if (restMethod.toUpperCase() === 'DELETE') {
|
|
789
|
+
action = 'deleteGenericNoBase';
|
|
790
|
+
returnF = false;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
try {
|
|
794
|
+
// Make the call -
|
|
795
|
+
// identifyRequest(entity, action, requestObj, returnDataFlag, callback)
|
|
796
|
+
return this.requestHandlerInst.identifyRequest('.generic', action, reqObj, returnF, (irReturnData, irReturnError) => {
|
|
797
|
+
// if we received an error or their is no response on the results
|
|
798
|
+
// return an error
|
|
799
|
+
if (irReturnError) {
|
|
800
|
+
/* HERE IS WHERE YOU CAN ALTER THE ERROR MESSAGE */
|
|
801
|
+
return callback(null, irReturnError);
|
|
802
|
+
}
|
|
803
|
+
if (!Object.hasOwnProperty.call(irReturnData, 'response')) {
|
|
804
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['genericAdapterRequestNoBasePath'], null, null, null);
|
|
805
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
806
|
+
return callback(null, errorObj);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
/* HERE IS WHERE YOU CAN ALTER THE RETURN DATA */
|
|
810
|
+
// return the response
|
|
811
|
+
return callback(irReturnData, null);
|
|
812
|
+
});
|
|
813
|
+
} catch (ex) {
|
|
814
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
815
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
816
|
+
return callback(null, errorObj);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
1038
820
|
/**
|
|
1039
821
|
* @callback healthCallback
|
|
1040
822
|
* @param {Object} result - the result of the get request (contains an id and a status)
|