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());
}
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());
}
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);
}
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;
}
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));
}
}
Aggregations