Add new kubernetes node state, add a set of state related REST APIs
Change-Id: I2ac3d9ff26030433e61148e0bf8963016f751f8a
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNodeHandler.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNodeHandler.java
index 71c3914..0ef7302 100644
--- a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNodeHandler.java
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNodeHandler.java
@@ -66,4 +66,13 @@
* @param k8sNode kubernetes node
*/
void processOnBoardedState(K8sNode k8sNode);
+
+ /**
+ * Processes the give node for post-on-board state.
+ * As long as external interface is configured,
+ * it will mark the node state as post-on-board.
+ *
+ * @param k8sNode kubernetes node
+ */
+ void processPostOnBoardState(K8sNode k8sNode);
}
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNodeState.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNodeState.java
index 2cdbe94..3311ac6 100644
--- a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNodeState.java
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sNodeState.java
@@ -49,6 +49,20 @@
}
},
/**
+ * Indicates the node is post-on-board.
+ */
+ POST_ON_BOARD {
+ @Override
+ public void process(K8sNodeHandler handler, K8sNode node) {
+ handler.processPostOnBoardState(node);
+ }
+
+ @Override
+ public K8sNodeState nextState() {
+ return POST_ON_BOARD;
+ }
+ },
+ /**
* Indicates the node is newly added.
*/
INIT {
diff --git a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sNodeHandler.java b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sNodeHandler.java
index 1c68f3d..a64b772 100644
--- a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sNodeHandler.java
+++ b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/impl/DefaultK8sNodeHandler.java
@@ -255,6 +255,11 @@
// do something if needed
}
+ @Override
+ public void processPostOnBoardState(K8sNode k8sNode) {
+ // do something if needed
+ }
+
/**
* Extracts properties from the component configuration context.
*
diff --git a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/web/K8sNodeWebResource.java b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/web/K8sNodeWebResource.java
index 3b1048f..1786f4c 100644
--- a/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/web/K8sNodeWebResource.java
+++ b/apps/k8s-node/app/src/main/java/org/onosproject/k8snode/web/K8sNodeWebResource.java
@@ -48,6 +48,7 @@
import static javax.ws.rs.core.Response.created;
import static org.onlab.util.Tools.nullIsIllegal;
import static org.onlab.util.Tools.readTreeFromStream;
+import static org.onosproject.k8snode.api.K8sNodeState.POST_ON_BOARD;
import static org.onosproject.k8snode.util.K8sNodeUtil.endpoint;
/**
@@ -70,6 +71,7 @@
private static final String INIT = "INIT";
private static final String NOT_EXIST = "Not exist";
private static final String STATE = "State";
+ private static final String RESULT = "Result";
private static final String HOST_NAME = "hostname";
private static final String ENDPOINT = "endpoint";
@@ -248,6 +250,39 @@
return ok(mapper().createObjectNode()).build();
}
+ /**
+ * 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
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("update/postonboard/{hostname}")
+ public Response postOnBoardNode(@PathParam("hostname") String hostname) {
+ nodeAdminService.node(hostname).updateState(POST_ON_BOARD);
+ return Response.ok().build();
+ }
+
+ /**
+ * Indicates whether all kubernetes nodes are in post-on-board state.
+ *
+ * @return 200 OK with True, or 200 OK with False
+ */
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("get/postonboard/all")
+ public Response postOnBoardNodes() {
+ long numOfAllNodes = nodeAdminService.nodes().size();
+ long numOfReadyNodes = nodeAdminService.nodes().stream()
+ .filter(n -> n.state() == POST_ON_BOARD)
+ .count();
+ boolean result = numOfAllNodes == numOfReadyNodes;
+
+ return ok(mapper().createObjectNode().put(RESULT, result)).build();
+ }
+
private Set<K8sNode> readNodeConfiguration(InputStream input) {
Set<K8sNode> nodeSet = Sets.newHashSet();
try {