Define and implement a method to query available resources

Change-Id: I49fbcdf215e402603ea15f469d41e572f1cce1c6
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java
index 82d8474..ad684c8 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java
@@ -153,6 +153,14 @@
     Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer);
 
     /**
+     * Returns resource paths that point available child resources under the specified resource path.
+     *
+     * @param parent parent resource path
+     * @return available resource paths under the specified resource path
+     */
+    Collection<ResourcePath> getAvailableResources(ResourcePath parent);
+
+    /**
      * Returns the availability of the specified resource.
      *
      * @param resource resource to check the availability
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
index 5a034b4..2cab9d4 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java
@@ -92,6 +92,14 @@
     Collection<ResourcePath> getResources(ResourceConsumer consumer);
 
     /**
+     * Returns a collection of the child resources of the specified parent.
+     *
+     * @param parent parent of the resource to be returned
+     * @return a collection of the child resources of the specified resource
+     */
+    Collection<ResourcePath> getChildResources(ResourcePath parent);
+
+    /**
      * Returns a collection of the resources which are children of the specified parent and
      * whose type is the specified class.
      *
diff --git a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
index a27ce67..10fe75e 100644
--- a/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java
@@ -127,6 +127,17 @@
     }
 
     @Override
+    public Collection<ResourcePath> getAvailableResources(ResourcePath parent) {
+        checkNotNull(parent);
+
+        Collection<ResourcePath> children = store.getChildResources(parent);
+        return children.stream()
+                // We access store twice in this method, then the store may be updated by others
+                .filter(x -> !store.getConsumer(x).isPresent())
+                .collect(Collectors.toList());
+    }
+
+    @Override
     public boolean isAvailable(ResourcePath resource) {
         checkNotNull(resource);
 
diff --git a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
index d466c95..687576c 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java
@@ -239,6 +239,18 @@
     }
 
     @Override
+    public Collection<ResourcePath> getChildResources(ResourcePath parent) {
+        checkNotNull(parent);
+
+        Versioned<List<ResourcePath>> children = childMap.get(parent);
+        if (children == null) {
+            return Collections.emptyList();
+        }
+
+        return children.value();
+    }
+
+    @Override
     public <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls) {
         checkNotNull(parent);
         checkNotNull(cls);