use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult 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.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class RestconfImpl method invokeSalRemoteRpcSubscribeRPC.
private ListenableFuture<DOMRpcResult> invokeSalRemoteRpcSubscribeRPC(final NormalizedNodeContext payload) {
final ContainerNode value = (ContainerNode) payload.getData();
final QName rpcQName = payload.getInstanceIdentifierContext().getSchemaNode().getQName();
final Optional<DataContainerChild> path = value.findChildByArg(new NodeIdentifier(QName.create(rpcQName, "path")));
final Object pathValue = path.isPresent() ? path.get().body() : null;
if (!(pathValue instanceof YangInstanceIdentifier)) {
LOG.debug("Instance identifier {} was not normalized correctly", rpcQName);
throw new RestconfDocumentedException("Instance identifier was not normalized correctly", ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED);
}
final YangInstanceIdentifier pathIdentifier = (YangInstanceIdentifier) pathValue;
String streamName = (String) CREATE_DATA_SUBSCR;
NotificationOutputType outputType = null;
if (!pathIdentifier.isEmpty()) {
final String fullRestconfIdentifier = DATA_SUBSCR + controllerContext.toFullRestconfIdentifier(pathIdentifier, null);
LogicalDatastoreType datastore = parseEnumTypeParameter(value, LogicalDatastoreType.class, DATASTORE_PARAM_NAME);
datastore = datastore == null ? DEFAULT_DATASTORE : datastore;
Scope scope = parseEnumTypeParameter(value, Scope.class, SCOPE_PARAM_NAME);
scope = scope == null ? Scope.BASE : scope;
outputType = parseEnumTypeParameter(value, NotificationOutputType.class, OUTPUT_TYPE_PARAM_NAME);
outputType = outputType == null ? NotificationOutputType.XML : outputType;
streamName = Notificator.createStreamNameFromUri(fullRestconfIdentifier + "/datastore=" + datastore + "/scope=" + scope);
}
if (Strings.isNullOrEmpty(streamName)) {
LOG.debug("Path is empty or contains value node which is not Container or List built-in type at {}", pathIdentifier);
throw new RestconfDocumentedException("Path is empty or contains value node which is not Container or List " + "built-in type.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final QName outputQname = QName.create(rpcQName, "output");
final QName streamNameQname = QName.create(rpcQName, "stream-name");
final ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname)).withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
if (!Notificator.existListenerFor(streamName)) {
Notificator.createListener(pathIdentifier, streamName, outputType, controllerContext);
}
return Futures.immediateFuture(new DefaultDOMRpcResult(output));
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class CreateStreamUtil method createDataChangeNotifiStream.
/**
* Create data-change-event or notification stream with POST operation via RPC.
*
* @param payload Input of RPC - example in JSON (data-change-event stream):
* <pre>
* {@code
* {
* "input": {
* "path": "/toaster:toaster/toaster:toasterStatus",
* "sal-remote-augment:datastore": "OPERATIONAL",
* "sal-remote-augment:scope": "ONE"
* }
* }
* }
* </pre>
* @param refSchemaCtx Reference to {@link EffectiveModelContext}.
* @return {@link DOMRpcResult} - Output of RPC - example in JSON:
* <pre>
* {@code
* {
* "output": {
* "stream-name": "toaster:toaster/toaster:toasterStatus/datastore=OPERATIONAL/scope=ONE"
* }
* }
* }
* </pre>
*/
static DOMRpcResult createDataChangeNotifiStream(final NormalizedNodePayload payload, final EffectiveModelContext refSchemaCtx) {
// parsing out of container with settings and path
final ContainerNode data = (ContainerNode) requireNonNull(payload).getData();
final QName qname = payload.getInstanceIdentifierContext().getSchemaNode().getQName();
final YangInstanceIdentifier path = preparePath(data, qname);
// building of stream name
final StringBuilder streamNameBuilder = new StringBuilder(prepareDataChangeNotifiStreamName(path, requireNonNull(refSchemaCtx), data));
final NotificationOutputType outputType = prepareOutputType(data);
if (outputType.equals(NotificationOutputType.JSON)) {
streamNameBuilder.append('/').append(outputType.getName());
}
final String streamName = streamNameBuilder.toString();
// registration of the listener
ListenersBroker.getInstance().registerDataChangeListener(path, streamName, outputType);
// building of output
final QName outputQname = QName.create(qname, "output");
final QName streamNameQname = QName.create(qname, "stream-name");
final ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname)).withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
return new DefaultDOMRpcResult(output);
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class RestconfInvokeOperationsServiceImplTest method invokeRpcViaMountPointTest.
@Test
public void invokeRpcViaMountPointTest() throws InterruptedException, ExecutionException {
doReturn(Optional.ofNullable(rpcService)).when(mountPoint).getService(DOMRpcService.class);
final DOMRpcResult mockResult = new DefaultDOMRpcResult(OUTPUT, List.of());
doReturn(immediateFluentFuture(mockResult)).when(rpcService).invokeRpc(RPC, INPUT);
final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, RPC, mountPoint).get();
assertTrue(rpcResult.getErrors().isEmpty());
assertEquals(OUTPUT, rpcResult.getResult());
}
use of org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult in project netconf by opendaylight.
the class RestconfInvokeOperationsServiceImplTest method checkResponseTest.
@Test
public void checkResponseTest() throws InterruptedException, ExecutionException {
doReturn(immediateFluentFuture(new DefaultDOMRpcResult(OUTPUT, List.of()))).when(rpcService).invokeRpc(RPC, INPUT);
final DOMRpcResult rpcResult = RestconfInvokeOperationsServiceImpl.invokeRpc(INPUT, RPC, rpcService).get();
assertTrue(rpcResult.getErrors().isEmpty());
assertEquals(OUTPUT, rpcResult.getResult());
}
Aggregations