jiangrui
Committed by Gerrit Code Review

[ONOS-2718][ONOS-2722][ONOS-2723] Fix three bugs of vtnweb.

Change-Id: I4dc631c879e1a7239ce1538289cea51d903ddb50
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 */ 15 */
16 package org.onosproject.vtnweb.resources; 16 package org.onosproject.vtnweb.resources;
17 17
18 +import static com.google.common.base.Preconditions.checkArgument;
18 import static com.google.common.base.Preconditions.checkNotNull; 19 import static com.google.common.base.Preconditions.checkNotNull;
19 import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; 20 import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
20 21
...@@ -225,6 +226,8 @@ public class SubnetWebResource extends AbstractWebResource { ...@@ -225,6 +226,8 @@ public class SubnetWebResource extends AbstractWebResource {
225 */ 226 */
226 public Iterable<Subnet> changeJsonToSub(JsonNode subnetNodes) { 227 public Iterable<Subnet> changeJsonToSub(JsonNode subnetNodes) {
227 checkNotNull(subnetNodes, JSON_NOT_NULL); 228 checkNotNull(subnetNodes, JSON_NOT_NULL);
229 + checkArgument(!subnetNodes.get("enable_dhcp").isBoolean(), "enable_dhcp should be boolean");
230 + checkArgument(!subnetNodes.get("shared").isBoolean(), "shared should be boolean");
228 Map<SubnetId, Subnet> subMap = new HashMap<SubnetId, Subnet>(); 231 Map<SubnetId, Subnet> subMap = new HashMap<SubnetId, Subnet>();
229 if (!subnetNodes.hasNonNull("id")) { 232 if (!subnetNodes.hasNonNull("id")) {
230 return null; 233 return null;
...@@ -245,7 +248,7 @@ public class SubnetWebResource extends AbstractWebResource { ...@@ -245,7 +248,7 @@ public class SubnetWebResource extends AbstractWebResource {
245 ipVersion = Version.INET; 248 ipVersion = Version.INET;
246 break; 249 break;
247 default: 250 default:
248 - ipVersion = null; 251 + throw new IllegalArgumentException("ipVersion should be 4 or 6.");
249 } 252 }
250 253
251 IpPrefix cidr = IpPrefix.valueOf(subnetNodes.get("cidr").asText()); 254 IpPrefix cidr = IpPrefix.valueOf(subnetNodes.get("cidr").asText());
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.vtnweb.resources; 16 package org.onosproject.vtnweb.resources;
17 17
18 import static com.google.common.base.Preconditions.checkNotNull; 18 import static com.google.common.base.Preconditions.checkNotNull;
19 +import static com.google.common.base.Preconditions.checkArgument;
19 import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; 20 import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
20 import static javax.ws.rs.core.Response.Status.OK; 21 import static javax.ws.rs.core.Response.Status.OK;
21 22
...@@ -268,6 +269,9 @@ public class TenantNetworkWebResource extends AbstractWebResource { ...@@ -268,6 +269,9 @@ public class TenantNetworkWebResource extends AbstractWebResource {
268 ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps 269 ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps
269 .newConcurrentMap(); 270 .newConcurrentMap();
270 if (node != null) { 271 if (node != null) {
272 + checkArgument(!node.get("admin_state_up").isBoolean(), "admin_state_up should be boolean");
273 + checkArgument(!node.get("shared").isBoolean(), "shared should be boolean");
274 + checkArgument(!node.get("router:external").isBoolean(), "router:external should be boolean");
271 String name = node.get("name").asText(); 275 String name = node.get("name").asText();
272 boolean adminStateUp = node.get("admin_state_up").asBoolean(); 276 boolean adminStateUp = node.get("admin_state_up").asBoolean();
273 String state = node.get("status").asText(); 277 String state = node.get("status").asText();
......
...@@ -94,7 +94,7 @@ public class VirtualPortWebResource extends AbstractWebResource { ...@@ -94,7 +94,7 @@ public class VirtualPortWebResource extends AbstractWebResource {
94 public Response getportsById(@PathParam("id") String id) { 94 public Response getportsById(@PathParam("id") String id) {
95 95
96 if (!get(VirtualPortService.class).exists(VirtualPortId.portId(id))) { 96 if (!get(VirtualPortService.class).exists(VirtualPortId.portId(id))) {
97 - return ok("the virtualPort does not exists").build(); 97 + return ok("The virtualPort does not exists").build();
98 } 98 }
99 VirtualPort virtualPort = nullIsNotFound(get(VirtualPortService.class) 99 VirtualPort virtualPort = nullIsNotFound(get(VirtualPortService.class)
100 .getPort(VirtualPortId.portId(id)), VPORT_NOT_FOUND); 100 .getPort(VirtualPortId.portId(id)), VPORT_NOT_FOUND);
......