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 {
}
private void printDetails(IntentService service, Intent intent) {
if (intent.resources() != null && !intent.resources().isEmpty()) {
if (!intent.resources().isEmpty()) {
print(" resources=%s", intent.resources());
}
if (intent instanceof ConnectivityIntent) {
......@@ -392,7 +392,7 @@ public class IntentsListCommand extends AbstractShellCommand {
result.put("state", state.toString());
}
if (intent.resources() != null && !intent.resources().isEmpty()) {
if (!intent.resources().isEmpty()) {
ArrayNode rnode = mapper.createArrayNode();
for (NetworkResource resource : intent.resources()) {
rnode.add(resource.toString());
......
......@@ -26,6 +26,7 @@ import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
......@@ -86,7 +87,7 @@ public final class HostToHostIntent extends ConnectivityIntent {
TrafficSelector selector,
TrafficTreatment treatment,
List<Constraint> constraints) {
super(appId, null, selector, treatment, constraints);
super(appId, Collections.emptyList(), selector, treatment, constraints);
// TODO: consider whether the case one and two are same is allowed
this.one = checkNotNull(one);
......
......@@ -60,7 +60,7 @@ public abstract class Intent implements BatchOperationTarget {
checkState(idGenerator != null, "Id generator is not bound.");
this.id = IntentId.valueOf(idGenerator.getNewId());
this.appId = checkNotNull(appId, "Application ID cannot be null");
this.resources = resources;
this.resources = checkNotNull(resources);
}
/**
......
......@@ -80,7 +80,7 @@ public final class MultiPointToSinglePointIntent extends ConnectivityIntent {
Set<ConnectPoint> ingressPoints,
ConnectPoint egressPoint,
List<Constraint> constraints) {
super(appId, null, selector, treatment, constraints);
super(appId, Collections.emptyList(), selector, treatment, constraints);
checkNotNull(ingressPoints);
checkArgument(!ingressPoints.isEmpty(), "Ingress point set cannot be empty");
......
......@@ -18,6 +18,8 @@ package org.onosproject.net.intent;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import java.util.Collections;
/**
* An optical layer intent for connectivity from one transponder port to another
* transponder port. No traffic selector or traffic treatment are needed.
......@@ -36,7 +38,7 @@ public class OpticalConnectivityIntent extends Intent {
*/
public OpticalConnectivityIntent(ApplicationId appId,
ConnectPoint src, ConnectPoint dst) {
super(appId, null);
super(appId, Collections.emptyList());
this.src = src;
this.dst = dst;
}
......
......@@ -24,6 +24,7 @@ import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
......@@ -73,7 +74,7 @@ public class PointToPointIntent extends ConnectivityIntent {
ConnectPoint ingressPoint,
ConnectPoint egressPoint,
List<Constraint> constraints) {
super(appId, null, selector, treatment, constraints);
super(appId, Collections.emptyList(), selector, treatment, constraints);
checkNotNull(ingressPoint);
checkNotNull(egressPoint);
......
......@@ -75,7 +75,7 @@ public class SinglePointToMultiPointIntent extends ConnectivityIntent {
TrafficSelector selector, TrafficTreatment treatment,
ConnectPoint ingressPoint, Set<ConnectPoint> egressPoints,
List<Constraint> constraints) {
super(appId, null, selector, treatment, constraints);
super(appId, Collections.emptyList(), selector, treatment, constraints);
checkNotNull(egressPoints);
checkNotNull(ingressPoint);
checkArgument(!egressPoints.isEmpty(), "Egress point set cannot be empty");
......
......@@ -17,6 +17,8 @@ package org.onosproject.net.intent;
import org.onosproject.TestApplicationId;
import java.util.Collections;
/**
* An installable intent used in the unit test.
*/
......@@ -30,7 +32,7 @@ public class TestInstallableIntent extends Intent {
* @param value intent ID
*/
public TestInstallableIntent(int value) { // FIXME
super(new TestApplicationId("foo"), null);
super(new TestApplicationId("foo"), Collections.emptyList());
this.value = value;
}
......
......@@ -17,6 +17,8 @@ package org.onosproject.net.intent;
import org.onosproject.TestApplicationId;
import java.util.Collections;
/**
* An intent used in the unit test.
*/
......@@ -30,7 +32,7 @@ public class TestIntent extends Intent {
* @param value intent ID
*/
public TestIntent(int value) { // FIXME
super(new TestApplicationId("foo"), null);
super(new TestApplicationId("foo"), Collections.emptyList());
this.value = value;
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.net.intent.impl;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -154,7 +155,7 @@ public class IntentManagerTest {
private final Long number;
// Nothing new here
public MockIntent(Long number) {
super(APPID, null);
super(APPID, Collections.emptyList());
this.number = number;
}
......@@ -507,7 +508,7 @@ public class IntentManagerTest {
public void intentWithoutCompiler() {
class IntentNoCompiler extends Intent {
IntentNoCompiler() {
super(APPID, null);
super(APPID, Collections.emptyList());
}
}
......
......@@ -41,10 +41,8 @@ public class IntentCodec extends JsonCodec<Intent> {
final ArrayNode jsonResources = result.putArray("resources");
if (intent.resources() != null) {
for (final NetworkResource resource : intent.resources()) {
jsonResources.add(resource.toString());
}
for (final NetworkResource resource : intent.resources()) {
jsonResources.add(resource.toString());
}
return result;
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.rest;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicLong;
......@@ -300,7 +301,7 @@ public class IntentsResourceTest extends JerseyTest {
public void testIntentsArray() {
replay(mockIntentService);
final Intent intent1 = new MockIntent(null);
final Intent intent1 = new MockIntent(Collections.emptyList());
final HashSet<NetworkResource> resources = new HashSet<>();
resources.add(new MockResource(1));
resources.add(new MockResource(2));
......