BUG-1135 Improve error reporting in config pusher 81/20781/5
authorMaros Marsalek <mmarsale@cisco.com>
Wed, 20 May 2015 09:05:56 +0000 (11:05 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 28 May 2015 15:53:44 +0000 (15:53 +0000)
Change-Id: I78e9550bf78cf5c5b3d929827f379e9009a4468f
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusherImpl.java
opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java

index 22b061a1285c88d0ea372a5c104a2baf69fcb58c..0e179ad7d58c92e019c9a8c98c6d1bd8d8563d78 100644 (file)
@@ -138,28 +138,65 @@ public class ConfigPusherImpl implements ConfigPusher {
 
     private NetconfOperationService getOperationServiceWithRetries(Set<String> expectedCapabilities, String idForReporting) {
         Stopwatch stopwatch = Stopwatch.createStarted();
-        NotEnoughCapabilitiesException lastException;
+        ConfigPusherException lastException;
         do {
             try {
                 return getOperationService(expectedCapabilities, idForReporting);
-            } catch (NotEnoughCapabilitiesException e) {
+            } catch (ConfigPusherException e) {
                 LOG.debug("Not enough capabilities: {}", e.toString());
                 lastException = e;
                 sleep();
             }
         } while (stopwatch.elapsed(TimeUnit.MILLISECONDS) < maxWaitForCapabilitiesMillis);
-        throw new IllegalStateException("Max wait for capabilities reached." + lastException.getMessage(), lastException);
+
+        if(lastException instanceof NotEnoughCapabilitiesException) {
+            LOG.error("Unable to push configuration due to missing yang models." +
+                            " Yang models that are missing, but required by the configuration: {}." +
+                            " For each mentioned model check: " +
+                            " 1. that the mentioned yang model namespace/name/revision is identical to those in the yang model itself" +
+                            " 2. the yang file is present in the system" +
+                            " 3. the bundle with that yang file is present in the system and active" +
+                            " 4. the yang parser did not fail while attempting to parse that model",
+                    ((NotEnoughCapabilitiesException) lastException).getMissingCaps());
+            throw new IllegalStateException("Unable to push configuration due to missing yang models." +
+                    " Required yang models that are missing: "
+                    + ((NotEnoughCapabilitiesException) lastException).getMissingCaps(), lastException);
+        } else {
+            final String msg = "Unable to push configuration due to missing netconf service";
+            LOG.error(msg, lastException);
+            throw new IllegalStateException(msg, lastException);
+        }
     }
 
-    private static class NotEnoughCapabilitiesException extends Exception {
-        private static final long serialVersionUID = 1L;
+    private static class ConfigPusherException extends Exception {
 
-        private NotEnoughCapabilitiesException(String message, Throwable cause) {
+        public ConfigPusherException(final String message) {
+            super(message);
+        }
+
+        public ConfigPusherException(final String message, final Throwable cause) {
             super(message, cause);
         }
+    }
+
+    private static class NotEnoughCapabilitiesException extends ConfigPusherException {
+        private static final long serialVersionUID = 1L;
+        private Set<String> missingCaps;
 
-        private NotEnoughCapabilitiesException(String message) {
+        private NotEnoughCapabilitiesException(String message, Set<String> missingCaps) {
             super(message);
+            this.missingCaps = missingCaps;
+        }
+
+        public Set<String> getMissingCaps() {
+            return missingCaps;
+        }
+    }
+
+    private static final class NetconfServiceNotAvailableException extends ConfigPusherException {
+
+        public NetconfServiceNotAvailableException(final String s, final RuntimeException e) {
+            super(s, e);
         }
     }
 
@@ -170,23 +207,24 @@ public class ConfigPusherImpl implements ConfigPusher {
      * @param idForReporting
      * @return service if capabilities are present, otherwise absent value
      */
-    private NetconfOperationService getOperationService(Set<String> expectedCapabilities, String idForReporting) throws NotEnoughCapabilitiesException {
+    private NetconfOperationService getOperationService(Set<String> expectedCapabilities, String idForReporting) throws ConfigPusherException {
         NetconfOperationService serviceCandidate;
         try {
             serviceCandidate = configNetconfConnector.createService(idForReporting);
         } catch(RuntimeException e) {
-            throw new NotEnoughCapabilitiesException("Netconf service not stable for " + idForReporting, e);
+            throw new NetconfServiceNotAvailableException("Netconf service not stable for config pusher." +
+                    " Cannot push any configuration", e);
         }
         Set<String> notFoundDiff = computeNotFoundCapabilities(expectedCapabilities, configNetconfConnector);
         if (notFoundDiff.isEmpty()) {
             return serviceCandidate;
         } else {
             serviceCandidate.close();
-            LOG.trace("Netconf server did not provide required capabilities for {} ", idForReporting,
+            LOG.debug("Netconf server did not provide required capabilities for {} ", idForReporting,
                     "Expected but not found: {}, all expected {}, current {}",
                      notFoundDiff, expectedCapabilities, configNetconfConnector.getCapabilities()
             );
-            throw new NotEnoughCapabilitiesException("Not enough capabilities for " + idForReporting + ". Expected but not found: " + notFoundDiff);
+            throw new NotEnoughCapabilitiesException("Not enough capabilities for " + idForReporting + ". Expected but not found: " + notFoundDiff, notFoundDiff);
         }
     }
 
@@ -202,8 +240,6 @@ public class ConfigPusherImpl implements ConfigPusher {
         return allNotFound;
     }
 
-
-
     private void sleep() {
         try {
             Thread.sleep(100);
index 1f5d2c1d0f34dec1ada1bb45ab7fbbfb17954880..b998b9eff0bee8d9e2224104a9bd0f09491f3701 100644 (file)
@@ -67,8 +67,7 @@ public class ConfigPersisterTest {
     public void testPersisterNotAllCapabilitiesProvided() throws Exception {
         setUpContextAndStartPersister("required-cap", getConflictingService());
         Thread.sleep(2000);
-        handler.assertException(IllegalStateException.class, "Max wait for capabilities reached.Not enough capabilities " +
-                "for <data><config-snapshot/></data>. Expected but not found: [required-cap]");
+        handler.assertException(IllegalStateException.class, "Required yang models that are missing: [required-cap]");
 
     }