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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations