Search in sources :

Example 1 with KubevirtNodeAdminService

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

the class KubevirtInitNodeCommand method doExecute.

@Override
protected void doExecute() throws Exception {
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    if ((!isAll && !isIncomplete && hostnames == null) || (isAll && isIncomplete) || (isIncomplete && hostnames != null) || (hostnames != null && isAll)) {
        print("Please specify one of hostname, --all, and --incomplete options.");
        return;
    }
    if (isAll) {
        hostnames = service.nodes().stream().map(KubevirtNode::hostname).toArray(String[]::new);
    } else if (isIncomplete) {
        hostnames = service.nodes().stream().filter(node -> node.state() != COMPLETE).map(KubevirtNode::hostname).toArray(String[]::new);
    }
    for (String hostname : hostnames) {
        KubevirtNode node = service.node(hostname);
        if (node == null) {
            print("Unable to find %s", hostname);
            continue;
        }
        print("Initializing %s", hostname);
        KubevirtNode updated = node.updateState(INIT);
        service.updateNode(updated);
    }
    print("Done.");
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)

Example 2 with KubevirtNodeAdminService

use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService 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 3 with KubevirtNodeAdminService

use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService 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 4 with KubevirtNodeAdminService

use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService 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 5 with KubevirtNodeAdminService

use of org.onosproject.kubevirtnode.api.KubevirtNodeAdminService 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

KubevirtNodeAdminService (org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)11 KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)9 Produces (javax.ws.rs.Produces)8 Path (javax.ws.rs.Path)6 GET (javax.ws.rs.GET)5 Consumes (javax.ws.rs.Consumes)4 INDENT_OUTPUT (com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT)2 DELETE (javax.ws.rs.DELETE)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Sets (com.google.common.collect.Sets)1 Node (io.fabric8.kubernetes.api.model.Node)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 InputStream (java.io.InputStream)1 Set (java.util.Set)1 PathParam (javax.ws.rs.PathParam)1