use of org.opendaylight.yangtools.yang.common.RpcError 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;
}
use of org.opendaylight.yangtools.yang.common.RpcError in project lispflowmapping by opendaylight.
the class MappingServiceTest method addKeyTest.
/**
* Tests {@link MappingService#addKey} method.
*/
@Test
public void addKeyTest() throws ExecutionException, InterruptedException {
final MappingAuthkey mappingAuthkey = new MappingAuthkeyBuilder().setKeyString("dummy-password").setKeyType(2).build();
final AddKeyInput addKeyInput = new AddKeyInputBuilder().setMappingAuthkey(mappingAuthkey).setEid(IPV4_EID).build();
Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(MAPPING_AUTHKEY);
// input
final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-exists", "Key already exists! Please use update-key if you want to change it.").build();
// equals() not implemented int RpcError
final RpcError error = rpc.getErrors().iterator().next();
// result
final Future<RpcResult<Void>> result = mappingService.addKey(addKeyInput);
final RpcError errorResult = result.get().getErrors().iterator().next();
assertEquals(1, result.get().getErrors().size());
assertEquals(error.getMessage(), errorResult.getMessage());
assertEquals(error.getApplicationTag(), errorResult.getApplicationTag());
assertEquals(error.getCause(), errorResult.getCause());
assertEquals(error.getErrorType(), errorResult.getErrorType());
assertEquals(error.getInfo(), errorResult.getInfo());
assertEquals(error.getTag(), errorResult.getTag());
assertEquals(error.getSeverity(), errorResult.getSeverity());
assertEquals(rpc.getResult(), result.get().getResult());
assertEquals(rpc.isSuccessful(), result.get().isSuccessful());
}
use of org.opendaylight.yangtools.yang.common.RpcError in project genius by opendaylight.
the class IdManagerTest method requestIdsConcurrently.
// OK as exceptionInExecutor can't be Exception & AssertionFailedError
@SuppressWarnings("checkstyle:IllegalThrows")
private void requestIdsConcurrently(boolean isSameKey) throws Throwable {
int numberOfTasks = 3;
CountDownLatch latch = new CountDownLatch(numberOfTasks);
Set<Long> idSet = Sets.newConcurrentHashSet();
ExecutorService executor = Executors.newCachedThreadPool("requestIdsConcurrently()", LOG);
AtomicReference<Throwable> exceptionInExecutorAtomic = new AtomicReference<>();
for (int i = 0; i < numberOfTasks; i++) {
final String idKey;
if (isSameKey) {
idKey = TEST_KEY1;
} else {
idKey = TEST_KEY1 + i;
}
executor.execute(() -> {
// Any exception thrown inside this background thread will not cause the test to fail
// so you cannot use assert* here but must set the exceptionInExecutor which is checked after
Future<RpcResult<AllocateIdOutput>> result;
result = idManagerService.allocateId(new AllocateIdInputBuilder().setPoolName(ID_POOL_NAME).setIdKey(idKey).build());
try {
if (result.get().isSuccessful()) {
Long idValue = result.get().getResult().getIdValue();
idSet.add(idValue);
if (idValue > ID_LOW + BLOCK_SIZE) {
exceptionInExecutorAtomic.set(new AssertionFailedError("idValue <= ID_LOW + BLOCK_SIZE"));
}
} else {
RpcError error = result.get().getErrors().iterator().next();
if (!error.getCause().getMessage().contains("Ids exhausted for pool : " + ID_POOL_NAME)) {
exceptionInExecutorAtomic.set(error.getCause());
}
}
} catch (InterruptedException | ExecutionException e) {
exceptionInExecutorAtomic.set(e);
} finally {
latch.countDown();
}
});
}
if (!latch.await(13, SECONDS)) {
fail("latch.await(13, SECONDS) timed out :(");
}
Throwable exceptionInExecutor = exceptionInExecutorAtomic.get();
if (exceptionInExecutor != null) {
throw exceptionInExecutor;
}
if (isSameKey) {
assertEquals(1, idSet.size());
} else {
assertEquals(numberOfTasks, idSet.size());
}
}
use of org.opendaylight.yangtools.yang.common.RpcError in project genius by opendaylight.
the class TestFutureRpcResults method assertRpcErrorCause.
private static <T> void assertRpcErrorCause(RpcResult<T> rpcResult, Class<?> expected1stExceptionClass, String expected1stRpcErrorMessage) {
assertThat(rpcResult.isSuccessful()).named("rpcResult.isSuccessful").isFalse();
Collection<RpcError> errors = rpcResult.getErrors();
assertThat(errors).named("rpcResult.errors").hasSize(1);
RpcError error1 = errors.iterator().next();
assertThat(error1.getErrorType()).named("rpcResult.errors[0].errorType").isEqualTo(ErrorType.APPLICATION);
assertThat(error1.getMessage()).named("rpcResult.errors[0].message").isEqualTo(expected1stRpcErrorMessage);
if (error1.getCause() != null) {
// Check needed because FutureRpcResults does not propagate cause if OperationFailedException
assertThat(error1.getCause()).named("rpcResult.errors[0].cause").isInstanceOf(expected1stExceptionClass);
}
}
Aggregations