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 {
/**
* Currently only VXLAN moded is supported.
*/
VXLAN,
VLAN,
STT,
LOCAL
VXLAN
}
/**
......
......@@ -28,6 +28,7 @@ import org.slf4j.Logger;
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 @@ public class OpenstackRestHandler {
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 @@ public class OpenstackRestHandler {
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;
......
......@@ -56,13 +56,22 @@ public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> {
.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();
}
}
......