DeviceInfo getDeviceInfo();
- /**
- * 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 role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
- * @return RoleChangeTxChainManager future for activation/deactivation
- * @deprecated replaced by method onDeviceTakeClusterLeadership and onDevicLostClusterLeadership
- */
- @Deprecated
- ListenableFuture<Void> onClusterRoleChange(@CheckForNull OfpRole role);
-
/**
* Method has to activate TransactionChainManager and prepare all Contexts from Device Contects suite
* to Taking ClusterLeadership role {@link OfpRole#BECOMEMASTER} (e.g. Routed RPC registration, StatPolling ...)
package org.opendaylight.openflowplugin.api.openflow.device;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+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;
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;
+
+import javax.annotation.CheckForNull;
/**
* This interface is responsible for instantiating DeviceContext and
*/
DeviceContext getDeviceContextFromNodeId(DeviceInfo deviceInfo);
+ /**
+ * 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
+ * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
+ * @return RoleChangeTxChainManager future for activation/deactivation
+ */
+ ListenableFuture<Void> onClusterRoleChange(final DeviceInfo deviceInfo, final OfpRole role);
+
+
}
OfpRole.BECOMESLAVE);
}
- final ListenableFuture<Void> onClusterRoleChange = deviceContext.onClusterRoleChange(newRole);
+ final ListenableFuture<Void> onClusterRoleChange = deviceManager.onClusterRoleChange(deviceInfo, newRole);
Futures.addCallback(onClusterRoleChange, new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void aVoid) {
return dataBroker.newReadOnlyTransaction();
}
- @Override
- public ListenableFuture<Void> onClusterRoleChange(@CheckForNull final OfpRole role) {
- LOG.trace("onClusterRoleChange {} for node:", role, deviceInfo.getNodeId());
- if (OfpRole.BECOMEMASTER.equals(role)) {
- return onDeviceTakeClusterLeadership();
- }
- return transactionChainManager.deactivateTransactionManager();
- }
-
@Override
public ListenableFuture<Void> onDeviceTakeClusterLeadership() {
LOG.trace("onDeviceTakeClusterLeadership for node: {}", deviceInfo.getNodeId());
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.openflowjava.protocol.api.connection.ConnectionAdapter;
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;
public void onDeviceDisconnected(final ConnectionContext connectionContext) {
LOG.trace("onDeviceDisconnected method call for Node: {}", connectionContext.getNodeId());
final DeviceInfo deviceInfo = connectionContext.getDeviceInfo();
- final DeviceContext deviceCtx = this.deviceContexts.get(deviceInfo.getNodeId());
+ final DeviceContext deviceCtx = this.deviceContexts.get(deviceInfo);
if (null == deviceCtx) {
LOG.info("DeviceContext for Node {} was not found. Connection is terminated without OFP context suite.", deviceInfo.getNodeId());
public <T extends OFPContext> T gainContext(final DeviceInfo deviceInfo) {
return (T) deviceContexts.get(deviceInfo);
}
+
+ @Override
+ public ListenableFuture<Void> onClusterRoleChange(final DeviceInfo deviceInfo, final OfpRole role) {
+ DeviceContext deviceContext = conductor.getDeviceContext(deviceInfo);
+ LOG.trace("onClusterRoleChange {} for node:", role, deviceInfo.getNodeId());
+ if (OfpRole.BECOMEMASTER.equals(role)) {
+ return deviceContext.onDeviceTakeClusterLeadership();
+ }
+ return ((DeviceContextImpl)deviceContext).getTransactionChainManager().deactivateTransactionManager();
+ }
+
}
public void roleChangeOnDeviceTest4() {
when(deviceContext.getDeviceState()).thenReturn(deviceState);
when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext);
- when(deviceContext.onClusterRoleChange(OfpRole.BECOMEMASTER)).thenReturn(listenableFuture);
+ when(deviceManager.onClusterRoleChange(deviceInfo, OfpRole.BECOMEMASTER)).thenReturn(listenableFuture);
lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMEMASTER,false);
verify(statisticsManager).startScheduling(Mockito.<DeviceInfo>any());
}
public void roleChangeOnDeviceTest5() {
when(deviceContext.getDeviceState()).thenReturn(deviceState);
when(deviceManager.gainContext(deviceInfo)).thenReturn(deviceContext);
- when(deviceContext.onClusterRoleChange(OfpRole.BECOMESLAVE)).thenReturn(listenableFuture);
+ when(deviceManager.onClusterRoleChange(deviceInfo, OfpRole.BECOMESLAVE)).thenReturn(listenableFuture);
lifecycleConductor.roleChangeOnDevice(deviceInfo,true,OfpRole.BECOMESLAVE,false);
verify(statisticsManager).stopScheduling(Mockito.<DeviceInfo>any());
}
assertEquals(0, deviceContext.getDeviceMeterRegistry().getAllMeterIds().size());
}
-
- @Test
- public void testOnClusterRoleChange() throws Exception {
-
- // test call transactionChainManager.deactivateTransactionManager()
- Assert.assertNull(deviceContextSpy.onClusterRoleChange(OfpRole.NOCHANGE).get());
-
- Assert.assertNull(deviceContextSpy.onClusterRoleChange(OfpRole.NOCHANGE).get());
-
- final StatisticsContext statisticsContext = mock(StatisticsContext.class);
- deviceContextSpy.setStatisticsContext(statisticsContext);
-
- deviceContextSpy.onClusterRoleChange(OfpRole.BECOMEMASTER);
- verify(deviceContextSpy).onDeviceTakeClusterLeadership();
-
- Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
- deviceContextSpy.onClusterRoleChange(OfpRole.BECOMESLAVE);
- }
}
when(mockConnectionContext.getNodeId()).thenReturn(DUMMY_NODE_ID);
when(mockConnectionContext.getFeatures()).thenReturn(mockFeatures);
when(mockConnectionContext.getConnectionAdapter()).thenReturn(mockedConnectionAdapter);
- when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockConnectionContext);
when(mockConnectionContext.getDeviceInfo()).thenReturn(deviceInfo);
+ when(mockedDeviceContext.getPrimaryConnectionContext()).thenReturn(mockConnectionContext);
when(deviceInfo.getNodeId()).thenReturn(DUMMY_NODE_ID);
final Capabilities capabilitiesV13 = mock(Capabilities.class);
when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionContext);
when(deviceContext.getDeviceState()).thenReturn(deviceState);
- final ConcurrentHashMap<NodeId, DeviceContext> deviceContexts = getContextsCollection(deviceManager);
- deviceContexts.put(DUMMY_NODE_ID, deviceContext);
+ final ConcurrentHashMap<DeviceInfo, DeviceContext> deviceContexts = getContextsCollection(deviceManager);
+ deviceContexts.put(deviceInfo, deviceContext);
deviceManager.onDeviceDisconnected(connectionContext);
public void testClose() throws Exception {
final DeviceContext deviceContext = mock(DeviceContext.class);
final DeviceManagerImpl deviceManager = prepareDeviceManager();
- final ConcurrentHashMap<NodeId, DeviceContext> deviceContexts = getContextsCollection(deviceManager);
- deviceContexts.put(mockedNodeId, deviceContext);
+ final ConcurrentHashMap<DeviceInfo, DeviceContext> deviceContexts = getContextsCollection(deviceManager);
+ deviceContexts.put(deviceInfo, deviceContext);
Assert.assertEquals(1, deviceContexts.size());
deviceManager.close();
verify(deviceContext, Mockito.never()).close();
}
- private static ConcurrentHashMap<NodeId, DeviceContext> getContextsCollection(final DeviceManagerImpl deviceManager) throws NoSuchFieldException, IllegalAccessException {
+ private static ConcurrentHashMap<DeviceInfo, DeviceContext> getContextsCollection(final DeviceManagerImpl deviceManager) throws NoSuchFieldException, IllegalAccessException {
// HACK: contexts collection for testing shall be accessed in some more civilized way
final Field contextsField = DeviceManagerImpl.class.getDeclaredField("deviceContexts");
Assert.assertNotNull(contextsField);
contextsField.setAccessible(true);
- return (ConcurrentHashMap<NodeId, DeviceContext>) contextsField.get(deviceManager);
+ return (ConcurrentHashMap<DeviceInfo, DeviceContext>) contextsField.get(deviceManager);
}
}