Search in sources :

Example 36 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class DefaultKubevirtNodeHandler method cleanPhysicalInterfaces.

private void cleanPhysicalInterfaces(KubevirtNode node) {
    Device device = deviceService.getDevice(node.ovsdb());
    BridgeConfig bridgeConfig = device.as(BridgeConfig.class);
    Set<String> bridgeNames = bridgeConfig.getBridges().stream().map(BridgeDescription::name).collect(Collectors.toSet());
    Set<String> phyNetworkNames = node.phyIntfs().stream().map(pi -> BRIDGE_PREFIX + pi.network()).collect(Collectors.toSet());
    // bridges are not defined in kubevirt node
    for (String brName : bridgeNames) {
        // physical bridges
        if (brName.equals(INTEGRATION_BRIDGE) || brName.equals(TUNNEL_BRIDGE) || brName.startsWith(TENANT_BRIDGE_PREFIX)) {
            continue;
        }
        if (!phyNetworkNames.contains(brName)) {
            removePhysicalPatchPorts(node, brName.substring(NETWORK_BEGIN));
            removePhysicalBridge(node, brName.substring(NETWORK_BEGIN));
            log.info("Removing physical bridge {}...", brName);
        }
    }
}
Also used : INTEGRATION_BRIDGE(org.onosproject.kubevirtnode.api.Constants.INTEGRATION_BRIDGE) DefaultBridgeDescription(org.onosproject.net.behaviour.DefaultBridgeDescription) GRE(org.onosproject.kubevirtnode.api.Constants.GRE) GATEWAY(org.onosproject.kubevirtnode.api.KubevirtNode.Type.GATEWAY) CoreService(org.onosproject.core.CoreService) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) KubevirtNodeUtil.getOvsdbClient(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.getOvsdbClient) DEVICE_CREATED(org.onosproject.kubevirtnode.api.KubevirtNodeState.DEVICE_CREATED) TpPort.tpPort(org.onlab.packet.TpPort.tpPort) GENEVE(org.onosproject.kubevirtnode.api.Constants.GENEVE) FlowRuleService(org.onosproject.net.flow.FlowRuleService) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) AUTO_RECOVERY(org.onosproject.kubevirtnode.impl.OsgiPropertyConstants.AUTO_RECOVERY) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) Thread.sleep(java.lang.Thread.sleep) NodeId(org.onosproject.cluster.NodeId) Device(org.onosproject.net.Device) AUTO_RECOVERY_DEFAULT(org.onosproject.kubevirtnode.impl.OsgiPropertyConstants.AUTO_RECOVERY_DEFAULT) Deactivate(org.osgi.service.component.annotations.Deactivate) KubevirtNodeUtil.isOvsdbConnected(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.isOvsdbConnected) BridgeName(org.onosproject.net.behaviour.BridgeName) Set(java.util.Set) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) Collectors(java.util.stream.Collectors) INTEGRATION_TO_TUNNEL(org.onosproject.kubevirtnode.api.Constants.INTEGRATION_TO_TUNNEL) OVSDB_PORT(org.onosproject.kubevirtnode.impl.OsgiPropertyConstants.OVSDB_PORT) DefaultPatchDescription(org.onosproject.net.behaviour.DefaultPatchDescription) Objects(java.util.Objects) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) List(java.util.List) TunnelEndPoints(org.onosproject.net.behaviour.TunnelEndPoints) INIT(org.onosproject.kubevirtnode.api.KubevirtNodeState.INIT) DeviceEvent(org.onosproject.net.device.DeviceEvent) ClusterService(org.onosproject.cluster.ClusterService) KubevirtNodeState(org.onosproject.kubevirtnode.api.KubevirtNodeState) DeviceId(org.onosproject.net.DeviceId) Dictionary(java.util.Dictionary) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) InterfaceConfig(org.onosproject.net.behaviour.InterfaceConfig) KubevirtNodeUtil.resolveHostname(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.resolveHostname) Tools(org.onlab.util.Tools) BridgeDescription(org.onosproject.net.behaviour.BridgeDescription) ComponentContext(org.osgi.service.component.ComponentContext) TUNNEL_BRIDGE(org.onosproject.kubevirtnode.api.Constants.TUNNEL_BRIDGE) PORT_NAME(org.onosproject.net.AnnotationKeys.PORT_NAME) TunnelKey(org.onosproject.net.behaviour.TunnelKey) APP_ID(org.onosproject.kubevirtnode.api.KubevirtNodeService.APP_ID) COMPLETE(org.onosproject.kubevirtnode.api.KubevirtNodeState.COMPLETE) INCOMPLETE(org.onosproject.kubevirtnode.api.KubevirtNodeState.INCOMPLETE) KubevirtNodeHandler(org.onosproject.kubevirtnode.api.KubevirtNodeHandler) PHYSICAL_TO_INTEGRATION_SUFFIX(org.onosproject.kubevirtnode.api.Constants.PHYSICAL_TO_INTEGRATION_SUFFIX) INTEGRATION_TO_PHYSICAL_PREFIX(org.onosproject.kubevirtnode.api.Constants.INTEGRATION_TO_PHYSICAL_PREFIX) KubevirtApiConfigService(org.onosproject.kubevirtnode.api.KubevirtApiConfigService) Component(org.osgi.service.component.annotations.Component) WORKER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.WORKER) Lists(com.google.common.collect.Lists) DefaultTunnelDescription(org.onosproject.net.behaviour.DefaultTunnelDescription) TENANT_BRIDGE_PREFIX(org.onosproject.kubevirtnode.api.Constants.TENANT_BRIDGE_PREFIX) KubevirtNodeUtil.structurePortName(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.structurePortName) Activate(org.osgi.service.component.annotations.Activate) ExecutorService(java.util.concurrent.ExecutorService) IpAddress(org.onlab.packet.IpAddress) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) ControllerInfo(org.onosproject.net.behaviour.ControllerInfo) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) BRIDGE_PREFIX(org.onosproject.kubevirtnode.api.Constants.BRIDGE_PREFIX) STT(org.onosproject.kubevirtnode.api.Constants.STT) PatchDescription(org.onosproject.net.behaviour.PatchDescription) TunnelDescription(org.onosproject.net.behaviour.TunnelDescription) FLOW_KEY(org.onosproject.kubevirtnode.api.Constants.FLOW_KEY) OVSDB_PORT_NUM_DEFAULT(org.onosproject.kubevirtnode.impl.OsgiPropertyConstants.OVSDB_PORT_NUM_DEFAULT) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DeviceAdminService(org.onosproject.net.device.DeviceAdminService) KubevirtNodeEvent(org.onosproject.kubevirtnode.api.KubevirtNodeEvent) KubevirtNodeListener(org.onosproject.kubevirtnode.api.KubevirtNodeListener) Modified(org.osgi.service.component.annotations.Modified) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) TUNNEL_TO_INTEGRATION(org.onosproject.kubevirtnode.api.Constants.TUNNEL_TO_INTEGRATION) VXLAN(org.onosproject.kubevirtnode.api.Constants.VXLAN) Reference(org.osgi.service.component.annotations.Reference) KubevirtNodeUtil.addOrRemoveSystemInterface(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.addOrRemoveSystemInterface) LeadershipService(org.onosproject.cluster.LeadershipService) KubevirtNodeUtil.getBooleanProperty(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.getBooleanProperty) Device(org.onosproject.net.Device) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig)

Example 37 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class DefaultKubevirtNodeHandler method setState.

/**
 * Configures the kubernetes node with new state.
 *
 * @param node          kubevirt node
 * @param newState      a new state
 */
private void setState(KubevirtNode node, KubevirtNodeState newState) {
    if (node.state() == newState) {
        return;
    }
    KubevirtNode updated = node.updateState(newState);
    nodeAdminService.updateNode(updated);
    log.info("Changed {} state: {}", node.hostname(), newState);
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode)

Example 38 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeUtil method buildKubevirtNode.

/**
 * Returns the kubevirt node from the node.
 *
 * @param node a raw node object returned from a k8s client
 * @return kubevirt node
 */
public static KubevirtNode buildKubevirtNode(Node node) {
    String hostname = node.getMetadata().getName();
    IpAddress managementIp = null;
    IpAddress dataIp = null;
    for (NodeAddress nodeAddress : node.getStatus().getAddresses()) {
        if (nodeAddress.getType().equals(INTERNAL_IP)) {
            managementIp = IpAddress.valueOf(nodeAddress.getAddress());
            dataIp = IpAddress.valueOf(nodeAddress.getAddress());
        }
    }
    Set<String> rolesFull = node.getMetadata().getLabels().keySet().stream().filter(l -> l.contains(K8S_ROLE)).collect(Collectors.toSet());
    KubevirtNode.Type nodeType = WORKER;
    for (String roleStr : rolesFull) {
        String role = roleStr.split("/")[1];
        if (MASTER.name().equalsIgnoreCase(role)) {
            nodeType = MASTER;
            break;
        }
    }
    // start to parse kubernetes annotation
    Map<String, String> annots = node.getMetadata().getAnnotations();
    String physnetConfig = annots.get(PHYSNET_CONFIG_KEY);
    String gatewayConfig = annots.get(GATEWAY_CONFIG_KEY);
    String dataIpStr = annots.get(DATA_IP_KEY);
    Set<KubevirtPhyInterface> phys = new HashSet<>();
    String gatewayBridgeName = null;
    try {
        if (physnetConfig != null) {
            JSONArray configJson = new JSONArray(physnetConfig);
            for (int i = 0; i < configJson.length(); i++) {
                JSONObject object = configJson.getJSONObject(i);
                String network = object.getString(NETWORK_KEY);
                String intf = object.getString(INTERFACE_KEY);
                if (network != null && intf != null) {
                    String physBridgeId;
                    if (object.has(PHYS_BRIDGE_ID)) {
                        physBridgeId = object.getString(PHYS_BRIDGE_ID);
                    } else {
                        physBridgeId = genDpidFromName(network + intf + hostname);
                        log.trace("host {} physnet dpid for network {} intf {} is null so generate dpid {}", hostname, network, intf, physBridgeId);
                    }
                    phys.add(DefaultKubevirtPhyInterface.builder().network(network).intf(intf).physBridge(DeviceId.deviceId(physBridgeId)).build());
                }
            }
        }
        if (dataIpStr != null) {
            dataIp = IpAddress.valueOf(dataIpStr);
        }
        if (gatewayConfig != null) {
            JsonNode jsonNode = new ObjectMapper().readTree(gatewayConfig);
            nodeType = GATEWAY;
            gatewayBridgeName = jsonNode.get(GATEWAY_BRIDGE_NAME).asText();
        }
    } catch (JSONException | JsonProcessingException e) {
        log.error("Failed to parse physnet config or gateway config object", e);
    }
    // if the node is taint with kubevirt.io key configured,
    // we mark this node as OTHER type, and do not add it into the cluster
    NodeSpec spec = node.getSpec();
    if (spec.getTaints() != null) {
        for (Taint taint : spec.getTaints()) {
            String effect = taint.getEffect();
            String key = taint.getKey();
            String value = taint.getValue();
            if (StringUtils.equals(effect, NO_SCHEDULE_EFFECT) && StringUtils.equals(key, KUBEVIRT_IO_KEY) && StringUtils.equals(value, DRAINING_VALUE)) {
                nodeType = OTHER;
            }
        }
    }
    return DefaultKubevirtNode.builder().hostname(hostname).managementIp(managementIp).dataIp(dataIp).type(nodeType).state(KubevirtNodeState.ON_BOARDED).phyIntfs(phys).gatewayBridgeName(gatewayBridgeName).build();
}
Also used : Address(org.xbill.DNS.Address) StringUtils(org.apache.commons.lang.StringUtils) OvsdbNodeId(org.onosproject.ovsdb.controller.OvsdbNodeId) GATEWAY(org.onosproject.kubevirtnode.api.KubevirtNode.Type.GATEWAY) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig) NodeSpec(io.fabric8.kubernetes.api.model.NodeSpec) DefaultKubevirtPhyInterface(org.onosproject.kubevirtnode.api.DefaultKubevirtPhyInterface) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) JSONException(org.json.JSONException) WORKER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.WORKER) JSONObject(org.json.JSONObject) OvsdbController(org.onosproject.ovsdb.controller.OvsdbController) OTHER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.OTHER) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Node(io.fabric8.kubernetes.api.model.Node) IpAddress(org.onlab.packet.IpAddress) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Tools.get(org.onlab.util.Tools.get) Logger(org.slf4j.Logger) Device(org.onosproject.net.Device) Taint(io.fabric8.kubernetes.api.model.Taint) BridgeName(org.onosproject.net.behaviour.BridgeName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) MASTER(org.onosproject.kubevirtnode.api.KubevirtNode.Type.MASTER) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) List(java.util.List) SONA_PROJECT_DOMAIN(org.onosproject.kubevirtnode.api.Constants.SONA_PROJECT_DOMAIN) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) OvsdbClientService(org.onosproject.ovsdb.controller.OvsdbClientService) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) KubevirtNodeState(org.onosproject.kubevirtnode.api.KubevirtNodeState) DeviceId(org.onosproject.net.DeviceId) JSONArray(org.json.JSONArray) Dictionary(java.util.Dictionary) BridgeConfig(org.onosproject.net.behaviour.BridgeConfig) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JsonNode(com.fasterxml.jackson.databind.JsonNode) Taint(io.fabric8.kubernetes.api.model.Taint) Taint(io.fabric8.kubernetes.api.model.Taint) DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) JSONObject(org.json.JSONObject) DefaultKubevirtPhyInterface(org.onosproject.kubevirtnode.api.DefaultKubevirtPhyInterface) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) NodeSpec(io.fabric8.kubernetes.api.model.NodeSpec) IpAddress(org.onlab.packet.IpAddress) NodeAddress(io.fabric8.kubernetes.api.model.NodeAddress) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet)

Example 39 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeWebResource method healthz.

/**
 * Returns the health check result.
 *
 * @return 200 OK with health check result, 404 not found
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("healthz")
public Response healthz() {
    KubevirtApiConfigService configService = get(KubevirtApiConfigService.class);
    KubevirtNodeService nodeService = get(KubevirtNodeService.class);
    // TODO: we need to add more health check items
    boolean allInit = true;
    KubevirtApiConfig config = configService.apiConfig();
    if (nodeService.nodes().size() == 0) {
        allInit = false;
    } else {
        for (KubevirtNode node : nodeService.nodes()) {
            if (node.state() != INIT) {
                allInit = false;
            }
        }
    }
    String result = ERROR;
    if (config != null && !allInit) {
        result = OK;
    }
    ObjectNode jsonResult = mapper().createObjectNode();
    jsonResult.put(API_CONFIG, result);
    return ok(jsonResult).build();
}
Also used : KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig) KubevirtApiConfigService(org.onosproject.kubevirtnode.api.KubevirtApiConfigService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeWebResource method initIncompleteNodes.

/**
 * Initializes KubeVirt nodes which are in the stats other than COMPLETE.
 *
 * @return 200 OK with init result, 500 server error
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("init/incomplete")
public Response initIncompleteNodes() {
    log.trace(String.format(MESSAGE_NODE, QUERY));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    service.nodes().stream().filter(n -> n.state() != KubevirtNodeState.COMPLETE).forEach(n -> {
        KubevirtNode updated = n.updateState(INIT);
        service.updateNode(updated);
    });
    return ok(mapper().createObjectNode()).build();
}
Also used : PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) KubevirtApiConfig(org.onosproject.kubevirtnode.api.KubevirtApiConfig) KubevirtNodeService(org.onosproject.kubevirtnode.api.KubevirtNodeService) COMPLETE(org.onosproject.kubevirtnode.api.KubevirtNodeState.COMPLETE) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtApiConfigService(org.onosproject.kubevirtnode.api.KubevirtApiConfigService) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) JsonNode(com.fasterxml.jackson.databind.JsonNode) UriBuilder(javax.ws.rs.core.UriBuilder) Tools.nullIsIllegal(org.onlab.util.Tools.nullIsIllegal) DELETE(javax.ws.rs.DELETE) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) Set(java.util.Set) Sets(com.google.common.collect.Sets) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) Response(javax.ws.rs.core.Response) INIT(org.onosproject.kubevirtnode.api.KubevirtNodeState.INIT) KubevirtNodeUtil.waitFor(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.waitFor) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) KubevirtNodeState(org.onosproject.kubevirtnode.api.KubevirtNodeState) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) InputStream(java.io.InputStream) Response.created(javax.ws.rs.core.Response.created) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)49 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)13 TrafficSelector (org.onosproject.net.flow.TrafficSelector)13 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)13 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)12 PortNumber (org.onosproject.net.PortNumber)11 KubevirtNodeAdminService (org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)10 DefaultKubevirtNode (org.onosproject.kubevirtnode.api.DefaultKubevirtNode)9 Produces (javax.ws.rs.Produces)8 KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Path (javax.ws.rs.Path)6 Test (org.junit.Test)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Set (java.util.Set)5 GET (javax.ws.rs.GET)5 MacAddress (org.onlab.packet.MacAddress)5 DeviceId (org.onosproject.net.DeviceId)5 DeviceService (org.onosproject.net.device.DeviceService)5 Logger (org.slf4j.Logger)5