Committed by
Gerrit Code Review
Change the APIs to instantiate Resource and ResourceId
Now, DiscreteResource/DiscreteResourceId is provided by DiscreteFactory. Similarly, ContinuousResource/ContinuousResourceId is provided by ContinuousFactory. These factory instances can be obtained by static factory method such as Resource.discrete(...) or Resource.continuous(...). Change-Id: Ic94f7336c0e1f74cf2dddcac899de300362aff3e
Showing
22 changed files
with
364 additions
and
174 deletions
... | @@ -106,7 +106,7 @@ public class AllocationsCommand extends AbstractShellCommand { | ... | @@ -106,7 +106,7 @@ public class AllocationsCommand extends AbstractShellCommand { |
106 | // TODO: Current design cannot deal with sub-resources | 106 | // TODO: Current design cannot deal with sub-resources |
107 | // (e.g., TX/RX under Port) | 107 | // (e.g., TX/RX under Port) |
108 | 108 | ||
109 | - Resource resource = Resource.discrete(did, num); | 109 | + Resource resource = Resource.discrete(did, num).resource(); |
110 | if (lambda) { | 110 | if (lambda) { |
111 | //print("Lambda resources:"); | 111 | //print("Lambda resources:"); |
112 | Collection<ResourceAllocation> allocations | 112 | Collection<ResourceAllocation> allocations | ... | ... |
... | @@ -89,11 +89,11 @@ public class ResourcesCommand extends AbstractShellCommand { | ... | @@ -89,11 +89,11 @@ public class ResourcesCommand extends AbstractShellCommand { |
89 | DeviceId deviceId = deviceId(deviceIdStr); | 89 | DeviceId deviceId = deviceId(deviceIdStr); |
90 | PortNumber portNumber = PortNumber.fromString(portNumberStr); | 90 | PortNumber portNumber = PortNumber.fromString(portNumberStr); |
91 | 91 | ||
92 | - printResource(Resource.discrete(deviceId, portNumber), 0); | 92 | + printResource(Resource.discrete(deviceId, portNumber).resource(), 0); |
93 | } else if (deviceIdStr != null) { | 93 | } else if (deviceIdStr != null) { |
94 | DeviceId deviceId = deviceId(deviceIdStr); | 94 | DeviceId deviceId = deviceId(deviceIdStr); |
95 | 95 | ||
96 | - printResource(Resource.discrete(deviceId), 0); | 96 | + printResource(Resource.discrete(deviceId).resource(), 0); |
97 | } else { | 97 | } else { |
98 | printResource(Resource.ROOT, 0); | 98 | printResource(Resource.ROOT, 0); |
99 | } | 99 | } | ... | ... |
... | @@ -74,7 +74,7 @@ public class TestAllocateResource extends AbstractShellCommand { | ... | @@ -74,7 +74,7 @@ public class TestAllocateResource extends AbstractShellCommand { |
74 | ResourceConsumer consumer = IntentId.valueOf(nIntendId); | 74 | ResourceConsumer consumer = IntentId.valueOf(nIntendId); |
75 | 75 | ||
76 | Resource resource = discrete(did, portNum, | 76 | Resource resource = discrete(did, portNum, |
77 | - createLambda(Integer.parseInt(lambda))); | 77 | + createLambda(Integer.parseInt(lambda))).resource(); |
78 | 78 | ||
79 | Optional<ResourceAllocation> allocate = resourceService.allocate(consumer, resource); | 79 | Optional<ResourceAllocation> allocate = resourceService.allocate(consumer, resource); |
80 | if (allocate.isPresent()) { | 80 | if (allocate.isPresent()) { | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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 | + * Factory class for continuous-type resource related instances. | ||
22 | + */ | ||
23 | +@Beta | ||
24 | +public final class ContinuousFactory { | ||
25 | + private final ContinuousResourceId id; | ||
26 | + | ||
27 | + /** | ||
28 | + * Creates an instance with the specified resource ID. | ||
29 | + * | ||
30 | + * @param id resource ID that is associated with the resource related instances | ||
31 | + * which will be created from this instance | ||
32 | + */ | ||
33 | + ContinuousFactory(ContinuousResourceId id) { | ||
34 | + this.id = id; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns the resource ID for continuous-type. | ||
39 | + * | ||
40 | + * @return continuous-type resource ID | ||
41 | + */ | ||
42 | + public ContinuousResourceId id() { | ||
43 | + return id; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns the resource for continuous-type specified by the given value. | ||
48 | + * | ||
49 | + * @param volume volume of the returned resource | ||
50 | + * @return continuous-type resource | ||
51 | + */ | ||
52 | + public ContinuousResource resource(double volume) { | ||
53 | + return new ContinuousResource(id(), volume); | ||
54 | + } | ||
55 | +} |
... | @@ -98,7 +98,7 @@ public final class ContinuousResource implements Resource { | ... | @@ -98,7 +98,7 @@ public final class ContinuousResource implements Resource { |
98 | 98 | ||
99 | @Override | 99 | @Override |
100 | public Optional<DiscreteResource> parent() { | 100 | public Optional<DiscreteResource> parent() { |
101 | - return id.parent().map(DiscreteResource::new); | 101 | + return id.parent().map(x -> Resource.discrete(x).resource()); |
102 | } | 102 | } |
103 | 103 | ||
104 | @Override | 104 | @Override | ... | ... |
... | @@ -21,8 +21,6 @@ import com.google.common.collect.ImmutableList; | ... | @@ -21,8 +21,6 @@ import com.google.common.collect.ImmutableList; |
21 | import java.util.Objects; | 21 | import java.util.Objects; |
22 | import java.util.Optional; | 22 | import java.util.Optional; |
23 | 23 | ||
24 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | - | ||
26 | /** | 24 | /** |
27 | * ResourceId for {@link ContinuousResource} | 25 | * ResourceId for {@link ContinuousResource} |
28 | * | 26 | * |
... | @@ -36,11 +34,6 @@ public final class ContinuousResourceId extends ResourceId { | ... | @@ -36,11 +34,6 @@ public final class ContinuousResourceId extends ResourceId { |
36 | // for printing purpose only (used in toString() implementation) | 34 | // for printing purpose only (used in toString() implementation) |
37 | private final String name; | 35 | private final String name; |
38 | 36 | ||
39 | - ContinuousResourceId(ImmutableList<Object> components, String name) { | ||
40 | - this.components = components; | ||
41 | - this.name = checkNotNull(name); | ||
42 | - } | ||
43 | - | ||
44 | ContinuousResourceId(ImmutableList.Builder<Object> parentComponents, Class<?> last) { | 37 | ContinuousResourceId(ImmutableList.Builder<Object> parentComponents, Class<?> last) { |
45 | this.components = parentComponents.add(last.getCanonicalName()).build(); | 38 | this.components = parentComponents.add(last.getCanonicalName()).build(); |
46 | this.name = last.getSimpleName(); | 39 | this.name = last.getSimpleName(); | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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 | + * Factory class for discrete-type resource related instances. | ||
22 | + */ | ||
23 | +@Beta | ||
24 | +public final class DiscreteFactory { | ||
25 | + private final DiscreteResourceId id; | ||
26 | + | ||
27 | + /** | ||
28 | + * Create an instance with the specified resource ID. | ||
29 | + * | ||
30 | + * @param id resource ID that is associated with the resource related instances | ||
31 | + * which will be created from this instance | ||
32 | + */ | ||
33 | + DiscreteFactory(DiscreteResourceId id) { | ||
34 | + this.id = id; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Returns the resource ID for discrete-type. | ||
39 | + * | ||
40 | + * @return discrete-type resource ID | ||
41 | + */ | ||
42 | + public DiscreteResourceId id() { | ||
43 | + return id; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * Returns the resource for discrete-type. | ||
48 | + * | ||
49 | + * @return discrete-type resource | ||
50 | + */ | ||
51 | + public DiscreteResource resource() { | ||
52 | + return new DiscreteResource(id); | ||
53 | + } | ||
54 | +} |
... | @@ -40,7 +40,7 @@ public final class DiscreteResource implements Resource { | ... | @@ -40,7 +40,7 @@ public final class DiscreteResource implements Resource { |
40 | this.id = id; | 40 | this.id = id; |
41 | } | 41 | } |
42 | 42 | ||
43 | - protected DiscreteResource() { | 43 | + DiscreteResource() { |
44 | this.id = ResourceId.ROOT; | 44 | this.id = ResourceId.ROOT; |
45 | } | 45 | } |
46 | 46 | ||
... | @@ -80,17 +80,17 @@ public final class DiscreteResource implements Resource { | ... | @@ -80,17 +80,17 @@ public final class DiscreteResource implements Resource { |
80 | public DiscreteResource child(Object child) { | 80 | public DiscreteResource child(Object child) { |
81 | checkArgument(!(child instanceof Class<?>)); | 81 | checkArgument(!(child instanceof Class<?>)); |
82 | 82 | ||
83 | - return new DiscreteResource(id.child(child)); | 83 | + return Resource.discrete(id.child(child)).resource(); |
84 | } | 84 | } |
85 | 85 | ||
86 | @Override | 86 | @Override |
87 | public ContinuousResource child(Class<?> child, double value) { | 87 | public ContinuousResource child(Class<?> child, double value) { |
88 | - return new ContinuousResource(id.child(child), value); | 88 | + return Resource.continuous(id.child(child)).resource(value); |
89 | } | 89 | } |
90 | 90 | ||
91 | @Override | 91 | @Override |
92 | public Optional<DiscreteResource> parent() { | 92 | public Optional<DiscreteResource> parent() { |
93 | - return id.parent().map(DiscreteResource::new); | 93 | + return id.parent().map(x -> Resource.discrete(x).resource()); |
94 | } | 94 | } |
95 | 95 | ||
96 | @Override | 96 | @Override | ... | ... |
... | @@ -50,17 +50,14 @@ public final class DiscreteResourceId extends ResourceId { | ... | @@ -50,17 +50,14 @@ public final class DiscreteResourceId extends ResourceId { |
50 | public DiscreteResourceId child(Object child) { | 50 | public DiscreteResourceId child(Object child) { |
51 | checkArgument(!(child instanceof Class<?>)); | 51 | checkArgument(!(child instanceof Class<?>)); |
52 | 52 | ||
53 | - return new DiscreteResourceId(ImmutableList.builder() | 53 | + return Resource.discrete(this, child).id(); |
54 | - .addAll(components) | ||
55 | - .add(child) | ||
56 | - .build()); | ||
57 | } | 54 | } |
58 | 55 | ||
59 | @Override | 56 | @Override |
60 | public ContinuousResourceId child(Class<?> child) { | 57 | public ContinuousResourceId child(Class<?> child) { |
61 | checkNotNull(child); | 58 | checkNotNull(child); |
62 | 59 | ||
63 | - return new ContinuousResourceId(ImmutableList.builder().addAll(components), child); | 60 | + return Resource.continuous(this, child).id(); |
64 | } | 61 | } |
65 | 62 | ||
66 | @Override | 63 | @Override | ... | ... |
... | @@ -16,14 +16,16 @@ | ... | @@ -16,14 +16,16 @@ |
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 | - | 19 | +import com.google.common.collect.ImmutableList; |
20 | import org.onosproject.net.DeviceId; | 20 | import org.onosproject.net.DeviceId; |
21 | import org.onosproject.net.PortNumber; | 21 | import org.onosproject.net.PortNumber; |
22 | 22 | ||
23 | +import java.util.Arrays; | ||
23 | import java.util.List; | 24 | import java.util.List; |
24 | import java.util.Optional; | 25 | import java.util.Optional; |
25 | 26 | ||
26 | import static com.google.common.base.Preconditions.checkArgument; | 27 | import static com.google.common.base.Preconditions.checkArgument; |
28 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
27 | 29 | ||
28 | /** | 30 | /** |
29 | * An object that represent a resource in a network. | 31 | * An object that represent a resource in a network. |
... | @@ -46,65 +48,6 @@ public interface Resource { | ... | @@ -46,65 +48,6 @@ public interface Resource { |
46 | 48 | ||
47 | DiscreteResource ROOT = new DiscreteResource(); | 49 | DiscreteResource ROOT = new DiscreteResource(); |
48 | 50 | ||
49 | - static DiscreteResource discrete(DeviceId device) { | ||
50 | - return new DiscreteResource(ResourceId.discrete(device)); | ||
51 | - } | ||
52 | - | ||
53 | - /** | ||
54 | - * Creates an resource path which represents a discrete-type resource from the specified components. | ||
55 | - * | ||
56 | - * @param device device ID which is the first component of the path | ||
57 | - * @param components following components of the path. The order represents hierarchical structure of the resource. | ||
58 | - * @return resource path instance | ||
59 | - */ | ||
60 | - static DiscreteResource discrete(DeviceId device, Object... components) { | ||
61 | - return new DiscreteResource(ResourceId.discrete(device, components)); | ||
62 | - } | ||
63 | - | ||
64 | - /** | ||
65 | - * Creates an resource path which represents a discrete-type resource from the specified components. | ||
66 | - * | ||
67 | - * @param device device ID which is the first component of the path | ||
68 | - * @param port port number which is the second component of the path | ||
69 | - * @param components following components of the path. The order represents hierarchical structure of the resource. | ||
70 | - * @return resource path instance | ||
71 | - */ | ||
72 | - static DiscreteResource discrete(DeviceId device, PortNumber port, Object... components) { | ||
73 | - return new DiscreteResource(ResourceId.discrete(device, port, components)); | ||
74 | - } | ||
75 | - | ||
76 | - /** | ||
77 | - * Creates an resource path which represents a continuous-type resource from the specified components. | ||
78 | - * | ||
79 | - * @param value amount of the resource | ||
80 | - * @param device device ID which is the first component of the path | ||
81 | - * @param components following components of the path. The order represents hierarchical structure of the resource. | ||
82 | - * The last element of this list must be an {@link Class} instance. Otherwise, this method throws | ||
83 | - * an IllegalArgumentException. | ||
84 | - * @return resource path instance | ||
85 | - */ | ||
86 | - static ContinuousResource continuous(double value, DeviceId device, Object... components) { | ||
87 | - checkArgument(components.length > 0, | ||
88 | - "Length of components must be greater thant 0, but " + components.length); | ||
89 | - | ||
90 | - return new ContinuousResource(ResourceId.continuous(device, components), value); | ||
91 | - } | ||
92 | - | ||
93 | - /** | ||
94 | - * Creates an resource path which represents a continuous-type resource from the specified components. | ||
95 | - * | ||
96 | - * @param value amount of the resource | ||
97 | - * @param device device ID which is the first component of the path. | ||
98 | - * @param port port number which is the second component of the path. | ||
99 | - * @param components following components of the path. The order represents hierarchical structure of the resource. | ||
100 | - * The last element of this list must be an {@link Class} instance. Otherwise, this method throws | ||
101 | - * an IllegalArgumentException. | ||
102 | - * @return resource path instance | ||
103 | - */ | ||
104 | - static ContinuousResource continuous(double value, DeviceId device, PortNumber port, Object... components) { | ||
105 | - return new ContinuousResource(ResourceId.continuous(device, port, components), value); | ||
106 | - } | ||
107 | - | ||
108 | /** | 51 | /** |
109 | * Returns the components of this resource path. | 52 | * Returns the components of this resource path. |
110 | * | 53 | * |
... | @@ -163,4 +106,189 @@ public interface Resource { | ... | @@ -163,4 +106,189 @@ public interface Resource { |
163 | * @return the ID of this resource path | 106 | * @return the ID of this resource path |
164 | */ | 107 | */ |
165 | ResourceId id(); | 108 | ResourceId id(); |
109 | + | ||
110 | + /** | ||
111 | + * Create a factory for discrete-type with the specified resource ID. | ||
112 | + * | ||
113 | + * @param id resource ID | ||
114 | + * @return {@link DiscreteFactory} | ||
115 | + */ | ||
116 | + static DiscreteFactory discrete(DiscreteResourceId id) { | ||
117 | + checkNotNull(id); | ||
118 | + | ||
119 | + return new DiscreteFactory(id); | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Creates a factory for discrete-type with the specified parent ID and child. | ||
124 | + * | ||
125 | + * @param parent ID of the parent | ||
126 | + * @param child child | ||
127 | + * @return {@link DiscreteFactory} | ||
128 | + */ | ||
129 | + static DiscreteFactory discrete(DiscreteResourceId parent, Object child) { | ||
130 | + checkNotNull(parent); | ||
131 | + checkNotNull(child); | ||
132 | + checkArgument(!(child instanceof Class<?>)); | ||
133 | + | ||
134 | + return new DiscreteFactory(new DiscreteResourceId(ImmutableList.builder() | ||
135 | + .addAll(parent.components()) | ||
136 | + .add(child) | ||
137 | + .build())); | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * Create a factory for discrete-type with the specified device ID. | ||
142 | + * | ||
143 | + * @param device device ID | ||
144 | + * @return {@link DiscreteFactory} | ||
145 | + */ | ||
146 | + static DiscreteFactory discrete(DeviceId device) { | ||
147 | + checkNotNull(device); | ||
148 | + | ||
149 | + return new DiscreteFactory(new DiscreteResourceId(ImmutableList.of(device))); | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Create a factory for discrete-type with the specified device ID and components. | ||
154 | + * | ||
155 | + * @param device device ID | ||
156 | + * @param components resource ID components other than the device ID | ||
157 | + * @return {@link DiscreteFactory} | ||
158 | + */ | ||
159 | + static DiscreteFactory discrete(DeviceId device, Object... components) { | ||
160 | + checkNotNull(device); | ||
161 | + checkNotNull(components); | ||
162 | + | ||
163 | + return new DiscreteFactory(new DiscreteResourceId(ImmutableList.builder() | ||
164 | + .add(device) | ||
165 | + .add(components) | ||
166 | + .build())); | ||
167 | + } | ||
168 | + | ||
169 | + /** | ||
170 | + * Create a factory for discrete-type with the specified device ID, port number and components. | ||
171 | + * | ||
172 | + * @param device device ID | ||
173 | + * @param port port number | ||
174 | + * @param components resource ID components other than the device ID and port number | ||
175 | + * @return {@link DiscreteFactory} | ||
176 | + */ | ||
177 | + static DiscreteFactory discrete(DeviceId device, PortNumber port, Object... components) { | ||
178 | + checkNotNull(device); | ||
179 | + checkNotNull(port); | ||
180 | + checkNotNull(components); | ||
181 | + | ||
182 | + return new DiscreteFactory(new DiscreteResourceId(ImmutableList.builder() | ||
183 | + .add(device) | ||
184 | + .add(port) | ||
185 | + .add(components) | ||
186 | + .build())); | ||
187 | + } | ||
188 | + | ||
189 | + /** | ||
190 | + * Create a factory for continuous-type with the specified resource ID. | ||
191 | + * | ||
192 | + * @param id resource ID | ||
193 | + * @return {@link ContinuousFactory} | ||
194 | + */ | ||
195 | + static ContinuousFactory continuous(ContinuousResourceId id) { | ||
196 | + checkNotNull(id); | ||
197 | + | ||
198 | + return new ContinuousFactory(id); | ||
199 | + } | ||
200 | + | ||
201 | + /** | ||
202 | + * Creates a factory for continuous-type wit the specified parent ID and child. | ||
203 | + * | ||
204 | + * @param parent ID of the parent | ||
205 | + * @param child child | ||
206 | + * @return {@link ContinuousFactory} | ||
207 | + */ | ||
208 | + static ContinuousFactory continuous(DiscreteResourceId parent, Class<?> child) { | ||
209 | + checkNotNull(parent); | ||
210 | + checkNotNull(child); | ||
211 | + | ||
212 | + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder() | ||
213 | + .addAll(parent.components()), child)); | ||
214 | + } | ||
215 | + | ||
216 | + /** | ||
217 | + * Create a factory for continuous-type with the specified device ID and type. | ||
218 | + * | ||
219 | + * @param device device ID | ||
220 | + * @param cls type of resource the returned factory will create | ||
221 | + * @return {@link ContinuousFactory} | ||
222 | + */ | ||
223 | + static ContinuousFactory continuous(DeviceId device, Class<?> cls) { | ||
224 | + checkNotNull(device); | ||
225 | + checkNotNull(cls); | ||
226 | + | ||
227 | + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder().add(device), cls)); | ||
228 | + } | ||
229 | + | ||
230 | + /** | ||
231 | + * Create a factory for continuous-type with the specified device ID and components. | ||
232 | + * The last element of the components must be a {@link Class} instance. Otherwise, | ||
233 | + * an {@link IllegalArgumentException} is thrown. | ||
234 | + * | ||
235 | + * @param device device ID | ||
236 | + * @param components resource ID components other than the device ID. | ||
237 | + * @return {@link ContinuousFactory} | ||
238 | + */ | ||
239 | + static ContinuousFactory continuous(DeviceId device, Object... components) { | ||
240 | + checkNotNull(device); | ||
241 | + checkNotNull(components); | ||
242 | + checkArgument(components.length > 1); | ||
243 | + | ||
244 | + Object last = components[components.length - 1]; | ||
245 | + checkArgument(last instanceof Class<?>); | ||
246 | + | ||
247 | + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder() | ||
248 | + .add(device) | ||
249 | + .add(Arrays.copyOfRange(components, 0, components.length - 1)), (Class<?>) last)); | ||
250 | + } | ||
251 | + | ||
252 | + /** | ||
253 | + * Create a factory for continuous-type with the specified device ID, port number and type. | ||
254 | + * | ||
255 | + * @param device device ID | ||
256 | + * @param port port number | ||
257 | + * @param cls type of resource the returned factory will create | ||
258 | + * @return {@link ContinuousFactory} | ||
259 | + */ | ||
260 | + static ContinuousFactory continuous(DeviceId device, PortNumber port, Class<?> cls) { | ||
261 | + checkNotNull(device); | ||
262 | + checkNotNull(port); | ||
263 | + checkNotNull(cls); | ||
264 | + | ||
265 | + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder() | ||
266 | + .add(device) | ||
267 | + .add(port), cls)); | ||
268 | + } | ||
269 | + | ||
270 | + /** | ||
271 | + * Create a factory for continuous-type with the specified device ID and components. | ||
272 | + * The last element of the components must be a {@link Class} instance. Otherwise, | ||
273 | + * an {@link IllegalArgumentException} is thrown. | ||
274 | + * | ||
275 | + * @param device device ID | ||
276 | + * @param port port number | ||
277 | + * @param components resource ID components other than the device ID and port number. | ||
278 | + * @return {@link ContinuousFactory} | ||
279 | + */ | ||
280 | + static ContinuousFactory continuous(DeviceId device, PortNumber port, Object... components) { | ||
281 | + checkNotNull(device); | ||
282 | + checkNotNull(port); | ||
283 | + checkNotNull(components); | ||
284 | + checkArgument(components.length > 1); | ||
285 | + | ||
286 | + Object last = components[components.length - 1]; | ||
287 | + checkArgument(last instanceof Class<?>); | ||
288 | + | ||
289 | + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder() | ||
290 | + .add(device) | ||
291 | + .add(port) | ||
292 | + .add(Arrays.copyOfRange(components, 0, components.length - 1)), (Class<?>) last)); | ||
293 | + } | ||
166 | } | 294 | } | ... | ... |
... | @@ -16,15 +16,9 @@ | ... | @@ -16,15 +16,9 @@ |
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.collect.ImmutableList; | ||
20 | -import org.onosproject.net.DeviceId; | ||
21 | -import org.onosproject.net.PortNumber; | ||
22 | 19 | ||
23 | -import java.util.Arrays; | ||
24 | import java.util.Optional; | 20 | import java.util.Optional; |
25 | 21 | ||
26 | -import static com.google.common.base.Preconditions.checkArgument; | ||
27 | - | ||
28 | /** | 22 | /** |
29 | * Represents identifier of resource. | 23 | * Represents identifier of resource. |
30 | * This class is exposed to public, but intended to use only in ResourceStore implementations. | 24 | * This class is exposed to public, but intended to use only in ResourceStore implementations. |
... | @@ -33,40 +27,6 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -33,40 +27,6 @@ import static com.google.common.base.Preconditions.checkArgument; |
33 | public abstract class ResourceId { | 27 | public abstract class ResourceId { |
34 | static final DiscreteResourceId ROOT = new DiscreteResourceId(); | 28 | static final DiscreteResourceId ROOT = new DiscreteResourceId(); |
35 | 29 | ||
36 | - static DiscreteResourceId discrete(DeviceId device, Object... components) { | ||
37 | - return new DiscreteResourceId(ImmutableList.builder() | ||
38 | - .add(device) | ||
39 | - .add(components) | ||
40 | - .build()); | ||
41 | - } | ||
42 | - | ||
43 | - static DiscreteResourceId discrete(DeviceId device, PortNumber port, Object... components) { | ||
44 | - return new DiscreteResourceId(ImmutableList.builder() | ||
45 | - .add(device) | ||
46 | - .add(port) | ||
47 | - .add(components) | ||
48 | - .build()); | ||
49 | - } | ||
50 | - | ||
51 | - static ContinuousResourceId continuous(DeviceId device, Object... components) { | ||
52 | - Object last = components[components.length - 1]; | ||
53 | - checkArgument(last instanceof Class<?>); | ||
54 | - | ||
55 | - return new ContinuousResourceId(ImmutableList.builder() | ||
56 | - .add(device) | ||
57 | - .add(Arrays.copyOfRange(components, 0, components.length - 1)), (Class<?>) last); | ||
58 | - } | ||
59 | - | ||
60 | - static ContinuousResourceId continuous(DeviceId device, PortNumber port, Object... components) { | ||
61 | - Object last = components[components.length - 1]; | ||
62 | - checkArgument(last instanceof Class<?>); | ||
63 | - | ||
64 | - return new ContinuousResourceId(ImmutableList.builder() | ||
65 | - .add(device) | ||
66 | - .add(port) | ||
67 | - .add(Arrays.copyOfRange(components, 0, components.length - 1)), (Class<?>) last); | ||
68 | - } | ||
69 | - | ||
70 | /** | 30 | /** |
71 | * Returns the parent resource ID of this instance. | 31 | * Returns the parent resource ID of this instance. |
72 | * | 32 | * | ... | ... |
... | @@ -32,9 +32,9 @@ public class ResourceAllocationTest { | ... | @@ -32,9 +32,9 @@ public class ResourceAllocationTest { |
32 | 32 | ||
33 | @Test | 33 | @Test |
34 | public void testEquals() { | 34 | public void testEquals() { |
35 | - ResourceAllocation alloc1 = new ResourceAllocation(Resource.discrete(D1, P1, VLAN1), IID1); | 35 | + ResourceAllocation alloc1 = new ResourceAllocation(Resource.discrete(D1, P1, VLAN1).resource(), IID1); |
36 | - ResourceAllocation sameAsAlloc1 = new ResourceAllocation(Resource.discrete(D1, P1, VLAN1), IID1); | 36 | + ResourceAllocation sameAsAlloc1 = new ResourceAllocation(Resource.discrete(D1, P1, VLAN1).resource(), IID1); |
37 | - ResourceAllocation alloc2 = new ResourceAllocation(Resource.discrete(D2, P1, VLAN1), IID1); | 37 | + ResourceAllocation alloc2 = new ResourceAllocation(Resource.discrete(D2, P1, VLAN1).resource(), IID1); |
38 | 38 | ||
39 | new EqualsTester() | 39 | new EqualsTester() |
40 | .addEqualityGroup(alloc1, sameAsAlloc1) | 40 | .addEqualityGroup(alloc1, sameAsAlloc1) | ... | ... |
... | @@ -32,20 +32,20 @@ public class ResourceIdTest { | ... | @@ -32,20 +32,20 @@ public class ResourceIdTest { |
32 | 32 | ||
33 | @Test | 33 | @Test |
34 | public void testDiscreteToString() { | 34 | public void testDiscreteToString() { |
35 | - ResourceId resource = ResourceId.discrete(D1, P1); | 35 | + ResourceId resource = Resource.discrete(D1, P1).id(); |
36 | 36 | ||
37 | assertThat(resource.toString(), is(Arrays.asList(D1, P1).toString())); | 37 | assertThat(resource.toString(), is(Arrays.asList(D1, P1).toString())); |
38 | } | 38 | } |
39 | 39 | ||
40 | @Test | 40 | @Test |
41 | public void testContinuousToString() { | 41 | public void testContinuousToString() { |
42 | - ResourceId resource = ResourceId.continuous(D1, P1, Bandwidth.class); | 42 | + ResourceId resource = Resource.continuous(D1, P1, Bandwidth.class).id(); |
43 | 43 | ||
44 | assertThat(resource.toString(), is(Arrays.asList(D1, P1, Bandwidth.class.getSimpleName()).toString())); | 44 | assertThat(resource.toString(), is(Arrays.asList(D1, P1, Bandwidth.class.getSimpleName()).toString())); |
45 | } | 45 | } |
46 | 46 | ||
47 | @Test(expected = IllegalArgumentException.class) | 47 | @Test(expected = IllegalArgumentException.class) |
48 | public void testInitWithNonClassInstance() { | 48 | public void testInitWithNonClassInstance() { |
49 | - ResourceId.continuous(D1, P1, BW1); | 49 | + Resource.continuous(D1, P1, BW1).id(); |
50 | } | 50 | } |
51 | } | 51 | } | ... | ... |
... | @@ -39,11 +39,11 @@ public class ResourceTest { | ... | @@ -39,11 +39,11 @@ public class ResourceTest { |
39 | 39 | ||
40 | @Test | 40 | @Test |
41 | public void testEquals() { | 41 | public void testEquals() { |
42 | - Resource resource1 = Resource.discrete(D1, P1, VLAN1); | 42 | + Resource resource1 = Resource.discrete(D1, P1, VLAN1).resource(); |
43 | - Resource sameAsResource1 = Resource.discrete(D1, P1, VLAN1); | 43 | + Resource sameAsResource1 = Resource.discrete(D1, P1, VLAN1).resource(); |
44 | - Resource resource2 = Resource.discrete(D2, P1, VLAN1); | 44 | + Resource resource2 = Resource.discrete(D2, P1, VLAN1).resource(); |
45 | - Resource resource3 = Resource.continuous(BW1.bps(), D1, P1, Bandwidth.class); | 45 | + Resource resource3 = Resource.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); |
46 | - Resource sameAsResource3 = Resource.continuous(BW1.bps(), D1, P1, Bandwidth.class); | 46 | + Resource sameAsResource3 = Resource.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); |
47 | 47 | ||
48 | new EqualsTester() | 48 | new EqualsTester() |
49 | .addEqualityGroup(resource1, sameAsResource1) | 49 | .addEqualityGroup(resource1, sameAsResource1) |
... | @@ -54,7 +54,7 @@ public class ResourceTest { | ... | @@ -54,7 +54,7 @@ public class ResourceTest { |
54 | 54 | ||
55 | @Test | 55 | @Test |
56 | public void testComponents() { | 56 | public void testComponents() { |
57 | - Resource port = Resource.discrete(D1, P1); | 57 | + Resource port = Resource.discrete(D1, P1).resource(); |
58 | 58 | ||
59 | assertThat(port.components(), contains(D1, P1)); | 59 | assertThat(port.components(), contains(D1, P1)); |
60 | } | 60 | } |
... | @@ -64,9 +64,9 @@ public class ResourceTest { | ... | @@ -64,9 +64,9 @@ public class ResourceTest { |
64 | ResourceId id1 = Resource.discrete(D1, P1, VLAN1).id(); | 64 | ResourceId id1 = Resource.discrete(D1, P1, VLAN1).id(); |
65 | ResourceId sameAsId1 = Resource.discrete(D1, P1, VLAN1).id(); | 65 | ResourceId sameAsId1 = Resource.discrete(D1, P1, VLAN1).id(); |
66 | ResourceId id2 = Resource.discrete(D2, P1, VLAN1).id(); | 66 | ResourceId id2 = Resource.discrete(D2, P1, VLAN1).id(); |
67 | - ResourceId id3 = Resource.continuous(BW1.bps(), D1, P1, Bandwidth.class).id(); | 67 | + ResourceId id3 = Resource.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()).id(); |
68 | // intentionally set a different value | 68 | // intentionally set a different value |
69 | - ResourceId sameAsId3 = Resource.continuous(BW2.bps(), D1, P1, Bandwidth.class).id(); | 69 | + ResourceId sameAsId3 = Resource.continuous(D1, P1, Bandwidth.class).resource(BW2.bps()).id(); |
70 | 70 | ||
71 | new EqualsTester() | 71 | new EqualsTester() |
72 | .addEqualityGroup(id1, sameAsId1) | 72 | .addEqualityGroup(id1, sameAsId1) |
... | @@ -76,30 +76,30 @@ public class ResourceTest { | ... | @@ -76,30 +76,30 @@ public class ResourceTest { |
76 | 76 | ||
77 | @Test | 77 | @Test |
78 | public void testChild() { | 78 | public void testChild() { |
79 | - Resource r1 = Resource.discrete(D1).child(P1); | 79 | + Resource r1 = Resource.discrete(D1).resource().child(P1); |
80 | - Resource sameAsR2 = Resource.discrete(D1, P1); | 80 | + Resource sameAsR2 = Resource.discrete(D1, P1).resource(); |
81 | 81 | ||
82 | assertThat(r1, is(sameAsR2)); | 82 | assertThat(r1, is(sameAsR2)); |
83 | } | 83 | } |
84 | 84 | ||
85 | @Test | 85 | @Test |
86 | public void testThereIsParent() { | 86 | public void testThereIsParent() { |
87 | - Resource resource = Resource.discrete(D1, P1, VLAN1); | 87 | + Resource resource = Resource.discrete(D1, P1, VLAN1).resource(); |
88 | - Resource parent = Resource.discrete(D1, P1); | 88 | + Resource parent = Resource.discrete(D1, P1).resource(); |
89 | 89 | ||
90 | assertThat(resource.parent(), is(Optional.of(parent))); | 90 | assertThat(resource.parent(), is(Optional.of(parent))); |
91 | } | 91 | } |
92 | 92 | ||
93 | @Test | 93 | @Test |
94 | public void testNoParent() { | 94 | public void testNoParent() { |
95 | - Resource resource = Resource.discrete(D1); | 95 | + Resource resource = Resource.discrete(D1).resource(); |
96 | 96 | ||
97 | assertThat(resource.parent(), is(Optional.of(Resource.ROOT))); | 97 | assertThat(resource.parent(), is(Optional.of(Resource.ROOT))); |
98 | } | 98 | } |
99 | 99 | ||
100 | @Test | 100 | @Test |
101 | public void testBase() { | 101 | public void testBase() { |
102 | - Resource resource = Resource.discrete(D1); | 102 | + Resource resource = Resource.discrete(D1).resource(); |
103 | 103 | ||
104 | DeviceId child = (DeviceId) resource.last(); | 104 | DeviceId child = (DeviceId) resource.last(); |
105 | assertThat(child, is(D1)); | 105 | assertThat(child, is(D1)); |
... | @@ -107,7 +107,7 @@ public class ResourceTest { | ... | @@ -107,7 +107,7 @@ public class ResourceTest { |
107 | 107 | ||
108 | @Test | 108 | @Test |
109 | public void testVolumeOfDiscrete() { | 109 | public void testVolumeOfDiscrete() { |
110 | - Resource resource = Resource.discrete(D1); | 110 | + Resource resource = Resource.discrete(D1).resource(); |
111 | 111 | ||
112 | DeviceId volume = resource.volume(); | 112 | DeviceId volume = resource.volume(); |
113 | assertThat(volume, is(D1)); | 113 | assertThat(volume, is(D1)); |
... | @@ -115,7 +115,7 @@ public class ResourceTest { | ... | @@ -115,7 +115,7 @@ public class ResourceTest { |
115 | 115 | ||
116 | @Test | 116 | @Test |
117 | public void testVolumeOfContinuous() { | 117 | public void testVolumeOfContinuous() { |
118 | - Resource resource = Resource.continuous(BW1.bps(), D1, P1, Bandwidth.class); | 118 | + Resource resource = Resource.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); |
119 | 119 | ||
120 | double volume = resource.volume(); | 120 | double volume = resource.volume(); |
121 | assertThat(volume, is(BW1.bps())); | 121 | assertThat(volume, is(BW1.bps())); | ... | ... |
... | @@ -125,8 +125,10 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { | ... | @@ -125,8 +125,10 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { |
125 | // TODO: introduce the concept of Tx and Rx resources of a port | 125 | // TODO: introduce the concept of Tx and Rx resources of a port |
126 | Set<Resource> resources = labels.entrySet().stream() | 126 | Set<Resource> resources = labels.entrySet().stream() |
127 | .flatMap(x -> Stream.of( | 127 | .flatMap(x -> Stream.of( |
128 | - Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()), | 128 | + Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()) |
129 | + .resource(), | ||
129 | Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue()) | 130 | Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue()) |
131 | + .resource() | ||
130 | )) | 132 | )) |
131 | .collect(Collectors.toSet()); | 133 | .collect(Collectors.toSet()); |
132 | List<org.onosproject.net.newresource.ResourceAllocation> allocations = | 134 | List<org.onosproject.net.newresource.ResourceAllocation> allocations = |
... | @@ -154,7 +156,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { | ... | @@ -154,7 +156,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { |
154 | } | 156 | } |
155 | 157 | ||
156 | private Set<MplsLabel> findMplsLabel(ConnectPoint cp) { | 158 | private Set<MplsLabel> findMplsLabel(ConnectPoint cp) { |
157 | - return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port())).stream() | 159 | + return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port()).resource()).stream() |
158 | .filter(x -> x.last() instanceof MplsLabel) | 160 | .filter(x -> x.last() instanceof MplsLabel) |
159 | .map(x -> (MplsLabel) x.last()) | 161 | .map(x -> (MplsLabel) x.last()) |
160 | .collect(Collectors.toSet()); | 162 | .collect(Collectors.toSet()); | ... | ... |
... | @@ -160,8 +160,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -160,8 +160,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
160 | log.debug("Compiling optical circuit intent between {} and {}", src, dst); | 160 | log.debug("Compiling optical circuit intent between {} and {}", src, dst); |
161 | 161 | ||
162 | // Reserve OduClt ports | 162 | // Reserve OduClt ports |
163 | - Resource srcPortResource = Resource.discrete(src.deviceId(), src.port()); | 163 | + Resource srcPortResource = Resource.discrete(src.deviceId(), src.port()).resource(); |
164 | - Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port()); | 164 | + Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port()).resource(); |
165 | List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource); | 165 | List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource); |
166 | if (allocation.isEmpty()) { | 166 | if (allocation.isEmpty()) { |
167 | throw new IntentCompilationException("Unable to reserve ports for intent " + intent); | 167 | throw new IntentCompilationException("Unable to reserve ports for intent " + intent); |
... | @@ -312,7 +312,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -312,7 +312,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
312 | if (ochCP != null) { | 312 | if (ochCP != null) { |
313 | OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); | 313 | OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); |
314 | Optional<IntentId> intentId = | 314 | Optional<IntentId> intentId = |
315 | - resourceService.getResourceAllocations(Resource.discrete(ochCP.deviceId(), ochCP.port())) | 315 | + resourceService.getResourceAllocations(Resource.discrete(ochCP.deviceId(), ochCP.port()).resource()) |
316 | .stream() | 316 | .stream() |
317 | .map(ResourceAllocation::consumer) | 317 | .map(ResourceAllocation::consumer) |
318 | .filter(x -> x instanceof IntentId) | 318 | .filter(x -> x instanceof IntentId) |
... | @@ -333,7 +333,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu | ... | @@ -333,7 +333,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu |
333 | } | 333 | } |
334 | 334 | ||
335 | Optional<IntentId> intentId = | 335 | Optional<IntentId> intentId = |
336 | - resourceService.getResourceAllocations(Resource.discrete(oduPort.deviceId(), port.number())) | 336 | + resourceService.getResourceAllocations( |
337 | + Resource.discrete(oduPort.deviceId(), port.number()).resource()) | ||
337 | .stream() | 338 | .stream() |
338 | .map(ResourceAllocation::consumer) | 339 | .map(ResourceAllocation::consumer) |
339 | .filter(x -> x instanceof IntentId) | 340 | .filter(x -> x instanceof IntentId) | ... | ... |
... | @@ -109,8 +109,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -109,8 +109,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
109 | log.debug("Compiling optical connectivity intent between {} and {}", src, dst); | 109 | log.debug("Compiling optical connectivity intent between {} and {}", src, dst); |
110 | 110 | ||
111 | // Reserve OCh ports | 111 | // Reserve OCh ports |
112 | - Resource srcPortResource = Resource.discrete(src.deviceId(), src.port()); | 112 | + Resource srcPortResource = Resource.discrete(src.deviceId(), src.port()).resource(); |
113 | - Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port()); | 113 | + Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port()).resource(); |
114 | List<org.onosproject.net.newresource.ResourceAllocation> allocation = | 114 | List<org.onosproject.net.newresource.ResourceAllocation> allocation = |
115 | resourceService.allocate(intent.id(), srcPortResource, dstPortResource); | 115 | resourceService.allocate(intent.id(), srcPortResource, dstPortResource); |
116 | if (allocation.isEmpty()) { | 116 | if (allocation.isEmpty()) { |
... | @@ -184,8 +184,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -184,8 +184,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
184 | List<OchSignal> minLambda = findFirstLambda(lambdas, slotCount()); | 184 | List<OchSignal> minLambda = findFirstLambda(lambdas, slotCount()); |
185 | List<Resource> lambdaResources = path.links().stream() | 185 | List<Resource> lambdaResources = path.links().stream() |
186 | .flatMap(x -> Stream.of( | 186 | .flatMap(x -> Stream.of( |
187 | - Resource.discrete(x.src().deviceId(), x.src().port()), | 187 | + Resource.discrete(x.src().deviceId(), x.src().port()).resource(), |
188 | - Resource.discrete(x.dst().deviceId(), x.dst().port()) | 188 | + Resource.discrete(x.dst().deviceId(), x.dst().port()).resource() |
189 | )) | 189 | )) |
190 | .flatMap(x -> minLambda.stream().map(l -> x.child(l))) | 190 | .flatMap(x -> minLambda.stream().map(l -> x.child(l))) |
191 | .collect(Collectors.toList()); | 191 | .collect(Collectors.toList()); |
... | @@ -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 | - Resource.discrete(x.src().deviceId(), x.src().port()), | 217 | + Resource.discrete(x.src().deviceId(), x.src().port()).resource(), |
218 | - Resource.discrete(x.dst().deviceId(), x.dst().port()) | 218 | + Resource.discrete(x.dst().deviceId(), x.dst().port()).resource() |
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)) | ... | ... |
... | @@ -252,8 +252,10 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { | ... | @@ -252,8 +252,10 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { |
252 | //same VLANID is used for both directions | 252 | //same VLANID is used for both directions |
253 | Set<Resource> resources = vlanIds.entrySet().stream() | 253 | Set<Resource> resources = vlanIds.entrySet().stream() |
254 | .flatMap(x -> Stream.of( | 254 | .flatMap(x -> Stream.of( |
255 | - Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()), | 255 | + Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()) |
256 | + .resource(), | ||
256 | Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue()) | 257 | Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue()) |
258 | + .resource() | ||
257 | )) | 259 | )) |
258 | .collect(Collectors.toSet()); | 260 | .collect(Collectors.toSet()); |
259 | List<org.onosproject.net.newresource.ResourceAllocation> allocations = | 261 | List<org.onosproject.net.newresource.ResourceAllocation> allocations = |
... | @@ -280,7 +282,7 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { | ... | @@ -280,7 +282,7 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { |
280 | } | 282 | } |
281 | 283 | ||
282 | private Set<VlanId> findVlanId(ConnectPoint cp) { | 284 | private Set<VlanId> findVlanId(ConnectPoint cp) { |
283 | - return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port())).stream() | 285 | + return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port()).resource()).stream() |
284 | .filter(x -> x.last() instanceof VlanId) | 286 | .filter(x -> x.last() instanceof VlanId) |
285 | .map(x -> (VlanId) x.last()) | 287 | .map(x -> (VlanId) x.last()) |
286 | .collect(Collectors.toSet()); | 288 | .collect(Collectors.toSet()); | ... | ... |
... | @@ -118,15 +118,15 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -118,15 +118,15 @@ final class ResourceDeviceListener implements DeviceListener { |
118 | } | 118 | } |
119 | 119 | ||
120 | private void registerDeviceResource(Device device) { | 120 | private void registerDeviceResource(Device device) { |
121 | - executor.submit(() -> adminService.registerResources(Resource.discrete(device.id()))); | 121 | + executor.submit(() -> adminService.registerResources(Resource.discrete(device.id()).resource())); |
122 | } | 122 | } |
123 | 123 | ||
124 | private void unregisterDeviceResource(Device device) { | 124 | private void unregisterDeviceResource(Device device) { |
125 | - executor.submit(() -> adminService.unregisterResources(Resource.discrete(device.id()))); | 125 | + executor.submit(() -> adminService.unregisterResources(Resource.discrete(device.id()).resource())); |
126 | } | 126 | } |
127 | 127 | ||
128 | private void registerPortResource(Device device, Port port) { | 128 | private void registerPortResource(Device device, Port port) { |
129 | - Resource portPath = Resource.discrete(device.id(), port.number()); | 129 | + Resource portPath = Resource.discrete(device.id(), port.number()).resource(); |
130 | executor.submit(() -> { | 130 | executor.submit(() -> { |
131 | adminService.registerResources(portPath); | 131 | adminService.registerResources(portPath); |
132 | 132 | ||
... | @@ -174,7 +174,7 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -174,7 +174,7 @@ final class ResourceDeviceListener implements DeviceListener { |
174 | } | 174 | } |
175 | 175 | ||
176 | private void unregisterPortResource(Device device, Port port) { | 176 | private void unregisterPortResource(Device device, Port port) { |
177 | - Resource resource = Resource.discrete(device.id(), port.number()); | 177 | + Resource resource = Resource.discrete(device.id(), port.number()).resource(); |
178 | executor.submit(() -> adminService.unregisterResources(resource)); | 178 | executor.submit(() -> adminService.unregisterResources(resource)); |
179 | } | 179 | } |
180 | 180 | ... | ... |
... | @@ -93,9 +93,9 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { | ... | @@ -93,9 +93,9 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { |
93 | 93 | ||
94 | switch (event.type()) { | 94 | switch (event.type()) { |
95 | case CONFIG_ADDED: | 95 | case CONFIG_ADDED: |
96 | - if (!adminService.registerResources(continuous(bwCapacity.capacity().bps(), | 96 | + if (!adminService.registerResources(continuous(cp.deviceId(), |
97 | - cp.deviceId(), | 97 | + cp.port(), Bandwidth.class) |
98 | - cp.port(), Bandwidth.class))) { | 98 | + .resource(bwCapacity.capacity().bps()))) { |
99 | log.info("Failed to register Bandwidth for {}, attempting update", cp); | 99 | log.info("Failed to register Bandwidth for {}, attempting update", cp); |
100 | 100 | ||
101 | // Bandwidth based on port speed, was probably already registered. | 101 | // Bandwidth based on port speed, was probably already registered. |
... | @@ -115,10 +115,9 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { | ... | @@ -115,10 +115,9 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { |
115 | 115 | ||
116 | case CONFIG_REMOVED: | 116 | case CONFIG_REMOVED: |
117 | // FIXME Following should be an update to the value based on port speed | 117 | // FIXME Following should be an update to the value based on port speed |
118 | - if (!adminService.unregisterResources(continuous(0, | 118 | + if (!adminService.unregisterResources(continuous(cp.deviceId(), |
119 | - cp.deviceId(), | ||
120 | cp.port(), | 119 | cp.port(), |
121 | - Bandwidth.class))) { | 120 | + Bandwidth.class).resource(0))) { |
122 | log.warn("Failed to unregister Bandwidth for {}", cp); | 121 | log.warn("Failed to unregister Bandwidth for {}", cp); |
123 | } | 122 | } |
124 | break; | 123 | break; |
... | @@ -148,13 +147,12 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { | ... | @@ -148,13 +147,12 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { |
148 | // but both unregisterResources(..) and registerResources(..) | 147 | // but both unregisterResources(..) and registerResources(..) |
149 | // returns true (success) | 148 | // returns true (success) |
150 | 149 | ||
151 | - if (!adminService.unregisterResources(continuous(0, cp.deviceId(), cp.port(), Bandwidth.class))) { | 150 | + if (!adminService.unregisterResources(continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(0))) { |
152 | log.warn("unregisterResources for {} failed", cp); | 151 | log.warn("unregisterResources for {} failed", cp); |
153 | } | 152 | } |
154 | - return adminService.registerResources(continuous(bwCapacity.capacity().bps(), | 153 | + return adminService.registerResources(continuous(cp.deviceId(), |
155 | - cp.deviceId(), | ||
156 | cp.port(), | 154 | cp.port(), |
157 | - Bandwidth.class)); | 155 | + Bandwidth.class).resource(bwCapacity.capacity().bps())); |
158 | } | 156 | } |
159 | 157 | ||
160 | } | 158 | } | ... | ... |
... | @@ -232,7 +232,7 @@ public class ObjectiveTrackerTest { | ... | @@ -232,7 +232,7 @@ public class ObjectiveTrackerTest { |
232 | @Test | 232 | @Test |
233 | public void testResourceEvent() throws Exception { | 233 | public void testResourceEvent() throws Exception { |
234 | ResourceEvent event = new ResourceEvent(RESOURCE_ADDED, | 234 | ResourceEvent event = new ResourceEvent(RESOURCE_ADDED, |
235 | - Resource.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(1))); | 235 | + Resource.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(1)).resource()); |
236 | resourceListener.event(event); | 236 | resourceListener.event(event); |
237 | 237 | ||
238 | assertThat( | 238 | assertThat( | ... | ... |
... | @@ -388,7 +388,7 @@ public class KryoSerializerTest { | ... | @@ -388,7 +388,7 @@ public class KryoSerializerTest { |
388 | 388 | ||
389 | @Test | 389 | @Test |
390 | public void testResource() { | 390 | public void testResource() { |
391 | - testSerializedEquals(Resource.discrete(DID1, P1, VLAN1)); | 391 | + testSerializedEquals(Resource.discrete(DID1, P1, VLAN1).resource()); |
392 | } | 392 | } |
393 | 393 | ||
394 | @Test | 394 | @Test |
... | @@ -399,7 +399,7 @@ public class KryoSerializerTest { | ... | @@ -399,7 +399,7 @@ public class KryoSerializerTest { |
399 | @Test | 399 | @Test |
400 | public void testResourceAllocation() { | 400 | public void testResourceAllocation() { |
401 | testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation( | 401 | testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation( |
402 | - Resource.discrete(DID1, P1, VLAN1), | 402 | + Resource.discrete(DID1, P1, VLAN1).resource(), |
403 | IntentId.valueOf(30))); | 403 | IntentId.valueOf(30))); |
404 | } | 404 | } |
405 | 405 | ... | ... |
-
Please register or login to post a comment