use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sNodeManager method updateNode.
@Override
public void updateNode(K8sNode node) {
checkNotNull(node, ERR_NULL_NODE);
K8sNode intNode;
K8sNode extNode;
K8sNode localNode;
K8sNode tunNode;
K8sNode existingNode = nodeStore.node(node.hostname());
checkNotNull(existingNode, ERR_NULL_NODE);
DeviceId existIntgBridge = nodeStore.node(node.hostname()).intgBridge();
if (node.intgBridge() == null) {
intNode = node.updateIntgBridge(existIntgBridge);
checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
} else {
intNode = node;
checkArgument(!hasIntgBridge(intNode.intgBridge(), intNode.hostname()), NOT_DUPLICATED_MSG, intNode.intgBridge());
}
DeviceId existExtBridge = nodeStore.node(node.hostname()).extBridge();
if (intNode.extBridge() == null) {
extNode = intNode.updateExtBridge(existExtBridge);
checkArgument(!hasExtBridge(extNode.extBridge(), extNode.hostname()), NOT_DUPLICATED_MSG, extNode.extBridge());
} else {
extNode = intNode;
checkArgument(!hasExtBridge(extNode.extBridge(), extNode.hostname()), NOT_DUPLICATED_MSG, extNode.extBridge());
}
DeviceId existLocalBridge = nodeStore.node(node.hostname()).localBridge();
if (extNode.localBridge() == null) {
localNode = extNode.updateLocalBridge(existLocalBridge);
checkArgument(!hasLocalBridge(localNode.localBridge(), localNode.hostname()), NOT_DUPLICATED_MSG, localNode.localBridge());
} else {
localNode = extNode;
checkArgument(!hasLocalBridge(localNode.localBridge(), localNode.hostname()), NOT_DUPLICATED_MSG, localNode.localBridge());
}
if (node.mode() == NORMAL) {
DeviceId existTunBridge = nodeStore.node(node.hostname()).tunBridge();
if (localNode.tunBridge() == null) {
tunNode = localNode.updateTunBridge(existTunBridge);
checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
} else {
tunNode = localNode;
checkArgument(!hasTunBridge(tunNode.tunBridge(), tunNode.hostname()), NOT_DUPLICATED_MSG, tunNode.tunBridge());
}
nodeStore.updateNode(tunNode);
} else {
nodeStore.updateNode(localNode);
}
log.info(String.format(MSG_NODE, extNode.hostname(), MSG_UPDATED));
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sNodeManager method removeNode.
@Override
public K8sNode removeNode(String hostname) {
checkArgument(!Strings.isNullOrEmpty(hostname), ERR_NULL_HOSTNAME);
K8sNode node = nodeStore.removeNode(hostname);
log.info(String.format(MSG_NODE, hostname, MSG_REMOVED));
return node;
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sNodeWebResource method stateOfNode.
/**
* Obtains the state of the kubernetes node.
*
* @param hostname hostname of the kubernetes
* @return the state of the kubernetes 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));
K8sNode k8sNode = nodeAdminService.node(hostname);
String nodeState = k8sNode != null ? k8sNode.state().toString() : NOT_EXIST;
return ok(mapper().createObjectNode().put(STATE, nodeState)).build();
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sNodeWebResource method postOnBoardNode.
/**
* Updates a kubernetes nodes' state as post-on-board.
*
* @param hostname kubernetes node name
* @return 200 OK with the updated kubernetes node's config, 400 BAD_REQUEST
* if the JSON is malformed, and 304 NOT_MODIFIED without the updated config
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("update/postonboard/{hostname}")
public Response postOnBoardNode(@PathParam("hostname") String hostname) {
K8sNode node = nodeAdminService.node(hostname);
if (node != null && node.state() != POST_ON_BOARD) {
K8sNode updated = node.updateState(POST_ON_BOARD);
nodeAdminService.updateNode(updated);
}
return Response.ok().build();
}
use of org.onosproject.k8snode.api.K8sNode in project onos by opennetworkinglab.
the class K8sNodeWebResource method updateNodes.
/**
* Updates a set of kubernetes nodes' config from the JSON input stream.
*
* @param input kubernetes nodes JSON input stream
* @return 200 OK with the updated kubernetes node's config, 400 BAD_REQUEST
* if the JSON is malformed, and 304 NOT_MODIFIED without the updated config
* @onos.rsModel K8sNode
*/
@PUT
@Path("node")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateNodes(InputStream input) {
log.trace(String.format(MESSAGE_NODE, UPDATE));
Set<K8sNode> nodes = readNodeConfiguration(input);
for (K8sNode node : nodes) {
K8sNode existing = nodeAdminService.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)) {
nodeAdminService.updateNode(node);
}
}
return Response.ok().build();
}
Aggregations