use of org.opendaylight.yangtools.yang.common.RpcError in project openflowplugin by opendaylight.
the class MockPlugin method getSwitchFeatures.
protected void getSwitchFeatures() {
GetFeaturesInputBuilder featuresBuilder = new GetFeaturesInputBuilder();
featuresBuilder.setVersion((short) 4);
featuresBuilder.setXid(3L);
GetFeaturesInput featuresInput = featuresBuilder.build();
try {
LOGGER.debug("Requesting features ");
RpcResult<GetFeaturesOutput> rpcResult = adapter.getFeatures(featuresInput).get(2500, TimeUnit.MILLISECONDS);
if (rpcResult.isSuccessful()) {
byte[] byteArray = rpcResult.getResult().getDatapathId().toByteArray();
LOGGER.debug("DatapathId: {}", Arrays.toString(byteArray));
} else {
RpcError rpcError = rpcResult.getErrors().iterator().next();
LOGGER.warn("rpcResult failed", rpcError.getCause());
}
} catch (InterruptedException | ExecutionException | TimeoutException e) {
LOGGER.error("getSwitchFeatures() exception caught: ", e.getMessage(), e);
}
}
use of org.opendaylight.yangtools.yang.common.RpcError in project lispflowmapping by opendaylight.
the class MappingServiceTest method getMappingTest_withNullMapRecord.
/**
* Tests {@link MappingService#getMapping} method with null MappingRecord.
*/
@Test
public void getMappingTest_withNullMapRecord() throws ExecutionException, InterruptedException {
// input
final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(null);
final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "data-missing", "No mapping was found in the mapping database").build();
final RpcError error = rpc.getErrors().iterator().next();
// result
final Future<RpcResult<GetMappingOutput>> result = (mappingService.getMapping(getMappingInput));
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 lispflowmapping by opendaylight.
the class MappingServiceTest method updateKeyTest_withNullMapAuthkey.
/**
* Tests {@link MappingService#updateKey} method with null MappingAuthkey.
*/
@Test
public void updateKeyTest_withNullMapAuthkey() throws ExecutionException, InterruptedException {
final UpdateKeyInput updateKeyInput = new UpdateKeyInputBuilder().setEid(IPV4_EID).build();
Mockito.when(mappingSystem.getAuthenticationKey(IPV4_EID)).thenReturn(null);
// input
final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.PROTOCOL, "data-missing", "Key doesn't exist! Please use add-key if you want to create a new authentication key.").build();
final RpcError error = rpc.getErrors().iterator().next();
// result
final Future<RpcResult<Void>> result = mappingService.updateKey(updateKeyInput);
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 lispflowmapping by opendaylight.
the class MappingServiceTest method getKeyTest_withNullMappingAuthkey.
/**
* Tests {@link MappingService#getKey} method with null MappingAuthkey.
*/
@Test
public void getKeyTest_withNullMappingAuthkey() throws ExecutionException, InterruptedException {
// input
final GetKeyInput getKeyInput = new GetKeyInputBuilder().setEid(IPV4_EID).build();
Mockito.when(mappingSystem.getAuthenticationKey(getKeyInput.getEid())).thenReturn(null);
final RpcResult<Object> rpc = RpcResultBuilder.failed().withError(RpcError.ErrorType.APPLICATION, "data-missing", "Key was not found in the mapping database").build();
final RpcError error = rpc.getErrors().iterator().next();
// result
final Future<RpcResult<GetKeyOutput>> result = mappingService.getKey(getKeyInput);
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 controller by opendaylight.
the class PrefixShardHandler method onCreatePrefixShard.
public ListenableFuture<RpcResult<Void>> onCreatePrefixShard(final CreatePrefixShardInput input) {
final SettableFuture<RpcResult<Void>> future = SettableFuture.create();
final CompletionStage<DistributedShardRegistration> completionStage;
final YangInstanceIdentifier identifier = serializer.toYangInstanceIdentifier(input.getPrefix());
try {
completionStage = shardFactory.createDistributedShard(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, identifier), input.getReplicas().stream().map(MemberName::forName).collect(Collectors.toList()));
completionStage.thenAccept(registration -> {
LOG.debug("Shard[{}] created successfully.", identifier);
registrations.put(identifier, registration);
final ListenableFuture<Void> ensureFuture = ensureListExists();
Futures.addCallback(ensureFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
LOG.debug("Initial list write successful.");
future.set(RpcResultBuilder.<Void>success().build());
}
@Override
public void onFailure(final Throwable throwable) {
LOG.warn("Shard[{}] creation failed:", identifier, throwable);
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Shard creation failed", "cluster-test-app", "", throwable);
future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
}
}, MoreExecutors.directExecutor());
});
completionStage.exceptionally(throwable -> {
LOG.warn("Shard[{}] creation failed:", identifier, throwable);
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Shard creation failed", "cluster-test-app", "", throwable);
future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
return null;
});
} catch (final DOMDataTreeShardingConflictException e) {
LOG.warn("Unable to register shard for: {}.", identifier);
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Sharding conflict", "cluster-test-app", "", e);
future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
}
return future;
}
Aggregations