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

Change-Id: I4dc631c879e1a7239ce1538289cea51d903ddb50
This commit is contained in:
jiangrui 2015-08-25 20:30:16 +08:00 committed by Gerrit Code Review
parent 743a8492b8
commit bac6283d17
3 changed files with 9 additions and 2 deletions

View File

@ -15,6 +15,7 @@
*/ */
package org.onosproject.vtnweb.resources; package org.onosproject.vtnweb.resources;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
@ -225,6 +226,8 @@ public class SubnetWebResource extends AbstractWebResource {
*/ */
public Iterable<Subnet> changeJsonToSub(JsonNode subnetNodes) { public Iterable<Subnet> changeJsonToSub(JsonNode subnetNodes) {
checkNotNull(subnetNodes, JSON_NOT_NULL); checkNotNull(subnetNodes, JSON_NOT_NULL);
checkArgument(!subnetNodes.get("enable_dhcp").isBoolean(), "enable_dhcp should be boolean");
checkArgument(!subnetNodes.get("shared").isBoolean(), "shared should be boolean");
Map<SubnetId, Subnet> subMap = new HashMap<SubnetId, Subnet>(); Map<SubnetId, Subnet> subMap = new HashMap<SubnetId, Subnet>();
if (!subnetNodes.hasNonNull("id")) { if (!subnetNodes.hasNonNull("id")) {
return null; return null;
@ -245,7 +248,7 @@ public class SubnetWebResource extends AbstractWebResource {
ipVersion = Version.INET; ipVersion = Version.INET;
break; break;
default: default:
ipVersion = null; throw new IllegalArgumentException("ipVersion should be 4 or 6.");
} }
IpPrefix cidr = IpPrefix.valueOf(subnetNodes.get("cidr").asText()); IpPrefix cidr = IpPrefix.valueOf(subnetNodes.get("cidr").asText());

View File

@ -16,6 +16,7 @@
package org.onosproject.vtnweb.resources; package org.onosproject.vtnweb.resources;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkArgument;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.OK; import static javax.ws.rs.core.Response.Status.OK;
@ -268,6 +269,9 @@ public class TenantNetworkWebResource extends AbstractWebResource {
ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps ConcurrentMap<TenantNetworkId, TenantNetwork> networksMap = Maps
.newConcurrentMap(); .newConcurrentMap();
if (node != null) { if (node != null) {
checkArgument(!node.get("admin_state_up").isBoolean(), "admin_state_up should be boolean");
checkArgument(!node.get("shared").isBoolean(), "shared should be boolean");
checkArgument(!node.get("router:external").isBoolean(), "router:external should be boolean");
String name = node.get("name").asText(); String name = node.get("name").asText();
boolean adminStateUp = node.get("admin_state_up").asBoolean(); boolean adminStateUp = node.get("admin_state_up").asBoolean();
String state = node.get("status").asText(); String state = node.get("status").asText();

View File

@ -94,7 +94,7 @@ public class VirtualPortWebResource extends AbstractWebResource {
public Response getportsById(@PathParam("id") String id) { public Response getportsById(@PathParam("id") String id) {
if (!get(VirtualPortService.class).exists(VirtualPortId.portId(id))) { if (!get(VirtualPortService.class).exists(VirtualPortId.portId(id))) {
return ok("the virtualPort does not exists").build(); return ok("The virtualPort does not exists").build();
} }
VirtualPort virtualPort = nullIsNotFound(get(VirtualPortService.class) VirtualPort virtualPort = nullIsNotFound(get(VirtualPortService.class)
.getPort(VirtualPortId.portId(id)), VPORT_NOT_FOUND); .getPort(VirtualPortId.portId(id)), VPORT_NOT_FOUND);