Search in sources :

Example 1 with SetRoleOutput

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

the class SalRoleServiceImplTest method testSetRole.

@Test
public void testSetRole() throws Exception {
    RoleRequestOutput roleRequestOutput = (new RoleRequestOutputBuilder()).setXid(testXid).setGenerationId(BigInteger.valueOf(1)).build();
    ListenableFuture<RpcResult<RoleRequestOutput>> futureOutput = RpcResultBuilder.<RoleRequestOutput>success().withResult(roleRequestOutput).buildFuture();
    Mockito.when(mockRequestContext.getFuture()).thenReturn(futureOutput);
    SalRoleService salRoleService = new SalRoleServiceImpl(mockRequestContextStack, mockDeviceContext);
    SetRoleInput setRoleInput = new SetRoleInputBuilder().setControllerRole(OfpRole.BECOMESLAVE).setNode(nodeRef).build();
    Future<RpcResult<SetRoleOutput>> future = salRoleService.setRole(setRoleInput);
    RpcResult<SetRoleOutput> roleOutputRpcResult = future.get(5, TimeUnit.SECONDS);
    assertNotNull("RpcResult from future cannot be null.", roleOutputRpcResult);
    assertTrue("RpcResult from future is not successful.", roleOutputRpcResult.isSuccessful());
    SetRoleOutput setRoleOutput = roleOutputRpcResult.getResult();
    assertNotNull(setRoleOutput);
    assertEquals(BigInteger.valueOf(testXid), setRoleOutput.getTransactionId().getValue());
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RoleRequestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder) SetRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder) SetRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) SetRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput) SalRoleService(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService) Test(org.junit.Test)

Example 2 with SetRoleOutput

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

the class SalRoleServiceImplTest method testDuplicateRoles.

@Test
public void testDuplicateRoles() throws Exception {
    // set role to slave
    RoleRequestOutput roleRequestOutput = (new RoleRequestOutputBuilder()).setXid(testXid).setGenerationId(BigInteger.valueOf(1)).build();
    ListenableFuture<RpcResult<RoleRequestOutput>> futureOutput = RpcResultBuilder.<RoleRequestOutput>success().withResult(roleRequestOutput).buildFuture();
    Mockito.when(mockRequestContext.getFuture()).thenReturn(futureOutput);
    SalRoleService salRoleService = new SalRoleServiceImpl(mockRequestContextStack, mockDeviceContext);
    SetRoleInput setRoleInput = new SetRoleInputBuilder().setControllerRole(OfpRole.BECOMESLAVE).setNode(nodeRef).build();
    Future<RpcResult<SetRoleOutput>> future = salRoleService.setRole(setRoleInput);
    RpcResult<SetRoleOutput> roleOutputRpcResult = future.get(5, TimeUnit.SECONDS);
    assertNotNull("RpcResult from future cannot be null.", roleOutputRpcResult);
    assertTrue("RpcResult from future is not successful.", roleOutputRpcResult.isSuccessful());
    SetRoleOutput setRoleOutput = roleOutputRpcResult.getResult();
    assertNotNull(setRoleOutput);
    assertEquals(BigInteger.valueOf(testXid), setRoleOutput.getTransactionId().getValue());
    // make another role change with the same role - slave
    Future<RpcResult<SetRoleOutput>> future2 = salRoleService.setRole(setRoleInput);
    RpcResult<SetRoleOutput> roleOutputRpcResult2 = future2.get(5, TimeUnit.SECONDS);
    assertNotNull("RpcResult from future cannot be null.", roleOutputRpcResult2);
    assertTrue("RpcResult from future for duplicate role is not successful.", roleOutputRpcResult2.isSuccessful());
}
Also used : RoleRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput) RoleRequestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder) SetRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder) SetRoleOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) SetRoleInput(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput) SalRoleService(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService) Test(org.junit.Test)

Example 3 with SetRoleOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput 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 4 with SetRoleOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput 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

SetRoleOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleOutput)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 RoleRequestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput)3 SalRoleService (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SalRoleService)3 SetRoleInput (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput)3 SetRoleInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder)3 Collection (java.util.Collection)2 Test (org.junit.Test)2 RoleRequestOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutputBuilder)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