Merge "BUG-1281: share filters between instances"
authorTony Tkacik <ttkacik@cisco.com>
Sun, 3 Aug 2014 18:14:29 +0000 (18:14 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Sun, 3 Aug 2014 18:14:29 +0000 (18:14 +0000)
1  2 
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java

index befc9f2c65e5685204049d78ca5f9164185c653e,91e24541994487089be96a7ce3586d09320c4a32..695f9f82af486cc2ed742d9ff55c54d9259bbca8
@@@ -9,7 -9,6 +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;
@@@ -18,6 -17,7 +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,9 -31,11 +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;
@@@ -89,13 -91,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 globalSchema.findModuleByName(moduleName, null);
      }
  
 -    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 globalSchema.findModuleByNamespaceAndRevision(namespace, null);
      }
  
 -    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;
          }
          return findModuleByNameAndRevision(Draft02.RestConfModule.IETF_RESTCONF_QNAME);
      }
  
+     private static final Predicate<GroupingDefinition> ERRORS_GROUPING_FILTER = new Predicate<GroupingDefinition>() {
+         @Override
+         public boolean apply(final GroupingDefinition g) {
+             return Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName());
+         }
+     };
      public DataSchemaNode getRestconfModuleErrorsSchemaNode() {
          Module restconfModule = getRestconfModule();
          if (restconfModule == null) {
  
          Set<GroupingDefinition> groupings = restconfModule.getGroupings();
  
-         final Predicate<GroupingDefinition> filter = new Predicate<GroupingDefinition>() {
-             @Override
-             public boolean apply(final GroupingDefinition g) {
-                 return Objects.equal(g.getQName().getLocalName(), Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE);
-             }
-         };
-         Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, filter);
+         Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, ERRORS_GROUPING_FILTER);
  
          final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
  
          return Iterables.getFirst(instanceDataChildrenByName, null);
      }
  
+     private static final Predicate<GroupingDefinition> GROUPING_FILTER = new Predicate<GroupingDefinition>() {
+         @Override
+         public boolean apply(final GroupingDefinition g) {
+             return Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE.equals(g.getQName().getLocalName());
+         }
+     };
      public DataSchemaNode getRestconfModuleRestConfSchemaNode(final Module inRestconfModule, final String schemaNodeName) {
          Module restconfModule = inRestconfModule;
          if (restconfModule == null) {
          }
  
          Set<GroupingDefinition> groupings = restconfModule.getGroupings();
-         final Predicate<GroupingDefinition> filter = new Predicate<GroupingDefinition>() {
-             @Override
-             public boolean apply(final GroupingDefinition g) {
-                 return Objects.equal(g.getQName().getLocalName(), Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE);
-             }
-         };
-         Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, filter);
+         Iterable<GroupingDefinition> filteredGroups = Iterables.filter(groupings, GROUPING_FILTER);
          final GroupingDefinition restconfGrouping = Iterables.getFirst(filteredGroups, null);
  
          List<DataSchemaNode> instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping,
      }
  
      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) {
          return instantiatedDataNodeContainers;
      }
  
+     private static final Function<ChoiceNode, Set<ChoiceCaseNode>> CHOICE_FUNCTION = new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
+         @Override
+         public Set<ChoiceCaseNode> apply(final ChoiceNode node) {
+             return node.getCases();
+         }
+     };
      private void collectInstanceDataNodeContainers(final List<DataSchemaNode> potentialSchemaNodes,
              final DataNodeContainer container, final String name) {
  
              }
          }
  
-         Iterable<ChoiceNode> choiceNodes = Iterables.<ChoiceNode> filter(container.getChildNodes(), ChoiceNode.class);
-         final Function<ChoiceNode, Set<ChoiceCaseNode>> choiceFunction = new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
-             @Override
-             public Set<ChoiceCaseNode> apply(final ChoiceNode node) {
-                 return node.getCases();
-             }
-         };
-         Iterable<Set<ChoiceCaseNode>> map = Iterables.<ChoiceNode, Set<ChoiceCaseNode>> transform(choiceNodes,
-                 choiceFunction);
+         Iterable<ChoiceNode> choiceNodes = Iterables.filter(container.getChildNodes(), ChoiceNode.class);
+         Iterable<Set<ChoiceCaseNode>> map = Iterables.transform(choiceNodes, CHOICE_FUNCTION);
  
          final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat(map);
          for (final ChoiceCaseNode caze : allCases) {
      }
  
      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));