lishuai
Committed by Gerrit Code Review

[ONOS-2871]update VTN's bug: docking the neutron's interface, when get

the value is empty, should return a 404 error 

Change-Id: I939191d44387cb3160b1cb325b7fb261dd916a9b
......@@ -18,6 +18,7 @@ package org.onosproject.vtnweb.resources;
import static com.google.common.base.Preconditions.checkArgument;
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.NOT_FOUND;
import java.io.IOException;
import java.io.InputStream;
......@@ -87,7 +88,8 @@ public class SubnetWebResource extends AbstractWebResource {
public Response getSubnet(@PathParam("subnetUUID") String id) {
if (!get(SubnetService.class).exists(SubnetId.subnetId(id))) {
return ok("The subnet does not exists").build();
return Response.status(NOT_FOUND)
.entity(SUBNET_NOT_FOUND).build();
}
Subnet sub = nullIsNotFound(get(SubnetService.class)
.getSubnet(SubnetId.subnetId(id)),
......@@ -112,7 +114,8 @@ public class SubnetWebResource extends AbstractWebResource {
SUBNET_NOT_CREATE);
if (!result) {
return Response.status(204).entity(SUBNET_NOT_CREATE).build();
return Response.status(INTERNAL_SERVER_ERROR)
.entity(SUBNET_NOT_CREATE).build();
}
return Response.status(202).entity(result.toString()).build();
} catch (Exception e) {
......@@ -134,7 +137,8 @@ public class SubnetWebResource extends AbstractWebResource {
Boolean result = nullIsNotFound(get(SubnetService.class)
.updateSubnets(subnets), SUBNET_NOT_FOUND);
if (!result) {
return Response.status(204).entity(SUBNET_NOT_FOUND).build();
return Response.status(INTERNAL_SERVER_ERROR)
.entity(SUBNET_NOT_FOUND).build();
}
return Response.status(203).entity(result.toString()).build();
} catch (Exception e) {
......@@ -194,8 +198,18 @@ public class SubnetWebResource extends AbstractWebResource {
.tenantId(subnetNode.get("tenant_id").asText());
TenantNetworkId networkId = TenantNetworkId
.networkId(subnetNode.get("network_id").asText());
Version ipVersion = Version
.valueOf(subnetNode.get("ip_version").asText());
String version = subnetNode.get("ip_version").asText();
Version ipVersion;
switch (version) {
case "4":
ipVersion = Version.INET;
break;
case "6":
ipVersion = Version.INET;
break;
default:
throw new IllegalArgumentException("ipVersion should be 4 or 6.");
}
IpPrefix cidr = IpPrefix.valueOf(subnetNode.get("cidr").asText());
IpAddress gatewayIp = IpAddress
.valueOf(subnetNode.get("gateway_ip").asText());
......
......@@ -19,6 +19,7 @@ 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.OK;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import java.io.InputStream;
import java.util.Collections;
......@@ -150,7 +151,8 @@ public class TenantNetworkWebResource extends AbstractWebResource {
if (!get(TenantNetworkService.class).exists(TenantNetworkId
.networkId(id))) {
return ok("The tenantNetwork does not exists").build();
return Response.status(NOT_FOUND)
.entity(NETWORK_NOT_FOUND).build();
}
TenantNetwork network = nullIsNotFound(get(TenantNetworkService.class)
.getNetwork(TenantNetworkId.networkId(id)), NETWORK_NOT_FOUND);
......
......@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkArgument;
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.OK;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
import java.io.InputStream;
import java.util.Collection;
......@@ -96,7 +97,8 @@ public class VirtualPortWebResource extends AbstractWebResource {
public Response getportsById(@PathParam("id") String id) {
if (!get(VirtualPortService.class).exists(VirtualPortId.portId(id))) {
return ok("The virtualPort does not exists").build();
return Response.status(NOT_FOUND)
.entity(VPORT_NOT_FOUND).build();
}
VirtualPort virtualPort = nullIsNotFound(get(VirtualPortService.class)
.getPort(VirtualPortId.portId(id)), VPORT_NOT_FOUND);
......