use of org.opendaylight.yangtools.yang.common.RpcError in project controller by opendaylight.
the class PrefixShardHandler method onRemovePrefixShard.
public ListenableFuture<RpcResult<Void>> onRemovePrefixShard(final RemovePrefixShardInput input) {
final YangInstanceIdentifier identifier = serializer.toYangInstanceIdentifier(input.getPrefix());
final DistributedShardRegistration registration = registrations.get(identifier);
if (registration == null) {
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "registration-missing", "No shard registered at this prefix.");
return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withRpcError(error).build());
}
final SettableFuture<RpcResult<Void>> future = SettableFuture.create();
final CompletionStage<Void> close = registration.close();
close.thenRun(() -> future.set(RpcResultBuilder.<Void>success().build()));
close.exceptionally(throwable -> {
LOG.warn("Shard[{}] removal failed:", identifier, throwable);
final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "remove-shard-failed", "Shard removal failed", "cluster-test-app", "", throwable);
future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
return null;
});
return future;
}
use of org.opendaylight.yangtools.yang.common.RpcError in project controller by opendaylight.
the class RpcServiceAdapter method transformFuture.
private static ListenableFuture<RpcResult<?>> transformFuture(final SchemaPath rpc, final ListenableFuture<DOMRpcResult> domFuture, final BindingNormalizedNodeSerializer codec) {
return Futures.transform(domFuture, input -> {
final NormalizedNode<?, ?> domData = input.getResult();
final DataObject bindingResult;
if (domData != null) {
final SchemaPath rpcOutput = rpc.createChild(QName.create(rpc.getLastComponent(), "output"));
bindingResult = codec.fromNormalizedNodeRpcData(rpcOutput, (ContainerNode) domData);
} else {
bindingResult = null;
}
// DOMRpcResult does not have a notion of success, hence we have to reverse-engineer it by looking
// at reported errors and checking whether they are just warnings.
final Collection<RpcError> errors = input.getErrors();
return RpcResult.class.cast(RpcResultBuilder.status(errors.stream().noneMatch(error -> error.getSeverity() == ErrorSeverity.ERROR)).withResult(bindingResult).withRpcErrors(errors).build());
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.yangtools.yang.common.RpcError in project controller by opendaylight.
the class MdsalLowLevelTestProvider method unsubscribeYnl.
@Override
public Future<RpcResult<UnsubscribeYnlOutput>> unsubscribeYnl(final UnsubscribeYnlInput input) {
LOG.debug("Received unsubscribe-ynl, input: {}", input);
if (!ynlRegistrations.containsKey(input.getId())) {
final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration", "No ynl listener with this id registered.");
final RpcResult<UnsubscribeYnlOutput> result = RpcResultBuilder.<UnsubscribeYnlOutput>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
}
final ListenerRegistration<YnlListener> reg = ynlRegistrations.remove(input.getId());
final UnsubscribeYnlOutput output = reg.getInstance().getOutput();
reg.close();
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeYnlOutput>success().withResult(output).build());
}
use of org.opendaylight.yangtools.yang.common.RpcError in project controller by opendaylight.
the class MdsalLowLevelTestProvider method unsubscribeDtcl.
@Override
public Future<RpcResult<UnsubscribeDtclOutput>> unsubscribeDtcl() {
LOG.debug("Received unsubscribe-dtcl");
if (idIntsListener == null || dtclReg == null) {
final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Dtcl missing.", "No DataTreeChangeListener registered.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
try {
idIntsListener.tryFinishProcessing().get(120, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "resource-denied-transport", "Unable to finish notification processing in 120 seconds.", "clustering-it", "clustering-it", e);
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
dtclReg.close();
dtclReg = null;
if (!idIntsListener.hasTriggered()) {
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" + "any notifications.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
final DOMDataReadOnlyTransaction rTx = domDataBroker.newReadOnlyTransaction();
try {
final Optional<NormalizedNode<?, ?>> readResult = rTx.read(CONTROLLER_CONFIG, WriteTransactionsHandler.ID_INT_YID).checkedGet();
if (!readResult.isPresent()) {
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Final read empty.", "No data read from id-ints list.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
return Futures.immediateFuture(RpcResultBuilder.success(new UnsubscribeDtclOutputBuilder().setCopyMatches(idIntsListener.checkEqual(readResult.get()))).build());
} catch (final ReadFailedException e) {
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Read failed.", "Final read from id-ints failed.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
}
}
use of org.opendaylight.yangtools.yang.common.RpcError in project controller by opendaylight.
the class MdsalLowLevelTestProvider method unsubscribeDdtl.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<UnsubscribeDdtlOutput>> unsubscribeDdtl() {
LOG.debug("Received unsubscribe-ddtl.");
if (idIntsDdtl == null || ddtlReg == null) {
final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "Ddtl missing.", "No DOMDataTreeListener registered.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withRpcError(error).build());
}
try {
idIntsDdtl.tryFinishProcessing().get(120, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "resource-denied-transport", "Unable to finish notification processing in 120 seconds.", "clustering-it", "clustering-it", e);
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withRpcError(error).build());
}
ddtlReg.close();
ddtlReg = null;
if (!idIntsDdtl.hasTriggered()) {
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" + "any notifications.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withRpcError(error).build());
}
final String shardName = ClusterUtils.getCleanShardName(ProduceTransactionsHandler.ID_INTS_YID);
LOG.debug("Creating distributed datastore client for shard {}", shardName);
final ActorContext actorContext = configDataStore.getActorContext();
final Props distributedDataStoreClientProps = SimpleDataStoreClientActor.props(actorContext.getCurrentMemberName(), "Shard-" + shardName, actorContext, shardName);
final ActorRef clientActor = actorSystem.actorOf(distributedDataStoreClientProps);
final DataStoreClient distributedDataStoreClient;
try {
distributedDataStoreClient = SimpleDataStoreClientActor.getDistributedDataStoreClient(clientActor, 30, TimeUnit.SECONDS);
} catch (RuntimeException e) {
LOG.error("Failed to get actor for {}", distributedDataStoreClientProps, e);
clientActor.tell(PoisonPill.getInstance(), noSender());
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Unable to create ds client for read.", "Unable to create ds client for read.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withRpcError(error).build());
}
final ClientLocalHistory localHistory = distributedDataStoreClient.createLocalHistory();
final ClientTransaction tx = localHistory.createTransaction();
final CheckedFuture<Optional<NormalizedNode<?, ?>>, org.opendaylight.mdsal.common.api.ReadFailedException> read = tx.read(YangInstanceIdentifier.of(ProduceTransactionsHandler.ID_INT));
tx.abort();
localHistory.close();
try {
final Optional<NormalizedNode<?, ?>> optional = read.checkedGet();
if (!optional.isPresent()) {
LOG.warn("Final read from client is empty.");
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Read failed.", "Final read from id-ints is empty.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withRpcError(error).build());
}
return Futures.immediateFuture(RpcResultBuilder.success(new UnsubscribeDdtlOutputBuilder().setCopyMatches(idIntsDdtl.checkEqual(optional.get()))).build());
} catch (org.opendaylight.mdsal.common.api.ReadFailedException e) {
LOG.error("Unable to read data to verify ddtl data.", e);
final RpcError error = RpcResultBuilder.newError(ErrorType.APPLICATION, "Read failed.", "Final read from id-ints failed.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withRpcError(error).build());
} finally {
distributedDataStoreClient.close();
clientActor.tell(PoisonPill.getInstance(), noSender());
}
}
Aggregations