Merge "Include JMX Counters and resetTransactionCounters"
authorTom Pantelis <tpanteli@brocade.com>
Tue, 2 Sep 2014 18:21:13 +0000 (18:21 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 2 Sep 2014 18:21:13 +0000 (18:21 +0000)
49 files changed:
features/mdsal/pom.xml
features/mdsal/src/main/resources/features.xml
features/netconf/src/main/resources/features.xml
opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/pom.xml
opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/src/main/resources/80-__repoName__.xml [moved from opendaylight/archetypes/opendaylight-configfile-archetype/src/main/resources/archetype-resources/src/main/resources/80-configfile.xml with 100% similarity]
opendaylight/commons/opendaylight/pom.xml
opendaylight/distribution/opendaylight/pom.xml
opendaylight/md-sal/compatibility/sal-compatibility/src/main/java/org/opendaylight/controller/sal/compatibility/NodeMapping.java
opendaylight/md-sal/pom.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/connect/dom/DomToBindingRpcForwarder.java
opendaylight/md-sal/sal-binding-it/src/main/java/org/opendaylight/controller/test/sal/binding/it/TestHelper.java
opendaylight/md-sal/sal-rest-connector/pom.xml
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/api/RestconfConstants.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/api/RestconfService.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/AbstractIdentifierAwareJaxRsProvider.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeJsonBodyWriter.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeXmlBodyWriter.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfApplication.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/StructuredDataToJsonProvider.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlToCompositeNodeReader.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlToNormalizedNodeReaderWithSchema.java [deleted file]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/InstanceIdentifierContext.java [moved from opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/InstanceIdWithSchemaNode.java with 71% similarity]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NormalizedDataPrunner.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NormalizedNodeContext.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/InvokeRpcMethodTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetAugmentedElementWhenEqualNamesTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestGetOperationTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/TestUtils.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java
opendaylight/md-sal/sal-rest-docgen/src/main/resources/WEB-INF/web.xml
opendaylight/md-sal/sal-rest-docgen/src/main/resources/explorer/index.html
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/AbstractStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/FlowStatsEntry.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/FlowStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/FlowTableStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/GroupDescStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/GroupStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/MeterConfigStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/MeterStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeConnectorStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/QueueStatsTracker.java
opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java
opendaylight/samples/northbound/loadbalancer/pom.xml

index 3a9de7abcd13cc74c80833a6152bd84a43e87003..41f1eab488212d58e28e220080f001db932e7880 100644 (file)
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-dom-xsql</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-dom-xsql-config</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal-binding-api</artifactId>
       <type>xml</type>
       <classifier>config</classifier>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-rest-docgen</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-annotations</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.core</groupId>
+      <artifactId>jackson-databind</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.datatype</groupId>
+      <artifactId>jackson-datatype-json-org</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.module</groupId>
+      <artifactId>jackson-module-jaxb-annotations</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.jaxrs</groupId>
+      <artifactId>jackson-jaxrs-base</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.fasterxml.jackson.jaxrs</groupId>
+      <artifactId>jackson-jaxrs-json-provider</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.json</groupId>
+      <artifactId>json</artifactId>
+    </dependency>
     <!-- test to validate features.xml -->
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
index 9e29fc84f813ffb15e4c55440824c2708785b538..0176a0388c76f46e57489a6d439446d632ced7e8 100644 (file)
         <bundle>mvn:org.opendaylight.controller/sal-dom-xsql/${project.version}</bundle>
         <configfile finalname="${config.configfile.directory}/${config.xsql.configfile}">mvn:org.opendaylight.controller/sal-dom-xsql-config/${project.version}/xml/config</configfile>
     </feature>
+    <feature name ='odl-mdsal-apidocs' version='${project.version}'>
+        <feature version='${project.version}'>odl-restconf</feature>
+        <bundle>mvn:org.opendaylight.controller/sal-rest-docgen/${project.version}</bundle>
+        <bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version}</bundle>
+        <bundle>mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version}</bundle>
+        <bundle>mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version}</bundle>
+        <bundle>mvn:com.fasterxml.jackson.datatype/jackson-datatype-json-org/${jackson.version}</bundle>
+        <bundle>mvn:com.fasterxml.jackson.module/jackson-module-jaxb-annotations/${jackson.version}</bundle>
+        <bundle>mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-base/${jackson.version}</bundle>
+        <bundle>mvn:com.fasterxml.jackson.jaxrs/jackson-jaxrs-json-provider/${jackson.version}</bundle>
+        <bundle>mvn:com.sun.jersey/jersey-core/${jersey.version}</bundle>
+        <bundle>mvn:com.sun.jersey/jersey-server/${jersey.version}</bundle>
+        <bundle>mvn:com.sun.jersey/jersey-servlet/${jersey.version}</bundle>
+        <bundle>wrap:mvn:org.json/json/${org.json.version}</bundle>
+    </feature>
 </features>
index 1453a5fb969a9d1e3f6b9f6bec88cebb59182d3f..0a6356231a84d1c671fa07e48212200a61451490 100644 (file)
@@ -19,6 +19,7 @@
   <feature name='odl-netconf-api' version='${project.version}' description="OpenDaylight :: Netconf :: API">
     <feature version='${protocol-framework.version}'>odl-protocol-framework</feature>
     <bundle>mvn:org.opendaylight.controller/netconf-api/${project.version}</bundle>
+    <bundle>mvn:org.opendaylight.controller/netconf-auth/${project.version}</bundle>
     <bundle>mvn:org.opendaylight.controller/ietf-netconf-monitoring/${project.version}</bundle>
     <bundle>mvn:org.opendaylight.controller/ietf-netconf-monitoring-extension/${project.version}</bundle>
     <bundle>mvn:org.opendaylight.yangtools.model/ietf-inet-types/${ietf-inet-types.version}</bundle>
index e217b9abfac46321e8922812ac4b2c4a1a7a6c39..3c778e262b66ec985a1b67b4ec78a4e542f71d03 100644 (file)
     will pick the pom.xml from the parent directory as the parent pom, which may or may
     not be correct.
   -->
+  <!--
+    Necessary TODO: Replace the contents of src/main/resources/80-${repoName}.xml with
+    the proper config subsystem contents for your module
+  -->
   <artifactId>${artifactId}</artifactId>
   <groupId>${groupId}</groupId>
   <description>Configuration files for md-sal</description>
@@ -23,7 +27,7 @@
   <packaging>jar</packaging>
   <properties>
       <!-- Optional TODO: Rename your configfile to taste -->
-      <configfile>80-configfile.xml</configfile>
+      <configfile>80-${repoName}.xml</configfile>
   </properties>
   <build>
     <plugins>
                   <type>xml</type>
                   <classifier>config</classifier>
                 </artifact>
+                <!--
+                  Optional TODO: Add additional config files
+                    You may need to add more than one config file
+                    if so, you just need to add additional <artifact> entries
+                    here WITH DIFFERENT CLASSIFIERS
+                    Example:
+                    <artifact>
+                      <file>${project.build.directory}/classes/<another-configfile></file>
+                      <type>xml</type>
+                      <classifier>config-<meaningful suffix to describe your other configfile></classifier>
+                    </artifact>
+                -->
               </artifacts>
             </configuration>
           </execution>
index b812fcbd8b8e12746509bf09ef293a821f70c61a..1fc32b37d8a364b5e0536480044bed122172e2f2 100644 (file)
         <artifactId>sal-dom-xsql</artifactId>
         <version>${mdsal.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal-dom-xsql-config</artifactId>
+        <version>${mdsal.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.opendaylight.controller</groupId>
         <artifactId>sal-core-api</artifactId>
         <artifactId>yang-data-composite-node</artifactId>
         <version>${yangtools.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.opendaylight.yangtools</groupId>
+        <artifactId>yang-data-codec-gson</artifactId>
+        <version>${yangtools.version}</version>
+      </dependency>
 
       <!-- yangtools dependencies -->
       <dependency>
index fc8b4453eadc48f4fecdae144b29ddf822e9967d..4ae35c905f122a6691072df720882ac88b68ddee 100644 (file)
           <groupId>org.opendaylight.yangtools</groupId>
           <artifactId>yang-parser-impl</artifactId>
         </dependency>
+        <dependency>
+          <groupId>org.opendaylight.yangtools</groupId>
+          <artifactId>yang-data-codec-gson</artifactId>
+        </dependency>
         <dependency>
           <groupId>org.opendaylight.yangtools</groupId>
           <artifactId>yang-data-composite-node</artifactId>
index be087abdb41099b9a5d8505ed20f7ac59624f531..b873f8a9fe060ff93c0279fbef0ad3cf59d0ab84 100644 (file)
@@ -14,6 +14,7 @@ import java.math.BigInteger;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
+import java.util.regex.Pattern;
 import org.opendaylight.controller.sal.common.util.Arguments;
 import org.opendaylight.controller.sal.core.AdvertisedBandwidth;
 import org.opendaylight.controller.sal.core.Bandwidth;
@@ -80,6 +81,12 @@ public final class NodeMapping {
 
     private final static Class<NodeConnector> NODECONNECTOR_CLASS = NodeConnector.class;
 
+    private final static Pattern COLON_NUMBERS_EOL = Pattern.compile(":[0-9]+$");
+
+    private final static Pattern NUMBERS_ONLY = Pattern.compile("[0-9]+");
+
+    private final static Pattern ALL_CHARS_TO_COLON = Pattern.compile("^.*:");
+
     private NodeMapping() {
         throw new UnsupportedOperationException("Utility class. Instantiation is not allowed.");
     }
@@ -182,15 +189,16 @@ public final class NodeMapping {
             return org.opendaylight.controller.sal.core.NodeConnector.SPECIALNODECONNECTORID;
         }
 
-        String nodeConnectorIdStripped = nodeConnectorId.getValue().replaceFirst("^.*:", "");
-        if (nodeConnectorIdStripped.matches("[0-9]+")) {
+        String nodeConnectorIdStripped = ALL_CHARS_TO_COLON.matcher(nodeConnectorId.getValue()).replaceFirst("");
+
+        if (NUMBERS_ONLY.matcher(nodeConnectorIdStripped).matches()) {
             Short nodeConnectorIdVal = null;
             try {
                 nodeConnectorIdVal = Short.valueOf(nodeConnectorIdStripped);
+                return nodeConnectorIdVal;
             } catch (NumberFormatException e) {
-                LOG.warn("nodeConnectorId not supported (short): {}", nodeConnectorIdStripped, e);
+                LOG.warn("nodeConnectorId not supported (long): {}", nodeConnectorIdStripped, e);
             }
-            return nodeConnectorIdVal;
         }
         return nodeConnectorIdStripped;
     }
@@ -198,7 +206,7 @@ public final class NodeMapping {
     public static NodeId toAdNodeId(final NodeConnectorId nodeConnectorId) {
         NodeId nodeId = null;
         if (nodeConnectorId != null) {
-            nodeId = new NodeId(nodeConnectorId.getValue().replaceFirst(":[0-9]+$", ""));
+            nodeId = new NodeId(COLON_NUMBERS_EOL.matcher(nodeConnectorId.getValue()).replaceFirst(""));
         }
         return nodeId;
     }
index c184c44d7d0fae3661632e3a3bb77f1d86ff879e..ce830eaa62d3e1f23c288f1969b1e79969252cf7 100644 (file)
 
     <!-- XSQL -->
     <module>sal-dom-xsql</module>
+    <module>sal-dom-xsql-config</module>
 
     <!-- Yang Test Models for MD-SAL -->
     <module>sal-test-model</module>
 
     <!-- Clustering -->
     <module>sal-remoterpc-connector</module>
-    <module>sal-dom-xsql-config</module>
   </modules>
 
   <build>
index ab6d56c15a5bdb696f5cb136965519206f40ef79..6be5f2d481515c1dd0b6fb140ff63fdf2e9d019b 100644 (file)
@@ -3,6 +3,12 @@ package org.opendaylight.controller.sal.binding.impl.connect.dom;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
 
+import com.google.common.base.Function;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+
 import java.lang.ref.WeakReference;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
@@ -21,13 +27,13 @@ import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
 import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.util.ClassLoaderUtils;
 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
 import org.opendaylight.yangtools.yang.binding.BindingMapping;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.RpcService;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
-import org.opendaylight.yangtools.yang.binding.util.ClassLoaderUtils;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
@@ -35,12 +41,6 @@ import org.opendaylight.yangtools.yang.data.impl.codec.BindingIndependentMapping
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Function;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-
 class DomToBindingRpcForwarder implements RpcImplementation, InvocationHandler {
 
     private final Logger LOG = LoggerFactory.getLogger(DomToBindingRpcForwarder.class);
@@ -65,8 +65,8 @@ class DomToBindingRpcForwarder implements RpcImplementation, InvocationHandler {
     static {
         try {
             EQUALS_METHOD = Object.class.getMethod("equals", Object.class);
-        } catch (Exception e) {
-            throw new RuntimeException(e);
+        } catch (NoSuchMethodException | SecurityException e) {
+            throw new ExceptionInInitializerError(e);
         }
     }
 
@@ -94,7 +94,7 @@ class DomToBindingRpcForwarder implements RpcImplementation, InvocationHandler {
     }
 
     /**
-     * Constructor for Routed RPC Forwareder.
+     * Constructor for Routed RPC Forwarder.
      *
      * @param service
      * @param context
index dba2908e9c4a9309bf3a1acba4e4fcc5974f7a03..efd35ccfa606d298834cb0eaa05a4d5d393a825a 100644 (file)
@@ -100,6 +100,7 @@ public class TestHelper {
                 mavenBundle("org.javassist", "javassist").versionAsInProject(), // //
 
                 mavenBundle(YANGTOOLS, "yang-data-api").versionAsInProject(), // //
+                mavenBundle(YANGTOOLS, "yang-data-util").versionAsInProject(), // //
                 mavenBundle(YANGTOOLS, "yang-data-impl").versionAsInProject(), // //
                 mavenBundle(YANGTOOLS, "yang-model-api").versionAsInProject(), // //
                 mavenBundle(YANGTOOLS, "yang-model-util").versionAsInProject(), // //
index e61cafa70b40c83f922460572ee232f5043ed4ea..fe5c9f39d8251e903c1ed5d9f173ced7df5f0f5b 100644 (file)
       <artifactId>jaxrs-api</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-core-spi</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-data-composite-node</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yang-data-codec-gson</artifactId>
+    </dependency>
+
     <dependency>
       <groupId>ch.qos.logback</groupId>
       <artifactId>logback-classic</artifactId>
       <artifactId>mockito-all</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.opendaylight.controller</groupId>
-      <artifactId>sal-core-spi</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.opendaylight.yangtools</groupId>
-      <artifactId>yang-data-composite-node</artifactId>
-      <version>0.6.2-SNAPSHOT</version>
-    </dependency>
   </dependencies>
 
   <build>
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/api/RestconfConstants.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/api/RestconfConstants.java
new file mode 100644 (file)
index 0000000..1ec1c29
--- /dev/null
@@ -0,0 +1,7 @@
+package org.opendaylight.controller.sal.rest.api;
+
+public interface RestconfConstants {
+
+
+    public static String IDENTIFIER = "identifier";
+}
index 9c149a21e60e70ff88c0371e936e3844c05b5985..4a46a3c26712c8e54da6650bd4e68b2de9ad91ca 100644 (file)
@@ -21,10 +21,12 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.controller.sal.restconf.impl.StructuredData;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
 
+
 /**
  * The URI hierarchy for the RESTCONF resources consists of an entry point container, 4 top-level resources, and 1
  * field.
@@ -109,14 +111,14 @@ public interface RestconfService {
     @Path("/config/{identifier:.+}")
     @Produces({ Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON,
             MediaType.APPLICATION_XML, MediaType.TEXT_XML })
-    public StructuredData readConfigurationData(@Encoded @PathParam("identifier") String identifier,
+    public NormalizedNodeContext readConfigurationData(@Encoded @PathParam("identifier") String identifier,
             @Context UriInfo uriInfo);
 
     @GET
     @Path("/operational/{identifier:.+}")
     @Produces({ Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON,
             MediaType.APPLICATION_XML, MediaType.TEXT_XML })
-    public StructuredData readOperationalData(@Encoded @PathParam("identifier") String identifier,
+    public NormalizedNodeContext readOperationalData(@Encoded @PathParam("identifier") String identifier,
             @Context UriInfo uriInfo);
 
     @PUT
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/AbstractIdentifierAwareJaxRsProvider.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/AbstractIdentifierAwareJaxRsProvider.java
new file mode 100644 (file)
index 0000000..978ae0d
--- /dev/null
@@ -0,0 +1,30 @@
+package org.opendaylight.controller.sal.rest.impl;
+
+import com.google.common.base.Optional;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
+import org.opendaylight.controller.sal.rest.api.RestconfConstants;
+import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
+
+public class AbstractIdentifierAwareJaxRsProvider {
+
+    @Context
+    private UriInfo uriInfo;
+
+    protected final String getIdentifier() {
+        return uriInfo.getPathParameters().getFirst(RestconfConstants.IDENTIFIER);
+    }
+
+    protected final Optional<InstanceIdentifierContext> getIdentifierWithSchema() {
+        return Optional.of(getInstanceIdentifierContext());
+    }
+
+    protected InstanceIdentifierContext getInstanceIdentifierContext() {
+        return ControllerContext.getInstance().toInstanceIdentifier(getIdentifier());
+    }
+
+    protected UriInfo getUriInfo() {
+        return uriInfo;
+    }
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/JsonNormalizedNodeBodyReader.java
new file mode 100644 (file)
index 0000000..dc989d2
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.rest.impl;
+
+import com.google.common.base.Optional;
+import com.google.gson.stream.JsonReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+import org.opendaylight.controller.sal.rest.api.Draft02;
+import org.opendaylight.controller.sal.rest.api.RestconfService;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
+import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.codec.gson.JsonParserStream;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Provider
+@Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft02.MediaTypes.OPERATION + RestconfService.JSON,
+        MediaType.APPLICATION_JSON })
+public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
+
+    private final static Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
+
+    @Override
+    public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+            final MediaType mediaType) {
+        return true;
+    }
+
+    @Override
+    public NormalizedNodeContext readFrom(final Class<NormalizedNodeContext> type, final Type genericType,
+            final Annotation[] annotations, final MediaType mediaType,
+            final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException,
+            WebApplicationException {
+        try {
+            Optional<InstanceIdentifierContext> path = getIdentifierWithSchema();
+            NormalizedNodeResult resultHolder = new NormalizedNodeResult();
+            NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
+            JsonParserStream jsonParser = JsonParserStream.create(writer, path.get().getSchemaContext());
+            JsonReader reader = new JsonReader(new InputStreamReader(entityStream));
+            jsonParser.parse(reader);
+            return new NormalizedNodeContext(path.get(),resultHolder.getResult());
+        } catch (Exception e) {
+            LOG.debug("Error parsing json input", e);
+
+            throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
+                    ErrorTag.MALFORMED_MESSAGE);
+        }
+    }
+}
+
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeJsonBodyWriter.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeJsonBodyWriter.java
new file mode 100644 (file)
index 0000000..af21db8
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.rest.impl;
+
+import com.google.common.base.Charsets;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.net.URI;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import org.opendaylight.controller.sal.rest.api.Draft02;
+import org.opendaylight.controller.sal.rest.api.RestconfService;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
+import org.opendaylight.yangtools.yang.data.codec.gson.JSONNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+@Provider
+@Produces({ Draft02.MediaTypes.API + RestconfService.JSON, Draft02.MediaTypes.DATA + RestconfService.JSON,
+    Draft02.MediaTypes.OPERATION + RestconfService.JSON, MediaType.APPLICATION_JSON })
+public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<NormalizedNodeContext> {
+
+    @Override
+    public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
+        return type.equals(NormalizedNodeContext.class);
+    }
+
+    @Override
+    public long getSize(final NormalizedNodeContext t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
+        return -1;
+    }
+
+    @Override
+    public void writeTo(final NormalizedNodeContext t, final Class<?> type, final Type genericType, final Annotation[] annotations,
+            final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
+                    throws IOException, WebApplicationException {
+        NormalizedNode<?, ?> data = t.getData();
+        InstanceIdentifierContext context = t.getInstanceIdentifierContext();
+        DataSchemaNode schema = context.getSchemaNode();
+        SchemaPath path = context.getSchemaNode().getPath();
+        OutputStreamWriter outputWriter = new OutputStreamWriter(entityStream, Charsets.UTF_8);
+        if (data == null) {
+            throw new RestconfDocumentedException(Response.Status.NOT_FOUND);
+        }
+
+
+        URI initialNs = null;
+        outputWriter.write('{');
+        if (!SchemaPath.ROOT.equals(path)) {
+            path = path.getParent();
+            // FIXME: Add proper handling of reading root.
+        }
+        if(data instanceof MapEntryNode) {
+            data = ImmutableNodes.mapNodeBuilder(data.getNodeType()).withChild(((MapEntryNode) data)).build();
+        }
+        if(!schema.isAugmenting() && !(schema instanceof SchemaContext)) {
+            initialNs = schema.getQName().getNamespace();
+        }
+        NormalizedNodeStreamWriter jsonWriter = JSONNormalizedNodeStreamWriter.create(context.getSchemaContext(),path,initialNs,outputWriter);
+        NormalizedNodeWriter nnWriter = NormalizedNodeWriter.forStreamWriter(jsonWriter);
+        nnWriter.write(data);
+        nnWriter.flush();
+
+        outputWriter.write('}');
+        outputWriter.flush();
+    }
+
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeXmlBodyWriter.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/NormalizedNodeXmlBodyWriter.java
new file mode 100644 (file)
index 0000000..ef12f93
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.rest.impl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import org.opendaylight.controller.sal.rest.api.Draft02;
+import org.opendaylight.controller.sal.rest.api.RestconfService;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
+import org.opendaylight.yangtools.yang.data.impl.codec.xml.XMLStreamNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+@Provider
+@Produces({ Draft02.MediaTypes.API + RestconfService.XML, Draft02.MediaTypes.DATA + RestconfService.XML,
+    Draft02.MediaTypes.OPERATION + RestconfService.XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+
+public class NormalizedNodeXmlBodyWriter implements MessageBodyWriter<NormalizedNodeContext> {
+
+
+    private static final XMLOutputFactory XML_FACTORY;
+
+    static {
+        XML_FACTORY  = XMLOutputFactory.newFactory();
+        XML_FACTORY.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
+    }
+
+
+    @Override
+    public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
+        return type.equals(NormalizedNodeContext.class);
+    }
+
+    @Override
+    public long getSize(final NormalizedNodeContext t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
+        return -1;
+    }
+
+    @Override
+    public void writeTo(final NormalizedNodeContext t, final Class<?> type, final Type genericType, final Annotation[] annotations,
+            final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
+                    throws IOException, WebApplicationException {
+        InstanceIdentifierContext pathContext = t.getInstanceIdentifierContext();
+        if (t.getData() == null) {
+            throw new RestconfDocumentedException(Response.Status.NOT_FOUND);
+        }
+
+        XMLStreamWriter xmlWriter;
+        try {
+            xmlWriter = XML_FACTORY.createXMLStreamWriter(entityStream);
+        } catch (XMLStreamException e) {
+            throw new IllegalStateException(e);
+        } catch (FactoryConfigurationError e) {
+            throw new IllegalStateException(e);
+        }
+        NormalizedNode<?, ?> data = t.getData();
+        SchemaPath schemaPath = pathContext.getSchemaNode().getPath().getParent();
+        if(data instanceof MapEntryNode) {
+            data = ImmutableNodes.mapNodeBuilder(data.getNodeType()).addChild((MapEntryNode) data).build();
+            //schemaPath = pathContext.getSchemaNode().getPath();
+        }
+
+        NormalizedNodeStreamWriter jsonWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter,pathContext.getSchemaContext(),schemaPath);
+        NormalizedNodeWriter nnWriter = NormalizedNodeWriter.forStreamWriter(jsonWriter);
+
+        nnWriter.write(data);
+        nnWriter.flush();
+    }
+}
index b4b2a1f9ef7249734e128456a33876abc3862ae8..a298f4b0937ae71c146c9baada15a14535b7de9d 100644 (file)
@@ -19,7 +19,13 @@ public class RestconfApplication extends Application {
 
     @Override
     public Set<Class<?>> getClasses() {
-        return ImmutableSet.<Class<?>> of(RestconfDocumentedExceptionMapper.class);
+        return ImmutableSet.<Class<?>> builder()
+                .add(RestconfDocumentedExceptionMapper.class)
+                .add(XmlNormalizedNodeBodyReader.class)
+                .add(JsonNormalizedNodeBodyReader.class)
+                .add(NormalizedNodeJsonBodyWriter.class)
+                .add(NormalizedNodeXmlBodyWriter.class)
+                .build();
     }
 
     @Override
@@ -33,10 +39,10 @@ public class RestconfApplication extends Application {
         singletons.add(controllerContext);
         singletons.add(brokerFacade);
         singletons.add(restconfImpl);
-        singletons.add(XmlToCompositeNodeProvider.INSTANCE);
         singletons.add(StructuredDataToXmlProvider.INSTANCE);
-        singletons.add(JsonToCompositeNodeProvider.INSTANCE);
         singletons.add(StructuredDataToJsonProvider.INSTANCE);
+        singletons.add(JsonToCompositeNodeProvider.INSTANCE);
+        singletons.add(XmlToCompositeNodeProvider.INSTANCE);
         return singletons;
     }
 
index 933ed0f849e7171b7c16c423c5462aa8de1bb25a..063d2f51afffdd0c7094d7363d95795182b5cd8e 100644 (file)
@@ -30,27 +30,24 @@ import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 
 @Provider
 @Produces({ Draft02.MediaTypes.API + RestconfService.JSON, Draft02.MediaTypes.DATA + RestconfService.JSON,
-        Draft02.MediaTypes.OPERATION + RestconfService.JSON, MediaType.APPLICATION_JSON })
+    Draft02.MediaTypes.OPERATION + RestconfService.JSON, MediaType.APPLICATION_JSON })
 public enum StructuredDataToJsonProvider implements MessageBodyWriter<StructuredData> {
     INSTANCE;
 
     @Override
-    public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
-            final MediaType mediaType) {
+    public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
         return type.equals(StructuredData.class);
     }
 
     @Override
-    public long getSize(final StructuredData t, final Class<?> type, final Type genericType,
-            final Annotation[] annotations, final MediaType mediaType) {
+    public long getSize(final StructuredData t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
         return -1;
     }
 
     @Override
-    public void writeTo(final StructuredData t, final Class<?> type, final Type genericType,
-            final Annotation[] annotations, final MediaType mediaType,
-            final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException,
-            WebApplicationException {
+    public void writeTo(final StructuredData t, final Class<?> type, final Type genericType, final Annotation[] annotations,
+            final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream)
+                    throws IOException, WebApplicationException {
         CompositeNode data = t.getData();
         if (data == null) {
             throw new RestconfDocumentedException(Response.Status.NOT_FOUND);
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlNormalizedNodeBodyReader.java
new file mode 100644 (file)
index 0000000..062a448
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.rest.impl;
+
+import com.google.common.base.Optional;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.List;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Provider;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.opendaylight.controller.sal.rest.api.Draft02;
+import org.opendaylight.controller.sal.rest.api.RestconfService;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
+import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlUtils;
+import org.opendaylight.yangtools.yang.data.impl.schema.transform.dom.parser.DomToNormalizedNodeParserFactory;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+@Provider
+@Consumes({ Draft02.MediaTypes.DATA + RestconfService.XML, Draft02.MediaTypes.OPERATION + RestconfService.XML,
+    MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
+
+    private final static Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
+    private final static DomToNormalizedNodeParserFactory DOM_PARSER_FACTORY = DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER);
+    private static final DocumentBuilderFactory BUILDERFACTORY;
+
+    static {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setNamespaceAware(true);
+        factory.setCoalescing(true);
+        factory.setIgnoringElementContentWhitespace(true);
+        factory.setIgnoringComments(true);
+        BUILDERFACTORY = factory;
+    }
+
+    @Override
+    public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
+            final MediaType mediaType) {
+        return true;
+    }
+
+    @Override
+    public NormalizedNodeContext readFrom(final Class<NormalizedNodeContext> type, final Type genericType,
+            final Annotation[] annotations, final MediaType mediaType,
+            final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException,
+            WebApplicationException {
+        try {
+            Optional<InstanceIdentifierContext> path = getIdentifierWithSchema();
+
+            final DocumentBuilder dBuilder;
+            try {
+                dBuilder = BUILDERFACTORY.newDocumentBuilder();
+            } catch (ParserConfigurationException e) {
+                throw new RuntimeException("Failed to parse XML document", e);
+            }
+            Document doc = dBuilder.parse(entityStream);
+
+            NormalizedNode<?, ?> result = parse(path.get(),doc);
+            return new NormalizedNodeContext(path.get(),result);
+        } catch (Exception e) {
+            LOG.debug("Error parsing json input", e);
+
+            throw new RestconfDocumentedException("Error parsing input: " + e.getMessage(), ErrorType.PROTOCOL,
+                    ErrorTag.MALFORMED_MESSAGE);
+        }
+    }
+
+    private static NormalizedNode<?,?> parse(InstanceIdentifierContext pathContext,Document doc) {
+        List<Element> elements = Collections.singletonList(doc.getDocumentElement());
+        DataSchemaNode schemaNode = pathContext.getSchemaNode();
+        if(schemaNode instanceof ContainerSchemaNode) {
+            return DOM_PARSER_FACTORY.getContainerNodeParser().parse(Collections.singletonList(doc.getDocumentElement()), (ContainerSchemaNode) schemaNode);
+        } else if(schemaNode instanceof ListSchemaNode) {
+            ListSchemaNode casted = (ListSchemaNode) schemaNode;
+            return DOM_PARSER_FACTORY.getMapEntryNodeParser().parse(elements, casted);
+        }
+        return null;
+    }
+}
+
index 5944d6003e9e1e33dba8a0b482a60de5f01ac4c0..6b9da80c685f913cce59edb19bc4588b16e0ed57 100644 (file)
@@ -28,6 +28,7 @@ import org.opendaylight.controller.sal.restconf.impl.NodeWrapper;
 import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
 import org.opendaylight.yangtools.yang.data.api.Node;
 
+@Deprecated
 public class XmlToCompositeNodeReader {
 
     private final static XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
@@ -45,7 +46,6 @@ public class XmlToCompositeNodeReader {
         }
 
         eventReader = xmlInputFactory.createXMLEventReader(entityStream);
-
         if (eventReader.hasNext()) {
             XMLEvent element = eventReader.peek();
             if (element.isStartDocument()) {
@@ -110,7 +110,7 @@ public class XmlToCompositeNodeReader {
         return entityStream;
     }
 
-    private boolean isInputStreamEmpty(InputStream entityStream) throws IOException {
+    private boolean isInputStreamEmpty(final InputStream entityStream) throws IOException {
         boolean isEmpty = false;
         entityStream.mark(1);
         if (entityStream.read() == -1) {
@@ -180,7 +180,7 @@ public class XmlToCompositeNodeReader {
                 resolveValueOfElement(data, startElement));
     }
 
-    private String getValueOf(StartElement startElement) throws XMLStreamException {
+    private String getValueOf(final StartElement startElement) throws XMLStreamException {
         String data = null;
         if (eventReader.hasNext()) {
             final XMLEvent innerEvent = eventReader.peek();
@@ -201,7 +201,7 @@ public class XmlToCompositeNodeReader {
         return data == null ? null : data.trim();
     }
 
-    private String getAdditionalData(XMLEvent event) throws XMLStreamException {
+    private String getAdditionalData(final XMLEvent event) throws XMLStreamException {
         String data = "";
         if (eventReader.hasNext()) {
             final XMLEvent innerEvent = eventReader.peek();
@@ -216,16 +216,16 @@ public class XmlToCompositeNodeReader {
         return data;
     }
 
-    private String getLocalNameFor(StartElement startElement) {
+    private String getLocalNameFor(final StartElement startElement) {
         return startElement.getName().getLocalPart();
     }
 
-    private URI getNamespaceFor(StartElement startElement) {
+    private URI getNamespaceFor(final StartElement startElement) {
         String namespaceURI = startElement.getName().getNamespaceURI();
         return namespaceURI.isEmpty() ? null : URI.create(namespaceURI);
     }
 
-    private Object resolveValueOfElement(String value, StartElement startElement) {
+    private Object resolveValueOfElement(final String value, final StartElement startElement) {
         // it could be instance-identifier Built-In Type
         if (value.startsWith("/")) {
             IdentityValuesDTO iiValue = RestUtil.asInstanceIdentifier(value, new RestUtil.PrefixMapingFromXml(
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlToNormalizedNodeReaderWithSchema.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/XmlToNormalizedNodeReaderWithSchema.java
deleted file mode 100644 (file)
index 935d96c..0000000
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.rest.impl;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import java.io.BufferedInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Stack;
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.events.Characters;
-import javax.xml.stream.events.StartElement;
-import javax.xml.stream.events.XMLEvent;
-import org.opendaylight.controller.sal.restconf.impl.CompositeNodeWrapper;
-import org.opendaylight.controller.sal.restconf.impl.IdentityValuesDTO;
-import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
-import org.opendaylight.controller.sal.restconf.impl.NodeWrapper;
-import org.opendaylight.controller.sal.restconf.impl.RestCodec;
-import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
-import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.controller.sal.restconf.impl.SimpleNodeWrapper;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.Node;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-
-public class XmlToNormalizedNodeReaderWithSchema {
-
-    private final static XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
-    private XMLEventReader eventReader;
-    private InstanceIdWithSchemaNode iiWithSchema;
-
-    public XmlToNormalizedNodeReaderWithSchema(final InstanceIdWithSchemaNode iiWithSchema) {
-        this.iiWithSchema = iiWithSchema;
-    }
-
-    public Node<?> read(InputStream entityStream) throws XMLStreamException, UnsupportedFormatException, IOException {
-        // Get an XML stream which can be marked, and reset, so we can check and see if there is
-        // any content being provided.
-        entityStream = getMarkableStream(entityStream);
-
-        if (isInputStreamEmpty(entityStream)) {
-            return null;
-        }
-
-        eventReader = xmlInputFactory.createXMLEventReader(entityStream);
-        if (eventReader.hasNext()) {
-            XMLEvent element = eventReader.peek();
-            if (element.isStartDocument()) {
-                eventReader.nextEvent();
-            }
-        }
-
-        final Stack<NodeWrapper<?>> processingQueue = new Stack<>();
-        NodeWrapper<?> root = null;
-        NodeWrapper<?> element = null;
-        Stack<DataSchemaNode> processingQueueSchema = new Stack<>();
-
-        while (eventReader.hasNext()) {
-            final XMLEvent event = eventReader.nextEvent();
-
-            if (event.isStartElement()) {
-                final StartElement startElement = event.asStartElement();
-                CompositeNodeWrapper compParentNode = null;
-                if (!processingQueue.isEmpty() && processingQueue.peek() instanceof CompositeNodeWrapper) {
-                    compParentNode = (CompositeNodeWrapper) processingQueue.peek();
-                    findSchemaNodeForElement(startElement, processingQueueSchema);
-                } else {
-                    processingQueueSchema = checkElementAndSchemaNodeNameAndNamespace(startElement,
-                            iiWithSchema.getSchemaNode());
-                    DataSchemaNode currentSchemaNode = processingQueueSchema.peek();
-                    if (!(currentSchemaNode instanceof ListSchemaNode)
-                            && !(currentSchemaNode instanceof ContainerSchemaNode)) {
-                        throw new UnsupportedFormatException(
-                                "Top level element has to be of type list or container schema node.");
-                    }
-                }
-
-                NodeWrapper<?> newNode = null;
-                if (isCompositeNodeEvent(event)) {
-                    newNode = resolveCompositeNodeFromStartElement(processingQueueSchema.peek().getQName());
-                    if (root == null) {
-                        root = newNode;
-                    }
-                } else if (isSimpleNodeEvent(event)) {
-                    newNode = resolveSimpleNodeFromStartElement(processingQueueSchema.peek(), getValueOf(startElement));
-                    if (root == null) {
-                        root = newNode;
-                    }
-                }
-
-                if (newNode != null) {
-                    processingQueue.push(newNode);
-                    if (compParentNode != null) {
-                        compParentNode.addValue(newNode);
-                    }
-                }
-            } else if (event.isEndElement()) {
-                element = processingQueue.pop();
-//                if(((EndElement)event).getName().getLocalPart().equals
-                processingQueueSchema.pop();
-            }
-        }
-
-        if (!root.getLocalName().equals(element.getLocalName())) {
-            throw new UnsupportedFormatException("XML should contain only one root element");
-        }
-
-        return root.unwrap();
-    }
-
-    private void findSchemaNodeForElement(StartElement element, Stack<DataSchemaNode> processingQueueSchema) {
-        DataSchemaNode currentSchemaNode = processingQueueSchema.peek();
-        if (currentSchemaNode instanceof DataNodeContainer) {
-            final URI realNamespace = getNamespaceFor(element);
-            final String realName = getLocalNameFor(element);
-            Map<URI, DataSchemaNode> childNamesakes = resolveChildsWithNameAsElement(
-                    ((DataNodeContainer) currentSchemaNode), realName);
-            DataSchemaNode childDataSchemaNode = childNamesakes.get(realNamespace);
-            if (childDataSchemaNode == null) {
-                throw new RestconfDocumentedException("Element " + realName + " has namespace " + realNamespace
-                        + ". Available namespaces are: " + childNamesakes.keySet(), ErrorType.APPLICATION,
-                        ErrorTag.INVALID_VALUE);
-            }
-            processingQueueSchema.push(childDataSchemaNode);
-        } else {
-            throw new RestconfDocumentedException("Element " + processingQueueSchema.peek().getQName().getLocalName()
-                    + " should be data node container .", ErrorType.APPLICATION, ErrorTag.INVALID_VALUE);
-        }
-
-    }
-
-    /**
-     * Returns map of data schema node which are accesible by URI which have equal name
-     */
-    private Map<URI, DataSchemaNode> resolveChildsWithNameAsElement(final DataNodeContainer dataNodeContainer,
-            final String realName) {
-        final Map<URI, DataSchemaNode> namespaceToDataSchemaNode = new HashMap<URI, DataSchemaNode>();
-        for (DataSchemaNode dataSchemaNode : dataNodeContainer.getChildNodes()) {
-            if (dataSchemaNode.equals(realName)) {
-                namespaceToDataSchemaNode.put(dataSchemaNode.getQName().getNamespace(), dataSchemaNode);
-            }
-        }
-        return namespaceToDataSchemaNode;
-    }
-
-    private final Stack<DataSchemaNode> checkElementAndSchemaNodeNameAndNamespace(final StartElement startElement,
-            final DataSchemaNode node) {
-        checkArgument(startElement != null, "Start Element cannot be NULL!");
-        final String expectedName = node.getQName().getLocalName();
-        final String xmlName = getLocalNameFor(startElement);
-        final URI expectedNamespace = node.getQName().getNamespace();
-        final URI xmlNamespace = getNamespaceFor(startElement);
-        if (!expectedName.equals(xmlName)) {
-            throw new RestconfDocumentedException("Xml element name: " + xmlName + "\nSchema node name: "
-                    + expectedName, org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType.APPLICATION,
-                    ErrorTag.INVALID_VALUE);
-        }
-
-        if (xmlNamespace != null && !expectedNamespace.equals(xmlNamespace)) {
-            throw new RestconfDocumentedException("Xml element ns: " + xmlNamespace + "\nSchema node ns: "
-                    + expectedNamespace,
-                    org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType.APPLICATION,
-                    ErrorTag.INVALID_VALUE);
-        }
-        Stack<DataSchemaNode> processingQueueSchema = new Stack<>();
-        processingQueueSchema.push(node);
-        return processingQueueSchema;
-    }
-
-    /**
-     * If the input stream is not markable, then it wraps the input stream with a buffered stream, which is mark able.
-     * That way we can check if the stream is empty safely.
-     *
-     * @param entityStream
-     * @return
-     */
-    private InputStream getMarkableStream(InputStream entityStream) {
-        if (!entityStream.markSupported()) {
-            entityStream = new BufferedInputStream(entityStream);
-        }
-        return entityStream;
-    }
-
-    private boolean isInputStreamEmpty(final InputStream entityStream) throws IOException {
-        boolean isEmpty = false;
-        entityStream.mark(1);
-        if (entityStream.read() == -1) {
-            isEmpty = true;
-        }
-        entityStream.reset();
-        return isEmpty;
-    }
-
-    private boolean isSimpleNodeEvent(final XMLEvent event) throws XMLStreamException {
-        checkArgument(event != null, "XML Event cannot be NULL!");
-        if (event.isStartElement()) {
-            XMLEvent innerEvent = skipCommentsAndWhitespace();
-            if (innerEvent != null && (innerEvent.isCharacters() || innerEvent.isEndElement())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private boolean isCompositeNodeEvent(final XMLEvent event) throws XMLStreamException {
-        checkArgument(event != null, "XML Event cannot be NULL!");
-        if (event.isStartElement()) {
-            XMLEvent innerEvent = skipCommentsAndWhitespace();
-            if (innerEvent != null) {
-                if (innerEvent.isStartElement()) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    private XMLEvent skipCommentsAndWhitespace() throws XMLStreamException {
-        while (eventReader.hasNext()) {
-            XMLEvent event = eventReader.peek();
-            if (event.getEventType() == XMLStreamConstants.COMMENT) {
-                eventReader.nextEvent();
-                continue;
-            }
-
-            if (event.isCharacters()) {
-                Characters chars = event.asCharacters();
-                if (chars.isWhiteSpace()) {
-                    eventReader.nextEvent();
-                    continue;
-                }
-            }
-            return event;
-        }
-        return null;
-    }
-
-    private CompositeNodeWrapper resolveCompositeNodeFromStartElement(final QName qName) {
-        // checkArgument(startElement != null, "Start Element cannot be NULL!");
-        CompositeNodeWrapper compositeNodeWrapper = new CompositeNodeWrapper("dummy");
-        compositeNodeWrapper.setQname(qName);
-        return compositeNodeWrapper;
-
-    }
-
-    private SimpleNodeWrapper resolveSimpleNodeFromStartElement(final DataSchemaNode node, final String value)
-            throws XMLStreamException {
-        // checkArgument(startElement != null, "Start Element cannot be NULL!");
-        Object deserializedValue = null;
-
-        if (node instanceof LeafSchemaNode) {
-            TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(((LeafSchemaNode) node).getType());
-            deserializedValue = RestCodec.from(baseType, iiWithSchema.getMountPoint()).deserialize(value);
-        } else if (node instanceof LeafListSchemaNode) {
-            TypeDefinition<?> baseType = RestUtil.resolveBaseTypeFrom(((LeafListSchemaNode) node).getType());
-            deserializedValue = RestCodec.from(baseType, iiWithSchema.getMountPoint()).deserialize(value);
-        }
-        // String data;
-        // if (data == null) {
-        // return new EmptyNodeWrapper(getNamespaceFor(startElement), getLocalNameFor(startElement));
-        // }
-        SimpleNodeWrapper simpleNodeWrapper = new SimpleNodeWrapper("dummy", deserializedValue);
-        simpleNodeWrapper.setQname(node.getQName());
-        return simpleNodeWrapper;
-    }
-
-    private String getValueOf(final StartElement startElement) throws XMLStreamException {
-        String data = null;
-        if (eventReader.hasNext()) {
-            final XMLEvent innerEvent = eventReader.peek();
-            if (innerEvent.isCharacters()) {
-                final Characters chars = innerEvent.asCharacters();
-                if (!chars.isWhiteSpace()) {
-                    data = innerEvent.asCharacters().getData();
-                    data = data + getAdditionalData(eventReader.nextEvent());
-                }
-            } else if (innerEvent.isEndElement()) {
-                if (startElement.getLocation().getCharacterOffset() == innerEvent.getLocation().getCharacterOffset()) {
-                    data = null;
-                } else {
-                    data = "";
-                }
-            }
-        }
-        return data == null ? null : data.trim();
-    }
-
-    private String getAdditionalData(final XMLEvent event) throws XMLStreamException {
-        String data = "";
-        if (eventReader.hasNext()) {
-            final XMLEvent innerEvent = eventReader.peek();
-            if (innerEvent.isCharacters() && !innerEvent.isEndElement()) {
-                final Characters chars = innerEvent.asCharacters();
-                if (!chars.isWhiteSpace()) {
-                    data = innerEvent.asCharacters().getData();
-                    data = data + getAdditionalData(eventReader.nextEvent());
-                }
-            }
-        }
-        return data;
-    }
-
-    private String getLocalNameFor(final StartElement startElement) {
-        return startElement.getName().getLocalPart();
-    }
-
-    private URI getNamespaceFor(final StartElement startElement) {
-        String namespaceURI = startElement.getName().getNamespaceURI();
-        return namespaceURI.isEmpty() ? null : URI.create(namespaceURI);
-    }
-
-    private Object resolveValueOfElement(final String value, final StartElement startElement) {
-        // it could be instance-identifier Built-In Type
-        if (value.startsWith("/")) {
-            IdentityValuesDTO iiValue = RestUtil.asInstanceIdentifier(value, new RestUtil.PrefixMapingFromXml(
-                    startElement));
-            if (iiValue != null) {
-                return iiValue;
-            }
-        }
-        // it could be identityref Built-In Type
-        String[] namespaceAndValue = value.split(":");
-        if (namespaceAndValue.length == 2) {
-            String namespace = startElement.getNamespaceContext().getNamespaceURI(namespaceAndValue[0]);
-            if (namespace != null && !namespace.isEmpty()) {
-                return new IdentityValuesDTO(namespace, namespaceAndValue[1], namespaceAndValue[0], value);
-            }
-        }
-        // it is not "prefix:value" but just "value"
-        return value;
-    }
-
-}
index f11e25c046feab69fe3c41f229dfdbadd496e18d..8dbc5b50ee5dbd8ac374ef7d1452384442923085 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.sal.restconf.impl;
 
 import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.ListenableFuture;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@@ -40,6 +41,7 @@ import javax.ws.rs.core.Response.Status;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
@@ -176,31 +178,39 @@ public class BrokerFacade {
     private NormalizedNode<?, ?> readDataViaTransaction(final DOMDataReadTransaction transaction,
             LogicalDatastoreType datastore, YangInstanceIdentifier path) {
         LOG.trace("Read " + datastore.name() + " via Restconf: {}", path);
-        final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> listenableFuture =
-                                                                 transaction.read(datastore, path);
+        final ListenableFuture<Optional<NormalizedNode<?, ?>>> listenableFuture = transaction.read(datastore, path);
+        if (listenableFuture != null) {
+            Optional<NormalizedNode<?, ?>> optional;
+            try {
+                LOG.debug("Reading result data from transaction.");
+                optional = listenableFuture.get();
+            } catch (InterruptedException | ExecutionException e) {
+                throw new RestconfDocumentedException("Problem to get data from transaction.", e.getCause());
 
-        try {
-            Optional<NormalizedNode<?, ?>> optional = listenableFuture.checkedGet();
-            return optional.isPresent() ? optional.get() : null;
-        } catch(ReadFailedException e) {
-            throw new RestconfDocumentedException(e.getMessage(), e, e.getErrorList());
+            }
+            if (optional != null) {
+                if (optional.isPresent()) {
+                    return optional.get();
+                }
+            }
         }
+        return null;
     }
 
     private CheckedFuture<Void, TransactionCommitFailedException> postDataViaTransaction(
             final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
             final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, DataNormalizationOperation<?> root) {
-        CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> futureDatastoreData =
-                                                               rWTransaction.read(datastore, path);
+        ListenableFuture<Optional<NormalizedNode<?, ?>>> futureDatastoreData = rWTransaction.read(datastore, path);
         try {
-            final Optional<NormalizedNode<?, ?>> optionalDatastoreData = futureDatastoreData.checkedGet();
+            final Optional<NormalizedNode<?, ?>> optionalDatastoreData = futureDatastoreData.get();
             if (optionalDatastoreData.isPresent() && payload.equals(optionalDatastoreData.get())) {
-                LOG.trace("Post Configuration via Restconf was not executed because data already exists :{}", path);
+                String errMsg = "Post Configuration via Restconf was not executed because data already exists";
+                LOG.trace(errMsg + ":{}", path);
                 throw new RestconfDocumentedException("Data already exists for path: " + path, ErrorType.PROTOCOL,
                         ErrorTag.DATA_EXISTS);
             }
-        } catch(ReadFailedException e) {
-            LOG.warn("Error reading from datastore with path: " + path, e);
+        } catch (InterruptedException | ExecutionException e) {
+            LOG.trace("It wasn't possible to get data loaded from datastore at path " + path);
         }
 
         ensureParentsByMerge(datastore, path, rWTransaction, root);
@@ -241,21 +251,27 @@ public class BrokerFacade {
             try {
                 currentOp = currentOp.getChild(currentArg);
             } catch (DataNormalizationException e) {
-                throw new RestconfDocumentedException(
-                        String.format("Error normalizing data for path %s", normalizedPath), e);
+                throw new IllegalArgumentException(
+                        String.format("Invalid child encountered in path %s", normalizedPath), e);
             }
             currentArguments.add(currentArg);
             YangInstanceIdentifier currentPath = YangInstanceIdentifier.create(currentArguments);
 
+            final Boolean exists;
+
             try {
 
-                boolean exists = rwTx.exists(store, currentPath).checkedGet();
-                if (!exists && iterator.hasNext()) {
-                    rwTx.merge(store, currentPath, currentOp.createDefault(currentArg));
-                }
+                CheckedFuture<Boolean, ReadFailedException> future =
+                    rwTx.exists(store, currentPath);
+                exists = future.checkedGet();
             } catch (ReadFailedException e) {
                 LOG.error("Failed to read pre-existing data from store {} path {}", store, currentPath, e);
-                throw new RestconfDocumentedException("Failed to read pre-existing data", e);
+                throw new IllegalStateException("Failed to read pre-existing data", e);
+            }
+
+
+            if (!exists && iterator.hasNext()) {
+                rwTx.merge(store, currentPath, currentOp.createDefault(currentArg));
             }
         }
     }
index 93e6a2c0e98504e169703423837177078992c2a4..b0a6e0d6f3885f20242d483044c0cfa92af1dea6 100644 (file)
@@ -118,15 +118,19 @@ public class ControllerContext implements SchemaContextListener {
         this.onGlobalContextUpdated(schemas);
     }
 
-    public InstanceIdWithSchemaNode toInstanceIdentifier(final String restconfInstance) {
+    public InstanceIdentifierContext toInstanceIdentifier(final String restconfInstance) {
         return this.toIdentifier(restconfInstance, false);
     }
 
-    public InstanceIdWithSchemaNode toMountPointIdentifier(final String restconfInstance) {
+    public SchemaContext getGlobalSchema() {
+        return globalSchema;
+    }
+
+    public InstanceIdentifierContext toMountPointIdentifier(final String restconfInstance) {
         return this.toIdentifier(restconfInstance, true);
     }
 
-    private InstanceIdWithSchemaNode toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
+    private InstanceIdentifierContext toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
         this.checkPreconditions();
 
         final List<String> pathArgs = urlPathArgsDecode(SLASH_SPLITTER.split(restconfInstance));
@@ -144,7 +148,7 @@ public class ControllerContext implements SchemaContextListener {
 
         InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
         Module latestModule = globalSchema.findModuleByName(startModule, null);
-        InstanceIdWithSchemaNode iiWithSchemaNode = this.collectPathArguments(builder, pathArgs, latestModule, null,
+        InstanceIdentifierContext iiWithSchemaNode = this.collectPathArguments(builder, pathArgs, latestModule, null,
                 toMountPointIdentifier);
 
         if (iiWithSchemaNode == null) {
@@ -462,7 +466,7 @@ public class ControllerContext implements SchemaContextListener {
         return object == null ? "" : URLEncoder.encode(object.toString(), ControllerContext.URI_ENCODING_CHAR_SET);
     }
 
-    private InstanceIdWithSchemaNode collectPathArguments(final InstanceIdentifierBuilder builder,
+    private InstanceIdentifierContext collectPathArguments(final InstanceIdentifierBuilder builder,
             final List<String> strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint,
             final boolean returnJustMountPoint) {
         Preconditions.<List<String>> checkNotNull(strings);
@@ -472,7 +476,7 @@ public class ControllerContext implements SchemaContextListener {
         }
 
         if (strings.isEmpty()) {
-            return new InstanceIdWithSchemaNode(builder.toInstance(), ((DataSchemaNode) parentNode), mountPoint);
+            return new InstanceIdentifierContext(builder.toInstance(), ((DataSchemaNode) parentNode), mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
         }
 
         String head = strings.iterator().next();
@@ -511,12 +515,12 @@ public class ControllerContext implements SchemaContextListener {
 
                 if (returnJustMountPoint) {
                     YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
-                    return new InstanceIdWithSchemaNode(instance, mountPointSchema, mount);
+                    return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
                 }
 
                 if (strings.size() == 1) {
                     YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
-                    return new InstanceIdWithSchemaNode(instance, mountPointSchema, mount);
+                    return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
                 }
 
                 final String moduleNameBehindMountPoint = toModuleName(strings.get(1));
@@ -632,7 +636,7 @@ public class ControllerContext implements SchemaContextListener {
                     returnJustMountPoint);
         }
 
-        return new InstanceIdWithSchemaNode(builder.toInstance(), targetNode, mountPoint);
+        return new InstanceIdentifierContext(builder.toInstance(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
     }
 
     public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name,
@@ -10,18 +10,21 @@ package org.opendaylight.controller.sal.restconf.impl;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-public class InstanceIdWithSchemaNode {
+public class InstanceIdentifierContext {
 
     private final YangInstanceIdentifier instanceIdentifier;
     private final DataSchemaNode schemaNode;
     private final DOMMountPoint mountPoint;
+    private final SchemaContext schemaContext;
 
-    public InstanceIdWithSchemaNode(YangInstanceIdentifier instanceIdentifier, DataSchemaNode schemaNode,
-            DOMMountPoint mountPoint) {
+    public InstanceIdentifierContext(YangInstanceIdentifier instanceIdentifier, DataSchemaNode schemaNode,
+            DOMMountPoint mountPoint,SchemaContext context) {
         this.instanceIdentifier = instanceIdentifier;
         this.schemaNode = schemaNode;
         this.mountPoint = mountPoint;
+        this.schemaContext = context;
     }
 
     public YangInstanceIdentifier getInstanceIdentifier() {
@@ -36,4 +39,8 @@ public class InstanceIdWithSchemaNode {
         return mountPoint;
     }
 
+    public SchemaContext getSchemaContext() {
+        return schemaContext;
+    }
+
 }
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NormalizedDataPrunner.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NormalizedDataPrunner.java
new file mode 100644 (file)
index 0000000..5d0185b
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.restconf.impl;
+
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.AnyXmlNode;
+import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MixinNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
+
+class NormalizedDataPrunner {
+
+    public DataContainerChild<?, ?> pruneDataAtDepth(final DataContainerChild<?, ?> node, final Integer depth) {
+        if (depth == null) {
+            return node;
+        }
+
+        if (node instanceof LeafNode || node instanceof LeafSetNode || node instanceof AnyXmlNode
+                || node instanceof OrderedLeafSetNode) {
+            return node;
+        } else if (node instanceof MixinNode) {
+            return processMixinNode(node, depth);
+        } else if (node instanceof DataContainerNode) {
+            return processContainerNode(node, depth);
+        }
+        throw new IllegalStateException("Unexpected Mixin node occured why pruning data to requested depth");
+    }
+
+    private DataContainerChild<?, ?> processMixinNode(final NormalizedNode<?, ?> node, final Integer depth) {
+        if (node instanceof AugmentationNode) {
+            return processAugmentationNode(node, depth);
+        } else if (node instanceof ChoiceNode) {
+            return processChoiceNode(node, depth);
+        } else if (node instanceof OrderedMapNode) {
+            return processOrderedMapNode(node, depth);
+        } else if (node instanceof MapNode) {
+            return processMapNode(node, depth);
+        } else if (node instanceof UnkeyedListNode) {
+            return processUnkeyedListNode(node, depth);
+        }
+        throw new IllegalStateException("Unexpected Mixin node occured why pruning data to requested depth");
+    }
+
+    private DataContainerChild<?, ?> processContainerNode(final NormalizedNode<?, ?> node, final Integer depth) {
+        final ContainerNode containerNode = (ContainerNode) node;
+        DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> newContainerBuilder = Builders.containerBuilder()
+                .withNodeIdentifier(containerNode.getIdentifier());
+        if (depth > 1) {
+            processDataContainerChild((DataContainerNode<?>) node, depth, newContainerBuilder);
+        }
+        return newContainerBuilder.build();
+    }
+
+    private DataContainerChild<?, ?> processChoiceNode(final NormalizedNode<?, ?> node, final Integer depth) {
+        final ChoiceNode choiceNode = (ChoiceNode) node;
+        DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> newChoiceBuilder = Builders.choiceBuilder()
+                .withNodeIdentifier(choiceNode.getIdentifier());
+
+        processDataContainerChild((DataContainerNode<?>) node, depth, newChoiceBuilder);
+
+        return newChoiceBuilder.build();
+    }
+
+    private DataContainerChild<?, ?> processAugmentationNode(final NormalizedNode<?, ?> node, final Integer depth) {
+        final AugmentationNode augmentationNode = (AugmentationNode) node;
+        DataContainerNodeBuilder<AugmentationIdentifier, ? extends DataContainerChild<?, ?>> newAugmentationBuilder = Builders
+                .augmentationBuilder().withNodeIdentifier(augmentationNode.getIdentifier());
+
+        processDataContainerChild((DataContainerNode<?>) node, depth, newAugmentationBuilder);
+
+        return newAugmentationBuilder.build();
+    }
+
+    private void processDataContainerChild(
+            final DataContainerNode<?> node,
+            final Integer depth,
+            final DataContainerNodeBuilder<? extends YangInstanceIdentifier.PathArgument, ? extends DataContainerNode<?>> newBuilder) {
+
+        for (DataContainerChild<? extends PathArgument, ?> nodeValue : node.getValue()) {
+            newBuilder.withChild(pruneDataAtDepth(nodeValue, depth - 1));
+        }
+
+    }
+
+    private DataContainerChild<?, ?> processUnkeyedListNode(final NormalizedNode<?, ?> node, final Integer depth) {
+        CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> newUnkeyedListBuilder = Builders
+                .unkeyedListBuilder();
+        if (depth > 1) {
+            for (UnkeyedListEntryNode oldUnkeyedListEntry : ((UnkeyedListNode) node).getValue()) {
+                DataContainerNodeAttrBuilder<NodeIdentifier, UnkeyedListEntryNode> newUnkeyedListEntry = Builders
+                        .unkeyedListEntryBuilder().withNodeIdentifier(oldUnkeyedListEntry.getIdentifier());
+                for (DataContainerChild<? extends PathArgument, ?> oldUnkeyedListEntryValue : oldUnkeyedListEntry
+                        .getValue()) {
+                    newUnkeyedListEntry.withChild(pruneDataAtDepth(oldUnkeyedListEntryValue, depth - 1));
+                }
+                newUnkeyedListBuilder.addChild(newUnkeyedListEntry.build());
+            }
+        }
+        return newUnkeyedListBuilder.build();
+    }
+
+    private DataContainerChild<?, ?> processOrderedMapNode(final NormalizedNode<?, ?> node, final Integer depth) {
+        CollectionNodeBuilder<MapEntryNode, OrderedMapNode> newOrderedMapNodeBuilder = Builders.orderedMapBuilder();
+        processMapEntries(node, depth, newOrderedMapNodeBuilder);
+        return newOrderedMapNodeBuilder.build();
+    }
+
+    private DataContainerChild<?, ?> processMapNode(final NormalizedNode<?, ?> node, final Integer depth) {
+        CollectionNodeBuilder<MapEntryNode, MapNode> newMapNodeBuilder = Builders.mapBuilder();
+        processMapEntries(node, depth, newMapNodeBuilder);
+        return newMapNodeBuilder.build();
+    }
+
+    private void processMapEntries(final NormalizedNode<?, ?> node, final Integer depth,
+            CollectionNodeBuilder<MapEntryNode, ? extends MapNode> newOrderedMapNodeBuilder) {
+        if (depth > 1) {
+            for (MapEntryNode oldMapEntryNode : ((MapNode) node).getValue()) {
+                DataContainerNodeAttrBuilder<NodeIdentifierWithPredicates, MapEntryNode> newMapEntryNodeBuilder = Builders
+                        .mapEntryBuilder().withNodeIdentifier(oldMapEntryNode.getIdentifier());
+                for (DataContainerChild<? extends PathArgument, ?> mapEntryNodeValue : oldMapEntryNode.getValue()) {
+                    newMapEntryNodeBuilder.withChild(pruneDataAtDepth(mapEntryNodeValue, depth - 1));
+                }
+                newOrderedMapNodeBuilder.withChild(newMapEntryNodeBuilder.build());
+            }
+        }
+    }
+
+
+}
diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NormalizedNodeContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/NormalizedNodeContext.java
new file mode 100644 (file)
index 0000000..e698693
--- /dev/null
@@ -0,0 +1,22 @@
+package org.opendaylight.controller.sal.restconf.impl;
+
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+public class NormalizedNodeContext {
+
+    private final InstanceIdentifierContext context;
+    private final NormalizedNode<?,?> data;
+
+    public NormalizedNodeContext(InstanceIdentifierContext context, NormalizedNode<?, ?> data) {
+        this.context = context;
+        this.data = data;
+    }
+
+    public InstanceIdentifierContext getInstanceIdentifierContext() {
+        return context;
+    }
+
+    public NormalizedNode<?, ?> getData() {
+        return data;
+    }
+}
index b94f6a6166c47f3b1308f7dc4696341fe5ec202b..adad26e141d2315af5287c9ff2b49a02f16f68ac 100644 (file)
@@ -15,7 +15,6 @@ import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
-
 import java.net.URI;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -32,7 +31,6 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
-
 import org.apache.commons.lang3.StringUtils;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -205,7 +203,7 @@ public class RestconfImpl implements RestconfService {
         Set<Module> modules = null;
         DOMMountPoint mountPoint = null;
         if (identifier.contains(ControllerContext.MOUNT)) {
-            InstanceIdWithSchemaNode mountPointIdentifier = this.controllerContext.toMountPointIdentifier(identifier);
+            InstanceIdentifierContext mountPointIdentifier = this.controllerContext.toMountPointIdentifier(identifier);
             mountPoint = mountPointIdentifier.getMountPoint();
             modules = this.controllerContext.getAllModules(mountPoint);
         } else {
@@ -236,7 +234,7 @@ public class RestconfImpl implements RestconfService {
         Module module = null;
         DOMMountPoint mountPoint = null;
         if (identifier.contains(ControllerContext.MOUNT)) {
-            InstanceIdWithSchemaNode mountPointIdentifier = this.controllerContext.toMountPointIdentifier(identifier);
+            InstanceIdentifierContext mountPointIdentifier = this.controllerContext.toMountPointIdentifier(identifier);
             mountPoint = mountPointIdentifier.getMountPoint();
             module = this.controllerContext.findModuleByNameAndRevision(mountPoint, moduleNameAndRevision);
         } else {
@@ -267,7 +265,7 @@ public class RestconfImpl implements RestconfService {
         Set<Module> modules = null;
         DOMMountPoint mountPoint = null;
         if (identifier.contains(ControllerContext.MOUNT)) {
-            InstanceIdWithSchemaNode mountPointIdentifier = this.controllerContext.toMountPointIdentifier(identifier);
+            InstanceIdentifierContext mountPointIdentifier = this.controllerContext.toMountPointIdentifier(identifier);
             mountPoint = mountPointIdentifier.getMountPoint();
             modules = this.controllerContext.getAllModules(mountPoint);
         } else {
@@ -518,7 +516,7 @@ public class RestconfImpl implements RestconfService {
         DOMMountPoint mountPoint = null;
         if (identifier.contains(ControllerContext.MOUNT)) {
             // mounted RPC call - look up mount instance.
-            InstanceIdWithSchemaNode mountPointId = controllerContext.toMountPointIdentifier(identifier);
+            InstanceIdentifierContext mountPointId = controllerContext.toMountPointIdentifier(identifier);
             mountPoint = mountPointId.getMountPoint();
 
             int startOfRemoteRpcName = identifier.lastIndexOf(ControllerContext.MOUNT)
@@ -615,8 +613,8 @@ public class RestconfImpl implements RestconfService {
     }
 
     @Override
-    public StructuredData readConfigurationData(final String identifier, final UriInfo uriInfo) {
-        final InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier(identifier);
+    public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
+        final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier);
         DOMMountPoint mountPoint = iiWithData.getMountPoint();
         NormalizedNode<?, ?> data = null;
         YangInstanceIdentifier normalizedII;
@@ -628,12 +626,7 @@ public class RestconfImpl implements RestconfService {
             normalizedII = controllerContext.toNormalized(iiWithData.getInstanceIdentifier());
             data = broker.readConfigurationData(normalizedII);
         }
-
-        final CompositeNode compositeNode = datastoreNormalizedNodeToCompositeNode(data, iiWithData.getSchemaNode());
-        final CompositeNode prunedCompositeNode = pruneDataAtDepth(compositeNode, parseDepthParameter(uriInfo));
-
-        final boolean prettyPrintMode = parsePrettyPrintParameter(uriInfo);
-        return new StructuredData(prunedCompositeNode, iiWithData.getSchemaNode(), mountPoint, prettyPrintMode);
+        return new NormalizedNodeContext(iiWithData, data);
     }
 
     @SuppressWarnings("unchecked")
@@ -679,8 +672,8 @@ public class RestconfImpl implements RestconfService {
     }
 
     @Override
-    public StructuredData readOperationalData(final String identifier, final UriInfo info) {
-        final InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier(identifier);
+    public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo info) {
+        final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier);
         DOMMountPoint mountPoint = iiWithData.getMountPoint();
         NormalizedNode<?, ?> data = null;
         YangInstanceIdentifier normalizedII;
@@ -693,11 +686,7 @@ public class RestconfImpl implements RestconfService {
             data = broker.readOperationalData(normalizedII);
         }
 
-        final CompositeNode compositeNode = datastoreNormalizedNodeToCompositeNode(data, iiWithData.getSchemaNode());
-        final CompositeNode prunedCompositeNode = pruneDataAtDepth(compositeNode, parseDepthParameter(info));
-
-        final boolean prettyPrintMode = parsePrettyPrintParameter(info);
-        return new StructuredData(prunedCompositeNode, iiWithData.getSchemaNode(), mountPoint, prettyPrintMode);
+        return new NormalizedNodeContext(iiWithData, data);
     }
 
     private boolean parsePrettyPrintParameter(final UriInfo info) {
@@ -707,7 +696,7 @@ public class RestconfImpl implements RestconfService {
 
     @Override
     public Response updateConfigurationData(final String identifier, final Node<?> payload) {
-        final InstanceIdWithSchemaNode iiWithData = this.controllerContext.toInstanceIdentifier(identifier);
+        final InstanceIdentifierContext iiWithData = this.controllerContext.toInstanceIdentifier(identifier);
 
         validateInput(iiWithData.getSchemaNode(), payload);
 
@@ -774,7 +763,7 @@ public class RestconfImpl implements RestconfService {
      *             if key values or key count in payload and URI isn't equal
      *
      */
-    private void validateListKeysEqualityInPayloadAndUri(final InstanceIdWithSchemaNode iiWithData,
+    private void validateListKeysEqualityInPayloadAndUri(final InstanceIdentifierContext iiWithData,
             final CompositeNode payload) {
         if (iiWithData.getSchemaNode() instanceof ListSchemaNode) {
             final List<QName> keyDefinitions = ((ListSchemaNode) iiWithData.getSchemaNode()).getKeyDefinition();
@@ -825,7 +814,7 @@ public class RestconfImpl implements RestconfService {
                     ErrorType.PROTOCOL, ErrorTag.UNKNOWN_NAMESPACE);
         }
 
-        InstanceIdWithSchemaNode iiWithData = null;
+        InstanceIdentifierContext iiWithData = null;
         CompositeNode value = null;
         if (this.representsMountPointRootData(payload)) {
             // payload represents mount point data and URI represents path to the mount point
@@ -841,7 +830,7 @@ public class RestconfImpl implements RestconfService {
 
             value = this.normalizeNode(payload, iiWithData.getSchemaNode(), iiWithData.getMountPoint());
         } else {
-            final InstanceIdWithSchemaNode incompleteInstIdWithData = this.controllerContext
+            final InstanceIdentifierContext incompleteInstIdWithData = this.controllerContext
                     .toInstanceIdentifier(identifier);
             final DataNodeContainer parentSchema = (DataNodeContainer) incompleteInstIdWithData.getSchemaNode();
             DOMMountPoint mountPoint = incompleteInstIdWithData.getMountPoint();
@@ -856,7 +845,7 @@ public class RestconfImpl implements RestconfService {
                     parentSchema, payloadName, module.getNamespace());
             value = this.normalizeNode(payload, schemaNode, mountPoint);
 
-            iiWithData = addLastIdentifierFromData(incompleteInstIdWithData, value, schemaNode);
+            iiWithData = addLastIdentifierFromData(incompleteInstIdWithData, value, schemaNode,incompleteInstIdWithData.getSchemaContext());
         }
 
         final NormalizedNode<?, ?> datastoreNormalizedData = compositeNodeToDatastoreNormalizedNode(value,
@@ -906,7 +895,7 @@ public class RestconfImpl implements RestconfService {
         final DataSchemaNode schemaNode = ControllerContext.findInstanceDataChildByNameAndNamespace(module,
                 payloadName, module.getNamespace());
         final CompositeNode value = this.normalizeNode(payload, schemaNode, null);
-        final InstanceIdWithSchemaNode iiWithData = this.addLastIdentifierFromData(null, value, schemaNode);
+        final InstanceIdentifierContext iiWithData = this.addLastIdentifierFromData(null, value, schemaNode,ControllerContext.getInstance().getGlobalSchema());
         final NormalizedNode<?, ?> datastoreNormalizedData = compositeNodeToDatastoreNormalizedNode(value, schemaNode);
         DOMMountPoint mountPoint = iiWithData.getMountPoint();
         YangInstanceIdentifier normalizedII;
@@ -932,7 +921,7 @@ public class RestconfImpl implements RestconfService {
 
     @Override
     public Response deleteConfigurationData(final String identifier) {
-        final InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier(identifier);
+        final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier);
         DOMMountPoint mountPoint = iiWithData.getMountPoint();
         YangInstanceIdentifier normalizedII;
 
@@ -1098,8 +1087,8 @@ public class RestconfImpl implements RestconfService {
         return module;
     }
 
-    private InstanceIdWithSchemaNode addLastIdentifierFromData(final InstanceIdWithSchemaNode identifierWithSchemaNode,
-            final CompositeNode data, final DataSchemaNode schemaOfData) {
+    private InstanceIdentifierContext addLastIdentifierFromData(final InstanceIdentifierContext identifierWithSchemaNode,
+            final CompositeNode data, final DataSchemaNode schemaOfData, SchemaContext schemaContext) {
         YangInstanceIdentifier instanceIdentifier = null;
         if (identifierWithSchemaNode != null) {
             instanceIdentifier = identifierWithSchemaNode.getInstanceIdentifier();
@@ -1122,11 +1111,12 @@ public class RestconfImpl implements RestconfService {
 
         YangInstanceIdentifier instance = iiBuilder.toInstance();
         DOMMountPoint mountPoint = null;
+        SchemaContext schemaCtx = null;
         if (identifierWithSchemaNode != null) {
             mountPoint = identifierWithSchemaNode.getMountPoint();
         }
 
-        return new InstanceIdWithSchemaNode(instance, schemaOfData, mountPoint);
+        return new InstanceIdentifierContext(instance, schemaOfData, mountPoint,schemaContext);
     }
 
     private HashMap<QName, Object> resolveKeysFromData(final ListSchemaNode listNode, final CompositeNode dataNode) {
@@ -1514,16 +1504,16 @@ public class RestconfImpl implements RestconfService {
                 "It wasn't possible to translate specified data to datastore readable form."));
     }
 
-    private InstanceIdWithSchemaNode normalizeInstanceIdentifierWithSchemaNode(
-            final InstanceIdWithSchemaNode iiWithSchemaNode) {
+    private InstanceIdentifierContext normalizeInstanceIdentifierWithSchemaNode(
+            final InstanceIdentifierContext iiWithSchemaNode) {
         return normalizeInstanceIdentifierWithSchemaNode(iiWithSchemaNode, false);
     }
 
-    private InstanceIdWithSchemaNode normalizeInstanceIdentifierWithSchemaNode(
-            final InstanceIdWithSchemaNode iiWithSchemaNode, final boolean unwrapLastListNode) {
-        return new InstanceIdWithSchemaNode(instanceIdentifierToReadableFormForNormalizeNode(
+    private InstanceIdentifierContext normalizeInstanceIdentifierWithSchemaNode(
+            final InstanceIdentifierContext iiWithSchemaNode, final boolean unwrapLastListNode) {
+        return new InstanceIdentifierContext(instanceIdentifierToReadableFormForNormalizeNode(
                 iiWithSchemaNode.getInstanceIdentifier(), unwrapLastListNode), iiWithSchemaNode.getSchemaNode(),
-                iiWithSchemaNode.getMountPoint());
+                iiWithSchemaNode.getMountPoint(),iiWithSchemaNode.getSchemaContext());
     }
 
     private YangInstanceIdentifier instanceIdentifierToReadableFormForNormalizeNode(
index 2f045ce381ca0572cbeff4ad43147834fb59d2cf..559a6b9e8e4a8a88aed3f4c4c3b9a34d5ea377ae 100644 (file)
@@ -40,7 +40,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
 import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
-import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
@@ -324,7 +324,7 @@ public class InvokeRpcMethodTest {
         when(mockMountPoint.getService(eq(RpcProvisionRegistry.class))).thenReturn(Optional.of(mockedRpcProvisionRegistry));
         when(mockMountPoint.getSchemaContext()).thenReturn(TestUtils.loadSchemaContext("/invoke-rpc"));
 
-        InstanceIdWithSchemaNode mockedInstanceId = mock(InstanceIdWithSchemaNode.class);
+        InstanceIdentifierContext mockedInstanceId = mock(InstanceIdentifierContext.class);
         when(mockedInstanceId.getMountPoint()).thenReturn(mockMountPoint);
 
         ControllerContext mockedContext = mock(ControllerContext.class);
index bab06e92451985b5a0d95032e99174adb91ba4b0..856d8c006b6c40349d2a1fd646cc70db6bd5fd62 100644 (file)
@@ -17,7 +17,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
-import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
@@ -36,7 +36,7 @@ public class RestGetAugmentedElementWhenEqualNamesTest {
 
     @Test
     public void augmentedNodesInUri() {
-        InstanceIdWithSchemaNode iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1");
+        InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1");
         assertEquals("ns:augment:main:a", iiWithData.getSchemaNode().getQName().getNamespace().toString());
         iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-b:cont1");
         assertEquals("ns:augment:main:b", iiWithData.getSchemaNode().getQName().getNamespace().toString());
index 539248a147cd4eea16dca9f4725cf26e9b185496..06cfd84b05048513249462de9245871da3905c5f 100644 (file)
@@ -44,12 +44,14 @@ import javax.ws.rs.core.UriInfo;
 import org.glassfish.jersey.server.ResourceConfig;
 import org.glassfish.jersey.test.JerseyTest;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.rest.impl.JsonToCompositeNodeProvider;
+import org.opendaylight.controller.sal.rest.impl.RestconfApplication;
 import org.opendaylight.controller.sal.rest.impl.RestconfDocumentedExceptionMapper;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
@@ -130,6 +132,7 @@ public class RestGetOperationTest extends JerseyTest {
                 StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE,
                 JsonToCompositeNodeProvider.INSTANCE);
         resourceConfig.registerClasses(RestconfDocumentedExceptionMapper.class);
+        resourceConfig.registerClasses(new RestconfApplication().getClasses());
         return resourceConfig;
     }
 
@@ -717,6 +720,7 @@ public class RestGetOperationTest extends JerseyTest {
     }
 
     @Test
+    @Ignore
     public void getDataWithUriDepthParameterTest() throws UnsupportedEncodingException {
 
         ControllerContext.getInstance().setGlobalSchema(schemaContextModules);
@@ -903,6 +907,7 @@ public class RestGetOperationTest extends JerseyTest {
      * Tests behavior when invalid value of depth URI parameter
      */
     @Test
+    @Ignore
     public void getDataWithInvalidDepthParameterTest() {
 
         ControllerContext.getInstance().setGlobalSchema(schemaContextModules);
@@ -930,7 +935,7 @@ public class RestGetOperationTest extends JerseyTest {
         try {
             QName qNameDepth1Cont = QName.create("urn:nested:module", "2014-06-3", "depth1-cont");
             YangInstanceIdentifier ii = YangInstanceIdentifier.builder().node(qNameDepth1Cont).build();
-            NormalizedNode value = (NormalizedNode<?,?>)(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(qNameDepth1Cont)).build());
+            NormalizedNode value = (Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(qNameDepth1Cont)).build());
             when(brokerFacade.readConfigurationData(eq(ii))).thenReturn(value);
             restconfImpl.readConfigurationData("nested-module:depth1-cont", uriInfo);
             fail("Expected RestconfDocumentedException");
index 4e9c96ac3e8acef126077d7b932e737caae1e4f3..3a16b18efcf26e8704a06900fb16a36d32cb5a00 100644 (file)
@@ -53,6 +53,7 @@ import org.glassfish.jersey.server.ResourceConfig;
 import org.glassfish.jersey.test.JerseyTest;
 import org.junit.Before;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.controller.sal.rest.api.Draft02;
 import org.opendaylight.controller.sal.rest.api.RestconfService;
@@ -60,11 +61,11 @@ import org.opendaylight.controller.sal.rest.impl.RestconfDocumentedExceptionMapp
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToJsonProvider;
 import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider;
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.controller.sal.restconf.impl.StructuredData;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -679,13 +680,14 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest {
     }
 
     @Test
+    @Ignore
     public void testToResponseWithStatusOnly() throws Exception {
 
         // The StructuredDataToJsonProvider should throw a
         // RestconfDocumentedException with no data
 
         when(mockRestConf.readOperationalData(any(String.class), any(UriInfo.class))).thenReturn(
-                new StructuredData(null, null, null));
+                new NormalizedNodeContext(null, null));
 
         Response resp = target("/operational/foo").request(MediaType.APPLICATION_JSON).get();
 
index c2b153f02bd27b6729dbba2a89a201a306763a99..15d73e3e7a301ca5a70879a851941eab0e4b35b3 100644 (file)
@@ -402,7 +402,7 @@ public final class TestUtils {
         return interfaceBuilder.toInstance();
     }
 
-    static NormalizedNode prepareNormalizedNodeWithIetfInterfacesInterfacesData() throws ParseException {
+    static NormalizedNode<?,?> prepareNormalizedNodeWithIetfInterfacesInterfacesData() throws ParseException {
         String ietfInterfacesDate = "2013-07-04";
         String namespace = "urn:ietf:params:xml:ns:yang:ietf-interfaces";
         DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapEntryNode = ImmutableMapEntryNodeBuilder.create();
index ed871bb52727895c5cdf69dd80e0caa2433cacef..4900e6a66f1ab9d9d3324c85e6ca5c98f103e5ba 100644 (file)
@@ -26,7 +26,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
-import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -51,7 +51,7 @@ public class URITest {
 
     @Test
     public void testToInstanceIdentifierList() throws FileNotFoundException {
-        InstanceIdWithSchemaNode instanceIdentifier = controllerContext
+        InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:userWithoutClass/foo");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "userWithoutClass");
 
@@ -80,7 +80,7 @@ public class URITest {
 
     @Test
     public void testToInstanceIdentifierContainer() throws FileNotFoundException {
-        InstanceIdWithSchemaNode instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:users");
+        InstanceIdentifierContext instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:users");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "users");
         assertTrue(instanceIdentifier.getSchemaNode() instanceof ContainerSchemaNode);
         assertEquals(2, ((ContainerSchemaNode) instanceIdentifier.getSchemaNode()).getChildNodes().size());
@@ -88,7 +88,7 @@ public class URITest {
 
     @Test
     public void testToInstanceIdentifierChoice() throws FileNotFoundException {
-        InstanceIdWithSchemaNode instanceIdentifier = controllerContext
+        InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:food/nonalcoholic");
         assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "nonalcoholic");
     }
@@ -120,7 +120,7 @@ public class URITest {
     @Test
     public void testMountPointWithExternModul() throws FileNotFoundException {
         initMountService(true);
-        InstanceIdWithSchemaNode instanceIdentifier = controllerContext
+        InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
         assertEquals(
                 "[(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)class, (urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)student[{(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)name=name}]]",
@@ -130,7 +130,7 @@ public class URITest {
     @Test
     public void testMountPointWithoutExternModul() throws FileNotFoundException {
         initMountService(true);
-        InstanceIdWithSchemaNode instanceIdentifier = controllerContext
+        InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/");
         assertTrue(Iterables.isEmpty(instanceIdentifier.getInstanceIdentifier().getPathArguments()));
     }
@@ -140,7 +140,7 @@ public class URITest {
         exception.expect(RestconfDocumentedException.class);
 
         controllerContext.setMountService(null);
-        InstanceIdWithSchemaNode instanceIdentifier = controllerContext
+        InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
     }
 
@@ -149,7 +149,7 @@ public class URITest {
         initMountService(false);
         exception.expect(RestconfDocumentedException.class);
 
-        InstanceIdWithSchemaNode instanceIdentifier = controllerContext
+        InstanceIdentifierContext instanceIdentifier = controllerContext
                 .toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class");
     }
 
index 2a778180d4448dd33ce7cabb17f911e77151df9f..c470b3237ea7fe2dd69f37254cae4b38439c8861 100644 (file)
@@ -2,7 +2,9 @@
 <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">
-
+    <welcome-file-list>
+        <welcome-file>index.html</welcome-file>
+    </welcome-file-list>
     <servlet>
         <servlet-name>JAXRSApiDoc</servlet-name>
         <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
index 05a76a4cb7ca0551d0bb55322b4603f78eb7fd4b..f12616bc4b910d8127fc7269ea8bd5bc6b863dd5 100644 (file)
@@ -32,7 +32,7 @@
        var loadMount = function(mountIndex, mountPath) {\r
                $("#message").empty();\r
                $("#message").append( "<p>Loading...</p>" );\r
-               loadSwagger("http://localhost:8080/apidoc/apis/mounts/" + mountIndex,\r
+               loadSwagger("/apidoc/apis/mounts/" + mountIndex,\r
                                "swagger-ui-container");\r
                $("#message").empty();\r
                $("#message").append( "<h2><b>Showing mount points for " + mountPath + "</b></h2>");\r
@@ -48,7 +48,7 @@
        //loads the root swagger documenation (which comes from RestConf)\r
        var loadRootSwagger = function() {\r
                $("#message").empty();\r
-               loadSwagger("http://localhost:8080/apidoc/apis", "swagger-ui-container");\r
+               loadSwagger("/apidoc/apis", "swagger-ui-container");\r
        }\r
 \r
        //main method to initialize the mount list / swagger docs / tabs on page load\r
index e23ad0acdbe43a2603f458dd3a17b467116acd1b..838aeb7dc36af37ae0916fd1e60f708c8be1861d 100644 (file)
@@ -97,14 +97,15 @@ abstract class AbstractStatsTracker<I, K> {
     }
     protected abstract void cleanupSingleStat(DataModificationTransaction trans, K item);
     protected abstract K updateSingleStat(DataModificationTransaction trans, I item);
+    protected abstract K createInvariantKey(K item);
     public abstract void request();
 
     public final synchronized void updateStats(List<I> list) {
 
         final DataModificationTransaction trans = startTransaction();
-
         for (final I item : list) {
-            trackedItems.put(updateSingleStat(trans, item), requestCounter);
+            K key = updateSingleStat(trans, item);
+            trackedItems.put(createInvariantKey(key), requestCounter);
         }
 
         trans.commit();
index b5b39d94d2f5839cf3901807f3435d93d53ba38d..c43c1ebaca211216a5046d65870b56b7ef432513 100644 (file)
@@ -56,4 +56,9 @@ final class FlowStatsEntry {
             return false;
         return true;
     }
+
+    @Override
+    public String toString() {
+        return "FlowStatsEntry [tableId=" + tableId + ", flow=" + flow + "]";
+    }
 }
index e92d0bd6251dbf89af9c98b175aa699d8d697994..d540f115c3ab7c107536a5797b3527e9dc7a36ba 100644 (file)
@@ -301,4 +301,13 @@ final class FlowStatsTracker extends AbstractListeningStatsTracker<FlowAndStatis
         }
         return flowCookieMap;
     }
+
+    @Override
+    protected FlowStatsEntry createInvariantKey(final FlowStatsEntry item) {
+        FlowBuilder newFlow = new FlowBuilder();
+        newFlow.setId(item.getFlow().getId());
+        newFlow.setKey(item.getFlow().getKey());
+        newFlow.fieldsFrom(item.getFlow());
+        return new FlowStatsEntry(item.getTableId(),newFlow.build());
+    }
 }
index a160f6d467ca6731a8c4d485250d6697cec8b97e..2e850580416084c36a1de4c054d21a7860b8d394 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev13
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.GetFlowTablesStatisticsInputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.OpendaylightFlowTableStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -70,4 +71,12 @@ final class FlowTableStatsTracker extends AbstractStatsTracker<FlowTableAndStati
             requestHelper(flowTableStatsService.getFlowTablesStatistics(input.build()));
         }
     }
+
+    @Override
+    protected FlowTableAndStatisticsMap createInvariantKey(FlowTableAndStatisticsMap item) {
+        FlowTableAndStatisticsMapBuilder flowTableAndStatisticsMapBuilder = new FlowTableAndStatisticsMapBuilder();
+        flowTableAndStatisticsMapBuilder.setTableId(item.getTableId());
+        flowTableAndStatisticsMapBuilder.setKey(item.getKey());
+        return flowTableAndStatisticsMapBuilder.build();
+    }
 }
index a775b73169dc5581cd3175eebfa078a471d5dbd3..11c6d4c22df5f53cd17d8bc089aa8b7338c8eceb 100644 (file)
@@ -114,4 +114,10 @@ final class GroupDescStatsTracker extends AbstractListeningStatsTracker<GroupDes
 
         super.start(dbs);
     }
+
+    @Override
+    protected GroupDescStats createInvariantKey(GroupDescStats item) {
+        // No invariant data exist in the group description stats.
+        return item;
+    }
 }
index c3c23c9b582cf493c02248087b08f80914b3fd82..f3ba45643c3fd4338b4f8f6bd8951de0d5184757 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
@@ -105,4 +106,12 @@ final class GroupStatsTracker extends AbstractListeningStatsTracker<GroupStats,
 
         super.start(dbs);
     }
+
+    @Override
+    protected GroupStats createInvariantKey(GroupStats item) {
+        GroupStatsBuilder groupStatsBuilder = new GroupStatsBuilder();
+        groupStatsBuilder.setKey(item.getKey());
+        groupStatsBuilder.setGroupId(item.getGroupId());
+        return groupStatsBuilder.build();
+    }
 }
index ea412a09e183db8dcf958c6769a8b0ac37211c5f..88139fc60649541678f63edb46e8f9a250898644 100644 (file)
@@ -109,4 +109,10 @@ final class MeterConfigStatsTracker extends AbstractListeningStatsTracker<MeterC
 
         super.start(dbs);
     }
+
+    @Override
+    protected MeterConfigStats createInvariantKey(MeterConfigStats item) {
+        // No invariant data exist in the meter config stats.
+        return item;
+    }
 }
index be53a38f186eb2407b9ce30ff4a2e20da6379b53..f43ec693cd1d7a283a037f770361f1024ab4ed01 100644 (file)
@@ -20,6 +20,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatisticsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStats;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -112,4 +113,12 @@ final class MeterStatsTracker extends AbstractListeningStatsTracker<MeterStats,
 
         super.start(dbs);
     }
+
+    @Override
+    protected MeterStats createInvariantKey(MeterStats item) {
+        MeterStatsBuilder meterStatsBuilder = new MeterStatsBuilder();
+        meterStatsBuilder.setKey(item.getKey());
+        meterStatsBuilder.setMeterId(item.getMeterId());
+        return meterStatsBuilder.build();
+    }
 }
index e4490eaa3cc2ea9ac2683ff36f6d48787ddded99..2e2bf1cd518b94a2b97c81b877b8372f447ef36e 100644 (file)
@@ -17,6 +17,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.G
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.OpendaylightPortStatisticsService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMapBuilder;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -83,4 +84,12 @@ final class NodeConnectorStatsTracker extends AbstractStatsTracker<NodeConnector
             requestHelper(portStatsService.getAllNodeConnectorsStatistics(input.build()));
         }
     }
+
+    @Override
+    protected NodeConnectorStatisticsAndPortNumberMap createInvariantKey(NodeConnectorStatisticsAndPortNumberMap item) {
+        NodeConnectorStatisticsAndPortNumberMapBuilder ncStatsBuilder = new NodeConnectorStatisticsAndPortNumberMapBuilder();
+        ncStatsBuilder.setNodeConnectorId(item.getNodeConnectorId());
+        ncStatsBuilder.setKey(item.getKey());
+        return ncStatsBuilder.build();
+    }
 }
index 03f7808c8f9b119cfb6ed0ba2fe877d340e3ffc0..4a589703beb4303b9686d7887663b8f6d1492486 100644 (file)
@@ -152,4 +152,10 @@ final class QueueStatsTracker extends AbstractListeningStatsTracker<QueueIdAndSt
 
         super.start(dbs);
     }
+
+    @Override
+    protected QueueStatsEntry createInvariantKey(QueueStatsEntry item) {
+        // No invariant data exist in the group description stats.
+        return item;
+    }
 }
index 10aec4ca2e85038cdc7ff21dd0ebd4dc4b6cddf6..c1996f4691632637abc9fc7dffacce0bcb12f2ad 100644 (file)
@@ -151,7 +151,7 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open
             public void applyOperation(final ReadWriteTransaction transaction) {
                 final Link link = toTopologyLink(notification);
                 final InstanceIdentifier<Link> path = linkPath(link);
-                transaction.put(LogicalDatastoreType.OPERATIONAL, path, link);
+                transaction.merge(LogicalDatastoreType.OPERATIONAL, path, link, true);
             }
         });
     }
index 5854d5577fe007be058adc5db033c4746d220dc3..d39241757fea07732c7920340fd3fdd5ebf37c7d 100644 (file)
@@ -81,7 +81,7 @@
           <dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal</artifactId>
-            <version>0.7.1-SNAPSHOT</version>
+            <version>${sal.version}</version>
           </dependency>
         </dependencies>
       </plugin>