@itentialopensource/adapter-aruba_airwave 0.2.1 → 0.3.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/.eslintignore +0 -1
- package/.jshintrc +3 -0
- package/AUTH.md +39 -0
- package/BROKER.md +199 -0
- package/CALLS.md +349 -0
- package/CHANGELOG.md +8 -0
- package/CODE_OF_CONDUCT.md +12 -17
- package/CONTRIBUTING.md +3 -148
- package/ENHANCE.md +69 -0
- package/LICENSE +0 -0
- package/PROPERTIES.md +641 -0
- package/README.md +240 -438
- package/SUMMARY.md +9 -0
- package/SYSTEMINFO.md +11 -0
- package/TROUBLESHOOT.md +47 -0
- package/adapter.js +482 -226
- package/adapterBase.js +883 -337
- package/changelogs/changelog.md +24 -0
- package/entities/.generic/action.json +214 -0
- package/entities/.generic/schema.json +28 -0
- package/error.json +6 -0
- package/metadata.json +47 -0
- package/package.json +23 -25
- package/pronghorn.json +774 -34
- package/propertiesDecorators.json +14 -0
- package/propertiesSchema.json +866 -6
- package/refs?service=git-upload-pack +0 -0
- package/report/adapter-openapi.json +1583 -0
- package/report/adapter-openapi.yaml +1300 -0
- package/report/adapterInfo.json +10 -0
- package/report/updateReport1691507584816.json +120 -0
- package/report/updateReport1692202582785.json +120 -0
- package/report/updateReport1694461838457.json +120 -0
- package/report/updateReport1698420960460.json +120 -0
- package/sampleProperties.json +163 -4
- package/test/integration/adapterTestBasicGet.js +3 -5
- package/test/integration/adapterTestConnectivity.js +91 -42
- package/test/integration/adapterTestIntegration.js +157 -98
- package/test/unit/adapterBaseTestUnit.js +400 -305
- package/test/unit/adapterTestUnit.js +917 -158
- package/utils/adapterInfo.js +206 -0
- package/utils/addAuth.js +94 -0
- package/utils/artifactize.js +1 -1
- package/utils/basicGet.js +1 -14
- package/utils/checkMigrate.js +63 -0
- package/utils/entitiesToDB.js +179 -0
- package/utils/findPath.js +74 -0
- package/utils/methodDocumentor.js +273 -0
- package/utils/modify.js +152 -0
- package/utils/packModificationScript.js +1 -1
- package/utils/patches2bundledDeps.js +90 -0
- package/utils/pre-commit.sh +5 -0
- package/utils/removeHooks.js +20 -0
- package/utils/setup.js +0 -0
- package/utils/taskMover.js +309 -0
- package/utils/tbScript.js +129 -53
- package/utils/tbUtils.js +152 -35
- package/utils/testRunner.js +17 -17
- package/utils/troubleshootingAdapter.js +17 -43
- package/workflows/README.md +0 -3
package/adapterBase.js
CHANGED
|
@@ -8,23 +8,33 @@
|
|
|
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
|
-
const fs = require('fs-extra');
|
|
14
14
|
const path = require('path');
|
|
15
|
-
const EventEmitterCl = require('events').EventEmitter;
|
|
16
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;
|
|
17
22
|
|
|
18
23
|
/* The schema validator */
|
|
19
24
|
const AjvCl = require('ajv');
|
|
25
|
+
const { Test } = require('mocha');
|
|
20
26
|
|
|
21
27
|
/* Fetch in the other needed components for the this Adaptor */
|
|
22
28
|
const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
|
|
23
29
|
const RequestHandlerCl = require('@itentialopensource/adapter-utils').RequestHandler;
|
|
24
|
-
|
|
25
|
-
const
|
|
30
|
+
|
|
31
|
+
const entitiesToDB = require(path.join(__dirname, 'utils/entitiesToDB'));
|
|
32
|
+
const troubleshootingAdapter = require(path.join(__dirname, 'utils/troubleshootingAdapter'));
|
|
33
|
+
const tbUtils = require(path.join(__dirname, 'utils/tbUtils'));
|
|
34
|
+
const taskMover = require(path.join(__dirname, 'utils/taskMover'));
|
|
26
35
|
|
|
27
36
|
let propUtil = null;
|
|
37
|
+
let choosepath = null;
|
|
28
38
|
|
|
29
39
|
/*
|
|
30
40
|
* INTERNAL FUNCTION: force fail the adapter - generally done to cause restart
|
|
@@ -97,7 +107,7 @@ function updateSchema(entityPath, configFile, changes) {
|
|
|
97
107
|
/*
|
|
98
108
|
* INTERNAL FUNCTION: update the mock data file
|
|
99
109
|
*/
|
|
100
|
-
function updateMock(mockPath, configFile, changes) {
|
|
110
|
+
function updateMock(mockPath, configFile, changes, replace) {
|
|
101
111
|
// if the mock file does not exist - create it
|
|
102
112
|
const mockFile = path.join(mockPath, `/${configFile}`);
|
|
103
113
|
if (!fs.existsSync(mockFile)) {
|
|
@@ -109,7 +119,11 @@ function updateMock(mockPath, configFile, changes) {
|
|
|
109
119
|
let mock = require(path.resolve(mockPath, configFile));
|
|
110
120
|
|
|
111
121
|
// merge the changes into the mock file
|
|
112
|
-
|
|
122
|
+
if (replace === true) {
|
|
123
|
+
mock = changes;
|
|
124
|
+
} else {
|
|
125
|
+
mock = propUtil.mergeProperties(changes, mock);
|
|
126
|
+
}
|
|
113
127
|
|
|
114
128
|
fs.writeFileSync(mockFile, JSON.stringify(mock, null, 2));
|
|
115
129
|
return null;
|
|
@@ -152,6 +166,9 @@ class AdapterBase extends EventEmitterCl {
|
|
|
152
166
|
// Instantiate the EventEmitter super class
|
|
153
167
|
super();
|
|
154
168
|
|
|
169
|
+
// IAP home directory injected by core when running the adapter within IAP
|
|
170
|
+
[, , , process.env.iap_home] = process.argv;
|
|
171
|
+
|
|
155
172
|
try {
|
|
156
173
|
// Capture the adapter id
|
|
157
174
|
this.id = prongid;
|
|
@@ -227,7 +244,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
227
244
|
this.allProps = this.propUtilInst.mergeProperties(properties, defProps);
|
|
228
245
|
|
|
229
246
|
// validate the entity against the schema
|
|
230
|
-
const ajvInst = new AjvCl();
|
|
247
|
+
const ajvInst = new AjvCl({ strictSchema: false, allowUnionTypes: true });
|
|
231
248
|
const validate = ajvInst.compile(propertiesSchema);
|
|
232
249
|
const result = validate(this.allProps);
|
|
233
250
|
|
|
@@ -246,6 +263,7 @@ class AdapterBase extends EventEmitterCl {
|
|
|
246
263
|
// properties that this code cares about
|
|
247
264
|
this.healthcheckType = this.allProps.healthcheck.type;
|
|
248
265
|
this.healthcheckInterval = this.allProps.healthcheck.frequency;
|
|
266
|
+
this.healthcheckQuery = this.allProps.healthcheck.query_object;
|
|
249
267
|
|
|
250
268
|
// set the failover codes from properties
|
|
251
269
|
if (this.allProps.request.failover_codes) {
|
|
@@ -274,129 +292,6 @@ class AdapterBase extends EventEmitterCl {
|
|
|
274
292
|
}
|
|
275
293
|
}
|
|
276
294
|
|
|
277
|
-
/**
|
|
278
|
-
* updateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
279
|
-
* allows customers to make changes to adapter configuration without having to be on the
|
|
280
|
-
* file system.
|
|
281
|
-
*
|
|
282
|
-
* @function updateAdapterConfiguration
|
|
283
|
-
* @param {string} configFile - the name of the file being updated (required)
|
|
284
|
-
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
|
285
|
-
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
286
|
-
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
|
287
|
-
* @param {string} action - the action to be changed, if an action, schema or mock data file (optional)
|
|
288
|
-
* @param {Callback} callback - The results of the call
|
|
289
|
-
*/
|
|
290
|
-
updateAdapterConfiguration(configFile, changes, entity, type, action, callback) {
|
|
291
|
-
const meth = 'adapterBase-updateAdapterConfiguration';
|
|
292
|
-
const origin = `${this.id}-${meth}`;
|
|
293
|
-
log.trace(origin);
|
|
294
|
-
|
|
295
|
-
// verify the parameters are valid
|
|
296
|
-
if (changes === undefined || changes === null || typeof changes !== 'object'
|
|
297
|
-
|| Object.keys(changes).length === 0) {
|
|
298
|
-
const result = {
|
|
299
|
-
response: 'No configuration updates to make'
|
|
300
|
-
};
|
|
301
|
-
log.info(result.response);
|
|
302
|
-
return callback(result, null);
|
|
303
|
-
}
|
|
304
|
-
if (configFile === undefined || configFile === null || configFile === '') {
|
|
305
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
|
306
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
307
|
-
return callback(null, errorObj);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// take action based on configFile being changed
|
|
311
|
-
if (configFile === 'package.json') {
|
|
312
|
-
const pres = updatePackage(changes);
|
|
313
|
-
if (pres) {
|
|
314
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
|
315
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
316
|
-
return callback(null, errorObj);
|
|
317
|
-
}
|
|
318
|
-
const result = {
|
|
319
|
-
response: 'Package updates completed - restarting adapter'
|
|
320
|
-
};
|
|
321
|
-
log.info(result.response);
|
|
322
|
-
forceFail(true);
|
|
323
|
-
return callback(result, null);
|
|
324
|
-
}
|
|
325
|
-
if (entity === undefined || entity === null || entity === '') {
|
|
326
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
|
327
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
328
|
-
return callback(null, errorObj);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// this means we are changing an entity file so type is required
|
|
332
|
-
if (type === undefined || type === null || type === '') {
|
|
333
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
|
334
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
335
|
-
return callback(null, errorObj);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// if the entity does not exist - error
|
|
339
|
-
const epath = `${__dirname}/entities/${entity}`;
|
|
340
|
-
if (!fs.existsSync(epath)) {
|
|
341
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
|
342
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
343
|
-
return callback(null, errorObj);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// take action based on type of file being changed
|
|
347
|
-
if (type === 'action') {
|
|
348
|
-
// BACKUP???
|
|
349
|
-
const ares = updateAction(epath, action, changes);
|
|
350
|
-
if (ares) {
|
|
351
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
|
352
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
353
|
-
return callback(null, errorObj);
|
|
354
|
-
}
|
|
355
|
-
// AJV CHECK???
|
|
356
|
-
// RESTORE IF NEEDED???
|
|
357
|
-
const result = {
|
|
358
|
-
response: `Action updates completed to entity: ${entity} - ${action}`
|
|
359
|
-
};
|
|
360
|
-
log.info(result.response);
|
|
361
|
-
return callback(result, null);
|
|
362
|
-
}
|
|
363
|
-
if (type === 'schema') {
|
|
364
|
-
const sres = updateSchema(epath, configFile, changes);
|
|
365
|
-
if (sres) {
|
|
366
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
|
367
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
368
|
-
return callback(null, errorObj);
|
|
369
|
-
}
|
|
370
|
-
const result = {
|
|
371
|
-
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
|
372
|
-
};
|
|
373
|
-
log.info(result.response);
|
|
374
|
-
return callback(result, null);
|
|
375
|
-
}
|
|
376
|
-
if (type === 'mock') {
|
|
377
|
-
// if the mock directory does not exist - error
|
|
378
|
-
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
|
379
|
-
if (!fs.existsSync(mpath)) {
|
|
380
|
-
fs.mkdirSync(mpath);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
const mres = updateMock(mpath, configFile, changes);
|
|
384
|
-
if (mres) {
|
|
385
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
|
386
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
387
|
-
return callback(null, errorObj);
|
|
388
|
-
}
|
|
389
|
-
const result = {
|
|
390
|
-
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
|
391
|
-
};
|
|
392
|
-
log.info(result.response);
|
|
393
|
-
return callback(result, null);
|
|
394
|
-
}
|
|
395
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
|
396
|
-
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
397
|
-
return callback(null, errorObj);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
295
|
/**
|
|
401
296
|
* @summary Connect function is used during Pronghorn startup to provide instantiation feedback.
|
|
402
297
|
*
|
|
@@ -441,67 +336,6 @@ class AdapterBase extends EventEmitterCl {
|
|
|
441
336
|
}
|
|
442
337
|
}
|
|
443
338
|
|
|
444
|
-
/**
|
|
445
|
-
* @summary Suspends the adapter
|
|
446
|
-
* @param {Callback} callback - The adapater suspension status
|
|
447
|
-
* @function suspend
|
|
448
|
-
*/
|
|
449
|
-
suspend(mode, callback) {
|
|
450
|
-
const origin = `${this.id}-adapterBase-suspend`;
|
|
451
|
-
if (this.suspended) {
|
|
452
|
-
throw new Error(`${origin}: Adapter is already suspended`);
|
|
453
|
-
}
|
|
454
|
-
try {
|
|
455
|
-
this.suspended = true;
|
|
456
|
-
this.suspendMode = mode;
|
|
457
|
-
if (this.suspendMode === 'pause') {
|
|
458
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
459
|
-
// To suspend adapter, enable throttling and set concurrent max to 0
|
|
460
|
-
props.throttle.throttle_enabled = true;
|
|
461
|
-
props.throttle.concurrent_max = 0;
|
|
462
|
-
this.refreshProperties(props);
|
|
463
|
-
}
|
|
464
|
-
return callback({ suspended: true });
|
|
465
|
-
} catch (error) {
|
|
466
|
-
return callback(null, error);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* @summary Unsuspends the adapter
|
|
472
|
-
* @param {Callback} callback - The adapater suspension status
|
|
473
|
-
*
|
|
474
|
-
* @function unsuspend
|
|
475
|
-
*/
|
|
476
|
-
unsuspend(callback) {
|
|
477
|
-
const origin = `${this.id}-adapterBase-unsuspend`;
|
|
478
|
-
if (!this.suspended) {
|
|
479
|
-
throw new Error(`${origin}: Adapter is not suspended`);
|
|
480
|
-
}
|
|
481
|
-
if (this.suspendMode === 'pause') {
|
|
482
|
-
const props = JSON.parse(JSON.stringify(this.initProps));
|
|
483
|
-
// To unsuspend adapter, keep throttling enabled and begin processing queued requests in order
|
|
484
|
-
props.throttle.throttle_enabled = true;
|
|
485
|
-
props.throttle.concurrent_max = 1;
|
|
486
|
-
this.refreshProperties(props);
|
|
487
|
-
setTimeout(() => {
|
|
488
|
-
this.getQueue((q, error) => {
|
|
489
|
-
// console.log("Items in queue: " + String(q.length))
|
|
490
|
-
if (q.length === 0) {
|
|
491
|
-
// if queue is empty, return to initial properties state
|
|
492
|
-
this.refreshProperties(this.initProps);
|
|
493
|
-
this.suspended = false;
|
|
494
|
-
return callback({ suspended: false });
|
|
495
|
-
}
|
|
496
|
-
// recursive call to check queue again every second
|
|
497
|
-
return this.unsuspend(callback);
|
|
498
|
-
});
|
|
499
|
-
}, 1000);
|
|
500
|
-
} else {
|
|
501
|
-
this.suspended = false;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
339
|
/**
|
|
506
340
|
* @summary HealthCheck function is used to provide Pronghorn the status of this adapter.
|
|
507
341
|
*
|
|
@@ -511,8 +345,22 @@ class AdapterBase extends EventEmitterCl {
|
|
|
511
345
|
const origin = `${this.id}-adapterBase-healthCheck`;
|
|
512
346
|
log.trace(origin);
|
|
513
347
|
|
|
348
|
+
// if there is healthcheck query_object property, it needs to be added to the adapter
|
|
349
|
+
let myRequest = reqObj;
|
|
350
|
+
if (this.healthcheckQuery && Object.keys(this.healthcheckQuery).length > 0) {
|
|
351
|
+
if (myRequest && myRequest.uriQuery) {
|
|
352
|
+
myRequest.uriQuery = { ...myRequest.uriQuery, ...this.healthcheckQuery };
|
|
353
|
+
} else if (myRequest) {
|
|
354
|
+
myRequest.uriQuery = this.healthcheckQuery;
|
|
355
|
+
} else {
|
|
356
|
+
myRequest = {
|
|
357
|
+
uriQuery: this.healthcheckQuery
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
514
362
|
// call to the healthcheck in connector
|
|
515
|
-
return this.requestHandlerInst.identifyHealthcheck(
|
|
363
|
+
return this.requestHandlerInst.identifyHealthcheck(myRequest, (res, error) => {
|
|
516
364
|
// unhealthy
|
|
517
365
|
if (error) {
|
|
518
366
|
// if we were healthy, toggle health
|
|
@@ -520,9 +368,15 @@ class AdapterBase extends EventEmitterCl {
|
|
|
520
368
|
this.emit('OFFLINE', { id: this.id });
|
|
521
369
|
this.emit('DEGRADED', { id: this.id });
|
|
522
370
|
this.healthy = false;
|
|
523
|
-
|
|
524
|
-
|
|
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') {
|
|
525
377
|
// still log but set the level to trace
|
|
378
|
+
log.trace(`${origin}: HEALTH CHECK - Still Errors ${JSON.stringify(error)}`);
|
|
379
|
+
} else {
|
|
526
380
|
log.trace(`${origin}: HEALTH CHECK - Still Errors ${error}`);
|
|
527
381
|
}
|
|
528
382
|
|
|
@@ -569,24 +423,22 @@ class AdapterBase extends EventEmitterCl {
|
|
|
569
423
|
}
|
|
570
424
|
|
|
571
425
|
/**
|
|
572
|
-
*
|
|
426
|
+
* iapGetAdapterWorkflowFunctions is used to get all of the workflow function in the adapter
|
|
573
427
|
* @param {array} ignoreThese - additional methods to ignore (optional)
|
|
574
428
|
*
|
|
575
|
-
* @function
|
|
429
|
+
* @function iapGetAdapterWorkflowFunctions
|
|
576
430
|
*/
|
|
577
|
-
|
|
431
|
+
iapGetAdapterWorkflowFunctions(ignoreThese) {
|
|
578
432
|
const myfunctions = this.getAllFunctions();
|
|
579
433
|
const wffunctions = [];
|
|
580
434
|
|
|
581
435
|
// remove the functions that should not be in a Workflow
|
|
582
436
|
for (let m = 0; m < myfunctions.length; m += 1) {
|
|
583
|
-
if (myfunctions[m] === '
|
|
437
|
+
if (myfunctions[m] === 'checkActionFiles') {
|
|
584
438
|
// got to the second tier (adapterBase)
|
|
585
439
|
break;
|
|
586
440
|
}
|
|
587
|
-
if (myfunctions[m]
|
|
588
|
-
&& myfunctions[m] !== 'healthCheck' && myfunctions[m] !== 'getWorkflowFunctions'
|
|
589
|
-
&& !(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
|
|
441
|
+
if (!(myfunctions[m].endsWith('Emit') || myfunctions[m].match(/Emit__v[0-9]+/))) {
|
|
590
442
|
let found = false;
|
|
591
443
|
if (ignoreThese && Array.isArray(ignoreThese)) {
|
|
592
444
|
for (let i = 0; i < ignoreThese.length; i += 1) {
|
|
@@ -639,19 +491,6 @@ class AdapterBase extends EventEmitterCl {
|
|
|
639
491
|
}
|
|
640
492
|
}
|
|
641
493
|
|
|
642
|
-
/**
|
|
643
|
-
* getQueue is used to get information for all of the requests currently in the queue.
|
|
644
|
-
*
|
|
645
|
-
* @function getQueue
|
|
646
|
-
* @param {Callback} callback - a callback function to return the result (Queue) or the error
|
|
647
|
-
*/
|
|
648
|
-
getQueue(callback) {
|
|
649
|
-
const origin = `${this.id}-adapterBase-getQueue`;
|
|
650
|
-
log.trace(origin);
|
|
651
|
-
|
|
652
|
-
return this.requestHandlerInst.getQueue(callback);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
494
|
/**
|
|
656
495
|
* @summary Takes in property text and an encoding/encryption and returns the resulting
|
|
657
496
|
* encoded/encrypted string
|
|
@@ -673,89 +512,330 @@ class AdapterBase extends EventEmitterCl {
|
|
|
673
512
|
}
|
|
674
513
|
|
|
675
514
|
/**
|
|
676
|
-
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
* @param {String} entityType - the type of the entities
|
|
680
|
-
* @param {Array} data - the list of entities
|
|
681
|
-
* @param {String} key - unique key for the entities
|
|
515
|
+
* iapUpdateAdapterConfiguration is used to update any of the adapter configuration files. This
|
|
516
|
+
* allows customers to make changes to adapter configuration without having to be on the
|
|
517
|
+
* file system.
|
|
682
518
|
*
|
|
683
|
-
* @
|
|
684
|
-
*
|
|
519
|
+
* @function iapUpdateAdapterConfiguration
|
|
520
|
+
* @param {string} configFile - the name of the file being updated (required)
|
|
521
|
+
* @param {Object} changes - an object containing all of the changes = formatted like the configuration file (required)
|
|
522
|
+
* @param {string} entity - the entity to be changed, if an action, schema or mock data file (optional)
|
|
523
|
+
* @param {string} type - the type of entity file to change, (action, schema, mock) (optional)
|
|
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)
|
|
526
|
+
* @param {Callback} callback - The results of the call
|
|
685
527
|
*/
|
|
686
|
-
|
|
687
|
-
const meth = 'adapterBase-
|
|
528
|
+
iapUpdateAdapterConfiguration(configFile, changes, entity, type, action, replace, callback) {
|
|
529
|
+
const meth = 'adapterBase-iapUpdateAdapterConfiguration';
|
|
688
530
|
const origin = `${this.id}-${meth}`;
|
|
689
531
|
log.trace(origin);
|
|
690
532
|
|
|
691
|
-
//
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
533
|
+
// verify the parameters are valid
|
|
534
|
+
if (changes === undefined || changes === null || typeof changes !== 'object'
|
|
535
|
+
|| Object.keys(changes).length === 0) {
|
|
536
|
+
const result = {
|
|
537
|
+
response: 'No configuration updates to make'
|
|
538
|
+
};
|
|
539
|
+
log.info(result.response);
|
|
540
|
+
return callback(result, null);
|
|
541
|
+
}
|
|
542
|
+
if (configFile === undefined || configFile === null || configFile === '') {
|
|
543
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['configFile'], null, null, null);
|
|
544
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
545
|
+
return callback(null, errorObj);
|
|
699
546
|
}
|
|
700
547
|
|
|
701
|
-
//
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
if (!loaded) {
|
|
707
|
-
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Entity Cache Not Loading', [entityType], null, null, null);
|
|
548
|
+
// take action based on configFile being changed
|
|
549
|
+
if (configFile === 'package.json') {
|
|
550
|
+
const pres = updatePackage(changes);
|
|
551
|
+
if (pres) {
|
|
552
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${pres}`, [], null, null, null);
|
|
708
553
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
709
554
|
return callback(null, errorObj);
|
|
710
555
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
*
|
|
723
|
-
* @param {Callback} callback - An array of whether the adapter can has the
|
|
724
|
-
* desired capability or an error
|
|
725
|
-
*/
|
|
726
|
-
entityInList(entityId, data) {
|
|
727
|
-
const origin = `${this.id}-adapterBase-entityInList`;
|
|
728
|
-
log.trace(origin);
|
|
729
|
-
|
|
730
|
-
// need to check on the entities that were passed in
|
|
731
|
-
if (Array.isArray(entityId)) {
|
|
732
|
-
const resEntity = [];
|
|
733
|
-
|
|
734
|
-
for (let e = 0; e < entityId.length; e += 1) {
|
|
735
|
-
if (data.includes(entityId[e])) {
|
|
736
|
-
resEntity.push(true);
|
|
737
|
-
} else {
|
|
738
|
-
resEntity.push(false);
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
return resEntity;
|
|
556
|
+
const result = {
|
|
557
|
+
response: 'Package updates completed - restarting adapter'
|
|
558
|
+
};
|
|
559
|
+
log.info(result.response);
|
|
560
|
+
forceFail(true);
|
|
561
|
+
return callback(result, null);
|
|
562
|
+
}
|
|
563
|
+
if (entity === undefined || entity === null || entity === '') {
|
|
564
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Unsupported Configuration Change or Missing Entity', [], null, null, null);
|
|
565
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
566
|
+
return callback(null, errorObj);
|
|
743
567
|
}
|
|
744
568
|
|
|
745
|
-
//
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
569
|
+
// this means we are changing an entity file so type is required
|
|
570
|
+
if (type === undefined || type === null || type === '') {
|
|
571
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['type'], null, null, null);
|
|
572
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
573
|
+
return callback(null, errorObj);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// if the entity does not exist - error
|
|
577
|
+
const epath = `${__dirname}/entities/${entity}`;
|
|
578
|
+
if (!fs.existsSync(epath)) {
|
|
579
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Invalid Entity - ${entity}`, [], null, null, null);
|
|
580
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
581
|
+
return callback(null, errorObj);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// take action based on type of file being changed
|
|
585
|
+
if (type === 'action') {
|
|
586
|
+
// BACKUP???
|
|
587
|
+
const ares = updateAction(epath, action, changes);
|
|
588
|
+
if (ares) {
|
|
589
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${ares}`, [], null, null, null);
|
|
590
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
591
|
+
return callback(null, errorObj);
|
|
592
|
+
}
|
|
593
|
+
// AJV CHECK???
|
|
594
|
+
// RESTORE IF NEEDED???
|
|
595
|
+
const result = {
|
|
596
|
+
response: `Action updates completed to entity: ${entity} - ${action}`
|
|
597
|
+
};
|
|
598
|
+
log.info(result.response);
|
|
599
|
+
return callback(result, null);
|
|
600
|
+
}
|
|
601
|
+
if (type === 'schema') {
|
|
602
|
+
const sres = updateSchema(epath, configFile, changes);
|
|
603
|
+
if (sres) {
|
|
604
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${sres}`, [], null, null, null);
|
|
605
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
606
|
+
return callback(null, errorObj);
|
|
607
|
+
}
|
|
608
|
+
const result = {
|
|
609
|
+
response: `Schema updates completed to entity: ${entity} - ${configFile}`
|
|
610
|
+
};
|
|
611
|
+
log.info(result.response);
|
|
612
|
+
return callback(result, null);
|
|
613
|
+
}
|
|
614
|
+
if (type === 'mock') {
|
|
615
|
+
// if the mock directory does not exist - error
|
|
616
|
+
const mpath = `${__dirname}/entities/${entity}/mockdatafiles`;
|
|
617
|
+
if (!fs.existsSync(mpath)) {
|
|
618
|
+
fs.mkdirSync(mpath);
|
|
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);
|
|
627
|
+
|
|
628
|
+
if (mres) {
|
|
629
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: ${mres}`, [], null, null, null);
|
|
630
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
631
|
+
return callback(null, errorObj);
|
|
632
|
+
}
|
|
633
|
+
const result = {
|
|
634
|
+
response: `Mock data updates completed to entity: ${entity} - ${configFile}`
|
|
635
|
+
};
|
|
636
|
+
log.info(result.response);
|
|
637
|
+
return callback(result, null);
|
|
638
|
+
}
|
|
639
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Incomplete Configuration Change: Unsupported Type - ${type}`, [], null, null, null);
|
|
640
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
641
|
+
return callback(null, errorObj);
|
|
642
|
+
}
|
|
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
|
+
/* ********************************************** */
|
|
724
|
+
/**
|
|
725
|
+
* See if the API path provided is found in this adapter
|
|
726
|
+
*
|
|
727
|
+
* @function iapFindAdapterPath
|
|
728
|
+
* @param {string} apiPath - the api path to check on
|
|
729
|
+
* @param {Callback} callback - The results of the call
|
|
730
|
+
*/
|
|
731
|
+
iapFindAdapterPath(apiPath, callback) {
|
|
732
|
+
const result = {
|
|
733
|
+
apiPath
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
// verify the path was provided
|
|
737
|
+
if (!apiPath) {
|
|
738
|
+
log.error('NO API PATH PROVIDED!');
|
|
739
|
+
result.found = false;
|
|
740
|
+
result.message = 'NO PATH PROVIDED!';
|
|
741
|
+
return callback(null, result);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (typeof this.allProps.choosepath === 'string') {
|
|
745
|
+
choosepath = this.allProps.choosepath;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// make sure the entities directory exists
|
|
749
|
+
const entitydir = path.join(__dirname, 'entities');
|
|
750
|
+
if (!fs.statSync(entitydir).isDirectory()) {
|
|
751
|
+
log.error('Could not find the entities directory');
|
|
752
|
+
result.found = false;
|
|
753
|
+
result.message = 'Could not find the entities directory';
|
|
754
|
+
return callback(null, result);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
const entities = fs.readdirSync(entitydir);
|
|
758
|
+
const fitems = [];
|
|
759
|
+
|
|
760
|
+
// need to go through each entity in the entities directory
|
|
761
|
+
for (let e = 0; e < entities.length; e += 1) {
|
|
762
|
+
// make sure the entity is a directory - do not care about extra files
|
|
763
|
+
// only entities (dir)
|
|
764
|
+
if (fs.statSync(`${entitydir}/${entities[e]}`).isDirectory()) {
|
|
765
|
+
// see if the action file exists in the entity
|
|
766
|
+
if (fs.existsSync(`${entitydir}/${entities[e]}/action.json`)) {
|
|
767
|
+
// Read the entity actions from the file system
|
|
768
|
+
const actions = require(`${entitydir}/${entities[e]}/action.json`);
|
|
769
|
+
|
|
770
|
+
// go through all of the actions set the appropriate info in the newActions
|
|
771
|
+
for (let a = 0; a < actions.actions.length; a += 1) {
|
|
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) {
|
|
791
|
+
log.info(` Found - entity: ${entities[e]} action: ${actions.actions[a].name}`);
|
|
792
|
+
log.info(` method: ${actions.actions[a].method} path: ${actions.actions[a].entitypath}`);
|
|
793
|
+
const fitem = {
|
|
794
|
+
entity: entities[e],
|
|
795
|
+
action: actions.actions[a].name,
|
|
796
|
+
method: actions.actions[a].method,
|
|
797
|
+
path: actions.actions[a].entitypath
|
|
798
|
+
};
|
|
799
|
+
fitems.push(fitem);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
} else {
|
|
803
|
+
log.error(`Could not find entities ${entities[e]} action.json file`);
|
|
804
|
+
result.found = false;
|
|
805
|
+
result.message = `Could not find entities ${entities[e]} action.json file`;
|
|
806
|
+
return callback(null, result);
|
|
807
|
+
}
|
|
808
|
+
} else {
|
|
809
|
+
log.error(`Could not find entities ${entities[e]} directory`);
|
|
810
|
+
result.found = false;
|
|
811
|
+
result.message = `Could not find entities ${entities[e]} directory`;
|
|
812
|
+
return callback(null, result);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
if (fitems.length === 0) {
|
|
817
|
+
log.info('PATH NOT FOUND!');
|
|
818
|
+
result.found = false;
|
|
819
|
+
result.message = 'API PATH NOT FOUND!';
|
|
820
|
+
return callback(null, result);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
result.foundIn = fitems;
|
|
824
|
+
result.found = true;
|
|
825
|
+
result.message = 'API PATH FOUND!';
|
|
826
|
+
return callback(result, null);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* @summary runs troubleshoot scripts for adapter
|
|
751
831
|
*
|
|
752
|
-
* @function
|
|
832
|
+
* @function iapTroubleshootAdapter
|
|
753
833
|
* @param {Object} props - the connection, healthcheck and authentication properties
|
|
754
834
|
* @param {boolean} persistFlag - whether the adapter properties should be updated
|
|
755
835
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
756
836
|
* @param {Callback} callback - callback function to return troubleshoot results
|
|
757
837
|
*/
|
|
758
|
-
async
|
|
838
|
+
async iapTroubleshootAdapter(props, persistFlag, adapter, callback) {
|
|
759
839
|
try {
|
|
760
840
|
const result = await troubleshootingAdapter.troubleshoot(props, false, persistFlag, adapter);
|
|
761
841
|
if (result.healthCheck && result.connectivity.failCount === 0 && result.basicGet.failCount === 0) {
|
|
@@ -770,17 +850,17 @@ class AdapterBase extends EventEmitterCl {
|
|
|
770
850
|
/**
|
|
771
851
|
* @summary runs healthcheck script for adapter
|
|
772
852
|
*
|
|
773
|
-
* @function
|
|
853
|
+
* @function iapRunAdapterHealthcheck
|
|
774
854
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
775
855
|
* @param {Callback} callback - callback function to return healthcheck status
|
|
776
856
|
*/
|
|
777
|
-
async
|
|
857
|
+
async iapRunAdapterHealthcheck(adapter, callback) {
|
|
778
858
|
try {
|
|
779
859
|
const result = await tbUtils.healthCheck(adapter);
|
|
780
860
|
if (result) {
|
|
781
861
|
return callback(result);
|
|
782
862
|
}
|
|
783
|
-
return callback(null,
|
|
863
|
+
return callback(null, 'Healthcheck failed');
|
|
784
864
|
} catch (error) {
|
|
785
865
|
return callback(null, error);
|
|
786
866
|
}
|
|
@@ -789,14 +869,13 @@ class AdapterBase extends EventEmitterCl {
|
|
|
789
869
|
/**
|
|
790
870
|
* @summary runs connectivity check script for adapter
|
|
791
871
|
*
|
|
792
|
-
* @function
|
|
872
|
+
* @function iapRunAdapterConnectivity
|
|
793
873
|
* @param {Adapter} adapter - adapter instance to troubleshoot
|
|
794
874
|
* @param {Callback} callback - callback function to return connectivity status
|
|
795
875
|
*/
|
|
796
|
-
async
|
|
876
|
+
async iapRunAdapterConnectivity(callback) {
|
|
797
877
|
try {
|
|
798
|
-
const {
|
|
799
|
-
const { host } = serviceItem.properties.properties;
|
|
878
|
+
const { host } = this.allProps;
|
|
800
879
|
const result = tbUtils.runConnectivity(host, false);
|
|
801
880
|
if (result.failCount > 0) {
|
|
802
881
|
return callback(null, result);
|
|
@@ -810,10 +889,10 @@ class AdapterBase extends EventEmitterCl {
|
|
|
810
889
|
/**
|
|
811
890
|
* @summary runs basicGet script for adapter
|
|
812
891
|
*
|
|
813
|
-
* @function
|
|
892
|
+
* @function iapRunAdapterBasicGet
|
|
814
893
|
* @param {Callback} callback - callback function to return basicGet result
|
|
815
894
|
*/
|
|
816
|
-
|
|
895
|
+
iapRunAdapterBasicGet(callback) {
|
|
817
896
|
try {
|
|
818
897
|
const result = tbUtils.runBasicGet(false);
|
|
819
898
|
if (result.failCount > 0) {
|
|
@@ -826,79 +905,546 @@ class AdapterBase extends EventEmitterCl {
|
|
|
826
905
|
}
|
|
827
906
|
|
|
828
907
|
/**
|
|
829
|
-
* @summary
|
|
908
|
+
* @summary moves entities to mongo database
|
|
830
909
|
*
|
|
831
|
-
* @function
|
|
832
|
-
* @param {Array} results - the results from the capability check
|
|
910
|
+
* @function iapMoveAdapterEntitiesToDB
|
|
833
911
|
*
|
|
834
|
-
* @
|
|
835
|
-
* desired capability or an error
|
|
912
|
+
* @return {Callback} - containing the response from the mongo transaction
|
|
836
913
|
*/
|
|
837
|
-
|
|
838
|
-
const meth = 'adapterBase-
|
|
914
|
+
async iapMoveAdapterEntitiesToDB(callback) {
|
|
915
|
+
const meth = 'adapterBase-iapMoveAdapterEntitiesToDB';
|
|
839
916
|
const origin = `${this.id}-${meth}`;
|
|
840
917
|
log.trace(origin);
|
|
841
|
-
let locResults = results;
|
|
842
918
|
|
|
843
|
-
|
|
844
|
-
const
|
|
919
|
+
try {
|
|
920
|
+
const result = await entitiesToDB.moveEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id });
|
|
921
|
+
return callback(result, null);
|
|
922
|
+
} catch (err) {
|
|
923
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
|
|
845
924
|
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
846
|
-
|
|
847
|
-
return callback(null, errorObj);
|
|
925
|
+
return callback(null, err.message);
|
|
848
926
|
}
|
|
927
|
+
}
|
|
849
928
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
929
|
+
/**
|
|
930
|
+
* @function iapDeactivateTasks
|
|
931
|
+
*
|
|
932
|
+
* @param {Array} tasks - List of tasks to deactivate
|
|
933
|
+
* @param {Callback} callback
|
|
934
|
+
*/
|
|
935
|
+
iapDeactivateTasks(tasks, callback) {
|
|
936
|
+
const meth = 'adapterBase-iapDeactivateTasks';
|
|
937
|
+
const origin = `${this.id}-${meth}`;
|
|
938
|
+
log.trace(origin);
|
|
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);
|
|
855
946
|
}
|
|
947
|
+
taskMover.deleteBackups(__dirname);
|
|
948
|
+
return callback(data, null);
|
|
949
|
+
}
|
|
856
950
|
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
951
|
+
/**
|
|
952
|
+
* @function iapActivateTasks
|
|
953
|
+
*
|
|
954
|
+
* @param {Array} tasks - List of tasks to deactivate
|
|
955
|
+
* @param {Callback} callback
|
|
956
|
+
*/
|
|
957
|
+
iapActivateTasks(tasks, callback) {
|
|
958
|
+
const meth = 'adapterBase-iapActivateTasks';
|
|
959
|
+
const origin = `${this.id}-${meth}`;
|
|
960
|
+
log.trace(origin);
|
|
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);
|
|
968
|
+
}
|
|
969
|
+
taskMover.deleteBackups(__dirname);
|
|
970
|
+
return callback(data, null);
|
|
971
|
+
}
|
|
868
972
|
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
973
|
+
/* ********************************************** */
|
|
974
|
+
/* */
|
|
975
|
+
/* EXPOSES CACHE CALLS */
|
|
976
|
+
/* */
|
|
977
|
+
/* ********************************************** */
|
|
978
|
+
/**
|
|
979
|
+
* @summary Populate the cache for the given entities
|
|
980
|
+
*
|
|
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
|
|
985
|
+
*/
|
|
986
|
+
iapPopulateEntityCache(entityTypes, callback) {
|
|
987
|
+
const origin = `${this.myid}-adapterBase-iapPopulateEntityCache`;
|
|
988
|
+
log.trace(origin);
|
|
989
|
+
|
|
990
|
+
return this.requestHandlerInst.populateEntityCache(entityTypes, callback);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* @summary Retrieves data from cache for specified entity type
|
|
995
|
+
*
|
|
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
|
|
1000
|
+
*/
|
|
1001
|
+
iapRetrieveEntitiesCache(entityType, options, callback) {
|
|
1002
|
+
const origin = `${this.myid}-adapterBase-iapRetrieveEntitiesCache`;
|
|
1003
|
+
log.trace(origin);
|
|
1004
|
+
|
|
1005
|
+
return this.requestHandlerInst.retrieveEntitiesCache(entityType, options, callback);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/* ********************************************** */
|
|
1009
|
+
/* */
|
|
1010
|
+
/* EXPOSES BROKER CALLS */
|
|
1011
|
+
/* */
|
|
1012
|
+
/* ********************************************** */
|
|
1013
|
+
/**
|
|
1014
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
1015
|
+
*
|
|
1016
|
+
* @function hasEntities
|
|
1017
|
+
* @param {String} entityType - the entity type to check for
|
|
1018
|
+
* @param {Array} entityList - the list of entities we are looking for
|
|
1019
|
+
*
|
|
1020
|
+
* @param {Callback} callback - A map where the entity is the key and the
|
|
1021
|
+
* value is true or false
|
|
1022
|
+
*/
|
|
1023
|
+
hasEntities(entityType, entityList, callback) {
|
|
1024
|
+
const origin = `${this.id}-adapterBase-hasEntities`;
|
|
1025
|
+
log.trace(origin);
|
|
1026
|
+
|
|
1027
|
+
return this.requestHandlerInst.hasEntities(entityType, entityList, callback);
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* @summary Determines if this adapter supports any in a list of entities
|
|
1032
|
+
*
|
|
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
|
|
1039
|
+
* value is true or false
|
|
1040
|
+
*/
|
|
1041
|
+
hasEntitiesAuth(entityType, entityList, callOptions, callback) {
|
|
1042
|
+
const origin = `${this.id}-adapterBase-hasEntitiesAuth`;
|
|
1043
|
+
log.trace(origin);
|
|
1044
|
+
|
|
1045
|
+
return this.requestHandlerInst.hasEntitiesAuth(entityType, entityList, callOptions, callback);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* @summary Get Appliance that match the deviceName
|
|
1050
|
+
*
|
|
1051
|
+
* @function getDevice
|
|
1052
|
+
* @param {String} deviceName - the deviceName to find (required)
|
|
1053
|
+
*
|
|
1054
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1055
|
+
* (appliance) or the error
|
|
1056
|
+
*/
|
|
1057
|
+
getDevice(deviceName, callback) {
|
|
1058
|
+
const origin = `${this.id}-adapterBase-getDevice`;
|
|
1059
|
+
log.trace(origin);
|
|
1060
|
+
|
|
1061
|
+
return this.requestHandlerInst.getDevice(deviceName, callback);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* @summary Get Appliance that match the deviceName
|
|
1066
|
+
*
|
|
1067
|
+
* @function getDeviceAuth
|
|
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
|
|
1070
|
+
*
|
|
1071
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1072
|
+
* (appliance) or the error
|
|
1073
|
+
*/
|
|
1074
|
+
getDeviceAuth(deviceName, callOptions, callback) {
|
|
1075
|
+
const origin = `${this.id}-adapterBase-getDeviceAuth`;
|
|
1076
|
+
log.trace(origin);
|
|
1077
|
+
|
|
1078
|
+
return this.requestHandlerInst.getDeviceAuth(deviceName, callOptions, callback);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* @summary Get Appliances that match the filter
|
|
1083
|
+
*
|
|
1084
|
+
* @function getDevicesFiltered
|
|
1085
|
+
* @param {Object} options - the data to use to filter the appliances (optional)
|
|
1086
|
+
*
|
|
1087
|
+
* @param {getCallback} callback - a callback function to return the result
|
|
1088
|
+
* (appliances) or the error
|
|
1089
|
+
*/
|
|
1090
|
+
getDevicesFiltered(options, callback) {
|
|
1091
|
+
const origin = `${this.id}-adapterBase-getDevicesFiltered`;
|
|
1092
|
+
log.trace(origin);
|
|
1093
|
+
|
|
1094
|
+
return this.requestHandlerInst.getDevicesFiltered(options, callback);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
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);
|
|
1110
|
+
|
|
1111
|
+
return this.requestHandlerInst.getDevicesFilteredAuth(options, callOptions, callback);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
/**
|
|
1115
|
+
* @summary Gets the status for the provided appliance
|
|
1116
|
+
*
|
|
1117
|
+
* @function isAlive
|
|
1118
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
1119
|
+
*
|
|
1120
|
+
* @param {configCallback} callback - callback function to return the result
|
|
1121
|
+
* (appliance isAlive) or the error
|
|
1122
|
+
*/
|
|
1123
|
+
isAlive(deviceName, callback) {
|
|
1124
|
+
const origin = `${this.id}-adapterBase-isAlive`;
|
|
1125
|
+
log.trace(origin);
|
|
1126
|
+
|
|
1127
|
+
return this.requestHandlerInst.isAlive(deviceName, callback);
|
|
1128
|
+
}
|
|
1129
|
+
|
|
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);
|
|
1143
|
+
|
|
1144
|
+
return this.requestHandlerInst.isAliveAuth(deviceName, callOptions, callback);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* @summary Gets a config for the provided Appliance
|
|
1149
|
+
*
|
|
1150
|
+
* @function getConfig
|
|
1151
|
+
* @param {String} deviceName - the deviceName of the appliance. (required)
|
|
1152
|
+
* @param {String} format - the desired format of the config. (optional)
|
|
1153
|
+
*
|
|
1154
|
+
* @param {configCallback} callback - callback function to return the result
|
|
1155
|
+
* (appliance config) or the error
|
|
1156
|
+
*/
|
|
1157
|
+
getConfig(deviceName, format, callback) {
|
|
1158
|
+
const origin = `${this.id}-adapterBase-getConfig`;
|
|
1159
|
+
log.trace(origin);
|
|
1160
|
+
|
|
1161
|
+
return this.requestHandlerInst.getConfig(deviceName, format, callback);
|
|
1162
|
+
}
|
|
1163
|
+
|
|
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);
|
|
1178
|
+
|
|
1179
|
+
return this.requestHandlerInst.getConfigAuth(deviceName, format, callOptions, callback);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* @summary Gets the device count from the system
|
|
1184
|
+
*
|
|
1185
|
+
* @function iapGetDeviceCount
|
|
1186
|
+
*
|
|
1187
|
+
* @param {getCallback} callback - callback function to return the result
|
|
1188
|
+
* (count) or the error
|
|
1189
|
+
*/
|
|
1190
|
+
iapGetDeviceCount(callback) {
|
|
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';
|
|
1302
|
+
const origin = `${this.id}-${meth}`;
|
|
1303
|
+
log.trace(origin);
|
|
1304
|
+
let command = null;
|
|
1305
|
+
|
|
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);
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
log.error('Package Not Found');
|
|
1330
|
+
return callback(null, 'Package Not Found');
|
|
1331
|
+
}
|
|
1332
|
+
|
|
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');
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// run baseunit test
|
|
1358
|
+
basecommand = spawnSync('npm', ['run', 'test:baseunit'], { cwd: __dirname, encoding: 'utf-8' });
|
|
1359
|
+
|
|
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;
|
|
878
1379
|
}
|
|
1380
|
+
|
|
1381
|
+
// format the response and return it
|
|
1382
|
+
const result = {
|
|
1383
|
+
base: baseresult,
|
|
1384
|
+
unit: unitresult
|
|
1385
|
+
};
|
|
1386
|
+
return callback(result);
|
|
879
1387
|
}
|
|
880
1388
|
|
|
881
|
-
|
|
882
|
-
return callback(
|
|
1389
|
+
log.error('Package Not Found');
|
|
1390
|
+
return callback(null, 'Package Not Found');
|
|
883
1391
|
}
|
|
884
1392
|
|
|
885
1393
|
/**
|
|
886
|
-
* @summary
|
|
887
|
-
* all of the capabilities for the current adapter
|
|
1394
|
+
* @summary provide inventory information abbout the adapter
|
|
888
1395
|
*
|
|
889
|
-
* @function
|
|
1396
|
+
* @function iapGetAdapterInventory
|
|
890
1397
|
*
|
|
891
|
-
* @return {
|
|
1398
|
+
* @return {Object} - containing the adapter inventory information
|
|
892
1399
|
*/
|
|
893
|
-
|
|
894
|
-
const
|
|
1400
|
+
iapGetAdapterInventory(callback) {
|
|
1401
|
+
const meth = 'adapterBase-iapGetAdapterInventory';
|
|
1402
|
+
const origin = `${this.id}-${meth}`;
|
|
895
1403
|
log.trace(origin);
|
|
896
1404
|
|
|
897
|
-
// validate the capabilities for the adapter
|
|
898
1405
|
try {
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
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
|
+
});
|
|
1443
|
+
});
|
|
1444
|
+
} catch (ex) {
|
|
1445
|
+
const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
|
|
1446
|
+
log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
|
|
1447
|
+
return callback(null, errorObj);
|
|
902
1448
|
}
|
|
903
1449
|
}
|
|
904
1450
|
}
|