use of org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType 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.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType 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);
}
Aggregations