@itentialopensource/adapter-ciena_mcp 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ ## 0.2.0 [01-21-2022]
3
+
4
+ * migration to the latest foundation and broker ready
5
+
6
+ See merge request itentialopensource/adapters/controller-orchestrator/adapter-ciena_mcp!1
7
+
8
+ ---
9
+
2
10
  ## 0.1.1 [07-23-2021]
3
11
 
4
12
  * Bug fixes and performance improvements
@@ -6,4 +14,3 @@
6
14
  See commit 332dc00
7
15
 
8
16
  ---
9
-
package/README.md CHANGED
@@ -400,7 +400,7 @@ There are several node scripts that now accompany the adapter. These scripts are
400
400
  | npm run troubleshoot | Provides a way to troubleshoot the adapter - runs connectivity, healthcheck and basic get.|
401
401
  | npm run connectivity | Provides a connectivity check to the Ciena_mcp system.|
402
402
  | npm run healthcheck | Checks whether the configured healthcheck call works to Ciena_mcp.|
403
- | npm run basicget | Checks whether the cbasic get calls works to Ciena_mcp.|
403
+ | npm run basicget | Checks whether the basic get calls works to Ciena_mcp.|
404
404
 
405
405
  ## Installing an Itential Product Adapter
406
406
 
@@ -414,21 +414,21 @@ if the @itentialopensource directory does not exist, create it:
414
414
  mkdir @itentialopensource
415
415
  ```
416
416
 
417
- 1. Clone the adapter into your IAP environment.
417
+ 2. Clone the adapter into your IAP environment.
418
418
 
419
419
  ```bash
420
420
  cd \@itentialopensource
421
421
  git clone git@gitlab.com:\@itentialopensource/adapters/adapter-ciena_mcp
422
422
  ```
423
423
 
424
- 1. Run the adapter install script.
424
+ 3. Run the adapter install script.
425
425
 
426
426
  ```bash
427
427
  cd adapter-ciena_mcp
428
428
  npm run adapter:install
429
429
  ```
430
430
 
431
- 1. Restart IAP
431
+ 4. Restart IAP
432
432
 
433
433
  ```bash
434
434
  systemctl restart pronghorn
@@ -448,7 +448,7 @@ Depending on where your code is located, this process is different.
448
448
  Adapter should be placed into: /opt/pronghorn/current/node_modules/\@itentialopensource
449
449
  ```
450
450
 
451
- 1. Follow Steps 3-4 (above) to install an Itential adapter to load your properties, dependencies and restart IAP.
451
+ 2. Follow Steps 3-4 (above) to install an Itential adapter to load your properties, dependencies and restart IAP.
452
452
 
453
453
  ## Using this Adapter
454
454
 
@@ -553,6 +553,10 @@ Specific adapter calls are built based on the API of the Ciena_mcp. The Adapter
553
553
 
554
554
  ## Extending/Enhancing the Adapter
555
555
 
556
+ ### Adding a Second Instance of an Adapter
557
+
558
+ You can add a second instance of this adapter without adding new code on the file system. To do this go into the IAP Admin Essentials and add a new service config for this adapter. The two instances of the adapter should have unique ids. In addition, they should point to different instances of the other system. For example, they should be configured to talk to different hosts.
559
+
556
560
  ### Adding Adapter Calls
557
561
 
558
562
  There are multiple ways to add calls to an existing adapter.
@@ -635,26 +639,26 @@ User also have the option to run individual command to perform specific test
635
639
  npm run troubleshoot
636
640
  ```
637
641
 
638
- 1. Verify the adapter properties are set up correctly.
642
+ 2. Verify the adapter properties are set up correctly.
639
643
 
640
644
  ```text
641
645
  Go into the Itential Platform GUI and verify/update the properties
642
646
  ```
643
647
 
644
- 1. Verify there is connectivity between the Itential Platform Server and Ciena_mcp Server.
648
+ 3. Verify there is connectivity between the Itential Platform Server and Ciena_mcp Server.
645
649
 
646
650
  ```text
647
651
  ping the ip address of Ciena_mcp server
648
652
  try telnet to the ip address port of Ciena_mcp
649
653
  ```
650
654
 
651
- 1. Verify the credentials provided for Ciena_mcp.
655
+ 4. Verify the credentials provided for Ciena_mcp.
652
656
 
653
657
  ```text
654
658
  login to Ciena_mcp using the provided credentials
655
659
  ```
656
660
 
657
- 1. Verify the API of the call utilized for Ciena_mcp Healthcheck.
661
+ 5. Verify the API of the call utilized for Ciena_mcp Healthcheck.
658
662
 
659
663
  ```text
660
664
  Go into the Itential Platform GUI and verify/update the properties
package/adapter.js CHANGED
@@ -83,7 +83,7 @@ class CienaMcp extends AdapterBaseCl {
83
83
  * @getWorkflowFunctions
84
84
  */
85
85
  getWorkflowFunctions(inIgnore) {
86
- let myIgnore = [];
86
+ let myIgnore = ['hasEntities', 'hasDevices'];
87
87
  if (!inIgnore && Array.isArray(inIgnore)) {
88
88
  myIgnore = inIgnore;
89
89
  } else if (!inIgnore && typeof inIgnore === 'string') {
@@ -247,6 +247,24 @@ class CienaMcp extends AdapterBaseCl {
247
247
  }
248
248
  }
249
249
 
250
+ /**
251
+ * @summary moves entites into Mongo DB
252
+ *
253
+ * @function moveEntitiesToDB
254
+ * @param {getCallback} callback - a callback function to return the result (Generics)
255
+ * or the error
256
+ */
257
+ moveEntitiesToDB(callback) {
258
+ const origin = `${this.id}-adapter-moveEntitiesToDB`;
259
+ log.trace(origin);
260
+ try {
261
+ return super.moveEntitiesToDB(callback);
262
+ } catch (err) {
263
+ log.error(`${origin}: ${err}`);
264
+ return callback(null, err);
265
+ }
266
+ }
267
+
250
268
  /**
251
269
  * @summary Determines if this adapter supports the specific entity
252
270
  *
@@ -443,11 +461,6 @@ class CienaMcp extends AdapterBaseCl {
443
461
  }
444
462
 
445
463
  /* HERE IS WHERE YOU VALIDATE DATA */
446
- if (uriPath === undefined || uriPath === null || uriPath === '') {
447
- const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['uriPath'], null, null, null);
448
- log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
449
- return callback(null, errorObj);
450
- }
451
464
  if (restMethod === undefined || restMethod === null || restMethod === '') {
452
465
  const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['restMethod'], null, null, null);
453
466
  log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
@@ -456,11 +469,14 @@ class CienaMcp extends AdapterBaseCl {
456
469
 
457
470
  /* HERE IS WHERE YOU SET THE DATA TO PASS INTO REQUEST */
458
471
  // remove any leading / and split the uripath into path variables
459
- let myPath = uriPath;
460
- while (myPath.indexOf('/') === 0) {
461
- myPath = myPath.substring(1);
472
+ let pathVars = [];
473
+ if (uriPath) {
474
+ let myPath = uriPath;
475
+ while (myPath.indexOf('/') === 0) {
476
+ myPath = myPath.substring(1);
477
+ }
478
+ pathVars = myPath.split('/');
462
479
  }
463
- const pathVars = myPath.split('/');
464
480
  const queryParamsAvailable = queryData;
465
481
  const queryParams = {};
466
482
  const bodyVars = requestBody;
@@ -526,6 +542,456 @@ class CienaMcp extends AdapterBaseCl {
526
542
  }
527
543
  }
528
544
 
545
+ /* BROKER CALLS */
546
+ /**
547
+ * @summary Determines if this adapter supports any in a list of entities
548
+ *
549
+ * @function hasEntities
550
+ * @param {String} entityType - the entity type to check for
551
+ * @param {Array} entityList - the list of entities we are looking for
552
+ *
553
+ * @param {Callback} callback - A map where the entity is the key and the
554
+ * value is true or false
555
+ */
556
+ hasEntities(entityType, entityList, callback) {
557
+ const origin = `${this.id}-adapter-hasEntities`;
558
+ log.trace(origin);
559
+
560
+ switch (entityType) {
561
+ case 'Device':
562
+ return this.hasDevices(entityList, callback);
563
+ default:
564
+ return callback(null, `${this.id} does not support entity ${entityType}`);
565
+ }
566
+ }
567
+
568
+ /**
569
+ * @summary Helper method for hasEntities for the specific device case
570
+ *
571
+ * @param {Array} deviceList - array of unique device identifiers
572
+ * @param {Callback} callback - A map where the device is the key and the
573
+ * value is true or false
574
+ */
575
+ hasDevices(deviceList, callback) {
576
+ const origin = `${this.id}-adapter-hasDevices`;
577
+ log.trace(origin);
578
+
579
+ const findings = deviceList.reduce((map, device) => {
580
+ // eslint-disable-next-line no-param-reassign
581
+ map[device] = false;
582
+ log.debug(`In reduce: ${JSON.stringify(map)}`);
583
+ return map;
584
+ }, {});
585
+ const apiCalls = deviceList.map((device) => new Promise((resolve) => {
586
+ this.getDevice(device, (result, error) => {
587
+ if (error) {
588
+ log.debug(`In map error: ${JSON.stringify(device)}`);
589
+ return resolve({ name: device, found: false });
590
+ }
591
+ log.debug(`In map: ${JSON.stringify(device)}`);
592
+ return resolve({ name: device, found: true });
593
+ });
594
+ }));
595
+ Promise.all(apiCalls).then((results) => {
596
+ results.forEach((device) => {
597
+ findings[device.name] = device.found;
598
+ });
599
+ log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
600
+ return callback(findings);
601
+ }).catch((errors) => {
602
+ log.error('Unable to do device lookup.');
603
+ return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
604
+ });
605
+ }
606
+
607
+ /**
608
+ * @summary Get Appliance that match the deviceName
609
+ *
610
+ * @function getDevice
611
+ * @param {String} deviceName - the deviceName to find (required)
612
+ *
613
+ * @param {getCallback} callback - a callback function to return the result
614
+ * (appliance) or the error
615
+ */
616
+ getDevice(deviceName, callback) {
617
+ const meth = 'adapter-getDevice';
618
+ const origin = `${this.id}-${meth}`;
619
+ log.trace(origin);
620
+
621
+ if (this.suspended && this.suspendMode === 'error') {
622
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
623
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
624
+ return callback(null, errorObj);
625
+ }
626
+
627
+ /* HERE IS WHERE YOU VALIDATE DATA */
628
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
629
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
630
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
631
+ return callback(null, errorObj);
632
+ }
633
+
634
+ try {
635
+ // need to get the device so we can convert the deviceName to an id
636
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
637
+ const opts = {
638
+ filter: {
639
+ name: deviceName
640
+ }
641
+ };
642
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
643
+ // if we received an error or their is no response on the results return an error
644
+ if (ferr) {
645
+ return callback(null, ferr);
646
+ }
647
+ if (devs.list.length < 1) {
648
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
649
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
650
+ return callback(null, errorObj);
651
+ }
652
+ // get the uuid from the device
653
+ const { uuid } = devs.list[0];
654
+
655
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
656
+ // !! you can also replace with a specific call if that is easier
657
+ const uriPath = `/call/toget/device/${uuid}`;
658
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
659
+ // if we received an error or their is no response on the results return an error
660
+ if (error) {
661
+ return callback(null, error);
662
+ }
663
+ if (!result.response || !result.response.applianceMo) {
664
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
665
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
666
+ return callback(null, errorObj);
667
+ }
668
+
669
+ // return the response
670
+ // !! format the data we send back
671
+ // !! these fields are config manager fields you need to map to the data we receive
672
+ const thisDevice = result.response;
673
+ thisDevice.name = thisDevice.systemName;
674
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
675
+ thisDevice.port = thisDevice.systemPort;
676
+ thisDevice.ipaddress = thisDevice.systemIP;
677
+ return callback(thisDevice);
678
+ });
679
+ });
680
+ } catch (ex) {
681
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
682
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
683
+ return callback(null, errorObj);
684
+ }
685
+ }
686
+
687
+ /**
688
+ * @summary Get Appliances that match the filter
689
+ *
690
+ * @function getDevicesFiltered
691
+ * @param {Object} options - the data to use to filter the appliances (optional)
692
+ *
693
+ * @param {getCallback} callback - a callback function to return the result
694
+ * (appliances) or the error
695
+ */
696
+ getDevicesFiltered(options, callback) {
697
+ const meth = 'adapter-getDevicesFiltered';
698
+ const origin = `${this.id}-${meth}`;
699
+ log.trace(origin);
700
+
701
+ // verify the required fields have been provided
702
+ if (options === undefined || options === null || options === '' || options.length === 0) {
703
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
704
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
705
+ return callback(null, errorObj);
706
+ }
707
+ log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
708
+
709
+ // TODO - get pagination working
710
+ // const nextToken = options.start;
711
+ // const maxResults = options.limit;
712
+
713
+ // set up the filter of Device Names
714
+ let filterName = [];
715
+ if (options && options.filter && options.filter.name) {
716
+ // when this hack is removed, remove the lint ignore above
717
+ if (Array.isArray(options.filter.name)) {
718
+ // eslint-disable-next-line prefer-destructuring
719
+ filterName = options.filter.name;
720
+ } else {
721
+ filterName = [options.filter.name];
722
+ }
723
+ }
724
+
725
+ // TODO - get sort and order working
726
+ /*
727
+ if (options && options.sort) {
728
+ reqObj.uriOptions.sort = JSON.stringify(options.sort);
729
+ }
730
+ if (options && options.order) {
731
+ reqObj.uriOptions.order = options.order;
732
+ }
733
+ */
734
+ try {
735
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
736
+ // !! you can also replace with a specific call if that is easier
737
+ const uriPath = '/call/toget/devices';
738
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
739
+ // if we received an error or their is no response on the results return an error
740
+ if (error) {
741
+ return callback(null, error);
742
+ }
743
+ if (!result.response) {
744
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
745
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
746
+ return callback(null, errorObj);
747
+ }
748
+
749
+ // !! go through the response - may have to look for sub object
750
+ // handle an array of devices
751
+ if (Array.isArray(result.response)) {
752
+ const myDevices = [];
753
+
754
+ for (let d = 0; d < result.response.length; d += 1) {
755
+ // !! format the data we send back
756
+ // !! these fields are config manager fields you need to map to the data we receive
757
+ const thisDevice = result.response;
758
+ thisDevice.name = thisDevice.systemName;
759
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
760
+ thisDevice.port = thisDevice.systemPort;
761
+ thisDevice.ipaddress = thisDevice.systemIP;
762
+
763
+ // if there is no filter - return the device
764
+ if (filterName.length === 0) {
765
+ myDevices.push(thisDevice);
766
+ } else {
767
+ // if we have to match a filter
768
+ let found = false;
769
+ for (let f = 0; f < filterName.length; f += 1) {
770
+ if (thisDevice.name.indexOf(filterName[f]) >= 0) {
771
+ found = true;
772
+ break;
773
+ }
774
+ }
775
+ // matching device
776
+ if (found) {
777
+ myDevices.push(thisDevice);
778
+ }
779
+ }
780
+ }
781
+ log.debug(`${origin}: Found #${myDevices.length} devices.`);
782
+ log.debug(`Devices: ${JSON.stringify(myDevices)}`);
783
+ return callback({ total: myDevices.length, list: myDevices });
784
+ }
785
+ // handle a single device response
786
+ // !! format the data we send back
787
+ // !! these fields are config manager fields you need to map to the data we receive
788
+ const thisDevice = result.response;
789
+ thisDevice.name = thisDevice.systemName;
790
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
791
+ thisDevice.port = thisDevice.systemPort;
792
+ thisDevice.ipaddress = thisDevice.systemIP;
793
+
794
+ // if there is no filter - return the device
795
+ if (filterName.length === 0) {
796
+ log.debug(`${origin}: Found #1 device.`);
797
+ log.debug(`Device: ${JSON.stringify(thisDevice)}`);
798
+ return callback({ total: 1, list: [thisDevice] });
799
+ }
800
+
801
+ // if there is a filter need to check for matching device
802
+ let found = false;
803
+ for (let f = 0; f < filterName.length; f += 1) {
804
+ if (thisDevice.name.indexOf(filterName[f]) >= 0) {
805
+ found = true;
806
+ break;
807
+ }
808
+ }
809
+ // matching device
810
+ if (found) {
811
+ log.debug(`${origin}: Found #1 device.`);
812
+ log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
813
+ return callback({ total: 1, list: [thisDevice] });
814
+ }
815
+ // not a matching device
816
+ log.debug(`${origin}: No matching device found.`);
817
+ return callback({ total: 0, list: [] });
818
+ });
819
+ } catch (ex) {
820
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
821
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
822
+ return callback(null, errorObj);
823
+ }
824
+ }
825
+
826
+ /**
827
+ * @summary Gets the status for the provided appliance
828
+ *
829
+ * @function isAlive
830
+ * @param {String} deviceName - the deviceName of the appliance. (required)
831
+ *
832
+ * @param {configCallback} callback - callback function to return the result
833
+ * (appliance isAlive) or the error
834
+ */
835
+ isAlive(deviceName, callback) {
836
+ const meth = 'adapter-isAlive';
837
+ const origin = `${this.id}-${meth}`;
838
+ log.trace(origin);
839
+
840
+ // verify the required fields have been provided
841
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
842
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
843
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
844
+ return callback(null, errorObj);
845
+ }
846
+
847
+ try {
848
+ // need to get the device so we can convert the deviceName to an id
849
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
850
+ const opts = {
851
+ filter: {
852
+ name: deviceName
853
+ }
854
+ };
855
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
856
+ // if we received an error or their is no response on the results return an error
857
+ if (ferr) {
858
+ return callback(null, ferr);
859
+ }
860
+ if (devs.list.length < 1) {
861
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
862
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
863
+ return callback(null, errorObj);
864
+ }
865
+ // get the uuid from the device
866
+ const { uuid } = devs.list[0];
867
+
868
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
869
+ // !! you can also replace with a specific call if that is easier
870
+ const uriPath = `/call/toget/status/${uuid}`;
871
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
872
+ // if we received an error or their is no response on the results return an error
873
+ if (error) {
874
+ return callback(null, error);
875
+ }
876
+ // !! should update this to make sure we are checking for the appropriate object/field
877
+ if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
878
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
879
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
880
+ return callback(null, errorObj);
881
+ }
882
+
883
+ // !! return the response - Update to the appropriate object/field
884
+ return callback(!result.response.returnObj.statusField);
885
+ });
886
+ });
887
+ } catch (ex) {
888
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
889
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
890
+ return callback(null, errorObj);
891
+ }
892
+ }
893
+
894
+ /**
895
+ * @summary Gets a config for the provided Appliance
896
+ *
897
+ * @function getConfig
898
+ * @param {String} deviceName - the deviceName of the appliance. (required)
899
+ * @param {String} format - the desired format of the config. (optional)
900
+ *
901
+ * @param {configCallback} callback - callback function to return the result
902
+ * (appliance config) or the error
903
+ */
904
+ getConfig(deviceName, format, callback) {
905
+ const meth = 'adapter-getConfig';
906
+ const origin = `${this.id}-${meth}`;
907
+ log.trace(origin);
908
+
909
+ // verify the required fields have been provided
910
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
911
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
912
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
913
+ return callback(null, errorObj);
914
+ }
915
+
916
+ try {
917
+ // need to get the device so we can convert the deviceName to an id
918
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
919
+ const opts = {
920
+ filter: {
921
+ name: deviceName
922
+ }
923
+ };
924
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
925
+ // if we received an error or their is no response on the results return an error
926
+ if (ferr) {
927
+ return callback(null, ferr);
928
+ }
929
+ if (devs.list.length < 1) {
930
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
931
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
932
+ return callback(null, errorObj);
933
+ }
934
+ // get the uuid from the device
935
+ const { uuid } = devs.list[0];
936
+
937
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
938
+ // !! you can also replace with a specific call if that is easier
939
+ const uriPath = `/call/toget/config/${uuid}`;
940
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
941
+ // if we received an error or their is no response on the results return an error
942
+ if (error) {
943
+ return callback(null, error);
944
+ }
945
+
946
+ // return the result
947
+ const newResponse = {
948
+ response: JSON.stringify(result.response, null, 2)
949
+ };
950
+ return callback(newResponse);
951
+ });
952
+ });
953
+ } catch (ex) {
954
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
955
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
956
+ return callback(null, errorObj);
957
+ }
958
+ }
959
+
960
+ /**
961
+ * @summary Gets the device count from the system
962
+ *
963
+ * @function getCount
964
+ *
965
+ * @param {getCallback} callback - callback function to return the result
966
+ * (count) or the error
967
+ */
968
+ getCount(callback) {
969
+ const meth = 'adapter-getCount';
970
+ const origin = `${this.id}-${meth}`;
971
+ log.trace(origin);
972
+
973
+ // verify the required fields have been provided
974
+
975
+ try {
976
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
977
+ // !! you can also replace with a specific call if that is easier
978
+ const uriPath = '/call/toget/count';
979
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
980
+ // if we received an error or their is no response on the results return an error
981
+ if (error) {
982
+ return callback(null, error);
983
+ }
984
+
985
+ // return the result
986
+ return callback({ count: result.response });
987
+ });
988
+ } catch (ex) {
989
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
990
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
991
+ return callback(null, errorObj);
992
+ }
993
+ }
994
+
529
995
  /**
530
996
  * @callback healthCallback
531
997
  * @param {Object} result - the result of the get request (contains an id and a status)
package/adapterBase.js CHANGED
@@ -22,6 +22,7 @@ const AjvCl = require('ajv');
22
22
  const PropUtilCl = require('@itentialopensource/adapter-utils').PropertyUtility;
23
23
  const RequestHandlerCl = require('@itentialopensource/adapter-utils').RequestHandler;
24
24
 
25
+ const entitiesToDB = require(path.join(__dirname, 'utils/entitiesToDB'));
25
26
  const troubleshootingAdapter = require(path.join(__dirname, 'utils/troubleshootingAdapter'));
26
27
  const tbUtils = require(path.join(__dirname, 'utils/tbUtils'));
27
28
 
@@ -821,7 +822,7 @@ class AdapterBase extends EventEmitterCl {
821
822
  */
822
823
  async runConnectivity(callback) {
823
824
  try {
824
- const { serviceItem } = await troubleshootingAdapter.getAdapterConfig();
825
+ const { serviceItem } = await tbUtils.getAdapterConfig();
825
826
  const { host } = serviceItem.properties.properties;
826
827
  const result = tbUtils.runConnectivity(host, false);
827
828
  if (result.failCount > 0) {
@@ -1001,6 +1002,27 @@ class AdapterBase extends EventEmitterCl {
1001
1002
  return [];
1002
1003
  }
1003
1004
  }
1005
+
1006
+ /**
1007
+ * @summary moves entities to mongo database
1008
+ *
1009
+ * @function moveEntitiesToDB
1010
+ *
1011
+ * @return {Callback} - containing the response from the mongo transaction
1012
+ */
1013
+ moveEntitiesToDB(callback) {
1014
+ const meth = 'adapterBase-moveEntitiesToDB';
1015
+ const origin = `${this.id}-${meth}`;
1016
+ log.trace(origin);
1017
+
1018
+ try {
1019
+ return callback(entitiesToDB.moveEntitiesToDB(__dirname, { pronghornProps: this.allProps, id: this.id }), null);
1020
+ } catch (err) {
1021
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, err);
1022
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
1023
+ return callback(null, errorObj);
1024
+ }
1025
+ }
1004
1026
  }
1005
1027
 
1006
1028
  module.exports = AdapterBase;