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
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(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
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
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
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