Search in sources :

Example 1 with OfpRole

use of org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole in project openflowplugin by opendaylight.

the class RoleContextImpl method sendRoleChangeToDevice.

private ListenableFuture<RpcResult<SetRoleOutput>> sendRoleChangeToDevice(final OfpRole newRole) {
    final Boolean isEqualRole = config.isEnableEqualRole();
    if (isEqualRole) {
        LOG.warn("Skip sending role change request to device {} as user enabled" + " equal role for controller", deviceInfo);
        return Futures.immediateFuture(null);
    }
    LOG.debug("Sending new role {} to device {}", newRole, deviceInfo);
    if (deviceInfo.getVersion() >= OFConstants.OFP_VERSION_1_3) {
        final SetRoleInput setRoleInput = new SetRoleInputBuilder().setControllerRole(newRole).setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier())).build();
        final Future<RpcResult<SetRoleOutput>> setRoleOutputFuture = roleService.setRole(setRoleInput);
        final TimerTask timerTask = timeout -> {
            if (!setRoleOutputFuture.isDone()) {
                LOG.warn("New role {} was not propagated to device {} during {} sec", newRole, deviceInfo, SET_ROLE_TIMEOUT);
                setRoleOutputFuture.cancel(true);
            }
        };
        timer.newTimeout(timerTask, SET_ROLE_TIMEOUT, TimeUnit.MILLISECONDS);
        return JdkFutureAdapters.listenInPoolThread(setRoleOutputFuture);
    }
    LOG.info("Device: {} with version: {} does not support role {}", deviceInfo, deviceInfo.getVersion(), newRole);
    return Futures.immediateFuture(null);
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) SetRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput) LoggerFactory(org.slf4j.LoggerFactory) OfpRole(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) AtomicReference(java.util.concurrent.atomic.AtomicReference) ContextChainMastershipWatcher(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipWatcher) HashSet(java.util.HashSet) ServiceGroupIdentifier(org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier) Future(java.util.concurrent.Future) RequestContextUtil(org.opendaylight.openflowplugin.impl.services.util.RequestContextUtil) OpenflowProviderConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.provider.config.rev160510.OpenflowProviderConfig) TimerTask(io.netty.util.TimerTask) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) Timeout(io.netty.util.Timeout) Logger(org.slf4j.Logger) RoleContext(org.opendaylight.openflowplugin.api.openflow.role.RoleContext) CancellationException(java.util.concurrent.CancellationException) ContextChainMastershipState(org.opendaylight.openflowplugin.api.openflow.lifecycle.ContextChainMastershipState) AbstractRequestContext(org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext) SalRoleService(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService) Collection(java.util.Collection) SetRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder) FutureCallback(com.google.common.util.concurrent.FutureCallback) SetRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput) OFConstants(org.opendaylight.openflowplugin.api.OFConstants) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) DeviceInfo(org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo) Futures(com.google.common.util.concurrent.Futures) HashedWheelTimer(io.netty.util.HashedWheelTimer) RequestContext(org.opendaylight.openflowplugin.api.openflow.device.RequestContext) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) SetRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder) TimerTask(io.netty.util.TimerTask) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) SetRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput)

Example 2 with OfpRole

use of org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.OfpRole in project openflowplugin by opendaylight.

the class RoleService method submitRoleChange.

public Future<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Short version, final BigInteger generationId) {
    LOG.info("submitRoleChange called for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
    final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
    roleRequestInputBuilder.setRole(toOFJavaRole(ofpRole));
    roleRequestInputBuilder.setVersion(version);
    roleRequestInputBuilder.setGenerationId(generationId);
    final ListenableFuture<RpcResult<RoleRequestOutput>> roleListenableFuture = handleServiceCall(roleRequestInputBuilder);
    final SettableFuture<RpcResult<SetRoleOutput>> finalFuture = SettableFuture.create();
    Futures.addCallback(roleListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {

        @Override
        public void onSuccess(@Nonnull final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
            LOG.info("submitRoleChange onSuccess for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
            final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
            final Collection<RpcError> rpcErrors = roleRequestOutputRpcResult.getErrors();
            if (roleRequestOutput != null) {
                final SetRoleOutputBuilder setRoleOutputBuilder = new SetRoleOutputBuilder();
                setRoleOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(roleRequestOutput.getXid())));
                finalFuture.set(RpcResultBuilder.<SetRoleOutput>success().withResult(setRoleOutputBuilder.build()).build());
            } else if (rpcErrors != null) {
                LOG.trace("roleRequestOutput is null , rpcErrors={}", rpcErrors);
                for (RpcError rpcError : rpcErrors) {
                    LOG.warn("RpcError on submitRoleChange for {}: {}", deviceContext.getPrimaryConnectionContext().getNodeId(), rpcError.toString());
                }
                finalFuture.set(RpcResultBuilder.<SetRoleOutput>failed().withRpcErrors(rpcErrors).build());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.error("submitRoleChange onFailure for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole, throwable);
            finalFuture.setException(throwable);
        }
    }, MoreExecutors.directExecutor());
    return finalFuture;
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) TransactionId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId) SetRoleOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutputBuilder) SetRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput) RoleRequestInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInputBuilder) Collection(java.util.Collection)

Aggregations

Collection (java.util.Collection)2 SetRoleOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Timeout (io.netty.util.Timeout)1 TimerTask (io.netty.util.TimerTask)1 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 CancellationException (java.util.concurrent.CancellationException)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 ServiceGroupIdentifier (org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier)1