Search in sources :

Example 66 with EffectiveModelContext

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));
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) RestConfModule(org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)

Example 67 with EffectiveModelContext

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));
    }
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) WebApplicationException(javax.ws.rs.WebApplicationException) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) SchemaNode(org.opendaylight.yangtools.yang.model.api.SchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 68 with EffectiveModelContext

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();
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) DataNodeContainer(org.opendaylight.yangtools.yang.model.api.DataNodeContainer) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) Module(org.opendaylight.yangtools.yang.model.api.Module) RestConfModule(org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 69 with EffectiveModelContext

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);
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 70 with EffectiveModelContext

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);
}
Also used : EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Aggregations

EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)182 Test (org.junit.Test)99 Module (org.opendaylight.yangtools.yang.model.api.Module)37 QName (org.opendaylight.yangtools.yang.common.QName)29 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)28 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)26 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)24 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)24 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)21 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)18 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)16 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)16 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)16 IRSchemaSource (org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource)14 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)13 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)13 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)13 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)11 IOException (java.io.IOException)9 Collection (java.util.Collection)9