Device manager selection 96/136296/1
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>
Fri, 20 Oct 2023 09:22:41 +0000 (14:52 +0530)
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>
Fri, 20 Oct 2023 09:22:55 +0000 (14:52 +0530)
Device manager selection

Issue-ID: CCSDK-3950
Change-Id: I6b0f986a8288f914a2ea255a495ea6ff5009473a
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
sdnr/wt/devicemanager-core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/ne/factory/DevicemanagerNature.java [new file with mode: 0644]
sdnr/wt/devicemanager-core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/ne/factory/NetworkElementFactory2.java [new file with mode: 0644]
sdnr/wt/devicemanager-core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerImpl.java
sdnr/wt/devicemanager-core/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/impl/DeviceManagerNetconfConnectHandler.java

diff --git a/sdnr/wt/devicemanager-core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/ne/factory/DevicemanagerNature.java b/sdnr/wt/devicemanager-core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/ne/factory/DevicemanagerNature.java
new file mode 100644 (file)
index 0000000..53c34a7
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : ccsdk features
+ * ================================================================================
+ * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property.
+ * All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ */
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory;
+
+public class DevicemanagerNature implements Comparable<DevicemanagerNature> {
+
+    /** Specific devicemanager */
+    public static final DevicemanagerNature SPECIFIC = new DevicemanagerNature(10);
+    /** Priority of mid specfic types */
+    public static final DevicemanagerNature NORMAL = new DevicemanagerNature(100);
+    /** Common devicemanager with basic functionality for standard */
+    public static final DevicemanagerNature COMMON = new DevicemanagerNature(250);
+    /** Priority of "NetworkElementFactory" types */
+    public static final DevicemanagerNature NETWORKELEMENT_FACTORY_DEFAULT = new DevicemanagerNature(Integer.MAX_VALUE);
+
+    //Low numbers have the highest priority for devicemanager selection
+    private final int nature;
+
+    private DevicemanagerNature(int nature) {
+        super();
+        this.nature = nature;
+    }
+
+    @Override
+    public int compareTo(DevicemanagerNature o) {
+        return Integer.compare(nature, o.nature);
+    }
+
+    public static DevicemanagerNature getDefaultDevicemanagerNature(NetworkElementFactory a) {
+        return (a instanceof NetworkElementFactory2) ? ((NetworkElementFactory2) a).getDevicemanagerNature()
+                : NETWORKELEMENT_FACTORY_DEFAULT;
+    }
+
+    public static int compareTo(NetworkElementFactory a, NetworkElementFactory b) {
+        return getDefaultDevicemanagerNature(a).compareTo(getDefaultDevicemanagerNature(b));
+    }
+
+}
diff --git a/sdnr/wt/devicemanager-core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/ne/factory/NetworkElementFactory2.java b/sdnr/wt/devicemanager-core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/ne/factory/NetworkElementFactory2.java
new file mode 100644 (file)
index 0000000..c0ca8c8
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : ccsdk feature sdnr wt
+ * =================================================================================================
+ * Copyright (C) 2023 highstreet technologies GmbH Intellectual Property. All rights reserved.
+ * =================================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ * ============LICENSE_END==========================================================================
+ */
+
+package org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory;
+
+public interface NetworkElementFactory2 extends NetworkElementFactory {
+
+    /**
+     * Provide the nature of the devicemanager for list ordering
+     * @return nature definition of devicemanager
+     */
+    DevicemanagerNature getDevicemanagerNature();
+
+}
index 881f6b4..4c8003b 100644 (file)
@@ -38,6 +38,7 @@
  */
 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl;
 
+import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 import org.eclipse.jdt.annotation.NonNull;
@@ -60,8 +61,10 @@ import org.onap.ccsdk.features.sdnr.wt.devicemanager.housekeeping.ResyncNetworkE
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientImpl;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.WebSocketServiceClientInternal;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceServiceImpl;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.DevicemanagerNature;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.FactoryRegistration;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory;
+import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.factory.NetworkElementFactory2;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.PerformanceManagerImpl;
 import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.AaiService;
@@ -274,11 +277,12 @@ public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceMa
     }
 
     @Override
-    public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerBindingNetworkElementFactory(
+    synchronized public @NonNull <L extends NetworkElementFactory> FactoryRegistration<L> registerBindingNetworkElementFactory(
             @NonNull final L factory) {
         LOG.debug("Factory registration {}", factory.getClass().getName());
 
         factoryList.add(factory);
+        Collections.sort(factoryList, (a,b) -> DevicemanagerNature.compareTo(a, b) );
         factory.init(getServiceProvider());
         return new FactoryRegistration<L>() {
 
@@ -295,7 +299,11 @@ public class DeviceManagerImpl implements NetconfNetworkElementService, DeviceMa
         };
     }
 
-    @SuppressWarnings("null")
+    private DevicemanagerNature getNature(NetworkElementFactory a) {
+        return (a instanceof NetworkElementFactory2) ? ((NetworkElementFactory2)a).getDevicemanagerNature()
+                : DevicemanagerNature.NETWORKELEMENT_FACTORY_DEFAULT;
+    }
+
     @Override
     public @NonNull DataProvider getDataProvider() {
         return this.dataProvider;
index 5d9a7db..e9c5f7a 100644 (file)
@@ -89,14 +89,11 @@ public class DeviceManagerNetconfConnectHandler extends DeviceManagerNetconfNotC
         // update db with connect status
         NetconfNode netconfNode = acessor.getNetconfNode();
         sendUpdateNotification(acessor.getNodeId(), netconfNode.getConnectionStatus(), netconfNode);
-
-        for (NetworkElementFactory f : getFactoryList()) {
-            Optional<NetworkElement> optionalNe = f.create(acessor, getServiceProvider());
-            if (optionalNe.isPresent()) {
-                // sendUpdateNotification(mountPointNodeName, nNode.getConnectionStatus(), nNode);
-                handleNeStartup(acessor.getNodeId(), optionalNe.get());
-                break; // Use the first provided
-            }
+        // Start devicemanager if possible
+        Optional<NetworkElement> optionalNe = createNetworkElement(acessor);
+        // Startup device
+        if (optionalNe.isPresent()) {
+            handleNeStartup(acessor.getNodeId(), optionalNe.get());
         }
     }
 
@@ -135,6 +132,23 @@ public class DeviceManagerNetconfConnectHandler extends DeviceManagerNetconfNotC
      * Private functions
      */
 
+    /**
+     * Get the NetworkElement from list
+     *
+     * @param accessor
+     * @return Optional<NetowrkElement>
+     */
+    private Optional<NetworkElement> createNetworkElement(NetconfAccessor accessor) {
+        Optional<NetworkElement> optionalNe = Optional.empty();
+        for (NetworkElementFactory f : getFactoryList()) {
+            optionalNe = f.create(accessor, getServiceProvider());
+            if (optionalNe.isPresent()) {
+                return optionalNe; // Use the first provided
+            }
+        }
+        return Optional.empty();
+    }
+
     /**
      * Do all tasks necessary to move from mountpoint state connected -> connecting
      *