- public ListenableFuture<Void> onClusterRoleChange(final OfpRole oldRole, @CheckForNull final OfpRole role) {
- LOG.trace("onClusterRoleChange {} for node:", role, nodeId);
- Preconditions.checkArgument(role != null);
- if (role.equals(oldRole)) {
- LOG.debug("Demanded role change for device {} is not changed. OldRole: {}, NewRole {}", nodeId, oldRole, role);
- return Futures.immediateFuture(null);
- }
- if (OfpRole.BECOMEMASTER.equals(role)) {
- return onDeviceTakeClusterLeadership();
- } else if (OfpRole.BECOMESLAVE.equals(role)) {
- return onDeviceLostClusterLeadership();
- } else {
- LOG.warn("Unknown OFCluster Role {} for Node {}", role, nodeId);
- if (null != rpcContext) {
- MdSalRegistrationUtils.unregisterServices(rpcContext);
- }
- return transactionChainManager.deactivateTransactionManager();
- }
- }
-
- @Override
- public ListenableFuture<Void> onDeviceLostClusterLeadership() {
- LOG.trace("onDeviceLostClusterLeadership for node: {}", nodeId);
- if (null != rpcContext) {
- MdSalRegistrationUtils.registerSlaveServices(rpcContext, OfpRole.BECOMESLAVE);
- }
- return transactionChainManager.deactivateTransactionManager();
- }
-
- @Override
- public ListenableFuture<Void> onDeviceTakeClusterLeadership() {
- LOG.trace("onDeviceTakeClusterLeadership for node: {}", nodeId);
- /* validation */
- if (statisticsContext == null) {
- final String errMsg = String.format("DeviceCtx %s is up but we are missing StatisticsContext", nodeId);
- LOG.warn(errMsg);
- return Futures.immediateFailedFuture(new IllegalStateException(errMsg));
- }
- if (rpcContext == null) {
- final String errMsg = String.format("DeviceCtx %s is up but we are missing RpcContext", nodeId);
- LOG.warn(errMsg);
- return Futures.immediateFailedFuture(new IllegalStateException(errMsg));
- }
- /* Routed RPC registration */
- MdSalRegistrationUtils.registerMasterServices(getRpcContext(), DeviceContextImpl.this, OfpRole.BECOMEMASTER);
- getRpcContext().registerStatCompatibilityServices();
-
- /* Prepare init info collecting */
- getDeviceState().setDeviceSynchronized(false);
- transactionChainManager.activateTransactionManager();
- /* Init Collecting NodeInfo */
- final ListenableFuture<Void> initCollectingDeviceInfo = DeviceInitializationUtils.initializeNodeInformation(
- DeviceContextImpl.this, switchFeaturesMandatory);
- /* Init Collecting StatInfo */
- final ListenableFuture<Boolean> statPollFuture = Futures.transform(initCollectingDeviceInfo,
- new AsyncFunction<Void, Boolean>() {
-
- @Override
- public ListenableFuture<Boolean> apply(@Nonnull final Void input) throws Exception {
- getStatisticsContext().statListForCollectingInitialization();
- return getStatisticsContext().gatherDynamicData();
- }
- });
-
- return Futures.transform(statPollFuture, new Function<Boolean, Void>() {
-
- @Override
- public Void apply(final Boolean input) {
- if (ConnectionContext.CONNECTION_STATE.RIP.equals(getPrimaryConnectionContext().getConnectionState())) {
- final String errMsg = String.format("We lost connection for Device %s, context has to be closed.",
- getDeviceState().getNodeId());
- LOG.warn(errMsg);
- throw new IllegalStateException(errMsg);
- }
- if (!input) {
- final String errMsg = String.format("Get Initial Device %s information fails",
- getDeviceState().getNodeId());
- LOG.warn(errMsg);
- throw new IllegalStateException(errMsg);
- }
- LOG.debug("Get Initial Device {} information is successful", nodeId);
- getDeviceState().setDeviceSynchronized(true);
- initialSubmitTransaction();
- getDeviceState().setStatisticsPollingEnabledProp(true);
- return null;
- }
- });