use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project bgpcep by opendaylight.
the class SimpleEROSubobjectRegistryTest method testSerializerRegistration.
@Test
public void testSerializerRegistration() {
assertNotNull(this.simpleEROSubobjectRegistry.registerSubobjectSerializer(LabelCase.class, this.rroSubobjectSerializer));
final SubobjectContainer container = new SubobjectContainerBuilder().setSubobjectType(new LabelCaseBuilder().build()).build();
final ByteBuf output = Unpooled.buffer();
this.simpleEROSubobjectRegistry.serializeSubobject(container, output);
assertEquals(1, output.readableBytes());
}
use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netconf by opendaylight.
the class NetconfMessageTransformUtil method createEditConfigAnyxml.
/**
* Create edit-config structure to invoke {@code operation} with {@code lastChildOverride} data on {@code dataPath}.
*
* @param ctx {@link EffectiveModelContext} device's model context
* @param dataPath {@link YangInstanceIdentifier} path to data in device's data-store
* @param operation Optional of {@link ModifyAction} action to be invoked
* @param lastChildOverride Optional of {@code NormalizedNode} data on which action will be invoked
* @return {@link DOMSourceAnyxmlNode} containing edit-config structure
*/
public static DOMSourceAnyxmlNode createEditConfigAnyxml(final EffectiveModelContext ctx, final YangInstanceIdentifier dataPath, final Optional<ModifyAction> operation, final Optional<NormalizedNode> lastChildOverride) {
if (dataPath.isEmpty()) {
Preconditions.checkArgument(lastChildOverride.isPresent(), "Data has to be present when creating structure for top level element");
Preconditions.checkArgument(lastChildOverride.get() instanceof DataContainerChild, "Data has to be either container or a list node when creating structure for top level element, " + "but was: %s", lastChildOverride.get());
}
final var element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_CONFIG_QNAME.getLocalName(), Optional.of(NETCONF_CONFIG_QNAME.getNamespace().toString()));
final var metadata = operation.map(o -> leafMetadata(dataPath, o)).orElse(null);
try {
if (lastChildOverride.isPresent()) {
// FIXME remove ImmutableNodes.fromInstanceId usage
final var configContent = ImmutableNodes.fromInstanceId(ctx, dataPath, lastChildOverride.get());
NetconfUtil.writeNormalizedNode(configContent, metadata, new DOMResult(element), SchemaPath.ROOT, ctx);
} else {
NetconfUtil.writeNormalizedNode(dataPath, metadata, new DOMResult(element), SchemaPath.ROOT, ctx);
}
} catch (final IOException | XMLStreamException e) {
throw new IllegalStateException("Unable to serialize edit config content element for path " + dataPath, e);
}
return Builders.anyXmlBuilder().withNodeIdentifier(NETCONF_CONFIG_NODEID).withValue(new DOMSource(element)).build();
}
use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netconf by opendaylight.
the class NetconfDeviceTopologyAdapter method createNetworkTopologyIfNotPresent.
private void createNetworkTopologyIfNotPresent(final WriteTransaction writeTx) {
final NetworkTopology networkTopology = new NetworkTopologyBuilder().build();
LOG.trace("{}: Transaction {} merging {} container to ensure its presence", id, writeTx.getIdentifier(), NetworkTopology.QNAME);
writeTx.merge(LogicalDatastoreType.OPERATIONAL, networkTopologyPath, networkTopology);
final Topology topology = new TopologyBuilder().setTopologyId(new TopologyId(TopologyNetconf.QNAME.getLocalName())).build();
LOG.trace("{}: Transaction {} merging {} container to ensure its presence", id, writeTx.getIdentifier(), Topology.QNAME);
writeTx.merge(LogicalDatastoreType.OPERATIONAL, topologyListPath, topology);
}
use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netconf by opendaylight.
the class RestconfImpl method invokeSalRemoteRpcSubscribeRPC.
private ListenableFuture<DOMRpcResult> invokeSalRemoteRpcSubscribeRPC(final NormalizedNodeContext payload) {
final ContainerNode value = (ContainerNode) payload.getData();
final QName rpcQName = payload.getInstanceIdentifierContext().getSchemaNode().getQName();
final Optional<DataContainerChild> path = value.findChildByArg(new NodeIdentifier(QName.create(rpcQName, "path")));
final Object pathValue = path.isPresent() ? path.get().body() : null;
if (!(pathValue instanceof YangInstanceIdentifier)) {
LOG.debug("Instance identifier {} was not normalized correctly", rpcQName);
throw new RestconfDocumentedException("Instance identifier was not normalized correctly", ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED);
}
final YangInstanceIdentifier pathIdentifier = (YangInstanceIdentifier) pathValue;
String streamName = (String) CREATE_DATA_SUBSCR;
NotificationOutputType outputType = null;
if (!pathIdentifier.isEmpty()) {
final String fullRestconfIdentifier = DATA_SUBSCR + controllerContext.toFullRestconfIdentifier(pathIdentifier, null);
LogicalDatastoreType datastore = parseEnumTypeParameter(value, LogicalDatastoreType.class, DATASTORE_PARAM_NAME);
datastore = datastore == null ? DEFAULT_DATASTORE : datastore;
Scope scope = parseEnumTypeParameter(value, Scope.class, SCOPE_PARAM_NAME);
scope = scope == null ? Scope.BASE : scope;
outputType = parseEnumTypeParameter(value, NotificationOutputType.class, OUTPUT_TYPE_PARAM_NAME);
outputType = outputType == null ? NotificationOutputType.XML : outputType;
streamName = Notificator.createStreamNameFromUri(fullRestconfIdentifier + "/datastore=" + datastore + "/scope=" + scope);
}
if (Strings.isNullOrEmpty(streamName)) {
LOG.debug("Path is empty or contains value node which is not Container or List built-in type at {}", pathIdentifier);
throw new RestconfDocumentedException("Path is empty or contains value node which is not Container or List " + "built-in type.", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
final QName outputQname = QName.create(rpcQName, "output");
final QName streamNameQname = QName.create(rpcQName, "stream-name");
final ContainerNode output = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(outputQname)).withChild(ImmutableNodes.leafNode(streamNameQname, streamName)).build();
if (!Notificator.existListenerFor(streamName)) {
Notificator.createListener(pathIdentifier, streamName, outputType, controllerContext);
}
return Futures.immediateFuture(new DefaultDOMRpcResult(output));
}
use of org.opendaylight.yang.gen.v1.urn.test.opendaylight.mdsal298.rev180129.Container in project netconf by opendaylight.
the class CreateStreamUtil method prepareDataChangeNotifiStreamName.
/**
* Prepare stream name.
*
* @param path Path of element from which data-change-event notifications are going to be generated.
* @param schemaContext Schema context.
* @param data Container with stream settings (RPC create-stream).
* @return Parsed stream name.
*/
private static String prepareDataChangeNotifiStreamName(final YangInstanceIdentifier path, final EffectiveModelContext schemaContext, final ContainerNode data) {
final String datastoreName = extractStringLeaf(data, DATASTORE_NODEID);
final LogicalDatastoreType datastoreType = datastoreName != null ? LogicalDatastoreType.valueOf(datastoreName) : LogicalDatastoreType.CONFIGURATION;
final String scopeName = extractStringLeaf(data, SCOPE_NODEID);
// FIXME: this is not really used
final Scope scope = scopeName != null ? Scope.forName(scopeName).orElseThrow() : Scope.BASE;
return RestconfStreamsConstants.DATA_SUBSCRIPTION + "/" + ListenersBroker.createStreamNameFromUri(IdentifierCodec.serialize(path, schemaContext) + "/" + RestconfStreamsConstants.DATASTORE_PARAM_NAME + "=" + datastoreType + "/" + RestconfStreamsConstants.SCOPE_PARAM_NAME + "=" + scope);
}
Aggregations