From 55d7ecd5a44d3cc29598fda492ce527e082c7448 Mon Sep 17 00:00:00 2001 From: Jozef Bacigal Date: Tue, 11 Jul 2017 09:57:23 +0200 Subject: [PATCH] Extract mastership blueprint service Change-Id: I87180a1705c25cb51e9d71e1083e48cd4e52683c Signed-off-by: Jozef Bacigal --- .../OpenFlowPluginProviderFactory.java | 4 +- .../MastershipChangeServiceManager.java | 4 +- ...MastershipChangeServiceManagerFactory.java | 24 +++++ .../opendaylight/blueprint/openflowplugin.xml | 12 +++ .../OpenFlowPluginProviderFactoryImpl.java | 7 +- .../impl/OpenFlowPluginProviderImpl.java | 6 +- .../ConfigurationServiceFactoryImpl.java | 2 +- ...ershipChangeServiceManagerFactoryImpl.java | 87 +++++++++++++++++++ .../MastershipServiceManagerImpl.java | 73 ---------------- .../blueprint/openflowplugin-impl.xml | 3 + .../impl/OpenFlowPluginProviderImplTest.java | 7 +- 11 files changed, 147 insertions(+), 82 deletions(-) create mode 100644 openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManagerFactory.java create mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipChangeServiceManagerFactoryImpl.java delete mode 100644 openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipServiceManagerImpl.java diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProviderFactory.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProviderFactory.java index ef5aedec45..3322cc5d18 100644 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProviderFactory.java +++ b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProviderFactory.java @@ -15,6 +15,7 @@ import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService; +import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager; /** * Factory for creating OpenFlowPluginProvider instances. @@ -26,5 +27,6 @@ public interface OpenFlowPluginProviderFactory { NotificationPublishService notificationPublishService, EntityOwnershipService entityOwnershipService, List switchConnectionProviders, - ClusterSingletonServiceProvider singletonServiceProvider); + ClusterSingletonServiceProvider singletonServiceProvider, + MastershipChangeServiceManager mastershipChangeServiceManager); } diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManager.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManager.java index 6aaa72e2fa..f3c430ee7d 100644 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManager.java +++ b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManager.java @@ -14,11 +14,13 @@ import org.opendaylight.openflowplugin.api.openflow.lifecycle.OwnershipChangeLis * Provider to register mastership change listener. * @since 0.5.0 Nitrogen */ -public interface MastershipChangeServiceManager extends OwnershipChangeListener { +public interface MastershipChangeServiceManager extends OwnershipChangeListener, AutoCloseable { @Nonnull MastershipChangeRegistration register(@Nonnull MastershipChangeService service); void unregister(@Nonnull MastershipChangeService service); + @Override + void close(); } diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManagerFactory.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManagerFactory.java new file mode 100644 index 0000000000..3102554312 --- /dev/null +++ b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManagerFactory.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.api.openflow.mastership; + +/** + * Factory for mastership change service manager. + * @see MastershipChangeServiceManager + * @see MastershipChangeService + * @since 0.5.0 Nitrogen + */ +public interface MastershipChangeServiceManagerFactory { + + /** + * Creates instance of mastership change service manager. + * @return new instance + */ + MastershipChangeServiceManager newInstance(); + +} diff --git a/openflowplugin-blueprint-config/src/main/resources/org/opendaylight/blueprint/openflowplugin.xml b/openflowplugin-blueprint-config/src/main/resources/org/opendaylight/blueprint/openflowplugin.xml index 0a493f336c..08181d3c96 100644 --- a/openflowplugin-blueprint-config/src/main/resources/org/opendaylight/blueprint/openflowplugin.xml +++ b/openflowplugin-blueprint-config/src/main/resources/org/opendaylight/blueprint/openflowplugin.xml @@ -22,6 +22,9 @@ + + @@ -36,6 +39,14 @@ update-method="update"/> + + + + + diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderFactoryImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderFactoryImpl.java index d28e40edba..309ef486f8 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderFactoryImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderFactoryImpl.java @@ -17,6 +17,7 @@ import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionPro import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider; import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProviderFactory; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService; +import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,7 +36,8 @@ public class OpenFlowPluginProviderFactoryImpl implements OpenFlowPluginProvider final NotificationPublishService notificationPublishService, final EntityOwnershipService entityOwnershipService, final List switchConnectionProviders, - final ClusterSingletonServiceProvider singletonServiceProvider) { + final ClusterSingletonServiceProvider singletonServiceProvider, + final MastershipChangeServiceManager mastershipChangeServiceManager) { LOG.info("Initializing new OFP southbound."); final OpenFlowPluginProvider openflowPluginProvider = new OpenFlowPluginProviderImpl( configurationService, @@ -44,7 +46,8 @@ public class OpenFlowPluginProviderFactoryImpl implements OpenFlowPluginProvider rpcRegistry, notificationPublishService, singletonServiceProvider, - entityOwnershipService); + entityOwnershipService, + mastershipChangeServiceManager); openflowPluginProvider.initialize(); return openflowPluginProvider; 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 9ecfb8ac86..d7fd288a05 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 @@ -55,7 +55,6 @@ import org.opendaylight.openflowplugin.impl.device.DeviceManagerImpl; import org.opendaylight.openflowplugin.impl.device.initialization.DeviceInitializerProvider; import org.opendaylight.openflowplugin.impl.device.initialization.DeviceInitializerProviderFactory; import org.opendaylight.openflowplugin.impl.lifecycle.ContextChainHolderImpl; -import org.opendaylight.openflowplugin.impl.mastership.MastershipServiceManagerImpl; import org.opendaylight.openflowplugin.impl.protocol.deserialization.DeserializerInjector; import org.opendaylight.openflowplugin.impl.protocol.serialization.SerializerInjector; import org.opendaylight.openflowplugin.impl.rpc.RpcManagerImpl; @@ -117,7 +116,8 @@ public class OpenFlowPluginProviderImpl implements final RpcProviderRegistry rpcProviderRegistry, final NotificationPublishService notificationPublishService, final ClusterSingletonServiceProvider singletonServiceProvider, - final EntityOwnershipService entityOwnershipService) { + final EntityOwnershipService entityOwnershipService, + final MastershipChangeServiceManager mastershipChangeServiceManager) { this.switchConnectionProviders = switchConnectionProviders; this.dataBroker = dataBroker; this.rpcProviderRegistry = rpcProviderRegistry; @@ -128,7 +128,7 @@ public class OpenFlowPluginProviderImpl implements extensionConverterManager = new ExtensionConverterManagerImpl(); deviceInitializerProvider = DeviceInitializerProviderFactory.createDefaultProvider(); config = new OpenFlowProviderConfigImpl(configurationService); - mastershipChangeServiceManager = new MastershipServiceManagerImpl(); + this.mastershipChangeServiceManager = mastershipChangeServiceManager; } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java index 3ec7cb8a7a..94e32d3c4a 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java @@ -81,7 +81,7 @@ public class ConfigurationServiceFactoryImpl implements ConfigurationServiceFact .put(ConfigurationProperty.THREAD_POOL_TIMEOUT.toString(), providerConfig.getThreadPoolTimeout().toString()) .put(ConfigurationProperty.USING_RECONCILIATION_FRAMEWORK.toString(), - providerConfig.isUseSingleLayerSerialization().toString()) + providerConfig.isUsingReconciliationFramework().toString()) .build()); LOG.info("Loading configuration from '{}' configuration file", OFConstants.CONFIG_FILE_ID); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipChangeServiceManagerFactoryImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipChangeServiceManagerFactoryImpl.java new file mode 100644 index 0000000000..dc1c5a7dba --- /dev/null +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipChangeServiceManagerFactoryImpl.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * 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.mastership; + +import com.google.common.util.concurrent.FutureCallback; +import java.util.LinkedList; +import java.util.List; +import javax.annotation.Nonnull; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; +import org.opendaylight.openflowplugin.api.openflow.lifecycle.MasterChecker; +import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeRegistration; +import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeService; +import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager; +import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManagerFactory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.rf.state.rev170713.ResultState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MastershipChangeServiceManagerFactoryImpl implements MastershipChangeServiceManagerFactory { + + @Override + public MastershipChangeServiceManager newInstance() { + return new MastershipChangeServiceManagerImpl(); + } + + private static final class MastershipChangeServiceManagerImpl implements MastershipChangeServiceManager { + + private static final Logger LOG = LoggerFactory.getLogger(MastershipChangeServiceManagerImpl.class); + + private final List serviceGroup = new LinkedList<>(); + private MasterChecker masterChecker; + + @Nonnull + @Override + public MastershipChangeRegistration register(@Nonnull MastershipChangeService service) { + if (LOG.isDebugEnabled()) { + LOG.debug("Mastership change service registered: {}", service); + } + MastershipServiceDelegate registration = new MastershipServiceDelegate(service, this); + serviceGroup.add(registration); + if (masterChecker.isAnyDeviceMastered()) { + fireBecomeOwnerAfterRegistration(registration); + } + return registration; + + } + + @Override + public void unregister(@Nonnull MastershipChangeService service) { + serviceGroup.remove(service); + } + + @Override + public void close() { + serviceGroup.clear(); + } + + @Override + public void becomeMaster(@Nonnull final DeviceInfo deviceInfo) { + serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onBecomeOwner(deviceInfo)); + } + + @Override + public void becomeSlaveOrDisconnect(@Nonnull final DeviceInfo deviceInfo) { + serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onLoseOwnership(deviceInfo)); + } + + @Override + public void becomeMasterBeforeSubmittedDS(@Nonnull DeviceInfo deviceInfo, @Nonnull FutureCallback callback) { + serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onDevicePrepared(deviceInfo, callback)); + } + + @Override + public void setMasterChecker(@Nonnull final MasterChecker masterChecker) { + this.masterChecker = masterChecker; + } + + private void fireBecomeOwnerAfterRegistration(@Nonnull final MastershipChangeService service) { + masterChecker.listOfMasteredDevices().forEach(service::onBecomeOwner); + } + } +} \ No newline at end of file diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipServiceManagerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipServiceManagerImpl.java deleted file mode 100644 index 031e1191bf..0000000000 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipServiceManagerImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * 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.mastership; - -import com.google.common.util.concurrent.FutureCallback; -import java.util.LinkedList; -import java.util.List; -import javax.annotation.Nonnull; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; -import org.opendaylight.openflowplugin.api.openflow.lifecycle.MasterChecker; -import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeRegistration; -import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeService; -import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.rf.state.rev170713.ResultState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class MastershipServiceManagerImpl implements MastershipChangeServiceManager { - - private static final Logger LOG = LoggerFactory.getLogger(MastershipServiceManagerImpl.class); - - private final List serviceGroup = new LinkedList<>(); - private MasterChecker masterChecker; - - @Nonnull - @Override - public MastershipChangeRegistration register(@Nonnull MastershipChangeService service) { - if (LOG.isDebugEnabled()) { - LOG.debug("Mastership change service registered: {}", service); - } - MastershipServiceDelegate registration = new MastershipServiceDelegate(service, this); - serviceGroup.add(registration); - if (masterChecker.isAnyDeviceMastered()) { - fireBecomeOwnerAfterRegistration(registration); - } - return registration; - - } - - @Override - public void unregister(@Nonnull MastershipChangeService service) { - serviceGroup.remove(service); - } - - @Override - public void becomeMaster(@Nonnull final DeviceInfo deviceInfo) { - serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onBecomeOwner(deviceInfo)); - } - - @Override - public void becomeSlaveOrDisconnect(@Nonnull final DeviceInfo deviceInfo) { - serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onLoseOwnership(deviceInfo)); - } - - @Override - public void becomeMasterBeforeSubmittedDS(@Nonnull DeviceInfo deviceInfo, @Nonnull FutureCallback callback) { - serviceGroup.forEach(mastershipChangeService -> mastershipChangeService.onDevicePrepared(deviceInfo, callback)); - } - - @Override - public void setMasterChecker(@Nonnull final MasterChecker masterChecker) { - this.masterChecker = masterChecker; - } - - private void fireBecomeOwnerAfterRegistration(@Nonnull final MastershipChangeService service) { - masterChecker.listOfMasteredDevices().forEach(service::onBecomeOwner); - } -} diff --git a/openflowplugin-impl/src/main/resources/org/opendaylight/blueprint/openflowplugin-impl.xml b/openflowplugin-impl/src/main/resources/org/opendaylight/blueprint/openflowplugin-impl.xml index f83753964c..7712098b95 100644 --- a/openflowplugin-impl/src/main/resources/org/opendaylight/blueprint/openflowplugin-impl.xml +++ b/openflowplugin-impl/src/main/resources/org/opendaylight/blueprint/openflowplugin-impl.xml @@ -8,4 +8,7 @@ + + + diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java index 9f6abc99d7..acf9f1f42e 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java @@ -31,6 +31,7 @@ import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvid import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationProperty; import org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService; +import org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.sm.control.rev150812.StatisticsManagerControlService; @RunWith(MockitoJUnitRunner.class) @@ -66,6 +67,9 @@ public class OpenFlowPluginProviderImplTest { @Mock ConfigurationService configurationService; + @Mock + MastershipChangeServiceManager mastershipChangeServiceManager; + private static final int RPC_REQUESTS_QUOTA = 500; private static final long GLOBAL_NOTIFICATION_QUOTA = 131072; private static final int THREAD_POOL_MIN_THREADS = 1; @@ -98,7 +102,8 @@ public class OpenFlowPluginProviderImplTest { rpcProviderRegistry, notificationPublishService, clusterSingletonServiceProvider, - entityOwnershipService); + entityOwnershipService, + mastershipChangeServiceManager); } @Test -- 2.36.6