Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Rename ResourcePath to Resource for a better name

Also the followings
- Rename variables from path to resource
- Update Javadoc

Change-Id: I07da7e7d13882f2134a3687c66ed91a9de5b0849
Showing 22 changed files with 224 additions and 224 deletions
......@@ -31,7 +31,7 @@ import org.onosproject.net.Port;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
import com.google.common.base.Strings;
......@@ -106,11 +106,11 @@ public class AllocationsCommand extends AbstractShellCommand {
// TODO: Current design cannot deal with sub-resources
// (e.g., TX/RX under Port)
ResourcePath path = ResourcePath.discrete(did, num);
Resource resource = Resource.discrete(did, num);
if (lambda) {
//print("Lambda resources:");
Collection<ResourceAllocation> allocations
= resourceService.getResourceAllocations(path, OchSignal.class);
= resourceService.getResourceAllocations(resource, OchSignal.class);
for (ResourceAllocation a : allocations) {
print("%s%s allocated by %s", Strings.repeat(" ", level + 1),
......
......@@ -29,7 +29,7 @@ import org.apache.karaf.shell.commands.Option;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
import com.google.common.base.Strings;
......@@ -76,20 +76,20 @@ public class ResourcesCommand extends AbstractShellCommand {
DeviceId deviceId = deviceId(deviceIdStr);
PortNumber portNumber = PortNumber.fromString(portNumberStr);
printResource(ResourcePath.discrete(deviceId, portNumber), 0);
printResource(Resource.discrete(deviceId, portNumber), 0);
} else if (deviceIdStr != null) {
DeviceId deviceId = deviceId(deviceIdStr);
printResource(ResourcePath.discrete(deviceId), 0);
printResource(Resource.discrete(deviceId), 0);
} else {
printResource(ResourcePath.ROOT, 0);
printResource(Resource.ROOT, 0);
}
}
private void printResource(ResourcePath resource, int level) {
Collection<ResourcePath> children = resourceService.getAvailableResources(resource);
private void printResource(Resource resource, int level) {
Collection<Resource> children = resourceService.getAvailableResources(resource);
if (resource.equals(ResourcePath.ROOT)) {
if (resource.equals(Resource.ROOT)) {
print("ROOT");
} else {
String resourceName = resource.last().getClass().getSimpleName();
......
......@@ -15,7 +15,7 @@
*/
package org.onosproject.cli.net;
import static org.onosproject.net.newresource.ResourcePath.discrete;
import static org.onosproject.net.newresource.Resource.discrete;
import java.util.Optional;
......@@ -31,7 +31,7 @@ import org.onosproject.net.PortNumber;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourceConsumer;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
/**
......@@ -73,7 +73,7 @@ public class TestAllocateResource extends AbstractShellCommand {
ResourceConsumer consumer = IntentId.valueOf(nIntendId);
ResourcePath resource = discrete(did, portNum,
Resource resource = discrete(did, portNum,
createLambda(Integer.parseInt(lambda)));
Optional<ResourceAllocation> allocate = resourceService.allocate(consumer, resource);
......
......@@ -29,10 +29,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
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 @@ import static com.google.common.base.Preconditions.checkState;
* 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 @@ public abstract class ResourcePath {
* @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 @@ public abstract class ResourcePath {
* @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 @@ public abstract class ResourcePath {
* @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 @@ public abstract class ResourcePath {
* @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 @@ public abstract class ResourcePath {
*
* @param id id of the path
*/
protected ResourcePath(ResourceId id) {
protected Resource(ResourceId id) {
checkNotNull(id);
this.id = id;
......@@ -124,7 +124,7 @@ public abstract class ResourcePath {
}
// for serialization
private ResourcePath() {
private Resource() {
this.parent = null;
this.id = ResourceId.ROOT;
}
......@@ -156,7 +156,7 @@ public abstract class ResourcePath {
* @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 @@ public abstract class ResourcePath {
* @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 @@ public abstract class ResourcePath {
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 @@ public abstract class ResourcePath {
* </p>
*/
@Beta
public static final class Discrete extends ResourcePath {
public static final class Discrete extends Resource {
private Discrete() {
super();
}
......@@ -249,7 +249,7 @@ public abstract class ResourcePath {
* 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) {
......
......@@ -32,7 +32,7 @@ public interface ResourceAdminService {
* @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 @@ public interface ResourceAdminService {
* @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 @@ public interface ResourceAdminService {
* @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 @@ public interface ResourceAdminService {
* @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);
}
......
......@@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
@Beta
public class ResourceAllocation {
private final ResourcePath resource;
private final Resource resource;
private final ResourceConsumer consumer;
/**
......@@ -37,7 +37,7 @@ public class ResourceAllocation {
* @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 @@ public class ResourceAllocation {
*
* @return the specifier of the resource this allocation uses
*/
public ResourcePath resource() {
public Resource resource() {
return resource;
}
......
......@@ -24,7 +24,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* 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 @@ public final class ResourceEvent extends AbstractEvent<ResourceEvent.Type, Resou
* @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));
}
}
......
......@@ -38,7 +38,7 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
* @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 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
* @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 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
* @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 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
* @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 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
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 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
* @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
}
......
......@@ -36,7 +36,7 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
* @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);
}
......
......@@ -32,9 +32,9 @@ public class ResourceAllocationTest {
@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)
......
......@@ -28,7 +28,7 @@ import static org.hamcrest.Matchers.contains;
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 @@ public class ResourcePathTest {
@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 @@ public class ResourcePathTest {
@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 @@ public class ResourcePathTest {
@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));
}
}
......
......@@ -49,7 +49,7 @@ import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentCompiler;
import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.MplsPathIntent;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.resource.link.LinkResourceAllocations;
import org.slf4j.Logger;
......@@ -123,10 +123,10 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
// for short term solution: same label is used for both directions
// TODO: introduce the concept of Tx and Rx resources of a port
Set<ResourcePath> resources = labels.entrySet().stream()
Set<Resource> resources = labels.entrySet().stream()
.flatMap(x -> Stream.of(
ResourcePath.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()),
ResourcePath.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()),
Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
))
.collect(Collectors.toSet());
List<org.onosproject.net.newresource.ResourceAllocation> allocations =
......@@ -154,7 +154,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
}
private Set<MplsLabel> findMplsLabel(ConnectPoint cp) {
return resourceService.getAvailableResources(ResourcePath.discrete(cp.deviceId(), cp.port())).stream()
return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port())).stream()
.filter(x -> x.last() instanceof MplsLabel)
.map(x -> (MplsLabel) x.last())
.collect(Collectors.toSet());
......
......@@ -50,7 +50,7 @@ import org.onosproject.net.intent.OpticalCircuitIntent;
import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.resource.device.IntentSetMultimap;
import org.onosproject.net.resource.link.LinkResourceAllocations;
......@@ -160,9 +160,9 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
log.debug("Compiling optical circuit intent between {} and {}", src, dst);
// Reserve OduClt ports
ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port());
ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port());
List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath);
Resource srcPortResource = Resource.discrete(src.deviceId(), src.port());
Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port());
List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource);
if (allocation.isEmpty()) {
throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
}
......@@ -312,7 +312,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
if (ochCP != null) {
OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port());
Optional<IntentId> intentId =
resourceService.getResourceAllocation(ResourcePath.discrete(ochCP.deviceId(), ochCP.port()))
resourceService.getResourceAllocation(Resource.discrete(ochCP.deviceId(), ochCP.port()))
.stream()
.map(ResourceAllocation::consumer)
.filter(x -> x instanceof IntentId)
......@@ -333,7 +333,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
}
Optional<IntentId> intentId =
resourceService.getResourceAllocation(ResourcePath.discrete(oduPort.deviceId(), port.number()))
resourceService.getResourceAllocation(Resource.discrete(oduPort.deviceId(), port.number()))
.stream()
.map(ResourceAllocation::consumer)
.filter(x -> x instanceof IntentId)
......
......@@ -44,7 +44,7 @@ import org.onosproject.net.intent.OpticalConnectivityIntent;
import org.onosproject.net.intent.OpticalPathIntent;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.resource.link.LinkResourceAllocations;
import org.onosproject.net.topology.LinkWeight;
......@@ -109,10 +109,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
// Reserve OCh ports
ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port());
ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port());
Resource srcPortResource = Resource.discrete(src.deviceId(), src.port());
Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port());
List<org.onosproject.net.newresource.ResourceAllocation> allocation =
resourceService.allocate(intent.id(), srcPortPath, dstPortPath);
resourceService.allocate(intent.id(), srcPortResource, dstPortResource);
if (allocation.isEmpty()) {
throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
}
......@@ -182,10 +182,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
}
List<OchSignal> minLambda = findFirstLambda(lambdas, slotCount());
List<ResourcePath> lambdaResources = path.links().stream()
List<Resource> lambdaResources = path.links().stream()
.flatMap(x -> Stream.of(
ResourcePath.discrete(x.src().deviceId(), x.src().port()),
ResourcePath.discrete(x.dst().deviceId(), x.dst().port())
Resource.discrete(x.src().deviceId(), x.src().port()),
Resource.discrete(x.dst().deviceId(), x.dst().port())
))
.flatMap(x -> minLambda.stream().map(l -> x.child(l)))
.collect(Collectors.toList());
......@@ -214,8 +214,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
private Set<OchSignal> findCommonLambdasOverLinks(List<Link> links) {
return links.stream()
.flatMap(x -> Stream.of(
ResourcePath.discrete(x.src().deviceId(), x.src().port()),
ResourcePath.discrete(x.dst().deviceId(), x.dst().port())
Resource.discrete(x.src().deviceId(), x.src().port()),
Resource.discrete(x.dst().deviceId(), x.dst().port())
))
.map(resourceService::getAvailableResources)
.map(x -> Iterables.filter(x, r -> r.last() instanceof OchSignal))
......
......@@ -44,7 +44,7 @@ import org.onosproject.net.intent.IntentExtensionService;
import org.onosproject.net.intent.PathIntent;
import org.onosproject.net.intent.constraint.EncapsulationConstraint;
import org.onosproject.net.intent.impl.IntentCompilationException;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.resource.link.LinkResourceAllocations;
import org.slf4j.Logger;
......@@ -250,10 +250,10 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
}
//same VLANID is used for both directions
Set<ResourcePath> resources = vlanIds.entrySet().stream()
Set<Resource> resources = vlanIds.entrySet().stream()
.flatMap(x -> Stream.of(
ResourcePath.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()),
ResourcePath.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()),
Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
))
.collect(Collectors.toSet());
List<org.onosproject.net.newresource.ResourceAllocation> allocations =
......@@ -280,7 +280,7 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
}
private Set<VlanId> findVlanId(ConnectPoint cp) {
return resourceService.getAvailableResources(ResourcePath.discrete(cp.deviceId(), cp.port())).stream()
return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port())).stream()
.filter(x -> x.last() instanceof VlanId)
.map(x -> (VlanId) x.last())
.collect(Collectors.toSet());
......
......@@ -35,7 +35,7 @@ import org.onosproject.net.device.DeviceService;
import org.onosproject.net.driver.DriverHandler;
import org.onosproject.net.driver.DriverService;
import org.onosproject.net.newresource.ResourceAdminService;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -108,15 +108,15 @@ final class ResourceDeviceListener implements DeviceListener {
}
private void registerDeviceResource(Device device) {
executor.submit(() -> adminService.registerResources(ResourcePath.discrete(device.id())));
executor.submit(() -> adminService.registerResources(Resource.discrete(device.id())));
}
private void unregisterDeviceResource(Device device) {
executor.submit(() -> adminService.unregisterResources(ResourcePath.discrete(device.id())));
executor.submit(() -> adminService.unregisterResources(Resource.discrete(device.id())));
}
private void registerPortResource(Device device, Port port) {
ResourcePath portPath = ResourcePath.discrete(device.id(), port.number());
Resource portPath = Resource.discrete(device.id(), port.number());
executor.submit(() -> {
adminService.registerResources(portPath);
......@@ -155,7 +155,7 @@ final class ResourceDeviceListener implements DeviceListener {
}
private void unregisterPortResource(Device device, Port port) {
ResourcePath resource = ResourcePath.discrete(device.id(), port.number());
Resource resource = Resource.discrete(device.id(), port.number());
executor.submit(() -> adminService.unregisterResources(resource));
}
......
......@@ -31,7 +31,7 @@ import org.onosproject.net.newresource.ResourceConsumer;
import org.onosproject.net.newresource.ResourceEvent;
import org.onosproject.net.newresource.ResourceListener;
import org.onosproject.net.newresource.ResourceService;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceStore;
import org.onosproject.net.newresource.ResourceStoreDelegate;
......@@ -69,7 +69,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
@Override
public List<ResourceAllocation> allocate(ResourceConsumer consumer,
List<ResourcePath> resources) {
List<Resource> resources) {
checkNotNull(consumer);
checkNotNull(resources);
......@@ -87,7 +87,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
public boolean release(List<ResourceAllocation> allocations) {
checkNotNull(allocations);
List<ResourcePath> resources = allocations.stream()
List<Resource> resources = allocations.stream()
.map(ResourceAllocation::resource)
.collect(Collectors.toList());
List<ResourceConsumer> consumers = allocations.stream()
......@@ -106,7 +106,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
}
@Override
public List<ResourceAllocation> getResourceAllocation(ResourcePath resource) {
public List<ResourceAllocation> getResourceAllocation(Resource resource) {
checkNotNull(resource);
List<ResourceConsumer> consumers = store.getConsumers(resource);
......@@ -116,12 +116,12 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
}
@Override
public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) {
public <T> Collection<ResourceAllocation> getResourceAllocations(Resource parent, Class<T> cls) {
checkNotNull(parent);
checkNotNull(cls);
// We access store twice in this method, then the store may be updated by others
Collection<ResourcePath> resources = store.getAllocatedResources(parent, cls);
Collection<Resource> resources = store.getAllocatedResources(parent, cls);
return resources.stream()
.flatMap(resource -> store.getConsumers(resource).stream()
.map(consumer -> new ResourceAllocation(resource, consumer)))
......@@ -132,17 +132,17 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
public Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer) {
checkNotNull(consumer);
Collection<ResourcePath> resources = store.getResources(consumer);
Collection<Resource> resources = store.getResources(consumer);
return resources.stream()
.map(x -> new ResourceAllocation(x, consumer))
.collect(Collectors.toList());
}
@Override
public Collection<ResourcePath> getAvailableResources(ResourcePath parent) {
public Collection<Resource> getAvailableResources(Resource parent) {
checkNotNull(parent);
Collection<ResourcePath> children = store.getChildResources(parent);
Collection<Resource> children = store.getChildResources(parent);
return children.stream()
// We access store twice in this method, then the store may be updated by others
.filter(store::isAvailable)
......@@ -150,21 +150,21 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
}
@Override
public boolean isAvailable(ResourcePath resource) {
public boolean isAvailable(Resource resource) {
checkNotNull(resource);
return store.isAvailable(resource);
}
@Override
public boolean registerResources(List<ResourcePath> resources) {
public boolean registerResources(List<Resource> resources) {
checkNotNull(resources);
return store.register(resources);
}
@Override
public boolean unregisterResources(List<ResourcePath> resources) {
public boolean unregisterResources(List<Resource> resources) {
checkNotNull(resources);
return store.unregister(resources);
......
......@@ -41,7 +41,7 @@ import org.onosproject.net.intent.MockIdGenerator;
import org.onosproject.net.link.LinkEvent;
import org.onosproject.net.newresource.ResourceEvent;
import org.onosproject.net.newresource.ResourceListener;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.topology.Topology;
import org.onosproject.net.topology.TopologyEvent;
import org.onosproject.net.topology.TopologyListener;
......@@ -232,7 +232,7 @@ public class ObjectiveTrackerTest {
@Test
public void testResourceEvent() throws Exception {
ResourceEvent event = new ResourceEvent(RESOURCE_ADDED,
ResourcePath.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(1)));
Resource.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(1)));
resourceListener.event(event);
assertThat(
......
......@@ -21,7 +21,7 @@ import org.onlab.packet.VlanId;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourceConsumer;
import org.onosproject.net.newresource.ResourceListener;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceService;
import java.util.Collection;
......@@ -34,10 +34,10 @@ import java.util.stream.Collectors;
class MockResourceService implements ResourceService {
private final Map<ResourcePath, ResourceConsumer> assignment = new HashMap<>();
private final Map<Resource, ResourceConsumer> assignment = new HashMap<>();
@Override
public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<ResourcePath> resources) {
public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<Resource> resources) {
assignment.putAll(
resources.stream().collect(Collectors.toMap(x -> x, x -> consumer))
);
......@@ -56,7 +56,7 @@ class MockResourceService implements ResourceService {
@Override
public boolean release(ResourceConsumer consumer) {
List<ResourcePath> resources = assignment.entrySet().stream()
List<Resource> resources = assignment.entrySet().stream()
.filter(x -> x.getValue().equals(consumer))
.map(Map.Entry::getKey)
.collect(Collectors.toList());
......@@ -68,14 +68,14 @@ class MockResourceService implements ResourceService {
}
@Override
public List<ResourceAllocation> getResourceAllocation(ResourcePath resource) {
public List<ResourceAllocation> getResourceAllocation(Resource resource) {
return Optional.ofNullable(assignment.get(resource))
.map(x -> ImmutableList.of(new ResourceAllocation(resource, x)))
.orElse(ImmutableList.of());
}
@Override
public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) {
public <T> Collection<ResourceAllocation> getResourceAllocations(Resource parent, Class<T> cls) {
return assignment.entrySet().stream()
.filter(x -> x.getKey().parent().isPresent())
.filter(x -> x.getKey().parent().get().equals(parent))
......@@ -92,16 +92,16 @@ class MockResourceService implements ResourceService {
}
@Override
public Collection<ResourcePath> getAvailableResources(ResourcePath parent) {
public Collection<Resource> getAvailableResources(Resource parent) {
Collection<ResourcePath> resources = new HashSet<ResourcePath>();
Collection<Resource> resources = new HashSet<Resource>();
resources.add(parent.child(VlanId.vlanId((short) 10)));
resources.add(parent.child(MplsLabel.mplsLabel(10)));
return ImmutableList.copyOf(resources);
}
@Override
public boolean isAvailable(ResourcePath resource) {
public boolean isAvailable(Resource resource) {
return true;
}
......
......@@ -29,7 +29,7 @@ import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourceConsumer;
import org.onosproject.net.newresource.ResourceEvent;
import org.onosproject.net.newresource.ResourceId;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.newresource.ResourceStore;
import org.onosproject.net.newresource.ResourceStoreDelegate;
import org.onosproject.store.AbstractStore;
......@@ -84,13 +84,13 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService service;
private ConsistentMap<ResourcePath.Discrete, ResourceConsumer> discreteConsumers;
private ConsistentMap<Resource.Discrete, ResourceConsumer> discreteConsumers;
private ConsistentMap<ResourceId, ContinuousResourceAllocation> continuousConsumers;
private ConsistentMap<ResourcePath.Discrete, Set<ResourcePath>> childMap;
private ConsistentMap<Resource.Discrete, Set<Resource>> childMap;
@Activate
public void activate() {
discreteConsumers = service.<ResourcePath.Discrete, ResourceConsumer>consistentMapBuilder()
discreteConsumers = service.<Resource.Discrete, ResourceConsumer>consistentMapBuilder()
.withName(DISCRETE_CONSUMER_MAP)
.withSerializer(SERIALIZER)
.build();
......@@ -98,29 +98,29 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
.withName(CONTINUOUS_CONSUMER_MAP)
.withSerializer(SERIALIZER)
.build();
childMap = service.<ResourcePath.Discrete, Set<ResourcePath>>consistentMapBuilder()
childMap = service.<Resource.Discrete, Set<Resource>>consistentMapBuilder()
.withName(CHILD_MAP)
.withSerializer(SERIALIZER)
.build();
Tools.retryable(() -> childMap.put(ResourcePath.ROOT, new LinkedHashSet<>()),
Tools.retryable(() -> childMap.put(Resource.ROOT, new LinkedHashSet<>()),
ConsistentMapException.class, MAX_RETRIES, RETRY_DELAY);
log.info("Started");
}
@Override
public List<ResourceConsumer> getConsumers(ResourcePath resource) {
public List<ResourceConsumer> getConsumers(Resource resource) {
checkNotNull(resource);
checkArgument(resource instanceof ResourcePath.Discrete || resource instanceof ResourcePath.Continuous);
checkArgument(resource instanceof Resource.Discrete || resource instanceof Resource.Continuous);
if (resource instanceof ResourcePath.Discrete) {
return getConsumer((ResourcePath.Discrete) resource);
if (resource instanceof Resource.Discrete) {
return getConsumer((Resource.Discrete) resource);
} else {
return getConsumer((ResourcePath.Continuous) resource);
return getConsumer((Resource.Continuous) resource);
}
}
private List<ResourceConsumer> getConsumer(ResourcePath.Discrete resource) {
private List<ResourceConsumer> getConsumer(Resource.Discrete resource) {
Versioned<ResourceConsumer> consumer = discreteConsumers.get(resource);
if (consumer == null) {
return ImmutableList.of();
......@@ -129,7 +129,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
return ImmutableList.of(consumer.value());
}
private List<ResourceConsumer> getConsumer(ResourcePath.Continuous resource) {
private List<ResourceConsumer> getConsumer(Resource.Continuous resource) {
Versioned<ContinuousResourceAllocation> allocations = continuousConsumers.get(resource.id());
if (allocations == null) {
return ImmutableList.of();
......@@ -142,21 +142,21 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
}
@Override
public boolean register(List<ResourcePath> resources) {
public boolean register(List<Resource> resources) {
checkNotNull(resources);
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
TransactionalMap<ResourcePath.Discrete, Set<ResourcePath>> childTxMap =
TransactionalMap<Resource.Discrete, Set<Resource>> childTxMap =
tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
Map<ResourcePath.Discrete, List<ResourcePath>> resourceMap = resources.stream()
Map<Resource.Discrete, List<Resource>> resourceMap = resources.stream()
.filter(x -> x.parent().isPresent())
.collect(Collectors.groupingBy(x -> x.parent().get()));
for (Map.Entry<ResourcePath.Discrete, List<ResourcePath>> entry: resourceMap.entrySet()) {
Optional<ResourcePath.Discrete> child = lookup(childTxMap, entry.getKey());
for (Map.Entry<Resource.Discrete, List<Resource>> entry: resourceMap.entrySet()) {
Optional<Resource.Discrete> child = lookup(childTxMap, entry.getKey());
if (!child.isPresent()) {
return abortTransaction(tx);
}
......@@ -178,31 +178,31 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
}
@Override
public boolean unregister(List<ResourcePath> resources) {
public boolean unregister(List<Resource> resources) {
checkNotNull(resources);
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
TransactionalMap<ResourcePath.Discrete, Set<ResourcePath>> childTxMap =
TransactionalMap<Resource.Discrete, Set<Resource>> childTxMap =
tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
TransactionalMap<ResourcePath.Discrete, ResourceConsumer> discreteConsumerTxMap =
TransactionalMap<Resource.Discrete, ResourceConsumer> discreteConsumerTxMap =
tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
// Extract Discrete instances from resources
Map<ResourcePath.Discrete, List<ResourcePath>> resourceMap = resources.stream()
Map<Resource.Discrete, List<Resource>> resourceMap = resources.stream()
.filter(x -> x.parent().isPresent())
.collect(Collectors.groupingBy(x -> x.parent().get()));
// even if one of the resources is allocated to a consumer,
// all unregistrations are regarded as failure
for (Map.Entry<ResourcePath.Discrete, List<ResourcePath>> entry: resourceMap.entrySet()) {
for (Map.Entry<Resource.Discrete, List<Resource>> entry: resourceMap.entrySet()) {
boolean allocated = entry.getValue().stream().anyMatch(x -> {
if (x instanceof ResourcePath.Discrete) {
return discreteConsumerTxMap.get((ResourcePath.Discrete) x) != null;
} else if (x instanceof ResourcePath.Continuous) {
if (x instanceof Resource.Discrete) {
return discreteConsumerTxMap.get((Resource.Discrete) x) != null;
} else if (x instanceof Resource.Continuous) {
ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(x.id());
return allocations != null && !allocations.allocations().isEmpty();
} else {
......@@ -230,38 +230,38 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
}
@Override
public boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer) {
public boolean allocate(List<Resource> resources, ResourceConsumer consumer) {
checkNotNull(resources);
checkNotNull(consumer);
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
TransactionalMap<ResourcePath.Discrete, Set<ResourcePath>> childTxMap =
TransactionalMap<Resource.Discrete, Set<Resource>> childTxMap =
tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
TransactionalMap<ResourcePath.Discrete, ResourceConsumer> discreteConsumerTxMap =
TransactionalMap<Resource.Discrete, ResourceConsumer> discreteConsumerTxMap =
tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
for (ResourcePath resource: resources) {
if (resource instanceof ResourcePath.Discrete) {
for (Resource resource: resources) {
if (resource instanceof Resource.Discrete) {
if (!lookup(childTxMap, resource).isPresent()) {
return abortTransaction(tx);
}
ResourceConsumer oldValue = discreteConsumerTxMap.put((ResourcePath.Discrete) resource, consumer);
ResourceConsumer oldValue = discreteConsumerTxMap.put((Resource.Discrete) resource, consumer);
if (oldValue != null) {
return abortTransaction(tx);
}
} else if (resource instanceof ResourcePath.Continuous) {
Optional<ResourcePath.Continuous> continuous = lookup(childTxMap, (ResourcePath.Continuous) resource);
} else if (resource instanceof Resource.Continuous) {
Optional<Resource.Continuous> continuous = lookup(childTxMap, (Resource.Continuous) resource);
if (!continuous.isPresent()) {
return abortTransaction(tx);
}
ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(continuous.get().id());
if (!hasEnoughResource(continuous.get(), (ResourcePath.Continuous) resource, allocations)) {
if (!hasEnoughResource(continuous.get(), (Resource.Continuous) resource, allocations)) {
return abortTransaction(tx);
}
......@@ -277,7 +277,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
}
@Override
public boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers) {
public boolean release(List<Resource> resources, List<ResourceConsumer> consumers) {
checkNotNull(resources);
checkNotNull(consumers);
checkArgument(resources.size() == consumers.size());
......@@ -285,29 +285,29 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
TransactionContext tx = service.transactionContextBuilder().build();
tx.begin();
TransactionalMap<ResourcePath.Discrete, ResourceConsumer> discreteConsumerTxMap =
TransactionalMap<Resource.Discrete, ResourceConsumer> discreteConsumerTxMap =
tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
Iterator<ResourcePath> resourceIte = resources.iterator();
Iterator<Resource> resourceIte = resources.iterator();
Iterator<ResourceConsumer> consumerIte = consumers.iterator();
while (resourceIte.hasNext() && consumerIte.hasNext()) {
ResourcePath resource = resourceIte.next();
Resource resource = resourceIte.next();
ResourceConsumer consumer = consumerIte.next();
if (resource instanceof ResourcePath.Discrete) {
if (resource instanceof Resource.Discrete) {
// if this single release fails (because the resource is allocated to another consumer,
// the whole release fails
if (!discreteConsumerTxMap.remove((ResourcePath.Discrete) resource, consumer)) {
if (!discreteConsumerTxMap.remove((Resource.Discrete) resource, consumer)) {
return abortTransaction(tx);
}
} else if (resource instanceof ResourcePath.Continuous) {
ResourcePath.Continuous continuous = (ResourcePath.Continuous) resource;
} else if (resource instanceof Resource.Continuous) {
Resource.Continuous continuous = (Resource.Continuous) resource;
ContinuousResourceAllocation allocation = continuousConsumerTxMap.get(continuous.id());
ImmutableList<ResourceAllocation> newAllocations = allocation.allocations().stream()
.filter(x -> !(x.consumer().equals(consumer) &&
((ResourcePath.Continuous) x.resource()).value() == continuous.value()))
((Resource.Continuous) x.resource()).value() == continuous.value()))
.collect(GuavaCollectors.toImmutableList());
if (!continuousConsumerTxMap.replace(continuous.id(), allocation,
......@@ -321,18 +321,18 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
}
@Override
public boolean isAvailable(ResourcePath resource) {
public boolean isAvailable(Resource resource) {
checkNotNull(resource);
checkArgument(resource instanceof ResourcePath.Discrete || resource instanceof ResourcePath.Continuous);
checkArgument(resource instanceof Resource.Discrete || resource instanceof Resource.Continuous);
if (resource instanceof ResourcePath.Discrete) {
return getConsumer((ResourcePath.Discrete) resource).isEmpty();
if (resource instanceof Resource.Discrete) {
return getConsumer((Resource.Discrete) resource).isEmpty();
} else {
return isAvailable((ResourcePath.Continuous) resource);
return isAvailable((Resource.Continuous) resource);
}
}
private boolean isAvailable(ResourcePath.Continuous resource) {
private boolean isAvailable(Resource.Continuous resource) {
Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id());
if (allocation == null) {
return false;
......@@ -342,16 +342,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
}
@Override
public Collection<ResourcePath> getResources(ResourceConsumer consumer) {
public Collection<Resource> getResources(ResourceConsumer consumer) {
checkNotNull(consumer);
// NOTE: getting all entries may become performance bottleneck
// TODO: revisit for better backend data structure
Stream<ResourcePath.Discrete> discreteStream = discreteConsumers.entrySet().stream()
Stream<Resource.Discrete> discreteStream = discreteConsumers.entrySet().stream()
.filter(x -> x.getValue().value().equals(consumer))
.map(Map.Entry::getKey);
Stream<ResourcePath.Continuous> continuousStream = continuousConsumers.values().stream()
Stream<Resource.Continuous> continuousStream = continuousConsumers.values().stream()
.flatMap(x -> x.value().allocations().stream()
.map(y -> Maps.immutableEntry(x.value().original(), y)))
.filter(x -> x.getValue().consumer().equals(consumer))
......@@ -361,11 +361,11 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
}
@Override
public Collection<ResourcePath> getChildResources(ResourcePath parent) {
public Collection<Resource> getChildResources(Resource parent) {
checkNotNull(parent);
checkArgument(parent instanceof ResourcePath.Discrete);
checkArgument(parent instanceof Resource.Discrete);
Versioned<Set<ResourcePath>> children = childMap.get((ResourcePath.Discrete) parent);
Versioned<Set<Resource>> children = childMap.get((Resource.Discrete) parent);
if (children == null) {
return Collections.emptyList();
}
......@@ -374,26 +374,26 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
}
@Override
public <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls) {
public <T> Collection<Resource> getAllocatedResources(Resource parent, Class<T> cls) {
checkNotNull(parent);
checkNotNull(cls);
checkArgument(parent instanceof ResourcePath.Discrete);
checkArgument(parent instanceof Resource.Discrete);
Versioned<Set<ResourcePath>> children = childMap.get((ResourcePath.Discrete) parent);
Versioned<Set<Resource>> children = childMap.get((Resource.Discrete) parent);
if (children == null) {
return Collections.emptyList();
}
Stream<ResourcePath.Discrete> discrete = children.value().stream()
Stream<Resource.Discrete> discrete = children.value().stream()
.filter(x -> x.last().getClass().equals(cls))
.filter(x -> x instanceof ResourcePath.Discrete)
.map(x -> (ResourcePath.Discrete) x)
.filter(x -> x instanceof Resource.Discrete)
.map(x -> (Resource.Discrete) x)
.filter(discreteConsumers::containsKey);
Stream<ResourcePath.Continuous> continuous = children.value().stream()
Stream<Resource.Continuous> continuous = children.value().stream()
.filter(x -> x.last().getClass().equals(cls))
.filter(x -> x instanceof ResourcePath.Continuous)
.map(x -> (ResourcePath.Continuous) x)
.filter(x -> x instanceof Resource.Continuous)
.map(x -> (Resource.Continuous) x)
.filter(x -> continuousConsumers.containsKey(x.id()))
.filter(x -> continuousConsumers.get(x.id()) != null)
.filter(x -> !continuousConsumers.get(x.id()).value().allocations().isEmpty());
......@@ -414,7 +414,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
// Appends the specified ResourceAllocation to the existing values stored in the map
private boolean appendValue(TransactionalMap<ResourceId, ContinuousResourceAllocation> map,
ResourcePath.Continuous original, ResourceAllocation value) {
Resource.Continuous original, ResourceAllocation value) {
ContinuousResourceAllocation oldValue = map.putIfAbsent(original.id(),
new ContinuousResourceAllocation(original, ImmutableList.of(value)));
if (oldValue == null) {
......@@ -496,14 +496,14 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
* @return the resource which is regarded as the same as the specified resource
*/
// Naive implementation, which traverses all elements in the list
private <T extends ResourcePath> Optional<T> lookup(
TransactionalMap<ResourcePath.Discrete, Set<ResourcePath>> map, T resource) {
private <T extends Resource> Optional<T> lookup(
TransactionalMap<Resource.Discrete, Set<Resource>> map, T resource) {
// if it is root, always returns itself
if (!resource.parent().isPresent()) {
return Optional.of(resource);
}
Set<ResourcePath> values = map.get(resource.parent().get());
Set<Resource> values = map.get(resource.parent().get());
if (values == null) {
return Optional.empty();
}
......@@ -525,17 +525,17 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
* @param allocation current allocation of the resource
* @return true if there is enough resource volume. Otherwise, false.
*/
private boolean hasEnoughResource(ResourcePath.Continuous original,
ResourcePath.Continuous request,
private boolean hasEnoughResource(Resource.Continuous original,
Resource.Continuous request,
ContinuousResourceAllocation allocation) {
if (allocation == null) {
return request.value() <= original.value();
}
double allocated = allocation.allocations().stream()
.filter(x -> x.resource() instanceof ResourcePath.Continuous)
.map(x -> (ResourcePath.Continuous) x.resource())
.mapToDouble(ResourcePath.Continuous::value)
.filter(x -> x.resource() instanceof Resource.Continuous)
.map(x -> (Resource.Continuous) x.resource())
.mapToDouble(Resource.Continuous::value)
.sum();
double left = original.value() - allocated;
return request.value() <= left;
......@@ -543,16 +543,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
// internal use only
private static final class ContinuousResourceAllocation {
private final ResourcePath.Continuous original;
private final Resource.Continuous original;
private final ImmutableList<ResourceAllocation> allocations;
private ContinuousResourceAllocation(ResourcePath.Continuous original,
private ContinuousResourceAllocation(Resource.Continuous original,
ImmutableList<ResourceAllocation> allocations) {
this.original = original;
this.allocations = allocations;
}
private ResourcePath.Continuous original() {
private Resource.Continuous original() {
return original;
}
......
......@@ -174,7 +174,7 @@ import org.onosproject.net.link.DefaultLinkDescription;
import org.onosproject.net.meter.MeterId;
import org.onosproject.net.newresource.ResourceAllocation;
import org.onosproject.net.newresource.ResourceId;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.DefaultPacketRequest;
import org.onosproject.net.packet.PacketPriority;
......@@ -433,9 +433,9 @@ public final class KryoNamespaces {
DefaultLinkResourceAllocations.class,
BandwidthResourceAllocation.class,
LambdaResourceAllocation.class,
ResourcePath.class,
ResourcePath.Discrete.class,
ResourcePath.Continuous.class,
Resource.class,
Resource.Discrete.class,
Resource.Continuous.class,
ResourceId.class,
ResourceAllocation.class,
// Constraints
......
......@@ -62,7 +62,7 @@ import org.onosproject.net.flow.FlowId;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleBatchEntry;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.newresource.ResourcePath;
import org.onosproject.net.newresource.Resource;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.link.BandwidthResource;
import org.onosproject.net.resource.link.BandwidthResourceAllocation;
......@@ -374,19 +374,19 @@ public class KryoSerializerTest {
}
@Test
public void testResourcePath() {
testSerializedEquals(ResourcePath.discrete(DID1, P1, VLAN1));
public void testResource() {
testSerializedEquals(Resource.discrete(DID1, P1, VLAN1));
}
@Test
public void testResourceKey() {
testSerializedEquals(ResourcePath.discrete(DID1, P1).id());
testSerializedEquals(Resource.discrete(DID1, P1).id());
}
@Test
public void testResourceAllocation() {
testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation(
ResourcePath.discrete(DID1, P1, VLAN1),
Resource.discrete(DID1, P1, VLAN1),
IntentId.valueOf(30)));
}
......