<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-common-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.mdsal</groupId>
+ <artifactId>mdsal-singleton-common-api</artifactId>
+ </dependency>
</dependencies>
</project>
*/
package org.opendaylight.openflowplugin.api.openflow;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.RejectedExecutionException;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
+
/**
* General API for all OFP Context
*/
}
/**
- * distinguished device context states
+ * Context state
*/
enum CONTEXT_STATE {
- /**
- * initial phase
- */
+ /* Initialization phase, context not yet fully initialized */
INITIALIZATION,
- /**
- * standard phase
- */
+ /* Standard working phase everything is fine */
WORKING,
- /**
- * termination phase
- */
+ /* Termination phase context is being shutting down */
TERMINATION
}
+ /**
+ * @return actual context state
+ */
CONTEXT_STATE getState();
+ /**
+ * Starting cluster services for context becoming master
+ */
+ default void startupClusterServices() throws ExecutionException, InterruptedException {
+ throw new InterruptedException("Cannot start abstract service, check implementation of cluster services");
+ }
+
+ /**
+ * About to stop services in cluster not master anymore or going down
+ * @return Future most of services need time to be closed
+ */
+ default ListenableFuture<Void> stopClusterServices(){
+ return Futures.immediateFailedFuture(new RejectedExecutionException("Cannot stop abstract services, check implementation of cluster services"));
+ }
+
+ /**
+ * @return cluster singleton service identifier
+ */
+ ServiceGroupIdentifier getServiceIdentifier();
+
+ /**
+ * @return device info
+ */
+ DeviceInfo getDeviceInfo();
+
}
* a request to the switch will fail immediately, with proper error indication.
* </p>
*/
-public interface DeviceContext extends AutoCloseable,
+public interface DeviceContext extends
+ OFPContext,
+ AutoCloseable,
DeviceReplyProcessor,
TxFacade,
XidSequencer,
- OFPContext,
DeviceRegistry{
/**
/**
* Method add auxiliary connection contexts to this context representing single device connection.
- *
- * @param connectionContext
+ * @param connectionContext new connection context
*/
void addAuxiliaryConnectionContext(ConnectionContext connectionContext);
/**
* Method removes auxiliary connection context from this context representing single device connection.
- *
- * @param connectionContext
+ * @param connectionContext connection which need to be removed
*/
void removeAuxiliaryConnectionContext(ConnectionContext connectionContext);
*/
DeviceState getDeviceState();
- DeviceInfo getDeviceInfo();
-
/**
* Method has to close TxManager ASAP we are notified about Closed Connection
* @return sync. future for Slave and MD-SAL completition for Master
ListenableFuture<Void> shuttingDownDataStoreTransactions();
/**
- * Method provides current devices connection context.
- *
- * @return
+ * @return current devices connection context
*/
ConnectionContext getPrimaryConnectionContext();
/**
- * Method provides current devices auxiliary connection contexts.
- *
- * @return
+ * @return current devices auxiliary connection contexts
*/
ConnectionContext getAuxiliaryConnectiobContexts(BigInteger cookie);
@Override
void close();
+
+ void setSwitchFeaturesMandatory(boolean switchFeaturesMandatory);
+
}
package org.opendaylight.openflowplugin.api.openflow.device;
import java.math.BigInteger;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
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;
*/
BigInteger getDatapathId();
+ /**
+ * @return clustering service identifier
+ */
+ ServiceGroupIdentifier getServiceIdentifier();
+
}
--- /dev/null
+/*
+ * 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.mdsal.singleton.common.api.ClusterSingletonService;
+
+/**
+ * Service for starting or stopping all services in plugin in cluster
+ */
+public interface LifecycleService extends ClusterSingletonService {
+}
import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
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.rpc.RpcManager;
import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService;
/**
*/
Entity getTxEntity();
- /**
- * Actual nodeId
- * @return
- */
- DeviceInfo getDeviceInfo();
-
/**
* Returns true if main entity is registered
* @return
package org.opendaylight.openflowplugin.api.openflow.role;
import org.opendaylight.openflowplugin.api.openflow.OFPManager;
+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.DeviceLifecycleSupervisor;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.RoleChangeListener;
/**
- * Created by kramesha on 8/31/15.
+ * Manager for role change on device
*/
-public interface RoleManager extends DeviceLifecycleSupervisor, DeviceInitializationPhaseHandler, AutoCloseable,
- DeviceTerminationPhaseHandler, OFPManager {
+public interface RoleManager extends
+ DeviceLifecycleSupervisor,
+ DeviceInitializationPhaseHandler,
+ AutoCloseable,
+ DeviceTerminationPhaseHandler,
+ OFPManager {
String ENTITY_TYPE = "openflow";
String TX_ENTITY_TYPE = "ofTransaction";
package org.opendaylight.openflowplugin.api.openflow.rpc;
import org.opendaylight.openflowplugin.api.openflow.OFPManager;
+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.DeviceLifecycleSupervisor;
import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceTerminationPhaseHandler;
import io.netty.util.Timeout;
import java.util.Optional;
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.rpc.listener.ItemLifecycleListener;
@Override
void close();
+
}
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+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.connection.OutboundQueueHandlerRegistration;
final private KeyedInstanceIdentifier<Node, NodeKey> nodeII;
final private Short version;
final private BigInteger datapathId;
+ final private ServiceGroupIdentifier serviceGroupIdentifier;
DeviceInfoImpl(
final NodeId nodeId,
this.nodeII = nodeII;
this.version = version;
this.datapathId = datapathId;
+ this.serviceGroupIdentifier = ServiceGroupIdentifier.create(this.nodeId.getValue());
}
@Override
return datapathId;
}
+ @Override
+ public ServiceGroupIdentifier getServiceIdentifier() {
+ return this.serviceGroupIdentifier;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutionException;
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.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.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.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.registry.group.DeviceGroupRegistryImpl;
import org.opendaylight.openflowplugin.impl.registry.meter.DeviceMeterRegistryImpl;
+import org.opendaylight.openflowplugin.impl.util.DeviceInitializationUtils;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.openflowplugin.openflow.md.core.session.SwitchConnectionCookieOFImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDevBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
/**
*
*/
-public class DeviceContextImpl implements DeviceContext, ExtensionConverterProviderKeeper {
+public class DeviceContextImpl implements DeviceContext, ExtensionConverterProviderKeeper{
private static final Logger LOG = LoggerFactory.getLogger(DeviceContextImpl.class);
private ExtensionConverterProvider extensionConverterProvider;
private final DeviceManager deviceManager;
+ private boolean switchFeaturesMandatory;
private final DeviceInfo deviceInfo;
-
- private volatile CONTEXT_STATE contextState;
-
-
- @VisibleForTesting
- 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) {
+ 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) {
this.primaryConnectionContext = Preconditions.checkNotNull(primaryConnectionContext);
this.deviceState = Preconditions.checkNotNull(deviceState);
this.dataBroker = Preconditions.checkNotNull(dataBroker);
Preconditions.checkNotNull(conductor);
this.outboundQueueProvider = Preconditions.checkNotNull(outboundQueueProvider);
- deviceInfo = primaryConnectionContext.getDeviceInfo();
- this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo, conductor);
+ this.transactionChainManager = new TransactionChainManager(dataBroker, deviceInfo , conductor);
auxiliaryConnectionContexts = new HashMap<>();
deviceFlowRegistry = new DeviceFlowRegistryImpl(dataBroker, deviceInfo.getNodeInstanceIdentifier());
deviceGroupRegistry = new DeviceGroupRegistryImpl();
itemLifeCycleSourceRegistry = new ItemLifeCycleRegistryImpl();
flowLifeCycleKeeper = new ItemLifeCycleSourceImpl();
itemLifeCycleSourceRegistry.registerLifeCycleSource(flowLifeCycleKeeper);
- contextState = CONTEXT_STATE.INITIALIZATION;
+ this.deviceInfo = deviceInfo;
+ this.state = CONTEXT_STATE.INITIALIZATION;
+ this.convertorExecutor = convertorExecutor;
}
/**
public void removeAuxiliaryConnectionContext(final ConnectionContext connectionContext) {
final SwitchConnectionDistinguisher connectionDistinguisher = createConnectionDistinguisher(connectionContext);
LOG.debug("auxiliary connection dropped: {}, nodeId:{}", connectionContext.getConnectionAdapter()
- .getRemoteAddress(), deviceInfo.getNodeId());
+ .getRemoteAddress(), getDeviceInfo().getNodeId());
auxiliaryConnectionContexts.remove(connectionDistinguisher);
}
return deviceState;
}
- @Override
- public DeviceInfo getDeviceInfo() {
- return this.deviceInfo;
- }
-
@Override
public ReadOnlyTransaction getReadTransaction() {
return dataBroker.newReadOnlyTransaction();
@Override
public void processPortStatusMessage(final PortStatusMessage portStatus) {
messageSpy.spyMessage(portStatus.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS);
- final FlowCapableNodeConnector flowCapableNodeConnector = portStatusTranslator.translate(portStatus, deviceInfo, null);
+ final FlowCapableNodeConnector flowCapableNodeConnector = portStatusTranslator.translate(portStatus, getDeviceInfo(), null);
final KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey> iiToNodeConnector = provideIIToNodeConnector(portStatus.getPortNo(), portStatus.getVersion());
try {
}
private KeyedInstanceIdentifier<NodeConnector, NodeConnectorKey> provideIIToNodeConnector(final long portNo, final short version) {
- final InstanceIdentifier<Node> iiToNodes = deviceInfo.getNodeInstanceIdentifier();
- final BigInteger dataPathId = deviceInfo.getDatapathId();
+ final InstanceIdentifier<Node> iiToNodes = getDeviceInfo().getNodeInstanceIdentifier();
+ final BigInteger dataPathId = getDeviceInfo().getDatapathId();
final NodeConnectorId nodeConnectorId = NodeStaticReplyTranslatorUtil.nodeConnectorId(dataPathId.toString(), portNo, version);
return iiToNodes.child(NodeConnector.class, new NodeConnectorKey(nodeConnectorId));
}
public void processPacketInMessage(final PacketInMessage packetInMessage) {
messageSpy.spyMessage(packetInMessage.getImplementedInterface(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH);
final ConnectionAdapter connectionAdapter = getPrimaryConnectionContext().getConnectionAdapter();
- final PacketReceived packetReceived = packetInTranslator.translate(packetInMessage, deviceInfo, null);
+ final PacketReceived packetReceived = packetInTranslator.translate(packetInMessage, getDeviceInfo(), null);
if (packetReceived == null) {
LOG.debug("Received a null packet from switch {}", connectionAdapter.getRemoteAddress());
// lookup converter
final ExperimenterDataOfChoice vendorData = notification.getExperimenterDataOfChoice();
final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(
- deviceInfo.getVersion(),
+ getDeviceInfo().getVersion(),
(Class<? extends ExperimenterDataOfChoice>) vendorData.getImplementedInterface());
final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter = extensionConverterProvider.getMessageConverter(key);
if (messageConverter == null) {
LOG.warn("custom converter for {}[OF:{}] not found",
notification.getExperimenterDataOfChoice().getImplementedInterface(),
- deviceInfo.getVersion());
+ getDeviceInfo().getVersion());
return;
}
// build notification
try {
messageOfChoice = messageConverter.convert(vendorData, MessagePath.MESSAGE_NOTIFICATION);
final ExperimenterMessageFromDevBuilder experimenterMessageFromDevBld = new ExperimenterMessageFromDevBuilder()
- .setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier()))
+ .setNode(new NodeRef(getDeviceInfo().getNodeInstanceIdentifier()))
.setExperimenterMessageOfChoice(messageOfChoice);
// publish
notificationPublishService.offerNotification(experimenterMessageFromDevBld.build());
@Override
public void onPublished() {
- Verify.verify(CONTEXT_STATE.INITIALIZATION.equals(contextState));
- contextState = CONTEXT_STATE.WORKING;
+ Verify.verify(CONTEXT_STATE.INITIALIZATION.equals(getState()));
+ setState(CONTEXT_STATE.WORKING);
primaryConnectionContext.getConnectionAdapter().setPacketInFiltering(false);
for (final ConnectionContext switchAuxConnectionContext : auxiliaryConnectionContexts.values()) {
switchAuxConnectionContext.getConnectionAdapter().setPacketInFiltering(false);
@Override
public synchronized void shutdownConnection() {
- LOG.debug("Shutdown method for node {}", deviceInfo.getNodeId());
- if (CONTEXT_STATE.TERMINATION.equals(contextState)) {
- LOG.debug("DeviceCtx for Node {} is in termination process.", deviceInfo.getNodeId());
+ LOG.debug("Shutdown method for node {}", getDeviceInfo().getNodeId());
+ if (CONTEXT_STATE.TERMINATION.equals(getState())) {
+ LOG.debug("DeviceCtx for Node {} is in termination process.", getDeviceInfo().getNodeId());
return;
}
- contextState = CONTEXT_STATE.TERMINATION;
+ setState(CONTEXT_STATE.TERMINATION);
if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) {
- LOG.debug("ConnectionCtx for Node {} is in RIP state.", deviceInfo.getNodeId());
+ LOG.debug("ConnectionCtx for Node {} is in RIP state.", getDeviceInfo().getNodeId());
return;
}
/* Terminate Auxiliary Connection */
return this.transactionChainManager;
}
+ @Override
+ public void setSwitchFeaturesMandatory(boolean switchFeaturesMandatory) {
+ this.switchFeaturesMandatory = switchFeaturesMandatory;
+ }
+
@Override
public CONTEXT_STATE getState() {
- return this.contextState;
+ return this.state;
+ }
+
+ @Override
+ public void setState(CONTEXT_STATE state) {
+ this.state = state;
+ }
+
+ @Override
+ public void startupClusterServices() throws ExecutionException, InterruptedException {
+ LOG.debug("Initializing transaction chain manager for node {}", getDeviceInfo().getNodeId());
+ this.transactionChainManager.activateTransactionManager();
+ LOG.debug("Waiting to get node {} information", getDeviceInfo().getNodeId());
+ DeviceInitializationUtils.initializeNodeInformation(this, switchFeaturesMandatory, this.convertorExecutor).get();
+ }
+
+ @Override
+ public ListenableFuture<Void> stopClusterServices() {
+ return this.transactionChainManager.deactivateTransactionManager();
+ }
+
+ @Override
+ public ServiceGroupIdentifier getServiceIdentifier() {
+ return this.deviceInfo.getServiceIdentifier();
+ }
+
+ @Override
+ public DeviceInfo getDeviceInfo() {
+ return this.deviceInfo;
}
}
Preconditions.checkArgument(connectionContext != null);
DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
- /**
+ /*
* This part prevent destroy another device context. Throwing here an exception result to propagate close connection
* in {@link org.opendaylight.openflowplugin.impl.connection.org.opendaylight.openflowplugin.impl.connection.HandshakeContextImpl}
* If context already exist we are in state closing process (connection flapping) and we should not propagate connection close
conductor,
outboundQueueProvider,
translatorLibrary,
- this);
+ this,
+ connectionContext.getDeviceInfo(),
+ convertorExecutor);
Verify.verify(deviceContexts.putIfAbsent(deviceInfo, deviceContext) == null, "DeviceCtx still not closed.");
+ deviceContext.setSwitchFeaturesMandatory(switchFeaturesMandatory);
+
((ExtensionConverterProviderKeeper) deviceContext).setExtensionConverterProvider(extensionConverterProvider);
deviceContext.setNotificationPublishService(conductor.getNotificationPublishService());
--- /dev/null
+/*
+ * 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.lifecycle;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.concurrent.ExecutionException;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
+import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
+import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+class LifecycleServiceImpl implements LifecycleService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LifecycleServiceImpl.class);
+
+ private final DeviceContext deviceContext;
+ private final RpcContext rpcContext;
+ private final RoleContext roleContext;
+ private final StatisticsContext statContext;
+
+ public LifecycleServiceImpl(
+ final DeviceContext deviceContext,
+ final RpcContext rpcContext,
+ final RoleContext roleContext,
+ final StatisticsContext statContext) {
+ this.deviceContext = deviceContext;
+ this.rpcContext = rpcContext;
+ this.roleContext = roleContext;
+ this.statContext = statContext;
+ }
+
+ @Override
+ public void instantiateServiceInstance() {
+ LOG.info("Starting device context cluster services for node {}", this.deviceContext.getServiceIdentifier());
+ try {
+ this.deviceContext.startupClusterServices();
+ } catch (ExecutionException | InterruptedException e) {
+ LOG.warn("Cluster service {} was unable to start.", this.getIdentifier());
+ }
+ LOG.info("Starting statistics context cluster services for node {}", this.deviceContext.getServiceIdentifier());
+ }
+
+ @Override
+ public ListenableFuture<Void> closeServiceInstance() {
+ return deviceContext.stopClusterServices();
+ }
+
+ @Override
+ public ServiceGroupIdentifier getIdentifier() {
+ return deviceContext.getServiceIdentifier();
+ }
+}
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.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleConductor;
private static final Logger LOG = LoggerFactory.getLogger(RoleContextImpl.class);
private static final int TIMEOUT = 12;
- private final DeviceInfo deviceInfo;
private final EntityOwnershipService entityOwnershipService;
private volatile EntityOwnershipCandidateRegistration entityOwnershipCandidateRegistration = null;
private volatile EntityOwnershipCandidateRegistration txEntityOwnershipCandidateRegistration = null;
private final Semaphore roleChangeGuard = new Semaphore(1, true);
private final LifecycleConductor conductor;
- private volatile CONTEXT_STATE contextState;
+ private final DeviceInfo deviceInfo;
+ private CONTEXT_STATE state;
- RoleContextImpl(final DeviceInfo deviceInfo, final EntityOwnershipService entityOwnershipService, final Entity entity, final Entity txEntity, final LifecycleConductor lifecycleConductor) {
+ RoleContextImpl(final DeviceInfo deviceInfo,
+ final EntityOwnershipService entityOwnershipService,
+ final Entity entity,
+ final Entity txEntity,
+ final LifecycleConductor lifecycleConductor) {
this.entityOwnershipService = entityOwnershipService;
this.entity = entity;
this.txEntity = txEntity;
- this.deviceInfo = deviceInfo;
this.conductor = lifecycleConductor;
- contextState = CONTEXT_STATE.INITIALIZATION;
+ this.deviceInfo = deviceInfo;
+ state = CONTEXT_STATE.INITIALIZATION;
}
@Override
public boolean initialization() {
- LOG.info("Initialization main candidate for node {}", deviceInfo.getNodeId());
- contextState = CONTEXT_STATE.WORKING;
+ LOG.info("Initialization main candidate for node {}", getDeviceInfo().getNodeId());
+ setState(CONTEXT_STATE.WORKING);
return registerCandidate(this.entity);
}
@Override
public void unregisterAllCandidates() {
- LOG.info("Role context closed, unregistering all candidates for ownership for node {}", deviceInfo.getNodeId());
+ LOG.info("Role context closed, unregistering all candidates for ownership for node {}", getDeviceInfo().getNodeId());
if (isMainCandidateRegistered()) {
unregisterCandidate(this.entity);
}
@Nullable
@Override
public <T> RequestContext<T> createRequestContext() {
- return new AbstractRequestContext<T>(conductor.reserveXidForDeviceMessage(deviceInfo)) {
+ return new AbstractRequestContext<T>(conductor.reserveXidForDeviceMessage(getDeviceInfo())) {
@Override
public void close() {
}
return this.txEntity;
}
- @Override
- public DeviceInfo getDeviceInfo() {
- return deviceInfo;
- }
-
@Override
public boolean isMainCandidateRegistered() {
return entityOwnershipCandidateRegistration != null;
@Override
public void close() {
- contextState = CONTEXT_STATE.TERMINATION;
+ setState(CONTEXT_STATE.TERMINATION);
unregisterAllCandidates();
}
@Override
public CONTEXT_STATE getState() {
- return contextState;
+ return this.state;
}
@Override
- public void setState(CONTEXT_STATE contextState) {
- this.contextState = contextState;
+ public void setState(CONTEXT_STATE state) {
+ this.state = state;
}
+
+ @Override
+ public ServiceGroupIdentifier getServiceIdentifier() {
+ return this.deviceInfo.getServiceIdentifier();
+ }
+
+ @Override
+ public DeviceInfo getDeviceInfo() {
+ return this.deviceInfo;
+ }
+
}
}
@Override
- public <T extends OFPContext> T gainContext(DeviceInfo deviceInfo) {
+ public <T extends OFPContext> T gainContext(final DeviceInfo deviceInfo) {
return (T) contexts.get(deviceInfo);
}
}
import java.util.concurrent.Semaphore;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.openflowplugin.api.openflow.OFPContext;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
import org.opendaylight.openflowplugin.api.openflow.device.XidSequencer;
import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
private final XidSequencer xidSequencer;
private boolean isStatisticsRpcEnabled;
- private volatile CONTEXT_STATE contextState;
-
// TODO: add private Sal salBroker
private final ConcurrentMap<Class<?>, RoutedRpcRegistration<?>> rpcRegistrations = new ConcurrentHashMap<>();
private final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier;
-
- RpcContextImpl(final RpcProviderRegistry rpcProviderRegistry,
- final XidSequencer xidSequencer,
- final MessageSpy messageSpy,
- final int maxRequests,
- final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier) {
+ private CONTEXT_STATE state;
+ private final DeviceInfo deviceInfo;
+
+ RpcContextImpl(final DeviceInfo deviceInfo,
+ final RpcProviderRegistry rpcProviderRegistry,
+ final XidSequencer xidSequencer,
+ final MessageSpy messageSpy,
+ final int maxRequests,
+ final KeyedInstanceIdentifier<Node, NodeKey> nodeInstanceIdentifier) {
this.xidSequencer = Preconditions.checkNotNull(xidSequencer);
this.messageSpy = Preconditions.checkNotNull(messageSpy);
this.rpcProviderRegistry = Preconditions.checkNotNull(rpcProviderRegistry);
this.nodeInstanceIdentifier = nodeInstanceIdentifier;
tracker = new Semaphore(maxRequests, true);
- contextState = CONTEXT_STATE.WORKING;
+ setState(CONTEXT_STATE.WORKING);
+ this.deviceInfo = deviceInfo;
}
/**
*/
@Override
public void close() {
- if (CONTEXT_STATE.TERMINATION.equals(contextState)){
+ if (CONTEXT_STATE.TERMINATION.equals(getState())){
if (LOG.isDebugEnabled()) {
LOG.debug("RpcContext is already in TERMINATION state.");
}
} else {
- contextState = CONTEXT_STATE.TERMINATION;
+ setState(CONTEXT_STATE.TERMINATION);
for (final Iterator<Entry<Class<?>, RoutedRpcRegistration<?>>> iterator = Iterators
.consumingIterator(rpcRegistrations.entrySet().iterator()); iterator.hasNext(); ) {
final RoutedRpcRegistration<?> rpcRegistration = iterator.next().getValue();
@Override
public CONTEXT_STATE getState() {
- return contextState;
+ return this.state;
+ }
+
+ @Override
+ public void setState(CONTEXT_STATE state) {
+ this.state = state;
+ }
+
+ @Override
+ public ServiceGroupIdentifier getServiceIdentifier() {
+ return this.deviceInfo.getServiceIdentifier();
+ }
+
+ @Override
+ public DeviceInfo getDeviceInfo() {
+ return this.deviceInfo;
}
}
private final LifecycleConductor conductor;
- public RpcManagerImpl(final RpcProviderRegistry rpcProviderRegistry,
- final int quotaValue,
- final LifecycleConductor lifecycleConductor) {
+ public RpcManagerImpl(
+ final RpcProviderRegistry rpcProviderRegistry,
+ final int quotaValue,
+ final LifecycleConductor lifecycleConductor) {
this.rpcProviderRegistry = rpcProviderRegistry;
maxRequestsQuota = quotaValue;
this.conductor = lifecycleConductor;
final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
final RpcContext rpcContext = new RpcContextImpl(
+ deviceInfo,
rpcProviderRegistry,
deviceContext,
deviceContext.getMessageSpy(),
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
-import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
+import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
private StatisticsGatheringService statisticsGatheringService;
private StatisticsGatheringOnTheFlyService statisticsGatheringOnTheFlyService;
private Timeout pollTimeout;
+ private final DeviceInfo deviceInfo;
private volatile boolean schedulingEnabled;
- private volatile CONTEXT_STATE contextState;
+ private volatile CONTEXT_STATE state;
- StatisticsContextImpl(@CheckForNull final DeviceInfo deviceInfo, final boolean shuttingDownStatisticsPolling, final LifecycleConductor lifecycleConductor, final ConvertorExecutor convertorExecutor) {
+ StatisticsContextImpl(@Nonnull final DeviceInfo deviceInfo,
+ @Nonnull final boolean shuttingDownStatisticsPolling,
+ @Nonnull final LifecycleConductor lifecycleConductor,
+ @Nonnull final ConvertorExecutor convertorExecutor) {
this.deviceContext = Preconditions.checkNotNull(lifecycleConductor.getDeviceContext(deviceInfo));
this.devState = Preconditions.checkNotNull(deviceContext.getDeviceState());
this.shuttingDownStatisticsPolling = shuttingDownStatisticsPolling;
statisticsGatheringOnTheFlyService = new StatisticsGatheringOnTheFlyService(this, deviceContext, convertorExecutor);
itemLifeCycleListener = new ItemLifecycleListenerImpl(deviceContext);
statListForCollectingInitialization();
- contextState = CONTEXT_STATE.WORKING;
+ setState(CONTEXT_STATE.INITIALIZATION);
+ this.deviceInfo = deviceInfo;
}
@Override
private ListenableFuture<Boolean> gatherDynamicData(final boolean initial) {
if (shuttingDownStatisticsPolling) {
- LOG.debug("Statistics for device {} is not enabled.", deviceContext.getDeviceInfo().getNodeId());
+ LOG.debug("Statistics for device {} is not enabled.", getDeviceInfo().getNodeId());
return Futures.immediateFuture(Boolean.TRUE);
}
final ListenableFuture<Boolean> errorResultFuture = deviceConnectionCheck();
@Override
public void close() {
- if (CONTEXT_STATE.TERMINATION.equals(contextState)) {
+ if (CONTEXT_STATE.TERMINATION.equals(getState())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Statistics context is already in state TERMINATION.");
}
} else {
- contextState = CONTEXT_STATE.TERMINATION;
+ setState(CONTEXT_STATE.TERMINATION);
schedulingEnabled = false;
for (final Iterator<RequestContext<?>> iterator = Iterators.consumingIterator(requestContexts.iterator());
iterator.hasNext(); ) {
private void statChainFuture(final Iterator<MultipartType> iterator, final SettableFuture<Boolean> resultFuture, final boolean initial) {
if (ConnectionContext.CONNECTION_STATE.RIP.equals(deviceContext.getPrimaryConnectionContext().getConnectionState())) {
final String errMsg = String.format("Device connection is closed for Node : %s.",
- deviceContext.getDeviceInfo().getNodeId());
+ getDeviceInfo().getNodeId());
LOG.debug(errMsg);
resultFuture.setException(new IllegalStateException(errMsg));
return;
}
if ( ! iterator.hasNext()) {
resultFuture.set(Boolean.TRUE);
- LOG.debug("Stats collection successfully finished for node {}", deviceContext.getDeviceInfo().getNodeId());
+ LOG.debug("Stats collection successfully finished for node {}", getDeviceInfo().getNodeId());
return;
}
final MultipartType nextType = iterator.next();
- LOG.debug("Stats iterating to next type for node {} of type {}", deviceContext.getDeviceInfo().getNodeId(), nextType);
+ LOG.debug("Stats iterating to next type for node {} of type {}", getDeviceInfo().getNodeId(), nextType);
final ListenableFuture<Boolean> deviceStatisticsCollectionFuture = chooseStat(nextType, initial);
Futures.addCallback(deviceStatisticsCollectionFuture, new FutureCallback<Boolean>() {
private ListenableFuture<Boolean> collectFlowStatistics(final MultipartType multipartType, final boolean initial) {
return devState.isFlowStatisticsAvailable() ? StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringOnTheFlyService,
- deviceContext.getDeviceInfo(),
+ getDeviceInfo(),
/*MultipartType.OFPMPFLOW*/ multipartType,
deviceContext,
deviceContext,
private ListenableFuture<Boolean> collectTableStatistics(final MultipartType multipartType) {
return devState.isTableStatisticsAvailable() ? StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringService,
- deviceContext.getDeviceInfo(),
+ getDeviceInfo(),
/*MultipartType.OFPMPTABLE*/ multipartType,
deviceContext,
deviceContext,
private ListenableFuture<Boolean> collectPortStatistics(final MultipartType multipartType) {
return devState.isPortStatisticsAvailable() ? StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringService,
- deviceContext.getDeviceInfo(),
+ getDeviceInfo(),
/*MultipartType.OFPMPPORTSTATS*/ multipartType,
deviceContext,
deviceContext,
private ListenableFuture<Boolean> collectQueueStatistics(final MultipartType multipartType) {
return !devState.isQueueStatisticsAvailable() ? emptyFuture : StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringService,
- deviceContext.getDeviceInfo(),
+ getDeviceInfo(),
/*MultipartType.OFPMPQUEUE*/ multipartType,
deviceContext,
deviceContext,
private ListenableFuture<Boolean> collectGroupDescStatistics(final MultipartType multipartType) {
return devState.isGroupAvailable() ? StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringService,
- deviceContext.getDeviceInfo(),
+ getDeviceInfo(),
/*MultipartType.OFPMPGROUPDESC*/ multipartType,
deviceContext,
deviceContext,
private ListenableFuture<Boolean> collectGroupStatistics(final MultipartType multipartType) {
return devState.isGroupAvailable() ? StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringService,
- deviceContext.getDeviceInfo(),
+ getDeviceInfo(),
/*MultipartType.OFPMPGROUP*/ multipartType,
deviceContext,
deviceContext,
private ListenableFuture<Boolean> collectMeterConfigStatistics(final MultipartType multipartType) {
return devState.isMetersAvailable() ? StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringService,
- deviceContext.getDeviceInfo(),
+ getDeviceInfo(),
/*MultipartType.OFPMPMETERCONFIG*/ multipartType,
deviceContext,
deviceContext,
private ListenableFuture<Boolean> collectMeterStatistics(final MultipartType multipartType) {
return devState.isMetersAvailable() ? StatisticsGatheringUtils.gatherStatistics(
statisticsGatheringService,
- deviceContext.getDeviceInfo(),
+ getDeviceInfo(),
/*MultipartType.OFPMPMETER*/ multipartType,
deviceContext,
deviceContext,
@Override
public CONTEXT_STATE getState() {
- return contextState;
+ return this.state;
+ }
+
+ @Override
+ public void setState(CONTEXT_STATE state) {
+ this.state = state;
+ }
+
+ @Override
+ public ServiceGroupIdentifier getServiceIdentifier() {
+ return this.deviceInfo.getServiceIdentifier();
+ }
+
+ @Override
+ public DeviceInfo getDeviceInfo() {
+ return this.deviceInfo;
}
}
@Override
public void onDeviceContextLevelUp(final DeviceInfo deviceInfo) throws Exception {
- final DeviceContext deviceContext = Preconditions.checkNotNull(conductor.getDeviceContext(deviceInfo));
-
final StatisticsContext statisticsContext = new StatisticsContextImpl(deviceInfo, shuttingDownStatisticsPolling, conductor, convertorExecutor);
Verify.verify(contexts.putIfAbsent(deviceInfo, statisticsContext) == null, "StatisticsCtx still not closed for Node {}", deviceInfo.getNodeId());
LOG.trace("Statistics gathering for single node was not successful.. ", throwable);
calculateTimerDelay(timeCounter);
if (throwable instanceof CancellationException) {
- /** This often happens when something wrong with akka or DS, so closing connection will help to restart device **/
+ /* This often happens when something wrong with akka or DS, so closing connection will help to restart device **/
conductor.closeConnection(deviceInfo);
} else {
scheduleNextPolling(deviceState, deviceInfo, statisticsContext, timeCounter);
import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.OpendaylightQueueStatisticsService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
+import org.opendaylight.yangtools.yang.binding.RpcService;
public class MdSalRegistrationUtils {
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.openflowplugin.api.openflow.OFPContext;
import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
when(deviceInfo.getDatapathId()).thenReturn(BigInteger.TEN);
when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo);
- when(rpcManager.gainContext(Mockito.any())).thenReturn(rpcContext);
}
@Test
import org.opendaylight.openflowplugin.impl.registry.flow.FlowDescriptorFactory;
import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory;
import org.opendaylight.openflowplugin.impl.util.DeviceStateUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.ExperimenterMessageFromDev;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
private DeviceInfo deviceInfo;
@Mock
private DeviceManager deviceManager;
+ @Mock
+ private ConvertorExecutor convertorExecutor;
private InOrder inOrderDevState;
.thenReturn(messageTranslatorFlowRemoved);
Mockito.when(lifecycleConductor.getMessageIntelligenceAgency()).thenReturn(messageIntelligenceAgency);
- deviceContext = new DeviceContextImpl(connectionContext, deviceState, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager);
+ deviceContext = new DeviceContextImpl(
+ connectionContext,
+ deviceState,
+ dataBroker,
+ lifecycleConductor,
+ outboundQueueProvider,
+ translatorLibrary,
+ deviceManager,
+ deviceInfo,
+ convertorExecutor);
deviceContextSpy = Mockito.spy(deviceContext);
xid = new Xid(atomicLong.incrementAndGet());
@Test(expected = NullPointerException.class)
public void testDeviceContextImplConstructorNullDataBroker() throws Exception {
- new DeviceContextImpl(connectionContext, deviceState, null, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager).close();
+ new DeviceContextImpl(connectionContext, deviceState, null, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, deviceInfo, convertorExecutor).close();
}
@Test(expected = NullPointerException.class)
public void testDeviceContextImplConstructorNullDeviceState() throws Exception {
- new DeviceContextImpl(connectionContext, null, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager).close();
+ 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).close();
+ new DeviceContextImpl(null, deviceState, dataBroker, lifecycleConductor, outboundQueueProvider, translatorLibrary, deviceManager, deviceInfo, convertorExecutor).close();
}
@Test
--- /dev/null
+/**
+ * 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.lifecycle;
+
+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.mdsal.singleton.common.api.ServiceGroupIdentifier;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
+import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo;
+import org.opendaylight.openflowplugin.api.openflow.lifecycle.LifecycleService;
+import org.opendaylight.openflowplugin.api.openflow.role.RoleContext;
+import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
+import org.opendaylight.openflowplugin.api.openflow.statistics.StatisticsContext;
+
+@RunWith(MockitoJUnitRunner.class)
+public class LifecycleServiceImplTest {
+
+ private static final ServiceGroupIdentifier SERVICE_GROUP_IDENTIFIER = ServiceGroupIdentifier.create("test node");
+ @Mock
+ private DeviceInfo deviceInfo;
+ @Mock
+ private DeviceContext deviceContext;
+ @Mock
+ private RpcContext rpcContext;
+ @Mock
+ private RoleContext roleContext;
+ @Mock
+ private StatisticsContext statContext;
+
+ private LifecycleService lifecycleService;
+
+ @Before
+ public void setUp() {
+ lifecycleService = new LifecycleServiceImpl(deviceContext, rpcContext, roleContext, statContext);
+ Mockito.when(deviceInfo.getServiceIdentifier()).thenReturn(SERVICE_GROUP_IDENTIFIER);
+ }
+
+ @Test
+ public void instantiateServiceInstance() throws Exception {
+ lifecycleService.instantiateServiceInstance();
+ Mockito.verify(deviceContext).startupClusterServices();
+ }
+
+ @Test
+ public void closeServiceInstance() throws Exception {
+ lifecycleService.closeServiceInstance();
+ Mockito.verify(deviceContext).stopClusterServices();
+ }
+
+}
\ No newline at end of file
}
});
- Thread t1 = new Thread(new Runnable() {
- @Override
- public void run() {
- LOG.info("Starting thread 1");
- Assert.assertTrue(roleContext.initialization());
- }
+ Thread t1 = new Thread(() -> {
+ LOG.info("Starting thread 1");
+ Assert.assertTrue(roleContext.initialization());
});
- Thread t2 = new Thread(new Runnable() {
- @Override
- public void run() {
- LOG.info("Starting thread 2");
- Assert.assertFalse(roleContext.initialization());
- }
+ Thread t2 = new Thread(() -> {
+ LOG.info("Starting thread 2");
+ Assert.assertFalse(roleContext.initialization());
});
t1.start();
@Mock
private DeviceContext deviceContext;
@Mock
- private BindingAwareBroker.RoutedRpcRegistration routedRpcReg;
+ private BindingAwareBroker.RoutedRpcRegistration<TestRpcService> routedRpcReg;
@Mock
private NotificationPublishService notificationPublishService;
@Mock
when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(nodeInstanceIdentifier);
when(deviceContext.getMessageSpy()).thenReturn(messageSpy);
- rpcContext = new RpcContextImpl(rpcProviderRegistry,deviceContext, messageSpy, MAX_REQUESTS,nodeInstanceIdentifier);
+ rpcContext = new RpcContextImpl(
+ deviceInfo,
+ rpcProviderRegistry,
+ deviceContext,
+ messageSpy,
+ MAX_REQUESTS,
+ nodeInstanceIdentifier);
when(rpcProviderRegistry.addRoutedRpcImplementation(TestRpcService.class, serviceInstance)).thenReturn(routedRpcReg);
@Test
public void testStoreOrFail() throws Exception {
- try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, xidSequencer,
- messageSpy, 100, nodeInstanceIdentifier)) {
+ try (final RpcContext rpcContext = new RpcContextImpl(
+ deviceInfo,
+ rpcProviderRegistry,
+ xidSequencer,
+ messageSpy,
+ 100,
+ nodeInstanceIdentifier)) {
final RequestContext<?> requestContext = rpcContext.createRequestContext();
assertNotNull(requestContext);
}
@Test
public void testStoreOrFailThatFails() throws Exception {
- try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, xidSequencer,
- messageSpy, 0, nodeInstanceIdentifier)) {
+ try (final RpcContext rpcContext = new RpcContextImpl(
+ deviceInfo,
+ rpcProviderRegistry,
+ xidSequencer,
+ messageSpy,
+ 0,
+ nodeInstanceIdentifier)) {
final RequestContext<?> requestContext = rpcContext.createRequestContext();
assertNull(requestContext);
}
@Test
public void testStoreAndCloseOrFail() throws Exception {
- try (final RpcContext rpcContext = new RpcContextImpl(rpcProviderRegistry, deviceContext, messageSpy,
- 100, nodeInstanceIdentifier)) {
+ try (final RpcContext rpcContext = new RpcContextImpl(
+ deviceInfo,
+ rpcProviderRegistry,
+ deviceContext,
+ messageSpy,
+ 100,
+ nodeInstanceIdentifier)) {
final RequestContext<?> requestContext = rpcContext.createRequestContext();
assertNotNull(requestContext);
requestContext.close();