yuanzac commented on a change in pull request #133: SUBMARINE-324. Submarine cluster status RESTful URL: https://github.com/apache/submarine/pull/133#discussion_r361623875
########## File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/rest/ClusterRestApi.java ########## @@ -0,0 +1,236 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.submarine.server.rest; + +import com.google.gson.Gson; +import org.apache.submarine.commons.cluster.ClusterServer; +import org.apache.submarine.commons.cluster.meta.ClusterMeta; +import org.apache.submarine.commons.cluster.meta.ClusterMetaType; +import org.apache.submarine.commons.utils.SubmarineConfiguration; +import org.apache.submarine.server.response.JsonResponse; +import org.apache.submarine.server.workbench.annotation.SubmarineApi; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * clusters Rest api. + */ +@Path(RestConstants.V1 + "/" + RestConstants.CLUSTER) +@Produces("application/json") +public class ClusterRestApi { + private static final Logger LOG = LoggerFactory.getLogger(ClusterRestApi.class); + Gson gson = new Gson(); + + private ClusterServer clusterServer = ClusterServer.getInstance(); + + // Do not modify, Use by `zeppelin-web/src/app/cluster/cluster.html` + public static String PROPERTIES = "properties"; + + @GET + @Path("/" + RestConstants.ADDRESS) + @SubmarineApi + public Response getClusterAddress() { + SubmarineConfiguration sConf = SubmarineConfiguration.getInstance(); + String clusterAddr = sConf.getClusterAddress(); + String[] arrAddr = clusterAddr.split(","); + List<String> listAddr = Arrays.asList(arrAddr); + + return new JsonResponse.Builder<List<String>>(Response.Status.OK) + .success(true).result(listAddr).build(); + } + + /** + * get all nodes of clusters + */ + @GET + @Path("/" + RestConstants.NODES) + @SubmarineApi + public Response getClusterNodes(){ + ArrayList<HashMap<String, Object>> nodes = new ArrayList<>(); + + Map<String, HashMap<String, Object>> clusterMeta = null; + Map<String, HashMap<String, Object>> intpMeta = null; + clusterMeta = clusterServer.getClusterMeta(ClusterMetaType.SERVER_META, ""); + intpMeta = clusterServer.getClusterMeta(ClusterMetaType.INTP_PROCESS_META, ""); + + // Number of calculation processes Review comment: I'm not sure what's the meaning of the comment. Maybe "Loop through the calculation processes" ? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
