Search in sources :

Example 16 with KubevirtNode

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

the class KubevirtSyncStateCommand method bootstrapKubevirtNodes.

private void bootstrapKubevirtNodes(KubevirtApiConfig config) {
    KubevirtNodeAdminService nodeAdminService = get(KubevirtNodeAdminService.class);
    Set<KubevirtNode> completeNodeSet = nodeAdminService.completeNodes();
    KubernetesClient k8sClient = k8sClient(config);
    if (k8sClient == null) {
        log.warn("Failed to connect to kubernetes API server");
        return;
    }
    for (Node node : k8sClient.nodes().list().getItems()) {
        KubevirtNode kubevirtNode = buildKubevirtNode(node);
        // flow rules in worker nodes
        if (kubevirtNode.type() == WORKER) {
            if (completeNodeSet.stream().map(KubevirtNode::hostname).filter(name -> name.equals(kubevirtNode.hostname())).findAny().isPresent()) {
                print("Initializing %s because the node was COMPLETE state.", kubevirtNode.hostname());
                KubevirtNode updated = kubevirtNode.updateState(INIT);
                nodeAdminService.updateNode(updated);
            } else {
                nodeAdminService.updateNode(kubevirtNode);
            }
        }
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeUtil.buildKubevirtNode(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.buildKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeUtil.buildKubevirtNode(org.onosproject.kubevirtnode.util.KubevirtNodeUtil.buildKubevirtNode) Node(io.fabric8.kubernetes.api.model.Node) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)

Example 17 with KubevirtNode

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

the class KubevirtNodeWebResource method createNodes.

/**
 * Creates a set of KubeVirt nodes' config from the JSON input stream.
 *
 * @param input KubeVirt nodes JSON input stream
 * @return 201 CREATED if the JSON is correct, 400 BAD_REQUEST if the JSON
 * is malformed
 * @onos.rsModel KubevirtNode
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createNodes(InputStream input) {
    log.trace(String.format(MESSAGE_NODE, CREATE));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    readNodeConfiguration(input).forEach(node -> {
        KubevirtNode existing = service.node(node.hostname());
        if (existing == null) {
            service.createNode(node);
        }
    });
    UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(NODES).path(NODE_ID);
    return created(locationBuilder.build()).build();
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 18 with KubevirtNode

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

the class KubevirtNodeWebResource method initAllNodes.

/**
 * Initializes all KubeVirt nodes.
 *
 * @return 200 OK with init result, 500 server error
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("init/all")
public Response initAllNodes() {
    log.trace(String.format(MESSAGE_NODE, QUERY));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    service.nodes().forEach(n -> {
        KubevirtNode updated = n.updateState(INIT);
        service.updateNode(updated);
    });
    return ok(mapper().createObjectNode()).build();
}
Also used : 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)

Example 19 with KubevirtNode

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

the class KubevirtNodeWebResource method syncRulesBase.

private void syncRulesBase(KubevirtNodeAdminService service, KubevirtNode node) {
    KubevirtNode updated = node.updateState(INIT);
    service.updateNode(updated);
    boolean result = true;
    long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
    while (service.node(node.hostname()).state() != COMPLETE) {
        long waitMs = timeoutExpiredMs - System.currentTimeMillis();
        waitFor(SLEEP_S);
        if (waitMs <= 0) {
            result = false;
            break;
        }
    }
    if (result) {
        log.info("Successfully synchronize flow rules for node {}!", node.hostname());
    } else {
        log.warn("Failed to synchronize flow rules for node {}.", node.hostname());
    }
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode)

Example 20 with KubevirtNode

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

the class KubevirtNodeWebResource method updateNodes.

/**
 * Updates a set of KubeVirt nodes' config from the JSON input stream.
 *
 * @param input KubeVirt nodes JSON input stream
 * @return 200 OK with the updated KubeVirt node's config, 400 BAD_REQUEST
 * if the JSON is malformed, and 304 NOT_MODIFIED without the updated config
 * @onos.rsModel KubevirtNode
 */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateNodes(InputStream input) {
    log.trace(String.format(MESSAGE_NODE, UPDATE));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    Set<KubevirtNode> nodes = readNodeConfiguration(input);
    for (KubevirtNode node : nodes) {
        KubevirtNode existing = service.node(node.hostname());
        if (existing == null) {
            log.warn("There is no node configuration to update : {}", node.hostname());
            return Response.notModified().build();
        } else if (!existing.equals(node)) {
            service.updateNode(node);
        }
    }
    return Response.ok().build();
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) PUT(javax.ws.rs.PUT)

Aggregations

KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)46 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 KubevirtNodeAdminService (org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 DefaultKubevirtNode (org.onosproject.kubevirtnode.api.DefaultKubevirtNode)9 PortNumber (org.onosproject.net.PortNumber)9 Produces (javax.ws.rs.Produces)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 GET (javax.ws.rs.GET)5 KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)5 KubevirtNodeJsonMatcher.matchesKubevirtNode (org.onosproject.kubevirtnode.codec.KubevirtNodeJsonMatcher.matchesKubevirtNode)5 MacAddress (org.onlab.packet.MacAddress)4 KubevirtPhyInterface (org.onosproject.kubevirtnode.api.KubevirtPhyInterface)4 Device (org.onosproject.net.Device)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3