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