Refactor: Rename ResourcePath to Resource for a better name
Also the followings
- Rename variables from path to resource
- Update Javadoc
Change-Id: I07da7e7d13882f2134a3687c66ed91a9de5b0849
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java b/core/api/src/main/java/org/onosproject/net/newresource/Resource.java
similarity index 87%
rename from core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
rename to core/api/src/main/java/org/onosproject/net/newresource/Resource.java
index 2e86509..72b9a57 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/Resource.java
@@ -29,10 +29,10 @@
import static com.google.common.base.Preconditions.checkState;
/**
- * An object that is used to locate a resource in a network.
- * A ResourcePath represents a path that is hierarchical and composed of a sequence
- * of elementary resources that are not globally identifiable. A ResourcePath can be a globally
- * unique resource identifier.
+ * An object that represent a resource in a network.
+ * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is
+ * composed of a sequence of elementary resources that are not globally identifiable. A Resource
+ * can be globally identifiable by its ID.
*
* Two types of resource are considered. One is discrete type and the other is continuous type.
* Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and
@@ -41,18 +41,18 @@
* A double value is associated with a continuous type value.
*
* Users of this class must keep the semantics of resources regarding the hierarchical structure.
- * For example, resource path, Device:1/Port:1/VLAN ID:100, is valid, but resource path,
+ * For example, resource, Device:1/Port:1/VLAN ID:100, is valid, but resource,
* VLAN ID:100/Device:1/Port:1 is not valid because a link is not a sub-component of a VLAN ID.
*/
@Beta
-public abstract class ResourcePath {
+public abstract class Resource {
private final Discrete parent;
private final ResourceId id;
public static final Discrete ROOT = new Discrete();
- public static ResourcePath discrete(DeviceId device) {
+ public static Resource discrete(DeviceId device) {
return new Discrete(ResourceId.of(device));
}
@@ -63,7 +63,7 @@
* @param components following components of the path. The order represents hierarchical structure of the resource.
* @return resource path instance
*/
- public static ResourcePath discrete(DeviceId device, Object... components) {
+ public static Resource discrete(DeviceId device, Object... components) {
return new Discrete(ResourceId.of(device, components));
}
@@ -75,7 +75,7 @@
* @param components following components of the path. The order represents hierarchical structure of the resource.
* @return resource path instance
*/
- public static ResourcePath discrete(DeviceId device, PortNumber port, Object... components) {
+ public static Resource discrete(DeviceId device, PortNumber port, Object... components) {
return new Discrete(ResourceId.of(device, port, components));
}
@@ -87,7 +87,7 @@
* @param components following components of the path. The order represents hierarchical structure of the resource.
* @return resource path instance
*/
- public static ResourcePath continuous(double value, DeviceId device, Object... components) {
+ public static Resource continuous(double value, DeviceId device, Object... components) {
checkArgument(components.length > 0,
"Length of components must be greater thant 0, but " + components.length);
@@ -103,7 +103,7 @@
* @param components following components of the path. The order represents hierarchical structure of the resource.
* @return resource path instance
*/
- public static ResourcePath continuous(double value, DeviceId device, PortNumber port, Object... components) {
+ public static Resource continuous(double value, DeviceId device, PortNumber port, Object... components) {
return new Continuous(ResourceId.of(device, port, components), value);
}
@@ -112,7 +112,7 @@
*
* @param id id of the path
*/
- protected ResourcePath(ResourceId id) {
+ protected Resource(ResourceId id) {
checkNotNull(id);
this.id = id;
@@ -124,7 +124,7 @@
}
// for serialization
- private ResourcePath() {
+ private Resource() {
this.parent = null;
this.id = ResourceId.ROOT;
}
@@ -156,7 +156,7 @@
* @param child child object
* @return a child resource path
*/
- public ResourcePath child(Object child) {
+ public Resource child(Object child) {
checkState(this instanceof Discrete);
return new Discrete(id().child(child));
@@ -170,7 +170,7 @@
* @param value value
* @return a child resource path
*/
- public ResourcePath child(Object child, double value) {
+ public Resource child(Object child, double value) {
checkState(this instanceof Discrete);
return new Continuous(id.child(child), value);
@@ -208,10 +208,10 @@
if (this == obj) {
return true;
}
- if (!(obj instanceof ResourcePath)) {
+ if (!(obj instanceof Resource)) {
return false;
}
- final ResourcePath that = (ResourcePath) obj;
+ final Resource that = (Resource) obj;
return Objects.equals(this.id, that.id);
}
@@ -231,7 +231,7 @@
* </p>
*/
@Beta
- public static final class Discrete extends ResourcePath {
+ public static final class Discrete extends Resource {
private Discrete() {
super();
}
@@ -249,7 +249,7 @@
* implementation only. It is not for resource API user.
*/
@Beta
- public static final class Continuous extends ResourcePath {
+ public static final class Continuous extends Resource {
private final double value;
private Continuous(ResourceId id, double value) {
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java
index 28c429b..ee4b630 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java
@@ -32,7 +32,7 @@
* @return true if registration is successfully done, false otherwise. Registration
* succeeds when each resource is not registered or unallocated.
*/
- default boolean registerResources(ResourcePath... resources) {
+ default boolean registerResources(Resource... resources) {
return registerResources(ImmutableList.copyOf(resources));
}
@@ -43,7 +43,7 @@
* @return true if registration is successfully done, false otherwise. Registration
* succeeds when each resource is not registered or unallocated.
*/
- boolean registerResources(List<ResourcePath> resources);
+ boolean registerResources(List<Resource> resources);
/**
* Unregisters the specified resources.
@@ -52,7 +52,7 @@
* @return true if unregistration is successfully done, false otherwise. Unregistration
* succeeds when each resource is not registered or unallocated.
*/
- default boolean unregisterResources(ResourcePath... resources) {
+ default boolean unregisterResources(Resource... resources) {
return unregisterResources(ImmutableList.copyOf(resources));
}
@@ -63,5 +63,5 @@
* @return true if unregistration is successfully done, false otherwise. Unregistration
* succeeds when each resource is not registered or unallocated.
*/
- boolean unregisterResources(List<ResourcePath> resources);
+ boolean unregisterResources(List<Resource> resources);
}
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceAllocation.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceAllocation.java
index 2d68fa5..07976a9 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceAllocation.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceAllocation.java
@@ -28,7 +28,7 @@
@Beta
public class ResourceAllocation {
- private final ResourcePath resource;
+ private final Resource resource;
private final ResourceConsumer consumer;
/**
@@ -37,7 +37,7 @@
* @param resource resource of the subject
* @param consumer consumer of this resource
*/
- public ResourceAllocation(ResourcePath resource, ResourceConsumer consumer) {
+ public ResourceAllocation(Resource resource, ResourceConsumer consumer) {
this.resource = checkNotNull(resource);
this.consumer = consumer;
}
@@ -53,7 +53,7 @@
*
* @return the specifier of the resource this allocation uses
*/
- public ResourcePath resource() {
+ public Resource resource() {
return resource;
}
diff --git a/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java b/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java
index 98abf30..c54b505 100644
--- a/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java
+++ b/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java
@@ -24,7 +24,7 @@
* Describes an event related to a resource.
*/
@Beta
-public final class ResourceEvent extends AbstractEvent<ResourceEvent.Type, ResourcePath> {
+public final class ResourceEvent extends AbstractEvent<ResourceEvent.Type, Resource> {
/**
* Type of resource events.
@@ -48,7 +48,7 @@
* @param type type of resource event
* @param subject subject of resource event
*/
- public ResourceEvent(Type type, ResourcePath subject) {
+ public ResourceEvent(Type type, Resource subject) {
super(checkNotNull(type), checkNotNull(subject));
}
}
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 79a7bba..3076ec9 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
@@ -38,7 +38,7 @@
* @param resource resource to be allocated
* @return allocation information enclosed by Optional. If the allocation fails, the return value is empty
*/
- default Optional<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath resource) {
+ default Optional<ResourceAllocation> allocate(ResourceConsumer consumer, Resource resource) {
checkNotNull(consumer);
checkNotNull(resource);
@@ -65,7 +65,7 @@
* @param resources resources to be allocated
* @return non-empty list of allocation information if succeeded, otherwise empty list
*/
- List<ResourceAllocation> allocate(ResourceConsumer consumer, List<ResourcePath> resources);
+ List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources);
/**
* Transactionally allocates the specified resources to the specified user.
@@ -75,7 +75,7 @@
* @param resources resources to be allocated
* @return non-empty list of allocation information if succeeded, otherwise empty list
*/
- default List<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath... resources) {
+ default List<ResourceAllocation> allocate(ResourceConsumer consumer, Resource... resources) {
checkNotNull(consumer);
checkNotNull(resources);
@@ -132,18 +132,18 @@
* @return list of allocation information.
* If the resource is not allocated, the return value is an empty list.
*/
- List<ResourceAllocation> getResourceAllocation(ResourcePath resource);
+ List<ResourceAllocation> getResourceAllocation(Resource resource);
/**
* Returns allocated resources being as children of the specified parent and being the specified resource type.
*
- * @param parent parent resource path
+ * @param parent parent resource
* @param cls class to specify a type of resource
* @param <T> type of the resource
* @return non-empty collection of resource allocations if resources are allocated with the subject and type,
* empty collection if no resource is allocated with the subject and type
*/
- <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls);
+ <T> Collection<ResourceAllocation> getResourceAllocations(Resource parent, Class<T> cls);
/**
* Returns resources allocated to the specified consumer.
@@ -154,12 +154,12 @@
Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer);
/**
- * Returns resource paths that point available child resources under the specified resource path.
+ * Returns resources that point available child resources under the specified resource.
*
- * @param parent parent resource path
- * @return available resource paths under the specified resource path
+ * @param parent parent resource
+ * @return available resources under the specified resource
*/
- Collection<ResourcePath> getAvailableResources(ResourcePath parent);
+ Collection<Resource> getAvailableResources(Resource parent);
/**
* Returns the availability of the specified resource.
@@ -167,7 +167,7 @@
* @param resource resource to check the availability
* @return true if available, otherwise false
*/
- boolean isAvailable(ResourcePath resource);
+ boolean isAvailable(Resource resource);
// TODO: listener and event mechanism need to be considered
}
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 b0c24bd..ac30548 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
@@ -36,7 +36,7 @@
* @param resources resources to be registered
* @return true if the registration succeeds, false otherwise
*/
- boolean register(List<ResourcePath> resources);
+ boolean register(List<Resource> resources);
/**
* Unregisters the resources in transactional way.
@@ -47,7 +47,7 @@
* @param resources resources to be unregistered
* @return true if the registration succeeds, false otherwise
*/
- boolean unregister(List<ResourcePath> resources);
+ boolean unregister(List<Resource> resources);
/**
* Allocates the specified resources to the specified consumer in transactional way.
@@ -59,7 +59,7 @@
* @param consumer resource consumer which the resources are allocated to
* @return true if the allocation succeeds, false otherwise.
*/
- boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer);
+ boolean allocate(List<Resource> resources, ResourceConsumer consumer);
/**
* Releases the specified resources allocated to the specified corresponding consumers
@@ -73,7 +73,7 @@
* @param consumers resource consumers to whom the resource allocated to
* @return true if succeeds, otherwise false
*/
- boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers);
+ boolean release(List<Resource> resources, List<ResourceConsumer> consumers);
/**
* Returns the resource consumers to whom the specified resource is allocated.
@@ -84,7 +84,7 @@
* @return resource consumers who are allocated the resource.
* Returns empty list if there is no such consumer.
*/
- List<ResourceConsumer> getConsumers(ResourcePath resource);
+ List<ResourceConsumer> getConsumers(Resource resource);
/**
* Returns the availability of the specified resource.
@@ -92,7 +92,7 @@
* @param resource resource to check the availability
* @return true if available, otherwise false
*/
- boolean isAvailable(ResourcePath resource);
+ boolean isAvailable(Resource resource);
/**
* Returns a collection of the resources allocated to the specified consumer.
@@ -100,7 +100,7 @@
* @param consumer resource consumer whose allocated resource are searched for
* @return a collection of the resources allocated to the specified consumer
*/
- Collection<ResourcePath> getResources(ResourceConsumer consumer);
+ Collection<Resource> getResources(ResourceConsumer consumer);
/**
* Returns a collection of the child resources of the specified parent.
@@ -108,7 +108,7 @@
* @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);
+ Collection<Resource> getChildResources(Resource parent);
/**
* Returns a collection of the resources which are children of the specified parent and
@@ -120,5 +120,5 @@
* @return a collection of the resources which belongs to the specified subject and
* whose type is the specified class.
*/
- <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls);
+ <T> Collection<Resource> getAllocatedResources(Resource parent, Class<T> cls);
}
diff --git a/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java b/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java
index d21c4b1..a9a8ed2 100644
--- a/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java
+++ b/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java
@@ -32,9 +32,9 @@
@Test
public void testEquals() {
- ResourceAllocation alloc1 = new ResourceAllocation(ResourcePath.discrete(D1, P1, VLAN1), IID1);
- ResourceAllocation sameAsAlloc1 = new ResourceAllocation(ResourcePath.discrete(D1, P1, VLAN1), IID1);
- ResourceAllocation alloc2 = new ResourceAllocation(ResourcePath.discrete(D2, P1, VLAN1), IID1);
+ ResourceAllocation alloc1 = new ResourceAllocation(Resource.discrete(D1, P1, VLAN1), IID1);
+ ResourceAllocation sameAsAlloc1 = new ResourceAllocation(Resource.discrete(D1, P1, VLAN1), IID1);
+ ResourceAllocation alloc2 = new ResourceAllocation(Resource.discrete(D2, P1, VLAN1), IID1);
new EqualsTester()
.addEqualityGroup(alloc1, sameAsAlloc1)
diff --git a/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java b/core/api/src/test/java/org/onosproject/net/newresource/ResourceTest.java
similarity index 62%
rename from core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java
rename to core/api/src/test/java/org/onosproject/net/newresource/ResourceTest.java
index ea7ff5e..dd4432d 100644
--- a/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java
+++ b/core/api/src/test/java/org/onosproject/net/newresource/ResourceTest.java
@@ -28,7 +28,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-public class ResourcePathTest {
+public class ResourceTest {
private static final DeviceId D1 = DeviceId.deviceId("of:001");
private static final DeviceId D2 = DeviceId.deviceId("of:002");
@@ -39,11 +39,11 @@
@Test
public void testEquals() {
- ResourcePath resource1 = ResourcePath.discrete(D1, P1, VLAN1);
- ResourcePath sameAsResource1 = ResourcePath.discrete(D1, P1, VLAN1);
- ResourcePath resource2 = ResourcePath.discrete(D2, P1, VLAN1);
- ResourcePath resource3 = ResourcePath.continuous(BW1.bps(), D1, P1, BW1);
- ResourcePath sameAsResource3 = ResourcePath.continuous(BW1.bps(), D1, P1, BW1);
+ Resource resource1 = Resource.discrete(D1, P1, VLAN1);
+ Resource sameAsResource1 = Resource.discrete(D1, P1, VLAN1);
+ Resource resource2 = Resource.discrete(D2, P1, VLAN1);
+ Resource resource3 = Resource.continuous(BW1.bps(), D1, P1, BW1);
+ Resource sameAsResource3 = Resource.continuous(BW1.bps(), D1, P1, BW1);
new EqualsTester()
.addEqualityGroup(resource1, sameAsResource1)
@@ -54,19 +54,19 @@
@Test
public void testComponents() {
- ResourcePath port = ResourcePath.discrete(D1, P1);
+ Resource port = Resource.discrete(D1, P1);
assertThat(port.components(), contains(D1, P1));
}
@Test
public void testIdEquality() {
- ResourceId id1 = ResourcePath.discrete(D1, P1, VLAN1).id();
- ResourceId sameAsId1 = ResourcePath.discrete(D1, P1, VLAN1).id();
- ResourceId id2 = ResourcePath.discrete(D2, P1, VLAN1).id();
- ResourceId id3 = ResourcePath.continuous(BW1.bps(), D1, P1, BW1).id();
+ ResourceId id1 = Resource.discrete(D1, P1, VLAN1).id();
+ ResourceId sameAsId1 = Resource.discrete(D1, P1, VLAN1).id();
+ ResourceId id2 = Resource.discrete(D2, P1, VLAN1).id();
+ ResourceId id3 = Resource.continuous(BW1.bps(), D1, P1, BW1).id();
// intentionally set a different value
- ResourceId sameAsId3 = ResourcePath.continuous(BW2.bps(), D1, P1, BW1).id();
+ ResourceId sameAsId3 = Resource.continuous(BW2.bps(), D1, P1, BW1).id();
new EqualsTester()
.addEqualityGroup(id1, sameAsId1)
@@ -76,32 +76,32 @@
@Test
public void testChild() {
- ResourcePath r1 = ResourcePath.discrete(D1).child(P1);
- ResourcePath sameAsR2 = ResourcePath.discrete(D1, P1);
+ Resource r1 = Resource.discrete(D1).child(P1);
+ Resource sameAsR2 = Resource.discrete(D1, P1);
assertThat(r1, is(sameAsR2));
}
@Test
public void testThereIsParent() {
- ResourcePath path = ResourcePath.discrete(D1, P1, VLAN1);
- ResourcePath parent = ResourcePath.discrete(D1, P1);
+ Resource resource = Resource.discrete(D1, P1, VLAN1);
+ Resource parent = Resource.discrete(D1, P1);
- assertThat(path.parent(), is(Optional.of(parent)));
+ assertThat(resource.parent(), is(Optional.of(parent)));
}
@Test
public void testNoParent() {
- ResourcePath path = ResourcePath.discrete(D1);
+ Resource resource = Resource.discrete(D1);
- assertThat(path.parent(), is(Optional.of(ResourcePath.ROOT)));
+ assertThat(resource.parent(), is(Optional.of(Resource.ROOT)));
}
@Test
public void testBase() {
- ResourcePath path = ResourcePath.discrete(D1);
+ Resource resource = Resource.discrete(D1);
- DeviceId child = (DeviceId) path.last();
+ DeviceId child = (DeviceId) resource.last();
assertThat(child, is(D1));
}
}