X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-persister-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fpersist%2Fimpl%2FConfigPusherImpl.java;h=08c3330a2731a3d0cb2d9ffd1abdf001359aed71;hp=6fcc7dcd4d14b9d04bbad384f9ac38214e6da911;hb=2643c6b23a41336f28e6c912c31786a649b1a261;hpb=e87519797a3b0d6e250a89c65219610d88fccb92 diff --git a/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java b/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java index 6fcc7dcd4d..08c3330a27 100644 --- a/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java +++ b/opendaylight/config/config-persister-impl/src/main/java/org/opendaylight/controller/config/persist/impl/ConfigPusherImpl.java @@ -9,7 +9,6 @@ package org.opendaylight.controller.config.persist.impl; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Function; import com.google.common.base.Stopwatch; import com.google.common.collect.Collections2; import java.io.IOException; @@ -23,7 +22,6 @@ import java.util.SortedSet; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import javax.annotation.Nonnull; import javax.annotation.concurrent.Immutable; import javax.management.MBeanServerConnection; import org.opendaylight.controller.config.api.ConflictingVersionException; @@ -58,21 +56,21 @@ public class ConfigPusherImpl implements ConfigPusher { private final ConfigSubsystemFacadeFactory facade; private ConfigPersisterNotificationHandler jmxNotificationHandler; - public ConfigPusherImpl(ConfigSubsystemFacadeFactory facade, long maxWaitForCapabilitiesMillis, - long conflictingVersionTimeoutMillis) { + public ConfigPusherImpl(final ConfigSubsystemFacadeFactory facade, final long maxWaitForCapabilitiesMillis, + final long conflictingVersionTimeoutMillis) { this.maxWaitForCapabilitiesMillis = maxWaitForCapabilitiesMillis; this.conflictingVersionTimeoutMillis = conflictingVersionTimeoutMillis; this.facade = facade; } - public void process(List autoCloseables, MBeanServerConnection platformMBeanServer, - Persister persisterAggregator, boolean propagateExceptions) throws InterruptedException { + public void process(final List autoCloseables, final MBeanServerConnection platformMBeanServer, + final Persister persisterAggregator, final boolean propagateExceptions) throws InterruptedException { while(processSingle(autoCloseables, platformMBeanServer, persisterAggregator, propagateExceptions)) { } } boolean processSingle(final List autoCloseables, final MBeanServerConnection platformMBeanServer, - final Persister persisterAggregator, boolean propagateExceptions) throws InterruptedException { + final Persister persisterAggregator, final boolean propagateExceptions) throws InterruptedException { final List configs = queue.take(); try { internalPushConfigs(configs); @@ -87,7 +85,7 @@ public class ConfigPusherImpl implements ConfigPusher { } LOG.debug("ConfigPusher has pushed configs {}", configs); - } catch (Exception e) { + } catch (final Exception e) { // Exceptions are logged to error downstream LOG.debug("Failed to push some of configs: {}", configs, e); @@ -106,12 +104,12 @@ public class ConfigPusherImpl implements ConfigPusher { } @Override - public void pushConfigs(List configs) throws InterruptedException { + public void pushConfigs(final List configs) throws InterruptedException { LOG.debug("Requested to push configs {}", configs); this.queue.put(configs); } - private LinkedHashMap internalPushConfigs(List configs) + private LinkedHashMap internalPushConfigs(final List configs) throws DocumentedException { LOG.debug("Last config snapshots to be pushed to netconf: {}", configs); LinkedHashMap result = new LinkedHashMap<>(); @@ -122,11 +120,11 @@ public class ConfigPusherImpl implements ConfigPusher { boolean pushResult = false; try { pushResult = pushConfigWithConflictingVersionRetries(configSnapshotHolder); - } catch (ConfigSnapshotFailureException e) { + } catch (final ConfigSnapshotFailureException e) { LOG.error("Failed to apply configuration snapshot: {}. Config snapshot is not semantically correct and will be IGNORED. " + "for detailed information see enclosed exception.", e.getConfigIdForReporting(), e); throw new IllegalStateException("Failed to apply configuration snapshot " + e.getConfigIdForReporting(), e); - } catch (Exception e) { + } catch (final Exception e) { String msg = String.format("Failed to apply configuration snapshot: %s", configSnapshotHolder); LOG.error(msg, e); throw new IllegalStateException(msg, e); @@ -136,11 +134,11 @@ public class ConfigPusherImpl implements ConfigPusher { result.put(configSnapshotHolder, pushResult); } } - LOG.debug("All configuration snapshots have been pushed successfully."); + LOG.info("All configuration snapshots have been pushed successfully."); return result; } - private synchronized boolean pushConfigWithConflictingVersionRetries(ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException { + private synchronized boolean pushConfigWithConflictingVersionRetries(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException { ConflictingVersionException lastException; Stopwatch stopwatch = Stopwatch.createUnstarted(); do { @@ -157,7 +155,7 @@ public class ConfigPusherImpl implements ConfigPusher { stopwatch.start(); } return pushConfig(configSnapshotHolder); - } catch (ConflictingVersionException e) { + } catch (final ConflictingVersionException e) { lastException = e; LOG.info("Conflicting version detected, will retry after timeout"); sleep(); @@ -167,7 +165,7 @@ public class ConfigPusherImpl implements ConfigPusher { lastException); } - private void waitForCapabilities(Set expectedCapabilities, String idForReporting) { + private void waitForCapabilities(final Set expectedCapabilities, final String idForReporting) { Stopwatch stopwatch = Stopwatch.createStarted(); ConfigPusherException lastException; do { @@ -184,7 +182,7 @@ public class ConfigPusherImpl implements ConfigPusher { throw new NotEnoughCapabilitiesException( "Not enough capabilities for " + idForReporting + ". Expected but not found: " + notFoundCapabilities, notFoundCapabilities); } - } catch (ConfigPusherException e) { + } catch (final ConfigPusherException e) { LOG.debug("Not enough capabilities: {}", e.toString()); lastException = e; sleep(); @@ -204,7 +202,7 @@ public class ConfigPusherImpl implements ConfigPusher { + ((NotEnoughCapabilitiesException) lastException).getMissingCaps(), lastException); } - private static Set computeNotFoundCapabilities(Set expectedCapabilities, Set currentCapabilities) { + private static Set computeNotFoundCapabilities(final Set expectedCapabilities, final Set currentCapabilities) { Collection actual = transformCapabilities(currentCapabilities); Set allNotFound = new HashSet<>(expectedCapabilities); allNotFound.removeAll(actual); @@ -212,12 +210,7 @@ public class ConfigPusherImpl implements ConfigPusher { } static Set transformCapabilities(final Set currentCapabilities) { - return new HashSet<>(Collections2.transform(currentCapabilities, new Function() { - @Override - public String apply(@Nonnull final Capability input) { - return input.getCapabilityUri(); - } - })); + return new HashSet<>(Collections2.transform(currentCapabilities, Capability::getCapabilityUri)); } static class ConfigPusherException extends Exception { @@ -235,7 +228,7 @@ public class ConfigPusherImpl implements ConfigPusher { private static final long serialVersionUID = 1L; private final Set missingCaps; - NotEnoughCapabilitiesException(String message, Set missingCaps) { + NotEnoughCapabilitiesException(final String message, final Set missingCaps) { super(message); this.missingCaps = missingCaps; } @@ -262,13 +255,13 @@ public class ConfigPusherImpl implements ConfigPusher { private void sleep() { try { Thread.sleep(100); - } catch (InterruptedException e) { + } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException(e); } } - private synchronized boolean pushConfig(ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException, ConflictingVersionException { + private synchronized boolean pushConfig(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException, ConflictingVersionException { Element xmlToBePersisted; try { xmlToBePersisted = XmlUtil.readXmlToElement(configSnapshotHolder.getConfigSnapshot()); @@ -299,7 +292,7 @@ public class ConfigPusherImpl implements ConfigPusher { return true; } - private void executeWithMissingModuleFactoryRetries(ConfigSubsystemFacade facade, ConfigExecution configExecution) + private void executeWithMissingModuleFactoryRetries(final ConfigSubsystemFacade facade, final ConfigExecution configExecution) throws DocumentedException, ValidationException, ModuleFactoryNotFoundException { Stopwatch stopwatch = Stopwatch.createStarted(); ModuleFactoryNotFoundException lastException = null; @@ -307,7 +300,7 @@ public class ConfigPusherImpl implements ConfigPusher { try { facade.executeConfigExecution(configExecution); return; - } catch (ModuleFactoryNotFoundException e) { + } catch (final ModuleFactoryNotFoundException e) { LOG.debug("{} - will retry after timeout", e.toString()); lastException = e; sleep(); @@ -317,7 +310,7 @@ public class ConfigPusherImpl implements ConfigPusher { throw lastException; } - private ConfigExecution createConfigExecution(Element xmlToBePersisted, final ConfigSubsystemFacade currentFacade) throws DocumentedException { + private ConfigExecution createConfigExecution(final Element xmlToBePersisted, final ConfigSubsystemFacade currentFacade) throws DocumentedException { final Config configMapping = currentFacade.getConfigMapping(); return currentFacade.getConfigExecution(configMapping, xmlToBePersisted); }