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;fp=opendaylight%2Fnetconf%2Fconfig-persister-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fpersist%2Fimpl%2FConfigPusher.java;h=99d122c3c4aaf23dffa71d88a253179686fa99dc;hb=7d9b07a6cf8171e97eb5ce6ed4ccdcfadff8e741;hp=460aec6ac6fa94b4977c433ba3f6e76805bc8e8e;hpb=2e92a15f60261432cde594d86f033802f7410e17;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 460aec6ac6..99d122c3c4 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 @@ -8,20 +8,8 @@ package org.opendaylight.controller.netconf.persist.impl; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetSocketAddress; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import javax.annotation.concurrent.Immutable; - +import com.google.common.base.Preconditions; +import io.netty.channel.EventLoopGroup; import org.opendaylight.controller.config.api.ConflictingVersionException; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; import org.opendaylight.controller.netconf.api.NetconfMessage; @@ -38,12 +26,22 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; -import com.google.common.base.Preconditions; -import io.netty.channel.EventLoopGroup; +import javax.annotation.concurrent.Immutable; +import java.io.IOException; +import java.io.InputStream; +import java.net.InetSocketAddress; +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; @Immutable public class ConfigPusher { - private static final Logger logger = LoggerFactory.getLogger(ConfigPusher.class); + private static final Logger logger = LoggerFactory.getLogger(ConfigPersisterNotificationHandler.class); private static final int NETCONF_SEND_ATTEMPT_MS_DELAY = 1000; private static final int NETCONF_SEND_ATTEMPTS = 20; @@ -62,7 +60,7 @@ public class ConfigPusher { } public ConfigPusher(InetSocketAddress address, EventLoopGroup nettyThreadGroup, - long maxWaitForCapabilitiesMillis, long connectionTimeoutMillis) { + long maxWaitForCapabilitiesMillis, long connectionTimeoutMillis) { this.address = address; this.nettyThreadGroup = nettyThreadGroup; this.maxWaitForCapabilitiesMillis = maxWaitForCapabilitiesMillis; @@ -106,6 +104,7 @@ public class ConfigPusher { EditAndCommitResponse editAndCommitResponse = pushLastConfig(configSnapshotHolder, netconfClient); return new EditAndCommitResponseWithRetries(editAndCommitResponse, retryAttempt); } catch (ConflictingVersionException e) { + logger.debug("Conflicting version detected, will retry after timeout"); lastException = e; Thread.sleep(1000); } catch (RuntimeException e) { @@ -155,7 +154,10 @@ public class ConfigPusher { logger.trace("Session id received from netconf server: {}", netconfClient.getClientSession()); return netconfClient; } - logger.debug("Polling hello from netconf, attempt {}, capabilities {}", attempt, latestCapabilities); + Set allNotFound = computeNotFoundCapabilities(expectedCaps, latestCapabilities); + logger.debug("Netconf server did not provide required capabilities. Attempt {}. " + + "Expected but not found: {}, all expected {}, current {}", + attempt, allNotFound, expectedCaps, latestCapabilities); Util.closeClientAndDispatcher(netconfClient); Thread.sleep(delayMillis); } @@ -163,13 +165,18 @@ public class ConfigPusher { logger.error("Could not connect to the server in {} ms", maxWaitForCapabilitiesMillis); throw new RuntimeException("Could not connect to netconf server"); } - Set allNotFound = new HashSet<>(expectedCaps); - allNotFound.removeAll(latestCapabilities); + Set allNotFound = computeNotFoundCapabilities(expectedCaps, latestCapabilities); logger.error("Netconf server did not provide required capabilities. Expected but not found: {}, all expected {}, current {}", allNotFound, expectedCaps, latestCapabilities); throw new RuntimeException("Netconf server did not provide required capabilities. Expected but not found:" + allNotFound); } + private static Set computeNotFoundCapabilities(Set expectedCaps, Set latestCapabilities) { + Set allNotFound = new HashSet<>(expectedCaps); + allNotFound.removeAll(latestCapabilities); + return allNotFound; + } + /** * Sends two RPCs to the netconf server: edit-config and commit. @@ -222,17 +229,22 @@ public class ConfigPusher { } - private static NetconfMessage sendRequestGetResponseCheckIsOK(NetconfMessage request, NetconfClient netconfClient) throws IOException { + private static NetconfMessage sendRequestGetResponseCheckIsOK(NetconfMessage request, NetconfClient netconfClient) + throws ConflictingVersionException, IOException { try { NetconfMessage netconfMessage = netconfClient.sendMessage(request, NETCONF_SEND_ATTEMPTS, NETCONF_SEND_ATTEMPT_MS_DELAY); NetconfUtil.checkIsMessageOk(netconfMessage); return netconfMessage; - } catch (RuntimeException | ExecutionException | InterruptedException | TimeoutException e) { + }catch(ConflictingVersionException e) { + logger.trace("conflicting version detected: {}", e.toString()); + throw e; + } catch (RuntimeException | ExecutionException | InterruptedException | TimeoutException e) { // TODO: change NetconfClient#sendMessage to throw checked exceptions logger.debug("Error while executing netconf transaction {} to {}", request, netconfClient, e); throw new IOException("Failed to execute netconf transaction", e); } } + // load editConfig.xml template, populate /rpc/edit-config/config with parameter private static NetconfMessage createEditConfigMessage(Element dataElement) { String editConfigResourcePath = "/netconfOp/editConfig.xml";