- /*
- * we don't have active TxManager so anything will not be stored to DS yet, but we have
- * check all NodeInformation for statistics otherwise statistics will not contains
- * all possible MultipartTypes for polling in StatTypeList
- */
- private ListenableFuture<Void> asyncClusterRoleChange() {
- if (statisticsContext == null) {
- final String errMsg = String.format("DeviceCtx %s is up but we are missing StatisticsContext", deviceState.getNodeId());
- 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", deviceState.getNodeId());
- LOG.warn(errMsg);
- return Futures.immediateFailedFuture(new IllegalStateException(errMsg));
- }
-
- final InstanceIdentifier<FlowCapableNode> ofNodeII = deviceState.getNodeInstanceIdentifier()
- .augmentation(FlowCapableNode.class);
- final ReadOnlyTransaction readTx = getReadTransaction();
- final CheckedFuture<Optional<FlowCapableNode>, ReadFailedException> readOfNodeFuture = readTx.read(
- LogicalDatastoreType.OPERATIONAL, ofNodeII);
-
- final ListenableFuture<Void> nodeInitInfoFuture = Futures.transform(readOfNodeFuture,
- new AsyncFunction<Optional<FlowCapableNode>, Void>() {
- @Override
- public ListenableFuture<Void> apply(final Optional<FlowCapableNode> input) throws Exception {
- if (!input.isPresent() || input.get().getTable() == null || input.get().getTable().isEmpty()) {
- /* Last master close fail scenario so we would like to activate TxManager */
- LOG.debug("Operational DS for Device {} has to be replaced", deviceState.getNodeId());
- getDeviceState().setDeviceSynchronized(false);
- transactionChainManager.activateTransactionManager();
- }
- return DeviceInitializationUtils.initializeNodeInformation(DeviceContextImpl.this, switchFeaturesMandatory);
- }
- });
-
- final ListenableFuture<Boolean> statPollFuture = Futures.transform(nodeInitInfoFuture,
- new AsyncFunction<Void, Boolean>() {
-
- @Override
- public ListenableFuture<Boolean> apply(final Void input) throws Exception {
- getStatisticsContext().statListForCollectingInitialization();
- if (getDeviceState().deviceSynchronized()) {
- return Futures.immediateFuture(Boolean.TRUE);
- }
- 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);
- transactionChainManager.clearUnsubmittedTransaction();
- throw new IllegalStateException(errMsg);
- }
- if (!input.booleanValue()) {
- final String errMsg = String.format("Get Initial Device %s information fails",
- getDeviceState().getNodeId());
- LOG.warn(errMsg);
- transactionChainManager.clearUnsubmittedTransaction();
- throw new IllegalStateException(errMsg);
- }
- LOG.debug("Get Initial Device {} information is successful", getDeviceState().getNodeId());
- getDeviceState().setDeviceSynchronized(true);
- transactionChainManager.activateTransactionManager();
- MdSalRegistrationUtils.registerMasterServices(getRpcContext(), DeviceContextImpl.this, OfpRole.BECOMEMASTER);
- getRpcContext().registerStatCompatibilityServices();
- initialSubmitTransaction();
- getDeviceState().setStatisticsPollingEnabledProp(true);
- return null;
- }
- });