Sho SHIMIZU
Committed by Gerrit Code Review

Resource API changes as preparation for hierarchy support (ONOS-2446)

The changes:
- Introduce ResourcePath to point a resource
- Remove Resource interface
- Make ResourceAllocation concrete class and remove DefaultResourceAllocation
- Remove DefaultResource
- Changes in interfaces due to the above changes

Change-Id: I0f3f846be67b0f7917117943aac31e3099c851ec
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.newresource;
17 -
18 -import com.google.common.annotations.Beta;
19 -
20 -import java.util.Objects;
21 -
22 -import static com.google.common.base.Preconditions.checkNotNull;
23 -
24 -/**
25 - * Default implementation of a class representing resource which belongs to a particular subject.
26 - *
27 - * @param <S> type of the subject
28 - * @param <T> type of the resource
29 - */
30 -@Beta
31 -public class DefaultResource<S, T> implements Resource<S, T> {
32 -
33 - private final S subject;
34 - private final T resource;
35 -
36 - /**
37 - * Creates a resource with the specified subject and resource.
38 - *
39 - * @param subject identifier which this resource belongs to
40 - * @param resource resource of the subject
41 - */
42 - public DefaultResource(S subject, T resource) {
43 - this.subject = checkNotNull(subject);
44 - this.resource = checkNotNull(resource);
45 - }
46 -
47 - // for serialization
48 - private DefaultResource() {
49 - this.subject = null;
50 - this.resource = null;
51 - }
52 -
53 - @Override
54 - public S subject() {
55 - return subject;
56 - }
57 -
58 - @Override
59 - public T resource() {
60 - return resource;
61 - }
62 -
63 - @Override
64 - public int hashCode() {
65 - return Objects.hash(subject, resource);
66 - }
67 -
68 - @Override
69 - public boolean equals(Object obj) {
70 - if (this == obj) {
71 - return true;
72 - }
73 - if (!(obj instanceof DefaultResource)) {
74 - return false;
75 - }
76 - final DefaultResource that = (DefaultResource) obj;
77 - return Objects.equals(this.subject, that.subject)
78 - && Objects.equals(this.resource, that.resource);
79 - }
80 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.newresource;
17 -
18 -import com.google.common.annotations.Beta;
19 -
20 -import java.util.Objects;
21 -
22 -import static com.google.common.base.Preconditions.checkNotNull;
23 -
24 -/**
25 - * Default implementation of a class representing allocation of resource which belongs to a particular subject.
26 - *
27 - * @param <S> type of the subject
28 - * @param <T> type of the resource
29 - */
30 -@Beta
31 -public class DefaultResourceAllocation<S, T> implements ResourceAllocation<S, T> {
32 -
33 - private final S subject;
34 - private final T resource;
35 - private final ResourceConsumer consumer;
36 -
37 - /**
38 - * Creates an instance with the specified subject, resource and consumer.
39 - *
40 - * @param subject identifier which this resource belongs to
41 - * @param resource resource of the subject
42 - * @param consumer consumer ot this resource
43 - */
44 - public DefaultResourceAllocation(S subject, T resource, ResourceConsumer consumer) {
45 - this.subject = checkNotNull(subject);
46 - this.resource = checkNotNull(resource);
47 - this.consumer = consumer;
48 - }
49 -
50 - // for serialization
51 - private DefaultResourceAllocation() {
52 - this.subject = null;
53 - this.resource = null;
54 - this.consumer = null;
55 - }
56 -
57 - @Override
58 - public S subject() {
59 - return subject;
60 - }
61 -
62 - @Override
63 - public T resource() {
64 - return resource;
65 - }
66 -
67 - @Override
68 - public ResourceConsumer consumer() {
69 - return consumer;
70 - }
71 -
72 - @Override
73 - public int hashCode() {
74 - return Objects.hash(subject, resource, consumer);
75 - }
76 -
77 - @Override
78 - public boolean equals(Object obj) {
79 - if (this == obj) {
80 - return true;
81 - }
82 - if (!(obj instanceof DefaultResourceAllocation)) {
83 - return false;
84 - }
85 - final DefaultResourceAllocation that = (DefaultResourceAllocation) obj;
86 - return Objects.equals(this.subject, that.subject)
87 - && Objects.equals(this.resource, that.resource)
88 - && Objects.equals(this.consumer, that.consumer);
89 - }
90 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.newresource;
17 -
18 -import com.google.common.annotations.Beta;
19 -
20 -/**
21 - * Represents resource which belongs to a particular subject.
22 - *
23 - * @param <S> type of the subject
24 - * @param <T> type of the resource
25 - */
26 -@Beta
27 -public interface Resource<S, T> {
28 - /**
29 - * Returns the subject of the resource.
30 - * The value is the identifier which this resource belongs to.
31 - *
32 - * @return the subject of the resource
33 - */
34 - S subject();
35 -
36 - /**
37 - * Returns the resource of the subject.
38 - *
39 - * @return the resource of the subject
40 - */
41 - T resource();
42 -}
...@@ -16,34 +16,79 @@ ...@@ -16,34 +16,79 @@
16 package org.onosproject.net.newresource; 16 package org.onosproject.net.newresource;
17 17
18 import com.google.common.annotations.Beta; 18 import com.google.common.annotations.Beta;
19 +import com.google.common.base.MoreObjects;
20 +
21 +import java.util.Objects;
22 +
23 +import static com.google.common.base.Preconditions.checkNotNull;
19 24
20 /** 25 /**
21 - * Represents allocation of resource which belongs to a particular subject. 26 + * Represents allocation of resource which is identified by the specifier.
22 - *
23 - * @param <S> type of the subject
24 - * @param <T> type of the resource
25 */ 27 */
26 @Beta 28 @Beta
27 -public interface ResourceAllocation<S, T> { 29 +public class ResourceAllocation {
30 +
31 + private final ResourcePath resource;
32 + private final ResourceConsumer consumer;
33 +
28 /** 34 /**
29 - * Returns the subject of the resource. 35 + * Creates an instance with the specified subject, resource and consumer.
30 - * The value is the identifier which this resource belongs to.
31 * 36 *
32 - * @return the subject of the resource 37 + * @param resource resource of the subject
38 + * @param consumer consumer ot this resource
33 */ 39 */
34 - S subject(); 40 + public ResourceAllocation(ResourcePath resource, ResourceConsumer consumer) {
41 + this.resource = checkNotNull(resource);
42 + this.consumer = consumer;
43 + }
44 +
45 + // for serialization
46 + private ResourceAllocation() {
47 + this.resource = null;
48 + this.consumer = null;
49 + }
35 50
36 /** 51 /**
37 - * Returns the resource which belongs to the subject. 52 + * Returns the specifier of the resource this allocation uses.
38 * 53 *
39 - * @return the resource which belongs to the subject 54 + * @return the specifier of the resource this allocation uses
40 */ 55 */
41 - T resource(); 56 + public ResourcePath resource() {
57 + return resource;
58 + }
42 59
43 /** 60 /**
44 * Returns the consumer of this resource. 61 * Returns the consumer of this resource.
45 * 62 *
46 * @return the consumer of this resource 63 * @return the consumer of this resource
47 */ 64 */
48 - ResourceConsumer consumer(); 65 + public ResourceConsumer consumer() {
66 + return consumer;
67 + }
68 +
69 + @Override
70 + public int hashCode() {
71 + return Objects.hash(resource, consumer);
72 + }
73 +
74 + @Override
75 + public boolean equals(Object obj) {
76 + if (this == obj) {
77 + return true;
78 + }
79 + if (!(obj instanceof ResourceAllocation)) {
80 + return false;
81 + }
82 + final ResourceAllocation that = (ResourceAllocation) obj;
83 + return Objects.equals(this.resource, that.resource)
84 + && Objects.equals(this.consumer, that.consumer);
85 + }
86 +
87 + @Override
88 + public String toString() {
89 + return MoreObjects.toStringHelper(this)
90 + .add("resource", resource)
91 + .add("consumer", consumer)
92 + .toString();
93 + }
49 } 94 }
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.net.newresource;
17 +
18 +import com.google.common.annotations.Beta;
19 +import com.google.common.base.MoreObjects;
20 +import com.google.common.collect.ImmutableList;
21 +
22 +import java.util.Arrays;
23 +import java.util.List;
24 +import java.util.Objects;
25 +import java.util.Optional;
26 +
27 +import static com.google.common.base.Preconditions.checkArgument;
28 +import static com.google.common.base.Preconditions.checkNotNull;
29 +
30 +/**
31 + * An object that is used to locate a resource in a network.
32 + * A ResourcePath represents a path that is hierarchical and composed of a sequence
33 + * of elementary resources that are not globally identifiable. A ResourcePath can be a globally
34 + * unique resource identifier.
35 + *
36 + * Users of this class must keep the semantics of resources regarding the hierarchical structure.
37 + * For example, resource path, Link:1/VLAN ID:100, is valid, but resource path, VLAN ID:100/Link:1
38 + * is not valid because a link is not a sub-component of a VLAN ID.
39 + */
40 +@Beta
41 +public final class ResourcePath {
42 +
43 + private final List<Object> resources;
44 +
45 + /**
46 + * Creates an resource path from the specified components.
47 + *
48 + * @param components components of the path. The order represents hierarchical structure of the resource.
49 + */
50 + public ResourcePath(Object... components) {
51 + this(Arrays.asList(components));
52 + }
53 +
54 + /**
55 + * Creates an resource path from the specified components.
56 + *
57 + * @param components components of the path. The order represents hierarchical structure of the resource.
58 + */
59 + public ResourcePath(List<Object> components) {
60 + checkNotNull(components);
61 + checkArgument(components.size() > 0);
62 +
63 + this.resources = ImmutableList.copyOf(components);
64 + }
65 +
66 + // for serialization
67 + private ResourcePath() {
68 + this.resources = null;
69 + }
70 +
71 + /**
72 + * Returns the components of this resource path.
73 + *
74 + * @return the components of this resource path
75 + */
76 + public List<Object> components() {
77 + return resources;
78 + }
79 +
80 + /**
81 + * Returns the parent resource path of this instance.
82 + * E.g. if this path is Link:1/VLAN ID:100, the return value is the resource path for Link:1.
83 + *
84 + * @return the parent resource path of this instance.
85 + * If there is no parent, empty instance will be returned.
86 + */
87 + public Optional<ResourcePath> parent() {
88 + if (resources.size() >= 2) {
89 + return Optional.of(new ResourcePath(resources.subList(0, resources.size() - 1)));
90 + }
91 +
92 + return Optional.empty();
93 + }
94 +
95 + /**
96 + * Returns the last component of this instance.
97 + *
98 + * @return the last component of this instance.
99 + * The return value is equal to the last object of {@code components()}.
100 + */
101 + public Object lastComponent() {
102 + int last = resources.size() - 1;
103 + return resources.get(last);
104 + }
105 +
106 + @Override
107 + public int hashCode() {
108 + return resources.hashCode();
109 + }
110 +
111 + @Override
112 + public boolean equals(Object obj) {
113 + if (this == obj) {
114 + return true;
115 + }
116 + if (!(obj instanceof ResourcePath)) {
117 + return false;
118 + }
119 + final ResourcePath that = (ResourcePath) obj;
120 + return Objects.equals(this.resources, that.resources);
121 + }
122 +
123 + @Override
124 + public String toString() {
125 + return MoreObjects.toStringHelper(this)
126 + .add("resources", resources)
127 + .toString();
128 + }
129 +}
...@@ -31,11 +31,9 @@ public interface ResourceService { ...@@ -31,11 +31,9 @@ public interface ResourceService {
31 * 31 *
32 * @param consumer resource user which the resource is allocated to 32 * @param consumer resource user which the resource is allocated to
33 * @param resource resource to be allocated 33 * @param resource resource to be allocated
34 - * @param <S> type of the subject which this resource belongs to
35 - * @param <T> type of the resource
36 * @return allocation information enclosed by Optional. If the allocation fails, the return value is empty 34 * @return allocation information enclosed by Optional. If the allocation fails, the return value is empty
37 */ 35 */
38 - <S, T> Optional<ResourceAllocation<S, T>> allocate(ResourceConsumer consumer, Resource<S, T> resource); 36 + Optional<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath resource);
39 37
40 /** 38 /**
41 * Transactionally allocates the specified resources to the specified user. 39 * Transactionally allocates the specified resources to the specified user.
...@@ -45,7 +43,7 @@ public interface ResourceService { ...@@ -45,7 +43,7 @@ public interface ResourceService {
45 * @param resources resources to be allocated 43 * @param resources resources to be allocated
46 * @return non-empty list of allocation information if succeeded, otherwise empty list 44 * @return non-empty list of allocation information if succeeded, otherwise empty list
47 */ 45 */
48 - List<ResourceAllocation<?, ?>> allocate(ResourceConsumer consumer, List<? extends Resource<?, ?>> resources); 46 + List<ResourceAllocation> allocate(ResourceConsumer consumer, List<ResourcePath> resources);
49 47
50 /** 48 /**
51 * Transactionally allocates the specified resources to the specified user. 49 * Transactionally allocates the specified resources to the specified user.
...@@ -55,17 +53,15 @@ public interface ResourceService { ...@@ -55,17 +53,15 @@ public interface ResourceService {
55 * @param resources resources to be allocated 53 * @param resources resources to be allocated
56 * @return non-empty list of allocation information if succeeded, otherwise empty list 54 * @return non-empty list of allocation information if succeeded, otherwise empty list
57 */ 55 */
58 - List<ResourceAllocation<?, ?>> allocate(ResourceConsumer consumer, Resource<?, ?>... resources); 56 + List<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath... resources);
59 57
60 /** 58 /**
61 * Releases the specified resource allocation. 59 * Releases the specified resource allocation.
62 * 60 *
63 * @param allocation resource allocation to be released 61 * @param allocation resource allocation to be released
64 - * @param <S> type of the subject which this resource belongs to
65 - * @param <T> type of the device resource
66 * @return true if succeeded, otherwise false 62 * @return true if succeeded, otherwise false
67 */ 63 */
68 - <S, T> boolean release(ResourceAllocation<S, T> allocation); 64 + boolean release(ResourceAllocation allocation);
69 65
70 /** 66 /**
71 * Transactionally releases the specified resource allocations. 67 * Transactionally releases the specified resource allocations.
...@@ -74,7 +70,7 @@ public interface ResourceService { ...@@ -74,7 +70,7 @@ public interface ResourceService {
74 * @param allocations resource allocations to be released 70 * @param allocations resource allocations to be released
75 * @return true if succeeded, otherwise false 71 * @return true if succeeded, otherwise false
76 */ 72 */
77 - boolean release(List<? extends ResourceAllocation<?, ?>> allocations); 73 + boolean release(List<ResourceAllocation> allocations);
78 74
79 /** 75 /**
80 * Transactionally releases the specified resource allocations. 76 * Transactionally releases the specified resource allocations.
...@@ -83,7 +79,7 @@ public interface ResourceService { ...@@ -83,7 +79,7 @@ public interface ResourceService {
83 * @param allocations resource allocations to be released 79 * @param allocations resource allocations to be released
84 * @return true if succeeded, otherwise false 80 * @return true if succeeded, otherwise false
85 */ 81 */
86 - boolean release(ResourceAllocation<?, ?>... allocations); 82 + boolean release(ResourceAllocation... allocations);
87 83
88 /** 84 /**
89 * Transactionally releases the resources allocated to the specified consumer. 85 * Transactionally releases the resources allocated to the specified consumer.
...@@ -95,16 +91,14 @@ public interface ResourceService { ...@@ -95,16 +91,14 @@ public interface ResourceService {
95 boolean release(ResourceConsumer consumer); 91 boolean release(ResourceConsumer consumer);
96 92
97 /** 93 /**
98 - * Returns allocated resources in the specified subject regarding the specified resource type. 94 + * Returns allocated resources being as children of the specified parent and being the specified resource type.
99 * 95 *
100 - * @param subject subject where resource allocations are obtained
101 * @param cls class to specify a type of resource 96 * @param cls class to specify a type of resource
102 - * @param <S> type of the subject
103 * @param <T> type of the resource 97 * @param <T> type of the resource
104 * @return non-empty collection of resource allocations if resources are allocated with the subject and type, 98 * @return non-empty collection of resource allocations if resources are allocated with the subject and type,
105 * empty collection if no resource is allocated with the subject and type 99 * empty collection if no resource is allocated with the subject and type
106 */ 100 */
107 - <S, T> Collection<ResourceAllocation<S, T>> getResourceAllocations(S subject, Class<T> cls); 101 + <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls);
108 102
109 /** 103 /**
110 * Returns resources allocated to the specified consumer. 104 * Returns resources allocated to the specified consumer.
...@@ -112,17 +106,15 @@ public interface ResourceService { ...@@ -112,17 +106,15 @@ public interface ResourceService {
112 * @param consumer consumer whose allocated resources are to be returned 106 * @param consumer consumer whose allocated resources are to be returned
113 * @return resources allocated to the consumer 107 * @return resources allocated to the consumer
114 */ 108 */
115 - Collection<ResourceAllocation<?, ?>> getResourceAllocations(ResourceConsumer consumer); 109 + Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer);
116 110
117 /** 111 /**
118 - * Returns the availability of the specified device resource. 112 + * Returns the availability of the specified resource.
119 * 113 *
120 * @param resource resource to check the availability 114 * @param resource resource to check the availability
121 - * @param <S> type of the subject
122 - * @param <T> type of the resource
123 * @return true if available, otherwise false 115 * @return true if available, otherwise false
124 */ 116 */
125 - <S, T> boolean isAvailable(Resource<S, T> resource); 117 + boolean isAvailable(ResourcePath resource);
126 118
127 // TODO: listener and event mechanism need to be considered 119 // TODO: listener and event mechanism need to be considered
128 } 120 }
......
...@@ -21,7 +21,7 @@ public interface ResourceStore { ...@@ -21,7 +21,7 @@ public interface ResourceStore {
21 * @param consumer resource consumer which the resources are allocated to 21 * @param consumer resource consumer which the resources are allocated to
22 * @return true if the allocation succeeds, false otherwise. 22 * @return true if the allocation succeeds, false otherwise.
23 */ 23 */
24 - boolean allocate(List<? extends Resource<?, ?>> resources, ResourceConsumer consumer); 24 + boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer);
25 25
26 /** 26 /**
27 * Releases the specified resources allocated to the specified corresponding consumers 27 * Releases the specified resources allocated to the specified corresponding consumers
...@@ -35,17 +35,15 @@ public interface ResourceStore { ...@@ -35,17 +35,15 @@ public interface ResourceStore {
35 * @param consumers resource consumers to whom the resource allocated to 35 * @param consumers resource consumers to whom the resource allocated to
36 * @return true if succeeds, otherwise false 36 * @return true if succeeds, otherwise false
37 */ 37 */
38 - boolean release(List<? extends Resource<?, ?>> resources, List<ResourceConsumer> consumers); 38 + boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers);
39 39
40 /** 40 /**
41 * Returns the resource consumer to whom the specified resource is allocated. 41 * Returns the resource consumer to whom the specified resource is allocated.
42 * 42 *
43 * @param resource resource whose allocated consumer to be returned 43 * @param resource resource whose allocated consumer to be returned
44 - * @param <S> type of subject of the resource
45 - * @param <T> type of resource
46 * @return resource consumer who are allocated the resource 44 * @return resource consumer who are allocated the resource
47 */ 45 */
48 - <S, T> Optional<ResourceConsumer> getConsumer(Resource<S, T> resource); 46 + Optional<ResourceConsumer> getConsumer(ResourcePath resource);
49 47
50 /** 48 /**
51 * Returns a collection of the resources allocated to the specified consumer. 49 * Returns a collection of the resources allocated to the specified consumer.
...@@ -53,18 +51,17 @@ public interface ResourceStore { ...@@ -53,18 +51,17 @@ public interface ResourceStore {
53 * @param consumer resource consumer whose allocated resource are searched for 51 * @param consumer resource consumer whose allocated resource are searched for
54 * @return a collection of the resources allocated to the specified consumer 52 * @return a collection of the resources allocated to the specified consumer
55 */ 53 */
56 - Collection<Resource<?, ?>> getResources(ResourceConsumer consumer); 54 + Collection<ResourcePath> getResources(ResourceConsumer consumer);
57 55
58 /** 56 /**
59 - * Returns a collection of the resources which belongs to the specified subject and 57 + * Returns a collection of the resources which are children of the specified parent and
60 * whose type is the specified class. 58 * whose type is the specified class.
61 * 59 *
62 - * @param subject subject of the resources to be returned 60 + * @param parent parent of the resources to be returned
63 - * @param cls class instance of the resources 61 + * @param cls class instance of the children
64 - * @param <S> type of the subject
65 * @param <T> type of the resource 62 * @param <T> type of the resource
66 * @return a collection of the resources which belongs to the specified subject and 63 * @return a collection of the resources which belongs to the specified subject and
67 * whose type is the specified class. 64 * whose type is the specified class.
68 */ 65 */
69 - <S, T> Collection<Resource<S, T>> getAllocatedResources(S subject, Class<T> cls); 66 + <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls);
70 } 67 }
......
...@@ -33,15 +33,14 @@ public class ResourceAllocationTest { ...@@ -33,15 +33,14 @@ public class ResourceAllocationTest {
33 private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); 33 private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1);
34 private static final VlanId VLAN1 = VlanId.vlanId((short) 100); 34 private static final VlanId VLAN1 = VlanId.vlanId((short) 100);
35 private static final IntentId IID1 = IntentId.valueOf(30); 35 private static final IntentId IID1 = IntentId.valueOf(30);
36 + private static final LinkKey LK1 = LinkKey.linkKey(CP1_1, CP2_1);
37 + private static final LinkKey LK2 = LinkKey.linkKey(CP2_1, CP1_1);
36 38
37 @Test 39 @Test
38 public void testEquals() { 40 public void testEquals() {
39 - DefaultResourceAllocation<LinkKey, VlanId> alloc1 = 41 + ResourceAllocation alloc1 = new ResourceAllocation(new ResourcePath(LK1, VLAN1), IID1);
40 - new DefaultResourceAllocation<>(LinkKey.linkKey(CP1_1, CP2_1), VLAN1, IID1); 42 + ResourceAllocation sameAsAlloc1 = new ResourceAllocation(new ResourcePath(LK1, VLAN1), IID1);
41 - DefaultResourceAllocation<LinkKey, VlanId> sameAsAlloc1 = 43 + ResourceAllocation alloc2 = new ResourceAllocation(new ResourcePath(LK2, VLAN1), IID1);
42 - new DefaultResourceAllocation<>(LinkKey.linkKey(CP1_1, CP2_1), VLAN1, IID1);
43 - DefaultResourceAllocation<LinkKey, VlanId> alloc2 =
44 - new DefaultResourceAllocation<>(LinkKey.linkKey(CP2_1, CP1_1), VLAN1, IID1);
45 44
46 new EqualsTester() 45 new EqualsTester()
47 .addEqualityGroup(alloc1, sameAsAlloc1) 46 .addEqualityGroup(alloc1, sameAsAlloc1)
......
...@@ -23,7 +23,12 @@ import org.onosproject.net.DeviceId; ...@@ -23,7 +23,12 @@ import org.onosproject.net.DeviceId;
23 import org.onosproject.net.LinkKey; 23 import org.onosproject.net.LinkKey;
24 import org.onosproject.net.PortNumber; 24 import org.onosproject.net.PortNumber;
25 25
26 -public class DefaultResourceTest { 26 +import java.util.Optional;
27 +
28 +import static org.hamcrest.Matchers.is;
29 +import static org.junit.Assert.assertThat;
30 +
31 +public class ResourcePathTest {
27 32
28 private static final DeviceId D1 = DeviceId.deviceId("of:001"); 33 private static final DeviceId D1 = DeviceId.deviceId("of:001");
29 private static final DeviceId D2 = DeviceId.deviceId("of:002"); 34 private static final DeviceId D2 = DeviceId.deviceId("of:002");
...@@ -34,16 +39,42 @@ public class DefaultResourceTest { ...@@ -34,16 +39,42 @@ public class DefaultResourceTest {
34 39
35 @Test 40 @Test
36 public void testEquals() { 41 public void testEquals() {
37 - DefaultResource<LinkKey, VlanId> resource1 = 42 + ResourcePath resource1 = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1);
38 - new DefaultResource<>(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); 43 + ResourcePath sameAsResource1 = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1);
39 - DefaultResource<LinkKey, VlanId> sameAsResource1 = 44 + ResourcePath resource2 = new ResourcePath(LinkKey.linkKey(CP2_1, CP1_1), VLAN1);
40 - new DefaultResource<>(LinkKey.linkKey(CP1_1, CP2_1), VLAN1);
41 - DefaultResource<LinkKey, VlanId> resource2 =
42 - new DefaultResource<>(LinkKey.linkKey(CP2_1, CP1_1), VLAN1);
43 45
44 new EqualsTester() 46 new EqualsTester()
45 .addEqualityGroup(resource1, sameAsResource1) 47 .addEqualityGroup(resource1, sameAsResource1)
46 .addEqualityGroup(resource2) 48 .addEqualityGroup(resource2)
47 .testEquals(); 49 .testEquals();
48 } 50 }
51 +
52 + @Test(expected = IllegalArgumentException.class)
53 + public void testCreateWithZeroComponent() {
54 + ResourcePath path = new ResourcePath();
55 + }
56 +
57 + @Test
58 + public void testThereIsParent() {
59 + ResourcePath path = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1);
60 + ResourcePath parent = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1));
61 +
62 + assertThat(path.parent(), is(Optional.of(parent)));
63 + }
64 +
65 + @Test
66 + public void testNoParent() {
67 + ResourcePath path = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1));
68 +
69 + assertThat(path.parent(), is(Optional.empty()));
70 + }
71 +
72 + @Test
73 + public void testBase() {
74 + LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1);
75 + ResourcePath path = new ResourcePath(linkKey);
76 +
77 + LinkKey child = (LinkKey) path.lastComponent();
78 + assertThat(child, is(linkKey));
79 + }
49 } 80 }
......
...@@ -21,13 +21,11 @@ import org.apache.felix.scr.annotations.Component; ...@@ -21,13 +21,11 @@ import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Reference; 21 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service; 23 import org.apache.felix.scr.annotations.Service;
24 -import org.onosproject.net.newresource.DefaultResource;
25 -import org.onosproject.net.newresource.DefaultResourceAllocation;
26 -import org.onosproject.net.newresource.Resource;
27 import org.onosproject.net.newresource.ResourceAdminService; 24 import org.onosproject.net.newresource.ResourceAdminService;
28 import org.onosproject.net.newresource.ResourceAllocation; 25 import org.onosproject.net.newresource.ResourceAllocation;
29 import org.onosproject.net.newresource.ResourceConsumer; 26 import org.onosproject.net.newresource.ResourceConsumer;
30 import org.onosproject.net.newresource.ResourceService; 27 import org.onosproject.net.newresource.ResourceService;
28 +import org.onosproject.net.newresource.ResourcePath;
31 import org.onosproject.net.newresource.ResourceStore; 29 import org.onosproject.net.newresource.ResourceStore;
32 30
33 import java.util.ArrayList; 31 import java.util.ArrayList;
...@@ -55,31 +53,29 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ ...@@ -55,31 +53,29 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ
55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 53 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
56 protected ResourceStore store; 54 protected ResourceStore store;
57 55
58 - @SuppressWarnings("unchecked")
59 @Override 56 @Override
60 - public <S, T> Optional<ResourceAllocation<S, T>> allocate(ResourceConsumer consumer, Resource<S, T> resource) { 57 + public Optional<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath resource) {
61 checkNotNull(consumer); 58 checkNotNull(consumer);
62 checkNotNull(resource); 59 checkNotNull(resource);
63 60
64 - List<ResourceAllocation<?, ?>> allocations = allocate(consumer, ImmutableList.of(resource)); 61 + List<ResourceAllocation> allocations = allocate(consumer, ImmutableList.of(resource));
65 if (allocations.isEmpty()) { 62 if (allocations.isEmpty()) {
66 return Optional.empty(); 63 return Optional.empty();
67 } 64 }
68 65
69 assert allocations.size() == 1; 66 assert allocations.size() == 1;
70 67
71 - ResourceAllocation<?, ?> allocation = allocations.get(0); 68 + ResourceAllocation allocation = allocations.get(0);
72 69
73 - assert allocation.subject().getClass() == resource.subject().getClass(); 70 + assert allocation.resource().equals(resource);
74 - assert allocation.resource().getClass() == resource.resource().getClass();
75 71
76 // cast is ensured by the assertions above 72 // cast is ensured by the assertions above
77 - return Optional.of((ResourceAllocation<S, T>) allocation); 73 + return Optional.of(allocation);
78 } 74 }
79 75
80 @Override 76 @Override
81 - public List<ResourceAllocation<?, ?>> allocate(ResourceConsumer consumer, 77 + public List<ResourceAllocation> allocate(ResourceConsumer consumer,
82 - List<? extends Resource<?, ?>> resources) { 78 + List<ResourcePath> resources) {
83 checkNotNull(consumer); 79 checkNotNull(consumer);
84 checkNotNull(resources); 80 checkNotNull(resources);
85 81
...@@ -96,12 +92,12 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ ...@@ -96,12 +92,12 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ
96 } 92 }
97 93
98 return resources.stream() 94 return resources.stream()
99 - .map(x -> new DefaultResourceAllocation<>(x.subject(), x.resource(), consumer)) 95 + .map(x -> new ResourceAllocation(x, consumer))
100 .collect(Collectors.toList()); 96 .collect(Collectors.toList());
101 } 97 }
102 98
103 @Override 99 @Override
104 - public List<ResourceAllocation<?, ?>> allocate(ResourceConsumer consumer, Resource<?, ?>... resources) { 100 + public List<ResourceAllocation> allocate(ResourceConsumer consumer, ResourcePath... resources) {
105 checkNotNull(consumer); 101 checkNotNull(consumer);
106 checkNotNull(resources); 102 checkNotNull(resources);
107 103
...@@ -109,18 +105,18 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ ...@@ -109,18 +105,18 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ
109 } 105 }
110 106
111 @Override 107 @Override
112 - public <S, T> boolean release(ResourceAllocation<S, T> allocation) { 108 + public boolean release(ResourceAllocation allocation) {
113 checkNotNull(allocation); 109 checkNotNull(allocation);
114 110
115 return release(ImmutableList.of(allocation)); 111 return release(ImmutableList.of(allocation));
116 } 112 }
117 113
118 @Override 114 @Override
119 - public boolean release(List<? extends ResourceAllocation<?, ?>> allocations) { 115 + public boolean release(List<ResourceAllocation> allocations) {
120 checkNotNull(allocations); 116 checkNotNull(allocations);
121 117
122 - List<DefaultResource<?, ?>> resources = allocations.stream() 118 + List<ResourcePath> resources = allocations.stream()
123 - .map(x -> new DefaultResource<>(x.subject(), x.resource())) 119 + .map(ResourceAllocation::resource)
124 .collect(Collectors.toList()); 120 .collect(Collectors.toList());
125 List<ResourceConsumer> consumers = allocations.stream() 121 List<ResourceConsumer> consumers = allocations.stream()
126 .map(ResourceAllocation::consumer) 122 .map(ResourceAllocation::consumer)
...@@ -130,7 +126,7 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ ...@@ -130,7 +126,7 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ
130 } 126 }
131 127
132 @Override 128 @Override
133 - public boolean release(ResourceAllocation<?, ?>... allocations) { 129 + public boolean release(ResourceAllocation... allocations) {
134 checkNotNull(allocations); 130 checkNotNull(allocations);
135 131
136 return release(ImmutableList.copyOf(allocations)); 132 return release(ImmutableList.copyOf(allocations));
...@@ -140,23 +136,22 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ ...@@ -140,23 +136,22 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ
140 public boolean release(ResourceConsumer consumer) { 136 public boolean release(ResourceConsumer consumer) {
141 checkNotNull(consumer); 137 checkNotNull(consumer);
142 138
143 - Collection<ResourceAllocation<?, ?>> allocations = getResourceAllocations(consumer); 139 + Collection<ResourceAllocation> allocations = getResourceAllocations(consumer);
144 return release(ImmutableList.copyOf(allocations)); 140 return release(ImmutableList.copyOf(allocations));
145 } 141 }
146 142
147 @Override 143 @Override
148 - public <S, T> Collection<ResourceAllocation<S, T>> getResourceAllocations(S subject, Class<T> cls) { 144 + public <T> Collection<ResourceAllocation> getResourceAllocations(ResourcePath parent, Class<T> cls) {
149 - checkNotNull(subject); 145 + checkNotNull(parent);
150 checkNotNull(cls); 146 checkNotNull(cls);
151 147
152 - Collection<Resource<S, T>> resources = store.getAllocatedResources(subject, cls); 148 + Collection<ResourcePath> resources = store.getAllocatedResources(parent, cls);
153 - List<ResourceAllocation<S, T>> allocations = new ArrayList<>(resources.size()); 149 + List<ResourceAllocation> allocations = new ArrayList<>(resources.size());
154 - for (Resource<S, T> resource: resources) { 150 + for (ResourcePath resource: resources) {
155 // We access store twice in this method, then the store may be updated by others 151 // We access store twice in this method, then the store may be updated by others
156 Optional<ResourceConsumer> consumer = store.getConsumer(resource); 152 Optional<ResourceConsumer> consumer = store.getConsumer(resource);
157 if (consumer.isPresent()) { 153 if (consumer.isPresent()) {
158 - allocations.add( 154 + allocations.add(new ResourceAllocation(resource, consumer.get()));
159 - new DefaultResourceAllocation<>(resource.subject(), resource.resource(), consumer.get()));
160 } 155 }
161 } 156 }
162 157
...@@ -164,17 +159,17 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ ...@@ -164,17 +159,17 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ
164 } 159 }
165 160
166 @Override 161 @Override
167 - public Collection<ResourceAllocation<?, ?>> getResourceAllocations(ResourceConsumer consumer) { 162 + public Collection<ResourceAllocation> getResourceAllocations(ResourceConsumer consumer) {
168 checkNotNull(consumer); 163 checkNotNull(consumer);
169 164
170 - Collection<Resource<?, ?>> resources = store.getResources(consumer); 165 + Collection<ResourcePath> resources = store.getResources(consumer);
171 return resources.stream() 166 return resources.stream()
172 - .map(x -> new DefaultResourceAllocation<>(x.subject(), x.resource(), consumer)) 167 + .map(x -> new ResourceAllocation(x, consumer))
173 .collect(Collectors.toList()); 168 .collect(Collectors.toList());
174 } 169 }
175 170
176 @Override 171 @Override
177 - public <S, T> boolean isAvailable(Resource<S, T> resource) { 172 + public boolean isAvailable(ResourcePath resource) {
178 checkNotNull(resource); 173 checkNotNull(resource);
179 174
180 Optional<ResourceConsumer> consumer = store.getConsumer(resource); 175 Optional<ResourceConsumer> consumer = store.getConsumer(resource);
...@@ -204,16 +199,16 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ ...@@ -204,16 +199,16 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ
204 * E.g. VLAN ID against a link must be within 12 bit address space. 199 * E.g. VLAN ID against a link must be within 12 bit address space.
205 * 200 *
206 * @param resource resource to be checked if it is within the resource range 201 * @param resource resource to be checked if it is within the resource range
207 - * @param <S> type of the subject
208 - * @param <T> type of the resource
209 * @return true if the resource within the range, false otherwise 202 * @return true if the resource within the range, false otherwise
210 */ 203 */
211 - <S, T> boolean isValid(Resource<S, T> resource) { 204 + boolean isValid(ResourcePath resource) {
212 - Predicate<T> predicate = lookupPredicate(resource.resource()); 205 + List<Object> flatten = resource.components();
206 + Object bottom = flatten.get(flatten.size() - 1);
207 + Predicate<Object> predicate = lookupPredicate(bottom);
213 if (predicate == null) { 208 if (predicate == null) {
214 return true; 209 return true;
215 } 210 }
216 211
217 - return predicate.test(resource.resource()); 212 + return predicate.test(bottom);
218 } 213 }
219 } 214 }
......
...@@ -22,12 +22,12 @@ import org.onosproject.net.ConnectPoint; ...@@ -22,12 +22,12 @@ import org.onosproject.net.ConnectPoint;
22 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
23 import org.onosproject.net.LinkKey; 23 import org.onosproject.net.LinkKey;
24 import org.onosproject.net.PortNumber; 24 import org.onosproject.net.PortNumber;
25 -import org.onosproject.net.newresource.DefaultResource; 25 +import org.onosproject.net.newresource.ResourcePath;
26 26
27 import java.util.function.Predicate; 27 import java.util.function.Predicate;
28 28
29 import static org.hamcrest.Matchers.is; 29 import static org.hamcrest.Matchers.is;
30 -import static org.junit.Assert.*; 30 +import static org.junit.Assert.assertThat;
31 31
32 /** 32 /**
33 * Unit tests for ResourceManager. 33 * Unit tests for ResourceManager.
...@@ -60,19 +60,19 @@ public class ResourceManagerTest { ...@@ -60,19 +60,19 @@ public class ResourceManagerTest {
60 60
61 LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1); 61 LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1);
62 62
63 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId((short) (VLAN_LOWER_LIMIT - 1)))), 63 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId((short) (VLAN_LOWER_LIMIT - 1)))),
64 is(false)); 64 is(false));
65 65
66 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId(VLAN_LOWER_LIMIT))), 66 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId(VLAN_LOWER_LIMIT))),
67 is(true)); 67 is(true));
68 68
69 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId((short) 100))), 69 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId((short) 100))),
70 is(true)); 70 is(true));
71 71
72 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId((short) (VLAN_UPPER_LIMIT - 1)))), 72 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId((short) (VLAN_UPPER_LIMIT - 1)))),
73 is(true)); 73 is(true));
74 74
75 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId(VLAN_UPPER_LIMIT))), 75 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId(VLAN_UPPER_LIMIT))),
76 is(false)); 76 is(false));
77 } 77 }
78 78
...@@ -83,19 +83,19 @@ public class ResourceManagerTest { ...@@ -83,19 +83,19 @@ public class ResourceManagerTest {
83 public void testWhenBoundaryNotSet() { 83 public void testWhenBoundaryNotSet() {
84 LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1); 84 LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1);
85 85
86 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId((short) (VLAN_LOWER_LIMIT - 1)))), 86 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId((short) (VLAN_LOWER_LIMIT - 1)))),
87 is(true)); 87 is(true));
88 88
89 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId(VLAN_LOWER_LIMIT))), 89 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId(VLAN_LOWER_LIMIT))),
90 is(true)); 90 is(true));
91 91
92 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId((short) 100))), 92 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId((short) 100))),
93 is(true)); 93 is(true));
94 94
95 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId((short) (VLAN_UPPER_LIMIT - 1)))), 95 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId((short) (VLAN_UPPER_LIMIT - 1)))),
96 is(true)); 96 is(true));
97 97
98 - assertThat(manager.isValid(new DefaultResource<>(linkKey, VlanId.vlanId(VLAN_UPPER_LIMIT))), 98 + assertThat(manager.isValid(new ResourcePath(linkKey, VlanId.vlanId(VLAN_UPPER_LIMIT))),
99 is(true)); 99 is(true));
100 } 100 }
101 } 101 }
......
...@@ -21,8 +21,8 @@ import org.apache.felix.scr.annotations.Component; ...@@ -21,8 +21,8 @@ import org.apache.felix.scr.annotations.Component;
21 import org.apache.felix.scr.annotations.Reference; 21 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.apache.felix.scr.annotations.Service; 23 import org.apache.felix.scr.annotations.Service;
24 -import org.onosproject.net.newresource.Resource;
25 import org.onosproject.net.newresource.ResourceConsumer; 24 import org.onosproject.net.newresource.ResourceConsumer;
25 +import org.onosproject.net.newresource.ResourcePath;
26 import org.onosproject.net.newresource.ResourceStore; 26 import org.onosproject.net.newresource.ResourceStore;
27 import org.onosproject.store.serializers.KryoNamespaces; 27 import org.onosproject.store.serializers.KryoNamespaces;
28 import org.onosproject.store.service.ConsistentMap; 28 import org.onosproject.store.service.ConsistentMap;
...@@ -60,18 +60,18 @@ public class ConsistentResourceStore implements ResourceStore { ...@@ -60,18 +60,18 @@ public class ConsistentResourceStore implements ResourceStore {
60 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 60 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
61 protected StorageService service; 61 protected StorageService service;
62 62
63 - private ConsistentMap<Resource<?, ?>, ResourceConsumer> consumers; 63 + private ConsistentMap<ResourcePath, ResourceConsumer> consumers;
64 64
65 @Activate 65 @Activate
66 public void activate() { 66 public void activate() {
67 - consumers = service.<Resource<?, ?>, ResourceConsumer>consistentMapBuilder() 67 + consumers = service.<ResourcePath, ResourceConsumer>consistentMapBuilder()
68 .withName(MAP_NAME) 68 .withName(MAP_NAME)
69 .withSerializer(SERIALIZER) 69 .withSerializer(SERIALIZER)
70 .build(); 70 .build();
71 } 71 }
72 72
73 @Override 73 @Override
74 - public <S, T> Optional<ResourceConsumer> getConsumer(Resource<S, T> resource) { 74 + public Optional<ResourceConsumer> getConsumer(ResourcePath resource) {
75 checkNotNull(resource); 75 checkNotNull(resource);
76 76
77 Versioned<ResourceConsumer> consumer = consumers.get(resource); 77 Versioned<ResourceConsumer> consumer = consumers.get(resource);
...@@ -83,7 +83,7 @@ public class ConsistentResourceStore implements ResourceStore { ...@@ -83,7 +83,7 @@ public class ConsistentResourceStore implements ResourceStore {
83 } 83 }
84 84
85 @Override 85 @Override
86 - public boolean allocate(List<? extends Resource<?, ?>> resources, ResourceConsumer consumer) { 86 + public boolean allocate(List<ResourcePath> resources, ResourceConsumer consumer) {
87 checkNotNull(resources); 87 checkNotNull(resources);
88 checkNotNull(consumer); 88 checkNotNull(consumer);
89 89
...@@ -91,8 +91,8 @@ public class ConsistentResourceStore implements ResourceStore { ...@@ -91,8 +91,8 @@ public class ConsistentResourceStore implements ResourceStore {
91 tx.begin(); 91 tx.begin();
92 92
93 try { 93 try {
94 - TransactionalMap<Resource<?, ?>, ResourceConsumer> txMap = tx.getTransactionalMap(MAP_NAME, SERIALIZER); 94 + TransactionalMap<ResourcePath, ResourceConsumer> txMap = tx.getTransactionalMap(MAP_NAME, SERIALIZER);
95 - for (Resource<?, ?> resource: resources) { 95 + for (ResourcePath resource: resources) {
96 ResourceConsumer existing = txMap.putIfAbsent(resource, consumer); 96 ResourceConsumer existing = txMap.putIfAbsent(resource, consumer);
97 // if the resource is already allocated to another consumer, the whole allocation fails 97 // if the resource is already allocated to another consumer, the whole allocation fails
98 if (existing != null) { 98 if (existing != null) {
...@@ -108,7 +108,7 @@ public class ConsistentResourceStore implements ResourceStore { ...@@ -108,7 +108,7 @@ public class ConsistentResourceStore implements ResourceStore {
108 } 108 }
109 109
110 @Override 110 @Override
111 - public boolean release(List<? extends Resource<?, ?>> resources, List<ResourceConsumer> consumers) { 111 + public boolean release(List<ResourcePath> resources, List<ResourceConsumer> consumers) {
112 checkNotNull(resources); 112 checkNotNull(resources);
113 checkNotNull(consumers); 113 checkNotNull(consumers);
114 checkArgument(resources.size() == consumers.size()); 114 checkArgument(resources.size() == consumers.size());
...@@ -117,12 +117,12 @@ public class ConsistentResourceStore implements ResourceStore { ...@@ -117,12 +117,12 @@ public class ConsistentResourceStore implements ResourceStore {
117 tx.begin(); 117 tx.begin();
118 118
119 try { 119 try {
120 - TransactionalMap<Resource<?, ?>, ResourceConsumer> txMap = tx.getTransactionalMap(MAP_NAME, SERIALIZER); 120 + TransactionalMap<ResourcePath, ResourceConsumer> txMap = tx.getTransactionalMap(MAP_NAME, SERIALIZER);
121 - Iterator<? extends Resource<?, ?>> resourceIte = resources.iterator(); 121 + Iterator<ResourcePath> resourceIte = resources.iterator();
122 Iterator<ResourceConsumer> consumerIte = consumers.iterator(); 122 Iterator<ResourceConsumer> consumerIte = consumers.iterator();
123 123
124 while (resourceIte.hasNext() && consumerIte.hasNext()) { 124 while (resourceIte.hasNext() && consumerIte.hasNext()) {
125 - Resource<?, ?> resource = resourceIte.next(); 125 + ResourcePath resource = resourceIte.next();
126 ResourceConsumer consumer = consumerIte.next(); 126 ResourceConsumer consumer = consumerIte.next();
127 127
128 // if this single release fails (because the resource is allocated to another consumer, 128 // if this single release fails (because the resource is allocated to another consumer,
...@@ -140,7 +140,7 @@ public class ConsistentResourceStore implements ResourceStore { ...@@ -140,7 +140,7 @@ public class ConsistentResourceStore implements ResourceStore {
140 } 140 }
141 141
142 @Override 142 @Override
143 - public Collection<Resource<?, ?>> getResources(ResourceConsumer consumer) { 143 + public Collection<ResourcePath> getResources(ResourceConsumer consumer) {
144 checkNotNull(consumer); 144 checkNotNull(consumer);
145 145
146 // NOTE: getting all entries may become performance bottleneck 146 // NOTE: getting all entries may become performance bottleneck
...@@ -151,18 +151,17 @@ public class ConsistentResourceStore implements ResourceStore { ...@@ -151,18 +151,17 @@ public class ConsistentResourceStore implements ResourceStore {
151 .collect(Collectors.toList()); 151 .collect(Collectors.toList());
152 } 152 }
153 153
154 - @SuppressWarnings("unchecked")
155 @Override 154 @Override
156 - public <S, T> Collection<Resource<S, T>> getAllocatedResources(S subject, Class<T> cls) { 155 + public <T> Collection<ResourcePath> getAllocatedResources(ResourcePath parent, Class<T> cls) {
157 - checkNotNull(subject); 156 + checkNotNull(parent);
158 checkNotNull(cls); 157 checkNotNull(cls);
159 158
160 // NOTE: getting all entries may become performance bottleneck 159 // NOTE: getting all entries may become performance bottleneck
161 // TODO: revisit for better backend data structure 160 // TODO: revisit for better backend data structure
162 return consumers.entrySet().stream() 161 return consumers.entrySet().stream()
163 - .filter(x -> x.getKey().subject().equals(subject) && x.getKey().resource().getClass() == cls) 162 + .filter(x -> x.getKey().parent().isPresent() && x.getKey().parent().get().equals(parent))
164 - // cast is ensured by the above filter method 163 + .filter(x -> x.getKey().lastComponent().getClass() == cls)
165 - .map(x -> (Resource<S, T>) x.getKey()) 164 + .map(Map.Entry::getKey)
166 .collect(Collectors.toList()); 165 .collect(Collectors.toList());
167 } 166 }
168 167
......
...@@ -160,8 +160,8 @@ import org.onosproject.net.intent.constraint.ObstacleConstraint; ...@@ -160,8 +160,8 @@ import org.onosproject.net.intent.constraint.ObstacleConstraint;
160 import org.onosproject.net.intent.constraint.PartialFailureConstraint; 160 import org.onosproject.net.intent.constraint.PartialFailureConstraint;
161 import org.onosproject.net.intent.constraint.WaypointConstraint; 161 import org.onosproject.net.intent.constraint.WaypointConstraint;
162 import org.onosproject.net.link.DefaultLinkDescription; 162 import org.onosproject.net.link.DefaultLinkDescription;
163 -import org.onosproject.net.newresource.DefaultResource; 163 +import org.onosproject.net.newresource.ResourceAllocation;
164 -import org.onosproject.net.newresource.DefaultResourceAllocation; 164 +import org.onosproject.net.newresource.ResourcePath;
165 import org.onosproject.net.packet.DefaultOutboundPacket; 165 import org.onosproject.net.packet.DefaultOutboundPacket;
166 import org.onosproject.net.packet.DefaultPacketRequest; 166 import org.onosproject.net.packet.DefaultPacketRequest;
167 import org.onosproject.net.packet.PacketPriority; 167 import org.onosproject.net.packet.PacketPriority;
...@@ -402,8 +402,8 @@ public final class KryoNamespaces { ...@@ -402,8 +402,8 @@ public final class KryoNamespaces {
402 DefaultLinkResourceAllocations.class, 402 DefaultLinkResourceAllocations.class,
403 BandwidthResourceAllocation.class, 403 BandwidthResourceAllocation.class,
404 LambdaResourceAllocation.class, 404 LambdaResourceAllocation.class,
405 - DefaultResource.class, 405 + ResourcePath.class,
406 - DefaultResourceAllocation.class, 406 + ResourceAllocation.class,
407 // Constraints 407 // Constraints
408 LambdaConstraint.class, 408 LambdaConstraint.class,
409 BandwidthConstraint.class, 409 BandwidthConstraint.class,
......
...@@ -60,8 +60,7 @@ import org.onosproject.net.flow.FlowId; ...@@ -60,8 +60,7 @@ import org.onosproject.net.flow.FlowId;
60 import org.onosproject.net.flow.FlowRule; 60 import org.onosproject.net.flow.FlowRule;
61 import org.onosproject.net.flow.FlowRuleBatchEntry; 61 import org.onosproject.net.flow.FlowRuleBatchEntry;
62 import org.onosproject.net.intent.IntentId; 62 import org.onosproject.net.intent.IntentId;
63 -import org.onosproject.net.newresource.DefaultResource; 63 +import org.onosproject.net.newresource.ResourcePath;
64 -import org.onosproject.net.newresource.DefaultResourceAllocation;
65 import org.onosproject.net.provider.ProviderId; 64 import org.onosproject.net.provider.ProviderId;
66 import org.onosproject.net.resource.link.BandwidthResource; 65 import org.onosproject.net.resource.link.BandwidthResource;
67 import org.onosproject.net.resource.link.BandwidthResourceAllocation; 66 import org.onosproject.net.resource.link.BandwidthResourceAllocation;
...@@ -373,15 +372,14 @@ public class KryoSerializerTest { ...@@ -373,15 +372,14 @@ public class KryoSerializerTest {
373 } 372 }
374 373
375 @Test 374 @Test
376 - public void testDefaultResouce() { 375 + public void testResourcePath() {
377 - testSerializedEquals(new DefaultResource<>(LinkKey.linkKey(CP1, CP2), VLAN1)); 376 + testSerializedEquals(new ResourcePath(LinkKey.linkKey(CP1, CP2), VLAN1));
378 } 377 }
379 378
380 @Test 379 @Test
381 - public void testDefaultResourceAllocation() { 380 + public void testResourceAllocation() {
382 - testSerializedEquals(new DefaultResourceAllocation<>( 381 + testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation(
383 - LinkKey.linkKey(CP1, CP2), 382 + new ResourcePath(LinkKey.linkKey(CP1, CP2), VLAN1),
384 - VLAN1,
385 IntentId.valueOf(30))); 383 IntentId.valueOf(30)));
386 } 384 }
387 385
......