\r
package org.commscope.tr069adapter.netconf.server;\r
\r
-import com.google.common.base.Preconditions;\r
-\r
import java.io.BufferedReader;\r
import java.io.File;\r
import java.io.FileReader;\r
import java.util.concurrent.TimeUnit;\r
import java.util.regex.Matcher;\r
import java.util.regex.Pattern;\r
-\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
import org.opendaylight.netconf.test.tool.NetconfDeviceSimulator;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.context.annotation.Scope;\r
import org.springframework.stereotype.Component;\r
+import com.google.common.base.Preconditions;\r
+\r
\r
@Component\r
@Scope("singleton")\r
@Autowired\r
NetConfServerProperties config;\r
\r
- public boolean startServer(String netConfPort, String macID) {\r
+ @Autowired\r
+ DeviceVersionManager versionManager;\r
+\r
+ public boolean startServer(String netConfPort, String macID, String swVersion, String hwVersion) {\r
\r
if (netConfPort == null) {\r
LOG.error("Invalid NETCONF port for deviceID: {}, port is null.", macID);\r
return false;\r
}\r
\r
- LOG.debug("Starting Netconf server for MACID :{}, on port :{}", macID, netConfPort);\r
- boolean result = startServer(netConfPort, config.getSchemaDirPath(), macID);\r
+ LOG.debug(\r
+ "Starting Netconf server for MACID :{}, on port :{}, softwareVersion {}, hardwareVersion {}",\r
+ macID, netConfPort, swVersion, hwVersion);\r
+ boolean result =\r
+ startServer(netConfPort, config.getSchemaDirPath(), macID, swVersion, hwVersion);\r
LOG.debug("Completed starting Netconf server for MACID :{} , on port :{}, server status={}",\r
macID, netConfPort, result);\r
\r
}\r
\r
@SuppressWarnings({"resource", "deprecation"})\r
- private boolean startServer(String portStr, String schemaDirPath, String macID) {\r
+ private boolean startServer(String portStr, String schemaDirPath, String macID, String swVersion,\r
+ String hwVersion) {\r
\r
// creating configuration for the netconf instance\r
final Configuration configuration = new ConfigurationBuilder().build();\r
- OperationsCreator operationsCreator = new CustomOperationsCreator(macID);\r
+ 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
}\r
configuration.setDeviceCount(1);\r
configuration.setSsh(Boolean.TRUE);\r
- File schemaDir = new File(schemaDirPath);\r
- configuration.setSchemasDir(schemaDir);\r
+ File schemaDir = new File(schemaCommonPath);\r
configuration.setCapabilities(Configuration.DEFAULT_BASE_CAPABILITIES_EXI);\r
configuration.setIp("0.0.0.0");\r
\r
- boolean isSchemaLoaded = loadSchemas(schemaDir);\r
+ File schemaVerDir = new File(schemaVerPath);\r
+ if (!schemaVerDir.isDirectory()) {\r
+ LOG.error("No folder path found for given version path {}", schemaVerDir.getAbsolutePath());\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
+ 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