use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class RestconfImpl method invokeRpc.
@Override
public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
if (payload == null) {
// no payload specified, reroute this to no payload invokeRpc implementation
return invokeRpc(identifier, uriInfo);
}
final SchemaNode schema = payload.getInstanceIdentifierContext().getSchemaNode();
final ListenableFuture<? extends DOMRpcResult> response;
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final NormalizedNode input = nonnullInput(schema, payload.getData());
final EffectiveModelContext schemaContext;
if (mountPoint != null) {
final Optional<DOMRpcService> mountRpcServices = mountPoint.getService(DOMRpcService.class);
if (mountRpcServices.isEmpty()) {
LOG.debug("Error: Rpc service is missing.");
throw new RestconfDocumentedException("Rpc service is missing.");
}
schemaContext = modelContext(mountPoint);
response = mountRpcServices.get().invokeRpc(schema.getQName(), input);
} else {
final XMLNamespace namespace = schema.getQName().getNamespace();
if (namespace.toString().equals(SAL_REMOTE_NAMESPACE)) {
if (identifier.contains(CREATE_DATA_SUBSCR)) {
response = invokeSalRemoteRpcSubscribeRPC(payload);
} else if (identifier.contains(CREATE_NOTIFICATION_STREAM)) {
response = invokeSalRemoteRpcNotifiStrRPC(payload);
} else {
final String msg = "Not supported operation";
LOG.warn(msg);
throw new RestconfDocumentedException(msg, ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED);
}
} else {
response = broker.invokeRpc(schema.getQName(), input);
}
schemaContext = controllerContext.getGlobalSchema();
}
final DOMRpcResult result = checkRpcResponse(response);
RpcDefinition resultNodeSchema = null;
final NormalizedNode resultData;
if (result != null && result.getResult() != null) {
resultData = result.getResult();
resultNodeSchema = (RpcDefinition) payload.getInstanceIdentifierContext().getSchemaNode();
} else {
resultData = null;
}
if (resultData != null && ((ContainerNode) resultData).isEmpty()) {
throw new WebApplicationException(Response.Status.NO_CONTENT);
} else {
return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema, mountPoint, schemaContext), resultData, QueryParametersParser.parseWriterParameters(uriInfo));
}
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class RestconfImpl method getModules.
/**
* Valid only for mount point.
*/
@Override
@Deprecated
public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
if (!identifier.contains(ControllerContext.MOUNT)) {
final String errMsg = "URI has bad format. If modules behind mount point should be showed," + " URI has to end with " + ControllerContext.MOUNT;
LOG.debug("{} for {}", errMsg, identifier);
throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final InstanceIdentifierContext<?> mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
final MapNode mountPointModulesMap = makeModuleMapNode(controllerContext.getAllModules(mountPoint));
final Module restconfModule = getRestconfModule();
final DataSchemaNode modulesSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, RestConfModule.MODULES_CONTAINER_SCHEMA_NODE);
checkState(modulesSchemaNode instanceof ContainerSchemaNode);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> moduleContainerBuilder = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) modulesSchemaNode);
moduleContainerBuilder.withChild(mountPointModulesMap);
return new NormalizedNodeContext(new InstanceIdentifierContext<>(MODULES, modulesSchemaNode, mountPoint, controllerContext.getGlobalSchema()), moduleContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class RestconfImpl method getOperations.
@Override
@Deprecated
public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
if (!identifier.contains(ControllerContext.MOUNT)) {
final String errMsg = "URI has bad format. If operations behind mount point should be showed, URI has to " + " end with " + ControllerContext.MOUNT;
LOG.debug("{} for {}", errMsg, identifier);
throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final InstanceIdentifierContext<?> mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
final var entry = OperationsResourceUtils.contextForModelContext(modelContext(mountPoint), mountPoint);
return new NormalizedNodeContext(entry.getKey(), entry.getValue());
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class RestconfImpl method subscribeToStream.
/**
* Subscribes to some path in schema context (stream) to listen on changes
* on this stream.
*
* <p>
* Additional parameters for subscribing to stream are loaded via rpc input
* parameters:
* <ul>
* <li>datastore - default CONFIGURATION (other values of
* {@link LogicalDatastoreType} enum type)</li>
* <li>scope - default BASE (other values of {@link Scope})</li>
* </ul>
*/
@Override
public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
boolean startTimeUsed = false;
boolean stopTimeUsed = false;
Instant start = Instant.now();
Instant stop = null;
boolean filterUsed = false;
String filter = null;
boolean leafNodesOnlyUsed = false;
boolean leafNodesOnly = false;
boolean skipNotificationDataUsed = false;
boolean skipNotificationData = false;
for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
switch(entry.getKey()) {
case "start-time":
if (!startTimeUsed) {
startTimeUsed = true;
start = parseDateFromQueryParam(entry);
} else {
throw new RestconfDocumentedException("Start-time parameter can be used only once.");
}
break;
case "stop-time":
if (!stopTimeUsed) {
stopTimeUsed = true;
stop = parseDateFromQueryParam(entry);
} else {
throw new RestconfDocumentedException("Stop-time parameter can be used only once.");
}
break;
case "filter":
if (!filterUsed) {
filterUsed = true;
filter = entry.getValue().iterator().next();
} else {
throw new RestconfDocumentedException("Filter parameter can be used only once.");
}
break;
case "odl-leaf-nodes-only":
if (!leafNodesOnlyUsed) {
leafNodesOnlyUsed = true;
leafNodesOnly = Boolean.parseBoolean(entry.getValue().iterator().next());
} else {
throw new RestconfDocumentedException("Odl-leaf-nodes-only parameter can be used only once.");
}
break;
case "odl-skip-notification-data":
if (!skipNotificationDataUsed) {
skipNotificationDataUsed = true;
skipNotificationData = Boolean.parseBoolean(entry.getValue().iterator().next());
} else {
throw new RestconfDocumentedException("Odl-skip-notification-data parameter can be used only once.");
}
break;
default:
throw new RestconfDocumentedException("Bad parameter used with notifications: " + entry.getKey());
}
}
if (!startTimeUsed && stopTimeUsed) {
throw new RestconfDocumentedException("Stop-time parameter has to be used with start-time parameter.");
}
URI response = null;
if (identifier.contains(DATA_SUBSCR)) {
response = dataSubs(identifier, uriInfo, start, stop, filter, leafNodesOnly, skipNotificationData);
} else if (identifier.contains(NOTIFICATION_STREAM)) {
response = notifStream(identifier, uriInfo, start, stop, filter);
}
if (response != null) {
// prepare node with value of location
final InstanceIdentifierContext<?> iid = prepareIIDSubsStreamOutput();
final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> builder = ImmutableLeafNodeBuilder.create().withValue(response.toString());
builder.withNodeIdentifier(NodeIdentifier.create(QName.create("subscribe:to:notification", "2016-10-28", "location")));
// prepare new header with location
return new NormalizedNodeContext(iid, builder.build(), ImmutableMap.of("Location", response));
}
final String msg = "Bad type of notification of sal-remote";
LOG.warn(msg);
throw new RestconfDocumentedException(msg);
}
use of org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext in project netconf by opendaylight.
the class StatisticsRestconfServiceWrapper method readConfigurationData.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
this.configGet.incrementAndGet();
NormalizedNodeContext normalizedNodeContext = null;
try {
normalizedNodeContext = this.delegate.readConfigurationData(identifier, uriInfo);
if (normalizedNodeContext.getData() != null) {
this.successGetConfig.incrementAndGet();
} else {
this.failureGetConfig.incrementAndGet();
}
} catch (final Exception e) {
this.failureGetConfig.incrementAndGet();
throw e;
}
return normalizedNodeContext;
}
Aggregations