mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-05 04:06:49 +02:00
Resolves code smells of Openstack node app.
Change-Id: Ibcb17b75baa8a22a316ac259ca41adf6a9a4ef43
This commit is contained in:
parent
eff5092ecd
commit
4b24cec4ca
@ -54,10 +54,7 @@ public class OpenstackNodeInitCommand extends AbstractShellCommand {
|
||||
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 @@ public class OpenstackNodeInitCommand extends AbstractShellCommand {
|
||||
.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) {
|
||||
|
||||
@ -20,12 +20,13 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
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 @@ public class DpdkConfigCodec extends JsonCodec<DpdkConfig> {
|
||||
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());
|
||||
|
||||
@ -19,17 +19,23 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
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 @@ public class DpdkInterfaceCodec extends JsonCodec<DpdkInterface> {
|
||||
|
||||
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()
|
||||
|
||||
@ -18,13 +18,11 @@ package org.onosproject.openstacknode.codec;
|
||||
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 @@ import static org.slf4j.LoggerFactory.getLogger;
|
||||
*/
|
||||
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";
|
||||
|
||||
@ -20,19 +20,15 @@ import org.onlab.packet.IpAddress;
|
||||
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
|
||||
|
||||
@ -18,21 +18,17 @@ package org.onosproject.openstacknode.codec;
|
||||
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";
|
||||
|
||||
|
||||
@ -19,13 +19,11 @@ package org.onosproject.openstacknode.codec;
|
||||
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 @@ import static org.slf4j.LoggerFactory.getLogger;
|
||||
*/
|
||||
public class OpenstackSshAuthCodec extends JsonCodec<OpenstackSshAuth> {
|
||||
|
||||
private final Logger log = getLogger(getClass());
|
||||
|
||||
private static final String ID = "id";
|
||||
private static final String PASSWORD = "password";
|
||||
|
||||
|
||||
@ -121,6 +121,7 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
|
||||
@Override
|
||||
public void processIncompleteState(OpenstackNode osNode) {
|
||||
//TODO
|
||||
//Do nothing for now
|
||||
}
|
||||
|
||||
private boolean hasDpdkTunnelBridge(OpenstackNode osNode) {
|
||||
@ -293,7 +294,7 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
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 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
if (!isRelevantHelper()) {
|
||||
return;
|
||||
}
|
||||
|
||||
processOpenstackNodeRemoved(event.subject());
|
||||
});
|
||||
break;
|
||||
@ -958,5 +934,40 @@ public class DefaultOpenstackNodeHandler implements OpenstackNodeHandler {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,51 +184,20 @@ public class DistributedOpenstackNodeStore
|
||||
*/
|
||||
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 @@ public class DistributedOpenstackNodeStore
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
@ -163,7 +163,7 @@ public final class OpenstackNodeUtil {
|
||||
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 @@ public final class OpenstackNodeUtil {
|
||||
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 @@ public final class OpenstackNodeUtil {
|
||||
|
||||
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 @@ public final class OpenstackNodeUtil {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -162,16 +162,11 @@ public class OpenstackNodeWebResource extends AbstractWebResource {
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user