Sho SHIMIZU
Committed by Gerrit Code Review

Use ResourceId or DiscreteResourceId when specifying a resource

Change-Id: I4e29558ec649510c8d08bb5e5f8ed10c189252e5
...@@ -30,8 +30,8 @@ import org.onosproject.net.OchSignal; ...@@ -30,8 +30,8 @@ import org.onosproject.net.OchSignal;
30 import org.onosproject.net.Port; 30 import org.onosproject.net.Port;
31 import org.onosproject.net.PortNumber; 31 import org.onosproject.net.PortNumber;
32 import org.onosproject.net.device.DeviceService; 32 import org.onosproject.net.device.DeviceService;
33 +import org.onosproject.net.newresource.DiscreteResourceId;
33 import org.onosproject.net.newresource.ResourceAllocation; 34 import org.onosproject.net.newresource.ResourceAllocation;
34 -import org.onosproject.net.newresource.Resource;
35 import org.onosproject.net.newresource.ResourceService; 35 import org.onosproject.net.newresource.ResourceService;
36 36
37 import com.google.common.base.Strings; 37 import com.google.common.base.Strings;
...@@ -107,7 +107,7 @@ public class AllocationsCommand extends AbstractShellCommand { ...@@ -107,7 +107,7 @@ public class AllocationsCommand extends AbstractShellCommand {
107 // TODO: Current design cannot deal with sub-resources 107 // TODO: Current design cannot deal with sub-resources
108 // (e.g., TX/RX under Port) 108 // (e.g., TX/RX under Port)
109 109
110 - Resource resource = Resources.discrete(did, num).resource(); 110 + DiscreteResourceId resource = Resources.discrete(did, num).id();
111 if (lambda) { 111 if (lambda) {
112 //print("Lambda resources:"); 112 //print("Lambda resources:");
113 Collection<ResourceAllocation> allocations 113 Collection<ResourceAllocation> allocations
......
...@@ -34,6 +34,7 @@ import org.onosproject.net.DeviceId; ...@@ -34,6 +34,7 @@ import org.onosproject.net.DeviceId;
34 import org.onosproject.net.PortNumber; 34 import org.onosproject.net.PortNumber;
35 import org.onosproject.net.TributarySlot; 35 import org.onosproject.net.TributarySlot;
36 import org.onosproject.net.newresource.ContinuousResource; 36 import org.onosproject.net.newresource.ContinuousResource;
37 +import org.onosproject.net.newresource.DiscreteResource;
37 import org.onosproject.net.newresource.Resource; 38 import org.onosproject.net.newresource.Resource;
38 import org.onosproject.net.newresource.ResourceService; 39 import org.onosproject.net.newresource.ResourceService;
39 40
...@@ -101,7 +102,13 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -101,7 +102,13 @@ public class ResourcesCommand extends AbstractShellCommand {
101 102
102 private void printResource(Resource resource, int level) { 103 private void printResource(Resource resource, int level) {
103 // TODO add an option to show only available resource 104 // TODO add an option to show only available resource
104 - Set<Resource> children = resourceService.getRegisteredResources(resource); 105 + // workaround to preserve the original behavior of ResourceService#getRegisteredResources
106 + Set<Resource> children;
107 + if (resource instanceof DiscreteResource) {
108 + children = resourceService.getRegisteredResources(((DiscreteResource) resource).id());
109 + } else {
110 + children = Collections.emptySet();
111 + }
105 112
106 if (resource.equals(Resource.ROOT)) { 113 if (resource.equals(Resource.ROOT)) {
107 print("ROOT"); 114 print("ROOT");
......
...@@ -129,24 +129,22 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource ...@@ -129,24 +129,22 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
129 /** 129 /**
130 * Returns resource allocations of the specified resource. 130 * Returns resource allocations of the specified resource.
131 * 131 *
132 - * @param resource resource to check the allocation 132 + * @param id ID of the resource to check the allocation
133 * @return list of allocation information. 133 * @return list of allocation information.
134 * If the resource is not allocated, the return value is an empty list. 134 * If the resource is not allocated, the return value is an empty list.
135 */ 135 */
136 - // TODO: need to change the argument type to ResourceId 136 + List<ResourceAllocation> getResourceAllocations(ResourceId id);
137 - List<ResourceAllocation> getResourceAllocations(Resource resource);
138 137
139 /** 138 /**
140 * Returns allocated resources being as children of the specified parent and being the specified resource type. 139 * Returns allocated resources being as children of the specified parent and being the specified resource type.
141 * 140 *
142 - * @param parent parent resource 141 + * @param parent parent resource ID
143 * @param cls class to specify a type of resource 142 * @param cls class to specify a type of resource
144 * @param <T> type of the resource 143 * @param <T> type of the resource
145 * @return non-empty collection of resource allocations if resources are allocated with the subject and type, 144 * @return non-empty collection of resource allocations if resources are allocated with the subject and type,
146 * empty collection if no resource is allocated with the subject and type 145 * empty collection if no resource is allocated with the subject and type
147 */ 146 */
148 - // TODO: might need to change the first argument type to ResourceId or ResourceId.Discrete 147 + <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls);
149 - <T> Collection<ResourceAllocation> getResourceAllocations(Resource parent, Class<T> cls);
150 148
151 /** 149 /**
152 * Returns resources allocated to the specified consumer. 150 * Returns resources allocated to the specified consumer.
...@@ -159,20 +157,18 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource ...@@ -159,20 +157,18 @@ public interface ResourceService extends ListenerService<ResourceEvent, Resource
159 /** 157 /**
160 * Returns resources that point available child resources under the specified resource. 158 * Returns resources that point available child resources under the specified resource.
161 * 159 *
162 - * @param parent parent resource 160 + * @param parent parent resource ID
163 * @return available resources under the specified resource 161 * @return available resources under the specified resource
164 */ 162 */
165 - // TODO: need to change the argument type to ResourceId or ResourceId.Discrete 163 + Set<Resource> getAvailableResources(DiscreteResourceId parent);
166 - Set<Resource> getAvailableResources(Resource parent);
167 164
168 /** 165 /**
169 * Returns resources registered under the specified resource. 166 * Returns resources registered under the specified resource.
170 * 167 *
171 - * @param parent parent resource 168 + * @param parent parent resource ID
172 * @return registered resources under the specified resource 169 * @return registered resources under the specified resource
173 */ 170 */
174 - // TODO: need to change the argument type to ResourceId or ResourceId.Discrete 171 + Set<Resource> getRegisteredResources(DiscreteResourceId parent);
175 - Set<Resource> getRegisteredResources(Resource parent);
176 172
177 173
178 /** 174 /**
......
...@@ -81,12 +81,11 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat ...@@ -81,12 +81,11 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
81 * The return value is a list having only one element when the given resource is discrete type. 81 * The return value is a list having only one element when the given resource is discrete type.
82 * The return value may have multiple elements when the given resource is continuous type. 82 * The return value may have multiple elements when the given resource is continuous type.
83 * 83 *
84 - * @param resource resource whose allocated consumer to be returned 84 + * @param id ID of the resource whose allocated consumer to be returned
85 * @return resource consumers who are allocated the resource. 85 * @return resource consumers who are allocated the resource.
86 * Returns empty list if there is no such consumer. 86 * Returns empty list if there is no such consumer.
87 */ 87 */
88 - // TODO: need to change the argument type to ResourceId 88 + List<ResourceAllocation> getResourceAllocations(ResourceId id);
89 - List<ResourceConsumer> getConsumers(Resource resource);
90 89
91 /** 90 /**
92 * Returns the availability of the specified resource. 91 * Returns the availability of the specified resource.
...@@ -107,22 +106,20 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat ...@@ -107,22 +106,20 @@ public interface ResourceStore extends Store<ResourceEvent, ResourceStoreDelegat
107 /** 106 /**
108 * Returns a set of the child resources of the specified parent. 107 * Returns a set of the child resources of the specified parent.
109 * 108 *
110 - * @param parent parent of the resource to be returned 109 + * @param parent ID of the parent of the resource to be returned
111 * @return a set of the child resources of the specified resource 110 * @return a set of the child resources of the specified resource
112 */ 111 */
113 - // TODO: need to change the argument type to ResourceId or ResourceId.Discrete 112 + Set<Resource> getChildResources(DiscreteResourceId parent);
114 - Set<Resource> getChildResources(Resource parent);
115 113
116 /** 114 /**
117 * Returns a collection of the resources which are children of the specified parent and 115 * Returns a collection of the resources which are children of the specified parent and
118 * whose type is the specified class. 116 * whose type is the specified class.
119 * 117 *
120 - * @param parent parent of the resources to be returned 118 + * @param parent ID of the parent of the resources to be returned
121 * @param cls class instance of the children 119 * @param cls class instance of the children
122 * @param <T> type of the resource 120 * @param <T> type of the resource
123 * @return a collection of the resources which belongs to the specified subject and 121 * @return a collection of the resources which belongs to the specified subject and
124 * whose type is the specified class. 122 * whose type is the specified class.
125 */ 123 */
126 - // TODO: need to change the argument type to ResourceId or ResourceId.Discrete 124 + <T> Collection<Resource> getAllocatedResources(DiscreteResourceId parent, Class<T> cls);
127 - <T> Collection<Resource> getAllocatedResources(Resource parent, Class<T> cls);
128 } 125 }
......
...@@ -157,7 +157,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { ...@@ -157,7 +157,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
157 } 157 }
158 158
159 private Set<MplsLabel> findMplsLabel(ConnectPoint cp) { 159 private Set<MplsLabel> findMplsLabel(ConnectPoint cp) {
160 - return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).resource()).stream() 160 + return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).id()).stream()
161 .filter(x -> x.last() instanceof MplsLabel) 161 .filter(x -> x.last() instanceof MplsLabel)
162 .map(x -> (MplsLabel) x.last()) 162 .map(x -> (MplsLabel) x.last())
163 .collect(Collectors.toSet()); 163 .collect(Collectors.toSet());
......
...@@ -313,8 +313,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -313,8 +313,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
313 if (ochCP != null) { 313 if (ochCP != null) {
314 OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); 314 OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port());
315 Optional<IntentId> intentId = 315 Optional<IntentId> intentId =
316 - resourceService.getResourceAllocations( 316 + resourceService.getResourceAllocations(Resources.discrete(ochCP.deviceId(), ochCP.port()).id())
317 - Resources.discrete(ochCP.deviceId(), ochCP.port()).resource())
318 .stream() 317 .stream()
319 .map(ResourceAllocation::consumer) 318 .map(ResourceAllocation::consumer)
320 .filter(x -> x instanceof IntentId) 319 .filter(x -> x instanceof IntentId)
...@@ -335,8 +334,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -335,8 +334,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
335 } 334 }
336 335
337 Optional<IntentId> intentId = 336 Optional<IntentId> intentId =
338 - resourceService.getResourceAllocations( 337 + resourceService.getResourceAllocations(Resources.discrete(oduPort.deviceId(), port.number()).id())
339 - Resources.discrete(oduPort.deviceId(), port.number()).resource())
340 .stream() 338 .stream()
341 .map(ResourceAllocation::consumer) 339 .map(ResourceAllocation::consumer)
342 .filter(x -> x instanceof IntentId) 340 .filter(x -> x instanceof IntentId)
......
...@@ -214,8 +214,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -214,8 +214,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
214 private Set<OchSignal> findCommonLambdasOverLinks(List<Link> links) { 214 private Set<OchSignal> findCommonLambdasOverLinks(List<Link> links) {
215 return links.stream() 215 return links.stream()
216 .flatMap(x -> Stream.of( 216 .flatMap(x -> Stream.of(
217 - Resources.discrete(x.src().deviceId(), x.src().port()).resource(), 217 + Resources.discrete(x.src().deviceId(), x.src().port()).id(),
218 - Resources.discrete(x.dst().deviceId(), x.dst().port()).resource() 218 + Resources.discrete(x.dst().deviceId(), x.dst().port()).id()
219 )) 219 ))
220 .map(resourceService::getAvailableResources) 220 .map(resourceService::getAvailableResources)
221 .map(x -> Iterables.filter(x, r -> r.last() instanceof OchSignal)) 221 .map(x -> Iterables.filter(x, r -> r.last() instanceof OchSignal))
......
...@@ -285,7 +285,7 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { ...@@ -285,7 +285,7 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
285 } 285 }
286 286
287 private Set<VlanId> findVlanId(ConnectPoint cp) { 287 private Set<VlanId> findVlanId(ConnectPoint cp) {
288 - return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).resource()).stream() 288 + return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).id()).stream()
289 .filter(x -> x.last() instanceof VlanId) 289 .filter(x -> x.last() instanceof VlanId)
290 .map(x -> (VlanId) x.last()) 290 .map(x -> (VlanId) x.last())
291 .collect(Collectors.toSet()); 291 .collect(Collectors.toSet());
......
...@@ -25,10 +25,12 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -25,10 +25,12 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
25 import org.apache.felix.scr.annotations.Service; 25 import org.apache.felix.scr.annotations.Service;
26 import org.onlab.util.GuavaCollectors; 26 import org.onlab.util.GuavaCollectors;
27 import org.onosproject.event.AbstractListenerManager; 27 import org.onosproject.event.AbstractListenerManager;
28 +import org.onosproject.net.newresource.DiscreteResourceId;
28 import org.onosproject.net.newresource.ResourceAdminService; 29 import org.onosproject.net.newresource.ResourceAdminService;
29 import org.onosproject.net.newresource.ResourceAllocation; 30 import org.onosproject.net.newresource.ResourceAllocation;
30 import org.onosproject.net.newresource.ResourceConsumer; 31 import org.onosproject.net.newresource.ResourceConsumer;
31 import org.onosproject.net.newresource.ResourceEvent; 32 import org.onosproject.net.newresource.ResourceEvent;
33 +import org.onosproject.net.newresource.ResourceId;
32 import org.onosproject.net.newresource.ResourceListener; 34 import org.onosproject.net.newresource.ResourceListener;
33 import org.onosproject.net.newresource.ResourceService; 35 import org.onosproject.net.newresource.ResourceService;
34 import org.onosproject.net.newresource.Resource; 36 import org.onosproject.net.newresource.Resource;
...@@ -115,25 +117,21 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent ...@@ -115,25 +117,21 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
115 } 117 }
116 118
117 @Override 119 @Override
118 - public List<ResourceAllocation> getResourceAllocations(Resource resource) { 120 + public List<ResourceAllocation> getResourceAllocations(ResourceId id) {
119 - checkNotNull(resource); 121 + checkNotNull(id);
120 122
121 - List<ResourceConsumer> consumers = store.getConsumers(resource); 123 + return store.getResourceAllocations(id);
122 - return consumers.stream()
123 - .map(x -> new ResourceAllocation(resource, x))
124 - .collect(GuavaCollectors.toImmutableList());
125 } 124 }
126 125
127 @Override 126 @Override
128 - public <T> Collection<ResourceAllocation> getResourceAllocations(Resource parent, Class<T> cls) { 127 + public <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls) {
129 checkNotNull(parent); 128 checkNotNull(parent);
130 checkNotNull(cls); 129 checkNotNull(cls);
131 130
132 // We access store twice in this method, then the store may be updated by others 131 // We access store twice in this method, then the store may be updated by others
133 Collection<Resource> resources = store.getAllocatedResources(parent, cls); 132 Collection<Resource> resources = store.getAllocatedResources(parent, cls);
134 return resources.stream() 133 return resources.stream()
135 - .flatMap(resource -> store.getConsumers(resource).stream() 134 + .flatMap(resource -> store.getResourceAllocations(resource.id()).stream())
136 - .map(consumer -> new ResourceAllocation(resource, consumer)))
137 .collect(GuavaCollectors.toImmutableList()); 135 .collect(GuavaCollectors.toImmutableList());
138 } 136 }
139 137
...@@ -148,7 +146,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent ...@@ -148,7 +146,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
148 } 146 }
149 147
150 @Override 148 @Override
151 - public Set<Resource> getAvailableResources(Resource parent) { 149 + public Set<Resource> getAvailableResources(DiscreteResourceId parent) {
152 checkNotNull(parent); 150 checkNotNull(parent);
153 151
154 Set<Resource> children = store.getChildResources(parent); 152 Set<Resource> children = store.getChildResources(parent);
...@@ -159,7 +157,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent ...@@ -159,7 +157,7 @@ public final class ResourceManager extends AbstractListenerManager<ResourceEvent
159 } 157 }
160 158
161 @Override 159 @Override
162 - public Set<Resource> getRegisteredResources(Resource parent) { 160 + public Set<Resource> getRegisteredResources(DiscreteResourceId parent) {
163 checkNotNull(parent); 161 checkNotNull(parent);
164 162
165 return store.getChildResources(parent); 163 return store.getChildResources(parent);
......
...@@ -19,11 +19,16 @@ import com.google.common.collect.ImmutableList; ...@@ -19,11 +19,16 @@ import com.google.common.collect.ImmutableList;
19 import com.google.common.collect.ImmutableSet; 19 import com.google.common.collect.ImmutableSet;
20 import org.onlab.packet.MplsLabel; 20 import org.onlab.packet.MplsLabel;
21 import org.onlab.packet.VlanId; 21 import org.onlab.packet.VlanId;
22 +import org.onosproject.net.newresource.ContinuousResourceId;
23 +import org.onosproject.net.newresource.DiscreteResource;
24 +import org.onosproject.net.newresource.DiscreteResourceId;
22 import org.onosproject.net.newresource.ResourceAllocation; 25 import org.onosproject.net.newresource.ResourceAllocation;
23 import org.onosproject.net.newresource.ResourceConsumer; 26 import org.onosproject.net.newresource.ResourceConsumer;
27 +import org.onosproject.net.newresource.ResourceId;
24 import org.onosproject.net.newresource.ResourceListener; 28 import org.onosproject.net.newresource.ResourceListener;
25 import org.onosproject.net.newresource.Resource; 29 import org.onosproject.net.newresource.Resource;
26 import org.onosproject.net.newresource.ResourceService; 30 import org.onosproject.net.newresource.ResourceService;
31 +import org.onosproject.net.newresource.Resources;
27 32
28 import java.util.Collection; 33 import java.util.Collection;
29 import java.util.HashMap; 34 import java.util.HashMap;
...@@ -70,17 +75,21 @@ class MockResourceService implements ResourceService { ...@@ -70,17 +75,21 @@ class MockResourceService implements ResourceService {
70 } 75 }
71 76
72 @Override 77 @Override
73 - public List<ResourceAllocation> getResourceAllocations(Resource resource) { 78 + public List<ResourceAllocation> getResourceAllocations(ResourceId id) {
74 - return Optional.ofNullable(assignment.get(resource)) 79 + if (id instanceof ContinuousResourceId) {
75 - .map(x -> ImmutableList.of(new ResourceAllocation(resource, x))) 80 + return ImmutableList.of();
81 + }
82 + DiscreteResource discrete = Resources.discrete((DiscreteResourceId) id).resource();
83 + return Optional.ofNullable(assignment.get(discrete))
84 + .map(x -> ImmutableList.of(new ResourceAllocation(discrete, x)))
76 .orElse(ImmutableList.of()); 85 .orElse(ImmutableList.of());
77 } 86 }
78 87
79 @Override 88 @Override
80 - public <T> Collection<ResourceAllocation> getResourceAllocations(Resource parent, Class<T> cls) { 89 + public <T> Collection<ResourceAllocation> getResourceAllocations(DiscreteResourceId parent, Class<T> cls) {
81 return assignment.entrySet().stream() 90 return assignment.entrySet().stream()
82 .filter(x -> x.getKey().parent().isPresent()) 91 .filter(x -> x.getKey().parent().isPresent())
83 - .filter(x -> x.getKey().parent().get().equals(parent)) 92 + .filter(x -> x.getKey().parent().get().id().equals(parent))
84 .map(x -> new ResourceAllocation(x.getKey(), x.getValue())) 93 .map(x -> new ResourceAllocation(x.getKey(), x.getValue()))
85 .collect(Collectors.toList()); 94 .collect(Collectors.toList());
86 } 95 }
...@@ -94,16 +103,15 @@ class MockResourceService implements ResourceService { ...@@ -94,16 +103,15 @@ class MockResourceService implements ResourceService {
94 } 103 }
95 104
96 @Override 105 @Override
97 - public Set<Resource> getAvailableResources(Resource parent) { 106 + public Set<Resource> getAvailableResources(DiscreteResourceId parent) {
98 - 107 + Collection<Resource> resources = new HashSet<>();
99 - Collection<Resource> resources = new HashSet<Resource>(); 108 + resources.add(Resources.discrete(parent).resource().child(VlanId.vlanId((short) 10)));
100 - resources.add(parent.child(VlanId.vlanId((short) 10))); 109 + resources.add(Resources.discrete(parent).resource().child(MplsLabel.mplsLabel(10)));
101 - resources.add(parent.child(MplsLabel.mplsLabel(10)));
102 return ImmutableSet.copyOf(resources); 110 return ImmutableSet.copyOf(resources);
103 } 111 }
104 112
105 @Override 113 @Override
106 - public Set<Resource> getRegisteredResources(Resource parent) { 114 + public Set<Resource> getRegisteredResources(DiscreteResourceId parent) {
107 return getAvailableResources(parent); 115 return getAvailableResources(parent);
108 } 116 }
109 117
......
...@@ -27,7 +27,9 @@ import org.apache.felix.scr.annotations.Service; ...@@ -27,7 +27,9 @@ import org.apache.felix.scr.annotations.Service;
27 import org.onlab.util.GuavaCollectors; 27 import org.onlab.util.GuavaCollectors;
28 import org.onlab.util.Tools; 28 import org.onlab.util.Tools;
29 import org.onosproject.net.newresource.ContinuousResource; 29 import org.onosproject.net.newresource.ContinuousResource;
30 +import org.onosproject.net.newresource.ContinuousResourceId;
30 import org.onosproject.net.newresource.DiscreteResource; 31 import org.onosproject.net.newresource.DiscreteResource;
32 +import org.onosproject.net.newresource.DiscreteResourceId;
31 import org.onosproject.net.newresource.ResourceAllocation; 33 import org.onosproject.net.newresource.ResourceAllocation;
32 import org.onosproject.net.newresource.ResourceConsumer; 34 import org.onosproject.net.newresource.ResourceConsumer;
33 import org.onosproject.net.newresource.ResourceEvent; 35 import org.onosproject.net.newresource.ResourceEvent;
...@@ -35,6 +37,7 @@ import org.onosproject.net.newresource.ResourceId; ...@@ -35,6 +37,7 @@ import org.onosproject.net.newresource.ResourceId;
35 import org.onosproject.net.newresource.Resource; 37 import org.onosproject.net.newresource.Resource;
36 import org.onosproject.net.newresource.ResourceStore; 38 import org.onosproject.net.newresource.ResourceStore;
37 import org.onosproject.net.newresource.ResourceStoreDelegate; 39 import org.onosproject.net.newresource.ResourceStoreDelegate;
40 +import org.onosproject.net.newresource.Resources;
38 import org.onosproject.store.AbstractStore; 41 import org.onosproject.store.AbstractStore;
39 import org.onosproject.store.serializers.KryoNamespaces; 42 import org.onosproject.store.serializers.KryoNamespaces;
40 import org.onosproject.store.service.ConsistentMap; 43 import org.onosproject.store.service.ConsistentMap;
...@@ -86,60 +89,63 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -86,60 +89,63 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 89 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
87 protected StorageService service; 90 protected StorageService service;
88 91
89 - private ConsistentMap<DiscreteResource, ResourceConsumer> discreteConsumers; 92 + private ConsistentMap<DiscreteResourceId, ResourceConsumer> discreteConsumers;
90 - private ConsistentMap<ResourceId, ContinuousResourceAllocation> continuousConsumers; 93 + private ConsistentMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumers;
91 - private ConsistentMap<DiscreteResource, Set<Resource>> childMap; 94 + private ConsistentMap<DiscreteResourceId, Set<Resource>> childMap;
92 95
93 @Activate 96 @Activate
94 public void activate() { 97 public void activate() {
95 - discreteConsumers = service.<DiscreteResource, ResourceConsumer>consistentMapBuilder() 98 + discreteConsumers = service.<DiscreteResourceId, ResourceConsumer>consistentMapBuilder()
96 .withName(DISCRETE_CONSUMER_MAP) 99 .withName(DISCRETE_CONSUMER_MAP)
97 .withSerializer(SERIALIZER) 100 .withSerializer(SERIALIZER)
98 .build(); 101 .build();
99 - continuousConsumers = service.<ResourceId, ContinuousResourceAllocation>consistentMapBuilder() 102 + continuousConsumers = service.<ContinuousResourceId, ContinuousResourceAllocation>consistentMapBuilder()
100 .withName(CONTINUOUS_CONSUMER_MAP) 103 .withName(CONTINUOUS_CONSUMER_MAP)
101 .withSerializer(SERIALIZER) 104 .withSerializer(SERIALIZER)
102 .build(); 105 .build();
103 - childMap = service.<DiscreteResource, Set<Resource>>consistentMapBuilder() 106 + childMap = service.<DiscreteResourceId, Set<Resource>>consistentMapBuilder()
104 .withName(CHILD_MAP) 107 .withName(CHILD_MAP)
105 .withSerializer(SERIALIZER) 108 .withSerializer(SERIALIZER)
106 .build(); 109 .build();
107 110
108 - Tools.retryable(() -> childMap.put(Resource.ROOT, new LinkedHashSet<>()), 111 + Tools.retryable(() -> childMap.put(Resource.ROOT.id(), new LinkedHashSet<>()),
109 ConsistentMapException.class, MAX_RETRIES, RETRY_DELAY); 112 ConsistentMapException.class, MAX_RETRIES, RETRY_DELAY);
110 log.info("Started"); 113 log.info("Started");
111 } 114 }
112 115
116 + // Computational complexity: O(1) if the resource is discrete type.
117 + // O(n) if the resource is continuous type where n is the number of the existing allocations for the resource
113 @Override 118 @Override
114 - public List<ResourceConsumer> getConsumers(Resource resource) { 119 + public List<ResourceAllocation> getResourceAllocations(ResourceId id) {
115 - checkNotNull(resource); 120 + checkNotNull(id);
116 - checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource); 121 + checkArgument(id instanceof DiscreteResourceId || id instanceof ContinuousResourceId);
117 122
118 - if (resource instanceof DiscreteResource) { 123 + if (id instanceof DiscreteResourceId) {
119 - return getConsumers((DiscreteResource) resource); 124 + return getResourceAllocations((DiscreteResourceId) id);
120 } else { 125 } else {
121 - return getConsumers((ContinuousResource) resource); 126 + return getResourceAllocations((ContinuousResourceId) id);
122 } 127 }
123 } 128 }
124 129
125 - private List<ResourceConsumer> getConsumers(DiscreteResource resource) { 130 + // computational complexity: O(1)
131 + private List<ResourceAllocation> getResourceAllocations(DiscreteResourceId resource) {
126 Versioned<ResourceConsumer> consumer = discreteConsumers.get(resource); 132 Versioned<ResourceConsumer> consumer = discreteConsumers.get(resource);
127 if (consumer == null) { 133 if (consumer == null) {
128 return ImmutableList.of(); 134 return ImmutableList.of();
129 } 135 }
130 136
131 - return ImmutableList.of(consumer.value()); 137 + return ImmutableList.of(new ResourceAllocation(Resources.discrete(resource).resource(), consumer.value()));
132 } 138 }
133 139
134 - private List<ResourceConsumer> getConsumers(ContinuousResource resource) { 140 + // computational complexity: O(n) where n is the number of the existing allocations for the resource
135 - Versioned<ContinuousResourceAllocation> allocations = continuousConsumers.get(resource.id()); 141 + private List<ResourceAllocation> getResourceAllocations(ContinuousResourceId resource) {
142 + Versioned<ContinuousResourceAllocation> allocations = continuousConsumers.get(resource);
136 if (allocations == null) { 143 if (allocations == null) {
137 return ImmutableList.of(); 144 return ImmutableList.of();
138 } 145 }
139 146
140 return allocations.value().allocations().stream() 147 return allocations.value().allocations().stream()
141 - .filter(x -> x.resource().equals(resource)) 148 + .filter(x -> x.resource().id().equals(resource))
142 - .map(ResourceAllocation::consumer)
143 .collect(GuavaCollectors.toImmutableList()); 149 .collect(GuavaCollectors.toImmutableList());
144 } 150 }
145 151
...@@ -153,7 +159,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -153,7 +159,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
153 TransactionContext tx = service.transactionContextBuilder().build(); 159 TransactionContext tx = service.transactionContextBuilder().build();
154 tx.begin(); 160 tx.begin();
155 161
156 - TransactionalMap<DiscreteResource, Set<Resource>> childTxMap = 162 + TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap =
157 tx.getTransactionalMap(CHILD_MAP, SERIALIZER); 163 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
158 164
159 Map<DiscreteResource, List<Resource>> resourceMap = resources.stream() 165 Map<DiscreteResource, List<Resource>> resourceMap = resources.stream()
...@@ -166,7 +172,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -166,7 +172,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
166 return abortTransaction(tx); 172 return abortTransaction(tx);
167 } 173 }
168 174
169 - if (!appendValues(childTxMap, entry.getKey(), entry.getValue())) { 175 + if (!appendValues(childTxMap, entry.getKey().id(), entry.getValue())) {
170 return abortTransaction(tx); 176 return abortTransaction(tx);
171 } 177 }
172 } 178 }
...@@ -189,26 +195,27 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -189,26 +195,27 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
189 TransactionContext tx = service.transactionContextBuilder().build(); 195 TransactionContext tx = service.transactionContextBuilder().build();
190 tx.begin(); 196 tx.begin();
191 197
192 - TransactionalMap<DiscreteResource, Set<Resource>> childTxMap = 198 + TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap =
193 tx.getTransactionalMap(CHILD_MAP, SERIALIZER); 199 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
194 - TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap = 200 + TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
195 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER); 201 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
196 - TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap = 202 + TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
197 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER); 203 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
198 204
199 // Extract Discrete instances from resources 205 // Extract Discrete instances from resources
200 - Map<DiscreteResource, List<Resource>> resourceMap = resources.stream() 206 + Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream()
201 .filter(x -> x.parent().isPresent()) 207 .filter(x -> x.parent().isPresent())
202 - .collect(Collectors.groupingBy(x -> x.parent().get())); 208 + .collect(Collectors.groupingBy(x -> x.parent().get().id()));
203 209
204 // even if one of the resources is allocated to a consumer, 210 // even if one of the resources is allocated to a consumer,
205 // all unregistrations are regarded as failure 211 // all unregistrations are regarded as failure
206 - for (Map.Entry<DiscreteResource, List<Resource>> entry: resourceMap.entrySet()) { 212 + for (Map.Entry<DiscreteResourceId, List<Resource>> entry: resourceMap.entrySet()) {
207 boolean allocated = entry.getValue().stream().anyMatch(x -> { 213 boolean allocated = entry.getValue().stream().anyMatch(x -> {
208 if (x instanceof DiscreteResource) { 214 if (x instanceof DiscreteResource) {
209 - return discreteConsumerTxMap.get((DiscreteResource) x) != null; 215 + return discreteConsumerTxMap.get(((DiscreteResource) x).id()) != null;
210 } else if (x instanceof ContinuousResource) { 216 } else if (x instanceof ContinuousResource) {
211 - ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(x.id()); 217 + ContinuousResourceAllocation allocations =
218 + continuousConsumerTxMap.get(((ContinuousResource) x).id());
212 return allocations != null && !allocations.allocations().isEmpty(); 219 return allocations != null && !allocations.allocations().isEmpty();
213 } else { 220 } else {
214 return false; 221 return false;
...@@ -247,11 +254,11 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -247,11 +254,11 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
247 TransactionContext tx = service.transactionContextBuilder().build(); 254 TransactionContext tx = service.transactionContextBuilder().build();
248 tx.begin(); 255 tx.begin();
249 256
250 - TransactionalMap<DiscreteResource, Set<Resource>> childTxMap = 257 + TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap =
251 tx.getTransactionalMap(CHILD_MAP, SERIALIZER); 258 tx.getTransactionalMap(CHILD_MAP, SERIALIZER);
252 - TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap = 259 + TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
253 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER); 260 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
254 - TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap = 261 + TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
255 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER); 262 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
256 263
257 for (Resource resource: resources) { 264 for (Resource resource: resources) {
...@@ -260,7 +267,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -260,7 +267,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
260 return abortTransaction(tx); 267 return abortTransaction(tx);
261 } 268 }
262 269
263 - ResourceConsumer oldValue = discreteConsumerTxMap.put((DiscreteResource) resource, consumer); 270 + ResourceConsumer oldValue = discreteConsumerTxMap.put(((DiscreteResource) resource).id(), consumer);
264 if (oldValue != null) { 271 if (oldValue != null) {
265 return abortTransaction(tx); 272 return abortTransaction(tx);
266 } 273 }
...@@ -295,9 +302,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -295,9 +302,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
295 TransactionContext tx = service.transactionContextBuilder().build(); 302 TransactionContext tx = service.transactionContextBuilder().build();
296 tx.begin(); 303 tx.begin();
297 304
298 - TransactionalMap<DiscreteResource, ResourceConsumer> discreteConsumerTxMap = 305 + TransactionalMap<DiscreteResourceId, ResourceConsumer> discreteConsumerTxMap =
299 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER); 306 tx.getTransactionalMap(DISCRETE_CONSUMER_MAP, SERIALIZER);
300 - TransactionalMap<ResourceId, ContinuousResourceAllocation> continuousConsumerTxMap = 307 + TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
301 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER); 308 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
302 Iterator<Resource> resourceIte = resources.iterator(); 309 Iterator<Resource> resourceIte = resources.iterator();
303 Iterator<ResourceConsumer> consumerIte = consumers.iterator(); 310 Iterator<ResourceConsumer> consumerIte = consumers.iterator();
...@@ -309,7 +316,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -309,7 +316,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
309 if (resource instanceof DiscreteResource) { 316 if (resource instanceof DiscreteResource) {
310 // if this single release fails (because the resource is allocated to another consumer, 317 // if this single release fails (because the resource is allocated to another consumer,
311 // the whole release fails 318 // the whole release fails
312 - if (!discreteConsumerTxMap.remove((DiscreteResource) resource, consumer)) { 319 + if (!discreteConsumerTxMap.remove(((DiscreteResource) resource).id(), consumer)) {
313 return abortTransaction(tx); 320 return abortTransaction(tx);
314 } 321 }
315 } else if (resource instanceof ContinuousResource) { 322 } else if (resource instanceof ContinuousResource) {
...@@ -330,20 +337,23 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -330,20 +337,23 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
330 return tx.commit(); 337 return tx.commit();
331 } 338 }
332 339
340 + // computational complexity: O(1) if the resource is discrete type.
341 + // O(n) if the resource is continuous type where n is the number of the children of
342 + // the specified resource's parent
333 @Override 343 @Override
334 public boolean isAvailable(Resource resource) { 344 public boolean isAvailable(Resource resource) {
335 checkNotNull(resource); 345 checkNotNull(resource);
336 checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource); 346 checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource);
337 347
338 // check if it's registered or not. 348 // check if it's registered or not.
339 - Versioned<Set<Resource>> v = childMap.get(resource.parent().get()); 349 + Versioned<Set<Resource>> v = childMap.get(resource.parent().get().id());
340 if (v == null || !v.value().contains(resource)) { 350 if (v == null || !v.value().contains(resource)) {
341 return false; 351 return false;
342 } 352 }
343 353
344 if (resource instanceof DiscreteResource) { 354 if (resource instanceof DiscreteResource) {
345 // check if already consumed 355 // check if already consumed
346 - return getConsumers((DiscreteResource) resource).isEmpty(); 356 + return getResourceAllocations(resource.id()).isEmpty();
347 } else { 357 } else {
348 ContinuousResource requested = (ContinuousResource) resource; 358 ContinuousResource requested = (ContinuousResource) resource;
349 ContinuousResource registered = v.value().stream() 359 ContinuousResource registered = v.value().stream()
...@@ -360,6 +370,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -360,6 +370,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
360 } 370 }
361 } 371 }
362 372
373 + // computational complexity: O(n) where n is the number of existing allocations for the resource
363 private boolean isAvailable(ContinuousResource resource) { 374 private boolean isAvailable(ContinuousResource resource) {
364 Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id()); 375 Versioned<ContinuousResourceAllocation> allocation = continuousConsumers.get(resource.id());
365 if (allocation == null) { 376 if (allocation == null) {
...@@ -370,6 +381,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -370,6 +381,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
370 return hasEnoughResource(allocation.value().original(), resource, allocation.value()); 381 return hasEnoughResource(allocation.value().original(), resource, allocation.value());
371 } 382 }
372 383
384 + // computational complexity: O(n + m) where n is the number of entries in discreteConsumers
385 + // and m is the number of allocations for all continuous resources
373 @Override 386 @Override
374 public Collection<Resource> getResources(ResourceConsumer consumer) { 387 public Collection<Resource> getResources(ResourceConsumer consumer) {
375 checkNotNull(consumer); 388 checkNotNull(consumer);
...@@ -378,7 +391,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -378,7 +391,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
378 // TODO: revisit for better backend data structure 391 // TODO: revisit for better backend data structure
379 Stream<DiscreteResource> discreteStream = discreteConsumers.entrySet().stream() 392 Stream<DiscreteResource> discreteStream = discreteConsumers.entrySet().stream()
380 .filter(x -> x.getValue().value().equals(consumer)) 393 .filter(x -> x.getValue().value().equals(consumer))
381 - .map(Map.Entry::getKey); 394 + .map(Map.Entry::getKey)
395 + .map(x -> Resources.discrete(x).resource());
382 396
383 Stream<ContinuousResource> continuousStream = continuousConsumers.values().stream() 397 Stream<ContinuousResource> continuousStream = continuousConsumers.values().stream()
384 .flatMap(x -> x.value().allocations().stream() 398 .flatMap(x -> x.value().allocations().stream()
...@@ -389,15 +403,12 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -389,15 +403,12 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
389 return Stream.concat(discreteStream, continuousStream).collect(Collectors.toList()); 403 return Stream.concat(discreteStream, continuousStream).collect(Collectors.toList());
390 } 404 }
391 405
406 + // computational complexity: O(n)
392 @Override 407 @Override
393 - public Set<Resource> getChildResources(Resource parent) { 408 + public Set<Resource> getChildResources(DiscreteResourceId parent) {
394 checkNotNull(parent); 409 checkNotNull(parent);
395 - if (!(parent instanceof DiscreteResource)) {
396 - // only Discrete resource can have child resource
397 - return ImmutableSet.of();
398 - }
399 410
400 - Versioned<Set<Resource>> children = childMap.get((DiscreteResource) parent); 411 + Versioned<Set<Resource>> children = childMap.get(parent);
401 if (children == null) { 412 if (children == null) {
402 return ImmutableSet.of(); 413 return ImmutableSet.of();
403 } 414 }
...@@ -405,13 +416,13 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -405,13 +416,13 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
405 return children.value(); 416 return children.value();
406 } 417 }
407 418
419 + // computational complexity: O(n) where n is the number of the children of the parent
408 @Override 420 @Override
409 - public <T> Collection<Resource> getAllocatedResources(Resource parent, Class<T> cls) { 421 + public <T> Collection<Resource> getAllocatedResources(DiscreteResourceId parent, Class<T> cls) {
410 checkNotNull(parent); 422 checkNotNull(parent);
411 checkNotNull(cls); 423 checkNotNull(cls);
412 - checkArgument(parent instanceof DiscreteResource);
413 424
414 - Versioned<Set<Resource>> children = childMap.get((DiscreteResource) parent); 425 + Versioned<Set<Resource>> children = childMap.get(parent);
415 if (children == null) { 426 if (children == null) {
416 return ImmutableList.of(); 427 return ImmutableList.of();
417 } 428 }
...@@ -419,11 +430,11 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -419,11 +430,11 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
419 Stream<DiscreteResource> discrete = children.value().stream() 430 Stream<DiscreteResource> discrete = children.value().stream()
420 .filter(x -> x.last().getClass().equals(cls)) 431 .filter(x -> x.last().getClass().equals(cls))
421 .filter(x -> x instanceof DiscreteResource) 432 .filter(x -> x instanceof DiscreteResource)
422 - .map(x -> (DiscreteResource) x) 433 + .map(x -> ((DiscreteResource) x))
423 - .filter(discreteConsumers::containsKey); 434 + .filter(x -> discreteConsumers.containsKey(x.id()));
424 435
425 Stream<ContinuousResource> continuous = children.value().stream() 436 Stream<ContinuousResource> continuous = children.value().stream()
426 - .filter(x -> x.id().equals(parent.id().child(cls))) 437 + .filter(x -> x.id().equals(parent.child(cls)))
427 .filter(x -> x instanceof ContinuousResource) 438 .filter(x -> x instanceof ContinuousResource)
428 .map(x -> (ContinuousResource) x) 439 .map(x -> (ContinuousResource) x)
429 .filter(x -> continuousConsumers.containsKey(x.id())) 440 .filter(x -> continuousConsumers.containsKey(x.id()))
...@@ -445,7 +456,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -445,7 +456,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
445 } 456 }
446 457
447 // Appends the specified ResourceAllocation to the existing values stored in the map 458 // Appends the specified ResourceAllocation to the existing values stored in the map
448 - private boolean appendValue(TransactionalMap<ResourceId, ContinuousResourceAllocation> map, 459 + // computational complexity: O(n) where n is the number of the elements in the associated allocation
460 + private boolean appendValue(TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> map,
449 ContinuousResource original, ResourceAllocation value) { 461 ContinuousResource original, ResourceAllocation value) {
450 ContinuousResourceAllocation oldValue = map.putIfAbsent(original.id(), 462 ContinuousResourceAllocation oldValue = map.putIfAbsent(original.id(),
451 new ContinuousResourceAllocation(original, ImmutableList.of(value))); 463 new ContinuousResourceAllocation(original, ImmutableList.of(value)));
...@@ -474,8 +486,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -474,8 +486,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
474 * @param values values to be appended 486 * @param values values to be appended
475 * @return true if the operation succeeds, false otherwise. 487 * @return true if the operation succeeds, false otherwise.
476 */ 488 */
477 - private boolean appendValues(TransactionalMap<DiscreteResource, Set<Resource>> map, 489 + // computational complexity: O(n) where n is the number of the specified value
478 - DiscreteResource key, List<Resource> values) { 490 + private boolean appendValues(TransactionalMap<DiscreteResourceId, Set<Resource>> map,
491 + DiscreteResourceId key, List<Resource> values) {
479 Set<Resource> oldValues = map.putIfAbsent(key, new LinkedHashSet<>(values)); 492 Set<Resource> oldValues = map.putIfAbsent(key, new LinkedHashSet<>(values));
480 if (oldValues == null) { 493 if (oldValues == null) {
481 return true; 494 return true;
...@@ -500,8 +513,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -500,8 +513,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
500 * @param values values to be removed 513 * @param values values to be removed
501 * @return true if the operation succeeds, false otherwise 514 * @return true if the operation succeeds, false otherwise
502 */ 515 */
503 - private boolean removeValues(TransactionalMap<DiscreteResource, Set<Resource>> map, 516 + // computational complexity: O(n) where n is the number of the specified values
504 - DiscreteResource key, List<Resource> values) { 517 + private boolean removeValues(TransactionalMap<DiscreteResourceId, Set<Resource>> map,
518 + DiscreteResourceId key, List<Resource> values) {
505 Set<Resource> oldValues = map.putIfAbsent(key, new LinkedHashSet<>()); 519 Set<Resource> oldValues = map.putIfAbsent(key, new LinkedHashSet<>());
506 if (oldValues == null) { 520 if (oldValues == null) {
507 log.trace("No-Op removing values. key {} did not exist", key); 521 log.trace("No-Op removing values. key {} did not exist", key);
...@@ -528,14 +542,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -528,14 +542,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
528 * @return the resource which is regarded as the same as the specified resource 542 * @return the resource which is regarded as the same as the specified resource
529 */ 543 */
530 // Naive implementation, which traverses all elements in the list 544 // Naive implementation, which traverses all elements in the list
545 + // computational complexity: O(n) where n is the number of elements
546 + // in the associated set
531 private <T extends Resource> Optional<T> lookup( 547 private <T extends Resource> Optional<T> lookup(
532 - TransactionalMap<DiscreteResource, Set<Resource>> map, T resource) { 548 + TransactionalMap<DiscreteResourceId, Set<Resource>> map, T resource) {
533 // if it is root, always returns itself 549 // if it is root, always returns itself
534 if (!resource.parent().isPresent()) { 550 if (!resource.parent().isPresent()) {
535 return Optional.of(resource); 551 return Optional.of(resource);
536 } 552 }
537 553
538 - Set<Resource> values = map.get(resource.parent().get()); 554 + Set<Resource> values = map.get(resource.parent().get().id());
539 if (values == null) { 555 if (values == null) {
540 return Optional.empty(); 556 return Optional.empty();
541 } 557 }
...@@ -557,6 +573,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -557,6 +573,7 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
557 * @param allocation current allocation of the resource 573 * @param allocation current allocation of the resource
558 * @return true if there is enough resource volume. Otherwise, false. 574 * @return true if there is enough resource volume. Otherwise, false.
559 */ 575 */
576 + // computational complexity: O(n) where n is the number of allocations
560 private boolean hasEnoughResource(ContinuousResource original, 577 private boolean hasEnoughResource(ContinuousResource original,
561 ContinuousResource request, 578 ContinuousResource request,
562 ContinuousResourceAllocation allocation) { 579 ContinuousResourceAllocation allocation) {
......