Search in sources :

Example 1 with SetRoleInputBuilder

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

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

the class RoleContextImplTest method instantiateServiceInstance.

@Test
public void instantiateServiceInstance() throws Exception {
    roleContext.instantiateServiceInstance();
    verify(roleService).setRole(new SetRoleInputBuilder().setControllerRole(OfpRole.BECOMEMASTER).setNode(new NodeRef(deviceInfo.getNodeInstanceIdentifier())).build());
    verify(contextChainMastershipWatcher).onMasterRoleAcquired(deviceInfo, ContextChainMastershipState.MASTER_ON_DEVICE);
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) SetRoleInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInputBuilder) Test(org.junit.Test)

Example 3 with SetRoleInputBuilder

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

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

Aggregations

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