Merge "RPC input is wrapped into RPC name element"
[controller.git] / opendaylight / netconf / config-persister-impl / src / main / java / org / opendaylight / controller / netconf / persist / impl / ConfigPersisterNotificationHandler.java
index a777ea4099e5bf2595f57b512618551c4c4d2d68..b20577afd23fcdde6bb8f3ab50b3f7f73c0c0a6f 100644 (file)
@@ -101,24 +101,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         if (maybeConfig.isPresent()) {
             logger.debug("Last config found {}", persister);
             ConflictingVersionException lastException = null;
-            int maxAttempts = 30;
-            for(int i = 0 ; i < maxAttempts; i++) {
-                registerToNetconf(maybeConfig.get().getCapabilities());
-
-                final String configSnapshot = maybeConfig.get().getConfigSnapshot();
-                logger.trace("Pushing following xml to netconf {}", configSnapshot);
-                try {
-                    pushLastConfig(XmlUtil.readXmlToElement(configSnapshot));
-                } catch(ConflictingVersionException e) {
-                    closeClientAndDispatcher(netconfClient, netconfClientDispatcher);
-                    lastException = e;
-                    Thread.sleep(1000);
-                } catch (SAXException | IOException e) {
-                    throw new IllegalStateException("Unable to load last config", e);
-                }
-            }
-            throw new IllegalStateException("Failed to push configuration, maximum attempt count has been reached: "
-                    + maxAttempts, lastException);
+            pushLastConfigWithRetries(maybeConfig, lastException);
 
         } else {
             // this ensures that netconf is initialized, this is first
@@ -131,6 +114,28 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         registerAsJMXListener();
     }
 
+    private void pushLastConfigWithRetries(Optional<ConfigSnapshotHolder> maybeConfig, ConflictingVersionException lastException) throws InterruptedException {
+        int maxAttempts = 30;
+        for(int i = 0 ; i < maxAttempts; i++) {
+            registerToNetconf(maybeConfig.get().getCapabilities());
+
+            final String configSnapshot = maybeConfig.get().getConfigSnapshot();
+            logger.trace("Pushing following xml to netconf {}", configSnapshot);
+            try {
+                pushLastConfig(XmlUtil.readXmlToElement(configSnapshot));
+                return;
+            } catch(ConflictingVersionException e) {
+                closeClientAndDispatcher(netconfClient, netconfClientDispatcher);
+                lastException = e;
+                Thread.sleep(1000);
+            } catch (SAXException | IOException e) {
+                throw new IllegalStateException("Unable to load last config", e);
+            }
+        }
+        throw new IllegalStateException("Failed to push configuration, maximum attempt count has been reached: "
+                + maxAttempts, lastException);
+    }
+
     private synchronized long registerToNetconf(Set<String> expectedCaps) throws InterruptedException {
 
         Set<String> currentCapabilities = Sets.newHashSet();
@@ -208,6 +213,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
     }
 
     private void registerAsJMXListener() {
+        logger.trace("Called registerAsJMXListener");
         try {
             mbeanServer.addNotificationListener(on, this, null, null);
         } catch (InstanceNotFoundException | IOException e) {
@@ -223,7 +229,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         // Socket should not be closed at this point
         // Activator unregisters this as JMX listener before close is called
 
-        logger.debug("Received notification {}", notification);
+        logger.info("Received notification {}", notification);
         if (notification instanceof CommitJMXNotification) {
             try {
                 handleAfterCommitNotification((CommitJMXNotification) notification);
@@ -240,7 +246,7 @@ public class ConfigPersisterNotificationHandler implements NotificationListener,
         try {
             persister.persistConfig(new CapabilityStrippingConfigSnapshotHolder(notification.getConfigSnapshot(),
                     notification.getCapabilities(), ignoredMissingCapabilityRegex));
-            logger.debug("Configuration persisted successfully");
+            logger.info("Configuration persisted successfully");
         } catch (IOException e) {
             throw new RuntimeException("Unable to persist configuration snapshot", e);
         }