*/
void onClusterRoleChange(@CheckForNull OfpRole role);
- /**
- * Same as {@link DeviceContext#onClusterRoleChange(OfpRole)} but it should be call for new
- * connection initialization only, because submit transaction is not active in this time.
- * @param role - NewRole expect to be {@link OfpRole#BECOMESLAVE} or {@link OfpRole#BECOMEMASTER}
- */
- void onInitClusterRoleChange(@CheckForNull final OfpRole role);
-
/**
* Method creates put operation using provided data in underlying transaction chain.
*/
import java.util.concurrent.Future;
import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
-import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
import org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole;
/**
* Created by kramesha on 9/12/15.
*/
-public interface RoleContext extends RoleChangeListener, DeviceContextClosedHandler, RequestContextStack {
+public interface RoleContext extends RoleChangeListener, RequestContextStack {
/**
* Initialization method is responsible for a registration of
@Override
public void onClusterRoleChange(@CheckForNull final OfpRole role) {
- this.onClusterRoleChange(role, true);
- }
-
- @Override
- public void onInitClusterRoleChange(@CheckForNull final OfpRole role) {
- this.onClusterRoleChange(role, false);
+ LOG.debug("onClusterRoleChange {} for node:", role, deviceState.getNodeId());
+ Preconditions.checkArgument(role != null);
+ if (OfpRole.BECOMEMASTER.equals(role)) {
+ transactionChainManager.activateTransactionManager();
+ } else if (OfpRole.BECOMESLAVE.equals(role)) {
+ transactionChainManager.deactivateTransactionManager();
+ } else {
+ LOG.warn("Unknow OFCluster Role {} for Node {}", role, deviceState.getNodeId());
+ }
}
@Override
public ExtensionConverterProvider getExtensionConverterProvider() {
return extensionConverterProvider;
}
-
- private void onClusterRoleChange(@CheckForNull final OfpRole role, final boolean enableSubmit) {
- LOG.debug("onClusterRoleChange {} for node:", role, deviceState.getNodeId());
- Preconditions.checkArgument(role != null);
- if (OfpRole.BECOMESLAVE.equals(role)) {
- transactionChainManager.activateTransactionManager(enableSubmit);
- } else if (OfpRole.BECOMEMASTER.equals(role)) {
- transactionChainManager.deactivateTransactionManager();
- } else {
- LOG.warn("Unknow OFCluster Role {} for Node {}", role, deviceState.getNodeId());
- }
- }
}
* Method change status for TxChainManager to {@link TransactionChainManagerStatus#WORKING} and it has to make
* registration for this class instance as {@link TransactionChainListener} to provide possibility a make DS
* transactions. Call this method for MASTER role only.
- * @param enableSubmit - marker to be sure a WriteTransaction submit is not blocking
- * (Blocking write is used for initialization part only)
*/
- public void activateTransactionManager(final boolean enableSubmit) {
- LOG.trace("activetTransactionManager for node {} transaction submit is set to {}", deviceState.getNodeId(), enableSubmit);
+ public void activateTransactionManager() {
+ LOG.trace("activetTransactionManaager for node {} transaction submit is set to {}", deviceState.getNodeId());
synchronized (txLock) {
if (TransactionChainManagerStatus.SLEEPING.equals(transactionChainManagerStatus)) {
LOG.debug("Transaction Factory create {}", deviceState.getNodeId());
Preconditions.checkState(wTx == null, "We have some unexpected WriteTransaction.");
this.transactionChainManagerStatus = TransactionChainManagerStatus.WORKING;
createTxChain();
- this.submitIsEnabled = enableSubmit;
} else {
LOG.debug("Transaction is active {}", deviceState.getNodeId());
}
return false;
}
synchronized (txLock) {
- Preconditions.checkState(TransactionChainManagerStatus.WORKING.equals(transactionChainManagerStatus),
- "we have here Uncompleted Transaction for node {} and we are not MASTER", nodeII);
if (wTx == null) {
LOG.trace("nothing to commit - submit returns true");
return true;
}
+ Preconditions.checkState(TransactionChainManagerStatus.WORKING.equals(transactionChainManagerStatus),
+ "we have here Uncompleted Transaction for node {} and we are not MASTER", nodeII);
final CheckedFuture<Void, TransactionCommitFailedException> submitFuture = wTx.submit();
Futures.addCallback(submitFuture, new FutureCallback<Void>() {
@Override
@Nullable
private WriteTransaction getTransactionSafely() {
- if (wTx == null && !TransactionChainManagerStatus.SHUTTING_DOWN.equals(transactionChainManagerStatus)) {
+ if (wTx == null && TransactionChainManagerStatus.WORKING.equals(transactionChainManagerStatus)) {
synchronized (txLock) {
- if (wTx == null && txChainFactory != null) {
- wTx = txChainFactory.newWriteOnlyTransaction();
+ if (wTx == null && TransactionChainManagerStatus.WORKING.equals(transactionChainManagerStatus)) {
+ if (wTx == null && txChainFactory != null) {
+ wTx = txChainFactory.newWriteOnlyTransaction();
+ }
}
}
}
if (!initRoleChangeFuture.isDone()) {
LOG.debug("Initialization Role for entity {} is chosed {}", entity, newRole);
+ // we don't want to wait for Device RoleChangeResponse in initial phase
+ deviceContext.onClusterRoleChange(newRole);
initRoleChangeFuture.set(newRole);
- deviceContext.onInitClusterRoleChange(newRole);
}
LOG.debug("Role change received from ownership listener from {} to {} for device:{}", oldRole, newRole,
}
}
- @Override
- public void onDeviceContextClosed(final DeviceContext deviceContext) {
- try {
- LOG.debug("onDeviceContextClosed called");
- this.close();
- } catch (final Exception e) {
- LOG.error("Exception in onDeviceContextClosed of RoleContext", e);
- }
- }
-
@Override
public Entity getEntity() {
return entity;
final RoleContext roleContext = new RoleContextImpl(deviceContext, rpcProviderRegistry, entityOwnershipService, openflowOwnershipListener);
// if the device context gets closed (mostly on connection close), we would need to cleanup
- deviceContext.addDeviceContextClosedHandler(roleContext);
+ deviceContext.addDeviceContextClosedHandler(this);
Verify.verify(contexts.putIfAbsent(deviceContext, roleContext) == null,
"RoleCtx for master Node {} is still not close.", deviceContext.getDeviceState().getNodeId());
OfpRole role = null;
path = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId));
Mockito.when(writeTx.submit()).thenReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null));
- txChainManager.activateTransactionManager(false);
+ txChainManager.activateTransactionManager();
}
@After
public void testSubmitTransaction() throws Exception {
final Node data = new NodeBuilder().setId(nodeId).build();
txChainManager.enableSubmit();
- txChainManager.activateTransactionManager(true);
+ txChainManager.activateTransactionManager();
txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data);
- txChainManager.activateTransactionManager(true);
+ txChainManager.activateTransactionManager();
txChainManager.submitWriteTransaction();
Mockito.verify(txChain).newWriteOnlyTransaction();