exchanging new version yang models on firmware upgrade
[oam/tr069-adapter.git] / netconf-server / src / main / java / org / commscope / tr069adapter / netconf / server / NetconfServerStarter.java
index 47f8dab..392b693 100644 (file)
@@ -30,7 +30,6 @@ import java.util.Map;
 import java.util.concurrent.TimeUnit;\r
 import java.util.regex.Matcher;\r
 import java.util.regex.Pattern;\r
-import org.apache.commons.io.FileUtils;\r
 import org.commscope.tr069adapter.common.deviceversion.DeviceVersionManager;\r
 import org.commscope.tr069adapter.netconf.config.NetConfServerProperties;\r
 import org.commscope.tr069adapter.netconf.operations.CustomOperationsCreator;\r
@@ -87,18 +86,6 @@ public class NetconfServerStarter {
     OperationsCreator operationsCreator = new CustomOperationsCreator(macID, swVersion, hwVersion);\r
     configuration.setOperationsCreator(operationsCreator);\r
     configuration.setGenerateConfigsTimeout((int) TimeUnit.MINUTES.toMillis(30));\r
-\r
-    String versionPath = versionManager.getNetconfYangSchemaPath(swVersion, hwVersion);\r
-    if (versionPath == null && swVersion != null) {\r
-      LOG.error("Failed to get version path for software version {}, calling base version",\r
-          swVersion);\r
-      versionPath = versionManager.getBaseNetconfYangSchemaPath();\r
-    } else if (swVersion == null) {\r
-      LOG.error("Software version is null {}", swVersion);\r
-      return false;\r
-    }\r
-    String schemaCommonPath = schemaDirPath + "/common";\r
-    String schemaVerPath = schemaDirPath + "/" + versionPath;\r
     if (portStr != null) {\r
       try {\r
         int port = Integer.parseInt(portStr);\r
@@ -110,27 +97,21 @@ public class NetconfServerStarter {
     }\r
     configuration.setDeviceCount(1);\r
     configuration.setSsh(Boolean.TRUE);\r
-    File schemaDir = new File(schemaCommonPath);\r
     configuration.setCapabilities(Configuration.DEFAULT_BASE_CAPABILITIES_EXI);\r
     configuration.setIp("0.0.0.0");\r
 \r
-    File schemaVerDir = new File(schemaVerPath);\r
-    if (!schemaVerDir.isDirectory()) {\r
-      LOG.error("No folder path found for given version path {}", schemaVerDir.getAbsolutePath());\r
+    String versionPath = versionManager.getNetconfYangSchemaPath(swVersion, hwVersion);\r
+    if (versionPath == null && swVersion != null) {\r
+      LOG.error("Failed to get version path for software version {}, calling base version",\r
+          swVersion);\r
+      versionPath = versionManager.getBaseNetconfYangSchemaPath();\r
+    } else if (swVersion == null) {\r
+      LOG.error("Software version is null {}", swVersion);\r
       return false;\r
     }\r
-\r
-    try {\r
-      FileUtils.copyDirectory(schemaDir, schemaVerDir);\r
-    } catch (IOException e) {\r
-      LOG.error("Failed to copy directory " + e.getMessage());\r
-    }\r
+    String schemaVerPath = schemaDirPath + File.separator + versionPath;\r
+    File schemaVerDir = new File(schemaVerPath);\r
     configuration.setSchemasDir(schemaVerDir);\r
-    boolean isSchemaLoaded = loadSchemas(schemaVerDir);\r
-    if (!isSchemaLoaded) {\r
-      LOG.debug("Failed to load schema for netconf server instance {}", macID);\r
-      return false;\r
-    }\r
 \r
     try (final NetconfDevice netconfDevice = new NetconfDevice(configuration)) {\r
       final List<Integer> openDevices = netconfDevice.start();\r
@@ -154,6 +135,7 @@ public class NetconfServerStarter {
       NetconfDevice netconf = serversMap.get(macID);\r
       netconf.setAutoClose(true);\r
       netconf.close();\r
+      serversMap.remove(macID);\r
       LOG.debug("Completed stopping Netconf server for MACID {}", macID);\r
       return true;\r
     } catch (Exception e) {\r
@@ -164,7 +146,7 @@ public class NetconfServerStarter {
     return false;\r
   }\r
 \r
-  private boolean loadSchemas(File schemasDir) {\r
+  protected boolean loadSchemas(File schemasDir) {\r
     if (schemasDir != null) {\r
       if (!schemasDir.exists() || !schemasDir.isDirectory() || !schemasDir.canRead()) {\r
         LOG.error("Failed to load schema. schema location is not valid.");\r
@@ -196,6 +178,14 @@ public class NetconfServerStarter {
     return true;\r
   }\r
 \r
+  public boolean isNetConfServerRunning(String deviceId) {\r
+    NetconfDevice nc = serversMap.get(deviceId);\r
+    if (null != nc)\r
+      return true;\r
+    else\r
+      return false;\r
+  }\r
+\r
   private void loadSchemaPattren(String line, File file, Pattern revisionregex) {\r
     if (line != null) {\r
       final Matcher m = revisionregex.matcher(line);\r