use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class RestconfImpl method getModules.
@Override
@Deprecated
public NormalizedNodeContext getModules(final UriInfo uriInfo) {
final MapNode allModuleMap = makeModuleMapNode(controllerContext.getAllModules());
final EffectiveModelContext schemaContext = controllerContext.getGlobalSchema();
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(allModuleMap);
return new NormalizedNodeContext(new InstanceIdentifierContext<>(MODULES, modulesSchemaNode, null, schemaContext), moduleContainerBuilder.build(), QueryParametersParser.parseWriterParameters(uriInfo));
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext 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.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class ControllerContext method toFullRestconfIdentifier.
public String toFullRestconfIdentifier(final YangInstanceIdentifier path, final DOMMountPoint mount) {
checkPreconditions();
final Iterable<PathArgument> elements = path.getPathArguments();
final StringBuilder builder = new StringBuilder();
final PathArgument head = elements.iterator().next();
final QName startQName = head.getNodeType();
final EffectiveModelContext schemaContext;
if (mount != null) {
schemaContext = getModelContext(mount);
} else {
schemaContext = globalSchema;
}
final Module initialModule = schemaContext.findModule(startQName.getModule()).orElse(null);
DataNodeContainer node = initialModule;
for (final PathArgument element : elements) {
if (!(element instanceof AugmentationIdentifier)) {
final QName _nodeType = element.getNodeType();
final DataSchemaNode potentialNode = childByQName(node, _nodeType);
if ((!(element instanceof NodeIdentifier) || !(potentialNode instanceof ListSchemaNode)) && !(potentialNode instanceof ChoiceSchemaNode)) {
builder.append(convertToRestconfIdentifier(element, potentialNode, mount));
if (potentialNode instanceof DataNodeContainer) {
node = (DataNodeContainer) potentialNode;
}
}
}
}
return builder.toString();
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class ControllerContext method findModuleByName.
public static Module findModuleByName(final DOMMountPoint mountPoint, final String moduleName) {
checkArgument(moduleName != null && mountPoint != null);
final EffectiveModelContext mountPointSchema = getModelContext(mountPoint);
return mountPointSchema == null ? null : mountPointSchema.findModules(moduleName).stream().findFirst().orElse(null);
}
use of org.opendaylight.yangtools.yang.model.api.EffectiveModelContext in project netconf by opendaylight.
the class ControllerContext method findModuleByNameAndRevision.
public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final String name, final Revision revision) {
checkPreconditions();
checkArgument(name != null && revision != null && mountPoint != null);
final EffectiveModelContext schemaContext = getModelContext(mountPoint);
return schemaContext == null ? null : schemaContext.findModule(name, revision).orElse(null);
}
Aggregations