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
diff --git a/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java b/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java
index 181caf8..c760146 100644
--- a/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java
+++ b/apps/openstackswitching/api/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java
@@ -36,10 +36,7 @@
/**
* Currently only VXLAN moded is supported.
*/
- VXLAN,
- VLAN,
- STT,
- LOCAL
+ VXLAN
}
/**
diff --git a/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackRestHandler.java b/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackRestHandler.java
index 599b7e6..842e9fe 100644
--- a/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackRestHandler.java
+++ b/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/OpenstackRestHandler.java
@@ -28,6 +28,7 @@
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -70,6 +71,8 @@
String response = builder.accept(MediaType.APPLICATION_JSON_TYPE).
header("X-Auth-Token", getToken()).get(String.class);
+ log.debug("networks response:" + response);
+
ObjectMapper mapper = new ObjectMapper();
List<OpenstackNetwork> openstackNetworks = Lists.newArrayList();
try {
@@ -81,7 +84,7 @@
log.warn("getNetworks()", e);
}
- log.debug("networks response:" + response);
+ openstackNetworks.removeAll(Collections.singleton(null));
openstackNetworks.forEach(n -> log.debug("network ID: {}", n.id()));
return openstackNetworks;
diff --git a/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java b/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java
index 7466df7..92f1552 100644
--- a/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java
+++ b/apps/openstackswitching/app/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java
@@ -56,13 +56,22 @@
.tenantId(tenantId)
.id(id);
- if (!networkInfo.path(NETWORK_TYPE).isMissingNode()) {
- onb.networkType(OpenstackNetwork.NetworkType.valueOf(networkInfo.path(NETWORK_TYPE).
- asText().toUpperCase()));
- onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText());
+ if (networkInfo.path(NETWORK_TYPE).isMissingNode()) {
+ log.warn("Network {} has no network type, ignore it.", name);
+ return null;
}
+ String networkType = networkInfo.path(NETWORK_TYPE).asText();
+ try {
+ onb.networkType(OpenstackNetwork.NetworkType.valueOf(networkType.toUpperCase()));
+ } catch (IllegalArgumentException e) {
+ log.warn("Network {} has unsupported network type {}, ignore it.",
+ name, networkType);
+ return null;
+ }
+
+ onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText());
+
return onb.build();
}
-
}