- if (!ownershipChange.wasOwner() && ownershipChange.isOwner()) {
- // SLAVE -> MASTER - acquired transition lock
- LOG.debug("Acquired tx-lock for entity {}", ownershipChange.getEntity());
- roleContext.setTxLockOwned(true);
- final OfpRole role = roleContext.getDeviceState().getRole();
- Verify.verify(OfpRole.BECOMEMASTER.equals(roleContext.getPropagatingRole()),
- "Acquired tx-lock but current role = {}", role);
-
- switch (roleContext.getState()) {
- case STARTING:
- processingClosure = roleContext.onRoleChanged(OfpRole.BECOMESLAVE, OfpRole.BECOMEMASTER);
- // activate stats - accomplished automatically by chaging role in deviceState
- // collect initial dynamic data from device
- processingClosure = Futures.transform(processingClosure, new AsyncFunction<Void, Void>() {
- @Nullable
- @Override
- public ListenableFuture<Void> apply(@Nullable final Void aVoid) {
- deviceContext.getDeviceState().setRole(OfpRole.BECOMEMASTER);
- return DeviceInitializationUtils.initializeNodeInformation(
- deviceContext, switchFeaturesMandatory);
- }
- });
- break;
- case WORKING:
- // activate txChainManager, activate rpcs
- processingClosure = roleContext.onRoleChanged(OfpRole.BECOMESLAVE, OfpRole.BECOMEMASTER);
- // activate stats - accomplished automatically by chaging role in deviceState
- processingClosure = Futures.transform(processingClosure, new Function<Void, Void>() {
- @Nullable
- @Override
- public Void apply(@Nullable final Void aVoid) {
- deviceContext.getDeviceState().setRole(OfpRole.BECOMEMASTER);
- return null;
- }
- });
- break;
- //case TEARING_DOWN:
- default:
- //TODO: reconsider if there is really nothing to do when tearing down
- processingClosure = Futures.immediateFuture(null);
- break;
+ if (roleContext.isMainCandidateRegistered()) {
+ LOG.debug("Main-EntityOwnershipRegistration is active for entity type {} and node {}",
+ ownershipChange.getEntity().getType(), roleContext.getNodeId());
+ if (!ownershipChange.wasOwner() && ownershipChange.isOwner()) {
+ // SLAVE -> MASTER
+ LOG.debug("SLAVE to MASTER for node {}", roleContext.getNodeId());
+ if (roleContext.registerCandidate(roleContext.getTxEntity())) {
+ LOG.debug("Starting watching tx entity for node {}", roleContext.getNodeId());
+ watchingEntities.putIfAbsent(roleContext.getTxEntity(), roleContext);
+ }
+ } else if (ownershipChange.wasOwner() && !ownershipChange.isOwner()) {
+ // MASTER -> SLAVE
+ LOG.debug("MASTER to SLAVE for node {}", roleContext.getNodeId());
+ conductor.addOneTimeListenerWhenServicesChangesDone(this, roleContext.getNodeId());
+ makeDeviceRoleChange(OfpRole.BECOMESLAVE, roleContext, false);