use of org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException in project netconf by opendaylight.
the class ActorProxyNetconfServiceFacade method discardChanges.
@Override
public ListenableFuture<DOMRpcResult> discardChanges() {
LOG.debug("{}: Discard changes via actor {}", id, masterActor);
final SettableFuture<DOMRpcResult> discardChangesResult = SettableFuture.create();
final Future<Object> future = Patterns.ask(masterActor, new DiscardChangesRequest(), askTimeout);
future.onComplete(new OnComplete<>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
discardChangesResult.setException(failure);
} else if (response instanceof InvokeRpcMessageReply) {
discardChangesResult.set(mapInvokeRpcMessageReplyToDOMRpcResult((InvokeRpcMessageReply) response));
} else {
discardChangesResult.setException(new ClusteringRpcException("Discard changes operation returned unexpected type"));
LOG.error("{}: Discard changes via actor {} returned unexpected type", id, masterActor);
}
}
}, executionContext);
return discardChangesResult;
}
use of org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException in project netconf by opendaylight.
the class NetconfNodeActorTest method testSlaveInvokeRpc.
@Test
public void testSlaveInvokeRpc() throws Exception {
final List<SourceIdentifier> sourceIdentifiers = Lists.newArrayList(RevisionSourceIdentifier.create("testID"));
initializeMaster(sourceIdentifiers);
registerSlaveMountPoint();
ArgumentCaptor<DOMRpcService> domRPCServiceCaptor = ArgumentCaptor.forClass(DOMRpcService.class);
verify(mockMountPointBuilder).addService(eq(DOMRpcService.class), domRPCServiceCaptor.capture());
final DOMRpcService slaveDomRPCService = domRPCServiceCaptor.getValue();
assertTrue(slaveDomRPCService instanceof ProxyDOMRpcService);
final QName testQName = QName.create("", "TestQname");
final NormalizedNode outputNode = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(testQName)).withChild(ImmutableNodes.leafNode(testQName, "foo")).build();
final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.RPC, null, "Rpc invocation failed.");
// RPC with no response output.
doReturn(FluentFutures.immediateNullFluentFuture()).when(mockDOMRpcService).invokeRpc(any(), any());
DOMRpcResult result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
assertEquals(null, result);
// RPC with response output.
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode))).when(mockDOMRpcService).invokeRpc(any(), any());
result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
assertEquals(outputNode, result.getResult());
assertTrue(result.getErrors().isEmpty());
// RPC with response error.
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(rpcError))).when(mockDOMRpcService).invokeRpc(any(), any());
result = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
assertNull(result.getResult());
assertEquals(rpcError, result.getErrors().iterator().next());
// RPC with response output and error.
doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult(outputNode, rpcError))).when(mockDOMRpcService).invokeRpc(any(), any());
final DOMRpcResult resultOutputError = slaveDomRPCService.invokeRpc(testQName, outputNode).get(2, TimeUnit.SECONDS);
assertEquals(outputNode, resultOutputError.getResult());
assertEquals(rpcError, resultOutputError.getErrors().iterator().next());
// RPC failure.
doReturn(FluentFutures.immediateFailedFluentFuture(new ClusteringRpcException("mock"))).when(mockDOMRpcService).invokeRpc(any(), any());
final ListenableFuture<? extends DOMRpcResult> future = slaveDomRPCService.invokeRpc(testQName, outputNode);
final ExecutionException e = assertThrows(ExecutionException.class, () -> future.get(2, TimeUnit.SECONDS));
final Throwable cause = e.getCause();
assertThat(cause, instanceOf(DOMRpcException.class));
assertEquals("mock", cause.getMessage());
}
use of org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException in project netconf by opendaylight.
the class ActorProxyNetconfServiceFacade method commit.
@Override
public ListenableFuture<? extends DOMRpcResult> commit() {
LOG.debug("{}: Commit via actor {}", id, masterActor);
final Future<Object> future = Patterns.ask(masterActor, new CommitRequest(), askTimeout);
final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
future.onComplete(new OnComplete<>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
LOG.debug("{}: Commit failed", id, failure);
settableFuture.setException(newNetconfServiceFailedException(processFailure(failure)));
} else if (response instanceof InvokeRpcMessageReply) {
LOG.debug("{}: Commit succeeded", id);
settableFuture.set(mapInvokeRpcMessageReplyToDOMRpcResult((InvokeRpcMessageReply) response));
} else {
settableFuture.setException(new ClusteringRpcException("Commit operation returned unexpected type"));
LOG.error("{}: Commit via actor {} returned unexpected type", id, masterActor);
}
}
private NetconfServiceFailedException newNetconfServiceFailedException(final Throwable failure) {
return new NetconfServiceFailedException(String.format("%s: Commit of operation failed", getDeviceId()), failure);
}
}, executionContext);
return settableFuture;
}
use of org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException in project netconf by opendaylight.
the class ProxyDOMRpcService method invokeRpc.
@Override
public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
LOG.trace("{}: Rpc operation invoked with schema type: {} and node: {}.", id, type, input);
final NormalizedNodeMessage normalizedNodeMessage = input != null ? new NormalizedNodeMessage(YangInstanceIdentifier.empty(), input) : null;
final Future<Object> scalaFuture = Patterns.ask(masterActorRef, new InvokeRpcMessage(new SchemaPathMessage(type), normalizedNodeMessage), actorResponseWaitTime);
final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
scalaFuture.onComplete(new OnComplete<>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
if (failure instanceof ClusteringRpcException) {
settableFuture.setException(failure);
} else {
settableFuture.setException(new ClusteringRpcException(id + ": Exception during remote rpc invocation.", failure));
}
return;
}
if (response instanceof EmptyResultResponse) {
settableFuture.set(null);
return;
}
final Collection<? extends RpcError> errors = ((InvokeRpcMessageReply) response).getRpcErrors();
final NormalizedNodeMessage normalizedNodeMessageResult = ((InvokeRpcMessageReply) response).getNormalizedNodeMessage();
final DOMRpcResult result;
if (normalizedNodeMessageResult == null) {
result = new DefaultDOMRpcResult(ImmutableList.copyOf(errors));
} else {
result = new DefaultDOMRpcResult(normalizedNodeMessageResult.getNode(), errors);
}
settableFuture.set(result);
}
}, actorSystem.dispatcher());
return FluentFuture.from(settableFuture);
}
use of org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException in project netconf by opendaylight.
the class ActorProxyNetconfServiceFacade method lock.
@Override
public ListenableFuture<DOMRpcResult> lock() {
LOG.debug("{}: Lock via actor {}", id, masterActor);
final SettableFuture<DOMRpcResult> lockResult = SettableFuture.create();
final Future<Object> future = Patterns.ask(masterActor, new LockRequest(), askTimeout);
future.onComplete(new OnComplete<>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
lockResult.setException(failure);
} else if (response instanceof InvokeRpcMessageReply) {
lockResult.set(mapInvokeRpcMessageReplyToDOMRpcResult((InvokeRpcMessageReply) response));
} else {
lockResult.setException(new ClusteringRpcException("Lock operation returned unexpected type"));
LOG.error("{}: Lock via actor {} returned unexpected type", id, masterActor);
}
}
}, executionContext);
return lockResult;
}
Aggregations