Merge "Remove inventory related code from netconf connector"
authorTomas Cere <tcere@cisco.com>
Wed, 20 Apr 2016 09:45:26 +0000 (09:45 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 20 Apr 2016 09:45:26 +0000 (09:45 +0000)
12 files changed:
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/RuntimeRpc.java
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/get/AbstractGet.java
netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionListener.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfMonitoringServiceImpl.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfSessionNegotiator.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/messages/SubtreeFilter.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceRpc.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/schema/NetconfRemoteSchemaYangSourceProvider.java
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/mountpoints/MountPointSwagger.java
restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/MountPointSwaggerTest.java

index bec5a4a509d857a30a639d70c604d6bd5fc01c75..94dfa5e38a5d94f109a7597dbbb61a8a3806eb32 100644 (file)
@@ -202,7 +202,6 @@ public class RuntimeRpc extends AbstractSingletonNetconfOperation {
         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));
 
index 6d220071bacd4f1f540da7ca2b2791fc6118a0f9..7bf710f37076e609b47cdd92b50288d6c8c08b40 100644 (file)
@@ -102,7 +102,6 @@ public abstract class AbstractGet extends AbstractSingletonNetconfOperation {
         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)) {
index 01d229bf24fdc50f359df00cd69500911f7808e9..31246bbea019fc6e4cc0f52261384acf55232d9a 100644 (file)
@@ -237,7 +237,7 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener
     }
 
     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);
index ca61311cdcbd48f046d2be71644be9432e2296ad..f3a26ce40b97494d71a00cf10b72c6f3f0069d62 100644 (file)
@@ -82,8 +82,7 @@ public class NetconfServerSessionListener implements NetconfSessionListener<Netc
         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);
index 27dbb67715c7e499b19f9796d4f6fb0a4572bedb..9d7d760b2173a36955b826a05718c6707966554c 100644 (file)
@@ -284,7 +284,6 @@ public class NetconfMonitoringServiceImpl implements NetconfMonitoringService, A
 
 
     private synchronized void onCapabilitiesAdded(final Set<Capability> addedCaps) {
-        // FIXME howto check for duplicates
         this.capabilities.putAll(Maps.uniqueIndex(setupCapabilities(addedCaps), CAPABILITY_TO_URI));
     }
 
index 3482c1fbef34e4882b753e0cd3949f189101709f..b3d35dc3c0d05bd8811505b4c450948052c9f0ff 100644 (file)
@@ -65,7 +65,6 @@ public abstract class AbstractNetconfSessionNegotiator<P extends NetconfSessionP
     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);
index 949e63d661a1deea9d1692c50ec997ccd683f1bb..73ce520d2b8774013082c389abb9ff49085473b2 100644 (file)
@@ -42,8 +42,6 @@ public class SubtreeFilter {
             if (!maybeFilter.isPresent()) {
                 return rpcReply;
             }
-
-            rpcReply = reReadDocument(rpcReply);
             XmlElement filter = maybeFilter.get();
             if (isSupported(filter)) {
 
@@ -64,7 +62,6 @@ public class SubtreeFilter {
      * @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));
@@ -72,17 +69,6 @@ public class SubtreeFilter {
         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);
index d7222c1bb26beb1ce03bb3acdded9a35d65003f8..4538857184f42f7befc4c9034dd42fd6e9f85e25 100644 (file)
@@ -47,10 +47,13 @@ import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
 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;
@@ -105,6 +108,8 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
     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
@@ -226,6 +231,12 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
                         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);
index d1282d09b45c58c82785e391a11059705c2c25da..ff27e3c9129404d36f9329bf7afd975ebe388e99 100644 (file)
@@ -67,7 +67,6 @@ public final class NetconfDeviceRpc implements DOMRpcService {
                 if (input.isSuccessful()) {
                     return transformer.toRpcResult(input.getResult(), type);
                 } else {
-                    // TODO check whether the listener sets errors properly
                     return new DefaultDOMRpcResult(input.getErrors());
                 }
             }
@@ -77,7 +76,6 @@ public final class NetconfDeviceRpc implements DOMRpcService {
             @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);
             }
         });
index e4fba0cb99facc07e57a76edc02fa55f77307b61..72d2b391a2c32276768789774c9bddde053c455e 100644 (file)
@@ -129,16 +129,6 @@ public final class NetconfRemoteSchemaYangSourceProvider implements SchemaSource
 
         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;
     }
 
index 1726e2aad0a32a3e637cfe09ec715ac576e272b5..b20aa967b9e66f38a37cb1ee59e353a51190c15d 100644 (file)
@@ -90,25 +90,19 @@ public class MountPointSwagger extends BaseYangSwaggerGenerator implements Mount
             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) {
index 7b3344348ae96f38ba2ecca2df7d87157974d44a..881f9e95657e0ae3df0fc9a0a80a813b62c7334c 100644 (file)
@@ -42,6 +42,7 @@ public class MountPointSwaggerTest {
     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;