}\r
}\r
} catch (Exception e) {\r
- LOG.error("Load schemas failed in netconf server {}", e.getMessage());\r
+ LOG.error("Load schema's failed in netconf server {}", e.getMessage());\r
return false;\r
}\r
LOG.debug("Loading yang schema completed");\r
try {\r
restartServersHandler.restart(entity);\r
} catch (RetryFailedException e) {\r
- e.printStackTrace();\r
+ LOG.error("submit task for restarting is failed {}", e.toString());\r
}\r
}\r
}\r
return null;\r
}\r
\r
- if (null != entity) {\r
+ if (null != entity && ncServerStarter.isNetConfServerRunning(deviceId)) {\r
+ if (isVersionChanged(entity, swVersion, hwVersion)) {\r
+ return restartOnVersionChange(deviceId, enodeBName, swVersion, hwVersion);\r
+ }\r
+\r
// found the entity. server is already running. double check and run\r
// if\r
// required. else return the details.\r
\r
// update the ENB Name if Changed\r
entity.setEnodeBName(enodeBName);\r
- entity.setSwVersion(swVersion);\r
- entity.setHwVersion(hwVersion);\r
netconfDAO.save(entity);\r
result = getNetConfServerDetails(deviceId, entity);\r
return result;\r
return result;\r
}\r
\r
- public NetConfServerDetails restartServer(String deviceId, String enodeBName, String swVersion,\r
- String hwVersion) {\r
+ public NetConfServerDetails restartOnVersionChange(String deviceId, String enodeBName,\r
+ String swVersion, String hwVersion) {\r
\r
NetConfServerDetailsEntity entity = null;\r
if (deviceId != null) {\r
entity = netconfDAO.findByDeviceId(deviceId);\r
}\r
- if (entity != null) {\r
- boolean result = this.ncServerStarter.stopServer(deviceId);\r
- restartServersOnStartup(entity);\r
+ if (entity == null) {\r
+ return null;\r
}\r
\r
- return null;\r
+ boolean isVersionChanged = isVersionChanged(entity, swVersion, hwVersion);\r
+ if (isVersionChanged) {\r
+ LOG.debug("software version changed, stopping the the existing netconf instance");\r
+ boolean result = this.ncServerStarter.stopServer(deviceId);\r
+ if (result) {\r
+ LOG.debug(\r
+ "successfully stopped the netconf instance; trying to start with new version yang models");\r
+ entity.setSwVersion(swVersion);\r
+ entity.setHwVersion(hwVersion);\r
+ netconfDAO.save(entity);\r
+\r
+ boolean isSuccess = startNetConfServerInstance(entity);\r
+\r
+ if (!isSuccess) {\r
+ try {\r
+ restartServersHandler.restart(entity);\r
+ } catch (RetryFailedException e) {\r
+ LOG.debug("");\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return getNetConfServerDetails(deviceId, entity);\r
}\r
\r
\r
- public boolean restartServersOnStartup(NetConfServerDetailsEntity entity) {\r
+ public boolean startNetConfServerInstance(NetConfServerDetailsEntity entity) {\r
boolean isSuccess = false;\r
\r
boolean isServerStarted = ncServerStarter.startServer(entity.getListenPort(),\r
entity.getDeviceId(), entity.getSwVersion(), entity.getHwVersion());\r
if (isServerStarted) {\r
- LOG.info("Successfully restarted NETCONF server {} on port {} upon application startup.",\r
+ LOG.info("Successfully restarted NETCONF server {} on port {} .",\r
entity.getDeviceId(), entity.getListenPort());\r
// we need to push the pnfEntry for IP updated\r
NetConfServerDetails details = getNetConfServerDetails(entity.getDeviceId(), entity);\r
resultMsg = "Failed to unregister the device " + deviceId + ", enodeBName=" + enodeBName\r
+ ". Invalid deviceId/enodeBName specified.";\r
LOG.info(resultMsg);\r
+ return resultMsg;\r
}\r
boolean result = this.ncServerStarter.stopServer(deviceId);\r
if (result) {\r
return null;\r
}\r
\r
+ private boolean isVersionChanged(NetConfServerDetailsEntity entity, String swVersion,\r
+ String hwVersion) {\r
+ String existingProfileId =\r
+ versionManager.getAssociatedProfileId(entity.getSwVersion(), entity.getHwVersion());\r
+ String newProfiled = versionManager.getAssociatedProfileId(swVersion, hwVersion);\r
+ return !existingProfileId.equalsIgnoreCase(newProfiled) ? true : false;\r
+ }\r
+\r
class ServerStartTask implements Runnable {\r
\r
NetConfServerDetailsEntity entity;\r
\r
@Override\r
public void run() {\r
- boolean isSuccess = netconfServerManager.restartServersOnStartup(entity);\r
+ boolean isSuccess = netconfServerManager.startNetConfServerInstance(entity);\r
if (!isSuccess) {\r
try {\r
netconfServerManager.restartServersHandler.restart(entity);\r