Merge "BUG 1082 Migrate sal-rest-connector to Async Data Broker API"
authorTony Tkacik <ttkacik@cisco.com>
Sun, 3 Aug 2014 18:10:03 +0000 (18:10 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sun, 3 Aug 2014 18:10:03 +0000 (18:10 +0000)
1  2 
opendaylight/commons/opendaylight/pom.xml
opendaylight/distribution/opendaylight/pom.xml
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfProviderImpl.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/streams/listeners/Notificator.java

index c4ab2edcb3a41f654106fc7b7b58b473faca6b84,9468133db820c05d29dc299de9d80e3f96c209ab..5ce5840da8fc4deb45df33c1d2fc102933c2fe7e
@@@ -95,7 -95,6 +95,7 @@@
      <hosttracker.api.version>0.5.2-SNAPSHOT</hosttracker.api.version>
      <hosttracker.implementation.version>0.5.2-SNAPSHOT</hosttracker.implementation.version>
      <hosttracker.northbound.version>0.4.2-SNAPSHOT</hosttracker.northbound.version>
 +    <hosttracker.shell.version>1.0.0-SNAPSHOT</hosttracker.shell.version>
      <hosttracker_new.api.version>0.4.2-SNAPSHOT</hosttracker_new.api.version>
      <hosttracker_new.implementation.version>0.4.2-SNAPSHOT</hosttracker_new.implementation.version>
      <httpservice-bridge.northbound.version>0.0.2-SNAPSHOT</httpservice-bridge.northbound.version>
      <northbound.jolokia.version>1.4.2-SNAPSHOT</northbound.jolokia.version>
      <opendaylight-l2-types.version>2013.08.27.4-SNAPSHOT</opendaylight-l2-types.version>
      <osgi-brandfragment.web.version>0.0.2-SNAPSHOT</osgi-brandfragment.web.version>
 +    <pax.exam.version>4.0.0</pax.exam.version>
      <parboiled.version>1.1.6</parboiled.version>
      <parboiled.scala.version>1.1.6</parboiled.scala.version>
      <propertymavenplugin.version>1.0-alpha-2</propertymavenplugin.version>
      <topology.northbound.version>0.4.2-SNAPSHOT</topology.northbound.version>
      <topology.web.version>0.4.2-SNAPSHOT</topology.web.version>
      <topologymanager.version>0.4.2-SNAPSHOT</topologymanager.version>
 +    <topologymanager.shell.version>1.0.0-SNAPSHOT</topologymanager.shell.version>
      <troubleshoot.web.version>0.4.2-SNAPSHOT</troubleshoot.web.version>
      <typesafe.config.version>1.2.0</typesafe.config.version>
      <uncommons.maths.version>1.2.2</uncommons.maths.version>
          <artifactId>sal-rest-connector-config</artifactId>
          <version>${mdsal.version}</version>
        </dependency>
 +      <dependency>
 +        <groupId>org.opendaylight.controller</groupId>
 +        <artifactId>config-netty-config</artifactId>
 +        <version>${config.version}</version>
 +      </dependency>
 +      <dependency>
 +        <groupId>org.opendaylight.controller</groupId>
 +        <artifactId>md-sal-config</artifactId>
 +        <version>${mdsal.version}</version>
 +      </dependency>
 +      <dependency>
 +        <groupId>org.opendaylight.controller</groupId>
 +        <artifactId>netconf-config</artifactId>
 +        <version>${netconf.version}</version>
 +      </dependency>
 +      <dependency>
 +        <groupId>org.opendaylight.controller</groupId>
 +        <artifactId>netconf-connector-config</artifactId>
 +        <version>${netconf.version}</version>
 +      </dependency>
        <dependency>
          <groupId>org.opendaylight.controller</groupId>
          <artifactId>sal-rest-docgen</artifactId>
          <artifactId>sample-toaster-provider</artifactId>
          <version>${mdsal.version}</version>
        </dependency>
 +      <dependency>
 +        <groupId>org.opendaylight.controller.samples</groupId>
 +        <artifactId>toaster-config</artifactId>
 +        <version>${mdsal.version}</version>
 +      </dependency>
        <dependency>
          <groupId>org.opendaylight.controller.thirdparty</groupId>
          <artifactId>com.sun.jersey.jersey-servlet</artifactId>
          <artifactId>util</artifactId>
          <version>${yangtools.version}</version>
        </dependency>
+       <dependency>
+         <groupId>org.opendaylight.yangtools</groupId>
+         <artifactId>yang-data-composite-node</artifactId>
+         <version>${yangtools.version}</version>
+       </dependency>
  
        <!-- yangtools dependencies -->
        <dependency>
index 4d0770f8cb8837cfd12b897401c2db07546b2538,1d579ebe42ae891f934a1d4a88766774a9e893b9..7c3289adb5e0a7857227549535a8997be6837114
              <phase>generate-resources</phase>
              <configuration>
                 <outputDirectory>${project.build.directory}/configuration</outputDirectory>
 -               <includeArtifactIds>sal-rest-connector-config</includeArtifactIds>
 +               <includeArtifactIds>sal-rest-connector-config,config-netty-config,md-sal-config,netconf-config,toaster-config,netconf-connector-config</includeArtifactIds>
                 <includes>**\/*.xml</includes>
                 <excludeTransitive>true</excludeTransitive>
                 <ignorePermissions>false</ignorePermissions>
            <groupId>org.opendaylight.controller</groupId>
            <artifactId>sal-rest-connector-config</artifactId>
          </dependency>
 +        <dependency>
 +          <groupId>org.opendaylight.controller</groupId>
 +          <artifactId>config-netty-config</artifactId>
 +        </dependency>
 +        <dependency>
 +          <groupId>org.opendaylight.controller</groupId>
 +          <artifactId>md-sal-config</artifactId>
 +        </dependency>
 +        <dependency>
 +          <groupId>org.opendaylight.controller</groupId>
 +          <artifactId>netconf-config</artifactId>
 +        </dependency>
 +        <dependency>
 +          <groupId>org.opendaylight.controller</groupId>
 +          <artifactId>netconf-connector-config</artifactId>
 +        </dependency>
 +        <dependency>
 +          <groupId>org.opendaylight.controller.samples</groupId>
 +          <artifactId>toaster-config</artifactId>
 +        </dependency>
          <dependency>
            <groupId>org.opendaylight.controller</groupId>
            <artifactId>sal-rest-docgen</artifactId>
            <groupId>org.opendaylight.yangtools</groupId>
            <artifactId>yang-parser-impl</artifactId>
          </dependency>
+         <dependency>
+           <groupId>org.opendaylight.yangtools</groupId>
+           <artifactId>yang-data-composite-node</artifactId>
+         </dependency>
          <!-- yang model dependencies -->
          <dependency>
            <groupId>org.opendaylight.yangtools.model</groupId>
                  <phase>generate-resources</phase>
                  <configuration>
                     <outputDirectory>${project.build.directory}/configuration</outputDirectory>
 -                   <includeArtifactIds>sal-rest-connector-config</includeArtifactIds>
 +                   <includeArtifactIds>sal-rest-connector-config,config-netty-config,md-sal-config,netconf-config,toaster-config,netconf-connector-config</includeArtifactIds>
                     <includes>**\/*.xml</includes>
                     <excludeTransitive>true</excludeTransitive>
                     <ignorePermissions>false</ignorePermissions>
index 559be5aa6fe1358881d6df6f7f81a50409dfed49,bef1be2ed1d491ce5c9b7051d5489d7eff8ef96d..2fa99819d5f833a27c0de9d6fa02053e955b87ce
@@@ -9,25 -9,24 +9,24 @@@ package org.opendaylight.controller.sal
  
  import java.util.Collection;
  import java.util.Collections;
+ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
  import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
  import org.opendaylight.controller.sal.core.api.Provider;
- import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
  import org.opendaylight.controller.sal.core.api.model.SchemaService;
- import org.opendaylight.controller.sal.core.api.mount.MountService;
  import org.opendaylight.controller.sal.rest.api.RestConnector;
  import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
  import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
  import org.opendaylight.controller.sal.streams.websockets.WebSocketServer;
  import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
  import org.opendaylight.yangtools.concepts.ListenerRegistration;
 -import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
 +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
  
  public class RestconfProviderImpl implements Provider, AutoCloseable, RestConnector {
  
      public final static String NOT_INITALIZED_MSG = "Restconf is not initialized yet. Please try again later";
  
 -    private ListenerRegistration<SchemaServiceListener> listenerRegistration;
 +    private ListenerRegistration<SchemaContextListener> listenerRegistration;
      private PortNumber port;
      public void setWebsocketPort(PortNumber port) {
          this.port = port;
  
      @Override
      public void onSessionInitiated(ProviderSession session) {
-         DataBrokerService dataService = session.getService(DataBrokerService.class);
+         final DOMDataBroker domDataBroker = session.getService(DOMDataBroker.class);
  
          BrokerFacade.getInstance().setContext(session);
-         BrokerFacade.getInstance().setDataService(dataService);
+         BrokerFacade.getInstance().setDomDataBroker( domDataBroker);
  
          SchemaService schemaService = session.getService(SchemaService.class);
 -        listenerRegistration = schemaService.registerSchemaServiceListener(ControllerContext.getInstance());
 +        listenerRegistration = schemaService.registerSchemaContextListener(ControllerContext.getInstance());
          ControllerContext.getInstance().setSchemas(schemaService.getGlobalContext());
-         ControllerContext.getInstance().setMountService(session.getService(MountService.class));
+         ControllerContext.getInstance().setMountService(session.getService(DOMMountPointService.class));
  
          webSocketServerThread = new Thread(WebSocketServer.createInstance(port.getValue().intValue()));
          webSocketServerThread.setName("Web socket server on port " + port);
index f8bcbe3c616ab7910f1d2346543f898c8548cdac,6db4e63d10f74216cf041f847c5c43be6b573d47..39f4eef657bd0d06d42c7dd7c6cbbb222a97c856
@@@ -9,6 -9,7 +9,7 @@@ package org.opendaylight.controller.sal
  
  import com.google.common.base.Function;
  import com.google.common.base.Objects;
+ import com.google.common.base.Optional;
  import com.google.common.base.Preconditions;
  import com.google.common.base.Predicate;
  import com.google.common.base.Splitter;
@@@ -17,7 -18,6 +18,6 @@@ import com.google.common.collect.BiMap
  import com.google.common.collect.HashBiMap;
  import com.google.common.collect.ImmutableMap;
  import com.google.common.collect.Iterables;
  import java.io.UnsupportedEncodingException;
  import java.net.URI;
  import java.net.URLDecoder;
@@@ -31,11 -31,9 +31,9 @@@ import java.util.List
  import java.util.Map;
  import java.util.Set;
  import java.util.concurrent.atomic.AtomicReference;
  import javax.ws.rs.core.Response.Status;
- import org.opendaylight.controller.sal.core.api.mount.MountInstance;
- import org.opendaylight.controller.sal.core.api.mount.MountService;
+ import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
  import org.opendaylight.controller.sal.rest.api.Draft02;
  import org.opendaylight.controller.sal.rest.impl.RestUtil;
  import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
@@@ -91,13 -89,13 +89,13 @@@ public class ControllerContext implemen
              new AtomicReference<>(Collections.<QName, RpcDefinition>emptyMap());
  
      private volatile SchemaContext globalSchema;
-     private volatile MountService mountService;
+     private volatile DOMMountPointService mountService;
  
      public void setGlobalSchema(final SchemaContext globalSchema) {
          this.globalSchema = globalSchema;
      }
  
-     public void setMountService(final MountService mountService) {
+     public void setMountService(final DOMMountPointService mountService) {
          this.mountService = mountService;
      }
  
          return this.getLatestModule(globalSchema, moduleName);
      }
  
-     public Module findModuleByName(final MountInstance mountPoint, final String moduleName) {
+     public Module findModuleByName(final DOMMountPoint mountPoint, final String moduleName) {
          Preconditions.checkArgument(moduleName != null && mountPoint != null);
  
          final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
          return moduleSchemas == null ? null : this.filterLatestModule(moduleSchemas);
      }
  
-     public Module findModuleByNamespace(final MountInstance mountPoint, final URI namespace) {
+     public Module findModuleByNamespace(final DOMMountPoint mountPoint, final URI namespace) {
          Preconditions.checkArgument(namespace != null && mountPoint != null);
  
          final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
          return globalSchema.findModuleByName(module.getLocalName(), module.getRevision());
      }
  
-     public Module findModuleByNameAndRevision(final MountInstance mountPoint, final QName module) {
+     public Module findModuleByNameAndRevision(final DOMMountPoint mountPoint, final QName module) {
          this.checkPreconditions();
          Preconditions.checkArgument(module != null && module.getLocalName() != null && module.getRevision() != null
                  && mountPoint != null);
          return moduleName;
      }
  
-     public String findModuleNameByNamespace(final MountInstance mountPoint, final URI namespace) {
+     public String findModuleNameByNamespace(final DOMMountPoint mountPoint, final URI namespace) {
          final Module module = this.findModuleByNamespace(mountPoint, namespace);
          return module == null ? null : module.getName();
      }
          return namespace;
      }
  
-     public URI findNamespaceByModuleName(final MountInstance mountPoint, final String moduleName) {
+     public URI findNamespaceByModuleName(final DOMMountPoint mountPoint, final String moduleName) {
          final Module module = this.findModuleByName(mountPoint, moduleName);
          return module == null ? null : module.getNamespace();
      }
  
-     public Set<Module> getAllModules(final MountInstance mountPoint) {
+     public Set<Module> getAllModules(final DOMMountPoint mountPoint) {
          this.checkPreconditions();
  
          SchemaContext schemaContext = mountPoint == null ? null : mountPoint.getSchemaContext();
          return builder.toString();
      }
  
-     public CharSequence toRestconfIdentifier(final MountInstance mountPoint, final QName qname) {
+     public CharSequence toRestconfIdentifier(final DOMMountPoint mountPoint, final QName qname) {
          if (mountPoint == null) {
              return null;
          }
          DataSchemaNode ret = container.getDataChildByName(name);
          if (ret == null) {
              for (final DataSchemaNode node : container.getChildNodes()) {
 -                if ((node instanceof ChoiceCaseNode)) {
 -                    final ChoiceCaseNode caseNode = ((ChoiceCaseNode) node);
 -                    DataSchemaNode childByQName = ControllerContext.childByQName(caseNode, name);
 +                if ((node instanceof ChoiceNode)) {
 +                    final ChoiceNode choiceNode = ((ChoiceNode) node);
 +                    DataSchemaNode childByQName = ControllerContext.childByQName(choiceNode, name);
                      if (childByQName != null) {
                          return childByQName;
                      }
      }
  
      private InstanceIdWithSchemaNode collectPathArguments(final InstanceIdentifierBuilder builder,
-             final List<String> strings, final DataNodeContainer parentNode, final MountInstance mountPoint,
+             final List<String> strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint,
              final boolean returnJustMountPoint) {
          Preconditions.<List<String>> checkNotNull(strings);
  
                  }
  
                  final YangInstanceIdentifier partialPath = builder.toInstance();
-                 final MountInstance mount = mountService.getMountPoint(partialPath);
-                 if (mount == null) {
+                 final Optional<DOMMountPoint> mountOpt = mountService.getMountPoint(partialPath);
+                 if (!mountOpt.isPresent()) {
                      LOG.debug("Instance identifier to missing mount point: {}", partialPath);
                      throw new RestconfDocumentedException("Mount point does not exist.", ErrorType.PROTOCOL,
                              ErrorTag.UNKNOWN_ELEMENT);
                  }
+                 DOMMountPoint mount = mountOpt.get();
  
                  final SchemaContext mountPointSchema = mount.getSchemaContext();
                  if (mountPointSchema == null) {
      }
  
      private void addKeyValue(final HashMap<QName, Object> map, final DataSchemaNode node, final String uriValue,
-             final MountInstance mountPoint) {
+             final DOMMountPoint mountPoint) {
          Preconditions.<String> checkNotNull(uriValue);
          Preconditions.checkArgument((node instanceof LeafSchemaNode));
  
index 99bd8c5aafa88759847eda70c61d8d10c23923da,b911369cf049d1dd07869aaa8accd257d0d56c9f..17565a6b8c082d314f5b4e90715be18ca3536a8c
@@@ -15,12 -15,12 +15,12 @@@ import java.util.concurrent.locks.Reent
  import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
  
  /**
-  * {@link Notificator} is responsible to create, remove and find {@link ListenerAdapter} listener.
+  * {@link Notificator} is responsible to create, remove and find
+  * {@link ListenerAdapter} listener.
   */
  public class Notificator {
  
      private static Map<String, ListenerAdapter> listenersByStreamName = new ConcurrentHashMap<>();
-     private static Map<YangInstanceIdentifier, ListenerAdapter> listenersByInstanceIdentifier = new ConcurrentHashMap<>();
      private static final Lock lock = new ReentrantLock();
  
      private Notificator() {
          return listenersByStreamName.get(streamName);
      }
  
-     /**
-      * Gets {@link ListenerAdapter} listener specified by {@link YangInstanceIdentifier} path.
-      *
-      * @param path
-      *            Path to data in data repository.
-      * @return ListenerAdapter
-      */
-     public static ListenerAdapter getListenerFor(YangInstanceIdentifier path) {
-         return listenersByInstanceIdentifier.get(path);
-     }
      /**
       * Checks if the listener specified by {@link YangInstanceIdentifier} path exist.
       *
-      * @param path
-      *            Path to data in data repository.
+      * @param streamName
       * @return True if the listener exist, false otherwise.
       */
-     public static boolean existListenerFor(YangInstanceIdentifier path) {
-         return listenersByInstanceIdentifier.containsKey(path);
+     public static boolean existListenerFor(String streamName) {
+         return listenersByStreamName.containsKey(streamName);
      }
  
      /**
@@@ -79,7 -67,6 +67,6 @@@
          ListenerAdapter listener = new ListenerAdapter(path, streamName);
          try {
              lock.lock();
-             listenersByInstanceIdentifier.put(path, listener);
              listenersByStreamName.put(streamName, listener);
          } finally {
              lock.unlock();
  
      /**
       * Looks for listener determined by {@link YangInstanceIdentifier} path and removes it.
-      *
-      * @param path
-      *            InstanceIdentifier
-      */
-     public static void removeListener(YangInstanceIdentifier path) {
-         ListenerAdapter listener = listenersByInstanceIdentifier.get(path);
-         deleteListener(listener);
-     }
-     /**
       * Creates String representation of stream name from URI. Removes slash from URI in start and end position.
       *
       * @param uri
              result = result.substring(1);
          }
          if (result.endsWith("/")) {
 -            result = result.substring(0, result.length());
 +            result = result.substring(0, result.length()-1);
          }
          return result;
      }
       * Removes all listeners.
       */
      public static void removeAllListeners() {
-         for (ListenerAdapter listener : listenersByInstanceIdentifier.values()) {
+         for (ListenerAdapter listener : listenersByStreamName.values()) {
              try {
                  listener.close();
              } catch (Exception e) {
          try {
              lock.lock();
              listenersByStreamName = new ConcurrentHashMap<>();
-             listenersByInstanceIdentifier = new ConcurrentHashMap<>();
          } finally {
              lock.unlock();
          }
              }
              try {
                  lock.lock();
-                 listenersByInstanceIdentifier.remove(listener.getPath());
                  listenersByStreamName.remove(listener.getStreamName());
              } finally {
                  lock.unlock();