Resolves code smells of Openstack node app.
Change-Id: Ibcb17b75baa8a22a316ac259ca41adf6a9a4ef43
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/cli/OpenstackNodeInitCommand.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/cli/OpenstackNodeInitCommand.java
index 226560d..f9a51b0 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/cli/OpenstackNodeInitCommand.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/cli/OpenstackNodeInitCommand.java
@@ -54,10 +54,7 @@
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
OpenstackNodeAdminService osNodeAdminService = get(OpenstackNodeAdminService.class);
- if ((!isAll && !isIncomplete && hostnames == null) ||
- (isAll && isIncomplete) ||
- (isIncomplete && hostnames != null) ||
- (hostnames != null && isAll)) {
+ if (isAll && isIncomplete) {
print("Please specify one of hostname, --all, and --incomplete options.");
return;
}
@@ -71,6 +68,11 @@
.map(OpenstackNode::hostname).toArray(String[]::new);
}
+ if (hostnames == null) {
+ print("Please specify one of hostname, --all, and --incomplete options.");
+ return;
+ }
+
for (String hostname : hostnames) {
OpenstackNode osNode = osNodeService.node(hostname);
if (osNode == null) {
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/DpdkConfigCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/DpdkConfigCodec.java
index dcaed0f..13c8662 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/DpdkConfigCodec.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/DpdkConfigCodec.java
@@ -20,12 +20,13 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
+import org.onosproject.openstacknode.api.DefaultDpdkConfig;
import org.onosproject.openstacknode.api.DpdkConfig;
import org.onosproject.openstacknode.api.DpdkInterface;
-import org.onosproject.openstacknode.api.DefaultDpdkConfig;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.stream.IntStream;
import static org.onlab.util.Tools.nullIsIllegal;
@@ -70,7 +71,7 @@
DATA_PATH_TYPE + MISSING_MESSAGE);
DefaultDpdkConfig.Builder builder = DefaultDpdkConfig.builder()
- .datapathType(DpdkConfig.DatapathType.valueOf(datapathType.toUpperCase()));
+ .datapathType(DpdkConfig.DatapathType.valueOf(datapathType.toUpperCase(Locale.ENGLISH)));
if (json.get(SOCKET_DIR) != null) {
builder.socketDir(json.get(SOCKET_DIR).asText());
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/DpdkInterfaceCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/DpdkInterfaceCodec.java
index 2d38221..deb9eb5 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/DpdkInterfaceCodec.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/DpdkInterfaceCodec.java
@@ -19,17 +19,23 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
+import org.onosproject.openstacknode.api.DefaultDpdkInterface;
import org.onosproject.openstacknode.api.DpdkInterface;
import org.onosproject.openstacknode.api.DpdkInterface.Type;
-import org.onosproject.openstacknode.api.DefaultDpdkInterface;
+import org.slf4j.Logger;
+
+import java.util.Locale;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* DPDK interface codec used for serializing and de-serializing JSON string.
*/
public class DpdkInterfaceCodec extends JsonCodec<DpdkInterface> {
+ protected final Logger log = getLogger(getClass());
+
private static final String DEVICE_NAME = "deviceName";
private static final String INTF = "intf";
private static final String PCI_ADDRESS = "pciAddress";
@@ -68,9 +74,10 @@
Type type;
try {
- type = Type.valueOf(typeString.toUpperCase());
+ type = Type.valueOf(typeString.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
- throw new IllegalArgumentException(TYPE + MISSING_MESSAGE);
+ log.error(TYPE + MISSING_MESSAGE);
+ throw new IllegalArgumentException(e);
}
DpdkInterface.Builder builder = DefaultDpdkInterface.builder()
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackAuthCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackAuthCodec.java
index d3ddabb..2964980 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackAuthCodec.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackAuthCodec.java
@@ -18,13 +18,11 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
-import org.onosproject.openstacknode.api.OpenstackAuth;
import org.onosproject.openstacknode.api.DefaultOpenstackAuth;
-import org.slf4j.Logger;
+import org.onosproject.openstacknode.api.OpenstackAuth;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
-import static org.slf4j.LoggerFactory.getLogger;
/**
* Openstack keystone authentication codec used for serializing and
@@ -32,8 +30,6 @@
*/
public class OpenstackAuthCodec extends JsonCodec<OpenstackAuth> {
- private final Logger log = getLogger(getClass());
-
private static final String VERSION = "version";
private static final String PROTOCOL = "protocol";
private static final String USERNAME = "username";
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackControllerCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackControllerCodec.java
index 1921d43..7ac0659 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackControllerCodec.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackControllerCodec.java
@@ -20,19 +20,15 @@
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.net.behaviour.ControllerInfo;
-import org.slf4j.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
-import static org.slf4j.LoggerFactory.getLogger;
/**
* Openstack controller codec used for serializing and de-serializing JSON string.
*/
public class OpenstackControllerCodec extends JsonCodec<ControllerInfo> {
- private final Logger log = getLogger(getClass());
-
private static final String IP = "ip";
private static final String PORT = "port";
private static final String TCP = "tcp"; // controller connection should always be TCP
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceCodec.java
index d84abf8..551606e 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceCodec.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackPhyInterfaceCodec.java
@@ -18,21 +18,17 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
-import org.onosproject.openstacknode.api.OpenstackPhyInterface;
import org.onosproject.openstacknode.api.DefaultOpenstackPhyInterface;
-import org.slf4j.Logger;
+import org.onosproject.openstacknode.api.OpenstackPhyInterface;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
-import static org.slf4j.LoggerFactory.getLogger;
/**
* Openstack physical interface codec used for serializing and de-serializing JSON string.
*/
public final class OpenstackPhyInterfaceCodec extends JsonCodec<OpenstackPhyInterface> {
- private final Logger log = getLogger(getClass());
-
private static final String NETWORK = "network";
private static final String INTERFACE = "intf";
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackSshAuthCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackSshAuthCodec.java
index 56b860a..c7b4b49 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackSshAuthCodec.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackSshAuthCodec.java
@@ -19,13 +19,11 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
-import org.onosproject.openstacknode.api.OpenstackSshAuth;
import org.onosproject.openstacknode.api.DefaultOpenstackSshAuth;
-import org.slf4j.Logger;
+import org.onosproject.openstacknode.api.OpenstackSshAuth;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.nullIsIllegal;
-import static org.slf4j.LoggerFactory.getLogger;
/**
* Node ssh authentication info codec used for serializing and
@@ -33,8 +31,6 @@
*/
public class OpenstackSshAuthCodec extends JsonCodec<OpenstackSshAuth> {
- private final Logger log = getLogger(getClass());
-
private static final String ID = "id";
private static final String PASSWORD = "password";
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
index c2c3d57..01f8e4f 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNodeHandler.java
@@ -121,6 +121,7 @@
private final Logger log = getLogger(getClass());
private static final String DEFAULT_OF_PROTO = "tcp";
+ private static final String NO_OVSDB_CLIENT_MSG = "Failed to get ovsdb client";
private static final int DEFAULT_OFPORT = 6653;
private static final int DPID_BEGIN = 3;
@@ -278,7 +279,7 @@
@Override
public void processIncompleteState(OpenstackNode osNode) {
- //TODO
+ //Do nothing for now
}
private boolean hasDpdkTunnelBridge(OpenstackNode osNode) {
@@ -293,7 +294,7 @@
OvsdbClientService client = getOvsdbClient(osNode, ovsdbPortNum, ovsdbController);
if (client == null) {
- log.info("Failed to get ovsdb client");
+ log.info(NO_OVSDB_CLIENT_MSG);
return false;
}
@@ -453,6 +454,57 @@
port.isEnabled());
}
+
+ private boolean initStateDone(OpenstackNode osNode) {
+ if (!isOvsdbConnected(osNode, ovsdbPortNum, ovsdbController, deviceService)) {
+ return false;
+ }
+
+ boolean initStateDone = deviceService.isAvailable(osNode.intgBridge());
+ if (hasDpdkTunnelBridge(osNode)) {
+ initStateDone = initStateDone && dpdkTunnelBridgeCreated(osNode);
+ }
+
+ return initStateDone;
+ }
+
+ private boolean deviceCreatedStateDone(OpenstackNode osNode) {
+ if (osNode.dataIp() != null &&
+ !isIntfEnabled(osNode, VXLAN_TUNNEL)) {
+ return false;
+ }
+ if (osNode.dataIp() != null &&
+ !isIntfEnabled(osNode, GRE_TUNNEL)) {
+ return false;
+ }
+ if (osNode.dataIp() != null &&
+ !isIntfEnabled(osNode, GENEVE_TUNNEL)) {
+ return false;
+ }
+ if (osNode.vlanIntf() != null &&
+ !isIntfEnabled(osNode, osNode.vlanIntf())) {
+ return false;
+ }
+ if (osNode.type() == GATEWAY &&
+ !isIntfEnabled(osNode, osNode.uplinkPort())) {
+ return false;
+ }
+ if (osNode.dpdkConfig() != null &&
+ osNode.dpdkConfig().dpdkIntfs() != null &&
+ !isDpdkIntfsCreated(osNode, osNode.dpdkConfig().dpdkIntfs())) {
+ return false;
+ }
+
+ for (OpenstackPhyInterface intf : osNode.phyIntfs()) {
+ if (intf != null && !isIntfEnabled(osNode, intf.intf())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+
/**
* Checks whether all requirements for this state are fulfilled or not.
*
@@ -462,50 +514,9 @@
private boolean isCurrentStateDone(OpenstackNode osNode) {
switch (osNode.state()) {
case INIT:
- if (!isOvsdbConnected(osNode, ovsdbPortNum,
- ovsdbController, deviceService)) {
- return false;
- }
-
- boolean initStateDone = deviceService.isAvailable(osNode.intgBridge());
- if (hasDpdkTunnelBridge(osNode)) {
- initStateDone = initStateDone && dpdkTunnelBridgeCreated(osNode);
- }
- return initStateDone;
+ return initStateDone(osNode);
case DEVICE_CREATED:
- if (osNode.dataIp() != null &&
- !isIntfEnabled(osNode, VXLAN_TUNNEL)) {
- return false;
- }
- if (osNode.dataIp() != null &&
- !isIntfEnabled(osNode, GRE_TUNNEL)) {
- return false;
- }
- if (osNode.dataIp() != null &&
- !isIntfEnabled(osNode, GENEVE_TUNNEL)) {
- return false;
- }
- if (osNode.vlanIntf() != null &&
- !isIntfEnabled(osNode, osNode.vlanIntf())) {
- return false;
- }
- if (osNode.type() == GATEWAY &&
- !isIntfEnabled(osNode, osNode.uplinkPort())) {
- return false;
- }
- if (osNode.dpdkConfig() != null &&
- osNode.dpdkConfig().dpdkIntfs() != null &&
- !isDpdkIntfsCreated(osNode, osNode.dpdkConfig().dpdkIntfs())) {
- return false;
- }
-
- for (OpenstackPhyInterface intf : osNode.phyIntfs()) {
- if (intf != null && !isIntfEnabled(osNode, intf.intf())) {
- return false;
- }
- }
-
- return true;
+ return deviceCreatedStateDone(osNode);
case COMPLETE:
case INCOMPLETE:
// always return false
@@ -632,41 +643,6 @@
}
}
- private void processOpenstackNodeRemoved(OpenstackNode osNode) {
- OvsdbClientService client = getOvsdbClient(osNode, ovsdbPortNum, ovsdbController);
- if (client == null) {
- log.info("Failed to get ovsdb client");
- return;
- }
-
- //delete physical interfaces from the node
- removePhysicalInterface(osNode);
-
- //delete vlan interface from the node
- removeVlanInterface(osNode);
-
- //delete dpdk interfaces from the node
- if (osNode.dpdkConfig() != null) {
- osNode.dpdkConfig().dpdkIntfs().forEach(dpdkInterface -> {
- if (isDpdkIntfsCreated(osNode, Lists.newArrayList(dpdkInterface))) {
- addOrRemoveDpdkInterface(osNode, dpdkInterface, ovsdbPortNum,
- ovsdbController, false);
- }
- });
- }
-
- //delete tunnel bridge from the node
- if (hasDpdkTunnelBridge(osNode)) {
- client.dropBridge(TUNNEL_BRIDGE);
- }
-
- //delete integration bridge from the node
- client.dropBridge(INTEGRATION_BRIDGE);
-
- //disconnect ovsdb
- client.disconnect();
- }
-
/**
* Checks the validity of the given endpoint.
*
@@ -742,21 +718,10 @@
case DEVICE_AVAILABILITY_CHANGED:
case DEVICE_ADDED:
eventExecutor.execute(() -> {
-
if (!isRelevantHelper()) {
return;
}
-
- OpenstackNode osNode = osNodeService.node(device.id());
-
- if (osNode == null || osNode.type() == CONTROLLER) {
- return;
- }
-
- if (deviceService.isAvailable(device.id())) {
- log.debug("OVSDB {} detected", device.id());
- bootstrapNode(osNode);
- }
+ processDeviceAddedOfOvsdbDevice(osNodeService.node(device.id()), device);
});
break;
case PORT_ADDED:
@@ -767,6 +732,17 @@
break;
}
}
+
+ private void processDeviceAddedOfOvsdbDevice(OpenstackNode osNode, Device device) {
+ if (osNode == null || osNode.type() == CONTROLLER) {
+ return;
+ }
+
+ if (deviceService.isAvailable(device.id())) {
+ log.debug("OVSDB {} detected", device.id());
+ bootstrapNode(osNode);
+ }
+ }
}
/**
@@ -794,92 +770,27 @@
case DEVICE_AVAILABILITY_CHANGED:
case DEVICE_ADDED:
eventExecutor.execute(() -> {
-
if (!isRelevantHelper()) {
return;
}
-
- OpenstackNode osNode = osNodeService.node(device.id());
-
- if (osNode == null || osNode.type() == CONTROLLER) {
- return;
- }
-
- if (deviceService.isAvailable(device.id())) {
- log.debug("Integration bridge created on {}", osNode.hostname());
- bootstrapNode(osNode);
- } else if (osNode.state() == COMPLETE) {
- log.info("Device {} disconnected", device.id());
- setState(osNode, INCOMPLETE);
- }
-
- if (autoRecovery) {
- if (osNode.state() == INCOMPLETE ||
- osNode.state() == DEVICE_CREATED) {
- log.info("Device {} is reconnected", device.id());
- osNodeAdminService.updateNode(
- osNode.updateState(NodeState.INIT));
- }
- }
+ processDeviceAddedOfBridge(osNodeService.node(device.id()), device);
});
break;
case PORT_UPDATED:
case PORT_ADDED:
eventExecutor.execute(() -> {
-
if (!isRelevantHelper()) {
return;
}
-
- OpenstackNode osNode = osNodeService.node(device.id());
-
- if (osNode == null || osNode.type() == CONTROLLER) {
- return;
- }
-
- Port port = event.port();
- String portName = port.annotations().value(PORT_NAME);
- if (osNode.state() == DEVICE_CREATED && (
- Objects.equals(portName, VXLAN_TUNNEL) ||
- Objects.equals(portName, GRE_TUNNEL) ||
- Objects.equals(portName, GENEVE_TUNNEL) ||
- Objects.equals(portName, osNode.vlanIntf()) ||
- Objects.equals(portName, osNode.uplinkPort()) ||
- containsPhyIntf(osNode, portName)) ||
- containsDpdkIntfs(osNode, portName)) {
- log.info("Interface {} added or updated to {}",
- portName, device.id());
- bootstrapNode(osNode);
- }
+ processPortAddedOfBridge(osNodeService.node(device.id()), event.port());
});
break;
case PORT_REMOVED:
eventExecutor.execute(() -> {
-
if (!isRelevantHelper()) {
return;
}
-
- OpenstackNode osNode = osNodeService.node(device.id());
-
- if (osNode == null || osNode.type() == CONTROLLER) {
- return;
- }
-
- Port port = event.port();
- String portName = port.annotations().value(PORT_NAME);
- if (osNode.state() == COMPLETE && (
- Objects.equals(portName, VXLAN_TUNNEL) ||
- Objects.equals(portName, GRE_TUNNEL) ||
- Objects.equals(portName, GENEVE_TUNNEL) ||
- Objects.equals(portName, osNode.vlanIntf()) ||
- Objects.equals(portName, osNode.uplinkPort()) ||
- containsPhyIntf(osNode, portName)) ||
- containsDpdkIntfs(osNode, portName)) {
- log.warn("Interface {} removed from {}",
- portName, event.subject().id());
- setState(osNode, INCOMPLETE);
- }
+ processPortRemovedOfBridge(osNodeService.node(device.id()), event.port());
});
break;
case DEVICE_REMOVED:
@@ -888,37 +799,103 @@
break;
}
}
- }
- /**
- * Checks whether the openstack node contains the given physical interface.
- *
- * @param osNode openstack node
- * @param portName physical interface
- * @return true if openstack node contains the given physical interface,
- * false otherwise
- */
- private boolean containsPhyIntf(OpenstackNode osNode, String portName) {
- return osNode.phyIntfs().stream()
- .anyMatch(phyInterface -> phyInterface.intf().equals(portName));
- }
+ private void processDeviceAddedOfBridge(OpenstackNode osNode, Device device) {
- /**
- * Checks whether the openstack node contains the given dpdk interface.
- *
- * @param osNode openstack node
- * @param portName dpdk interface
- * @return true if openstack node contains the given dpdk interface,
- * false otherwise
- */
- private boolean containsDpdkIntfs(OpenstackNode osNode, String portName) {
- if (osNode.dpdkConfig() == null) {
- return false;
+ if (osNode == null || osNode.type() == CONTROLLER) {
+ return;
+ }
+
+ if (deviceService.isAvailable(device.id())) {
+ log.debug("Integration bridge created on {}", osNode.hostname());
+ bootstrapNode(osNode);
+ } else if (osNode.state() == COMPLETE) {
+ log.info("Device {} disconnected", device.id());
+ setState(osNode, INCOMPLETE);
+ }
+
+ if (autoRecovery) {
+ if (osNode.state() == INCOMPLETE ||
+ osNode.state() == DEVICE_CREATED) {
+ log.info("Device {} is reconnected", device.id());
+ osNodeAdminService.updateNode(
+ osNode.updateState(NodeState.INIT));
+ }
+ }
}
- return osNode.dpdkConfig().dpdkIntfs().stream()
- .anyMatch(dpdkInterface -> dpdkInterface.intf().equals(portName));
+
+ private void processPortAddedOfBridge(OpenstackNode osNode, Port port) {
+ if (osNode == null || osNode.type() == CONTROLLER) {
+ return;
+ }
+
+ String portName = port.annotations().value(PORT_NAME);
+ if (osNode.state() == DEVICE_CREATED && (
+ Objects.equals(portName, VXLAN_TUNNEL) ||
+ Objects.equals(portName, GRE_TUNNEL) ||
+ Objects.equals(portName, GENEVE_TUNNEL) ||
+ Objects.equals(portName, osNode.vlanIntf()) ||
+ Objects.equals(portName, osNode.uplinkPort()) ||
+ containsPhyIntf(osNode, portName)) ||
+ containsDpdkIntfs(osNode, portName)) {
+ log.info("Interface {} added or updated to {}",
+ portName, osNode.intgBridge());
+ bootstrapNode(osNode);
+ }
+ }
+
+ private void processPortRemovedOfBridge(OpenstackNode osNode, Port port) {
+ if (osNode == null || osNode.type() == CONTROLLER) {
+ return;
+ }
+
+ String portName = port.annotations().value(PORT_NAME);
+ if (osNode.state() == COMPLETE && (
+ Objects.equals(portName, VXLAN_TUNNEL) ||
+ Objects.equals(portName, GRE_TUNNEL) ||
+ Objects.equals(portName, GENEVE_TUNNEL) ||
+ Objects.equals(portName, osNode.vlanIntf()) ||
+ Objects.equals(portName, osNode.uplinkPort()) ||
+ containsPhyIntf(osNode, portName)) ||
+ containsDpdkIntfs(osNode, portName)) {
+ log.warn("Interface {} removed from {}",
+ portName, osNode.intgBridge());
+ setState(osNode, INCOMPLETE);
+ }
+ }
+
+
+ /**
+ * Checks whether the openstack node contains the given physical interface.
+ *
+ * @param osNode openstack node
+ * @param portName physical interface
+ * @return true if openstack node contains the given physical interface,
+ * false otherwise
+ */
+ private boolean containsPhyIntf(OpenstackNode osNode, String portName) {
+ return osNode.phyIntfs().stream()
+ .anyMatch(phyInterface -> phyInterface.intf().equals(portName));
+ }
+
+ /**
+ * Checks whether the openstack node contains the given dpdk interface.
+ *
+ * @param osNode openstack node
+ * @param portName dpdk interface
+ * @return true if openstack node contains the given dpdk interface,
+ * false otherwise
+ */
+ private boolean containsDpdkIntfs(OpenstackNode osNode, String portName) {
+ if (osNode.dpdkConfig() == null) {
+ return false;
+ }
+ return osNode.dpdkConfig().dpdkIntfs().stream()
+ .anyMatch(dpdkInterface -> dpdkInterface.intf().equals(portName));
+ }
}
+
/**
* An internal openstack node listener.
* The notification is triggered by OpenstackNodeStore.
@@ -949,7 +926,6 @@
if (!isRelevantHelper()) {
return;
}
-
processOpenstackNodeRemoved(event.subject());
});
break;
@@ -958,5 +934,40 @@
break;
}
}
+
+ private void processOpenstackNodeRemoved(OpenstackNode osNode) {
+ OvsdbClientService client = getOvsdbClient(osNode, ovsdbPortNum, ovsdbController);
+ if (client == null) {
+ log.info("Failed to get ovsdb client");
+ return;
+ }
+
+ //delete physical interfaces from the node
+ removePhysicalInterface(osNode);
+
+ //delete vlan interface from the node
+ removeVlanInterface(osNode);
+
+ //delete dpdk interfaces from the node
+ if (osNode.dpdkConfig() != null) {
+ osNode.dpdkConfig().dpdkIntfs().forEach(dpdkInterface -> {
+ if (isDpdkIntfsCreated(osNode, Lists.newArrayList(dpdkInterface))) {
+ addOrRemoveDpdkInterface(osNode, dpdkInterface, ovsdbPortNum,
+ ovsdbController, false);
+ }
+ });
+ }
+
+ //delete tunnel bridge from the node
+ if (hasDpdkTunnelBridge(osNode)) {
+ client.dropBridge(TUNNEL_BRIDGE);
+ }
+
+ //delete integration bridge from the node
+ client.dropBridge(INTEGRATION_BRIDGE);
+
+ //disconnect ovsdb
+ client.disconnect();
+ }
}
}
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
index 9014076..c6f5dac 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DistributedOpenstackNodeStore.java
@@ -184,51 +184,20 @@
*/
private class OpenstackNodeMapListener
implements MapEventListener<String, OpenstackNode> {
-
@Override
public void event(MapEvent<String, OpenstackNode> event) {
-
switch (event.type()) {
case INSERT:
log.debug("OpenStack node created {}", event.newValue());
- eventExecutor.execute(() ->
- notifyDelegate(new OpenstackNodeEvent(
- OPENSTACK_NODE_CREATED, event.newValue().value()
- )));
+ eventExecutor.execute(() -> processNodeCreation(event));
break;
case UPDATE:
log.debug("OpenStack node updated {}", event.newValue());
- eventExecutor.execute(() -> {
- notifyDelegate(new OpenstackNodeEvent(
- OPENSTACK_NODE_UPDATED,
- event.newValue().value()
- ));
-
- // if the event is about controller node, we will not
- // process COMPLETE and INCOMPLETE state
- if (isControllerNode(event)) {
- return;
- }
-
- if (event.newValue().value().state() == COMPLETE) {
- notifyDelegate(new OpenstackNodeEvent(
- OPENSTACK_NODE_COMPLETE,
- event.newValue().value()
- ));
- } else if (event.newValue().value().state() == INCOMPLETE) {
- notifyDelegate(new OpenstackNodeEvent(
- OPENSTACK_NODE_INCOMPLETE,
- event.newValue().value()
- ));
- }
- });
+ eventExecutor.execute(() -> processNodeUpdate(event));
break;
case REMOVE:
log.debug("OpenStack node removed {}", event.oldValue());
- eventExecutor.execute(() ->
- notifyDelegate(new OpenstackNodeEvent(
- OPENSTACK_NODE_REMOVED, event.oldValue().value()
- )));
+ eventExecutor.execute(() -> processNodeRemoval(event));
break;
default:
// do nothing
@@ -236,6 +205,41 @@
}
}
+ private void processNodeCreation(MapEvent<String, OpenstackNode> event) {
+ notifyDelegate(new OpenstackNodeEvent(
+ OPENSTACK_NODE_CREATED, event.newValue().value()));
+ }
+
+ private void processNodeUpdate(MapEvent<String, OpenstackNode> event) {
+ notifyDelegate(new OpenstackNodeEvent(
+ OPENSTACK_NODE_UPDATED,
+ event.newValue().value()
+ ));
+
+ // if the event is about controller node, we will not
+ // process COMPLETE and INCOMPLETE state
+ if (isControllerNode(event)) {
+ return;
+ }
+
+ if (event.newValue().value().state() == COMPLETE) {
+ notifyDelegate(new OpenstackNodeEvent(
+ OPENSTACK_NODE_COMPLETE,
+ event.newValue().value()
+ ));
+ } else if (event.newValue().value().state() == INCOMPLETE) {
+ notifyDelegate(new OpenstackNodeEvent(
+ OPENSTACK_NODE_INCOMPLETE,
+ event.newValue().value()
+ ));
+ }
+ }
+
+ private void processNodeRemoval(MapEvent<String, OpenstackNode> event) {
+ notifyDelegate(new OpenstackNodeEvent(
+ OPENSTACK_NODE_REMOVED, event.oldValue().value()));
+ }
+
/**
* Checks the openstack node whether a controller node or not with
* the given MapEvent.
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/util/OpenstackNodeUtil.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/util/OpenstackNodeUtil.java
index 277e58e..d478bcc 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/util/OpenstackNodeUtil.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/util/OpenstackNodeUtil.java
@@ -163,7 +163,7 @@
return null;
}
} catch (AuthenticationException e) {
- log.error("Authentication failed due to {}", e.toString());
+ log.error("Authentication failed due to {}", e);
return null;
}
}
@@ -183,6 +183,7 @@
String s = get(properties, propertyName);
value = Strings.isNullOrEmpty(s) ? null : Boolean.valueOf(s);
} catch (ClassCastException e) {
+ log.error("Exception occurred because of {}. set valud to null..", e);
value = null;
}
return value;
@@ -375,16 +376,21 @@
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
+ @Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
+ @Override
public void checkClientTrusted(X509Certificate[] certs,
String authType) {
+ return;
}
+ @Override
public void checkServerTrusted(X509Certificate[] certs,
String authType) {
+ return;
}
}
};
@@ -400,7 +406,7 @@
config.withSSLContext(sc);
} catch (Exception e) {
- log.error("Failed to access OpenStack service due to {}", e.toString());
+ log.error("Failed to access OpenStack service due to {}", e);
return null;
}
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
index 0acdb88..ae85af0 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/web/OpenstackNodeWebResource.java
@@ -162,16 +162,11 @@
JsonNode jsonTree = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
ArrayNode nodes = (ArrayNode) jsonTree.path(NODES);
nodes.forEach(node -> {
- try {
ObjectNode objectNode = node.deepCopy();
OpenstackNode openstackNode =
codec(OpenstackNode.class).decode(objectNode, this);
nodeSet.add(openstackNode);
- } catch (Exception e) {
- log.error("Exception occurred due to {}", e);
- throw new IllegalArgumentException();
- }
});
} catch (Exception e) {
throw new IllegalArgumentException(e);