@itentialopensource/adapter-nokia_altiplano 0.1.3 → 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/adapter.js CHANGED
@@ -83,7 +83,7 @@ class NokiaAltiplano 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 NokiaAltiplano 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
  *
@@ -526,6 +544,456 @@ class NokiaAltiplano extends AdapterBaseCl {
526
544
  }
527
545
  }
528
546
 
547
+ /* BROKER CALLS */
548
+ /**
549
+ * @summary Determines if this adapter supports any in a list of entities
550
+ *
551
+ * @function hasEntities
552
+ * @param {String} entityType - the entity type to check for
553
+ * @param {Array} entityList - the list of entities we are looking for
554
+ *
555
+ * @param {Callback} callback - A map where the entity is the key and the
556
+ * value is true or false
557
+ */
558
+ hasEntities(entityType, entityList, callback) {
559
+ const origin = `${this.id}-adapter-hasEntities`;
560
+ log.trace(origin);
561
+
562
+ switch (entityType) {
563
+ case 'Device':
564
+ return this.hasDevices(entityList, callback);
565
+ default:
566
+ return callback(null, `${this.id} does not support entity ${entityType}`);
567
+ }
568
+ }
569
+
570
+ /**
571
+ * @summary Helper method for hasEntities for the specific device case
572
+ *
573
+ * @param {Array} deviceList - array of unique device identifiers
574
+ * @param {Callback} callback - A map where the device is the key and the
575
+ * value is true or false
576
+ */
577
+ hasDevices(deviceList, callback) {
578
+ const origin = `${this.id}-adapter-hasDevices`;
579
+ log.trace(origin);
580
+
581
+ const findings = deviceList.reduce((map, device) => {
582
+ // eslint-disable-next-line no-param-reassign
583
+ map[device] = false;
584
+ log.debug(`In reduce: ${JSON.stringify(map)}`);
585
+ return map;
586
+ }, {});
587
+ const apiCalls = deviceList.map((device) => new Promise((resolve) => {
588
+ this.getDevice(device, (result, error) => {
589
+ if (error) {
590
+ log.debug(`In map error: ${JSON.stringify(device)}`);
591
+ return resolve({ name: device, found: false });
592
+ }
593
+ log.debug(`In map: ${JSON.stringify(device)}`);
594
+ return resolve({ name: device, found: true });
595
+ });
596
+ }));
597
+ Promise.all(apiCalls).then((results) => {
598
+ results.forEach((device) => {
599
+ findings[device.name] = device.found;
600
+ });
601
+ log.debug(`FINDINGS: ${JSON.stringify(findings)}`);
602
+ return callback(findings);
603
+ }).catch((errors) => {
604
+ log.error('Unable to do device lookup.');
605
+ return callback(null, { code: 503, message: 'Unable to do device lookup.', error: errors });
606
+ });
607
+ }
608
+
609
+ /**
610
+ * @summary Get Appliance that match the deviceName
611
+ *
612
+ * @function getDevice
613
+ * @param {String} deviceName - the deviceName to find (required)
614
+ *
615
+ * @param {getCallback} callback - a callback function to return the result
616
+ * (appliance) or the error
617
+ */
618
+ getDevice(deviceName, callback) {
619
+ const meth = 'adapter-getDevice';
620
+ const origin = `${this.id}-${meth}`;
621
+ log.trace(origin);
622
+
623
+ if (this.suspended && this.suspendMode === 'error') {
624
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'AD.600', [], null, null, null);
625
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
626
+ return callback(null, errorObj);
627
+ }
628
+
629
+ /* HERE IS WHERE YOU VALIDATE DATA */
630
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
631
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
632
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
633
+ return callback(null, errorObj);
634
+ }
635
+
636
+ try {
637
+ // need to get the device so we can convert the deviceName to an id
638
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
639
+ const opts = {
640
+ filter: {
641
+ name: deviceName
642
+ }
643
+ };
644
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
645
+ // if we received an error or their is no response on the results return an error
646
+ if (ferr) {
647
+ return callback(null, ferr);
648
+ }
649
+ if (devs.list.length < 1) {
650
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
651
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
652
+ return callback(null, errorObj);
653
+ }
654
+ // get the uuid from the device
655
+ const { uuid } = devs.list[0];
656
+
657
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
658
+ // !! you can also replace with a specific call if that is easier
659
+ const uriPath = `/call/toget/device/${uuid}`;
660
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
661
+ // if we received an error or their is no response on the results return an error
662
+ if (error) {
663
+ return callback(null, error);
664
+ }
665
+ if (!result.response || !result.response.applianceMo) {
666
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevice'], null, null, null);
667
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
668
+ return callback(null, errorObj);
669
+ }
670
+
671
+ // return the response
672
+ // !! format the data we send back
673
+ // !! these fields are config manager fields you need to map to the data we receive
674
+ const thisDevice = result.response;
675
+ thisDevice.name = thisDevice.systemName;
676
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
677
+ thisDevice.port = thisDevice.systemPort;
678
+ thisDevice.ipaddress = thisDevice.systemIP;
679
+ return callback(thisDevice);
680
+ });
681
+ });
682
+ } catch (ex) {
683
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
684
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
685
+ return callback(null, errorObj);
686
+ }
687
+ }
688
+
689
+ /**
690
+ * @summary Get Appliances that match the filter
691
+ *
692
+ * @function getDevicesFiltered
693
+ * @param {Object} options - the data to use to filter the appliances (optional)
694
+ *
695
+ * @param {getCallback} callback - a callback function to return the result
696
+ * (appliances) or the error
697
+ */
698
+ getDevicesFiltered(options, callback) {
699
+ const meth = 'adapter-getDevicesFiltered';
700
+ const origin = `${this.id}-${meth}`;
701
+ log.trace(origin);
702
+
703
+ // verify the required fields have been provided
704
+ if (options === undefined || options === null || options === '' || options.length === 0) {
705
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['options'], null, null, null);
706
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
707
+ return callback(null, errorObj);
708
+ }
709
+ log.debug(`Device Filter Options: ${JSON.stringify(options)}`);
710
+
711
+ // TODO - get pagination working
712
+ // const nextToken = options.start;
713
+ // const maxResults = options.limit;
714
+
715
+ // set up the filter of Device Names
716
+ let filterName = [];
717
+ if (options && options.filter && options.filter.name) {
718
+ // when this hack is removed, remove the lint ignore above
719
+ if (Array.isArray(options.filter.name)) {
720
+ // eslint-disable-next-line prefer-destructuring
721
+ filterName = options.filter.name;
722
+ } else {
723
+ filterName = [options.filter.name];
724
+ }
725
+ }
726
+
727
+ // TODO - get sort and order working
728
+ /*
729
+ if (options && options.sort) {
730
+ reqObj.uriOptions.sort = JSON.stringify(options.sort);
731
+ }
732
+ if (options && options.order) {
733
+ reqObj.uriOptions.order = options.order;
734
+ }
735
+ */
736
+ try {
737
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
738
+ // !! you can also replace with a specific call if that is easier
739
+ const uriPath = '/call/toget/devices';
740
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
741
+ // if we received an error or their is no response on the results return an error
742
+ if (error) {
743
+ return callback(null, error);
744
+ }
745
+ if (!result.response) {
746
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['getDevicesFiltered'], null, null, null);
747
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
748
+ return callback(null, errorObj);
749
+ }
750
+
751
+ // !! go through the response - may have to look for sub object
752
+ // handle an array of devices
753
+ if (Array.isArray(result.response)) {
754
+ const myDevices = [];
755
+
756
+ for (let d = 0; d < result.response.length; d += 1) {
757
+ // !! format the data we send back
758
+ // !! these fields are config manager fields you need to map to the data we receive
759
+ const thisDevice = result.response;
760
+ thisDevice.name = thisDevice.systemName;
761
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
762
+ thisDevice.port = thisDevice.systemPort;
763
+ thisDevice.ipaddress = thisDevice.systemIP;
764
+
765
+ // if there is no filter - return the device
766
+ if (filterName.length === 0) {
767
+ myDevices.push(thisDevice);
768
+ } else {
769
+ // if we have to match a filter
770
+ let found = false;
771
+ for (let f = 0; f < filterName.length; f += 1) {
772
+ if (thisDevice.name.indexOf(filterName[f]) >= 0) {
773
+ found = true;
774
+ break;
775
+ }
776
+ }
777
+ // matching device
778
+ if (found) {
779
+ myDevices.push(thisDevice);
780
+ }
781
+ }
782
+ }
783
+ log.debug(`${origin}: Found #${myDevices.length} devices.`);
784
+ log.debug(`Devices: ${JSON.stringify(myDevices)}`);
785
+ return callback({ total: myDevices.length, list: myDevices });
786
+ }
787
+ // handle a single device response
788
+ // !! format the data we send back
789
+ // !! these fields are config manager fields you need to map to the data we receive
790
+ const thisDevice = result.response;
791
+ thisDevice.name = thisDevice.systemName;
792
+ thisDevice.ostype = `System-${thisDevice.systemType}`;
793
+ thisDevice.port = thisDevice.systemPort;
794
+ thisDevice.ipaddress = thisDevice.systemIP;
795
+
796
+ // if there is no filter - return the device
797
+ if (filterName.length === 0) {
798
+ log.debug(`${origin}: Found #1 device.`);
799
+ log.debug(`Device: ${JSON.stringify(thisDevice)}`);
800
+ return callback({ total: 1, list: [thisDevice] });
801
+ }
802
+
803
+ // if there is a filter need to check for matching device
804
+ let found = false;
805
+ for (let f = 0; f < filterName.length; f += 1) {
806
+ if (thisDevice.name.indexOf(filterName[f]) >= 0) {
807
+ found = true;
808
+ break;
809
+ }
810
+ }
811
+ // matching device
812
+ if (found) {
813
+ log.debug(`${origin}: Found #1 device.`);
814
+ log.debug(`Device Found: ${JSON.stringify(thisDevice)}`);
815
+ return callback({ total: 1, list: [thisDevice] });
816
+ }
817
+ // not a matching device
818
+ log.debug(`${origin}: No matching device found.`);
819
+ return callback({ total: 0, list: [] });
820
+ });
821
+ } catch (ex) {
822
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
823
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
824
+ return callback(null, errorObj);
825
+ }
826
+ }
827
+
828
+ /**
829
+ * @summary Gets the status for the provided appliance
830
+ *
831
+ * @function isAlive
832
+ * @param {String} deviceName - the deviceName of the appliance. (required)
833
+ *
834
+ * @param {configCallback} callback - callback function to return the result
835
+ * (appliance isAlive) or the error
836
+ */
837
+ isAlive(deviceName, callback) {
838
+ const meth = 'adapter-isAlive';
839
+ const origin = `${this.id}-${meth}`;
840
+ log.trace(origin);
841
+
842
+ // verify the required fields have been provided
843
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
844
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
845
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
846
+ return callback(null, errorObj);
847
+ }
848
+
849
+ try {
850
+ // need to get the device so we can convert the deviceName to an id
851
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
852
+ const opts = {
853
+ filter: {
854
+ name: deviceName
855
+ }
856
+ };
857
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
858
+ // if we received an error or their is no response on the results return an error
859
+ if (ferr) {
860
+ return callback(null, ferr);
861
+ }
862
+ if (devs.list.length < 1) {
863
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
864
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
865
+ return callback(null, errorObj);
866
+ }
867
+ // get the uuid from the device
868
+ const { uuid } = devs.list[0];
869
+
870
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
871
+ // !! you can also replace with a specific call if that is easier
872
+ const uriPath = `/call/toget/status/${uuid}`;
873
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
874
+ // if we received an error or their is no response on the results return an error
875
+ if (error) {
876
+ return callback(null, error);
877
+ }
878
+ // !! should update this to make sure we are checking for the appropriate object/field
879
+ if (!result.response || !result.response.returnObj || !Object.hasOwnProperty.call(result.response.returnObj, 'statusField')) {
880
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Invalid Response', ['isAlive'], null, null, null);
881
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
882
+ return callback(null, errorObj);
883
+ }
884
+
885
+ // !! return the response - Update to the appropriate object/field
886
+ return callback(!result.response.returnObj.statusField);
887
+ });
888
+ });
889
+ } catch (ex) {
890
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
891
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
892
+ return callback(null, errorObj);
893
+ }
894
+ }
895
+
896
+ /**
897
+ * @summary Gets a config for the provided Appliance
898
+ *
899
+ * @function getConfig
900
+ * @param {String} deviceName - the deviceName of the appliance. (required)
901
+ * @param {String} format - the desired format of the config. (optional)
902
+ *
903
+ * @param {configCallback} callback - callback function to return the result
904
+ * (appliance config) or the error
905
+ */
906
+ getConfig(deviceName, format, callback) {
907
+ const meth = 'adapter-getConfig';
908
+ const origin = `${this.id}-${meth}`;
909
+ log.trace(origin);
910
+
911
+ // verify the required fields have been provided
912
+ if (deviceName === undefined || deviceName === null || deviceName === '' || deviceName.length === 0) {
913
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Missing Data', ['deviceName'], null, null, null);
914
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
915
+ return callback(null, errorObj);
916
+ }
917
+
918
+ try {
919
+ // need to get the device so we can convert the deviceName to an id
920
+ // !! if we can do a lookup by name the getDevicesFiltered may not be necessary
921
+ const opts = {
922
+ filter: {
923
+ name: deviceName
924
+ }
925
+ };
926
+ return this.getDevicesFiltered(opts, (devs, ferr) => {
927
+ // if we received an error or their is no response on the results return an error
928
+ if (ferr) {
929
+ return callback(null, ferr);
930
+ }
931
+ if (devs.list.length < 1) {
932
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, `Did Not Find Device ${deviceName}`, [], null, null, null);
933
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
934
+ return callback(null, errorObj);
935
+ }
936
+ // get the uuid from the device
937
+ const { uuid } = devs.list[0];
938
+
939
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
940
+ // !! you can also replace with a specific call if that is easier
941
+ const uriPath = `/call/toget/config/${uuid}`;
942
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
943
+ // if we received an error or their is no response on the results return an error
944
+ if (error) {
945
+ return callback(null, error);
946
+ }
947
+
948
+ // return the result
949
+ const newResponse = {
950
+ response: JSON.stringify(result.response, null, 2)
951
+ };
952
+ return callback(newResponse);
953
+ });
954
+ });
955
+ } catch (ex) {
956
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
957
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
958
+ return callback(null, errorObj);
959
+ }
960
+ }
961
+
962
+ /**
963
+ * @summary Gets the device count from the system
964
+ *
965
+ * @function getCount
966
+ *
967
+ * @param {getCallback} callback - callback function to return the result
968
+ * (count) or the error
969
+ */
970
+ getCount(callback) {
971
+ const meth = 'adapter-getCount';
972
+ const origin = `${this.id}-${meth}`;
973
+ log.trace(origin);
974
+
975
+ // verify the required fields have been provided
976
+
977
+ try {
978
+ // !! using Generic makes it easier on the Adapter Builder (just need to change the path)
979
+ // !! you can also replace with a specific call if that is easier
980
+ const uriPath = '/call/toget/count';
981
+ return this.genericAdapterRequest(uriPath, 'GET', {}, {}, {}, (result, error) => {
982
+ // if we received an error or their is no response on the results return an error
983
+ if (error) {
984
+ return callback(null, error);
985
+ }
986
+
987
+ // return the result
988
+ return callback({ count: result.response });
989
+ });
990
+ } catch (ex) {
991
+ const errorObj = this.requestHandlerInst.formatErrorObject(this.id, meth, 'Caught Exception', null, null, null, ex);
992
+ log.error(`${origin}: ${errorObj.IAPerror.displayString}`);
993
+ return callback(null, errorObj);
994
+ }
995
+ }
996
+
529
997
  /**
530
998
  * @callback healthCallback
531
999
  * @param {Object} result - the result of the get request (contains an id and a status)
package/adapterBase.js CHANGED
@@ -822,7 +822,7 @@ class AdapterBase extends EventEmitterCl {
822
822
  */
823
823
  async runConnectivity(callback) {
824
824
  try {
825
- const { serviceItem } = await troubleshootingAdapter.getAdapterConfig();
825
+ const { serviceItem } = await tbUtils.getAdapterConfig();
826
826
  const { host } = serviceItem.properties.properties;
827
827
  const result = tbUtils.runConnectivity(host, false);
828
828
  if (result.failCount > 0) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-nokia_altiplano",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "This adapter integrates with system described as: Nokia Altiplano.",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.44.7",
7
- "engineVersion": "1.59.46",
7
+ "engineVersion": "1.59.55",
8
8
  "adapterType": "http",
9
9
  "scripts": {
10
10
  "artifactize": "npm i && node utils/packModificationScript.js",
@@ -54,7 +54,7 @@
54
54
  "author": "Itential",
55
55
  "homepage": "https://gitlab.com/itentialopensource/adapters/controller-orchestrator/adapter-nokia_altiplano#readme",
56
56
  "dependencies": {
57
- "@itentialopensource/adapter-utils": "^4.44.8",
57
+ "@itentialopensource/adapter-utils": "^4.44.11",
58
58
  "ajv": "^6.12.0",
59
59
  "axios": "^0.21.0",
60
60
  "commander": "^2.20.0",