Search in sources :

Example 31 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sNodeWebResource method initAllNodes.

/**
 * Initializes all kubernetes 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));
    nodeAdminService.nodes().forEach(n -> {
        K8sNode updated = n.updateState(K8sNodeState.INIT);
        nodeAdminService.updateNode(updated);
    });
    return ok(mapper().createObjectNode()).build();
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sNodeWebResource method deleteNodes.

/**
 * Removes a set of kubernetes nodes' config from the JSON input stream.
 *
 * @param hostname host name contained in kubernetes nodes configuration
 * @return 204 NO_CONTENT, 400 BAD_REQUEST if the JSON is malformed, and
 * 304 NOT_MODIFIED without the updated config
 */
@DELETE
@Path("node/{hostname}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteNodes(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, REMOVE));
    K8sNode existing = nodeAdminService.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 {
        nodeAdminService.removeNode(hostname);
    }
    return Response.noContent().build();
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 33 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sNodeWebResource method initIncompleteNodes.

/**
 * Initializes kubernetes 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));
    nodeAdminService.nodes().stream().filter(n -> n.state() != K8sNodeState.COMPLETE).forEach(n -> {
        K8sNode updated = n.updateState(K8sNodeState.INIT);
        nodeAdminService.updateNode(updated);
    });
    return ok(mapper().createObjectNode()).build();
}
Also used : PathParam(javax.ws.rs.PathParam) AbstractWebResource(org.onosproject.rest.AbstractWebResource) POST_ON_BOARD(org.onosproject.k8snode.api.K8sNodeState.POST_ON_BOARD) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) K8sNodeAdminService(org.onosproject.k8snode.api.K8sNodeAdminService) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) K8sApiConfigAdminService(org.onosproject.k8snode.api.K8sApiConfigAdminService) HashSet(java.util.HashSet) K8sApiConfig(org.onosproject.k8snode.api.K8sApiConfig) 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) K8sNodeState(org.onosproject.k8snode.api.K8sNodeState) K8sNode(org.onosproject.k8snode.api.K8sNode) IpAddress(org.onlab.packet.IpAddress) DELETE(javax.ws.rs.DELETE) 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) K8sHostAdminService(org.onosproject.k8snode.api.K8sHostAdminService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Response(javax.ws.rs.core.Response) K8sNodeUtil.endpoint(org.onosproject.k8snode.util.K8sNodeUtil.endpoint) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) K8sHost(org.onosproject.k8snode.api.K8sHost) Tools.readTreeFromStream(org.onlab.util.Tools.readTreeFromStream) InputStream(java.io.InputStream) Response.created(javax.ws.rs.core.Response.created) K8sNode(org.onosproject.k8snode.api.K8sNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class K8sNodeWebResource method initNode.

/**
 * Initializes kubernetes node.
 *
 * @param hostname hostname of kubernetes node
 * @return 200 OK with init result, 404 not found, 500 server error
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("init/node/{hostname}")
public Response initNode(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, QUERY));
    K8sNode k8sNode = nodeAdminService.node(hostname);
    if (k8sNode == null) {
        log.error("Given node {} does not exist", hostname);
        return Response.serverError().build();
    }
    K8sNode updated = k8sNode.updateState(K8sNodeState.INIT);
    nodeAdminService.updateNode(updated);
    return ok(mapper().createObjectNode()).build();
}
Also used : K8sNode(org.onosproject.k8snode.api.K8sNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 35 with K8sNode

use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.

the class DefaultK8sNodeHandler method setState.

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

Aggregations

K8sNode (org.onosproject.k8snode.api.K8sNode)40 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 DefaultK8sNode (org.onosproject.k8snode.api.DefaultK8sNode)8 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)8 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)8 TrafficSelector (org.onosproject.net.flow.TrafficSelector)8 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)8 IpAddress (org.onlab.packet.IpAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 CoreService (org.onosproject.core.CoreService)6 DeviceId (org.onosproject.net.DeviceId)6 Objects (java.util.Objects)5 Set (java.util.Set)5 ExecutorService (java.util.concurrent.ExecutorService)5 Executors.newSingleThreadExecutor (java.util.concurrent.Executors.newSingleThreadExecutor)5 Consumes (javax.ws.rs.Consumes)5 Tools.groupedThreads (org.onlab.util.Tools.groupedThreads)5 ClusterService (org.onosproject.cluster.ClusterService)5 LeadershipService (org.onosproject.cluster.LeadershipService)5