From: Jozef Bacigal Date: Mon, 25 Jul 2016 12:00:28 +0000 (+0200) Subject: Bug 5596 Cleaning part 1 X-Git-Tag: release/boron~21 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=d8cc382a8dbdcb7c89b68457b3ae0b6d576ee28f;p=openflowplugin.git Bug 5596 Cleaning part 1 - Device Context - Device Manager - Device State Change-Id: I85a1269f1acc17a3e09cbe1d92fb993a9be5a4da Signed-off-by: Jozef Bacigal --- diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java index 871adf3bc7..c7dca5069a 100644 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java +++ b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceContext.java @@ -13,7 +13,6 @@ import io.netty.util.Timeout; import java.math.BigInteger; import java.util.List; import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; -import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.openflowplugin.api.openflow.OFPContext; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor; @@ -51,6 +50,8 @@ public interface DeviceContext extends */ void shutdownConnection(); + void initialSubmitTransaction(); + /** * Method add auxiliary connection contexts to this context representing single device connection. * @param connectionContext new connection context @@ -130,7 +131,5 @@ public interface DeviceContext extends void setSwitchFeaturesMandatory(boolean switchFeaturesMandatory); - void registerClusterSingletonServices(ClusterSingletonServiceProvider singletonServiceProvider); - } diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceManager.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceManager.java index db07c8f8f8..3f73661fc1 100644 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceManager.java +++ b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceManager.java @@ -8,7 +8,6 @@ package org.opendaylight.openflowplugin.api.openflow.device; -import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.openflowplugin.api.openflow.OFPManager; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceConnectedHandler; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler; @@ -16,7 +15,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitia import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceLifecycleSupervisor; import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler; import org.opendaylight.openflowplugin.api.openflow.translator.TranslatorLibrarian; -import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; /** * This interface is responsible for instantiating DeviceContext and @@ -32,46 +30,6 @@ public interface DeviceManager extends DeviceConnectedHandler, DeviceDisconnecte */ void initialize(); - /** - * Method has to activate (MASTER) or deactivate (SLAVE) TransactionChainManager. - * TransactionChainManager represents possibility to write or delete Node subtree data - * for actual Controller Cluster Node. We are able to have an active TxManager only if - * newRole is {@link OfpRole#BECOMESLAVE}. - * Parameters are used as marker to be sure it is change to SLAVE from MASTER or from - * MASTER to SLAVE and the last parameter "cleanDataStore" is used for validation only. - * - * @param deviceInfo which device - * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER} - * @return RoleChangeTxChainManager future for activation/deactivation - */ - ListenableFuture onClusterRoleChange(final DeviceInfo deviceInfo, final OfpRole role); - - /** - * Register device synchronize listeners - * @param deviceSynchronizeListener are notified if device is synchronized or not - */ - void addDeviceSynchronizeListener(final DeviceSynchronizeListener deviceSynchronizeListener); - - /** - * Notify all registered listeners about synchronized status - * @param deviceInfo which device - * @param deviceSynchronized true if device is synchronized - */ - void notifyDeviceSynchronizeListeners(final DeviceInfo deviceInfo, final boolean deviceSynchronized); - - /** - * Register device valid listeners - * @param deviceValidListener are notified if device is valid or not - */ - void addDeviceValidListener(final DeviceValidListener deviceValidListener); - - /** - * Notify all registered listeners about valid status - * @param deviceInfo which device - * @param deviceValid true if device is valid - */ - void notifyDeviceValidListeners(final DeviceInfo deviceInfo, final boolean deviceValid); - void setIsNotificationFlowRemovedOff(boolean value); boolean getIsNotificationFlowRemovedOff(); diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceState.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceState.java index 0ca7e2df60..becc8d09cb 100644 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceState.java +++ b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceState.java @@ -11,12 +11,7 @@ package org.opendaylight.openflowplugin.api.openflow.device; /** * Holder of device's structure */ -public interface DeviceState extends DeviceSynchronizeListener, DeviceValidListener { - - /** - * @return true if this session is valid - */ - boolean isValid(); +public interface DeviceState { /** * Return true if we have relevant meter information @@ -44,13 +39,6 @@ public interface DeviceState extends DeviceSynchronizeListener, DeviceValidListe */ void setGroupAvailable(boolean available); - /** - * Method returns true if initial statistics data were collected and written to DS. - * - * @return - */ - boolean deviceSynchronized(); - /** * Method returns true, if device capabilities provides flow statistics. * @@ -89,6 +77,4 @@ public interface DeviceState extends DeviceSynchronizeListener, DeviceValidListe boolean isStatisticsPollingEnabled(); - void setStatisticsPollingEnabledProp(boolean statPollEnabled); - } diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceSynchronizeListener.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceSynchronizeListener.java deleted file mode 100644 index 6c49c524cd..0000000000 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceSynchronizeListener.java +++ /dev/null @@ -1,17 +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.api.openflow.device; - -/** - * API for device synchronized listeners - */ -public interface DeviceSynchronizeListener { - - void deviceIsSynchronized(final DeviceInfo deviceInfo, final boolean isSynchronized); - -} diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceValidListener.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceValidListener.java deleted file mode 100644 index 55153a05a1..0000000000 --- a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/DeviceValidListener.java +++ /dev/null @@ -1,17 +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.api.openflow.device; - -/** - * API for device synchronized listeners - */ -public interface DeviceValidListener { - - void deviceIsValid(final DeviceInfo deviceInfo, final boolean isValid); - -} 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 index 6cd8fcf2f5..32b2d768fa 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImpl.java @@ -144,7 +144,6 @@ final class LifecycleConductorImpl implements LifecycleConductor, RoleChangeList LOG.debug("Close connection called for node {}", deviceInfo); final DeviceContext deviceContext = getDeviceContext(deviceInfo); if (null != deviceContext) { - deviceManager.notifyDeviceValidListeners(deviceInfo, false); deviceContext.shutdownConnection(); } } @@ -164,10 +163,7 @@ final class LifecycleConductorImpl implements LifecycleConductor, RoleChangeList LOG.info("Role change to {} in role context for node {} was successful.", newRole, deviceInfo.getNodeId().getValue()); - final String logText; - if (OfpRole.BECOMEMASTER.equals(newRole)) { - logText = "Start"; fillDeviceFlowRegistry(deviceInfo, deviceContext.getDeviceFlowRegistry()); MdSalRegistrationUtils.registerServices(rpcContext, deviceContext, this.extensionConverterProvider, convertorExecutor); @@ -178,7 +174,6 @@ final class LifecycleConductorImpl implements LifecycleConductor, RoleChangeList notificationPublishService, convertorExecutor); } } else { - logText = "Stopp"; statisticsManager.stopScheduling(deviceInfo); // Clean device flow registry if we became slave @@ -189,22 +184,6 @@ final class LifecycleConductorImpl implements LifecycleConductor, RoleChangeList MdSalRegistrationUtils.unregisterServices(rpcContext); } - final ListenableFuture onClusterRoleChange = deviceManager.onClusterRoleChange(deviceInfo, newRole); - Futures.addCallback(onClusterRoleChange, new FutureCallback() { - @Override - public void onSuccess(@Nullable final Void aVoid) { - LOG.info("{}ing services for node {} was successful", logText, deviceInfo); - if (newRole.equals(OfpRole.BECOMESLAVE)) { - notifyServiceChangeListeners(deviceInfo, true); - } - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.warn("{}ing services for node {} was NOT successful, closing connection", logText, deviceInfo.getNodeId().getValue()); - closeConnection(deviceInfo); - } - }); } private void fillDeviceFlowRegistry(final DeviceInfo deviceInfo, final DeviceFlowRegistry deviceFlowRegistry) { diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java index 5d68cc981e..63f97c73af 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java @@ -25,7 +25,6 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; 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.ClusterSingletonServiceProvider; import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue; @@ -142,17 +141,17 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi private final ConvertorExecutor convertorExecutor; private volatile CONTEXT_STATE state; - public DeviceContextImpl(@Nonnull final ConnectionContext primaryConnectionContext, - @Nonnull final DeviceState deviceState, - @Nonnull final DataBroker dataBroker, - @Nonnull final LifecycleConductor conductor, - @Nonnull final OutboundQueueProvider outboundQueueProvider, - @Nonnull final TranslatorLibrary translatorLibrary, - final DeviceManager manager, - @Nonnull final DeviceInfo deviceInfo, - final ConvertorExecutor convertorExecutor) { + public DeviceContextImpl( + @Nonnull final ConnectionContext primaryConnectionContext, + @Nonnull final DataBroker dataBroker, + @Nonnull final LifecycleConductor conductor, + @Nonnull final OutboundQueueProvider outboundQueueProvider, + @Nonnull final TranslatorLibrary translatorLibrary, + @Nonnull final DeviceManager manager, + final ConvertorExecutor convertorExecutor) { this.primaryConnectionContext = Preconditions.checkNotNull(primaryConnectionContext); - this.deviceState = Preconditions.checkNotNull(deviceState); + this.deviceInfo = primaryConnectionContext.getDeviceInfo(); + this.deviceState = new DeviceStateImpl(); this.dataBroker = Preconditions.checkNotNull(dataBroker); Preconditions.checkNotNull(conductor); this.outboundQueueProvider = Preconditions.checkNotNull(outboundQueueProvider); @@ -178,7 +177,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi itemLifeCycleSourceRegistry = new ItemLifeCycleRegistryImpl(); flowLifeCycleKeeper = new ItemLifeCycleSourceImpl(); itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper); - this.deviceInfo = deviceInfo; this.state = CONTEXT_STATE.INITIALIZATION; this.convertorExecutor = convertorExecutor; } @@ -187,7 +185,8 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi * This method is called from {@link DeviceManagerImpl} only. So we could say "posthandshake process finish" * and we are able to set a scheduler for an automatic transaction submitting by time (0,5sec). */ - void initialSubmitTransaction() { + @Override + public void initialSubmitTransaction() { transactionChainManager.initialSubmitWriteTransaction(); } @@ -538,11 +537,6 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi this.switchFeaturesMandatory = switchFeaturesMandatory; } - @Override - public void registerClusterSingletonServices(ClusterSingletonServiceProvider singletonServiceProvider) { - - } - @Override public CONTEXT_STATE getState() { return this.state; diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java index 8d5b506254..3d076300a9 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java @@ -8,19 +8,15 @@ package org.opendaylight.openflowplugin.impl.device; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.base.Verify; import com.google.common.collect.Iterators; -import com.google.common.util.concurrent.AsyncFunction; 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.TimerTask; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutionException; @@ -40,15 +36,11 @@ import org.opendaylight.openflowplugin.api.openflow.connection.OutboundQueueProv 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.DeviceSynchronizeListener; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceValidListener; 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.StatisticsContext; import org.opendaylight.openflowplugin.extension.api.ExtensionConverterProviderKeeper; import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider; import org.opendaylight.openflowplugin.impl.connection.OutboundQueueProviderImpl; @@ -59,7 +51,6 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorE import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodesBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,8 +81,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi private final int barrierCountLimit; private ExtensionConverterProvider extensionConverterProvider; private ScheduledThreadPoolExecutor spyPool; - private Set deviceSynchronizedListeners; - private Set deviceValidListeners; private final ClusterSingletonServiceProvider singletonServiceProvider; private final LifecycleConductor conductor; @@ -128,8 +117,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi this.conductor = lifecycleConductor; spyPool = new ScheduledThreadPoolExecutor(1); - this.deviceSynchronizedListeners = new HashSet<>(); - this.deviceValidListeners = new HashSet<>(); this.singletonServiceProvider = singletonServiceProvider; } @@ -181,18 +168,12 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, barrierCountLimit, barrierIntervalNanos); connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration); - final DeviceState deviceState = new DeviceStateImpl(deviceInfo); - this.addDeviceSynchronizeListener(deviceState); - this.addDeviceValidListener(deviceState); - final DeviceContext deviceContext = new DeviceContextImpl(connectionContext, - deviceState, dataBroker, conductor, outboundQueueProvider, translatorLibrary, this, - connectionContext.getDeviceInfo(), convertorExecutor); final LifecycleService lifecycleService = new LifecycleServiceImpl(); @@ -210,13 +191,9 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi final OpenflowProtocolListenerFullImpl messageListener = new OpenflowProtocolListenerFullImpl( connectionAdapter, deviceContext); - connectionAdapter.setMessageListener(messageListener); - notifyDeviceValidListeners(deviceInfo, true); - - deviceInitPhaseHandler.onDeviceContextLevelUp(connectionContext.getDeviceInfo(), lifecycleServices.get(deviceInfo)); - - notifyDeviceSynchronizeListeners(deviceInfo, true); + connectionAdapter.setMessageListener(messageListener); + deviceInitPhaseHandler.onDeviceContextLevelUp(connectionContext.getDeviceInfo(), lifecycleService); return true; } @@ -251,7 +228,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi for (final Iterator iterator = Iterators.consumingIterator(deviceContexts.values().iterator()); iterator.hasNext();) { final DeviceContext deviceCtx = iterator.next(); - notifyDeviceValidListeners(deviceCtx.getDeviceInfo(), false); deviceCtx.shutdownConnection(); deviceCtx.shuttingDownDataStoreTransactions(); } @@ -310,7 +286,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi /* Connection is not PrimaryConnection so try to remove from Auxiliary Connections */ deviceCtx.removeAuxiliaryConnectionContext(connectionContext); } else { - notifyDeviceValidListeners(deviceInfo, false); /* Device is disconnected and so we need to close TxManager */ final ListenableFuture future = deviceCtx.shuttingDownDataStoreTransactions(); Futures.addCallback(future, new FutureCallback() { @@ -348,40 +323,6 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi return (T) deviceContexts.get(deviceInfo); } - @Override - public ListenableFuture onClusterRoleChange(final DeviceInfo deviceInfo, final OfpRole role) { - DeviceContext deviceContext = deviceContexts.get(deviceInfo); - LOG.trace("onClusterRoleChange {} for node:", role, deviceInfo.getNodeId()); - if (OfpRole.BECOMEMASTER.equals(role)) { - return onDeviceTakeClusterLeadership(deviceInfo); - } - return ((DeviceContextImpl)deviceContext).getTransactionChainManager().deactivateTransactionManager(); - } - - @Override - public void addDeviceSynchronizeListener(final DeviceSynchronizeListener deviceSynchronizeListener) { - this.deviceSynchronizedListeners.add(deviceSynchronizeListener); - } - - @Override - public void notifyDeviceSynchronizeListeners(final DeviceInfo deviceInfo, final boolean deviceSynchronized) { - for (DeviceSynchronizeListener listener : deviceSynchronizedListeners) { - listener.deviceIsSynchronized(deviceInfo, deviceSynchronized); - } - } - - @Override - public void addDeviceValidListener(final DeviceValidListener deviceValidListener) { - this.deviceValidListeners.add(deviceValidListener); - } - - @Override - public void notifyDeviceValidListeners(final DeviceInfo deviceInfo, final boolean deviceValid) { - for (DeviceValidListener listener : deviceValidListeners) { - listener.deviceIsValid(deviceInfo, deviceValid); - } - } - @Override public void setIsNotificationFlowRemovedOff(boolean isNotificationFlowRemovedOff) { this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff; @@ -392,62 +333,4 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi return this.isNotificationFlowRemovedOff; } - private ListenableFuture onDeviceTakeClusterLeadership(final DeviceInfo deviceInfo) { - LOG.trace("onDeviceTakeClusterLeadership for node: {}", deviceInfo.getNodeId()); - /* validation */ - StatisticsContext statisticsContext = conductor.getStatisticsContext(deviceInfo); - if (statisticsContext == null) { - final String errMsg = String.format("DeviceCtx %s is up but we are missing StatisticsContext", deviceInfo.getDatapathId()); - LOG.warn(errMsg); - return Futures.immediateFailedFuture(new IllegalStateException(errMsg)); - } - DeviceContext deviceContext = deviceContexts.get(deviceInfo); - /* Prepare init info collecting */ - notifyDeviceSynchronizeListeners(deviceInfo, false); - ((DeviceContextImpl)deviceContext).getTransactionChainManager().activateTransactionManager(); - ((DeviceContextImpl)deviceContext).getTransactionChainManager().initialSubmitWriteTransaction(); - /* Init Collecting NodeInfo */ - final ListenableFuture initCollectingDeviceInfo = DeviceInitializationUtils.initializeNodeInformation( - deviceContext, switchFeaturesMandatory, convertorExecutor); - /* Init Collecting StatInfo */ - final ListenableFuture statPollFuture = Futures.transform(initCollectingDeviceInfo, - new AsyncFunction() { - - @Override - public ListenableFuture apply(@Nonnull final Void input) throws Exception { - statisticsContext.statListForCollectingInitialization(); - return statisticsContext.initialGatherDynamicData(); - } - }); - - return Futures.transform(statPollFuture, getInitialDeviceInformation(deviceContext)); - } - - private Function getInitialDeviceInformation(final DeviceContext deviceContext) { - return input -> { - if (ConnectionContext.CONNECTION_STATE.RIP.equals( - conductor.gainConnectionStateSafely(deviceContext.getDeviceInfo()) - )) { - final String errMsg = - String.format("We lost connection for Device %s, context has to be closed.", - deviceContext.getDeviceInfo().getNodeId()); - LOG.warn(errMsg); - throw new IllegalStateException(errMsg); - } - - if (input == null || !input) { - final String errMsg = - String.format("Get Initial Device %s information fails", - deviceContext.getDeviceInfo().getNodeId()); - LOG.warn(errMsg); - throw new IllegalStateException(errMsg); - } - LOG.debug("Get Initial Device {} information is successful", - deviceContext.getDeviceInfo().getNodeId()); - notifyDeviceSynchronizeListeners(deviceContext.getDeviceInfo(), true); - deviceContext.getDeviceState().setStatisticsPollingEnabledProp(true); - return null; - }; - } - } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImpl.java index 42162c8ab8..93c0e80357 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImpl.java @@ -8,7 +8,6 @@ package org.opendaylight.openflowplugin.impl.device; -import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; import org.opendaylight.openflowplugin.api.openflow.device.DeviceState; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FeaturesReply; @@ -23,26 +22,16 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ class DeviceStateImpl implements DeviceState { - private final DeviceInfo deviceInfo; - private boolean valid; private boolean meterIsAvailable; private boolean groupIsAvailable; - private boolean deviceSynchronized; private boolean flowStatisticsAvailable; private boolean tableStatisticsAvailable; private boolean portStatisticsAvailable; private boolean statPollEnabled; private boolean queueStatisticsAvailable; - public DeviceStateImpl(final DeviceInfo deviceInfo) { - this.deviceInfo = deviceInfo; + public DeviceStateImpl() { statPollEnabled = false; - deviceSynchronized = false; - } - - @Override - public boolean isValid() { - return valid; } @Override @@ -65,11 +54,6 @@ class DeviceStateImpl implements DeviceState { groupIsAvailable = available; } - @Override - public boolean deviceSynchronized() { - return deviceSynchronized; - } - @Override public boolean isFlowStatisticsAvailable() { return flowStatisticsAvailable; @@ -116,22 +100,4 @@ class DeviceStateImpl implements DeviceState { return statPollEnabled; } - @Override - public void setStatisticsPollingEnabledProp(final boolean statPollEnabled) { - this.statPollEnabled = statPollEnabled; - } - - @Override - public void deviceIsSynchronized(final DeviceInfo deviceInfo, final boolean isSynchronized) { - if (this.deviceInfo.equals(deviceInfo)) { - this.deviceSynchronized = isSynchronized; - } - } - - @Override - public void deviceIsValid(final DeviceInfo deviceInfo, final boolean isValid) { - if (this.deviceInfo.equals(deviceInfo)) { - this.valid = isValid; - } - } } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java index 77ea3e9753..43e78fc3ea 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/lifecycle/LifecycleServiceImpl.java @@ -41,6 +41,9 @@ public class LifecycleServiceImpl implements LifecycleService { LOG.info("Starting statistics context cluster services for node {}", getIdentifier()); this.statContext.startupClusterServices(); + LOG.info("Statistics initial gathering OK, submitting data for node {}", getIdentifier()); + this.deviceContext.initialSubmitTransaction(); + LOG.info("Starting rpc context cluster services for node {}", getIdentifier()); this.rpcContext.startupClusterServices(); diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java index 8255e35adb..6bc426dafc 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java @@ -111,11 +111,6 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag LOG.debug("Disabling statistics scheduling for device: {}", deviceInfo.getNodeId()); return; } - - if (!deviceState.isValid()) { - LOG.debug("Session is not valid for device: {}", deviceInfo.getNodeId()); - return; - } if (!deviceState.isStatisticsPollingEnabled()) { LOG.debug("Statistics polling is currently disabled for device: {}", deviceInfo.getNodeId()); 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 index 298a40e35a..723cb79723 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/LifecycleConductorImplTest.java @@ -183,7 +183,6 @@ public class LifecycleConductorImplTest { when(deviceContext.getDeviceState()).thenReturn(deviceState); when(deviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker, nodeInstanceIdentifier)); when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext); - when(deviceManager.onClusterRoleChange(deviceInfo, OfpRole.BECOMEMASTER)).thenReturn(listenableFuture); lifecycleConductor.roleChangeOnDevice(deviceInfo,OfpRole.BECOMEMASTER); verify(statisticsManager).startScheduling(Mockito.any()); } @@ -198,7 +197,6 @@ public class LifecycleConductorImplTest { when(deviceContext.getDeviceState()).thenReturn(deviceState); when(deviceContext.getDeviceFlowRegistry()).thenReturn(new DeviceFlowRegistryImpl(dataBroker, nodeInstanceIdentifier)); when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext); - when(deviceManager.onClusterRoleChange(deviceInfo, OfpRole.BECOMESLAVE)).thenReturn(listenableFuture); lifecycleConductor.roleChangeOnDevice(deviceInfo,OfpRole.BECOMESLAVE); verify(statisticsManager).stopScheduling(Mockito.any()); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java index f5840204e5..9498beeda7 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImplTest.java @@ -230,13 +230,11 @@ public class DeviceContextImplTest { deviceContext = new DeviceContextImpl( connectionContext, - deviceState, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, - deviceInfo, convertorExecutor); deviceContextSpy = Mockito.spy(deviceContext); @@ -248,24 +246,14 @@ public class DeviceContextImplTest { @Test(expected = NullPointerException.class) public void testDeviceContextImplConstructorNullDataBroker() throws Exception { - new DeviceContextImpl(connectionContext, deviceState, null, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, deviceInfo, convertorExecutor).close(); - } + new DeviceContextImpl(connectionContext, null, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, convertorExecutor).close(); - @Test(expected = NullPointerException.class) - public void testDeviceContextImplConstructorNullDeviceState() throws Exception { - new DeviceContextImpl(connectionContext, null, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, deviceInfo, convertorExecutor).close(); } @Test(expected = NullPointerException.class) public void testDeviceContextImplConstructorNullTimer() throws Exception { - new DeviceContextImpl(null, deviceState, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, deviceInfo, convertorExecutor).close(); - } - @Test - public void testGetDeviceState() { - final DeviceState deviceSt = deviceContext.getDeviceState(); - assertNotNull(deviceSt); - assertEquals(deviceState, deviceSt); + new DeviceContextImpl(null, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, convertorExecutor).close(); } @Test @@ -433,8 +421,6 @@ public class DeviceContextImplTest { final ConnectionContext mockedAuxiliaryConnectionContext = prepareConnectionContext(); deviceContext.addAuxiliaryConnectionContext(mockedAuxiliaryConnectionContext); - final DeviceTerminationPhaseHandler mockedDeviceContextClosedHandler = mock(DeviceTerminationPhaseHandler.class); - when(deviceState.isValid()).thenReturn(true); deviceContext.shutdownConnection(); verify(connectionContext).closeConnection(true); } diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImplTest.java index 5170dd75d6..071743ba3e 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceStateImplTest.java @@ -32,17 +32,7 @@ public class DeviceStateImplTest { @Before public void initialization() { - deviceState = new DeviceStateImpl(deviceInfo); - } - - @Test - public void testIsValid_initialValue(){ - Assert.assertFalse(deviceState.isValid()); - } - - @Test - public void testDeviceSynchronized_initialValue(){ - Assert.assertFalse(deviceState.deviceSynchronized()); + deviceState = new DeviceStateImpl(); } @Test diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/MultipartRequestOnTheFlyCallbackTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/MultipartRequestOnTheFlyCallbackTest.java index a085ce1e4c..9cef7daae3 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/MultipartRequestOnTheFlyCallbackTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/MultipartRequestOnTheFlyCallbackTest.java @@ -127,7 +127,6 @@ public class MultipartRequestOnTheFlyCallbackTest { when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockedPrimaryConnection); when(mockedDeviceInfo.getNodeInstanceIdentifier()).thenReturn(NODE_PATH); - when(mockedDeviceState.deviceSynchronized()).thenReturn(true); when(mockedDeviceInfo.getNodeId()).thenReturn(mockedNodeId); when(mockedDeviceInfo.getDatapathId()).thenReturn(BigInteger.TEN); when(mockedDeviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalExperimenterMessageServiceImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalExperimenterMessageServiceImplTest.java index af336d62c7..d1760f0cda 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalExperimenterMessageServiceImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/services/SalExperimenterMessageServiceImplTest.java @@ -44,7 +44,6 @@ public class SalExperimenterMessageServiceImplTest extends ServiceMocking { @Override protected void setup() { salExperimenterMessageService = new SalExperimenterMessageServiceImpl(mockedRequestContextStack, mockedDeviceContext, extensionConverterProvider); - Mockito.when(mockedDeviceContext.getExtensionConverterProvider()).thenReturn(extensionConverterProvider); Mockito.when(extensionConverterProvider.getMessageConverter(Matchers.any())) .thenReturn(extensionConverter); Mockito.when(extensionConverter.getExperimenterId()).thenReturn(new ExperimenterId(43L)); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java index 57a890ed4c..7076e6b886 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java @@ -518,7 +518,6 @@ public class StatisticsGatheringUtilsTest { @Test public void testDeleteAllKnownFlows() throws Exception { final short tableId = 0; - when(deviceState.deviceSynchronized()).thenReturn(true); final InstanceIdentifier nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); final TableBuilder tableDataBld = new TableBuilder(); tableDataBld.setId(tableId); diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java index 37eb28c5a4..68ed88b8d2 100644 --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImplTest.java @@ -380,7 +380,6 @@ public class StatisticsManagerImplTest { statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo); verify(mockedDeviceContext).getDeviceState(); - when(mockedDeviceContext.getDeviceState().isValid()).thenReturn(true); statisticsManager.pollStatistics(mockedDeviceContext.getDeviceState(), statisticsContext, mockTimerCounter, mockedDeviceInfo); when(mockedDeviceContext.getDeviceState().isStatisticsPollingEnabled()).thenReturn(true);