@itentialopensource/adapter-viptela 0.8.0 → 0.10.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/CHANGELOG.md +24 -0
- package/ENHANCE.md +69 -0
- package/PROPERTIES.md +247 -0
- package/README.md +113 -470
- package/SUMMARY.md +9 -0
- package/TROUBLESHOOT.md +46 -0
- package/adapter.js +33515 -61
- package/adapterBase.js +581 -279
- package/entities/.generic/action.json +5 -5
- package/entities/AdministrationAuditLog/action.json +252 -0
- package/entities/AdministrationAuditLog/schema.json +30 -0
- package/entities/AdministrationUserAndGroup/action.json +533 -0
- package/entities/AdministrationUserAndGroup/mockdatafiles/findUserGroups-default.json +4 -0
- package/entities/AdministrationUserAndGroup/mockdatafiles/findUserGroupsAsKeyValue-default.json +5 -0
- package/entities/AdministrationUserAndGroup/mockdatafiles/findUsers-default.json +3 -0
- package/entities/AdministrationUserAndGroup/mockdatafiles/getColoGroups-default.json +6 -0
- package/entities/AdministrationUserAndGroup/mockdatafiles/getVpnGroups-default.json +5 -0
- package/entities/AdministrationUserAndGroup/schema.json +44 -0
- package/entities/CertificateManagementDevice/action.json +517 -0
- package/entities/CertificateManagementDevice/mockdatafiles/getRootCertChains-default.json +3 -0
- package/entities/CertificateManagementDevice/schema.json +43 -0
- package/entities/ClusterManagement/action.json +477 -0
- package/entities/ClusterManagement/mockdatafiles/getConfiguredIPList-default.json +5 -0
- package/entities/ClusterManagement/mockdatafiles/getConnectedDevices-default.json +3 -0
- package/entities/ClusterManagement/mockdatafiles/getConnectedDevicesPerTenant-default.json +3 -0
- package/entities/ClusterManagement/mockdatafiles/getTenantsList-default.json +4 -0
- package/entities/ClusterManagement/mockdatafiles/listVmanages-default.json +4 -0
- package/entities/ClusterManagement/schema.json +41 -0
- package/entities/ColocationCluster/action.json +229 -0
- package/entities/ColocationCluster/schema.json +29 -0
- package/entities/ColocationServiceChain/action.json +86 -0
- package/entities/ColocationServiceChain/mockdatafiles/getEdgeDevices-default.json +5 -0
- package/entities/ColocationServiceChain/mockdatafiles/getpnfDevices-default.json +5 -0
- package/entities/ColocationServiceChain/schema.json +22 -0
- package/entities/ColocationServiceGroup/action.json +148 -0
- package/entities/ColocationServiceGroup/mockdatafiles/getAvailableChains-default.json +6 -0
- package/entities/ColocationServiceGroup/schema.json +25 -0
- package/entities/ConfigurationDisasterRecovery/action.json +696 -0
- package/entities/ConfigurationDisasterRecovery/mockdatafiles/downloadReplicationData-default.json +5 -0
- package/entities/ConfigurationDisasterRecovery/mockdatafiles/getDisasterRecoveryStatus-default.json +6 -0
- package/entities/ConfigurationDisasterRecovery/mockdatafiles/getLocalDataCenterState-default.json +6 -0
- package/entities/ConfigurationDisasterRecovery/mockdatafiles/getReachabilityInfo-default.json +5 -0
- package/entities/ConfigurationDisasterRecovery/mockdatafiles/getRemoteDCMembersState-default.json +3 -0
- package/entities/ConfigurationDisasterRecovery/mockdatafiles/getRemoteDataCenterState-default.json +6 -0
- package/entities/ConfigurationDisasterRecovery/schema.json +52 -0
- package/entities/ConfigurationFeatureList/action.json +46 -0
- package/entities/ConfigurationFeatureList/schema.json +20 -0
- package/entities/CreateABackupSnapshot/action.json +24 -0
- package/entities/CreateABackupSnapshot/schema.json +19 -0
- package/entities/DataCollectionAgent/action.json +470 -0
- package/entities/DataCollectionAgent/mockdatafiles/getTemplatePolicyDefinitionsDCA-default.json +5 -0
- package/entities/DataCollectionAgent/mockdatafiles/getVPNListsDCA-default.json +3 -0
- package/entities/DataCollectionAgent/mockdatafiles/getVedgeTemplateListDCA-default.json +6 -0
- package/entities/DataCollectionAgent/mockdatafiles/getVsmartTemplateListDCA-default.json +5 -0
- package/entities/DataCollectionAgent/mockdatafiles/listAllDevicesDCA-default.json +5 -0
- package/entities/DataCollectionAgent/schema.json +41 -0
- package/entities/DeviceActions/action.json +243 -0
- package/entities/DeviceActions/mockdatafiles/generateSecurityDevicesList-default.json +5 -0
- package/entities/DeviceActions/schema.json +13 -1
- package/entities/DeviceConfigHistory/action.json +294 -0
- package/entities/DeviceConfigHistory/schema.json +32 -0
- package/entities/MonitoringAlarmsDetails/action.json +684 -0
- package/entities/MonitoringAlarmsDetails/mockdatafiles/listDisabledAlarm-default.json +5 -0
- package/entities/MonitoringAlarmsDetails/schema.json +51 -0
- package/entities/MonitoringColocationCluster/action.json +360 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getClusterConfigByClusterId-default.json +3 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getClusterPortMappingByClusterId-default.json +3 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getPNFConfig-default.json +3 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getServiceGroupByClusterId-default.json +3 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getSystemStatusByDeviceId-default.json +6 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getVNFAlarmCount-default.json +6 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getVNFEventsCountDetail-default.json +4 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getVNFEventsDetail-default.json +3 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getVNFInterfaceDetail-default.json +3 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getpnfDetails-default.json +5 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/getvnfByDeviceId-default.json +4 -0
- package/entities/MonitoringColocationCluster/mockdatafiles/listNetworkFunctionMap-default.json +3 -0
- package/entities/MonitoringColocationCluster/schema.json +35 -0
- package/entities/MonitoringDeviceDetails/action.json +40 -0
- package/entities/MonitoringDeviceDetails/schema.json +3 -1
- package/entities/MonitoringDeviceStatisticsDetails/action.json +109 -0
- package/entities/MonitoringDeviceStatisticsDetails/mockdatafiles/generateDeviceStatisticsData-default.json +3 -0
- package/entities/MonitoringDeviceStatisticsDetails/mockdatafiles/getActiveAlarms-default.json +5 -0
- package/entities/MonitoringDeviceStatisticsDetails/mockdatafiles/getStatDataFieldsByStateDataType-default.json +6 -0
- package/entities/MonitoringDeviceStatisticsDetails/mockdatafiles/getStatisticsType-default.json +4 -0
- package/entities/MonitoringDeviceStatisticsDetails/schema.json +23 -0
- package/entities/MonitoringEvents/action.json +378 -0
- package/entities/MonitoringEvents/mockdatafiles/getComponentsAsKeyValue-default.json +4 -0
- package/entities/MonitoringEvents/mockdatafiles/getEventTypesAsKeyValue-default.json +3 -0
- package/entities/MonitoringEvents/schema.json +36 -0
- package/entities/RealTimeMonitoringAAA/action.json +109 -0
- package/entities/RealTimeMonitoringAAA/mockdatafiles/getAllDeviceUsers-default.json +5 -0
- package/entities/RealTimeMonitoringAAA/mockdatafiles/getUsersFromDevice-default.json +6 -0
- package/entities/RealTimeMonitoringAAA/schema.json +23 -0
- package/entities/SSLProxyCertificateManagementDevice/action.json +494 -0
- package/entities/SSLProxyCertificateManagementDevice/mockdatafiles/getSslProxyList-default.json +4 -0
- package/entities/SSLProxyCertificateManagementDevice/schema.json +42 -0
- package/entities/ScheduledBackupRestore/action.json +189 -0
- package/entities/ScheduledBackupRestore/schema.json +27 -0
- package/entities/SystemCloudService/action.json +313 -0
- package/entities/SystemCloudService/schema.json +33 -0
- package/entities/SystemContainer/action.json +189 -0
- package/entities/SystemContainer/mockdatafiles/getCustomApp-default.json +3 -0
- package/entities/SystemContainer/schema.json +27 -0
- package/entities/TroubleshootingToolsDashboard/action.json +128 -0
- package/entities/TroubleshootingToolsDashboard/schema.json +24 -0
- package/entities/TroubleshootingToolsDeviceConnectivity/action.json +288 -0
- package/entities/TroubleshootingToolsDeviceConnectivity/schema.json +32 -0
- package/entities/TroubleshootingToolsDeviceSoftwarePackage/action.json +85 -0
- package/entities/TroubleshootingToolsDeviceSoftwarePackage/schema.json +22 -0
- package/entities/TroubleshootingToolsDeviceSoftwareUpdate/action.json +86 -0
- package/entities/TroubleshootingToolsDeviceSoftwareUpdate/schema.json +22 -0
- package/entities/TroubleshootingToolsDiagnostics/action.json +977 -0
- package/entities/TroubleshootingToolsDiagnostics/schema.json +65 -0
- package/entities/TroubleshootingToolsSoftwareActions/action.json +232 -0
- package/entities/TroubleshootingToolsSoftwareActions/mockdatafiles/findSoftwareImages-default.json +6 -0
- package/entities/TroubleshootingToolsSoftwareActions/mockdatafiles/findSoftwareImagesWithFilters-default.json +5 -0
- package/entities/TroubleshootingToolsSoftwareActions/schema.json +29 -0
- package/error.json +12 -0
- package/package.json +19 -14
- package/pronghorn.json +14062 -90
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +369 -0
- package/refs?service=git-upload-pack +0 -0
- package/report/updateReport1642735010496.json +95 -0
- package/report/updateReport1651360586947.json +114 -0
- package/sampleProperties.json +16 -4
- package/test/integration/adapterTestBasicGet.js +1 -1
- package/test/integration/adapterTestIntegration.js +13175 -5
- package/test/unit/adapterBaseTestUnit.js +29 -27
- package/test/unit/adapterTestUnit.js +8633 -15
- package/utils/addAuth.js +94 -0
- package/utils/basicGet.js +1 -14
- package/utils/entitiesToDB.js +224 -0
- package/utils/modify.js +4 -4
- package/utils/packModificationScript.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/removeHooks.js +20 -0
- package/utils/tbScript.js +14 -8
- package/utils/tbUtils.js +111 -19
- package/utils/troubleshootingAdapter.js +2 -26
package/adapterBase.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
/* eslint no-cond-assign: warn */
|
|
9
9
|
/* eslint global-require: warn */
|
|
10
10
|
/* eslint no-unused-vars: warn */
|
|
11
|
+
/* eslint prefer-destructuring: warn */
|
|
11
12
|
|
|
12
13
|
/* Required libraries. */
|
|
13
14
|
const fs = require('fs-extra');
|
|
@@ -22,6 +23,7 @@ const AjvCl = require('ajv');
|
|
|
22
23
|
const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
|
|
23
24
|
const RequestHandlerCl = require('@itentialopensource/adapter-utils').RequestHandler;
|
|
24
25
|
|
|
26
|
+
const entitiesToDB = require(path.join(__dirname, 'utils/entitiesToDB'));
|
|
25
27
|
const troubleshootingAdapter = require(path.join(__dirname, 'utils/troubleshootingAdapter'));
|
|
26
28
|
const tbUtils = require(path.join(__dirname, 'utils/tbUtils'));
|
|
27
29
|
|
|
@@ -153,6 +155,9 @@ class AdapterBase extends EventEmitterCl {
|
|
|
153
155
|
// Instantiate the EventEmitter super class
|
|
154
156
|
super();
|
|
155
157
|
|
|
158
|
+
// IAP home directory injected by core when running the adapter within IAP
|
|
159
|
+
process.env.iap_home = process.argv[3];
|
|
160
|
+
|
|
156
161
|
try {
|
|
157
162
|
// Capture the adapter id
|
|
158
163
|
this.id = prongid;
|
|
@@ -247,6 +252,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
247
252
|
// properties that this code cares about
|
|
248
253
|
this.healthcheckType = this.allProps.healthcheck.type;
|
|
249
254
|
this.healthcheckInterval = this.allProps.healthcheck.frequency;
|
|
255
|
+
this.healthcheckQuery = this.allProps.healthcheck.query_object;
|
|
250
256
|
|
|
251
257
|
// set the failover codes from properties
|
|
252
258
|
if (this.allProps.request.failover_codes) {
|
|
@@ -275,129 +281,6 @@ class AdapterBase extends EventEmitterCl {
|
|
|
275
281
|
}
|
|
276
282
|
}
|
|
277
283
|
|
|
278
|
-
/**
|
|
279
|
-
* updateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
280
|
-
* allows customers to make changes to adapter configuration without having to be on the
|
|
281
|
-
* file system.
|
|
282
|
-
*
|
|
283
|
-
* @function updateAdapterConfiguration
|
|
284
|
-
* @param {string} configFile - the name of the file being updated (required)
|
|
285
|
-
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
|
286
|
-
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
287
|
-
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
|
288
|
-
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
289
|
-
* @param {Callback} callback - The results of the call
|
|
290
|
-
*/
|
|
291
|
-
updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
292
|
-
const meth = 'adapterBase-updateAdapterConfiguration';
|
|
293
|
-
const origin = `${this.id}-${meth}`;
|
|
294
|
-
log.trace(origin);
|
|
295
|
-
|
|
296
|
-
// verify the parameters are valid
|
|
297
|
-
if (changes === undefined || changes === null || typeof changes !== 'object'
|
|
298
|
-
|| Object.keys(changes).length === 0) {
|
|
299
|
-
const result = {
|
|
300
|
-
response: 'No configuration updates to make'
|
|
301
|
-
};
|
|
302
|
-
log.info(result.response);
|
|
303
|
-
return callback(result, null);
|
|
304
|
-
}
|
|
305
|
-
if (configFile === undefined || configFile === null || configFile === '') {
|
|
306
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
|
307
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
308
|
-
return callback(null, errorObj);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// take action based on configFile being changed
|
|
312
|
-
if (configFile === 'package.json') {
|
|
313
|
-
const pres = updatePackage(changes);
|
|
314
|
-
if (pres) {
|
|
315
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
|
316
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
317
|
-
return callback(null, errorObj);
|
|
318
|
-
}
|
|
319
|
-
const result = {
|
|
320
|
-
response: 'Package updates completed - restarting adapter'
|
|
321
|
-
};
|
|
322
|
-
log.info(result.response);
|
|
323
|
-
forceFail(true);
|
|
324
|
-
return callback(result, null);
|
|
325
|
-
}
|
|
326
|
-
if (entity === undefined || entity === null || entity === '') {
|
|
327
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
|
328
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
329
|
-
return callback(null, errorObj);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// this means we are changing an entity file so type is required
|
|
333
|
-
if (type === undefined || type === null || type === '') {
|
|
334
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
|
335
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
336
|
-
return callback(null, errorObj);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// if the entity does not exist - error
|
|
340
|
-
const epath = `${__dirname}/entities/${entity}`;
|
|
341
|
-
if (!fs.existsSync(epath)) {
|
|
342
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
|
343
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
344
|
-
return callback(null, errorObj);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// take action based on type of file being changed
|
|
348
|
-
if (type === 'action') {
|
|
349
|
-
// BACKUP???
|
|
350
|
-
const ares = updateAction(epath, action, changes);
|
|
351
|
-
if (ares) {
|
|
352
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
|
353
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
354
|
-
return callback(null, errorObj);
|
|
355
|
-
}
|
|
356
|
-
// AJV CHECK???
|
|
357
|
-
// RESTORE IF NEEDED???
|
|
358
|
-
const result = {
|
|
359
|
-
response: `Action updates completed to entity: ${entity} - ${action}`
|
|
360
|
-
};
|
|
361
|
-
log.info(result.response);
|
|
362
|
-
return callback(result, null);
|
|
363
|
-
}
|
|
364
|
-
if (type === 'schema') {
|
|
365
|
-
const sres = updateSchema(epath, configFile, changes);
|
|
366
|
-
if (sres) {
|
|
367
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
|
368
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
369
|
-
return callback(null, errorObj);
|
|
370
|
-
}
|
|
371
|
-
const result = {
|
|
372
|
-
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
|
373
|
-
};
|
|
374
|
-
log.info(result.response);
|
|
375
|
-
return callback(result, null);
|
|
376
|
-
}
|
|
377
|
-
if (type === 'mock') {
|
|
378
|
-
// if the mock directory does not exist - error
|
|
379
|
-
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
|
380
|
-
if (!fs.existsSync(mpath)) {
|
|
381
|
-
fs.mkdirSync(mpath);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const mres = updateMock(mpath, configFile, changes);
|
|
385
|
-
if (mres) {
|
|
386
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
|
387
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
388
|
-
return callback(null, errorObj);
|
|
389
|
-
}
|
|
390
|
-
const result = {
|
|
391
|
-
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
|
392
|
-
};
|
|
393
|
-
log.info(result.response);
|
|
394
|
-
return callback(result, null);
|
|
395
|
-
}
|
|
396
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
|
397
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
398
|
-
return callback(null, errorObj);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
284
|
/**
|
|
402
285
|
* @summary Connect function is used during Pronghorn startup to provide instantiation feedback.
|
|
403
286
|
*
|
|
@@ -451,8 +334,22 @@ class AdapterBase extends EventEmitterCl {
|
|
|
451
334
|
const origin = `${this.id}-adapterBase-healthCheck`;
|
|
452
335
|
log.trace(origin);
|
|
453
336
|
|
|
337
|
+
// if there is healthcheck query_object property, it needs to be added to the adapter
|
|
338
|
+
let myRequest = reqObj;
|
|
339
|
+
if (this.healthcheckQuery && Object.keys(this.healthcheckQuery).length > 0) {
|
|
340
|
+
if (myRequest && myRequest.uriQuery) {
|
|
341
|
+
myRequest.uriQuery = { ...myRequest.uriQuery, ...this.healthcheckQuery };
|
|
342
|
+
} else if (myRequest) {
|
|
343
|
+
myRequest.uriQuery = this.healthcheckQuery;
|
|
344
|
+
} else {
|
|
345
|
+
myRequest = {
|
|
346
|
+
uriQuery: this.healthcheckQuery
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
454
351
|
// call to the healthcheck in connector
|
|
455
|
-
return this.requestHandlerInst.identifyHealthcheck(
|
|
352
|
+
return this.requestHandlerInst.identifyHealthcheck(myRequest, (res, error) => {
|
|
456
353
|
// unhealthy
|
|
457
354
|
if (error) {
|
|
458
355
|
// if we were healthy, toggle health
|
|
@@ -485,98 +382,12 @@ class AdapterBase extends EventEmitterCl {
|
|
|
485
382
|
}
|
|
486
383
|
|
|
487
384
|
/**
|
|
488
|
-
*
|
|
489
|
-
* @param {Callback} callback - The adapater suspension status
|
|
490
|
-
* @function suspend
|
|
491
|
-
*/
|
|
492
|
-
suspend(mode, callback) {
|
|
493
|
-
const origin = `${this.id}-adapterBase-suspend`;
|
|
494
|
-
if (this.suspended) {
|
|
495
|
-
throw new Error(`${origin}: Adapter is already suspended`);
|
|
496
|
-
}
|
|
497
|
-
try {
|
|
498
|
-
this.suspended = true;
|
|
499
|
-
this.suspendMode = mode;
|
|
500
|
-
if (this.suspendMode === 'pause') {
|
|
501
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
502
|
-
// To suspend adapter, enable throttling and set concurrent max to 0
|
|
503
|
-
props.throttle.throttle_enabled = true;
|
|
504
|
-
props.throttle.concurrent_max = 0;
|
|
505
|
-
this.refreshProperties(props);
|
|
506
|
-
}
|
|
507
|
-
return callback({ suspended: true });
|
|
508
|
-
} catch (error) {
|
|
509
|
-
return callback(null, error);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* @summary Unsuspends the adapter
|
|
515
|
-
* @param {Callback} callback - The adapater suspension status
|
|
516
|
-
*
|
|
517
|
-
* @function unsuspend
|
|
518
|
-
*/
|
|
519
|
-
unsuspend(callback) {
|
|
520
|
-
const origin = `${this.id}-adapterBase-unsuspend`;
|
|
521
|
-
if (!this.suspended) {
|
|
522
|
-
throw new Error(`${origin}: Adapter is not suspended`);
|
|
523
|
-
}
|
|
524
|
-
if (this.suspendMode === 'pause') {
|
|
525
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
526
|
-
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
|
527
|
-
props.throttle.throttle_enabled = true;
|
|
528
|
-
props.throttle.concurrent_max = 1;
|
|
529
|
-
this.refreshProperties(props);
|
|
530
|
-
setTimeout(() => {
|
|
531
|
-
this.getQueue((q, error) => {
|
|
532
|
-
// console.log("Items in queue: " + String(q.length))
|
|
533
|
-
if (q.length === 0) {
|
|
534
|
-
// if queue is empty, return to initial properties state
|
|
535
|
-
this.refreshProperties(this.initProps);
|
|
536
|
-
this.suspended = false;
|
|
537
|
-
return callback({ suspended: false });
|
|
538
|
-
}
|
|
539
|
-
// recursive call to check queue again every second
|
|
540
|
-
return this.unsuspend(callback);
|
|
541
|
-
});
|
|
542
|
-
}, 1000);
|
|
543
|
-
} else {
|
|
544
|
-
this.suspended = false;
|
|
545
|
-
callback({ suspend: false });
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* getAllFunctions is used to get all of the exposed function in the adapter
|
|
551
|
-
*
|
|
552
|
-
* @function getAllFunctions
|
|
553
|
-
*/
|
|
554
|
-
getAllFunctions() {
|
|
555
|
-
let myfunctions = [];
|
|
556
|
-
let obj = this;
|
|
557
|
-
|
|
558
|
-
// find the functions in this class
|
|
559
|
-
do {
|
|
560
|
-
const l = Object.getOwnPropertyNames(obj)
|
|
561
|
-
.concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString()))
|
|
562
|
-
.sort()
|
|
563
|
-
.filter((p, i, arr) => typeof obj[p] === 'function' && p !== 'constructor' && (i === 0 || p !== arr[i - 1]) && myfunctions.indexOf(p) === -1);
|
|
564
|
-
myfunctions = myfunctions.concat(l);
|
|
565
|
-
}
|
|
566
|
-
while (
|
|
567
|
-
(obj = Object.getPrototypeOf(obj)) && Object.getPrototypeOf(obj)
|
|
568
|
-
);
|
|
569
|
-
|
|
570
|
-
return myfunctions;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
/**
|
|
574
|
-
* getWorkflowFunctions is used to get all of the workflow function in the adapter
|
|
385
|
+
* iapGetAdapterWorkflowFunctions is used to get all of the workflow function in the adapter
|
|
575
386
|
* @param {array} ignoreThese - additional methods to ignore (optional)
|
|
576
387
|
*
|
|
577
|
-
* @function
|
|
388
|
+
* @function iapGetAdapterWorkflowFunctions
|
|
578
389
|
*/
|
|
579
|
-
|
|
390
|
+
iapGetAdapterWorkflowFunctions(ignoreThese) {
|
|
580
391
|
const myfunctions = this.getAllFunctions();
|
|
581
392
|
const wffunctions = [];
|
|
582
393
|
|
|
@@ -586,8 +397,9 @@ class AdapterBase extends EventEmitterCl {
|
|
|
586
397
|
// got to the second tier (adapterBase)
|
|
587
398
|
break;
|
|
588
399
|
}
|
|
589
|
-
if (myfunctions[m] !== '
|
|
590
|
-
&& myfunctions[m] !== '
|
|
400
|
+
if (myfunctions[m] !== 'iapHasAdapterEntity' && myfunctions[m] !== 'iapVerifyAdapterCapability'
|
|
401
|
+
&& myfunctions[m] !== 'iapUpdateAdapterEntityCache' && myfunctions[m] !== 'healthCheck'
|
|
402
|
+
&& myfunctions[m] !== 'iapGetAdapterWorkflowFunctions'
|
|
591
403
|
&& !(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
|
|
592
404
|
let found = false;
|
|
593
405
|
if (ignoreThese && Array.isArray(ignoreThese)) {
|
|
@@ -601,36 +413,142 @@ class AdapterBase extends EventEmitterCl {
|
|
|
601
413
|
wffunctions.push(myfunctions[m]);
|
|
602
414
|
}
|
|
603
415
|
}
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
return wffunctions;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
return wffunctions;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
423
|
+
* allows customers to make changes to adapter configuration without having to be on the
|
|
424
|
+
* file system.
|
|
425
|
+
*
|
|
426
|
+
* @function iapUpdateAdapterConfiguration
|
|
427
|
+
* @param {string} configFile - the name of the file being updated (required)
|
|
428
|
+
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
|
429
|
+
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
430
|
+
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
|
431
|
+
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
432
|
+
* @param {Callback} callback - The results of the call
|
|
433
|
+
*/
|
|
434
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
435
|
+
const meth = 'adapterBase-iapUpdateAdapterConfiguration';
|
|
436
|
+
const origin = `${this.id}-${meth}`;
|
|
437
|
+
log.trace(origin);
|
|
438
|
+
|
|
439
|
+
// verify the parameters are valid
|
|
440
|
+
if (changes === undefined || changes === null || typeof changes !== 'object'
|
|
441
|
+
|| Object.keys(changes).length === 0) {
|
|
442
|
+
const result = {
|
|
443
|
+
response: 'No configuration updates to make'
|
|
444
|
+
};
|
|
445
|
+
log.info(result.response);
|
|
446
|
+
return callback(result, null);
|
|
447
|
+
}
|
|
448
|
+
if (configFile === undefined || configFile === null || configFile === '') {
|
|
449
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
|
450
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
451
|
+
return callback(null, errorObj);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// take action based on configFile being changed
|
|
455
|
+
if (configFile === 'package.json') {
|
|
456
|
+
const pres = updatePackage(changes);
|
|
457
|
+
if (pres) {
|
|
458
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
|
459
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
460
|
+
return callback(null, errorObj);
|
|
461
|
+
}
|
|
462
|
+
const result = {
|
|
463
|
+
response: 'Package updates completed - restarting adapter'
|
|
464
|
+
};
|
|
465
|
+
log.info(result.response);
|
|
466
|
+
forceFail(true);
|
|
467
|
+
return callback(result, null);
|
|
468
|
+
}
|
|
469
|
+
if (entity === undefined || entity === null || entity === '') {
|
|
470
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
|
471
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
472
|
+
return callback(null, errorObj);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// this means we are changing an entity file so type is required
|
|
476
|
+
if (type === undefined || type === null || type === '') {
|
|
477
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
|
478
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
479
|
+
return callback(null, errorObj);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// if the entity does not exist - error
|
|
483
|
+
const epath = `${__dirname}/entities/${entity}`;
|
|
484
|
+
if (!fs.existsSync(epath)) {
|
|
485
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
|
486
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
487
|
+
return callback(null, errorObj);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// take action based on type of file being changed
|
|
491
|
+
if (type === 'action') {
|
|
492
|
+
// BACKUP???
|
|
493
|
+
const ares = updateAction(epath, action, changes);
|
|
494
|
+
if (ares) {
|
|
495
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
|
496
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
497
|
+
return callback(null, errorObj);
|
|
498
|
+
}
|
|
499
|
+
// AJV CHECK???
|
|
500
|
+
// RESTORE IF NEEDED???
|
|
501
|
+
const result = {
|
|
502
|
+
response: `Action updates completed to entity: ${entity} - ${action}`
|
|
503
|
+
};
|
|
504
|
+
log.info(result.response);
|
|
505
|
+
return callback(result, null);
|
|
506
|
+
}
|
|
507
|
+
if (type === 'schema') {
|
|
508
|
+
const sres = updateSchema(epath, configFile, changes);
|
|
509
|
+
if (sres) {
|
|
510
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
|
511
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
512
|
+
return callback(null, errorObj);
|
|
513
|
+
}
|
|
514
|
+
const result = {
|
|
515
|
+
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
|
516
|
+
};
|
|
517
|
+
log.info(result.response);
|
|
518
|
+
return callback(result, null);
|
|
519
|
+
}
|
|
520
|
+
if (type === 'mock') {
|
|
521
|
+
// if the mock directory does not exist - error
|
|
522
|
+
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
|
523
|
+
if (!fs.existsSync(mpath)) {
|
|
524
|
+
fs.mkdirSync(mpath);
|
|
525
|
+
}
|
|
617
526
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
527
|
+
const mres = updateMock(mpath, configFile, changes);
|
|
528
|
+
if (mres) {
|
|
529
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
|
530
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
531
|
+
return callback(null, errorObj);
|
|
532
|
+
}
|
|
533
|
+
const result = {
|
|
534
|
+
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
|
535
|
+
};
|
|
536
|
+
log.info(result.response);
|
|
537
|
+
return callback(result, null);
|
|
623
538
|
}
|
|
539
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
|
540
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
541
|
+
return callback(null, errorObj);
|
|
624
542
|
}
|
|
625
543
|
|
|
626
544
|
/**
|
|
627
545
|
* See if the API path provided is found in this adapter
|
|
628
546
|
*
|
|
629
|
-
* @function
|
|
547
|
+
* @function iapFindAdapterPath
|
|
630
548
|
* @param {string} apiPath - the api path to check on
|
|
631
549
|
* @param {Callback} callback - The results of the call
|
|
632
550
|
*/
|
|
633
|
-
|
|
551
|
+
iapFindAdapterPath(apiPath, callback) {
|
|
634
552
|
const result = {
|
|
635
553
|
apiPath
|
|
636
554
|
};
|
|
@@ -644,7 +562,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
644
562
|
}
|
|
645
563
|
|
|
646
564
|
// make sure the entities directory exists
|
|
647
|
-
const entitydir = path.join(__dirname, '
|
|
565
|
+
const entitydir = path.join(__dirname, 'entities');
|
|
648
566
|
if (!fs.statSync(entitydir).isDirectory()) {
|
|
649
567
|
log.error('Could not find the entities directory');
|
|
650
568
|
result.found = false;
|
|
@@ -672,7 +590,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
672
590
|
log.info(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
|
|
673
591
|
const fitem = {
|
|
674
592
|
entity: entities[e],
|
|
675
|
-
action: actions[a].name,
|
|
593
|
+
action: actions.actions[a].name,
|
|
676
594
|
method: actions.actions[a].method,
|
|
677
595
|
path: actions.actions[a].entitypath
|
|
678
596
|
};
|
|
@@ -707,66 +625,90 @@ class AdapterBase extends EventEmitterCl {
|
|
|
707
625
|
}
|
|
708
626
|
|
|
709
627
|
/**
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
* @function
|
|
713
|
-
* @param {Object} properties - an object containing all of the properties
|
|
628
|
+
* @summary Suspends the adapter
|
|
629
|
+
* @param {Callback} callback - The adapater suspension status
|
|
630
|
+
* @function iapSuspendAdapter
|
|
714
631
|
*/
|
|
715
|
-
|
|
716
|
-
const origin = `${this.
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
632
|
+
iapSuspendAdapter(mode, callback) {
|
|
633
|
+
const origin = `${this.id}-adapterBase-iapSuspendAdapter`;
|
|
634
|
+
if (this.suspended) {
|
|
635
|
+
throw new Error(`${origin}: Adapter is already suspended`);
|
|
636
|
+
}
|
|
720
637
|
try {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
638
|
+
this.suspended = true;
|
|
639
|
+
this.suspendMode = mode;
|
|
640
|
+
if (this.suspendMode === 'pause') {
|
|
641
|
+
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
642
|
+
// To suspend adapter, enable throttling and set concurrent max to 0
|
|
643
|
+
props.throttle.throttle_enabled = true;
|
|
644
|
+
props.throttle.concurrent_max = 0;
|
|
645
|
+
this.refreshProperties(props);
|
|
646
|
+
}
|
|
647
|
+
return callback({ suspended: true });
|
|
648
|
+
} catch (error) {
|
|
649
|
+
return callback(null, error);
|
|
724
650
|
}
|
|
725
651
|
}
|
|
726
652
|
|
|
727
653
|
/**
|
|
728
|
-
*
|
|
654
|
+
* @summary Unsuspends the adapter
|
|
655
|
+
* @param {Callback} callback - The adapater suspension status
|
|
729
656
|
*
|
|
730
|
-
* @function
|
|
731
|
-
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
|
657
|
+
* @function iapUnsuspendAdapter
|
|
732
658
|
*/
|
|
733
|
-
|
|
734
|
-
const origin = `${this.id}-adapterBase-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
659
|
+
iapUnsuspendAdapter(callback) {
|
|
660
|
+
const origin = `${this.id}-adapterBase-iapUnsuspendAdapter`;
|
|
661
|
+
if (!this.suspended) {
|
|
662
|
+
throw new Error(`${origin}: Adapter is not suspended`);
|
|
663
|
+
}
|
|
664
|
+
if (this.suspendMode === 'pause') {
|
|
665
|
+
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
666
|
+
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
|
667
|
+
props.throttle.throttle_enabled = true;
|
|
668
|
+
props.throttle.concurrent_max = 1;
|
|
669
|
+
this.refreshProperties(props);
|
|
670
|
+
setTimeout(() => {
|
|
671
|
+
this.getQueue((q, error) => {
|
|
672
|
+
// console.log("Items in queue: " + String(q.length))
|
|
673
|
+
if (q.length === 0) {
|
|
674
|
+
// if queue is empty, return to initial properties state
|
|
675
|
+
this.refreshProperties(this.initProps);
|
|
676
|
+
this.suspended = false;
|
|
677
|
+
return callback({ suspended: false });
|
|
678
|
+
}
|
|
679
|
+
// recursive call to check queue again every second
|
|
680
|
+
return this.iapUnsuspendAdapter(callback);
|
|
681
|
+
});
|
|
682
|
+
}, 1000);
|
|
683
|
+
} else {
|
|
684
|
+
this.suspended = false;
|
|
685
|
+
callback({ suspend: false });
|
|
686
|
+
}
|
|
738
687
|
}
|
|
739
688
|
|
|
740
689
|
/**
|
|
741
|
-
*
|
|
742
|
-
* encoded/encrypted string
|
|
743
|
-
*
|
|
744
|
-
* @function encryptProperty
|
|
745
|
-
* @param {String} property - the property to encrypt
|
|
746
|
-
* @param {String} technique - the technique to use to encrypt
|
|
690
|
+
* iapGetAdapterQueue is used to get information for all of the requests currently in the queue.
|
|
747
691
|
*
|
|
748
|
-
* @
|
|
749
|
-
*
|
|
692
|
+
* @function iapGetAdapterQueue
|
|
693
|
+
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
|
750
694
|
*/
|
|
751
|
-
|
|
752
|
-
const origin = `${this.id}-adapterBase-
|
|
695
|
+
iapGetAdapterQueue(callback) {
|
|
696
|
+
const origin = `${this.id}-adapterBase-iapGetAdapterQueue`;
|
|
753
697
|
log.trace(origin);
|
|
754
698
|
|
|
755
|
-
|
|
756
|
-
// encryptProperty(property, technique, callback)
|
|
757
|
-
return this.requestHandlerInst.encryptProperty(property, technique, callback);
|
|
699
|
+
return this.requestHandlerInst.getQueue(callback);
|
|
758
700
|
}
|
|
759
701
|
|
|
760
702
|
/**
|
|
761
703
|
* @summary runs troubleshoot scripts for adapter
|
|
762
704
|
*
|
|
763
|
-
* @function
|
|
705
|
+
* @function iapTroubleshootAdapter
|
|
764
706
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
|
765
707
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
|
766
708
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
767
709
|
* @param {Callback} callback - callback function to return troubleshoot results
|
|
768
710
|
*/
|
|
769
|
-
async
|
|
711
|
+
async iapTroubleshootAdapter(props, persistFlag, adapter, callback) {
|
|
770
712
|
try {
|
|
771
713
|
const result = await troubleshootingAdapter.troubleshoot(props, false, persistFlag, adapter);
|
|
772
714
|
if (result.healthCheck && result.connectivity.failCount === 0 && result.basicGet.failCount === 0) {
|
|
@@ -781,11 +723,11 @@ class AdapterBase extends EventEmitterCl {
|
|
|
781
723
|
/**
|
|
782
724
|
* @summary runs healthcheck script for adapter
|
|
783
725
|
*
|
|
784
|
-
* @function
|
|
726
|
+
* @function iapRunAdapterHealthcheck
|
|
785
727
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
786
728
|
* @param {Callback} callback - callback function to return healthcheck status
|
|
787
729
|
*/
|
|
788
|
-
async
|
|
730
|
+
async iapRunAdapterHealthcheck(adapter, callback) {
|
|
789
731
|
try {
|
|
790
732
|
const result = await tbUtils.healthCheck(adapter);
|
|
791
733
|
if (result) {
|
|
@@ -800,13 +742,13 @@ class AdapterBase extends EventEmitterCl {
|
|
|
800
742
|
/**
|
|
801
743
|
* @summary runs connectivity check script for adapter
|
|
802
744
|
*
|
|
803
|
-
* @function
|
|
745
|
+
* @function iapRunAdapterConnectivity
|
|
804
746
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
805
747
|
* @param {Callback} callback - callback function to return connectivity status
|
|
806
748
|
*/
|
|
807
|
-
async
|
|
749
|
+
async iapRunAdapterConnectivity(callback) {
|
|
808
750
|
try {
|
|
809
|
-
const { serviceItem } = await
|
|
751
|
+
const { serviceItem } = await tbUtils.getAdapterConfig();
|
|
810
752
|
const { host } = serviceItem.properties.properties;
|
|
811
753
|
const result = tbUtils.runConnectivity(host, false);
|
|
812
754
|
if (result.failCount > 0) {
|
|
@@ -821,10 +763,10 @@ class AdapterBase extends EventEmitterCl {
|
|
|
821
763
|
/**
|
|
822
764
|
* @summary runs basicGet script for adapter
|
|
823
765
|
*
|
|
824
|
-
* @function
|
|
766
|
+
* @function iapRunAdapterBasicGet
|
|
825
767
|
* @param {Callback} callback - callback function to return basicGet result
|
|
826
768
|
*/
|
|
827
|
-
|
|
769
|
+
iapRunAdapterBasicGet(callback) {
|
|
828
770
|
try {
|
|
829
771
|
const result = tbUtils.runBasicGet(false);
|
|
830
772
|
if (result.failCount > 0) {
|
|
@@ -836,6 +778,106 @@ class AdapterBase extends EventEmitterCl {
|
|
|
836
778
|
}
|
|
837
779
|
}
|
|
838
780
|
|
|
781
|
+
/**
|
|
782
|
+
* @summary moves entities to mongo database
|
|
783
|
+
*
|
|
784
|
+
* @function iapMoveAdapterEntitiesToDB
|
|
785
|
+
*
|
|
786
|
+
* @return {Callback} - containing the response from the mongo transaction
|
|
787
|
+
*/
|
|
788
|
+
iapMoveAdapterEntitiesToDB(callback) {
|
|
789
|
+
const meth = 'adapterBase-iapMoveAdapterEntitiesToDB';
|
|
790
|
+
const origin = `${this.id}-${meth}`;
|
|
791
|
+
log.trace(origin);
|
|
792
|
+
|
|
793
|
+
try {
|
|
794
|
+
return callback(entitiesToDB.iapMoveAdapterEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
|
|
795
|
+
} catch (err) {
|
|
796
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
|
|
797
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
798
|
+
return callback(null, errorObj);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/**
|
|
803
|
+
* getAllFunctions is used to get all of the exposed function in the adapter
|
|
804
|
+
*
|
|
805
|
+
* @function getAllFunctions
|
|
806
|
+
*/
|
|
807
|
+
getAllFunctions() {
|
|
808
|
+
let myfunctions = [];
|
|
809
|
+
let obj = this;
|
|
810
|
+
|
|
811
|
+
// find the functions in this class
|
|
812
|
+
do {
|
|
813
|
+
const l = Object.getOwnPropertyNames(obj)
|
|
814
|
+
.concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString()))
|
|
815
|
+
.sort()
|
|
816
|
+
.filter((p, i, arr) => typeof obj[p] === 'function' && p !== 'constructor' && (i === 0 || p !== arr[i - 1]) && myfunctions.indexOf(p) === -1);
|
|
817
|
+
myfunctions = myfunctions.concat(l);
|
|
818
|
+
}
|
|
819
|
+
while (
|
|
820
|
+
(obj = Object.getPrototypeOf(obj)) && Object.getPrototypeOf(obj)
|
|
821
|
+
);
|
|
822
|
+
|
|
823
|
+
return myfunctions;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* checkActionFiles is used to update the validation of the action files.
|
|
828
|
+
*
|
|
829
|
+
* @function checkActionFiles
|
|
830
|
+
*/
|
|
831
|
+
checkActionFiles() {
|
|
832
|
+
const origin = `${this.id}-adapterBase-checkActionFiles`;
|
|
833
|
+
log.trace(origin);
|
|
834
|
+
|
|
835
|
+
// validate the action files for the adapter
|
|
836
|
+
try {
|
|
837
|
+
return this.requestHandlerInst.checkActionFiles();
|
|
838
|
+
} catch (e) {
|
|
839
|
+
return ['Exception increase log level'];
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* checkProperties is used to validate the adapter properties.
|
|
845
|
+
*
|
|
846
|
+
* @function checkProperties
|
|
847
|
+
* @param {Object} properties - an object containing all of the properties
|
|
848
|
+
*/
|
|
849
|
+
checkProperties(properties) {
|
|
850
|
+
const origin = `${this.myid}-adapterBase-checkProperties`;
|
|
851
|
+
log.trace(origin);
|
|
852
|
+
|
|
853
|
+
// validate the properties for the adapter
|
|
854
|
+
try {
|
|
855
|
+
return this.requestHandlerInst.checkProperties(properties);
|
|
856
|
+
} catch (e) {
|
|
857
|
+
return { exception: 'Exception increase log level' };
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* @summary Takes in property text and an encoding/encryption and returns the resulting
|
|
863
|
+
* encoded/encrypted string
|
|
864
|
+
*
|
|
865
|
+
* @function encryptProperty
|
|
866
|
+
* @param {String} property - the property to encrypt
|
|
867
|
+
* @param {String} technique - the technique to use to encrypt
|
|
868
|
+
*
|
|
869
|
+
* @param {Callback} callback - a callback function to return the result
|
|
870
|
+
* Encrypted String or the Error
|
|
871
|
+
*/
|
|
872
|
+
encryptProperty(property, technique, callback) {
|
|
873
|
+
const origin = `${this.id}-adapterBase-encryptProperty`;
|
|
874
|
+
log.trace(origin);
|
|
875
|
+
|
|
876
|
+
// Make the call -
|
|
877
|
+
// encryptProperty(property, technique, callback)
|
|
878
|
+
return this.requestHandlerInst.encryptProperty(property, technique, callback);
|
|
879
|
+
}
|
|
880
|
+
|
|
839
881
|
/**
|
|
840
882
|
* @summary take the entities and add them to the cache
|
|
841
883
|
*
|
|
@@ -986,6 +1028,266 @@ class AdapterBase extends EventEmitterCl {
|
|
|
986
1028
|
return [];
|
|
987
1029
|
}
|
|
988
1030
|
}
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* @summary Make one of the needed Broker calls - could be one of many
|
|
1034
|
+
*
|
|
1035
|
+
* @function iapMakeBrokerCall
|
|
1036
|
+
* @param {string} brokCall - the name of the broker call (required)
|
|
1037
|
+
* @param {object} callProps - the proeprties for the broker call (required)
|
|
1038
|
+
* @param {object} devResp - the device details to extract needed inputs (required)
|
|
1039
|
+
* @param {string} filterName - any filter to search on (required)
|
|
1040
|
+
*
|
|
1041
|
+
* @param {getCallback} callback - a callback function to return the result of the call
|
|
1042
|
+
*/
|
|
1043
|
+
iapMakeBrokerCall(brokCall, callProps, devResp, filterName, callback) {
|
|
1044
|
+
const meth = 'adapter-iapMakeBrokerCall';
|
|
1045
|
+
const origin = `${this.id}-${meth}`;
|
|
1046
|
+
log.trace(origin);
|
|
1047
|
+
|
|
1048
|
+
try {
|
|
1049
|
+
let uriPath = '';
|
|
1050
|
+
let uriMethod = 'GET';
|
|
1051
|
+
let callQuery = {};
|
|
1052
|
+
let callBody = {};
|
|
1053
|
+
let callHeaders = {};
|
|
1054
|
+
let handleFail = 'fail';
|
|
1055
|
+
let ostypePrefix = '';
|
|
1056
|
+
let statusValue = 'true';
|
|
1057
|
+
if (callProps.path) {
|
|
1058
|
+
uriPath = `${callProps.path}`;
|
|
1059
|
+
|
|
1060
|
+
// make any necessary changes to the path
|
|
1061
|
+
if (devResp && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
|
|
1062
|
+
const rqKeys = Object.keys(callProps.requestFields);
|
|
1063
|
+
|
|
1064
|
+
// get the field from the provided device
|
|
1065
|
+
for (let rq = 0; rq < rqKeys.length; rq += 1) {
|
|
1066
|
+
// get the request field we are retrieving
|
|
1067
|
+
const loopField = callProps.requestFields[rqKeys[rq]];
|
|
1068
|
+
const loopArray = loopField.split('.');
|
|
1069
|
+
let nestedValue = devResp;
|
|
1070
|
+
|
|
1071
|
+
// loops through incase the field is nested
|
|
1072
|
+
for (let i = 0; i < loopArray.length; i += 1) {
|
|
1073
|
+
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
|
1074
|
+
nestedValue = nestedValue[loopArray[i]];
|
|
1075
|
+
} else {
|
|
1076
|
+
// failed to traverse
|
|
1077
|
+
nestedValue = '';
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// put the value into the path - if it has been specified in the path
|
|
1083
|
+
uriPath = uriPath.replace(rqKeys[rq], nestedValue);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
if (callProps.method) {
|
|
1088
|
+
uriMethod = callProps.method;
|
|
1089
|
+
}
|
|
1090
|
+
if (callProps.query) {
|
|
1091
|
+
callQuery = callProps.query;
|
|
1092
|
+
|
|
1093
|
+
// go through the query params to check for variable values
|
|
1094
|
+
const cpKeys = Object.keys(callQuery);
|
|
1095
|
+
for (let cp = 0; cp < cpKeys.length; cp += 1) {
|
|
1096
|
+
if (callQuery[cpKeys[cp]].startsWith('{') && callQuery[cpKeys[cp]].endsWith('}')) {
|
|
1097
|
+
// make any necessary changes to the query params
|
|
1098
|
+
if (devResp && callProps.requestFields && Object.keys(callProps.requestFields).length > 0) {
|
|
1099
|
+
const rqKeys = Object.keys(callProps.requestFields);
|
|
1100
|
+
|
|
1101
|
+
// get the uuid from the device
|
|
1102
|
+
for (let rq = 0; rq < rqKeys.length; rq += 1) {
|
|
1103
|
+
if (cpKeys[cp] === rqKeys[rq]) {
|
|
1104
|
+
// get the request field we are retrieving
|
|
1105
|
+
const loopField = callProps.requestFields[rqKeys[rq]];
|
|
1106
|
+
const loopArray = loopField.split('.');
|
|
1107
|
+
let nestedValue = devResp;
|
|
1108
|
+
|
|
1109
|
+
// loops through incase the field is nested
|
|
1110
|
+
for (let i = 0; i < loopArray.length; i += 1) {
|
|
1111
|
+
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
|
1112
|
+
nestedValue = nestedValue[loopArray[i]];
|
|
1113
|
+
} else {
|
|
1114
|
+
// failed to traverse
|
|
1115
|
+
nestedValue = '';
|
|
1116
|
+
break;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
// put the value into the query - if it has been specified in the query
|
|
1121
|
+
callQuery[cpKeys[cp]] = nestedValue;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
if (callProps.body) {
|
|
1129
|
+
callBody = callProps.body;
|
|
1130
|
+
}
|
|
1131
|
+
if (callProps.headers) {
|
|
1132
|
+
callHeaders = callProps.headers;
|
|
1133
|
+
}
|
|
1134
|
+
if (callProps.handleFailure) {
|
|
1135
|
+
handleFail = callProps.handleFailure;
|
|
1136
|
+
}
|
|
1137
|
+
if (callProps.responseFields && callProps.responseFields.ostypePrefix) {
|
|
1138
|
+
ostypePrefix = callProps.responseFields.ostypePrefix;
|
|
1139
|
+
}
|
|
1140
|
+
if (callProps.responseFields && callProps.statusValue) {
|
|
1141
|
+
statusValue = callProps.statusValue;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// !! using Generic makes it easier on the Adapter Builder (just need to change the path)
|
|
1145
|
+
// !! you can also replace with a specific call if that is easier
|
|
1146
|
+
return this.genericAdapterRequest(uriPath, uriMethod, callQuery, callBody, callHeaders, (result, error) => {
|
|
1147
|
+
// if we received an error or their is no response on the results return an error
|
|
1148
|
+
if (error) {
|
|
1149
|
+
if (handleFail === 'fail') {
|
|
1150
|
+
return callback(null, error);
|
|
1151
|
+
}
|
|
1152
|
+
return callback({}, null);
|
|
1153
|
+
}
|
|
1154
|
+
if (!result.response) {
|
|
1155
|
+
if (handleFail === 'fail') {
|
|
1156
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', [brokCall], null, null, null);
|
|
1157
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1158
|
+
return callback(null, errorObj);
|
|
1159
|
+
}
|
|
1160
|
+
return callback({}, null);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
// get the keys for the response fields
|
|
1164
|
+
let rfKeys = [];
|
|
1165
|
+
if (callProps.responseFields && Object.keys(callProps.responseFields) > 0) {
|
|
1166
|
+
rfKeys = Object.keys(callProps.responseFields);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
// if we got an array returned (e.g. getDevicesFitered)
|
|
1170
|
+
if (Array.isArray(result.response)) {
|
|
1171
|
+
const listDevices = [];
|
|
1172
|
+
for (let a = 0; a < result.response.length; a += 1) {
|
|
1173
|
+
const thisDevice = result.response[a];
|
|
1174
|
+
for (let rf = 0; rf < rfKeys.length; rf += 1) {
|
|
1175
|
+
if (rfKeys[rf] !== 'ostypePrefix') {
|
|
1176
|
+
// get the response field we are retrieving
|
|
1177
|
+
const loopField = callProps.responseFields[rfKeys[rf]];
|
|
1178
|
+
const loopArray = loopField.split('.');
|
|
1179
|
+
let nestedValue = thisDevice;
|
|
1180
|
+
|
|
1181
|
+
// loops through incase the field is nested
|
|
1182
|
+
for (let i = 0; i < loopArray.length; i += 1) {
|
|
1183
|
+
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
|
1184
|
+
nestedValue = nestedValue[loopArray[i]];
|
|
1185
|
+
} else {
|
|
1186
|
+
// failed to traverse
|
|
1187
|
+
nestedValue = '';
|
|
1188
|
+
break;
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
// if the field is ostype - need to add prefix
|
|
1192
|
+
if (rfKeys[rf] === 'ostype' && typeof nestedValue === 'string') {
|
|
1193
|
+
nestedValue = ostypePrefix + nestedValue;
|
|
1194
|
+
}
|
|
1195
|
+
// if there is a status to set, set it
|
|
1196
|
+
if (rfKeys[rf] === 'status') {
|
|
1197
|
+
if (nestedValue.toString() === statusValue.toString()) {
|
|
1198
|
+
thisDevice.isAlive = true;
|
|
1199
|
+
} else {
|
|
1200
|
+
thisDevice.isAlive = false;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
// if we found a good value
|
|
1204
|
+
thisDevice[rfKeys[rf]] = nestedValue;
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// if there is no filter - add the device to the list
|
|
1209
|
+
if (!filterName || filterName.length === 0) {
|
|
1210
|
+
listDevices.push(thisDevice);
|
|
1211
|
+
} else {
|
|
1212
|
+
// if we have to match a filter
|
|
1213
|
+
let found = false;
|
|
1214
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
1215
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
1216
|
+
found = true;
|
|
1217
|
+
break;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
// matching device
|
|
1221
|
+
if (found) {
|
|
1222
|
+
listDevices.push(thisDevice);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// return the array of devices
|
|
1228
|
+
return callback(listDevices, null);
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// if this is not an array - just about everything else, just handle as a single object
|
|
1232
|
+
let thisDevice = result.response;
|
|
1233
|
+
for (let rf = 0; rf < rfKeys.length; rf += 1) {
|
|
1234
|
+
// skip ostypePrefix since it is not a field
|
|
1235
|
+
if (rfKeys[rf] !== 'ostypePrefix') {
|
|
1236
|
+
// get the response field we are retrieving
|
|
1237
|
+
const loopField = callProps.responseFields[rfKeys[rf]];
|
|
1238
|
+
const loopArray = loopField.split('.');
|
|
1239
|
+
let nestedValue = thisDevice;
|
|
1240
|
+
|
|
1241
|
+
// loops through incase the field is nested
|
|
1242
|
+
for (let i = 0; i < loopArray.length; i += 1) {
|
|
1243
|
+
if (Object.hasOwnProperty.call(nestedValue, loopArray[i])) {
|
|
1244
|
+
nestedValue = nestedValue[loopArray[i]];
|
|
1245
|
+
} else {
|
|
1246
|
+
// failed to traverse
|
|
1247
|
+
nestedValue = '';
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
// if the field is ostype - need to add prefix
|
|
1252
|
+
if (rfKeys[rf] === 'ostype' && typeof nestedValue === 'string') {
|
|
1253
|
+
nestedValue = ostypePrefix + nestedValue;
|
|
1254
|
+
}
|
|
1255
|
+
// if there is a status to set, set it
|
|
1256
|
+
if (rfKeys[rf] === 'status') {
|
|
1257
|
+
if (nestedValue.toString() === statusValue.toString()) {
|
|
1258
|
+
thisDevice.isAlive = true;
|
|
1259
|
+
} else {
|
|
1260
|
+
thisDevice.isAlive = false;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
// if we found a good value
|
|
1264
|
+
thisDevice[rfKeys[rf]] = nestedValue;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// if there is a filter - check the device is in the list
|
|
1269
|
+
if (filterName && filterName.length > 0) {
|
|
1270
|
+
let found = false;
|
|
1271
|
+
for (let f = 0; f < filterName.length; f += 1) {
|
|
1272
|
+
if (thisDevice.name.indexOf(filterName[f]) >= 0) {
|
|
1273
|
+
found = true;
|
|
1274
|
+
break;
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
// no matching device - clear the device
|
|
1278
|
+
if (!found) {
|
|
1279
|
+
thisDevice = {};
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
return callback(thisDevice, null);
|
|
1284
|
+
});
|
|
1285
|
+
} catch (e) {
|
|
1286
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, e);
|
|
1287
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1288
|
+
return callback(null, errorObj);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
989
1291
|
}
|
|
990
1292
|
|
|
991
1293
|
module.exports = AdapterBase;
|