Add a method to get resource allocation of the given resource

Change-Id: I06b2f83b5a07a1bcbada9db5263abd2e1a4a4d17
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 618042a..82d8474 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
@@ -125,6 +125,15 @@
     boolean release(ResourceConsumer consumer);
 
     /**
+     * Returns resource allocation of the specified resource.
+     *
+     * @param resource resource to check the allocation
+     * @return allocation information enclosed by Optional.
+     * If the resource is not allocated, the return value is empty.
+     */
+    Optional<ResourceAllocation> getResourceAllocation(ResourcePath resource);
+
+    /**
      * Returns allocated resources being as children of the specified parent and being the specified resource type.
      *
      * @param parent parent resource path
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 2cd1a2e..5226967 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
@@ -91,6 +91,14 @@
     }
 
     @Override
+    public Optional<ResourceAllocation> getResourceAllocation(ResourcePath resource) {
+        checkNotNull(resource);
+
+        Optional<ResourceConsumer> consumer = store.getConsumer(resource);
+        return consumer.map(x -> new ResourceAllocation(resource, x));
+    }
+
+    @Override
     public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) {
         checkNotNull(parent);
         checkNotNull(cls);