Hyunsun Moon
Committed by Gerrit Code Review

Handled exception case of OpenStack network type

Ignore the network with unsupported network type to make sure no flow rules
populated for the network by any chance.

Change-Id: I3fe01900e5239af1ea28f4c6cb95869ff47964a9
...@@ -36,10 +36,7 @@ public final class OpenstackNetwork { ...@@ -36,10 +36,7 @@ public final class OpenstackNetwork {
36 /** 36 /**
37 * Currently only VXLAN moded is supported. 37 * Currently only VXLAN moded is supported.
38 */ 38 */
39 - VXLAN, 39 + VXLAN
40 - VLAN,
41 - STT,
42 - LOCAL
43 } 40 }
44 41
45 /** 42 /**
......
...@@ -28,6 +28,7 @@ import org.slf4j.Logger; ...@@ -28,6 +28,7 @@ import org.slf4j.Logger;
28 import javax.ws.rs.core.MediaType; 28 import javax.ws.rs.core.MediaType;
29 import java.io.IOException; 29 import java.io.IOException;
30 import java.util.Collection; 30 import java.util.Collection;
31 +import java.util.Collections;
31 import java.util.List; 32 import java.util.List;
32 33
33 import static com.google.common.base.Preconditions.checkNotNull; 34 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -70,6 +71,8 @@ public class OpenstackRestHandler { ...@@ -70,6 +71,8 @@ public class OpenstackRestHandler {
70 String response = builder.accept(MediaType.APPLICATION_JSON_TYPE). 71 String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
71 header("X-Auth-Token", getToken()).get(String.class); 72 header("X-Auth-Token", getToken()).get(String.class);
72 73
74 + log.debug("networks response:" + response);
75 +
73 ObjectMapper mapper = new ObjectMapper(); 76 ObjectMapper mapper = new ObjectMapper();
74 List<OpenstackNetwork> openstackNetworks = Lists.newArrayList(); 77 List<OpenstackNetwork> openstackNetworks = Lists.newArrayList();
75 try { 78 try {
...@@ -81,7 +84,7 @@ public class OpenstackRestHandler { ...@@ -81,7 +84,7 @@ public class OpenstackRestHandler {
81 log.warn("getNetworks()", e); 84 log.warn("getNetworks()", e);
82 } 85 }
83 86
84 - log.debug("networks response:" + response); 87 + openstackNetworks.removeAll(Collections.singleton(null));
85 openstackNetworks.forEach(n -> log.debug("network ID: {}", n.id())); 88 openstackNetworks.forEach(n -> log.debug("network ID: {}", n.id()));
86 89
87 return openstackNetworks; 90 return openstackNetworks;
......
...@@ -56,13 +56,22 @@ public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> { ...@@ -56,13 +56,22 @@ public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> {
56 .tenantId(tenantId) 56 .tenantId(tenantId)
57 .id(id); 57 .id(id);
58 58
59 - if (!networkInfo.path(NETWORK_TYPE).isMissingNode()) { 59 + if (networkInfo.path(NETWORK_TYPE).isMissingNode()) {
60 - onb.networkType(OpenstackNetwork.NetworkType.valueOf(networkInfo.path(NETWORK_TYPE). 60 + log.warn("Network {} has no network type, ignore it.", name);
61 - asText().toUpperCase())); 61 + return null;
62 - onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText());
63 } 62 }
64 63
64 + String networkType = networkInfo.path(NETWORK_TYPE).asText();
65 + try {
66 + onb.networkType(OpenstackNetwork.NetworkType.valueOf(networkType.toUpperCase()));
67 + } catch (IllegalArgumentException e) {
68 + log.warn("Network {} has unsupported network type {}, ignore it.",
69 + name, networkType);
70 + return null;
71 + }
72 +
73 + onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText());
74 +
65 return onb.build(); 75 return onb.build();
66 } 76 }
67 -
68 } 77 }
......