Search in sources :

Example 11 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.

the class AugmentTest method testAugmentRpc.

@Test
public void testAugmentRpc() throws Exception {
    final EffectiveModelContext context = assertEffectiveModelDir("/augment-test/rpc");
    final XMLNamespace NS_BAR = XMLNamespace.of("urn:opendaylight:bar");
    final XMLNamespace NS_FOO = XMLNamespace.of("urn:opendaylight:foo");
    final Revision revision = Revision.of("2013-10-11");
    final Module bar = context.findModules("bar").iterator().next();
    final Collection<? extends RpcDefinition> rpcs = bar.getRpcs();
    assertEquals(2, rpcs.size());
    RpcDefinition submit = null;
    for (final RpcDefinition rpc : rpcs) {
        if ("submit".equals(rpc.getQName().getLocalName())) {
            submit = rpc;
            break;
        }
    }
    assertNotNull(submit);
    final QName submitQName = QName.create(NS_BAR, revision, "submit");
    assertEquals(submitQName, submit.getQName());
    final InputSchemaNode input = submit.getInput();
    final QName inputQName = QName.create(NS_BAR, revision, "input");
    assertEquals(inputQName, input.getQName());
    final ChoiceSchemaNode arguments = (ChoiceSchemaNode) input.getDataChildByName(QName.create(NS_BAR, revision, "arguments"));
    final QName argumentsQName = QName.create(NS_BAR, revision, "arguments");
    assertEquals(argumentsQName, arguments.getQName());
    assertFalse(arguments.isAugmenting());
    final Collection<? extends CaseSchemaNode> cases = arguments.getCases();
    assertEquals(3, cases.size());
    CaseSchemaNode attach = null;
    CaseSchemaNode create = null;
    CaseSchemaNode destroy = null;
    for (final CaseSchemaNode child : cases) {
        if ("attach".equals(child.getQName().getLocalName())) {
            attach = child;
        } else if ("create".equals(child.getQName().getLocalName())) {
            create = child;
        } else if ("destroy".equals(child.getQName().getLocalName())) {
            destroy = child;
        }
    }
    assertNotNull(attach);
    assertNotNull(create);
    assertNotNull(destroy);
    assertTrue(attach.isAugmenting());
    assertTrue(create.isAugmenting());
    assertTrue(destroy.isAugmenting());
    // case attach
    assertEquals(QName.create(NS_FOO, revision, "attach"), attach.getQName());
    final Collection<? extends DataSchemaNode> attachChildren = attach.getChildNodes();
    assertEquals(1, attachChildren.size());
    // case create
    assertEquals(QName.create(NS_FOO, revision, "create"), create.getQName());
    final Collection<? extends DataSchemaNode> createChildren = create.getChildNodes();
    assertEquals(1, createChildren.size());
    // case attach
    assertEquals(QName.create(NS_FOO, revision, "destroy"), destroy.getQName());
    final Collection<? extends DataSchemaNode> destroyChildren = destroy.getChildNodes();
    assertEquals(1, destroyChildren.size());
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) QName(org.opendaylight.yangtools.yang.common.QName) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) InputSchemaNode(org.opendaylight.yangtools.yang.model.api.InputSchemaNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 12 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.

the class MoreRevisionsTest method checkNetconfMonitoringModuleSimpleTest.

private static void checkNetconfMonitoringModuleSimpleTest(final EffectiveModelContext context, final Revision rev20130715, final QName dateTimeTypeDef20130715) {
    final XMLNamespace monitoringNS = XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring");
    final QNameModule monitoring19700101 = QNameModule.create(monitoringNS);
    QName lockedTime = QName.create(monitoring19700101, "locked-time");
    Module monitoringModule19700101 = context.findModule("ietf-netconf-monitoring").get();
    DataSchemaNode leafLockedTime = monitoringModule19700101.getDataChildByName(lockedTime);
    assertThat(leafLockedTime, instanceOf(LeafSchemaNode.class));
    QName lockedTimeTypeQName = ((LeafSchemaNode) leafLockedTime).getType().getQName();
    assertEquals(dateTimeTypeDef20130715, lockedTimeTypeQName);
    Collection<? extends ModuleImport> imports = monitoringModule19700101.getImports();
    assertEquals(1, imports.size());
    ModuleImport monitoringImport = imports.iterator().next();
    assertEquals("ietf-yang-types", monitoringImport.getModuleName());
    assertEquals(Optional.of(rev20130715), monitoringImport.getRevision());
}
Also used : DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) ModuleImport(org.opendaylight.yangtools.yang.model.api.ModuleImport) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule)

Example 13 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project yangtools by opendaylight.

the class MoreRevisionsTest method checkContentFullTest.

private static void checkContentFullTest(final EffectiveModelContext context) {
    final XMLNamespace yangTypesNS = XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-yang-types");
    final Revision rev20100924 = Revision.of("2010-09-24");
    final Revision rev20130516 = Revision.of("2013-05-16");
    final Revision rev20130715 = Revision.of("2013-07-15");
    final QNameModule yangTypes20100924 = QNameModule.create(yangTypesNS, rev20100924);
    final QNameModule yangTypes20130516 = QNameModule.create(yangTypesNS, rev20130516);
    final QNameModule yangTypes20130715 = QNameModule.create(yangTypesNS, rev20130715);
    final QName dateTimeTypeDef20100924 = QName.create(yangTypes20100924, "date-and-time");
    final QName dateTimeTypeDef20130516 = QName.create(yangTypes20130516, "date-and-time");
    final QName dateTimeTypeDef20130715 = QName.create(yangTypes20130715, "date-and-time");
    Module yangTypesModule20100924 = context.findModule("ietf-yang-types", rev20100924).get();
    Module yangTypesModule20130516 = context.findModule("ietf-yang-types", rev20130516).get();
    Module yangTypesModule20130715 = context.findModule("ietf-yang-types", rev20130715).get();
    assertTrue(findTypeDef(yangTypesModule20100924, dateTimeTypeDef20100924));
    assertTrue(findTypeDef(yangTypesModule20130516, dateTimeTypeDef20130516));
    assertTrue(findTypeDef(yangTypesModule20130715, dateTimeTypeDef20130715));
    checkNetconfMonitoringModuleFullTest(context, rev20130715, dateTimeTypeDef20130715);
    checkInterfacesModuleFullTest(context, rev20100924, dateTimeTypeDef20100924);
}
Also used : Revision(org.opendaylight.yangtools.yang.common.Revision) QName(org.opendaylight.yangtools.yang.common.QName) XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule)

Example 14 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace in project netconf by opendaylight.

the class RestCodec method getModuleByNamespace.

@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private static Module getModuleByNamespace(final String namespace, final DOMMountPoint mountPoint, final ControllerContext controllerContext) {
    final XMLNamespace validNamespace = resolveValidNamespace(namespace, mountPoint, controllerContext);
    Module module = null;
    if (mountPoint != null) {
        module = ControllerContext.findModuleByNamespace(mountPoint, validNamespace);
    } else {
        module = controllerContext.findModuleByNamespace(validNamespace);
    }
    if (module == null) {
        LOG.info("Module for namespace {} was not found.", validNamespace);
        return null;
    }
    return module;
}
Also used : XMLNamespace(org.opendaylight.yangtools.yang.common.XMLNamespace) Module(org.opendaylight.yangtools.yang.model.api.Module) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 15 with XMLNamespace

use of org.opendaylight.yangtools.yang.common.XMLNamespace 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)

Aggregations

XMLNamespace (org.opendaylight.yangtools.yang.common.XMLNamespace)35 Module (org.opendaylight.yangtools.yang.model.api.Module)14 QName (org.opendaylight.yangtools.yang.common.QName)12 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)9 Revision (org.opendaylight.yangtools.yang.common.Revision)9 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)9 Test (org.junit.Test)8 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)4 RpcDefinition (org.opendaylight.yangtools.yang.model.api.RpcDefinition)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)3 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)3 ModuleImport (org.opendaylight.yangtools.yang.model.api.ModuleImport)3 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 Optional (java.util.Optional)2