X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2FOpenFlowPluginProviderImpl.java;h=6890f037821ce374f1fce07547f2fc2e8c6336d1;hb=refs%2Fchanges%2F71%2F103171%2F4;hp=88d3fedd2b446d885d5e56b9726f83d4526c4141;hpb=9ad03257c3b24024b3f478a8c3f0bbce83a7601b;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java index 88d3fedd2b..6890f03782 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java @@ -5,27 +5,31 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.openflowplugin.impl; +import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import com.google.common.util.concurrent.SettableFuture; import io.netty.util.HashedWheelTimer; import io.netty.util.Timer; import java.lang.management.ManagementFactory; import java.util.Collection; import java.util.List; -import java.util.Objects; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import javax.annotation.Nonnull; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Singleton; import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceNotFoundException; import javax.management.MBeanRegistrationException; @@ -33,16 +37,18 @@ import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.NotCompliantMBeanException; import javax.management.ObjectName; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService; -import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.infrautils.diagstatus.ServiceState; import org.opendaylight.infrautils.ready.SystemReadyListener; import org.opendaylight.infrautils.ready.SystemReadyMonitor; +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.binding.api.NotificationPublishService; +import org.opendaylight.mdsal.binding.api.RpcProviderService; +import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipService; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; -import org.opendaylight.openflowplugin.api.diagstatus.OpenflowPluginDiagStatusProvider; +import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProviderList; +import org.opendaylight.openflowplugin.api.openflow.FlowGroupInfoHistories; +import org.opendaylight.openflowplugin.api.openflow.FlowGroupInfoHistory; import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager; @@ -75,13 +81,16 @@ import org.opendaylight.openflowplugin.openflow.md.core.extension.ExtensionConve import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager; import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory; import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +@Singleton public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenFlowPluginExtensionRegistratorProvider, + FlowGroupInfoHistories, SystemReadyListener { private static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderImpl.class); @@ -104,7 +113,7 @@ public class OpenFlowPluginProviderImpl implements private final Collection switchConnectionProviders; private final DeviceInitializerProvider deviceInitializerProvider; private final ConvertorManager convertorManager; - private final RpcProviderRegistry rpcProviderRegistry; + private final RpcProviderService rpcProviderRegistry; private final ClusterSingletonServiceProvider singletonServicesProvider; private final OpenflowProviderConfig config; private final EntityOwnershipService entityOwnershipService; @@ -114,51 +123,51 @@ public class OpenFlowPluginProviderImpl implements private StatisticsManager statisticsManager; private RoleManager roleManager; private ConnectionManager connectionManager; - private ListeningExecutorService executorService; + private ExecutorService executorService; private ContextChainHolderImpl contextChainHolder; - private OpenflowPluginDiagStatusProvider openflowPluginStatusMonitor; + private final DiagStatusProvider diagStatusProvider; + private final SystemReadyMonitor systemReadyMonitor; + private final SettableFuture fullyStarted = SettableFuture.create(); + private static final String OPENFLOW_SERVICE_NAME = "OPENFLOW"; public static MessageIntelligenceAgency getMessageIntelligenceAgency() { return MESSAGE_INTELLIGENCE_AGENCY; } - OpenFlowPluginProviderImpl(final ConfigurationService configurationService, - final List switchConnectionProviders, - final DataBroker dataBroker, - final RpcProviderRegistry rpcProviderRegistry, + @Inject + public OpenFlowPluginProviderImpl(final ConfigurationService configurationService, + final SwitchConnectionProviderList switchConnectionProviders, + final PingPongDataBroker pingPongDataBroker, + final RpcProviderService rpcProviderRegistry, final NotificationPublishService notificationPublishService, final ClusterSingletonServiceProvider singletonServiceProvider, final EntityOwnershipService entityOwnershipService, final MastershipChangeServiceManager mastershipChangeServiceManager, - final OpenflowPluginDiagStatusProvider openflowPluginStatusMonitor, + final DiagStatusProvider diagStatusProvider, final SystemReadyMonitor systemReadyMonitor) { this.switchConnectionProviders = switchConnectionProviders; - this.dataBroker = dataBroker; + dataBroker = pingPongDataBroker; this.rpcProviderRegistry = rpcProviderRegistry; this.notificationPublishService = notificationPublishService; - this.singletonServicesProvider = singletonServiceProvider; + singletonServicesProvider = singletonServiceProvider; this.entityOwnershipService = entityOwnershipService; convertorManager = ConvertorManagerFactory.createDefaultManager(); extensionConverterManager = new ExtensionConverterManagerImpl(); deviceInitializerProvider = DeviceInitializerProviderFactory.createDefaultProvider(); config = new OpenFlowProviderConfigImpl(configurationService); this.mastershipChangeServiceManager = mastershipChangeServiceManager; - this.openflowPluginStatusMonitor = openflowPluginStatusMonitor; - systemReadyMonitor.registerListener(this); - LOG.debug("registered onSystemBootReady() listener for deferred startSwitchConnections()"); + this.diagStatusProvider = diagStatusProvider; + this.systemReadyMonitor = systemReadyMonitor; } @Override public void onSystemBootReady() { - LOG.debug("onSystemBootReady() received, starting the switch connections"); - startSwitchConnections(); - } - - private void startSwitchConnections() { + LOG.info("onSystemBootReady() received, starting the switch connections"); Futures.addCallback(Futures.allAsList(switchConnectionProviders.stream().map(switchConnectionProvider -> { // Inject OpenFlowPlugin custom serializers and deserializers into OpenFlowJava - if (config.isUseSingleLayerSerialization()) { - SerializerInjector.injectSerializers(switchConnectionProvider); + if (config.getUseSingleLayerSerialization()) { + SerializerInjector.injectSerializers(switchConnectionProvider, + switchConnectionProvider.getConfiguration().isGroupAddModEnabled()); DeserializerInjector.injectDeserializers(switchConnectionProvider); } else { DeserializerInjector.revertDeserializers(switchConnectionProvider); @@ -171,22 +180,29 @@ public class OpenFlowPluginProviderImpl implements @Override public void onSuccess(final List result) { LOG.info("All switchConnectionProviders are up and running ({}).", result.size()); - openflowPluginStatusMonitor.reportStatus(ServiceState.OPERATIONAL, "switch connections started"); + diagStatusProvider.reportStatus(ServiceState.OPERATIONAL); + fullyStarted.set(null); } @Override - public void onFailure(@Nonnull final Throwable throwable) { + public void onFailure(final Throwable throwable) { LOG.warn("Some switchConnectionProviders failed to start.", throwable); - openflowPluginStatusMonitor.reportStatus(ServiceState.ERROR, "some switch connections failed to start"); + diagStatusProvider.reportStatus(ServiceState.ERROR, throwable); + fullyStarted.setException(throwable); } }, MoreExecutors.directExecutor()); } + @VisibleForTesting + public Future getFullyStarted() { + return fullyStarted; + } + private ListenableFuture> shutdownSwitchConnections() { final ListenableFuture> listListenableFuture = Futures.allAsList(switchConnectionProviders.stream().map(switchConnectionProvider -> { // Revert deserializers to their original state - if (config.isUseSingleLayerSerialization()) { + if (config.getUseSingleLayerSerialization()) { DeserializerInjector.revertDeserializers(switchConnectionProvider); } @@ -201,7 +217,7 @@ public class OpenFlowPluginProviderImpl implements } @Override - public void onFailure(@Nonnull final Throwable throwable) { + public void onFailure(final Throwable throwable) { LOG.warn("Some switchConnectionProviders failed to shutdown.", throwable); } }, MoreExecutors.directExecutor()); @@ -210,6 +226,7 @@ public class OpenFlowPluginProviderImpl implements } @Override + @PostConstruct public void initialize() { registerMXBean(MESSAGE_INTELLIGENCE_AGENCY, MESSAGE_INTELLIGENCE_AGENCY_MX_BEAN_NAME); @@ -220,11 +237,11 @@ public class OpenFlowPluginProviderImpl implements // Creates a thread pool that creates new threads as needed, but will reuse previously // constructed threads when they are available. // Threads that have not been used for x seconds are terminated and removed from the cache. - executorService = MoreExecutors.listeningDecorator(new ThreadPoolLoggingExecutor( - config.getThreadPoolMinThreads(), - config.getThreadPoolMaxThreads().getValue(), - config.getThreadPoolTimeout(), - TimeUnit.SECONDS, new SynchronousQueue<>(), POOL_NAME)); + executorService = new ThreadPoolLoggingExecutor( + config.getThreadPoolMinThreads().toJava(), + config.getThreadPoolMaxThreads().getValue().toJava(), + config.getThreadPoolTimeout().toJava(), + TimeUnit.SECONDS, new SynchronousQueue<>(), POOL_NAME); deviceManager = new DeviceManagerImpl( config, @@ -233,7 +250,8 @@ public class OpenFlowPluginProviderImpl implements notificationPublishService, hashedWheelTimer, convertorManager, - deviceInitializerProvider); + deviceInitializerProvider, + executorService); TranslatorLibraryUtil.injectBasicTranslatorLibrary(deviceManager, convertorManager); ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager); @@ -251,24 +269,28 @@ public class OpenFlowPluginProviderImpl implements convertorManager, executorService); - roleManager = new RoleManagerImpl(hashedWheelTimer); + roleManager = new RoleManagerImpl(hashedWheelTimer, config, executorService); contextChainHolder = new ContextChainHolderImpl( executorService, singletonServicesProvider, entityOwnershipService, - mastershipChangeServiceManager); + mastershipChangeServiceManager, + config); contextChainHolder.addManager(deviceManager); contextChainHolder.addManager(statisticsManager); contextChainHolder.addManager(rpcManager); contextChainHolder.addManager(roleManager); - connectionManager = new ConnectionManagerImpl(config, executorService); + connectionManager = new ConnectionManagerImpl(config, executorService, dataBroker, notificationPublishService); connectionManager.setDeviceConnectedHandler(contextChainHolder); connectionManager.setDeviceDisconnectedHandler(contextChainHolder); + deviceManager.setContextChainHolder(contextChainHolder); deviceManager.initialize(); + systemReadyMonitor.registerListener(this); + LOG.info("registered onSystemBootReady() listener for OpenFlowPluginProvider"); } @Override @@ -277,14 +299,27 @@ public class OpenFlowPluginProviderImpl implements } @Override + public Map getAllFlowGroupHistories() { + return deviceManager.getAllFlowGroupHistories(); + } + + @Override + public FlowGroupInfoHistory getFlowGroupHistory(final NodeId nodeId) { + return deviceManager.getFlowGroupHistory(nodeId); + } + + @Override + @PreDestroy + @SuppressWarnings("checkstyle:IllegalCatch") public void close() { try { shutdownSwitchConnections().get(10, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { - LOG.warn("Failed to shut down switch connections in time {}s, error: {}", 10, e); + LOG.warn("Failed to shut down switch connections in time {}s", 10, e); } gracefulShutdown(contextChainHolder); + gracefulShutdown(connectionManager); gracefulShutdown(deviceManager); gracefulShutdown(rpcManager); gracefulShutdown(statisticsManager); @@ -292,43 +327,45 @@ public class OpenFlowPluginProviderImpl implements gracefulShutdown(executorService); gracefulShutdown(hashedWheelTimer); unregisterMXBean(MESSAGE_INTELLIGENCE_AGENCY_MX_BEAN_NAME); - openflowPluginStatusMonitor.reportStatus(ServiceState.UNREGISTERED, "service shutting down"); + diagStatusProvider.reportStatus(ServiceState.UNREGISTERED); + try { + if (connectionManager != null) { + connectionManager.close(); + connectionManager = null; + } + } catch (Exception e) { + LOG.error("Failed to close ConnectionManager", e); + } } @SuppressWarnings("checkstyle:IllegalCatch") private static void gracefulShutdown(final AutoCloseable closeable) { - if (Objects.isNull(closeable)) { - return; - } - - try { - closeable.close(); - } catch (Exception e) { - LOG.warn("Failed to shutdown {} gracefully.", closeable); + if (closeable != null) { + try { + closeable.close(); + } catch (Exception e) { + LOG.warn("Failed to shutdown {} gracefully.", closeable); + } } } private static void gracefulShutdown(final Timer timer) { - if (Objects.isNull(timer)) { - return; - } - - try { - timer.stop(); - } catch (IllegalStateException e) { - LOG.warn("Failed to shutdown {} gracefully.", timer); + if (timer != null) { + try { + timer.stop(); + } catch (IllegalStateException e) { + LOG.warn("Failed to shutdown {} gracefully.", timer); + } } } private static void gracefulShutdown(final ExecutorService executorService) { - if (Objects.isNull(executorService)) { - return; - } - - try { - executorService.shutdownNow(); - } catch (SecurityException e) { - LOG.warn("Failed to shutdown {} gracefully.", executorService); + if (executorService != null) { + try { + executorService.shutdownNow(); + } catch (SecurityException e) { + LOG.warn("Failed to shutdown {} gracefully.", executorService); + } } } @@ -341,7 +378,7 @@ public class OpenFlowPluginProviderImpl implements | NotCompliantMBeanException | MBeanRegistrationException | InstanceAlreadyExistsException e) { - LOG.warn("Error registering MBean {}", e); + LOG.warn("Error registering MBean {}", beanName, e); } } @@ -353,7 +390,7 @@ public class OpenFlowPluginProviderImpl implements } catch (InstanceNotFoundException | MBeanRegistrationException | MalformedObjectNameException e) { - LOG.warn("Error unregistering MBean {}", e); + LOG.warn("Error unregistering MBean {}", beanName, e); } } }