return document;
}
- //TODO move all occurences of this method in mdsal netconf(and xml factories) to a utility class
private Node transformNormalizedNode(final Document document, final NormalizedNode<?, ?> data, final SchemaPath rpcOutputPath) {
final DOMResult result = new DOMResult(document.createElement(XmlMappingConstants.RPC_REPLY_KEY));
return SchemaPath.create(Iterables.transform(dataRoot.getPathArguments(), PATH_ARG_TO_QNAME), dataRoot.equals(ROOT));
}
- // TODO this code is located in Restconf already
private void writeRootElement(final XMLStreamWriter xmlWriter, final NormalizedNodeWriter nnWriter, final ContainerNode data) {
try {
if (data.getNodeType().equals(SchemaContext.NAME)) {
}
private AnyXmlNode encapsulate(final DOMNotification body) {
- // FIXME: Introduce something like AnyXmlWithNormalizedNodeData in Yangtools
+ // FIXME: Introduce something like YangModeledAnyXmlNode in Yangtools
final Document doc = XmlUtil.newDocument();
final Optional<String> namespace = Optional.of(PAYLOAD_ARG.getNodeType().getNamespace().toString());
final Element element = XmlUtil.createElement(doc, "payload", namespace);
try {
Preconditions.checkState(operationRouter != null, "Cannot handle message, session up was not yet received");
- // FIXME: there is no validation since the document may contain yang
- // schemas
+ // there is no validation since the document may contain yang schemas
final NetconfMessage message = processDocument(netconfMessage,
session);
LOG.debug("Responding with message {}", message);
private synchronized void onCapabilitiesAdded(final Set<Capability> addedCaps) {
- // FIXME howto check for duplicates
this.capabilities.putAll(Maps.uniqueIndex(setupCapabilities(addedCaps), CAPABILITY_TO_URI));
}
private final Timer timer;
private final long connectionTimeoutMillis;
- // TODO shrink constructor
protected AbstractNetconfSessionNegotiator(final P sessionPreferences, final Promise<S> promise, final Channel channel, final Timer timer,
final L sessionListener, final long connectionTimeoutMillis) {
super(promise, channel);
if (!maybeFilter.isPresent()) {
return rpcReply;
}
-
- rpcReply = reReadDocument(rpcReply);
XmlElement filter = maybeFilter.get();
if (isSupported(filter)) {
* @throws DocumentedException
*/
public static Optional<Document> applySubtreeNotificationFilter(XmlElement filter, Document notification) throws DocumentedException {
- notification = reReadDocument(notification);
removeEventTimeNode(notification);
if (isSupported(filter)) {
return Optional.fromNullable(filteredNotification(filter, notification));
return Optional.of(extractNotificationContent(notification));
}
- private static Document reReadDocument(Document notification) throws DocumentedException {
- // FIXME: rpcReply document must be reread otherwise some nodes do not inherit namespaces. (services/service)
- try {
- notification = XmlUtil.readXmlToDocument(XmlUtil.toString(notification, true));
- } catch (SAXException | IOException e) {
- LOG.error("Cannot transform document", e);
- throw new DocumentedException("Cannot transform document" + e);
- }
- return notification;
- }
-
private static void removeEventTimeNode(Document document) {
final Node eventTimeNode = document.getDocumentElement().getElementsByTagNameNS(
XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_CAPABILITY_NOTIFICATION_1_0, XmlNetconfConstants.EVENT_TIME).item(0);
import org.opendaylight.protocol.framework.TimedReconnectStrategy;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Host;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry;
import org.opendaylight.yangtools.yang.model.repo.util.FilesystemSchemaSourceCache;
import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
private static final SchemaContextFactory DEFAULT_SCHEMA_CONTEXT_FACTORY =
DEFAULT_SCHEMA_REPOSITORY.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+ private static final int LOCAL_IO_FALLBACK_COST = PotentialSchemaSource.Costs.LOCAL_IO.getValue() + 1;
+
/**
* Keeps track of initialized Schema resources. A Map is maintained in which the key represents the name
* of the schema cache directory, and the value is a corresponding <code>SchemaResourcesDTO</code>. The
setSchemaRegistry(dto.getSchemaRegistry());
schemaResourcesDTO = dto;
}
+ if (userCapabilities.isPresent()) {
+ for (QName qname : userCapabilities.get().getModuleBasedCaps()) {
+ final SourceIdentifier sourceIdentifier = new SourceIdentifier(qname.getLocalName(), qname.getFormattedRevision());
+ dto.getSchemaRegistry().registerSchemaSource(DEFAULT_CACHE, PotentialSchemaSource.create(sourceIdentifier, YangTextSchemaSource.class, LOCAL_IO_FALLBACK_COST));
+ }
+ }
}
LOG.info("Netconf connector for device {} will use schema cache directory {} instead of {}",
instanceName, moduleSchemaCacheDirectory, DEFAULT_CACHE_DIRECTORY);
if (input.isSuccessful()) {
return transformer.toRpcResult(input.getResult(), type);
} else {
- // TODO check whether the listener sets errors properly
return new DefaultDOMRpcResult(input.getErrors());
}
}
@Nullable
@Override
public DOMRpcException apply(@Nullable final Exception e) {
- // FIXME what other possible exceptions are there ?
return new DOMRpcImplementationNotAvailableException(e, "Unable to invoke rpc %s", type);
}
});
final CheckedFuture<YangTextSchemaSource, SchemaSourceException> checked = Futures.makeChecked(transformed, MAPPER);
- // / FIXME remove this get, it is only present to wait until source is retrieved
- // (goal is to limit concurrent schema download, since NetconfDevice listener does not handle concurrent messages properly)
- // TODO retest this
- try {
- LOG.trace("{}: Blocking for {}", id, sourceIdentifier);
- checked.checkedGet();
- } catch (final SchemaSourceException e) {
- return Futures.immediateFailedCheckedFuture(e);
- }
-
return checked;
}
builder.append(moduleName);
builder.append(':');
}
- boolean first = true;
for (PathArgument arg : key.getPathArguments()) {
-
String name = arg.getNodeType().getLocalName();
- if (first) {
- first = false;
- } else {
- builder.append('/');
- }
- builder.append(name);
if (arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
NodeIdentifierWithPredicates nodeId = (NodeIdentifierWithPredicates) arg;
for (Entry<QName, Object> entry : nodeId.getKeyValues().entrySet()) {
- builder.append('/').append(entry.getValue());
+ builder.append(entry.getValue()).append('/');
}
+ } else {
+ builder.append(name);
+ builder.append('/');
}
}
-
- return builder.append('/').toString();
+ return builder.toString();
}
private String getYangMountUrl(final YangInstanceIdentifier key) {
private static final String HTTP_URL = "http://localhost/path";
private static final YangInstanceIdentifier instanceId = YangInstanceIdentifier.builder()
.node(QName.create("nodes"))
+ .node(QName.create("node"))
.nodeWithKey(QName.create("node"), QName.create("id"), "123").build();
private static final String INSTANCE_URL = "nodes/node/123/";
private MountPointSwagger swagger;