Sho SHIMIZU

Move static factory methods to the utility class

Change-Id: Icf458adf78f51823e4ffa31346595fa9716485bf
Showing 19 changed files with 302 additions and 266 deletions
...@@ -35,6 +35,7 @@ import org.onosproject.net.newresource.Resource; ...@@ -35,6 +35,7 @@ import org.onosproject.net.newresource.Resource;
35 import org.onosproject.net.newresource.ResourceService; 35 import org.onosproject.net.newresource.ResourceService;
36 36
37 import com.google.common.base.Strings; 37 import com.google.common.base.Strings;
38 +import org.onosproject.net.newresource.Resources;
38 39
39 /** 40 /**
40 * Lists allocated resources. 41 * Lists allocated resources.
...@@ -106,7 +107,7 @@ public class AllocationsCommand extends AbstractShellCommand { ...@@ -106,7 +107,7 @@ public class AllocationsCommand extends AbstractShellCommand {
106 // TODO: Current design cannot deal with sub-resources 107 // TODO: Current design cannot deal with sub-resources
107 // (e.g., TX/RX under Port) 108 // (e.g., TX/RX under Port)
108 109
109 - Resource resource = Resource.discrete(did, num).resource(); 110 + Resource resource = Resources.discrete(did, num).resource();
110 if (lambda) { 111 if (lambda) {
111 //print("Lambda resources:"); 112 //print("Lambda resources:");
112 Collection<ResourceAllocation> allocations 113 Collection<ResourceAllocation> allocations
......
...@@ -46,6 +46,7 @@ import com.google.common.collect.Multimap; ...@@ -46,6 +46,7 @@ import com.google.common.collect.Multimap;
46 import com.google.common.collect.Range; 46 import com.google.common.collect.Range;
47 import com.google.common.collect.RangeSet; 47 import com.google.common.collect.RangeSet;
48 import com.google.common.collect.TreeRangeSet; 48 import com.google.common.collect.TreeRangeSet;
49 +import org.onosproject.net.newresource.Resources;
49 50
50 /** 51 /**
51 * Lists available resources. 52 * Lists available resources.
...@@ -89,11 +90,11 @@ public class ResourcesCommand extends AbstractShellCommand { ...@@ -89,11 +90,11 @@ public class ResourcesCommand extends AbstractShellCommand {
89 DeviceId deviceId = deviceId(deviceIdStr); 90 DeviceId deviceId = deviceId(deviceIdStr);
90 PortNumber portNumber = PortNumber.fromString(portNumberStr); 91 PortNumber portNumber = PortNumber.fromString(portNumberStr);
91 92
92 - printResource(Resource.discrete(deviceId, portNumber).resource(), 0); 93 + printResource(Resources.discrete(deviceId, portNumber).resource(), 0);
93 } else if (deviceIdStr != null) { 94 } else if (deviceIdStr != null) {
94 DeviceId deviceId = deviceId(deviceIdStr); 95 DeviceId deviceId = deviceId(deviceIdStr);
95 96
96 - printResource(Resource.discrete(deviceId).resource(), 0); 97 + printResource(Resources.discrete(deviceId).resource(), 0);
97 } else { 98 } else {
98 printResource(Resource.ROOT, 0); 99 printResource(Resource.ROOT, 0);
99 } 100 }
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
15 */ 15 */
16 package org.onosproject.cli.net; 16 package org.onosproject.cli.net;
17 17
18 -import static org.onosproject.net.newresource.Resource.discrete;
19 -
20 import java.util.Optional; 18 import java.util.Optional;
21 19
22 import org.apache.karaf.shell.commands.Argument; 20 import org.apache.karaf.shell.commands.Argument;
...@@ -33,6 +31,7 @@ import org.onosproject.net.newresource.ResourceAllocation; ...@@ -33,6 +31,7 @@ import org.onosproject.net.newresource.ResourceAllocation;
33 import org.onosproject.net.newresource.ResourceConsumer; 31 import org.onosproject.net.newresource.ResourceConsumer;
34 import org.onosproject.net.newresource.Resource; 32 import org.onosproject.net.newresource.Resource;
35 import org.onosproject.net.newresource.ResourceService; 33 import org.onosproject.net.newresource.ResourceService;
34 +import org.onosproject.net.newresource.Resources;
36 35
37 /** 36 /**
38 * Test tool to allocate resources. 37 * Test tool to allocate resources.
...@@ -73,8 +72,8 @@ public class TestAllocateResource extends AbstractShellCommand { ...@@ -73,8 +72,8 @@ public class TestAllocateResource extends AbstractShellCommand {
73 72
74 ResourceConsumer consumer = IntentId.valueOf(nIntendId); 73 ResourceConsumer consumer = IntentId.valueOf(nIntendId);
75 74
76 - Resource resource = discrete(did, portNum, 75 + Resource resource = Resources.discrete(did, portNum,
77 - createLambda(Integer.parseInt(lambda))).resource(); 76 + createLambda(Integer.parseInt(lambda))).resource();
78 77
79 Optional<ResourceAllocation> allocate = resourceService.allocate(consumer, resource); 78 Optional<ResourceAllocation> allocate = resourceService.allocate(consumer, resource);
80 if (allocate.isPresent()) { 79 if (allocate.isPresent()) {
......
...@@ -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(x -> Resource.discrete(x).resource()); 101 + return id.parent().map(x -> Resources.discrete(x).resource());
102 } 102 }
103 103
104 @Override 104 @Override
......
...@@ -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 Resource.discrete(id.child(child)).resource(); 83 + return Resources.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 Resource.continuous(id.child(child)).resource(value); 88 + return Resources.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(x -> Resource.discrete(x).resource()); 93 + return id.parent().map(x -> Resources.discrete(x).resource());
94 } 94 }
95 95
96 @Override 96 @Override
......
...@@ -50,14 +50,14 @@ public final class DiscreteResourceId extends ResourceId { ...@@ -50,14 +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 Resource.discrete(this, child).id(); 53 + return Resources.discrete(this, child).id();
54 } 54 }
55 55
56 @Override 56 @Override
57 public ContinuousResourceId child(Class<?> child) { 57 public ContinuousResourceId child(Class<?> child) {
58 checkNotNull(child); 58 checkNotNull(child);
59 59
60 - return Resource.continuous(this, child).id(); 60 + return Resources.continuous(this, child).id();
61 } 61 }
62 62
63 @Override 63 @Override
......
...@@ -16,17 +16,10 @@ ...@@ -16,17 +16,10 @@
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.List; 20 import java.util.List;
25 import java.util.Optional; 21 import java.util.Optional;
26 22
27 -import static com.google.common.base.Preconditions.checkArgument;
28 -import static com.google.common.base.Preconditions.checkNotNull;
29 -
30 /** 23 /**
31 * An object that represent a resource in a network. 24 * An object that represent a resource in a network.
32 * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is 25 * A Resource can represents path-like hierarchical structure with its ID. An ID of resource is
...@@ -106,189 +99,4 @@ public interface Resource { ...@@ -106,189 +99,4 @@ public interface Resource {
106 * @return the ID of this resource path 99 * @return the ID of this resource path
107 */ 100 */
108 ResourceId id(); 101 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 - }
294 } 102 }
......
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 +import com.google.common.collect.ImmutableList;
20 +import org.onosproject.net.DeviceId;
21 +import org.onosproject.net.PortNumber;
22 +
23 +import java.util.Arrays;
24 +
25 +import static com.google.common.base.Preconditions.checkArgument;
26 +import static com.google.common.base.Preconditions.checkNotNull;
27 +
28 +/**
29 + * Utility class for resource related classes.
30 + */
31 +@Beta
32 +public final class Resources {
33 + // public construction is prohibited
34 + private Resources() {}
35 +
36 + /**
37 + * Create a factory for discrete-type with the specified resource ID.
38 + *
39 + * @param id resource ID
40 + * @return {@link DiscreteFactory}
41 + */
42 + public static DiscreteFactory discrete(DiscreteResourceId id) {
43 + checkNotNull(id);
44 +
45 + return new DiscreteFactory(id);
46 + }
47 +
48 + /**
49 + * Creates a factory for discrete-type with the specified parent ID and child.
50 + *
51 + * @param parent ID of the parent
52 + * @param child child
53 + * @return {@link DiscreteFactory}
54 + */
55 + public static DiscreteFactory discrete(DiscreteResourceId parent, Object child) {
56 + checkNotNull(parent);
57 + checkNotNull(child);
58 + checkArgument(!(child instanceof Class<?>));
59 +
60 + return new DiscreteFactory(new DiscreteResourceId(ImmutableList.builder()
61 + .addAll(parent.components())
62 + .add(child)
63 + .build()));
64 + }
65 +
66 + /**
67 + * Create a factory for discrete-type with the specified device ID.
68 + *
69 + * @param device device ID
70 + * @return {@link DiscreteFactory}
71 + */
72 + public static DiscreteFactory discrete(DeviceId device) {
73 + checkNotNull(device);
74 +
75 + return new DiscreteFactory(new DiscreteResourceId(ImmutableList.of(device)));
76 + }
77 +
78 + /**
79 + * Create a factory for discrete-type with the specified device ID and components.
80 + *
81 + * @param device device ID
82 + * @param components resource ID components other than the device ID
83 + * @return {@link DiscreteFactory}
84 + */
85 + public static DiscreteFactory discrete(DeviceId device, Object... components) {
86 + checkNotNull(device);
87 + checkNotNull(components);
88 +
89 + return new DiscreteFactory(new DiscreteResourceId(ImmutableList.builder()
90 + .add(device)
91 + .add(components)
92 + .build()));
93 + }
94 +
95 + /**
96 + * Create a factory for discrete-type with the specified device ID, port number and components.
97 + *
98 + * @param device device ID
99 + * @param port port number
100 + * @param components resource ID components other than the device ID and port number
101 + * @return {@link DiscreteFactory}
102 + */
103 + public static DiscreteFactory discrete(DeviceId device, PortNumber port, Object... components) {
104 + checkNotNull(device);
105 + checkNotNull(port);
106 + checkNotNull(components);
107 +
108 + return new DiscreteFactory(new DiscreteResourceId(ImmutableList.builder()
109 + .add(device)
110 + .add(port)
111 + .add(components)
112 + .build()));
113 + }
114 +
115 + /**
116 + * Create a factory for continuous-type with the specified resource ID.
117 + *
118 + * @param id resource ID
119 + * @return {@link ContinuousFactory}
120 + */
121 + public static ContinuousFactory continuous(ContinuousResourceId id) {
122 + checkNotNull(id);
123 +
124 + return new ContinuousFactory(id);
125 + }
126 +
127 + /**
128 + * Creates a factory for continuous-type wit the specified parent ID and child.
129 + *
130 + * @param parent ID of the parent
131 + * @param child child
132 + * @return {@link ContinuousFactory}
133 + */
134 + public static ContinuousFactory continuous(DiscreteResourceId parent, Class<?> child) {
135 + checkNotNull(parent);
136 + checkNotNull(child);
137 +
138 + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder()
139 + .addAll(parent.components()), child));
140 + }
141 +
142 + /**
143 + * Create a factory for continuous-type with the specified device ID and type.
144 + *
145 + * @param device device ID
146 + * @param cls type of resource the returned factory will create
147 + * @return {@link ContinuousFactory}
148 + */
149 + public static ContinuousFactory continuous(DeviceId device, Class<?> cls) {
150 + checkNotNull(device);
151 + checkNotNull(cls);
152 +
153 + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder().add(device), cls));
154 + }
155 +
156 + /**
157 + * Create a factory for continuous-type with the specified device ID and components.
158 + * The last element of the components must be a {@link Class} instance. Otherwise,
159 + * an {@link IllegalArgumentException} is thrown.
160 + *
161 + * @param device device ID
162 + * @param components resource ID components other than the device ID.
163 + * @return {@link ContinuousFactory}
164 + */
165 + public static ContinuousFactory continuous(DeviceId device, Object... components) {
166 + checkNotNull(device);
167 + checkNotNull(components);
168 + checkArgument(components.length > 1);
169 +
170 + Object last = components[components.length - 1];
171 + checkArgument(last instanceof Class<?>);
172 +
173 + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder()
174 + .add(device)
175 + .add(Arrays.copyOfRange(components, 0, components.length - 1)), (Class<?>) last));
176 + }
177 +
178 + /**
179 + * Create a factory for continuous-type with the specified device ID, port number and type.
180 + *
181 + * @param device device ID
182 + * @param port port number
183 + * @param cls type of resource the returned factory will create
184 + * @return {@link ContinuousFactory}
185 + */
186 + public static ContinuousFactory continuous(DeviceId device, PortNumber port, Class<?> cls) {
187 + checkNotNull(device);
188 + checkNotNull(port);
189 + checkNotNull(cls);
190 +
191 + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder()
192 + .add(device)
193 + .add(port), cls));
194 + }
195 +
196 + /**
197 + * Create a factory for continuous-type with the specified device ID and components.
198 + * The last element of the components must be a {@link Class} instance. Otherwise,
199 + * an {@link IllegalArgumentException} is thrown.
200 + *
201 + * @param device device ID
202 + * @param port port number
203 + * @param components resource ID components other than the device ID and port number.
204 + * @return {@link ContinuousFactory}
205 + */
206 + public static ContinuousFactory continuous(DeviceId device, PortNumber port, Object... components) {
207 + checkNotNull(device);
208 + checkNotNull(port);
209 + checkNotNull(components);
210 + checkArgument(components.length > 1);
211 +
212 + Object last = components[components.length - 1];
213 + checkArgument(last instanceof Class<?>);
214 +
215 + return new ContinuousFactory(new ContinuousResourceId(ImmutableList.builder()
216 + .add(device)
217 + .add(port)
218 + .add(Arrays.copyOfRange(components, 0, components.length - 1)), (Class<?>) last));
219 + }
220 +}
...@@ -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).resource(), IID1); 35 + ResourceAllocation alloc1 = new ResourceAllocation(Resources.discrete(D1, P1, VLAN1).resource(), IID1);
36 - ResourceAllocation sameAsAlloc1 = new ResourceAllocation(Resource.discrete(D1, P1, VLAN1).resource(), IID1); 36 + ResourceAllocation sameAsAlloc1 = new ResourceAllocation(Resources.discrete(D1, P1, VLAN1).resource(), IID1);
37 - ResourceAllocation alloc2 = new ResourceAllocation(Resource.discrete(D2, P1, VLAN1).resource(), IID1); 37 + ResourceAllocation alloc2 = new ResourceAllocation(Resources.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 = Resource.discrete(D1, P1).id(); 35 + ResourceId resource = Resources.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 = Resource.continuous(D1, P1, Bandwidth.class).id(); 42 + ResourceId resource = Resources.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 - Resource.continuous(D1, P1, BW1).id(); 49 + Resources.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).resource(); 42 + Resource resource1 = Resources.discrete(D1, P1, VLAN1).resource();
43 - Resource sameAsResource1 = Resource.discrete(D1, P1, VLAN1).resource(); 43 + Resource sameAsResource1 = Resources.discrete(D1, P1, VLAN1).resource();
44 - Resource resource2 = Resource.discrete(D2, P1, VLAN1).resource(); 44 + Resource resource2 = Resources.discrete(D2, P1, VLAN1).resource();
45 - Resource resource3 = Resource.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); 45 + Resource resource3 = Resources.continuous(D1, P1, Bandwidth.class).resource(BW1.bps());
46 - Resource sameAsResource3 = Resource.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()); 46 + Resource sameAsResource3 = Resources.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,19 +54,19 @@ public class ResourceTest { ...@@ -54,19 +54,19 @@ public class ResourceTest {
54 54
55 @Test 55 @Test
56 public void testComponents() { 56 public void testComponents() {
57 - Resource port = Resource.discrete(D1, P1).resource(); 57 + Resource port = Resources.discrete(D1, P1).resource();
58 58
59 assertThat(port.components(), contains(D1, P1)); 59 assertThat(port.components(), contains(D1, P1));
60 } 60 }
61 61
62 @Test 62 @Test
63 public void testIdEquality() { 63 public void testIdEquality() {
64 - ResourceId id1 = Resource.discrete(D1, P1, VLAN1).id(); 64 + ResourceId id1 = Resources.discrete(D1, P1, VLAN1).id();
65 - ResourceId sameAsId1 = Resource.discrete(D1, P1, VLAN1).id(); 65 + ResourceId sameAsId1 = Resources.discrete(D1, P1, VLAN1).id();
66 - ResourceId id2 = Resource.discrete(D2, P1, VLAN1).id(); 66 + ResourceId id2 = Resources.discrete(D2, P1, VLAN1).id();
67 - ResourceId id3 = Resource.continuous(D1, P1, Bandwidth.class).resource(BW1.bps()).id(); 67 + ResourceId id3 = Resources.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(D1, P1, Bandwidth.class).resource(BW2.bps()).id(); 69 + ResourceId sameAsId3 = Resources.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).resource().child(P1); 79 + Resource r1 = Resources.discrete(D1).resource().child(P1);
80 - Resource sameAsR2 = Resource.discrete(D1, P1).resource(); 80 + Resource sameAsR2 = Resources.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).resource(); 87 + Resource resource = Resources.discrete(D1, P1, VLAN1).resource();
88 - Resource parent = Resource.discrete(D1, P1).resource(); 88 + Resource parent = Resources.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).resource(); 95 + Resource resource = Resources.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).resource(); 102 + Resource resource = Resources.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).resource(); 110 + Resource resource = Resources.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(D1, P1, Bandwidth.class).resource(BW1.bps()); 118 + Resource resource = Resources.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()));
......
...@@ -51,6 +51,7 @@ import org.onosproject.net.intent.IntentExtensionService; ...@@ -51,6 +51,7 @@ import org.onosproject.net.intent.IntentExtensionService;
51 import org.onosproject.net.intent.MplsPathIntent; 51 import org.onosproject.net.intent.MplsPathIntent;
52 import org.onosproject.net.newresource.Resource; 52 import org.onosproject.net.newresource.Resource;
53 import org.onosproject.net.newresource.ResourceService; 53 import org.onosproject.net.newresource.ResourceService;
54 +import org.onosproject.net.newresource.Resources;
54 import org.onosproject.net.resource.link.LinkResourceAllocations; 55 import org.onosproject.net.resource.link.LinkResourceAllocations;
55 import org.slf4j.Logger; 56 import org.slf4j.Logger;
56 57
...@@ -125,9 +126,9 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { ...@@ -125,9 +126,9 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
125 // TODO: introduce the concept of Tx and Rx resources of a port 126 // TODO: introduce the concept of Tx and Rx resources of a port
126 Set<Resource> resources = labels.entrySet().stream() 127 Set<Resource> resources = labels.entrySet().stream()
127 .flatMap(x -> Stream.of( 128 .flatMap(x -> Stream.of(
128 - Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()) 129 + Resources.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue())
129 .resource(), 130 .resource(),
130 - Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue()) 131 + Resources.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
131 .resource() 132 .resource()
132 )) 133 ))
133 .collect(Collectors.toSet()); 134 .collect(Collectors.toSet());
...@@ -156,7 +157,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { ...@@ -156,7 +157,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> {
156 } 157 }
157 158
158 private Set<MplsLabel> findMplsLabel(ConnectPoint cp) { 159 private Set<MplsLabel> findMplsLabel(ConnectPoint cp) {
159 - return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port()).resource()).stream() 160 + return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).resource()).stream()
160 .filter(x -> x.last() instanceof MplsLabel) 161 .filter(x -> x.last() instanceof MplsLabel)
161 .map(x -> (MplsLabel) x.last()) 162 .map(x -> (MplsLabel) x.last())
162 .collect(Collectors.toSet()); 163 .collect(Collectors.toSet());
......
...@@ -52,6 +52,7 @@ import org.onosproject.net.intent.impl.IntentCompilationException; ...@@ -52,6 +52,7 @@ import org.onosproject.net.intent.impl.IntentCompilationException;
52 import org.onosproject.net.newresource.ResourceAllocation; 52 import org.onosproject.net.newresource.ResourceAllocation;
53 import org.onosproject.net.newresource.Resource; 53 import org.onosproject.net.newresource.Resource;
54 import org.onosproject.net.newresource.ResourceService; 54 import org.onosproject.net.newresource.ResourceService;
55 +import org.onosproject.net.newresource.Resources;
55 import org.onosproject.net.resource.device.IntentSetMultimap; 56 import org.onosproject.net.resource.device.IntentSetMultimap;
56 import org.onosproject.net.resource.link.LinkResourceAllocations; 57 import org.onosproject.net.resource.link.LinkResourceAllocations;
57 import org.osgi.service.component.ComponentContext; 58 import org.osgi.service.component.ComponentContext;
...@@ -160,8 +161,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -160,8 +161,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
160 log.debug("Compiling optical circuit intent between {} and {}", src, dst); 161 log.debug("Compiling optical circuit intent between {} and {}", src, dst);
161 162
162 // Reserve OduClt ports 163 // Reserve OduClt ports
163 - Resource srcPortResource = Resource.discrete(src.deviceId(), src.port()).resource(); 164 + Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
164 - Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port()).resource(); 165 + Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
165 List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource); 166 List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource);
166 if (allocation.isEmpty()) { 167 if (allocation.isEmpty()) {
167 throw new IntentCompilationException("Unable to reserve ports for intent " + intent); 168 throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
...@@ -312,7 +313,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -312,7 +313,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
312 if (ochCP != null) { 313 if (ochCP != null) {
313 OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); 314 OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port());
314 Optional<IntentId> intentId = 315 Optional<IntentId> intentId =
315 - resourceService.getResourceAllocations(Resource.discrete(ochCP.deviceId(), ochCP.port()).resource()) 316 + resourceService.getResourceAllocations(
317 + Resources.discrete(ochCP.deviceId(), ochCP.port()).resource())
316 .stream() 318 .stream()
317 .map(ResourceAllocation::consumer) 319 .map(ResourceAllocation::consumer)
318 .filter(x -> x instanceof IntentId) 320 .filter(x -> x instanceof IntentId)
...@@ -334,7 +336,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu ...@@ -334,7 +336,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu
334 336
335 Optional<IntentId> intentId = 337 Optional<IntentId> intentId =
336 resourceService.getResourceAllocations( 338 resourceService.getResourceAllocations(
337 - Resource.discrete(oduPort.deviceId(), port.number()).resource()) 339 + Resources.discrete(oduPort.deviceId(), port.number()).resource())
338 .stream() 340 .stream()
339 .map(ResourceAllocation::consumer) 341 .map(ResourceAllocation::consumer)
340 .filter(x -> x instanceof IntentId) 342 .filter(x -> x instanceof IntentId)
......
...@@ -46,6 +46,7 @@ import org.onosproject.net.intent.impl.IntentCompilationException; ...@@ -46,6 +46,7 @@ import org.onosproject.net.intent.impl.IntentCompilationException;
46 import org.onosproject.net.newresource.ResourceAllocation; 46 import org.onosproject.net.newresource.ResourceAllocation;
47 import org.onosproject.net.newresource.Resource; 47 import org.onosproject.net.newresource.Resource;
48 import org.onosproject.net.newresource.ResourceService; 48 import org.onosproject.net.newresource.ResourceService;
49 +import org.onosproject.net.newresource.Resources;
49 import org.onosproject.net.resource.link.LinkResourceAllocations; 50 import org.onosproject.net.resource.link.LinkResourceAllocations;
50 import org.onosproject.net.topology.LinkWeight; 51 import org.onosproject.net.topology.LinkWeight;
51 import org.onosproject.net.topology.Topology; 52 import org.onosproject.net.topology.Topology;
...@@ -109,8 +110,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -109,8 +110,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
109 log.debug("Compiling optical connectivity intent between {} and {}", src, dst); 110 log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
110 111
111 // Reserve OCh ports 112 // Reserve OCh ports
112 - Resource srcPortResource = Resource.discrete(src.deviceId(), src.port()).resource(); 113 + Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
113 - Resource dstPortResource = Resource.discrete(dst.deviceId(), dst.port()).resource(); 114 + Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
114 List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource); 115 List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortResource, dstPortResource);
115 if (allocation.isEmpty()) { 116 if (allocation.isEmpty()) {
116 throw new IntentCompilationException("Unable to reserve ports for intent " + intent); 117 throw new IntentCompilationException("Unable to reserve ports for intent " + intent);
...@@ -183,8 +184,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -183,8 +184,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
183 List<OchSignal> minLambda = findFirstLambda(lambdas, slotCount()); 184 List<OchSignal> minLambda = findFirstLambda(lambdas, slotCount());
184 List<Resource> lambdaResources = path.links().stream() 185 List<Resource> lambdaResources = path.links().stream()
185 .flatMap(x -> Stream.of( 186 .flatMap(x -> Stream.of(
186 - Resource.discrete(x.src().deviceId(), x.src().port()).resource(), 187 + Resources.discrete(x.src().deviceId(), x.src().port()).resource(),
187 - Resource.discrete(x.dst().deviceId(), x.dst().port()).resource() 188 + Resources.discrete(x.dst().deviceId(), x.dst().port()).resource()
188 )) 189 ))
189 .flatMap(x -> minLambda.stream().map(l -> x.child(l))) 190 .flatMap(x -> minLambda.stream().map(l -> x.child(l)))
190 .collect(Collectors.toList()); 191 .collect(Collectors.toList());
...@@ -213,8 +214,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical ...@@ -213,8 +214,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
213 private Set<OchSignal> findCommonLambdasOverLinks(List<Link> links) { 214 private Set<OchSignal> findCommonLambdasOverLinks(List<Link> links) {
214 return links.stream() 215 return links.stream()
215 .flatMap(x -> Stream.of( 216 .flatMap(x -> Stream.of(
216 - Resource.discrete(x.src().deviceId(), x.src().port()).resource(), 217 + Resources.discrete(x.src().deviceId(), x.src().port()).resource(),
217 - Resource.discrete(x.dst().deviceId(), x.dst().port()).resource() 218 + Resources.discrete(x.dst().deviceId(), x.dst().port()).resource()
218 )) 219 ))
219 .map(resourceService::getAvailableResources) 220 .map(resourceService::getAvailableResources)
220 .map(x -> Iterables.filter(x, r -> r.last() instanceof OchSignal)) 221 .map(x -> Iterables.filter(x, r -> r.last() instanceof OchSignal))
......
...@@ -46,6 +46,7 @@ import org.onosproject.net.intent.constraint.EncapsulationConstraint; ...@@ -46,6 +46,7 @@ import org.onosproject.net.intent.constraint.EncapsulationConstraint;
46 import org.onosproject.net.intent.impl.IntentCompilationException; 46 import org.onosproject.net.intent.impl.IntentCompilationException;
47 import org.onosproject.net.newresource.Resource; 47 import org.onosproject.net.newresource.Resource;
48 import org.onosproject.net.newresource.ResourceService; 48 import org.onosproject.net.newresource.ResourceService;
49 +import org.onosproject.net.newresource.Resources;
49 import org.onosproject.net.resource.link.LinkResourceAllocations; 50 import org.onosproject.net.resource.link.LinkResourceAllocations;
50 import org.slf4j.Logger; 51 import org.slf4j.Logger;
51 52
...@@ -252,9 +253,9 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { ...@@ -252,9 +253,9 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
252 //same VLANID is used for both directions 253 //same VLANID is used for both directions
253 Set<Resource> resources = vlanIds.entrySet().stream() 254 Set<Resource> resources = vlanIds.entrySet().stream()
254 .flatMap(x -> Stream.of( 255 .flatMap(x -> Stream.of(
255 - Resource.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()) 256 + Resources.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue())
256 .resource(), 257 .resource(),
257 - Resource.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue()) 258 + Resources.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue())
258 .resource() 259 .resource()
259 )) 260 ))
260 .collect(Collectors.toSet()); 261 .collect(Collectors.toSet());
...@@ -282,7 +283,7 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> { ...@@ -282,7 +283,7 @@ public class PathIntentCompiler implements IntentCompiler<PathIntent> {
282 } 283 }
283 284
284 private Set<VlanId> findVlanId(ConnectPoint cp) { 285 private Set<VlanId> findVlanId(ConnectPoint cp) {
285 - return resourceService.getAvailableResources(Resource.discrete(cp.deviceId(), cp.port()).resource()).stream() 286 + return resourceService.getAvailableResources(Resources.discrete(cp.deviceId(), cp.port()).resource()).stream()
286 .filter(x -> x.last() instanceof VlanId) 287 .filter(x -> x.last() instanceof VlanId)
287 .map(x -> (VlanId) x.last()) 288 .map(x -> (VlanId) x.last())
288 .collect(Collectors.toSet()); 289 .collect(Collectors.toSet());
......
...@@ -40,6 +40,7 @@ import org.onosproject.net.driver.DriverService; ...@@ -40,6 +40,7 @@ import org.onosproject.net.driver.DriverService;
40 import org.onosproject.net.newresource.ResourceAdminService; 40 import org.onosproject.net.newresource.ResourceAdminService;
41 import org.onosproject.net.newresource.BandwidthCapacity; 41 import org.onosproject.net.newresource.BandwidthCapacity;
42 import org.onosproject.net.newresource.Resource; 42 import org.onosproject.net.newresource.Resource;
43 +import org.onosproject.net.newresource.Resources;
43 import org.slf4j.Logger; 44 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory; 45 import org.slf4j.LoggerFactory;
45 46
...@@ -118,15 +119,15 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -118,15 +119,15 @@ final class ResourceDeviceListener implements DeviceListener {
118 } 119 }
119 120
120 private void registerDeviceResource(Device device) { 121 private void registerDeviceResource(Device device) {
121 - executor.submit(() -> adminService.registerResources(Resource.discrete(device.id()).resource())); 122 + executor.submit(() -> adminService.registerResources(Resources.discrete(device.id()).resource()));
122 } 123 }
123 124
124 private void unregisterDeviceResource(Device device) { 125 private void unregisterDeviceResource(Device device) {
125 - executor.submit(() -> adminService.unregisterResources(Resource.discrete(device.id()).resource())); 126 + executor.submit(() -> adminService.unregisterResources(Resources.discrete(device.id()).resource()));
126 } 127 }
127 128
128 private void registerPortResource(Device device, Port port) { 129 private void registerPortResource(Device device, Port port) {
129 - Resource portPath = Resource.discrete(device.id(), port.number()).resource(); 130 + Resource portPath = Resources.discrete(device.id(), port.number()).resource();
130 executor.submit(() -> { 131 executor.submit(() -> {
131 adminService.registerResources(portPath); 132 adminService.registerResources(portPath);
132 133
...@@ -174,7 +175,7 @@ final class ResourceDeviceListener implements DeviceListener { ...@@ -174,7 +175,7 @@ final class ResourceDeviceListener implements DeviceListener {
174 } 175 }
175 176
176 private void unregisterPortResource(Device device, Port port) { 177 private void unregisterPortResource(Device device, Port port) {
177 - Resource resource = Resource.discrete(device.id(), port.number()).resource(); 178 + Resource resource = Resources.discrete(device.id(), port.number()).resource();
178 executor.submit(() -> adminService.unregisterResources(resource)); 179 executor.submit(() -> adminService.unregisterResources(resource));
179 } 180 }
180 181
......
...@@ -17,7 +17,6 @@ package org.onosproject.net.newresource.impl; ...@@ -17,7 +17,6 @@ package org.onosproject.net.newresource.impl;
17 17
18 import static com.google.common.base.Preconditions.checkArgument; 18 import static com.google.common.base.Preconditions.checkArgument;
19 import static com.google.common.base.Preconditions.checkNotNull; 19 import static com.google.common.base.Preconditions.checkNotNull;
20 -import static org.onosproject.net.newresource.Resource.continuous;
21 import static org.slf4j.LoggerFactory.getLogger; 20 import static org.slf4j.LoggerFactory.getLogger;
22 21
23 import java.util.Set; 22 import java.util.Set;
...@@ -30,6 +29,7 @@ import org.onosproject.net.config.NetworkConfigListener; ...@@ -30,6 +29,7 @@ import org.onosproject.net.config.NetworkConfigListener;
30 import org.onosproject.net.config.NetworkConfigService; 29 import org.onosproject.net.config.NetworkConfigService;
31 import org.onosproject.net.newresource.BandwidthCapacity; 30 import org.onosproject.net.newresource.BandwidthCapacity;
32 import org.onosproject.net.newresource.ResourceAdminService; 31 import org.onosproject.net.newresource.ResourceAdminService;
32 +import org.onosproject.net.newresource.Resources;
33 import org.slf4j.Logger; 33 import org.slf4j.Logger;
34 34
35 import com.google.common.annotations.Beta; 35 import com.google.common.annotations.Beta;
...@@ -93,8 +93,8 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { ...@@ -93,8 +93,8 @@ 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(cp.deviceId(), 96 + if (!adminService.registerResources(Resources.continuous(cp.deviceId(),
97 - cp.port(), Bandwidth.class) 97 + cp.port(), Bandwidth.class)
98 .resource(bwCapacity.capacity().bps()))) { 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
...@@ -115,9 +115,9 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { ...@@ -115,9 +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(cp.deviceId(), 118 + if (!adminService.unregisterResources(Resources.continuous(cp.deviceId(),
119 - cp.port(), 119 + cp.port(),
120 - Bandwidth.class).resource(0))) { 120 + Bandwidth.class).resource(0))) {
121 log.warn("Failed to unregister Bandwidth for {}", cp); 121 log.warn("Failed to unregister Bandwidth for {}", cp);
122 } 122 }
123 break; 123 break;
...@@ -147,12 +147,13 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener { ...@@ -147,12 +147,13 @@ final class ResourceNetworkConfigListener implements NetworkConfigListener {
147 // but both unregisterResources(..) and registerResources(..) 147 // but both unregisterResources(..) and registerResources(..)
148 // returns true (success) 148 // returns true (success)
149 149
150 - if (!adminService.unregisterResources(continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(0))) { 150 + if (!adminService.unregisterResources(
151 + Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(0))) {
151 log.warn("unregisterResources for {} failed", cp); 152 log.warn("unregisterResources for {} failed", cp);
152 } 153 }
153 - return adminService.registerResources(continuous(cp.deviceId(), 154 + return adminService.registerResources(Resources.continuous(cp.deviceId(),
154 - cp.port(), 155 + cp.port(),
155 - Bandwidth.class).resource(bwCapacity.capacity().bps())); 156 + Bandwidth.class).resource(bwCapacity.capacity().bps()));
156 } 157 }
157 158
158 } 159 }
......
...@@ -41,7 +41,7 @@ import org.onosproject.net.intent.MockIdGenerator; ...@@ -41,7 +41,7 @@ import org.onosproject.net.intent.MockIdGenerator;
41 import org.onosproject.net.link.LinkEvent; 41 import org.onosproject.net.link.LinkEvent;
42 import org.onosproject.net.newresource.ResourceEvent; 42 import org.onosproject.net.newresource.ResourceEvent;
43 import org.onosproject.net.newresource.ResourceListener; 43 import org.onosproject.net.newresource.ResourceListener;
44 -import org.onosproject.net.newresource.Resource; 44 +import org.onosproject.net.newresource.Resources;
45 import org.onosproject.net.topology.Topology; 45 import org.onosproject.net.topology.Topology;
46 import org.onosproject.net.topology.TopologyEvent; 46 import org.onosproject.net.topology.TopologyEvent;
47 import org.onosproject.net.topology.TopologyListener; 47 import org.onosproject.net.topology.TopologyListener;
...@@ -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)).resource()); 235 + Resources.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(1)).resource());
236 resourceListener.event(event); 236 resourceListener.event(event);
237 237
238 assertThat( 238 assertThat(
......
...@@ -62,7 +62,7 @@ import org.onosproject.net.flow.FlowId; ...@@ -62,7 +62,7 @@ import org.onosproject.net.flow.FlowId;
62 import org.onosproject.net.flow.FlowRule; 62 import org.onosproject.net.flow.FlowRule;
63 import org.onosproject.net.flow.FlowRuleBatchEntry; 63 import org.onosproject.net.flow.FlowRuleBatchEntry;
64 import org.onosproject.net.intent.IntentId; 64 import org.onosproject.net.intent.IntentId;
65 -import org.onosproject.net.newresource.Resource; 65 +import org.onosproject.net.newresource.Resources;
66 import org.onosproject.net.provider.ProviderId; 66 import org.onosproject.net.provider.ProviderId;
67 import org.onosproject.net.resource.link.BandwidthResource; 67 import org.onosproject.net.resource.link.BandwidthResource;
68 import org.onosproject.net.resource.link.BandwidthResourceAllocation; 68 import org.onosproject.net.resource.link.BandwidthResourceAllocation;
...@@ -388,18 +388,18 @@ public class KryoSerializerTest { ...@@ -388,18 +388,18 @@ public class KryoSerializerTest {
388 388
389 @Test 389 @Test
390 public void testResource() { 390 public void testResource() {
391 - testSerializedEquals(Resource.discrete(DID1, P1, VLAN1).resource()); 391 + testSerializedEquals(Resources.discrete(DID1, P1, VLAN1).resource());
392 } 392 }
393 393
394 @Test 394 @Test
395 public void testResourceId() { 395 public void testResourceId() {
396 - testSerializedEquals(Resource.discrete(DID1, P1).id()); 396 + testSerializedEquals(Resources.discrete(DID1, P1).id());
397 } 397 }
398 398
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).resource(), 402 + Resources.discrete(DID1, P1, VLAN1).resource(),
403 IntentId.valueOf(30))); 403 IntentId.valueOf(30)));
404 } 404 }
405 405
......