lishuai
Committed by Gerrit Code Review

[ONOS-3624] update vtnweb's bug and add Not-Null constraints of export.

Change-Id: I7699d8766f0653f5fafd4b32a68051994f43b00e
...@@ -413,7 +413,9 @@ public class VTNManager implements VTNService { ...@@ -413,7 +413,9 @@ public class VTNManager implements VTNService {
413 if (type == Objective.Operation.ADD) { 413 if (type == Objective.Operation.ADD) {
414 // Save external port 414 // Save external port
415 Port export = getExPort(device.id()); 415 Port export = getExPort(device.id());
416 - exPortOfDevice.put(device.id(), export); 416 + if (export != null) {
417 + exPortOfDevice.put(device.id(), export);
418 + }
417 switchOfLocalHostPorts.put(device.id(), new NetworkOfLocalHostPorts()); 419 switchOfLocalHostPorts.put(device.id(), new NetworkOfLocalHostPorts());
418 } else if (type == Objective.Operation.REMOVE) { 420 } else if (type == Objective.Operation.REMOVE) {
419 exPortOfDevice.remove(device.id()); 421 exPortOfDevice.remove(device.id());
...@@ -777,7 +779,7 @@ public class VTNManager implements VTNService { ...@@ -777,7 +779,7 @@ public class VTNManager implements VTNService {
777 for (RouterInterface r : interfacesSet) { 779 for (RouterInterface r : interfacesSet) {
778 // Get all the host of the subnet 780 // Get all the host of the subnet
779 Map<HostId, Host> hosts = hostsOfSubnet.get(r.subnetId()); 781 Map<HostId, Host> hosts = hostsOfSubnet.get(r.subnetId());
780 - if (hosts.size() > 0) { 782 + if (hosts != null && hosts.size() > 0) {
781 subnetVmNum++; 783 subnetVmNum++;
782 if (subnetVmNum >= SUBNET_NUM) { 784 if (subnetVmNum >= SUBNET_NUM) {
783 routerInfFlagOfTenant.put(r.tenantId(), true); 785 routerInfFlagOfTenant.put(r.tenantId(), true);
......
...@@ -134,6 +134,12 @@ public class RouterInterfaceManager implements RouterInterfaceService { ...@@ -134,6 +134,12 @@ public class RouterInterfaceManager implements RouterInterfaceService {
134 @Override 134 @Override
135 public boolean addRouterInterface(RouterInterface routerInterface) { 135 public boolean addRouterInterface(RouterInterface routerInterface) {
136 checkNotNull(routerInterface, ROUTER_INTERFACE_NULL); 136 checkNotNull(routerInterface, ROUTER_INTERFACE_NULL);
137 + if (!virtualPortService.exists(routerInterface.portId())) {
138 + log.debug("The port ID of interface is not exist whose identifier is {}",
139 + routerInterface.portId().toString());
140 + throw new IllegalArgumentException(
141 + "port ID of interface doesn't exist");
142 + }
137 verifyRouterInterfaceData(routerInterface); 143 verifyRouterInterfaceData(routerInterface);
138 routerInterfaceStore.put(routerInterface.subnetId(), routerInterface); 144 routerInterfaceStore.put(routerInterface.subnetId(), routerInterface);
139 if (!routerInterfaceStore.containsKey(routerInterface.subnetId())) { 145 if (!routerInterfaceStore.containsKey(routerInterface.subnetId())) {
...@@ -188,12 +194,6 @@ public class RouterInterfaceManager implements RouterInterfaceService { ...@@ -188,12 +194,6 @@ public class RouterInterfaceManager implements RouterInterfaceService {
188 throw new IllegalArgumentException( 194 throw new IllegalArgumentException(
189 "subnet ID of interface doesn't exist"); 195 "subnet ID of interface doesn't exist");
190 } 196 }
191 - if (!virtualPortService.exists(routerInterface.portId())) {
192 - log.debug("The port ID of interface is not exist whose identifier is {}",
193 - routerInterface.portId().toString());
194 - throw new IllegalArgumentException(
195 - "port ID of interface doesn't exist");
196 - }
197 if (!routerService.exists(routerInterface.routerId())) { 197 if (!routerService.exists(routerInterface.routerId())) {
198 log.debug("The router ID of interface is not exist whose identifier is {}", 198 log.debug("The router ID of interface is not exist whose identifier is {}",
199 routerInterface.routerId().toString()); 199 routerInterface.routerId().toString());
......
...@@ -104,8 +104,7 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -104,8 +104,7 @@ public class RouterWebResource extends AbstractWebResource {
104 .entity("The Router does not exists").build(); 104 .entity("The Router does not exists").build();
105 } 105 }
106 Router sub = nullIsNotFound(get(RouterService.class) 106 Router sub = nullIsNotFound(get(RouterService.class)
107 - .getRouter(RouterId.valueOf(id)), 107 + .getRouter(RouterId.valueOf(id)), NOT_EXIST);
108 - NOT_EXIST);
109 108
110 ObjectNode result = new ObjectMapper().createObjectNode(); 109 ObjectNode result = new ObjectMapper().createObjectNode();
111 if (fields.size() > 0) { 110 if (fields.size() > 0) {
...@@ -127,8 +126,7 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -127,8 +126,7 @@ public class RouterWebResource extends AbstractWebResource {
127 Collection<Router> routers = createOrUpdateByInputStream(subnode); 126 Collection<Router> routers = createOrUpdateByInputStream(subnode);
128 127
129 Boolean result = nullIsNotFound((get(RouterService.class) 128 Boolean result = nullIsNotFound((get(RouterService.class)
130 - .createRouters(routers)), 129 + .createRouters(routers)), CREATE_FAIL);
131 - CREATE_FAIL);
132 if (!result) { 130 if (!result) {
133 return Response.status(CONFLICT).entity(CREATE_FAIL).build(); 131 return Response.status(CONFLICT).entity(CREATE_FAIL).build();
134 } 132 }
...@@ -148,7 +146,7 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -148,7 +146,7 @@ public class RouterWebResource extends AbstractWebResource {
148 try { 146 try {
149 ObjectMapper mapper = new ObjectMapper(); 147 ObjectMapper mapper = new ObjectMapper();
150 JsonNode subnode = mapper.readTree(input); 148 JsonNode subnode = mapper.readTree(input);
151 - Collection<Router> routers = createOrUpdateByInputStream(subnode); 149 + Collection<Router> routers = changeUpdateJsonToSub(subnode, id);
152 Boolean result = nullIsNotFound(get(RouterService.class) 150 Boolean result = nullIsNotFound(get(RouterService.class)
153 .updateRouters(routers), UPDATE_FAIL); 151 .updateRouters(routers), UPDATE_FAIL);
154 if (!result) { 152 if (!result) {
...@@ -197,22 +195,22 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -197,22 +195,22 @@ public class RouterWebResource extends AbstractWebResource {
197 } else if (subnode.get("subnet_id").asText().isEmpty()) { 195 } else if (subnode.get("subnet_id").asText().isEmpty()) {
198 throw new IllegalArgumentException("subnet_id should not be empty"); 196 throw new IllegalArgumentException("subnet_id should not be empty");
199 } 197 }
200 - SubnetId subnetId = SubnetId.subnetId(subnode.get("subnet_id") 198 + SubnetId subnetId = SubnetId
201 - .asText()); 199 + .subnetId(subnode.get("subnet_id").asText());
202 if (!subnode.hasNonNull("tenant_id")) { 200 if (!subnode.hasNonNull("tenant_id")) {
203 throw new IllegalArgumentException("tenant_id should not be null"); 201 throw new IllegalArgumentException("tenant_id should not be null");
204 } else if (subnode.get("tenant_id").asText().isEmpty()) { 202 } else if (subnode.get("tenant_id").asText().isEmpty()) {
205 throw new IllegalArgumentException("tenant_id should not be empty"); 203 throw new IllegalArgumentException("tenant_id should not be empty");
206 } 204 }
207 - TenantId tenentId = TenantId.tenantId(subnode.get("tenant_id") 205 + TenantId tenentId = TenantId
208 - .asText()); 206 + .tenantId(subnode.get("tenant_id").asText());
209 if (!subnode.hasNonNull("port_id")) { 207 if (!subnode.hasNonNull("port_id")) {
210 throw new IllegalArgumentException("port_id should not be null"); 208 throw new IllegalArgumentException("port_id should not be null");
211 } else if (subnode.get("port_id").asText().isEmpty()) { 209 } else if (subnode.get("port_id").asText().isEmpty()) {
212 throw new IllegalArgumentException("port_id should not be empty"); 210 throw new IllegalArgumentException("port_id should not be empty");
213 } 211 }
214 - VirtualPortId portId = VirtualPortId.portId(subnode.get("port_id") 212 + VirtualPortId portId = VirtualPortId
215 - .asText()); 213 + .portId(subnode.get("port_id").asText());
216 RouterInterface routerInterface = RouterInterface 214 RouterInterface routerInterface = RouterInterface
217 .routerInterface(subnetId, portId, routerId, tenentId); 215 .routerInterface(subnetId, portId, routerId, tenentId);
218 get(RouterInterfaceService.class) 216 get(RouterInterfaceService.class)
...@@ -246,22 +244,22 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -246,22 +244,22 @@ public class RouterWebResource extends AbstractWebResource {
246 } else if (subnode.get("subnet_id").asText().isEmpty()) { 244 } else if (subnode.get("subnet_id").asText().isEmpty()) {
247 throw new IllegalArgumentException("subnet_id should not be empty"); 245 throw new IllegalArgumentException("subnet_id should not be empty");
248 } 246 }
249 - SubnetId subnetId = SubnetId.subnetId(subnode.get("subnet_id") 247 + SubnetId subnetId = SubnetId
250 - .asText()); 248 + .subnetId(subnode.get("subnet_id").asText());
251 if (!subnode.hasNonNull("port_id")) { 249 if (!subnode.hasNonNull("port_id")) {
252 throw new IllegalArgumentException("port_id should not be null"); 250 throw new IllegalArgumentException("port_id should not be null");
253 } else if (subnode.get("port_id").asText().isEmpty()) { 251 } else if (subnode.get("port_id").asText().isEmpty()) {
254 throw new IllegalArgumentException("port_id should not be empty"); 252 throw new IllegalArgumentException("port_id should not be empty");
255 } 253 }
256 - VirtualPortId portId = VirtualPortId.portId(subnode.get("port_id") 254 + VirtualPortId portId = VirtualPortId
257 - .asText()); 255 + .portId(subnode.get("port_id").asText());
258 if (!subnode.hasNonNull("tenant_id")) { 256 if (!subnode.hasNonNull("tenant_id")) {
259 throw new IllegalArgumentException("tenant_id should not be null"); 257 throw new IllegalArgumentException("tenant_id should not be null");
260 } else if (subnode.get("tenant_id").asText().isEmpty()) { 258 } else if (subnode.get("tenant_id").asText().isEmpty()) {
261 throw new IllegalArgumentException("tenant_id should not be empty"); 259 throw new IllegalArgumentException("tenant_id should not be empty");
262 } 260 }
263 - TenantId tenentId = TenantId.tenantId(subnode.get("tenant_id") 261 + TenantId tenentId = TenantId
264 - .asText()); 262 + .tenantId(subnode.get("tenant_id").asText());
265 RouterInterface routerInterface = RouterInterface 263 RouterInterface routerInterface = RouterInterface
266 .routerInterface(subnetId, portId, routerId, tenentId); 264 .routerInterface(subnetId, portId, routerId, tenentId);
267 get(RouterInterfaceService.class) 265 get(RouterInterfaceService.class)
...@@ -311,13 +309,13 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -311,13 +309,13 @@ public class RouterWebResource extends AbstractWebResource {
311 } else if (routerNode.get("tenant_id").asText().isEmpty()) { 309 } else if (routerNode.get("tenant_id").asText().isEmpty()) {
312 throw new IllegalArgumentException("tenant_id should not be empty"); 310 throw new IllegalArgumentException("tenant_id should not be empty");
313 } 311 }
314 - TenantId tenantId = TenantId.tenantId(routerNode.get("tenant_id") 312 + TenantId tenantId = TenantId
315 - .asText()); 313 + .tenantId(routerNode.get("tenant_id").asText());
316 314
317 VirtualPortId gwPortId = null; 315 VirtualPortId gwPortId = null;
318 if (routerNode.hasNonNull("gw_port_id")) { 316 if (routerNode.hasNonNull("gw_port_id")) {
319 - gwPortId = VirtualPortId.portId(routerNode.get("gw_port_id") 317 + gwPortId = VirtualPortId
320 - .asText()); 318 + .portId(routerNode.get("gw_port_id").asText());
321 } 319 }
322 320
323 if (!routerNode.hasNonNull("status")) { 321 if (!routerNode.hasNonNull("status")) {
...@@ -344,7 +342,59 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -344,7 +342,59 @@ public class RouterWebResource extends AbstractWebResource {
344 } 342 }
345 RouterGateway gateway = null; 343 RouterGateway gateway = null;
346 if (routerNode.hasNonNull("external_gateway_info")) { 344 if (routerNode.hasNonNull("external_gateway_info")) {
347 - gateway = jsonNodeToGateway(routerNode.get("external_gateway_info")); 345 + gateway = jsonNodeToGateway(routerNode
346 + .get("external_gateway_info"));
347 + }
348 + List<String> routes = new ArrayList<String>();
349 + DefaultRouter routerObj = new DefaultRouter(id, routerName,
350 + adminStateUp, status,
351 + distributed, gateway,
352 + gwPortId, tenantId, routes);
353 + subMap.put(id, routerObj);
354 + return Collections.unmodifiableCollection(subMap.values());
355 + }
356 +
357 + /**
358 + * Returns a collection of floatingIps from floatingIpNodes.
359 + *
360 + * @param subnode the router json node
361 + * @param routerId the router identify
362 + * @return routers a collection of router
363 + * @throws Exception when any argument is illegal
364 + */
365 + public Collection<Router> changeUpdateJsonToSub(JsonNode subnode,
366 + String routerId)
367 + throws Exception {
368 + checkNotNull(subnode, JSON_NOT_NULL);
369 + checkNotNull(routerId, "routerId should not be null");
370 + Map<RouterId, Router> subMap = new HashMap<RouterId, Router>();
371 + JsonNode routerNode = subnode.get("router");
372 + RouterId id = RouterId.valueOf(routerId);
373 + Router sub = nullIsNotFound(get(RouterService.class).getRouter(id),
374 + NOT_EXIST);
375 + TenantId tenantId = sub.tenantId();
376 +
377 + VirtualPortId gwPortId = null;
378 + if (routerNode.hasNonNull("gw_port_id")) {
379 + gwPortId = VirtualPortId
380 + .portId(routerNode.get("gw_port_id").asText());
381 + }
382 + Status status = sub.status();
383 +
384 + String routerName = routerNode.get("name").asText();
385 +
386 + checkArgument(routerNode.get("admin_state_up").isBoolean(),
387 + "admin_state_up should be boolean");
388 + boolean adminStateUp = routerNode.get("admin_state_up").asBoolean();
389 +
390 + boolean distributed = sub.distributed();
391 + if (routerNode.hasNonNull("distributed")) {
392 + distributed = routerNode.get("distributed").asBoolean();
393 + }
394 + RouterGateway gateway = sub.externalGatewayInfo();
395 + if (routerNode.hasNonNull("external_gateway_info")) {
396 + gateway = jsonNodeToGateway(routerNode
397 + .get("external_gateway_info"));
348 } 398 }
349 List<String> routes = new ArrayList<String>(); 399 List<String> routes = new ArrayList<String>();
350 DefaultRouter routerObj = new DefaultRouter(id, routerName, 400 DefaultRouter routerObj = new DefaultRouter(id, routerName,
...@@ -368,8 +418,8 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -368,8 +418,8 @@ public class RouterWebResource extends AbstractWebResource {
368 } else if (gateway.get("network_id").asText().isEmpty()) { 418 } else if (gateway.get("network_id").asText().isEmpty()) {
369 throw new IllegalArgumentException("network_id should not be empty"); 419 throw new IllegalArgumentException("network_id should not be empty");
370 } 420 }
371 - TenantNetworkId networkId = TenantNetworkId.networkId(gateway 421 + TenantNetworkId networkId = TenantNetworkId
372 - .get("network_id").asText()); 422 + .networkId(gateway.get("network_id").asText());
373 423
374 if (!gateway.hasNonNull("enable_snat")) { 424 if (!gateway.hasNonNull("enable_snat")) {
375 throw new IllegalArgumentException("enable_snat should not be null"); 425 throw new IllegalArgumentException("enable_snat should not be null");
...@@ -381,17 +431,14 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -381,17 +431,14 @@ public class RouterWebResource extends AbstractWebResource {
381 boolean enableSnat = gateway.get("enable_snat").asBoolean(); 431 boolean enableSnat = gateway.get("enable_snat").asBoolean();
382 432
383 if (!gateway.hasNonNull("external_fixed_ips")) { 433 if (!gateway.hasNonNull("external_fixed_ips")) {
384 - throw new IllegalArgumentException( 434 + throw new IllegalArgumentException("external_fixed_ips should not be null");
385 - "external_fixed_ips should not be null");
386 } else if (gateway.get("external_fixed_ips").isNull()) { 435 } else if (gateway.get("external_fixed_ips").isNull()) {
387 - throw new IllegalArgumentException( 436 + throw new IllegalArgumentException("external_fixed_ips should not be empty");
388 - "external_fixed_ips should not be empty");
389 } 437 }
390 Collection<FixedIp> fixedIpList = jsonNodeToFixedIp(gateway 438 Collection<FixedIp> fixedIpList = jsonNodeToFixedIp(gateway
391 .get("external_fixed_ips")); 439 .get("external_fixed_ips"));
392 - RouterGateway gatewayObj = RouterGateway.routerGateway(networkId, 440 + RouterGateway gatewayObj = RouterGateway
393 - enableSnat, 441 + .routerGateway(networkId, enableSnat, fixedIpList);
394 - fixedIpList);
395 return gatewayObj; 442 return gatewayObj;
396 } 443 }
397 444
...@@ -411,15 +458,15 @@ public class RouterWebResource extends AbstractWebResource { ...@@ -411,15 +458,15 @@ public class RouterWebResource extends AbstractWebResource {
411 } else if (node.get("subnet_id").asText().isEmpty()) { 458 } else if (node.get("subnet_id").asText().isEmpty()) {
412 throw new IllegalArgumentException("subnet_id should not be empty"); 459 throw new IllegalArgumentException("subnet_id should not be empty");
413 } 460 }
414 - SubnetId subnetId = SubnetId.subnetId(node.get("subnet_id") 461 + SubnetId subnetId = SubnetId
415 - .asText()); 462 + .subnetId(node.get("subnet_id").asText());
416 if (!node.hasNonNull("ip_address")) { 463 if (!node.hasNonNull("ip_address")) {
417 throw new IllegalArgumentException("ip_address should not be null"); 464 throw new IllegalArgumentException("ip_address should not be null");
418 } else if (node.get("ip_address").asText().isEmpty()) { 465 } else if (node.get("ip_address").asText().isEmpty()) {
419 throw new IllegalArgumentException("ip_address should not be empty"); 466 throw new IllegalArgumentException("ip_address should not be empty");
420 } 467 }
421 - IpAddress ipAddress = IpAddress.valueOf(node.get("ip_address") 468 + IpAddress ipAddress = IpAddress
422 - .asText()); 469 + .valueOf(node.get("ip_address").asText());
423 FixedIp fixedIpObj = FixedIp.fixedIp(subnetId, ipAddress); 470 FixedIp fixedIpObj = FixedIp.fixedIp(subnetId, ipAddress);
424 471
425 fixedIpMaps.putIfAbsent(i, fixedIpObj); 472 fixedIpMaps.putIfAbsent(i, fixedIpObj);
......