use of org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput 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());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.role.service.rev150727.SetRoleInput 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);
}
Aggregations