Extract mastership blueprint service 81/60181/12
authorJozef Bacigal <jozef.bacigal@pantheon.tech>
Tue, 11 Jul 2017 07:57:23 +0000 (09:57 +0200)
committerTomas Slusny <tomas.slusny@pantheon.tech>
Mon, 24 Jul 2017 10:19:12 +0000 (10:19 +0000)
Change-Id: I87180a1705c25cb51e9d71e1083e48cd4e52683c
Signed-off-by: Jozef Bacigal <jozef.bacigal@pantheon.tech>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProviderFactory.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManager.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/mastership/MastershipChangeServiceManagerFactory.java [new file with mode: 0644]
openflowplugin-blueprint-config/src/main/resources/org/opendaylight/blueprint/openflowplugin.xml
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderFactoryImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/configuration/ConfigurationServiceFactoryImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipChangeServiceManagerFactoryImpl.java [new file with mode: 0644]
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/mastership/MastershipServiceManagerImpl.java [deleted file]
openflowplugin-impl/src/main/resources/org/opendaylight/blueprint/openflowplugin-impl.xml
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java

index ef5aedec45dd511253843323316599eabf71c2f9..3322cc5d18e4cfc5072f0c8e355487f5db42b003 100644 (file)
@@ -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<SwitchConnectionProvider> switchConnectionProviders,
-                                       ClusterSingletonServiceProvider singletonServiceProvider);
+                                       ClusterSingletonServiceProvider singletonServiceProvider,
+                                       MastershipChangeServiceManager mastershipChangeServiceManager);
 }
index 6aaa72e2fae58973f6174809413bceca61a5d7a9..f3c430ee7db17eab42ffd4939935d24c494ef3c8 100644 (file)
@@ -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 (file)
index 0000000..3102554
--- /dev/null
@@ -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();
+
+}
index 0a493f336c116a85a80da0d5a5860a5060435f0b..08181d3c963ba720b0829ed3dc20a1b5626f9f7c 100644 (file)
@@ -22,6 +22,9 @@
     <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"
@@ -54,6 +65,7 @@
             </list>
         </argument>
         <argument ref="clusterSingletonServiceProvider"/>
+        <argument ref="mastershipChangeServiceManager"/>
     </bean>
 
     <service ref="openflowPluginProvider" odl:type="openflow-plugin-provider-impl">
index d28e40edba0a390bfdd98252aef1edf9a266c25d..309ef486f82d051b773ff65cc28e3bdaa1a8f3eb 100644 (file)
@@ -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<SwitchConnectionProvider> 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;
index 9ecfb8ac869378b70838f4bacd7d3f314d874792..d7fd288a059479c2f5c89cb3f9e6d3c119b8ac39 100644 (file)
@@ -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;
     }
 
 
index 3ec7cb8a7aa1aeae864c8cffe0639dc2944ce7de..94e32d3c4a2b90c3f8629ec6ce97958e3dd8943e 100644 (file)
@@ -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 (file)
index 0000000..dc1c5a7
--- /dev/null
@@ -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<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
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 (file)
index 031e119..0000000
+++ /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<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);
-    }
-}
index f83753964cf67ff3b10accf8bc7ce135187a51a2..7712098b9510449a5d719db066613676b7cff510 100644 (file)
@@ -8,4 +8,7 @@
 
   <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>
index 9f6abc99d7d710eee937e002d048b21f072aaa88..acf9f1f42e5009a6d12e47683cd759865bc267ac 100644 (file)
@@ -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