Sho SHIMIZU
Committed by Ray Milkey

Prohibit null for resources field in Intent

Change-Id: I128c6e63ccccaf817e83ff1c440a731fb98b42f7
...@@ -328,7 +328,7 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -328,7 +328,7 @@ public class IntentsListCommand extends AbstractShellCommand {
328 } 328 }
329 329
330 private void printDetails(IntentService service, Intent intent) { 330 private void printDetails(IntentService service, Intent intent) {
331 - if (intent.resources() != null && !intent.resources().isEmpty()) { 331 + if (!intent.resources().isEmpty()) {
332 print(" resources=%s", intent.resources()); 332 print(" resources=%s", intent.resources());
333 } 333 }
334 if (intent instanceof ConnectivityIntent) { 334 if (intent instanceof ConnectivityIntent) {
...@@ -392,7 +392,7 @@ public class IntentsListCommand extends AbstractShellCommand { ...@@ -392,7 +392,7 @@ public class IntentsListCommand extends AbstractShellCommand {
392 result.put("state", state.toString()); 392 result.put("state", state.toString());
393 } 393 }
394 394
395 - if (intent.resources() != null && !intent.resources().isEmpty()) { 395 + if (!intent.resources().isEmpty()) {
396 ArrayNode rnode = mapper.createArrayNode(); 396 ArrayNode rnode = mapper.createArrayNode();
397 for (NetworkResource resource : intent.resources()) { 397 for (NetworkResource resource : intent.resources()) {
398 rnode.add(resource.toString()); 398 rnode.add(resource.toString());
......
...@@ -26,6 +26,7 @@ import org.onosproject.net.flow.TrafficSelector; ...@@ -26,6 +26,7 @@ import org.onosproject.net.flow.TrafficSelector;
26 import org.onosproject.net.flow.TrafficTreatment; 26 import org.onosproject.net.flow.TrafficTreatment;
27 import org.onosproject.net.intent.constraint.LinkTypeConstraint; 27 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
28 28
29 +import java.util.Collections;
29 import java.util.List; 30 import java.util.List;
30 31
31 import static com.google.common.base.Preconditions.checkNotNull; 32 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -86,7 +87,7 @@ public final class HostToHostIntent extends ConnectivityIntent { ...@@ -86,7 +87,7 @@ public final class HostToHostIntent extends ConnectivityIntent {
86 TrafficSelector selector, 87 TrafficSelector selector,
87 TrafficTreatment treatment, 88 TrafficTreatment treatment,
88 List<Constraint> constraints) { 89 List<Constraint> constraints) {
89 - super(appId, null, selector, treatment, constraints); 90 + super(appId, Collections.emptyList(), selector, treatment, constraints);
90 91
91 // TODO: consider whether the case one and two are same is allowed 92 // TODO: consider whether the case one and two are same is allowed
92 this.one = checkNotNull(one); 93 this.one = checkNotNull(one);
......
...@@ -60,7 +60,7 @@ public abstract class Intent implements BatchOperationTarget { ...@@ -60,7 +60,7 @@ public abstract class Intent implements BatchOperationTarget {
60 checkState(idGenerator != null, "Id generator is not bound."); 60 checkState(idGenerator != null, "Id generator is not bound.");
61 this.id = IntentId.valueOf(idGenerator.getNewId()); 61 this.id = IntentId.valueOf(idGenerator.getNewId());
62 this.appId = checkNotNull(appId, "Application ID cannot be null"); 62 this.appId = checkNotNull(appId, "Application ID cannot be null");
63 - this.resources = resources; 63 + this.resources = checkNotNull(resources);
64 } 64 }
65 65
66 /** 66 /**
......
...@@ -80,7 +80,7 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent { ...@@ -80,7 +80,7 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
80 Set<ConnectPoint> ingressPoints, 80 Set<ConnectPoint> ingressPoints,
81 ConnectPoint egressPoint, 81 ConnectPoint egressPoint,
82 List<Constraint> constraints) { 82 List<Constraint> constraints) {
83 - super(appId, null, selector, treatment, constraints); 83 + super(appId, Collections.emptyList(), selector, treatment, constraints);
84 84
85 checkNotNull(ingressPoints); 85 checkNotNull(ingressPoints);
86 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty"); 86 checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
......
...@@ -18,6 +18,8 @@ package org.onosproject.net.intent; ...@@ -18,6 +18,8 @@ package org.onosproject.net.intent;
18 import org.onosproject.core.ApplicationId; 18 import org.onosproject.core.ApplicationId;
19 import org.onosproject.net.ConnectPoint; 19 import org.onosproject.net.ConnectPoint;
20 20
21 +import java.util.Collections;
22 +
21 /** 23 /**
22 * An optical layer intent for connectivity from one transponder port to another 24 * An optical layer intent for connectivity from one transponder port to another
23 * transponder port. No traffic selector or traffic treatment are needed. 25 * transponder port. No traffic selector or traffic treatment are needed.
...@@ -36,7 +38,7 @@ public class OpticalConnectivityIntent extends Intent { ...@@ -36,7 +38,7 @@ public class OpticalConnectivityIntent extends Intent {
36 */ 38 */
37 public OpticalConnectivityIntent(ApplicationId appId, 39 public OpticalConnectivityIntent(ApplicationId appId,
38 ConnectPoint src, ConnectPoint dst) { 40 ConnectPoint src, ConnectPoint dst) {
39 - super(appId, null); 41 + super(appId, Collections.emptyList());
40 this.src = src; 42 this.src = src;
41 this.dst = dst; 43 this.dst = dst;
42 } 44 }
......
...@@ -24,6 +24,7 @@ import org.onosproject.net.flow.TrafficSelector; ...@@ -24,6 +24,7 @@ import org.onosproject.net.flow.TrafficSelector;
24 import org.onosproject.net.flow.TrafficTreatment; 24 import org.onosproject.net.flow.TrafficTreatment;
25 import org.onosproject.net.intent.constraint.LinkTypeConstraint; 25 import org.onosproject.net.intent.constraint.LinkTypeConstraint;
26 26
27 +import java.util.Collections;
27 import java.util.List; 28 import java.util.List;
28 29
29 import static com.google.common.base.Preconditions.checkArgument; 30 import static com.google.common.base.Preconditions.checkArgument;
...@@ -73,7 +74,7 @@ public class PointToPointIntent extends ConnectivityIntent { ...@@ -73,7 +74,7 @@ public class PointToPointIntent extends ConnectivityIntent {
73 ConnectPoint ingressPoint, 74 ConnectPoint ingressPoint,
74 ConnectPoint egressPoint, 75 ConnectPoint egressPoint,
75 List<Constraint> constraints) { 76 List<Constraint> constraints) {
76 - super(appId, null, selector, treatment, constraints); 77 + super(appId, Collections.emptyList(), selector, treatment, constraints);
77 78
78 checkNotNull(ingressPoint); 79 checkNotNull(ingressPoint);
79 checkNotNull(egressPoint); 80 checkNotNull(egressPoint);
......
...@@ -75,7 +75,7 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent { ...@@ -75,7 +75,7 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
75 TrafficSelector selector, TrafficTreatment treatment, 75 TrafficSelector selector, TrafficTreatment treatment,
76 ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints, 76 ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
77 List<Constraint> constraints) { 77 List<Constraint> constraints) {
78 - super(appId, null, selector, treatment, constraints); 78 + super(appId, Collections.emptyList(), selector, treatment, constraints);
79 checkNotNull(egressPoints); 79 checkNotNull(egressPoints);
80 checkNotNull(ingressPoint); 80 checkNotNull(ingressPoint);
81 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty"); 81 checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
......
...@@ -17,6 +17,8 @@ package org.onosproject.net.intent; ...@@ -17,6 +17,8 @@ package org.onosproject.net.intent;
17 17
18 import org.onosproject.TestApplicationId; 18 import org.onosproject.TestApplicationId;
19 19
20 +import java.util.Collections;
21 +
20 /** 22 /**
21 * An installable intent used in the unit test. 23 * An installable intent used in the unit test.
22 */ 24 */
...@@ -30,7 +32,7 @@ public class TestInstallableIntent extends Intent { ...@@ -30,7 +32,7 @@ public class TestInstallableIntent extends Intent {
30 * @param value intent ID 32 * @param value intent ID
31 */ 33 */
32 public TestInstallableIntent(int value) { // FIXME 34 public TestInstallableIntent(int value) { // FIXME
33 - super(new TestApplicationId("foo"), null); 35 + super(new TestApplicationId("foo"), Collections.emptyList());
34 this.value = value; 36 this.value = value;
35 } 37 }
36 38
......
...@@ -17,6 +17,8 @@ package org.onosproject.net.intent; ...@@ -17,6 +17,8 @@ package org.onosproject.net.intent;
17 17
18 import org.onosproject.TestApplicationId; 18 import org.onosproject.TestApplicationId;
19 19
20 +import java.util.Collections;
21 +
20 /** 22 /**
21 * An intent used in the unit test. 23 * An intent used in the unit test.
22 */ 24 */
...@@ -30,7 +32,7 @@ public class TestIntent extends Intent { ...@@ -30,7 +32,7 @@ public class TestIntent extends Intent {
30 * @param value intent ID 32 * @param value intent ID
31 */ 33 */
32 public TestIntent(int value) { // FIXME 34 public TestIntent(int value) { // FIXME
33 - super(new TestApplicationId("foo"), null); 35 + super(new TestApplicationId("foo"), Collections.emptyList());
34 this.value = value; 36 this.value = value;
35 } 37 }
36 38
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.net.intent.impl; 16 package org.onosproject.net.intent.impl;
17 17
18 import java.util.Collection; 18 import java.util.Collection;
19 +import java.util.Collections;
19 import java.util.List; 20 import java.util.List;
20 import java.util.Map; 21 import java.util.Map;
21 import java.util.Set; 22 import java.util.Set;
...@@ -154,7 +155,7 @@ public class IntentManagerTest { ...@@ -154,7 +155,7 @@ public class IntentManagerTest {
154 private final Long number; 155 private final Long number;
155 // Nothing new here 156 // Nothing new here
156 public MockIntent(Long number) { 157 public MockIntent(Long number) {
157 - super(APPID, null); 158 + super(APPID, Collections.emptyList());
158 this.number = number; 159 this.number = number;
159 } 160 }
160 161
...@@ -507,7 +508,7 @@ public class IntentManagerTest { ...@@ -507,7 +508,7 @@ public class IntentManagerTest {
507 public void intentWithoutCompiler() { 508 public void intentWithoutCompiler() {
508 class IntentNoCompiler extends Intent { 509 class IntentNoCompiler extends Intent {
509 IntentNoCompiler() { 510 IntentNoCompiler() {
510 - super(APPID, null); 511 + super(APPID, Collections.emptyList());
511 } 512 }
512 } 513 }
513 514
......
...@@ -41,11 +41,9 @@ public class IntentCodec extends JsonCodec<Intent> { ...@@ -41,11 +41,9 @@ public class IntentCodec extends JsonCodec<Intent> {
41 41
42 final ArrayNode jsonResources = result.putArray("resources"); 42 final ArrayNode jsonResources = result.putArray("resources");
43 43
44 - if (intent.resources() != null) {
45 for (final NetworkResource resource : intent.resources()) { 44 for (final NetworkResource resource : intent.resources()) {
46 jsonResources.add(resource.toString()); 45 jsonResources.add(resource.toString());
47 } 46 }
48 - }
49 return result; 47 return result;
50 } 48 }
51 } 49 }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.rest; 16 package org.onosproject.rest;
17 17
18 import java.util.Collection; 18 import java.util.Collection;
19 +import java.util.Collections;
19 import java.util.HashSet; 20 import java.util.HashSet;
20 import java.util.concurrent.atomic.AtomicLong; 21 import java.util.concurrent.atomic.AtomicLong;
21 22
...@@ -300,7 +301,7 @@ public class IntentsResourceTest extends JerseyTest { ...@@ -300,7 +301,7 @@ public class IntentsResourceTest extends JerseyTest {
300 public void testIntentsArray() { 301 public void testIntentsArray() {
301 replay(mockIntentService); 302 replay(mockIntentService);
302 303
303 - final Intent intent1 = new MockIntent(null); 304 + final Intent intent1 = new MockIntent(Collections.emptyList());
304 final HashSet<NetworkResource> resources = new HashSet<>(); 305 final HashSet<NetworkResource> resources = new HashSet<>();
305 resources.add(new MockResource(1)); 306 resources.add(new MockResource(1));
306 resources.add(new MockResource(2)); 307 resources.add(new MockResource(2));
......