Search in sources :

Example 6 with KubevirtNodeAdminService

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

the class KubevirtNodeWebResource method deleteNode.

/**
 * Removes a set of KubeVirt nodes' config from the JSON input stream.
 *
 * @param hostname host name contained in KubeVirt nodes configuration
 * @return 204 NO_CONTENT, 400 BAD_REQUEST if the JSON is malformed, and
 * 304 NOT_MODIFIED without the updated config
 */
@DELETE
@Path("{hostname}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteNode(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, REMOVE));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    KubevirtNode existing = service.node(nullIsIllegal(hostname, HOST_NAME + ERROR_MESSAGE));
    if (existing == null) {
        log.warn("There is no node configuration to delete : {}", hostname);
        return Response.notModified().build();
    } else {
        service.removeNode(hostname);
    }
    return Response.noContent().build();
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 7 with KubevirtNodeAdminService

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

the class KubevirtNodeWebResource method initNode.

/**
 * Initializes KubeVirt node.
 *
 * @param hostname hostname of KubeVirt node
 * @return 200 OK with init result, 404 not found, 500 server error
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("init/{hostname}")
public Response initNode(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, QUERY));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    KubevirtNode node = service.node(hostname);
    if (node == null) {
        log.error("Given node {} does not exist", hostname);
        return Response.serverError().build();
    }
    KubevirtNode updated = node.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 8 with KubevirtNodeAdminService

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

Example 9 with KubevirtNodeAdminService

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

the class KubevirtNodeWebResource method stateOfNode.

/**
 * Obtains the state of the KubeVirt node.
 *
 * @param hostname hostname of the KubeVirt
 * @return the state of the KubeVirt node in Json
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("state/{hostname}")
public Response stateOfNode(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, QUERY));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    KubevirtNode node = service.node(hostname);
    String nodeState = node != null ? node.state().toString() : NOT_EXIST;
    return ok(mapper().createObjectNode().put(STATE, nodeState)).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 10 with KubevirtNodeAdminService

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

the class KubevirtNodeWebResource method syncRules.

/**
 * Synchronizes the flow rules.
 *
 * @return 200 OK with sync result, 404 not found
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sync/rules")
public Response syncRules() {
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    service.completeNodes().forEach(node -> syncRulesBase(service, node));
    return ok(mapper().createObjectNode()).build();
}
Also used : KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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