X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-persister-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fpersist%2Fimpl%2FConfigPusher.java;h=44e90270e7e31e5d691756ef421122d4418f0287;hb=f3714846c0eedf09fe83844c0dc30889f790fbc2;hp=6dba9ac64e22e1e5d5f528aa6b8c830aa78d9f17;hpb=d5759c52d69ba8725d9bbdc18e81848f319861d1;p=controller.git diff --git a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusher.java b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusher.java index 6dba9ac64e..44e90270e7 100644 --- a/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusher.java +++ b/opendaylight/netconf/config-persister-impl/src/main/java/org/opendaylight/controller/netconf/persist/impl/ConfigPusher.java @@ -59,7 +59,7 @@ public class ConfigPusher { this.conflictingVersionTimeoutMillis = conflictingVersionTimeoutMillis; } - public synchronized LinkedHashMap pushConfigs(List configs) { + public synchronized LinkedHashMap pushConfigs(List configs) throws NetconfDocumentedException { logger.debug("Last config snapshots to be pushed to netconf: {}", configs); LinkedHashMap result = new LinkedHashMap<>(); // start pushing snapshots: @@ -78,7 +78,7 @@ public class ConfigPusher { * is caught, whole process is retried - new service instance need to be obtained from the factory. Closes * {@link NetconfOperationService} after each use. */ - private synchronized EditAndCommitResponse pushConfigWithConflictingVersionRetries(ConfigSnapshotHolder configSnapshotHolder) { + private synchronized EditAndCommitResponse pushConfigWithConflictingVersionRetries(ConfigSnapshotHolder configSnapshotHolder) throws NetconfDocumentedException { ConflictingVersionException lastException; Stopwatch stopwatch = new Stopwatch().start(); do { @@ -110,6 +110,10 @@ public class ConfigPusher { } private static class NotEnoughCapabilitiesException extends Exception { + private NotEnoughCapabilitiesException(String message, Throwable cause) { + super(message, cause); + } + private NotEnoughCapabilitiesException(String message) { super(message); } @@ -123,14 +127,19 @@ public class ConfigPusher { * @return service if capabilities are present, otherwise absent value */ private NetconfOperationService getOperationService(Set expectedCapabilities, String idForReporting) throws NotEnoughCapabilitiesException { - NetconfOperationService serviceCandidate = configNetconfConnector.createService(idForReporting); + NetconfOperationService serviceCandidate; + try { + serviceCandidate = configNetconfConnector.createService(idForReporting); + } catch(RuntimeException e) { + throw new NotEnoughCapabilitiesException("Netconf service not stable for " + idForReporting, e); + } Set notFoundDiff = computeNotFoundCapabilities(expectedCapabilities, serviceCandidate); if (notFoundDiff.isEmpty()) { return serviceCandidate; } else { serviceCandidate.close(); - logger.debug("Netconf server did not provide required capabilities for {} " + - "Expected but not found: {}, all expected {}, current {}", + logger.trace("Netconf server did not provide required capabilities for {} " + + "Expected but not found: {}, all expected {}, current {}", idForReporting, notFoundDiff, expectedCapabilities, serviceCandidate.getCapabilities() ); throw new NotEnoughCapabilitiesException("Not enough capabilities for " + idForReporting + ". Expected but not found: " + notFoundDiff); @@ -168,7 +177,7 @@ public class ConfigPusher { * @throws java.lang.RuntimeException if edit-config or commit fails otherwise */ private synchronized EditAndCommitResponse pushConfig(ConfigSnapshotHolder configSnapshotHolder, NetconfOperationService operationService) - throws ConflictingVersionException { + throws ConflictingVersionException, NetconfDocumentedException { Element xmlToBePersisted; try { @@ -200,7 +209,7 @@ public class ConfigPusher { return new EditAndCommitResponse(editResponseMessage, commitResponseMessage); } - private NetconfOperation findOperation(NetconfMessage request, NetconfOperationService operationService) { + private NetconfOperation findOperation(NetconfMessage request, NetconfOperationService operationService) throws NetconfDocumentedException { TreeMap allOperations = new TreeMap<>(); Set netconfOperations = operationService.getNetconfOperations(); if (netconfOperations.isEmpty()) { @@ -219,26 +228,24 @@ public class ConfigPusher { private Document sendRequestGetResponseCheckIsOK(NetconfMessage request, NetconfOperationService operationService, String operationNameForReporting, String configIdForReporting) - throws ConflictingVersionException { + throws ConflictingVersionException, NetconfDocumentedException { NetconfOperation operation = findOperation(request, operationService); Document response; try { response = operation.handle(request.getDocument(), NetconfOperationChainedExecution.EXECUTION_TERMINATION_POINT); } catch (NetconfDocumentedException | RuntimeException e) { + if (e instanceof NetconfDocumentedException && e.getCause() instanceof ConflictingVersionException) { + throw (ConflictingVersionException) e.getCause(); + } throw new IllegalStateException("Failed to send " + operationNameForReporting + " for configuration " + configIdForReporting, e); } - try { - return NetconfUtil.checkIsMessageOk(response); - } catch (ConflictingVersionException e) { - logger.trace("conflicting version detected: {} while committing {}", e.toString(), configIdForReporting); - throw e; - } + return NetconfUtil.checkIsMessageOk(response); } // load editConfig.xml template, populate /rpc/edit-config/config with parameter - private static NetconfMessage createEditConfigMessage(Element dataElement) { + private static NetconfMessage createEditConfigMessage(Element dataElement) throws NetconfDocumentedException { String editConfigResourcePath = "/netconfOp/editConfig.xml"; try (InputStream stream = ConfigPersisterNotificationHandler.class.getResourceAsStream(editConfigResourcePath)) { Preconditions.checkNotNull(stream, "Unable to load resource " + editConfigResourcePath);