Bug 5596 Cleaning lifecycle conductor 67/42567/18
authorJozef Bacigal <jbacigal@cisco.com>
Tue, 26 Jul 2016 13:18:41 +0000 (15:18 +0200)
committerJozef Bacigal <jozef.bacigal@pantheon.tech>
Mon, 15 Aug 2016 08:39:45 +0000 (08:39 +0000)
- removed lifecycle conductor

Change-Id: I7143726358c7d2145e2109e269e8d50e2c865a1f
Signed-off-by: Jozef Bacigal <jbacigal@cisco.com>
36 files changed:
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProvider.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceInfo.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceManager.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/DeviceContextChangeListener.java [deleted file]
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/LifecycleConductor.java [deleted file]
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/LifecycleService.java
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/statistics/StatisticsContext.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImpl.java [deleted file]
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/connection/ConnectionContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManager.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/DeviceInitializationUtils.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java [deleted file]
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/TransactionChainManagerTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/role/RoleManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/rpc/RpcManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpMockInitiation.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplParamTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java

index 132dabed8982a755a7096205812088ea19e1b3f9..31f1828a7d82e7ff771391ba645247abf4017130 100644 (file)
@@ -60,9 +60,6 @@ public interface OpenFlowPluginProvider extends AutoCloseable, BindingService {
 
     void setIsStatisticsPollingOff(final boolean isStatisticsPollingOff);
 
-    void setEntityOwnershipService(EntityOwnershipService entityOwnershipService);
-
-
     /**
      * Backward compatibility feature - exposing rpc for statistics polling (result is provided in form of async notification)
      *
index c7dca5069ad58c2d8c97c429a833c8be21e2f2b1..a081ab7cabb4fb2541213ac0862e310a28443fd5 100644 (file)
@@ -42,7 +42,6 @@ public interface DeviceContext extends
         AutoCloseable,
         DeviceReplyProcessor,
         TxFacade,
-        XidSequencer,
         DeviceRegistry{
 
     /**
index 9272c919b223b312d63f5766b89a15b338240d2c..fa4a212cd8f34ecb750a82f83cb99ced1167ed1b 100644 (file)
@@ -18,7 +18,7 @@ import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 /**
  * API defining basic device information
  */
-public interface DeviceInfo {
+public interface DeviceInfo extends XidSequencer {
 
     /**
      * @return id of encapsulated node
index 3f73661fc1bcf1253cf9883a7f1c2db96601bc6e..6eac084af9c9026b5c25e5375cba9bf9ad9cd303 100644 (file)
@@ -14,6 +14,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDiscon
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceLifecycleSupervisor;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian;
 
 /**
diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/DeviceContextChangeListener.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/DeviceContextChangeListener.java
deleted file mode 100644 (file)
index 33d63b7..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.lifecycle;
-
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-
-/**
- * This API is for all listeners who wish to know about device context in cluster
- */
-public interface DeviceContextChangeListener {
-
-    /**
-     * Notification about start phase in device context, right after successful handshake
-     * @param deviceInfo
-     * @param success or failure
-     */
-    void deviceStartInitializationDone(final DeviceInfo deviceInfo, final boolean success);
-
-    /**
-     * Notification about start phase in device context, after all other contexts initialized properly
-     * @param deviceInfo
-     * @param success
-     */
-    void deviceInitializationDone(final DeviceInfo deviceInfo, final boolean success);
-
-}
diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/LifecycleConductor.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/lifecycle/LifecycleConductor.java
deleted file mode 100644 (file)
index 8e688eb..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.lifecycle;
-
-import io.netty.util.Timeout;
-import io.netty.util.TimerTask;
-import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.openflowplugin.api.openflow.OFPManager;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
-
-/**
- * This class is a binder between all managers
- * Should be defined in OpenFlowPluginProviderImpl
- */
-public interface LifecycleConductor {
-
-    /**
-     * Returns device context from device manager device contexts maps
-     *
-     * @param deviceInfo@return null if context doesn't exists
-     */
-    DeviceContext getDeviceContext(DeviceInfo deviceInfo);
-
-
-    /**
-     * Setter for device manager once set it cant be unset or overwritten
-     * @param manager
-     */
-    void setSafelyManager(OFPManager manager);
-
-    /**
-     * Set new timeout for {@link io.netty.util.HashedWheelTimer}
-     * @param task timer task
-     * @param delay delay
-     * @param unit time unit
-     * @return new timeout
-     */
-    Timeout newTimeout(@Nonnull TimerTask task, long delay, @Nonnull TimeUnit unit);
-
-    /**
-     * Returns message intelligence agency
-     * @return MessageIntelligenceAgency set by constructor
-     */
-    MessageIntelligenceAgency getMessageIntelligenceAgency();
-
-    /**
-     * Interrupt connection for the node
-     * @param deviceInfo node identification
-     */
-    void closeConnection(final DeviceInfo deviceInfo);
-
-    ConnectionContext.CONNECTION_STATE gainConnectionStateSafely(DeviceInfo deviceInfo);
-
-    /**
-     * Xid from outboundqueue
-     * @param deviceInfo
-     * @return
-     */
-    Long reserveXidForDeviceMessage(final DeviceInfo deviceInfo);
-
-    NotificationPublishService getNotificationPublishService();
-
-    void setNotificationPublishService(NotificationPublishService notificationPublishService);
-}
index 377be685e26d9c9bc03ab2f3f7f514bc88a307eb..53755179d78d79169533fa7d1a7dd2f67161baa0 100644 (file)
@@ -29,4 +29,16 @@ public interface LifecycleService extends ClusterSingletonService, AutoCloseable
     void setRoleContext(RoleContext roleContext);
 
     void setStatContext(StatisticsContext statContext);
+
+    /**
+     * Some services, contexts etc. still need to have access to device context,
+     * instead to push into them, here is the getter
+     * @return device context for this device
+     */
+    DeviceContext getDeviceContext();
+
+    /**
+     * if some services not started properly need to close connection
+     */
+    void closeConnection();
 }
index 9af51e543251ec82809c7bb1fa46710558b51227..0fbc6905d7d766afd00ba85fcbb633245a6ef487 100644 (file)
@@ -15,6 +15,7 @@ import org.opendaylight.openflowplugin.api.openflow.OFPContext;
 import org.opendaylight.openflowplugin.api.openflow.OFPManager;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
 
 /**
@@ -73,4 +74,6 @@ public interface StatisticsContext extends RequestContextStack, AutoCloseable, O
      * @return true if scheduling is enabled
      */
     boolean isSchedulingEnabled();
+
+    LifecycleService getLifecycleService();
 }
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImpl.java
deleted file mode 100644 (file)
index d8286b8..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.Timeout;
-import io.netty.util.TimerTask;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.openflowplugin.api.openflow.OFPManager;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.DeviceContextChangeListener;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
-import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
-import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
-import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper;
-import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
-import org.opendaylight.openflowplugin.impl.util.MdSalRegistrationUtils;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- */
-final class LifecycleConductorImpl implements LifecycleConductor, DeviceContextChangeListener, ExtensionConverterProviderKeeper {
-
-    private static final Logger LOG = LoggerFactory.getLogger(LifecycleConductorImpl.class);
-    private static final int TICKS_PER_WHEEL = 500;
-    private static final long TICK_DURATION = 10; // 0.5 sec.
-
-    private final HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(TICK_DURATION, TimeUnit.MILLISECONDS, TICKS_PER_WHEEL);
-    private ExtensionConverterProvider extensionConverterProvider;
-    private DeviceManager deviceManager;
-    private StatisticsManager statisticsManager;
-    private RpcManager rpcManager;
-    private final MessageIntelligenceAgency messageIntelligenceAgency;
-    private final ConvertorExecutor convertorExecutor;
-    private NotificationPublishService notificationPublishService;
-
-    LifecycleConductorImpl(final MessageIntelligenceAgency messageIntelligenceAgency, ConvertorExecutor convertorExecutor) {
-        this.messageIntelligenceAgency = Preconditions.checkNotNull(messageIntelligenceAgency);
-        this.convertorExecutor = convertorExecutor;
-    }
-
-    @Override
-    public ExtensionConverterProvider getExtensionConverterProvider() {
-        return extensionConverterProvider;
-    }
-
-    @Override
-    public void setExtensionConverterProvider(ExtensionConverterProvider extensionConverterProvider) {
-        this.extensionConverterProvider = extensionConverterProvider;
-    }
-
-    @Override
-    public void setSafelyManager(final OFPManager manager){
-        if (manager instanceof RpcManager) {
-            if (rpcManager != null) {
-                LOG.info("RPC manager {} is already defined in conductor. ", manager);
-                return;
-            }
-            this.rpcManager = (RpcManager) manager;
-        } else {
-            if (manager instanceof StatisticsManager) {
-                if (statisticsManager != null) {
-                    LOG.info("Statistics manager {} is already defined in conductor. ", manager);
-                    return;
-                }
-                this.statisticsManager = (StatisticsManager) manager;
-            } else {
-                if (manager instanceof DeviceManager) {
-                    if (deviceManager != null) {
-                        LOG.info("Device manager {} is already defined in conductor. ", manager);
-                        return;
-                    }
-                    this.deviceManager = (DeviceManager) manager;
-                }
-            }
-        }
-    }
-
-    public void closeConnection(final DeviceInfo deviceInfo) {
-        LOG.debug("Close connection called for node {}", deviceInfo);
-        final DeviceContext deviceContext = getDeviceContext(deviceInfo);
-        if (null != deviceContext) {
-            deviceContext.shutdownConnection();
-        }
-    }
-
-    public MessageIntelligenceAgency getMessageIntelligenceAgency() {
-        return messageIntelligenceAgency;
-    }
-
-    @Override
-    public DeviceContext getDeviceContext(DeviceInfo deviceInfo){
-         return deviceManager.gainContext(deviceInfo);
-    }
-
-    public Timeout newTimeout(@Nonnull TimerTask task, long delay, @Nonnull TimeUnit unit) {
-        return hashedWheelTimer.newTimeout(task, delay, unit);
-    }
-
-    @Override
-    public ConnectionContext.CONNECTION_STATE gainConnectionStateSafely(final DeviceInfo deviceInfo){
-        return (null != getDeviceContext(deviceInfo)) ? getDeviceContext(deviceInfo).getPrimaryConnectionContext().getConnectionState() : null;
-    }
-
-    @Override
-    public Long reserveXidForDeviceMessage(final DeviceInfo deviceInfo){
-        return null != getDeviceContext(deviceInfo) ? getDeviceContext(deviceInfo).reserveXidForDeviceMessage() : null;
-    }
-
-    @Override
-    public void deviceStartInitializationDone(final DeviceInfo deviceInfo, final boolean success) {
-        if (!success) {
-            LOG.warn("Initialization phase for node {} in device context was NOT successful, closing connection.", deviceInfo.getNodeId().getValue());
-            closeConnection(deviceInfo);
-        } else {
-            LOG.info("initialization phase for node {} in device context was successful. Continuing to next context.", deviceInfo.getNodeId().getValue());
-        }
-    }
-
-    @Override
-    public void deviceInitializationDone(final DeviceInfo deviceInfo, final boolean success) {
-        if (!success) {
-            LOG.warn("Initialization phase for node {} in device context was NOT successful, closing connection.", deviceInfo.getNodeId().getValue());
-            closeConnection(deviceInfo);
-        } else {
-            LOG.info("initialization phase for node {} in device context was successful. All phases initialized OK.", deviceInfo.getNodeId().getValue());
-        }
-    }
-
-    @Override
-    public NotificationPublishService getNotificationPublishService() {
-        return notificationPublishService;
-    }
-
-    @Override
-    public void setNotificationPublishService(NotificationPublishService notificationPublishService) {
-        this.notificationPublishService = notificationPublishService;
-    }
-}
index 8538bb6ebca97a551871377a0c2c49e8c87295d5..09c2ccc713700bc56837df16d24d076df9a1ecb6 100644 (file)
@@ -55,7 +55,6 @@ public class OpenFlowPluginProviderFactoryImpl implements OpenFlowPluginProvider
         openflowPluginProvider.setRpcProviderRegistry(rpcRegistry);
         openflowPluginProvider.setNotificationProviderService(notificationService);
         openflowPluginProvider.setNotificationPublishService(notificationPublishService);
-        openflowPluginProvider.setEntityOwnershipService(entityOwnershipService);
         openflowPluginProvider.setSwitchFeaturesMandatory(providerConfig.isSwitchFeaturesMandatory());
         openflowPluginProvider.setIsStatisticsPollingOff(providerConfig.isIsStatisticsPollingOff());
         openflowPluginProvider.setIsStatisticsRpcEnabled(providerConfig.isIsStatisticsRpcEnabled());
index c565d2e83fc95b8b0a60ca16aeba60c92850ebff..b253c1019d07bdce5fc6ba50bab9aef60b42abfa 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
 import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -31,14 +32,12 @@ 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.binding.api.NotificationService;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 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.OpenFlowPluginProvider;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionManager;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
@@ -67,6 +66,10 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenFlowPluginProviderImpl.class);
     private static final MessageIntelligenceAgency messageIntelligenceAgency = new MessageIntelligenceAgencyImpl();
+    private static final int TICKS_PER_WHEEL = 500;
+    private static final long TICK_DURATION = 10; // 0.5 sec.
+
+    private final HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(TICK_DURATION, TimeUnit.MILLISECONDS, TICKS_PER_WHEEL);
 
     private final int rpcRequestsQuota;
     private final long globalNotificationQuota;
@@ -82,18 +85,13 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private ConnectionManager connectionManager;
     private NotificationService notificationProviderService;
     private NotificationPublishService notificationPublishService;
-    private EntityOwnershipService entityOwnershipService;
-
     private ExtensionConverterManager extensionConverterManager;
-
     private DataBroker dataBroker;
     private Collection<SwitchConnectionProvider> switchConnectionProviders;
     private boolean switchFeaturesMandatory = false;
     private boolean isStatisticsPollingOff = false;
     private boolean isStatisticsRpcEnabled;
     private boolean isNotificationFlowRemovedOff = false;
-
-    private final LifecycleConductor conductor;
     private final ThreadPoolExecutor threadPool;
     private ClusterSingletonServiceProvider singletonServicesProvider;
 
@@ -114,9 +112,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
                 Preconditions.checkNotNull(threadPoolMaxThreads),
                 Preconditions.checkNotNull(threadPoolTimeout), TimeUnit.SECONDS,
                 new SynchronousQueue<>(), "ofppool");
-
         convertorManager = ConvertorManagerFactory.createDefaultManager();
-        conductor = new LifecycleConductorImpl(messageIntelligenceAgency, convertorManager);
     }
 
     @Override
@@ -157,11 +153,6 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         return switchFeaturesMandatory;
     }
 
-    @Override
-    public void setEntityOwnershipService(final EntityOwnershipService entityOwnershipService) {
-        this.entityOwnershipService = entityOwnershipService;
-    }
-
     @Override
     public void setBarrierCountLimit(final int barrierCountLimit) {
         this.barrierCountLimit = barrierCountLimit;
@@ -186,7 +177,6 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         this.singletonServicesProvider = singletonServicesProvider;
     }
 
-
     @Override
     public void setSwitchFeaturesMandatory(final boolean switchFeaturesMandatory) {
         this.switchFeaturesMandatory = switchFeaturesMandatory;
@@ -232,22 +222,19 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
                 switchFeaturesMandatory,
                 barrierInterval,
                 barrierCountLimit,
-                conductor,
+                getMessageIntelligenceAgency(),
                 isNotificationFlowRemovedOff,
-                convertorManager,
-                singletonServicesProvider);
-        ((ExtensionConverterProviderKeeper) conductor).setExtensionConverterProvider(extensionConverterManager);
-        ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
 
-        conductor.setSafelyManager(deviceManager);
-        conductor.setNotificationPublishService(notificationPublishService);
+                singletonServicesProvider,
+                notificationPublishService,
+                hashedWheelTimer,
+               convertorManager);
 
-        statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff, conductor, convertorManager);
-        roleManager = new RoleManagerImpl(dataBroker, conductor);
-        conductor.setSafelyManager(statisticsManager);
+        ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
 
-        rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, conductor, extensionConverterManager, convertorManager, notificationPublishService);
-        conductor.setSafelyManager(rpcManager);
+        rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, extensionConverterManager, convertorManager, notificationPublishService);
+        roleManager = new RoleManagerImpl(dataBroker, hashedWheelTimer);
+        statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff, hashedWheelTimer, convertorManager);
 
         /* Initialization Phase ordering - OFP Device Context suite */
         // CM -> DM -> SM -> RPC -> Role -> DM
index aebb3fe3d3221034a1291f9f1c7688aedf0d6657..5a5de4fe9ce65849fbb73f6d9586aa652478a185 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.openflowplugin.impl.connection;
 import com.google.common.base.Preconditions;
 import java.math.BigInteger;
 import java.net.InetSocketAddress;
+import java.util.Objects;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
@@ -235,7 +236,8 @@ public class ConnectionContextImpl implements ConnectionContext {
                 nodeId,
                 DeviceStateUtil.createNodeInstanceIdentifier(nodeId),
                 featuresReply.getVersion(),
-                featuresReply.getDatapathId());
+                featuresReply.getDatapathId(),
+                outboundQueueProvider);
     }
 
     @Override
@@ -246,21 +248,24 @@ public class ConnectionContextImpl implements ConnectionContext {
 
     private class DeviceInfoImpl implements DeviceInfo {
 
-        final private NodeId nodeId;
-        final private KeyedInstanceIdentifier<Node, NodeKey> nodeII;
-        final private Short version;
-        final private BigInteger datapathId;
-        final private ServiceGroupIdentifier serviceGroupIdentifier;
+        private final NodeId nodeId;
+        private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
+        private final Short version;
+        private final BigInteger datapathId;
+        private final ServiceGroupIdentifier serviceGroupIdentifier;
+        private OutboundQueue outboundQueueProvider;
 
         DeviceInfoImpl(
                 final NodeId nodeId,
                 final KeyedInstanceIdentifier<Node, NodeKey> nodeII,
                 final Short version,
-                final BigInteger datapathId) {
+                final BigInteger datapathId,
+                final OutboundQueue outboundQueueProvider) {
             this.nodeId = nodeId;
             this.nodeII = nodeII;
             this.version = version;
             this.datapathId = datapathId;
+            this.outboundQueueProvider = outboundQueueProvider;
             this.serviceGroupIdentifier = ServiceGroupIdentifier.create(this.nodeId.getValue());
         }
 
@@ -316,5 +321,10 @@ public class ConnectionContextImpl implements ConnectionContext {
             result = 31 * result + datapathId.hashCode();
             return result;
         }
+
+        @Override
+        public Long reserveXidForDeviceMessage() {
+            return outboundQueueProvider.reserveEntry();
+        }
     }
 }
index 63f97c73afcd8f04e90a77758e2048e324f9f121..97c791766331ee2cd058aceb9e15a378b39c7170 100644 (file)
@@ -27,10 +27,8 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
-import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
@@ -40,7 +38,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher;
 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
@@ -126,7 +123,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     private final MessageSpy messageSpy;
     private final ItemLifeCycleKeeper flowLifeCycleKeeper;
     private NotificationPublishService notificationPublishService;
-    private final OutboundQueue outboundQueueProvider;
     private Timeout barrierTaskTimeout;
     private final MessageTranslator<PortGrouping, FlowCapableNodeConnector> portStatusTranslator;
     private final MessageTranslator<PacketInMessage, PacketReceived> packetInTranslator;
@@ -144,8 +140,7 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
     public DeviceContextImpl(
             @Nonnull final ConnectionContext primaryConnectionContext,
             @Nonnull final DataBroker dataBroker,
-            @Nonnull final LifecycleConductor conductor,
-            @Nonnull final OutboundQueueProvider outboundQueueProvider,
+            @Nonnull final MessageSpy messageSpy,
             @Nonnull final TranslatorLibrary translatorLibrary,
             @Nonnull final DeviceManager manager,
            final ConvertorExecutor convertorExecutor) {
@@ -153,18 +148,16 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         this.deviceInfo = primaryConnectionContext.getDeviceInfo();
         this.deviceState = new DeviceStateImpl();
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
-        Preconditions.checkNotNull(conductor);
-        this.outboundQueueProvider = Preconditions.checkNotNull(outboundQueueProvider);
-        this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo , conductor);
+        this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo);
         auxiliaryConnectionContexts = new HashMap<>();
         deviceFlowRegistry = new DeviceFlowRegistryImpl(dataBroker, deviceInfo.getNodeInstanceIdentifier());
         deviceGroupRegistry = new DeviceGroupRegistryImpl();
         deviceMeterRegistry = new DeviceMeterRegistryImpl();
-        messageSpy = conductor.getMessageIntelligenceAgency();
+        this.messageSpy = Preconditions.checkNotNull(messageSpy);
         this.deviceManager = Preconditions.checkNotNull(manager);
 
         packetInLimiter = new PacketInRateLimiter(primaryConnectionContext.getConnectionAdapter(),
-                /*initial*/ 1000, /*initial*/2000, messageSpy, REJECTED_DRAIN_FACTOR);
+                /*initial*/ 1000, /*initial*/2000, this.messageSpy, REJECTED_DRAIN_FACTOR);
 
         this.translatorLibrary = translatorLibrary;
         portStatusTranslator = translatorLibrary.lookupTranslator(
@@ -190,11 +183,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi
         transactionChainManager.initialSubmitWriteTransaction();
     }
 
-    @Override
-    public Long reserveXidForDeviceMessage() {
-        return outboundQueueProvider.reserveEntry();
-    }
-
     @Override
     public void addAuxiliaryConnectionContext(final ConnectionContext connectionContext) {
         final SwitchConnectionDistinguisher connectionDistinguisher = createConnectionDistinguisher(connectionContext);
index 3d076300a96f4046488acc0127dc0c6eb071156a..ef850d972f48018a4b172dc3666b430264a758cd 100644 (file)
@@ -14,6 +14,7 @@ import com.google.common.collect.Iterators;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
 import io.netty.util.TimerTask;
 import java.util.Collections;
 import java.util.Iterator;
@@ -25,6 +26,7 @@ import java.util.concurrent.TimeUnit;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
@@ -39,8 +41,8 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
+import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper;
 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
 import org.opendaylight.openflowplugin.impl.connection.OutboundQueueProviderImpl;
@@ -82,23 +84,28 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     private ExtensionConverterProvider extensionConverterProvider;
     private ScheduledThreadPoolExecutor spyPool;
     private final ClusterSingletonServiceProvider singletonServiceProvider;
-
-    private final LifecycleConductor conductor;
+    private final NotificationPublishService notificationPublishService;
+    private final MessageSpy messageSpy;
+    private final HashedWheelTimer hashedWheelTimer;
 
     public DeviceManagerImpl(@Nonnull final DataBroker dataBroker,
                              final long globalNotificationQuota,
                              final boolean switchFeaturesMandatory,
                              final long barrierInterval,
                              final int barrierCountLimit,
-                             final LifecycleConductor lifecycleConductor,
-                             boolean isNotificationFlowRemovedOff,
-                            final ConvertorExecutor convertorExecutor,
-                            final ClusterSingletonServiceProvider singletonServiceProvider) {
+                            
+                             final MessageSpy messageSpy,
+                             final boolean isNotificationFlowRemovedOff,
+                             final ClusterSingletonServiceProvider singletonServiceProvider,
+                             final NotificationPublishService notificationPublishService,
+                             final HashedWheelTimer hashedWheelTimer,
+                            final ConvertorExecutor convertorExecutor) {
         this.switchFeaturesMandatory = switchFeaturesMandatory;
         this.globalNotificationQuota = globalNotificationQuota;
         this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff;
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
         this.convertorExecutor = convertorExecutor;
+        this.hashedWheelTimer = hashedWheelTimer;
         /* merge empty nodes to oper DS to predict any problems with missing parent for Node */
         final WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
 
@@ -115,9 +122,10 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         this.barrierIntervalNanos = TimeUnit.MILLISECONDS.toNanos(barrierInterval);
         this.barrierCountLimit = barrierCountLimit;
 
-        this.conductor = lifecycleConductor;
         spyPool = new ScheduledThreadPoolExecutor(1);
         this.singletonServiceProvider = singletonServiceProvider;
+        this.notificationPublishService = notificationPublishService;
+        this.messageSpy = messageSpy;
     }
 
 
@@ -168,24 +176,25 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                 connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, barrierCountLimit, barrierIntervalNanos);
         connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
 
-        final DeviceContext deviceContext = new DeviceContextImpl(connectionContext,
+        final DeviceContext deviceContext = new DeviceContextImpl(
+                connectionContext,
                 dataBroker,
-                conductor,
-                outboundQueueProvider,
+                messageSpy,
                 translatorLibrary,
                 this,
                 convertorExecutor);
 
+        Verify.verify(deviceContexts.putIfAbsent(deviceInfo, deviceContext) == null, "DeviceCtx still not closed.");
+
         final LifecycleService lifecycleService = new LifecycleServiceImpl();
         lifecycleService.setDeviceContext(deviceContext);
 
-        Verify.verify(deviceContexts.putIfAbsent(deviceInfo, deviceContext) == null, "DeviceCtx still not closed.");
         lifecycleServices.putIfAbsent(deviceInfo, lifecycleService);
 
         deviceContext.setSwitchFeaturesMandatory(switchFeaturesMandatory);
 
         ((ExtensionConverterProviderKeeper) deviceContext).setExtensionConverterProvider(extensionConverterProvider);
-        deviceContext.setNotificationPublishService(conductor.getNotificationPublishService());
+        deviceContext.setNotificationPublishService(notificationPublishService);
 
         updatePacketInRateLimiters();
 
@@ -253,7 +262,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
 
     @Override
     public void initialize() {
-        spyPool.scheduleAtFixedRate(conductor.getMessageIntelligenceAgency(), SPY_RATE, SPY_RATE, TimeUnit.SECONDS);
+        spyPool.scheduleAtFixedRate(messageSpy, SPY_RATE, SPY_RATE, TimeUnit.SECONDS);
     }
 
     @Override
@@ -309,7 +318,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
                     future.cancel(false);
                 }
             };
-            conductor.newTimeout(timerTask, 10, TimeUnit.SECONDS);
+            hashedWheelTimer.newTimeout(timerTask, 10, TimeUnit.SECONDS);
         }
     }
 
@@ -318,6 +327,11 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         deviceContexts.put(deviceInfo, deviceContext);
     }
 
+    @VisibleForTesting
+    void removeDeviceContextFromMap(final DeviceInfo deviceInfo){
+        deviceContexts.remove(deviceInfo);
+    }
+
     @Override
     public <T extends OFPContext> T gainContext(final DeviceInfo deviceInfo) {
         return (T) deviceContexts.get(deviceInfo);
index 60d928eb0dc44d98c6b2cf4c5d75a0e63bcb2c4e..897d87637887a09d6424eed7450ab05a0a9478df 100644 (file)
@@ -27,7 +27,6 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosed
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
@@ -52,9 +51,7 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
 
     private final Object txLock = new Object();
     private final KeyedInstanceIdentifier<Node, NodeKey> nodeII;
-    private final DeviceInfo deviceInfo;
     private final DataBroker dataBroker;
-    private final LifecycleConductor conductor;
 
     @GuardedBy("txLock")
     private WriteTransaction wTx;
@@ -67,19 +64,12 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
 
     private boolean initCommit;
 
-    public TransactionChainManagerStatus getTransactionChainManagerStatus() {
-        return transactionChainManagerStatus;
-    }
-
     @GuardedBy("txLock")
     private TransactionChainManagerStatus transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
 
     TransactionChainManager(@Nonnull final DataBroker dataBroker,
-                            @Nonnull final DeviceInfo deviceInfo,
-                            @Nonnull final LifecycleConductor conductor) {
+                            @Nonnull final DeviceInfo deviceInfo) {
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
-        this.conductor = Preconditions.checkNotNull(conductor);
-        this.deviceInfo = deviceInfo;
         this.nodeII = deviceInfo.getNodeInstanceIdentifier();
         this.transactionChainManagerStatus = TransactionChainManagerStatus.SLEEPING;
         lastSubmittedFuture = Futures.immediateFuture(null);
@@ -191,7 +181,6 @@ class TransactionChainManager implements TransactionChainListener, AutoCloseable
                     }
                     if (initCommit) {
                         LOG.error("Initial commit failed. {}", t);
-                        conductor.closeConnection(deviceInfo);
                     }
                 }
             });
index eb2f09fdf396018aa0c1e6fb4890c4eefb5bc5bf..53cc263eb3e16103762f99a9e3327d1604edc18e 100644 (file)
@@ -111,6 +111,16 @@ public class LifecycleServiceImpl implements LifecycleService {
         this.statContext = statContext;
     }
 
+    @Override
+    public DeviceContext getDeviceContext() {
+        return this.deviceContext;
+    }
+
+    @Override
+    public void closeConnection() {
+        this.deviceContext.shutdownConnection();
+    }
+
     private void fillDeviceFlowRegistry() {
         // Fill device flow registry with flows from datastore
         final ListenableFuture<List<Optional<FlowCapableNode>>> deviceFlowRegistryFill = deviceContext.getDeviceFlowRegistry().fill();
index 7b5d923e69ac21ea16f1c3f81dfcb9fc05906a17..3e33a80845768c0a59b8f9fe9d67e162dfe7cf7f 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.JdkFutureAdapters;
 import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
 import io.netty.util.TimerTask;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -21,7 +22,6 @@ import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
 import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
@@ -47,24 +47,24 @@ class RoleContextImpl implements RoleContext {
     private static final int MAX_CLEAN_DS_RETRIES = 3;
 
     private SalRoleService salRoleService = null;
-    private final LifecycleConductor conductor;
+    private final HashedWheelTimer hashedWheelTimer;
     private final DeviceInfo deviceInfo;
     private CONTEXT_STATE state;
     private final RoleManager myManager;
 
     RoleContextImpl(final DeviceInfo deviceInfo,
-                    final LifecycleConductor lifecycleConductor,
+                    final HashedWheelTimer hashedWheelTimer,
                     final RoleManager myManager) {
-        this.conductor = lifecycleConductor;
         this.deviceInfo = deviceInfo;
         state = CONTEXT_STATE.WORKING;
         this.myManager = myManager;
+        this.hashedWheelTimer = hashedWheelTimer;
     }
 
     @Nullable
     @Override
     public <T> RequestContext<T> createRequestContext() {
-        return new AbstractRequestContext<T>(conductor.reserveXidForDeviceMessage(getDeviceInfo())) {
+        return new AbstractRequestContext<T>(deviceInfo.reserveXidForDeviceMessage()) {
             @Override
             public void close() {
             }
@@ -143,7 +143,7 @@ class RoleContextImpl implements RoleContext {
                     setRoleOutputFuture.cancel(true);
                 }
             };
-            conductor.newTimeout(timerTask, 10, TimeUnit.SECONDS);
+            hashedWheelTimer.newTimeout(timerTask, 10, TimeUnit.SECONDS);
         }
         return JdkFutureAdapters.listenInPoolThread(setRoleOutputFuture);
     }
index 5613358ed7bf1fd68c6bcd14a1b8e20960f125a5..fbebd1d41f9f04ebb87a4f6d64b2ebb142671ce0 100644 (file)
@@ -14,10 +14,8 @@ import com.google.common.collect.Iterators;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import java.util.ArrayList;
+import io.netty.util.HashedWheelTimer;
 import java.util.Iterator;
-import java.util.List;
-import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import javax.annotation.CheckForNull;
@@ -31,14 +29,11 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
 import org.opendaylight.openflowplugin.impl.services.SalRoleServiceImpl;
 import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -58,13 +53,11 @@ public class RoleManagerImpl implements RoleManager {
     private DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
     private final DataBroker dataBroker;
     private final ConcurrentMap<DeviceInfo, RoleContext> contexts = new ConcurrentHashMap<>();
-    private List<RoleChangeListener> listeners = new ArrayList<>();
+    private final HashedWheelTimer hashedWheelTimer;
 
-    private final LifecycleConductor conductor;
-
-    public RoleManagerImpl(final DataBroker dataBroker, final LifecycleConductor lifecycleConductor) {
+    public RoleManagerImpl(final DataBroker dataBroker, final HashedWheelTimer hashedWheelTimer) {
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
-        this.conductor = lifecycleConductor;
+        this.hashedWheelTimer = hashedWheelTimer;
     }
 
     @Override
@@ -74,8 +67,8 @@ public class RoleManagerImpl implements RoleManager {
 
     @Override
     public void onDeviceContextLevelUp(@CheckForNull final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
-        final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
-        final RoleContext roleContext = new RoleContextImpl(deviceInfo, conductor, this);
+        final DeviceContext deviceContext = Preconditions.checkNotNull(lifecycleService.getDeviceContext());
+        final RoleContext roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, this);
         roleContext.setSalRoleService(new SalRoleServiceImpl(roleContext, deviceContext));
         Verify.verify(contexts.putIfAbsent(deviceInfo, roleContext) == null, "Role context for master Node %s is still not closed.", deviceInfo.getNodeId());
         lifecycleService.setRoleContext(roleContext);
index 66d59cc734610a327b9f16f8d8fb55562b3b4aa0..fa3c643074a00fb42ee8041e6705ad5fe758dda4 100644 (file)
@@ -44,7 +44,6 @@ class RpcContextImpl implements RpcContext {
     private final RpcProviderRegistry rpcProviderRegistry;
     private final MessageSpy messageSpy;
     private final Semaphore tracker;
-    private final XidSequencer xidSequencer;
     private boolean isStatisticsRpcEnabled;
 
     // TODO: add private Sal salBroker
@@ -59,7 +58,6 @@ class RpcContextImpl implements RpcContext {
 
     RpcContextImpl(final DeviceInfo deviceInfo,
                    final RpcProviderRegistry rpcProviderRegistry,
-                   final XidSequencer xidSequencer,
                    final MessageSpy messageSpy,
                    final int maxRequests,
                    final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier,
@@ -67,7 +65,6 @@ class RpcContextImpl implements RpcContext {
                    final ExtensionConverterProvider extensionConverterProvider,
                    final ConvertorExecutor convertorExecutor,
                    final NotificationPublishService notificationPublishService) {
-        this.xidSequencer = Preconditions.checkNotNull(xidSequencer);
         this.messageSpy = Preconditions.checkNotNull(messageSpy);
         this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry);
         this.nodeInstanceIdentifier = nodeInstanceIdentifier;
@@ -137,7 +134,7 @@ class RpcContextImpl implements RpcContext {
             LOG.trace("Acquired semaphore for {}, available permits:{} ", nodeInstanceIdentifier.getKey().getId(), tracker.availablePermits());
         }
 
-        final Long xid = xidSequencer.reserveXidForDeviceMessage();
+        final Long xid = deviceInfo.reserveXidForDeviceMessage();
         if (xid == null) {
             LOG.warn("Xid cannot be reserved for new RequestContext, node:{}", nodeInstanceIdentifier.getKey().getId());
             tracker.release();
index 6762d9e6b3bdfcab79361273f3e5e6437fc4c34e..4d41dc59b94e61965a507c7a56a5d41e44eff463 100644 (file)
@@ -21,7 +21,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
@@ -40,23 +39,19 @@ public class RpcManagerImpl implements RpcManager {
     private final ConcurrentMap<DeviceInfo, RpcContext> contexts = new ConcurrentHashMap<>();
     private boolean isStatisticsRpcEnabled;
     private final ExtensionConverterProvider extensionConverterProvider;
+    private final ConvertorExecutor convertorExecutor;
     private final NotificationPublishService notificationPublishService;
 
-    private final LifecycleConductor conductor;
-    private final ConvertorExecutor convertorExecutor;
 
     public RpcManagerImpl(
             final RpcProviderRegistry rpcProviderRegistry,
             final int quotaValue,
-            
-            final LifecycleConductor lifecycleConductor,
             final ExtensionConverterProvider extensionConverterProvider,
                final ConvertorExecutor convertorExecutor,
             final NotificationPublishService notificationPublishService) {
         this.rpcProviderRegistry = rpcProviderRegistry;
         maxRequestsQuota = quotaValue;
         this.extensionConverterProvider = extensionConverterProvider;
-        this.conductor = lifecycleConductor;
         this.convertorExecutor = convertorExecutor;
         this.notificationPublishService = notificationPublishService;
     }
@@ -69,12 +64,11 @@ public class RpcManagerImpl implements RpcManager {
     @Override
     public void onDeviceContextLevelUp(final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
 
-        final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
+        final DeviceContext deviceContext = Preconditions.checkNotNull(lifecycleService.getDeviceContext());
 
         final RpcContext rpcContext = new RpcContextImpl(
                 deviceInfo,
                 rpcProviderRegistry,
-                deviceContext,
                 deviceContext.getMessageSpy(),
                 maxRequestsQuota,
                 deviceInfo.getNodeInstanceIdentifier(),
index c00a45fbca5523a7e684db47a45c6fe85e83f409..bf31c1a65491463e81f053bb75730cc2575ec69f 100644 (file)
@@ -33,7 +33,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.rpc.listener.ItemLifecycleListener;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
@@ -68,16 +68,18 @@ class StatisticsContextImpl implements StatisticsContext {
     private Timeout pollTimeout;
     private final DeviceInfo deviceInfo;
     private final StatisticsManager myManager;
+    private final LifecycleService lifecycleService;
 
     private volatile boolean schedulingEnabled;
     private volatile CONTEXT_STATE state;
 
     StatisticsContextImpl(@Nonnull final DeviceInfo deviceInfo,
-                          @Nonnull final boolean shuttingDownStatisticsPolling,
-                          @Nonnull final LifecycleConductor lifecycleConductor,
+                          final boolean shuttingDownStatisticsPolling,
+                          @Nonnull final LifecycleService lifecycleService,
                          @Nonnull final ConvertorExecutor convertorExecutor,
-                         @Nonnull final StatisticsManager myManager) {
-        this.deviceContext = Preconditions.checkNotNull(lifecycleConductor.getDeviceContext(deviceInfo));
+                          @Nonnull final StatisticsManager myManager) {
+        this.lifecycleService = lifecycleService;
+        this.deviceContext = lifecycleService.getDeviceContext();
         this.devState = Preconditions.checkNotNull(deviceContext.getDeviceState());
         this.shuttingDownStatisticsPolling = shuttingDownStatisticsPolling;
         multipartReplyTranslator = new SinglePurposeMultipartReplyTranslator(convertorExecutor);
@@ -190,7 +192,7 @@ class StatisticsContextImpl implements StatisticsContext {
 
     @Override
     public <T> RequestContext<T> createRequestContext() {
-        final AbstractRequestContext<T> ret = new AbstractRequestContext<T>(deviceContext.reserveXidForDeviceMessage()) {
+        final AbstractRequestContext<T> ret = new AbstractRequestContext<T>(deviceInfo.reserveXidForDeviceMessage()) {
             @Override
             public void close() {
                 requestContexts.remove(this);
@@ -425,4 +427,9 @@ class StatisticsContextImpl implements StatisticsContext {
         myManager.stopScheduling(deviceInfo);
         return Futures.immediateFuture(null);
     }
+
+    @Override
+    public LifecycleService getLifecycleService() {
+        return lifecycleService;
+    }
 }
index bbc1707214ba1c9063023eb79228c9f96fa67a4a..68cee5bde57fa715a7d50e9c2a8fdbfa3f8c29bb 100644 (file)
@@ -15,6 +15,7 @@ import com.google.common.collect.Iterators;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import io.netty.util.HashedWheelTimer;
 import io.netty.util.Timeout;
 import io.netty.util.TimerTask;
 import java.util.Iterator;
@@ -30,11 +31,11 @@ import javax.annotation.Nonnull;
 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
 import org.opendaylight.openflowplugin.api.openflow.OFPContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
@@ -72,7 +73,7 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
     private boolean isStatisticsPollingEnabled;
     private BindingAwareBroker.RpcRegistration<StatisticsManagerControlService> controlServiceRegistration;
 
-    private final LifecycleConductor conductor;
+    private final HashedWheelTimer hashedWheelTimer;
 
     @Override
     public void setDeviceInitializationPhaseHandler(final DeviceInitializationPhaseHandler handler) {
@@ -81,20 +82,20 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
 
     public StatisticsManagerImpl(final RpcProviderRegistry rpcProviderRegistry,
                                  final boolean isStatisticsPollingEnabled,
-                                 final LifecycleConductor lifecycleConductor,
-                                final ConvertorExecutor convertorExecutor) {
+                                 final HashedWheelTimer hashedWheelTimer,
+                                 final ConvertorExecutor convertorExecutor) {
         Preconditions.checkArgument(rpcProviderRegistry != null);
        this.convertorExecutor = convertorExecutor;
         this.controlServiceRegistration = Preconditions.checkNotNull(rpcProviderRegistry.addRpcImplementation(
                 StatisticsManagerControlService.class, this));
         this.isStatisticsPollingEnabled = isStatisticsPollingEnabled;
-        this.conductor = lifecycleConductor;
+        this.hashedWheelTimer = hashedWheelTimer;
     }
 
     @Override
     public void onDeviceContextLevelUp(final DeviceInfo deviceInfo, final LifecycleService lifecycleService) throws Exception {
 
-        final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, isStatisticsPollingEnabled, conductor, convertorExecutor, this);
+        final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, isStatisticsPollingEnabled, lifecycleService, convertorExecutor, this);
         Verify.verify(contexts.putIfAbsent(deviceInfo, statisticsContext) == null, "StatisticsCtx still not closed for Node {}", deviceInfo.getNodeId());
         lifecycleService.setStatContext(statisticsContext);
         deviceInitPhaseHandler.onDeviceContextLevelUp(deviceInfo, lifecycleService);
@@ -130,7 +131,7 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
                 calculateTimerDelay(timeCounter);
                 if (throwable instanceof CancellationException) {
                     /* This often happens when something wrong with akka or DS, so closing connection will help to restart device **/
-                    conductor.closeConnection(deviceInfo);
+                    contexts.get(deviceInfo).getLifecycleService().closeConnection();
                 } else {
                     scheduleNextPolling(deviceState, deviceInfo, statisticsContext, timeCounter);
                 }
@@ -146,7 +147,7 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
             }
         };
 
-        conductor.newTimeout(timerTask, STATS_TIMEOUT_SEC, TimeUnit.SECONDS);
+        hashedWheelTimer.newTimeout(timerTask, STATS_TIMEOUT_SEC, TimeUnit.SECONDS);
     }
 
     private void scheduleNextPolling(final DeviceState deviceState,
@@ -155,7 +156,14 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
                                      final TimeCounter timeCounter) {
         LOG.debug("SCHEDULING NEXT STATISTICS POLLING for device: {}", deviceInfo.getNodeId());
         if (!isStatisticsPollingEnabled) {
-            final Timeout pollTimeout = conductor.newTimeout(timeout -> pollStatistics(deviceState, statisticsContext, timeCounter, deviceInfo), currentTimerDelay, TimeUnit.MILLISECONDS);
+            final Timeout pollTimeout = hashedWheelTimer.newTimeout(
+                    timeout -> pollStatistics(
+                            deviceState,
+                            statisticsContext,
+                            timeCounter,
+                            deviceInfo),
+                    currentTimerDelay,
+                    TimeUnit.MILLISECONDS);
             statisticsContext.setPollTimeout(pollTimeout);
         }
     }
@@ -209,20 +217,23 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
                 isStatisticsPollingEnabled = StatisticsWorkMode.FULLYDISABLED.equals(targetWorkMode);
                 // iterate through stats-ctx: propagate mode
                 for (Map.Entry<DeviceInfo, StatisticsContext> entry : contexts.entrySet()) {
+                    final DeviceInfo deviceInfo = entry.getKey();
+                    final StatisticsContext statisticsContext = entry.getValue();
+                    final DeviceContext deviceContext = statisticsContext.getLifecycleService().getDeviceContext();
                     switch (targetWorkMode) {
                         case COLLECTALL:
-                            scheduleNextPolling(conductor.getDeviceContext(entry.getKey()).getDeviceState(), entry.getKey(), entry.getValue(), new TimeCounter());
-                            for (final ItemLifeCycleSource lifeCycleSource : conductor.getDeviceContext(entry.getKey()).getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
+                            scheduleNextPolling(deviceContext.getDeviceState(), deviceInfo, statisticsContext, new TimeCounter());
+                            for (final ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
                                 lifeCycleSource.setItemLifecycleListener(null);
                             }
                             break;
                         case FULLYDISABLED:
-                            final Optional<Timeout> pollTimeout = entry.getValue().getPollTimeout();
+                            final Optional<Timeout> pollTimeout = statisticsContext.getPollTimeout();
                             if (pollTimeout.isPresent()) {
                                 pollTimeout.get().cancel();
                             }
-                            for (final ItemLifeCycleSource lifeCycleSource : conductor.getDeviceContext(entry.getKey()).getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
-                                lifeCycleSource.setItemLifecycleListener(entry.getValue().getItemLifeCycleListener());
+                            for (final ItemLifeCycleSource lifeCycleSource : deviceContext.getItemLifeCycleSourceRegistry().getLifeCycleSources()) {
+                                lifeCycleSource.setItemLifecycleListener(statisticsContext.getItemLifeCycleListener());
                             }
                             break;
                         default:
@@ -263,7 +274,8 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
         LOG.info("Scheduling statistics poll for device: {}", deviceInfo.getNodeId());
 
         statisticsContext.setSchedulingEnabled(true);
-        scheduleNextPolling(conductor.getDeviceContext(deviceInfo).getDeviceState(), deviceInfo, statisticsContext, new TimeCounter());
+        final DeviceState deviceState = contexts.get(deviceInfo).getLifecycleService().getDeviceContext().getDeviceState();
+        scheduleNextPolling(deviceState, deviceInfo, statisticsContext, new TimeCounter());
     }
 
     @Override
index 52feaf74fe29b3ce8330bbcc1de882234a06c44e..680e0e731a7973b5b119c1be880511aea43c9fa0 100644 (file)
@@ -434,7 +434,7 @@ public class DeviceInitializationUtils {
 
         final OutboundQueue queue = deviceContext.getPrimaryConnectionContext().getOutboundQueueProvider();
 
-        final Long reserved = deviceContext.reserveXidForDeviceMessage();
+        final Long reserved = deviceContext.getDeviceInfo().reserveXidForDeviceMessage();
         final RequestContext<List<MultipartReply>> requestContext = new AbstractRequestContext<List<MultipartReply>>(
                 reserved) {
             @Override
diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java
deleted file mode 100644 (file)
index c9ef335..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. 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;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.TimerTask;
-import java.math.BigInteger;
-import java.util.concurrent.TimeUnit;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
-import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
-import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
-import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
-import org.opendaylight.openflowplugin.impl.registry.flow.DeviceFlowRegistryImpl;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManager;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorManagerFactory;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
-
-@RunWith(MockitoJUnitRunner.class)
-public class LifecycleConductorImplTest {
-
-    private LifecycleConductorImpl lifecycleConductor;
-
-    @Mock
-    private MessageIntelligenceAgency messageIntelligenceAgency;
-    @Mock
-    private DeviceContext deviceContext;
-    @Mock
-    private DeviceManager deviceManager;
-    @Mock
-    private DeviceState deviceState;
-    @Mock
-    private ConnectionContext connectionContext;
-    @Mock
-    private FeaturesReply featuresReply;
-    @Mock
-    private TimerTask timerTask;
-    @Mock
-    private TimeUnit timeUnit;
-    @Mock
-    private HashedWheelTimer hashedWheelTimer;
-    @Mock
-    private ListenableFuture<Void> listenableFuture;
-    @Mock
-    private StatisticsManager statisticsManager;
-    @Mock
-    private RpcManager rpcManager;
-    @Mock
-    private RpcContext rpcContext;
-    @Mock
-    private DeviceInfo deviceInfo;
-
-    private NodeId nodeId = new NodeId("openflow-junit:1");
-    private OfpRole ofpRole = OfpRole.NOCHANGE;
-    private KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
-
-    @Before
-    public void setUp() {
-        nodeInstanceIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
-        final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
-
-        lifecycleConductor = new LifecycleConductorImpl(messageIntelligenceAgency, convertorManager);
-        lifecycleConductor.setSafelyManager(deviceManager);
-        lifecycleConductor.setSafelyManager(statisticsManager);
-        lifecycleConductor.setSafelyManager(rpcManager);
-
-        when(deviceManager.gainContext(Mockito.any())).thenReturn(deviceContext);
-        when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
-        when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
-        when(rpcManager.gainContext(Mockito.any())).thenReturn(rpcContext);
-        when(deviceInfo.getNodeId()).thenReturn(nodeId);
-        when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
-        when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
-        when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
-    }
-
-    /**
-     * If getDeviceContext return null then null should be returned
-     */
-    @Test
-    public void gainConnectionStateSafelyTest1() {
-        when(deviceManager.gainContext(deviceInfo)).thenReturn(null);
-        assertNull(lifecycleConductor.gainConnectionStateSafely(deviceInfo));
-    }
-
-    /**
-     * If getDeviceContext return deviceContext then getPrimaryConnectionContext should be called
-     */
-    @Test
-    public void gainConnectionStateSafelyTest2() {
-        lifecycleConductor.gainConnectionStateSafely(deviceInfo);
-        verify(deviceContext,times(1)).getPrimaryConnectionContext();
-    }
-
-    /**
-     * If getDeviceContext returns null then null should be returned
-     */
-    @Test
-    public void reserveXidForDeviceMessageTest1() {
-        when(deviceManager.gainContext(deviceInfo)).thenReturn(null);
-        assertNull(lifecycleConductor.reserveXidForDeviceMessage(deviceInfo));
-    }
-
-    /**
-     * If getDeviceContext returns deviceContext reserveXidForDeviceMessage() should be called
-     */
-    @Test
-    public void reserveXidForDeviceMessageTest2() {
-        lifecycleConductor.reserveXidForDeviceMessage(deviceInfo);
-        verify(deviceContext,times(1)).reserveXidForDeviceMessage();
-    }
-
-    /**
-     * When succes flag is set to FALSE connection should be closed
-     */
-    @Test
-    public void deviceStartInitializationDoneTest() {
-        lifecycleConductor.deviceStartInitializationDone(deviceInfo, false);
-        verify(deviceContext,times(1)).shutdownConnection();
-    }
-
-    /**
-     * When succes flag is set to FALSE connection should be closed
-     */
-    @Test
-    public void deviceInitializationDoneTest() {
-        lifecycleConductor.deviceInitializationDone(deviceInfo, false);
-        verify(deviceContext,times(1)).shutdownConnection();
-    }
-}
index ee0efbd500237c180459d8aad2808b7543bfe85a..dc619d61fc0f707f2422d9a200b2b81b9bfc1216 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.openflowplugin.impl;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
@@ -89,7 +88,6 @@ public class OpenFlowPluginProviderImplTest {
         provider.setDataBroker(dataBroker);
         provider.setRpcProviderRegistry(rpcProviderRegistry);
         provider.setNotificationProviderService(notificationService);
-        provider.setEntityOwnershipService(entityOwnershipService);
         provider.setSwitchConnectionProviders(Lists.newArrayList(switchConnectionProvider));
         provider.setClusteringSingletonServicesProvider(clusterSingletonServiceProvider);
     }
index 9498beeda74935ccda14dc15f7ffd3d0b2478754..9da0d86795f90097dba9880680fb7e80bb736697 100644 (file)
@@ -59,7 +59,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor;
@@ -153,8 +153,6 @@ public class DeviceContextImplTest {
     @Mock
     HashedWheelTimer timer;
     @Mock
-    MessageIntelligenceAgency messageIntelligenceAgency;
-    @Mock
     OutboundQueueProvider outboundQueueProvider;
     @Mock
     ConnectionAdapter connectionAdapter;
@@ -171,13 +169,14 @@ public class DeviceContextImplTest {
     @Mock
     private MessageTranslator<Object, Object> messageTranslatorFlowRemoved;
     @Mock
-    private LifecycleConductor lifecycleConductor;
-    @Mock
     private DeviceInfo deviceInfo;
     @Mock
     private DeviceManager deviceManager;
     @Mock
     private ConvertorExecutor convertorExecutor;
+    private LifecycleService lifecycleService;
+    @Mock
+    private MessageSpy messageSpy;
 
     private InOrder inOrderDevState;
 
@@ -226,13 +225,11 @@ public class DeviceContextImplTest {
         Mockito.when(translatorLibrary.lookupTranslator(eq(new TranslatorKey(OFConstants.OFP_VERSION_1_3,
                 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved.class.getName()))))
                 .thenReturn(messageTranslatorFlowRemoved);
-        Mockito.when(lifecycleConductor.getMessageIntelligenceAgency()).thenReturn(messageIntelligenceAgency);
 
         deviceContext = new DeviceContextImpl(
                 connectionContext,
                 dataBroker,
-                lifecycleConductor,
-                outboundQueueProvider,
+                messageSpy,
                 translatorLibrary,
                        deviceManager,
                 convertorExecutor);
@@ -246,14 +243,12 @@ public class DeviceContextImplTest {
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullDataBroker() throws Exception {
-        new DeviceContextImpl(connectionContext, null, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, convertorExecutor).close();
-
+        new DeviceContextImpl(connectionContext, null, null, translatorLibrary, deviceManager, convertorExecutor).close();
     }
 
     @Test(expected = NullPointerException.class)
     public void testDeviceContextImplConstructorNullTimer() throws Exception {
-
-        new DeviceContextImpl(null, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, convertorExecutor).close();
+        new DeviceContextImpl(null, dataBroker, null, translatorLibrary, deviceManager,convertorExecutor).close();
     }
 
     @Test
@@ -273,16 +268,10 @@ public class DeviceContextImplTest {
         ((DeviceContextImpl) deviceContext).getTransactionChainManager().activateTransactionManager() ;
         ((DeviceContextImpl) deviceContext).getTransactionChainManager().enableSubmit();
         deviceContext.addDeleteToTxChain(LogicalDatastoreType.CONFIGURATION, dummyII);
-        ((DeviceContextImpl) deviceContext).initialSubmitTransaction();
+        deviceContext.initialSubmitTransaction();
         verify(wTx).submit();
     }
 
-    @Test
-    public void testGetReservedXid() {
-        deviceContext.reserveXidForDeviceMessage();
-        verify(outboundQueueProvider).reserveEntry();
-    }
-
     @Test
     public void testAuxiliaryConnectionContext() {
         final ConnectionContext mockedConnectionContext = addDummyAuxiliaryConnectionContext();
@@ -365,10 +354,10 @@ public class DeviceContextImplTest {
     public void testProcessReply() {
         final Error mockedError = mock(Error.class);
         deviceContext.processReply(mockedError);
-        verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
+        verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
         final OfHeader mockedOfHeader = mock(OfHeader.class);
         deviceContext.processReply(mockedOfHeader);
-        verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
+        verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
     }
 
     @Test
@@ -376,7 +365,7 @@ public class DeviceContextImplTest {
         final MultipartReply mockedMultipartReply = mock(MultipartReply.class);
         final Xid dummyXid = new Xid(DUMMY_XID);
         deviceContext.processReply(dummyXid, Lists.newArrayList(mockedMultipartReply));
-        verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
+        verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE));
     }
 
     @Test
@@ -388,7 +377,7 @@ public class DeviceContextImplTest {
         when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(stringListenableFuture);
         deviceContext.setNotificationPublishService(mockedNotificationPublishService);
         deviceContext.processPacketInMessage(mockedPacketInMessage);
-        verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
+        verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS));
     }
 
     @Test
@@ -400,7 +389,7 @@ public class DeviceContextImplTest {
         when(mockedNotificationPublishService.offerNotification(any(PacketReceived.class))).thenReturn(dummyFuture);
         deviceContext.setNotificationPublishService(mockedNotificationPublishService);
         deviceContext.processPacketInMessage(mockedPacketInMessage);
-        verify(messageIntelligenceAgency).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED));
+        verify(messageSpy).spyMessage(any(Class.class), eq(MessageSpy.STATISTIC_GROUP.FROM_SWITCH_NOTIFICATION_REJECTED));
     }
 
     @Test
@@ -436,7 +425,7 @@ public class DeviceContextImplTest {
     @Test
     public void testGetMessageSpy() {
         final MessageSpy pickedMessageSpy = deviceContext.getMessageSpy();
-        assertEquals(messageIntelligenceAgency, pickedMessageSpy);
+        assertEquals(messageSpy, pickedMessageSpy);
     }
 
     @Test
index 702a5f6ca54848706f0c2249b0e1c30337be3b09..cef89f4e45091c8e4b60bc3185626ffb422b946a 100644 (file)
@@ -18,12 +18,11 @@ import static org.mockito.Mockito.when;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
-import io.netty.util.TimerTask;
+import io.netty.util.HashedWheelTimer;
 import java.lang.reflect.Field;
 import java.math.BigInteger;
 import java.util.Collections;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -40,7 +39,6 @@ import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
@@ -51,12 +49,12 @@ import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext
 import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProvider;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageIntelligenceAgency;
@@ -101,8 +99,6 @@ public class DeviceManagerImplTest {
     @Mock
     private NodeId mockedNodeId;
     @Mock
-    private LifecycleConductor lifecycleConductor;
-    @Mock
     private MessageIntelligenceAgency messageIntelligenceAgency;
     @Mock
     private DeviceInfo deviceInfo;
@@ -129,8 +125,6 @@ public class DeviceManagerImplTest {
         when(mockFeatures.getCapabilities()).thenReturn(capabilitiesV13);
         when(mockFeatures.getCapabilitiesV10()).thenReturn(capabilitiesV10);
         when(mockFeatures.getDatapathId()).thenReturn(BigInteger.valueOf(21L));
-
-        when(lifecycleConductor.getMessageIntelligenceAgency()).thenReturn(messageIntelligenceAgency);
     }
 
     @Test
@@ -139,10 +133,6 @@ public class DeviceManagerImplTest {
     }
 
     private DeviceManagerImpl prepareDeviceManager() {
-        return prepareDeviceManager(false);
-    }
-
-    private DeviceManagerImpl prepareDeviceManager(final boolean withException) {
         final DataBroker mockedDataBroker = mock(DataBroker.class);
         final WriteTransaction mockedWriteTransaction = mock(WriteTransaction.class);
 
@@ -161,10 +151,12 @@ public class DeviceManagerImplTest {
                 false,
                 barrierIntervalNanos,
                 barrierCountLimit,
-                lifecycleConductor,
+                messageIntelligenceAgency,
                 true,
-                convertorExecutor,
-                clusterSingletonServiceProvider);
+                clusterSingletonServiceProvider,
+                null,
+                new HashedWheelTimer(),
+                convertorExecutor);
 
         deviceManager.setDeviceInitializationPhaseHandler(deviceInitPhaseHandler);
         deviceManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
@@ -173,7 +165,7 @@ public class DeviceManagerImplTest {
     }
 
     public void onDeviceContextLevelUp(final boolean withException) throws Exception {
-        final DeviceManagerImpl deviceManager = prepareDeviceManager(withException);
+        final DeviceManagerImpl deviceManager = prepareDeviceManager();
         final DeviceState mockedDeviceState = mock(DeviceState.class);
         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
 
@@ -246,8 +238,6 @@ public class DeviceManagerImplTest {
         deviceContexts.put(deviceInfo, deviceContext);
 
         deviceManager.onDeviceDisconnected(connectionContext);
-
-        verify(lifecycleConductor).newTimeout(Mockito.<TimerTask>any(), Mockito.anyLong(), Mockito.<TimeUnit>any());
     }
 
     protected ConnectionContext buildMockConnectionContext(final short ofpVersion) {
index 68c07e23539f6a3931ab5ac3f7780cc63ad1100b..ef3d969b12b0200029368eb68be6d1bed167ca23 100644 (file)
@@ -33,7 +33,7 @@ import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFaile
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
@@ -69,7 +69,7 @@ public class TransactionChainManagerTest {
     @Mock
     DeviceInfo deviceInfo;
     @Mock
-    LifecycleConductor conductor;
+    LifecycleService lifecycleService;
 
     @Mock
     private KeyedInstanceIdentifier<Node, NodeKey> nodeKeyIdent;
@@ -90,7 +90,7 @@ public class TransactionChainManagerTest {
         nodeKeyIdent = DeviceStateUtil.createNodeInstanceIdentifier(nodeId);
         Mockito.when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeKeyIdent);
         Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
-        txChainManager = new TransactionChainManager(dataBroker, deviceInfo, conductor);
+        txChainManager = new TransactionChainManager(dataBroker, deviceInfo);
         Mockito.when(txChain.newWriteOnlyTransaction()).thenReturn(writeTx);
 
         path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
index ca0ffb6d193c0ae9a57b681a602d66f8f887df87..c45a9d50880b5eee2f64c0e15c3e74bb1e014691 100644 (file)
@@ -8,21 +8,16 @@
 package org.opendaylight.openflowplugin.impl.role;
 
 
+import io.netty.util.HashedWheelTimer;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
-import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleManager;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
@@ -35,7 +30,7 @@ public class RoleContextImplTest {
     private static final Logger LOG = LoggerFactory.getLogger(RoleContextImpl.class);
 
     @Mock
-    private LifecycleConductor conductor;
+    HashedWheelTimer hashedWheelTimer;
     @Mock
     private DeviceInfo deviceInfo;
     @Mock
@@ -46,14 +41,14 @@ public class RoleContextImplTest {
 
     @Before
     public void setup() throws CandidateAlreadyRegisteredException {
-        roleContext = new RoleContextImpl(deviceInfo, conductor, roleManager);
+        roleContext = new RoleContextImpl(deviceInfo, hashedWheelTimer, roleManager);
         Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
     }
 
     @Test
     public void testCreateRequestContext() throws Exception {
         roleContext.createRequestContext();
-        Mockito.verify(conductor).reserveXidForDeviceMessage(deviceInfo);
+        Mockito.verify(deviceInfo).reserveXidForDeviceMessage();
     }
 
     @Test(expected = NullPointerException.class)
index 5017e196aad4682d3ac853c466220d17a72879bf..adec48770bcec9218613cab03b0adc2bb5f598c6 100644 (file)
@@ -9,15 +9,14 @@
 package org.opendaylight.openflowplugin.impl.role;
 
 
-import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 
 import com.google.common.base.VerifyException;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
+import io.netty.util.HashedWheelTimer;
 import java.math.BigInteger;
 import org.junit.After;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -27,12 +26,6 @@ import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
-import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowplugin.api.OFConstants;
@@ -43,76 +36,44 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
 import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
 
 @RunWith(MockitoJUnitRunner.class)
 public class RoleManagerImplTest {
 
-    @Mock
-    EntityOwnershipService entityOwnershipService;
-
     @Mock
     DataBroker dataBroker;
-
     @Mock
     DeviceContext deviceContext;
-
     @Mock
     DeviceManager deviceManager;
-
-    @Mock
-    EntityOwnershipListener entityOwnershipListener;
-
-    @Mock
-    EntityOwnershipListenerRegistration entityOwnershipListenerRegistration;
-
-    @Mock
-    EntityOwnershipCandidateRegistration entityOwnershipCandidateRegistration;
-
     @Mock
     ConnectionContext connectionContext;
-
     @Mock
     FeaturesReply featuresReply;
-
     @Mock
     DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
-
     @Mock
     DeviceTerminationPhaseHandler deviceTerminationPhaseHandler;
-
     @Mock
     WriteTransaction writeTransaction;
-
-    @Mock
-    LifecycleConductor conductor;
-
     @Mock
     DeviceState deviceState;
-
     @Mock
     DeviceInfo deviceInfo;
-
     @Mock
     DeviceInfo deviceInfo2;
-
     @Mock
     MessageSpy messageSpy;
-
     @Mock
     OutboundQueue outboundQueue;
-
     @Mock
     GetFeaturesOutput featuresOutput;
-
     @Mock
     LifecycleService lifecycleService;
 
@@ -127,8 +88,6 @@ public class RoleManagerImplTest {
     @Before
     public void setUp() throws Exception {
         CheckedFuture<Void, TransactionCommitFailedException> future = Futures.immediateCheckedFuture(null);
-        Mockito.when(entityOwnershipService.registerListener(Mockito.anyString(), Mockito.any(EntityOwnershipListener.class))).thenReturn(entityOwnershipListenerRegistration);
-        Mockito.when(entityOwnershipService.registerCandidate(Mockito.any(Entity.class))).thenReturn(entityOwnershipCandidateRegistration);
         Mockito.when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
         Mockito.when(deviceContext.getDeviceState()).thenReturn(deviceState);
         Mockito.when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
@@ -147,16 +106,16 @@ public class RoleManagerImplTest {
         Mockito.when(deviceInfo.getNodeId()).thenReturn(nodeId);
         Mockito.when(deviceInfo2.getNodeId()).thenReturn(nodeId2);
         Mockito.when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
-        roleManager = new RoleManagerImpl(dataBroker, conductor);
+        Mockito.when(lifecycleService.getDeviceContext()).thenReturn(deviceContext);
+        roleManager = new RoleManagerImpl(dataBroker, new HashedWheelTimer());
         roleManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
         roleManager.setDeviceTerminationPhaseHandler(deviceTerminationPhaseHandler);
-        Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
         roleManagerSpy = Mockito.spy(roleManager);
         roleManagerSpy.onDeviceContextLevelUp(deviceInfo, lifecycleService);
         roleContextSpy = Mockito.spy(roleManager.getRoleContext(deviceInfo));
         Mockito.when(roleContextSpy.getDeviceInfo()).thenReturn(deviceInfo);
         Mockito.when(roleContextSpy.getDeviceInfo().getNodeId()).thenReturn(nodeId);
-        inOrder = Mockito.inOrder(entityOwnershipListenerRegistration, roleManagerSpy, roleContextSpy);
+        inOrder = Mockito.inOrder(roleManagerSpy, roleContextSpy);
     }
 
     @After
index a1ba78f65795c47008c7e234944214b4b33f6fbe..4344cc01e6bd3aabcbb3c76c15c55e7620f315cc 100644 (file)
@@ -83,7 +83,6 @@ public class RpcContextImplTest {
         rpcContext = new RpcContextImpl(
                 deviceInfo,
                 rpcProviderRegistry,
-                deviceContext,
                 messageSpy,
                 MAX_REQUESTS,
                 nodeInstanceIdentifier,
@@ -101,7 +100,6 @@ public class RpcContextImplTest {
         try (final RpcContext rpcContext = new RpcContextImpl(
                 deviceInfo,
                 rpcProviderRegistry,
-                xidSequencer,
                 messageSpy,
                 100,
                 nodeInstanceIdentifier,
@@ -119,7 +117,6 @@ public class RpcContextImplTest {
         try (final RpcContext rpcContext = new RpcContextImpl(
                 deviceInfo,
                 rpcProviderRegistry,
-                xidSequencer,
                 messageSpy,
                 0,
                 nodeInstanceIdentifier,
@@ -137,7 +134,6 @@ public class RpcContextImplTest {
         try (final RpcContext rpcContext = new RpcContextImpl(
                 deviceInfo,
                 rpcProviderRegistry,
-                deviceContext,
                 messageSpy,
                 100,
                 nodeInstanceIdentifier,
@@ -181,7 +177,7 @@ public class RpcContextImplTest {
      */
     @Test
     public void testCreateRequestContext1() throws InterruptedException {
-        when(deviceContext.reserveXidForDeviceMessage()).thenReturn(null);
+        when(deviceInfo.reserveXidForDeviceMessage()).thenReturn(null);
         assertEquals(rpcContext.createRequestContext(),null);
     }
 
index 9070688d2cb77147a14bd146b5be634d8f231f35..f3c6dabb6bd429ae0467c1a152b0f1d713fd4f9c 100644 (file)
@@ -33,7 +33,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
@@ -71,8 +70,6 @@ public class RpcManagerImplTest {
     @Mock
     private MessageSpy mockMsgSpy;
     @Mock
-    private LifecycleConductor conductor;
-    @Mock
     private ConnectionContext connectionContext;
     @Mock
     private ItemLifeCycleRegistry itemLifeCycleRegistry;
@@ -103,7 +100,7 @@ public class RpcManagerImplTest {
     @Before
     public void setUp() {
         final NodeKey nodeKey = new NodeKey(nodeId);
-        rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, conductor, extensionConverterProvider, convertorExecutor, notificationPublishService);
+        rpcManager = new RpcManagerImpl(rpcProviderRegistry, QUOTA_VALUE, extensionConverterProvider, convertorExecutor, notificationPublishService);
         rpcManager.setDeviceInitializationPhaseHandler(deviceINitializationPhaseHandler);
 
         GetFeaturesOutput featuresOutput = new GetFeaturesOutputBuilder()
@@ -128,14 +125,8 @@ public class RpcManagerImplTest {
         Mockito.when(rpcProviderRegistry.addRoutedRpcImplementation(
                 Matchers.<Class<RpcService>>any(), Matchers.any(RpcService.class)))
                 .thenReturn(routedRpcRegistration);
-        Mockito.when(conductor.getDeviceContext(deviceInfo)).thenReturn(deviceContext);
         Mockito.when(contexts.remove(deviceInfo)).thenReturn(removedContexts);
-    }
-
-    @Test
-    public void onDeviceContextLevelUp() throws Exception {
-        rpcManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
-        verify(conductor).getDeviceContext(deviceInfo);
+        Mockito.when(lifecycleService.getDeviceContext()).thenReturn(deviceContext);
     }
 
     @Test
index 4a0ad6c1cde42dcd53f3a30bc711fd7af9996734..55b18f5600f7d8cbd508bfd3a132ea0ac7331f58 100644 (file)
@@ -19,7 +19,7 @@ import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceManager;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceState;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsManager;
 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.MessageSpy;
 import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringOnTheFlyService;
@@ -49,12 +49,11 @@ class StatisticsContextImpMockInitiation {
     ConnectionContext mockedConnectionContext;
     DeviceInfo mockedDeviceInfo;
     StatisticsManager mockedStatisticsManager;
+    LifecycleService lifecycleService;
 
     static final KeyedInstanceIdentifier<Node, NodeKey> dummyNodeII = InstanceIdentifier.create(Nodes.class)
             .child(Node.class, new NodeKey(new NodeId("dummyNodeId")));
 
-    LifecycleConductor mockConductor;
-
     @Before
     public void initialize() {
         mockedDeviceContext = mock(DeviceContext.class);
@@ -64,14 +63,13 @@ class StatisticsContextImpMockInitiation {
         mockedDeviceState = mock(DeviceState.class);
         mockedDeviceInfo = mock(DeviceInfo.class);
         mockedStatisticsManager = mock(StatisticsManager.class);
+        lifecycleService = mock(LifecycleService.class);
 
         final FeaturesReply mockedFeatures = mock(FeaturesReply.class);
         final MessageSpy mockedMessageSpy = mock(MessageSpy.class);
         final OutboundQueue mockedOutboundQueue = mock(OutboundQueue.class);
         final DeviceManager mockedDeviceManager = mock(DeviceManager.class);
 
-        mockConductor = mock(LifecycleConductor.class);
-
         when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
         when(mockedDeviceContext.getDeviceInfo()).thenReturn(mockedDeviceInfo);
         when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedConnectionContext);
@@ -97,7 +95,5 @@ class StatisticsContextImpMockInitiation {
         when(mockedConnectionContext.getConnectionState()).thenReturn(ConnectionContext.CONNECTION_STATE.WORKING);
         when(mockedConnectionContext.getOutboundQueueProvider()).thenReturn(mockedOutboundQueue);
 
-        mockConductor.setSafelyManager(mockedDeviceManager);
-        when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
     }
 }
index 598ded051ff6a21152f396b493382d8ff3ee269c..5b7c3743505aedcdb3f7643a06d6ac7688fb176a 100644 (file)
@@ -63,9 +63,11 @@ public class StatisticsContextImplParamTest extends StatisticsContextImpMockInit
     @Test
     public void gatherDynamicDataTest() {
 
-        final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
-        final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor, convertorManager, mockedStatisticsManager);
+        when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+        when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
 
+        final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
+        final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, lifecycleService ,convertorManager, mockedStatisticsManager);
 
         final ListenableFuture<RpcResult<List<MultipartReply>>> rpcResult = immediateFuture(RpcResultBuilder.success(Collections.<MultipartReply>emptyList()).build());
         when(mockedStatisticsGatheringService.getStatisticsOfType(any(EventIdentifier.class), any(MultipartType
index 57eca24df7d6ceec00e9c1742f7b3782cf7e6345..7154e7742312d8a020eb8afb1567bd91267fd279 100644 (file)
@@ -49,13 +49,14 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio
     @Before
     public void setUp() throws Exception {
         convertorManager = ConvertorManagerFactory.createDefaultManager();
-        when(mockedDeviceContext.reserveXidForDeviceMessage()).thenReturn(TEST_XID);
-        when(mockConductor.getDeviceContext(mockedDeviceInfo)).thenReturn(mockedDeviceContext);
+        when(mockedDeviceInfo.reserveXidForDeviceMessage()).thenReturn(TEST_XID);
+        Mockito.when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+        Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
         initStatisticsContext();
     }
 
     private void initStatisticsContext() {
-        statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor, convertorManager, mockedStatisticsManager);
+        statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, lifecycleService, convertorManager, mockedStatisticsManager);
         statisticsContext.setStatisticsGatheringService(mockedStatisticsGatheringService);
         statisticsContext.setStatisticsGatheringOnTheFlyService(mockedStatisticsOnFlyGatheringService);
     }
@@ -73,7 +74,7 @@ public class StatisticsContextImplTest extends StatisticsContextImpMockInitiatio
      */
     @Test
     public void testClose() throws Exception {
-        final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, mockConductor, convertorManager, mockedStatisticsManager);
+        final StatisticsContextImpl statisticsContext = new StatisticsContextImpl(mockedDeviceInfo, false, lifecycleService, convertorManager, mockedStatisticsManager);
         final RequestContext<Object> requestContext = statisticsContext.createRequestContext();
         statisticsContext.close();
         try {
index 281ab5953ec27eacf4829c4f73e21e0556577968..ec9270f705e081f00c79c59dfd81b1b654f9f444 100644 (file)
@@ -51,7 +51,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
-import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
 import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
 import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
@@ -129,8 +128,6 @@ public class StatisticsManagerImplTest {
     @Mock
     private DeviceManager deviceManager;
     @Mock
-    private LifecycleConductor conductor;
-    @Mock
     private GetFeaturesOutput featuresOutput;
     @Mock
     private DeviceInitializationPhaseHandler deviceInitializationPhaseHandler;
@@ -188,9 +185,8 @@ public class StatisticsManagerImplTest {
                 Matchers.<StatisticsManagerControlService>any())).thenReturn(serviceControlRegistration);
 
         final ConvertorManager convertorManager = ConvertorManagerFactory.createDefaultManager();
-        statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, conductor, convertorManager);
+        statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, false, new HashedWheelTimer(), convertorManager);
         statisticsManager.setDeviceInitializationPhaseHandler(deviceInitializationPhaseHandler);
-        when(conductor.getDeviceContext(deviceInfo)).thenReturn(mockedDeviceContext);
     }
 
     @Test
@@ -207,6 +203,9 @@ public class StatisticsManagerImplTest {
         }).when(outboundQueue)
                 .commitEntry(Matchers.anyLong(), Matchers.<OfHeader>any(), Matchers.<FutureCallback<OfHeader>>any());
 
+        Mockito.when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+        Mockito.when(mockedDeviceContext.getDeviceState()).thenReturn(mockedDeviceState);
+
         statisticsManager.setDeviceInitializationPhaseHandler(mockedDevicePhaseHandler);
         statisticsManager.onDeviceContextLevelUp(deviceInfo, lifecycleService);
         verify(mockedDevicePhaseHandler).onDeviceContextLevelUp(deviceInfo, lifecycleService);
@@ -258,6 +257,9 @@ public class StatisticsManagerImplTest {
         when(itemLifeCycleRegistry.getLifeCycleSources()).thenReturn(
                 Collections.<ItemLifeCycleSource>emptyList());
 
+        when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+        when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
 
         final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
@@ -295,6 +297,9 @@ public class StatisticsManagerImplTest {
 
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
 
+        when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+        when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
         final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
                 new ChangeStatisticsWorkModeInputBuilder()
                         .setMode(StatisticsWorkMode.FULLYDISABLED);
@@ -331,6 +336,9 @@ public class StatisticsManagerImplTest {
 
         getContextsMap(statisticsManager).put(deviceInfo, statisticContext);
 
+        when(statisticContext.getLifecycleService()).thenReturn(lifecycleService);
+        when(lifecycleService.getDeviceContext()).thenReturn(mockedDeviceContext);
+
         final ChangeStatisticsWorkModeInputBuilder changeStatisticsWorkModeInputBld =
                 new ChangeStatisticsWorkModeInputBuilder()
                         .setMode(StatisticsWorkMode.FULLYDISABLED);