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.
NotificationPublishService notificationPublishService,
EntityOwnershipService entityOwnershipService,
List<SwitchConnectionProvider> switchConnectionProviders,
- ClusterSingletonServiceProvider singletonServiceProvider);
+ ClusterSingletonServiceProvider singletonServiceProvider,
+ MastershipChangeServiceManager mastershipChangeServiceManager);
}
* 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();
}
--- /dev/null
+/*
+ * 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();
+
+}
<reference id="configurationServiceFactory"
interface="org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationServiceFactory"/>
+ <reference id="mastershipChangeServiceManagerFactory"
+ interface="org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManagerFactory"/>
+
<odl:clustered-app-config id="openflowProviderConfig"
binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig"/>
update-method="update"/>
</bean>
+ <bean id="mastershipChangeServiceManager"
+ factory-ref="mastershipChangeServiceManagerFactory"
+ factory-method="newInstance"
+ destroy-method="close"
+ />
+
+ <service ref="mastershipChangeServiceManager" interface="org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManager"/>
+
<service ref="configurationService" interface="org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationService"/>
<bean id="openflowPluginProvider"
</list>
</argument>
<argument ref="clusterSingletonServiceProvider"/>
+ <argument ref="mastershipChangeServiceManager"/>
</bean>
<service ref="openflowPluginProvider" odl:type="openflow-plugin-provider-impl">
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;
final NotificationPublishService notificationPublishService,
final EntityOwnershipService entityOwnershipService,
final List<SwitchConnectionProvider> switchConnectionProviders,
- final ClusterSingletonServiceProvider singletonServiceProvider) {
+ final ClusterSingletonServiceProvider singletonServiceProvider,
+ final MastershipChangeServiceManager mastershipChangeServiceManager) {
LOG.info("Initializing new OFP southbound.");
final OpenFlowPluginProvider openflowPluginProvider = new OpenFlowPluginProviderImpl(
configurationService,
rpcRegistry,
notificationPublishService,
singletonServiceProvider,
- entityOwnershipService);
+ entityOwnershipService,
+ mastershipChangeServiceManager);
openflowPluginProvider.initialize();
return openflowPluginProvider;
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;
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;
extensionConverterManager = new ExtensionConverterManagerImpl();
deviceInitializerProvider = DeviceInitializerProviderFactory.createDefaultProvider();
config = new OpenFlowProviderConfigImpl(configurationService);
- mastershipChangeServiceManager = new MastershipServiceManagerImpl();
+ this.mastershipChangeServiceManager = mastershipChangeServiceManager;
}
.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);
--- /dev/null
+/*
+ * 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<MastershipChangeService> 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<ResultState> 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
+++ /dev/null
-/*
- * 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<MastershipChangeService> 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<ResultState> 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);
- }
-}
<bean id="configurationServiceFactory" class="org.opendaylight.openflowplugin.impl.configuration.ConfigurationServiceFactoryImpl"/>
<service ref="configurationServiceFactory" interface="org.opendaylight.openflowplugin.api.openflow.configuration.ConfigurationServiceFactory"/>
+
+ <bean id="mastershipChangeServiceManagerFactory" class="org.opendaylight.openflowplugin.impl.mastership.MastershipChangeServiceManagerFactoryImpl"/>
+ <service ref="mastershipChangeServiceManagerFactory" interface="org.opendaylight.openflowplugin.api.openflow.mastership.MastershipChangeServiceManagerFactory"/>
</blueprint>
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)
@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;
rpcProviderRegistry,
notificationPublishService,
clusterSingletonServiceProvider,
- entityOwnershipService);
+ entityOwnershipService,
+ mastershipChangeServiceManager);
}
@Test