summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-02-22 20:33:47 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-02-22 20:33:47 +0530
commitc95d2ea02cc4126ed5cf33dac5fba5971dcf88c6 (patch)
tree83b4477ed38636a59360409f342d493c0d91fb3b
parent3b50aecc54645135f31ae9f1f963ada100c316f3 (diff)
new resource GlusterServersResource and it's client
-rw-r--r--com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java61
-rw-r--r--com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java112
2 files changed, 173 insertions, 0 deletions
diff --git a/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java b/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java
new file mode 100644
index 00000000..fcc6f243
--- /dev/null
+++ b/com.gluster.storage.management.client/src/com/gluster/storage/management/client/GlusterServersClient.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
+ * This file is part of Gluster Management Console.
+ *
+ * Gluster Management Console is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Gluster Management Console is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *******************************************************************************/
+package com.gluster.storage.management.client;
+
+import java.util.List;
+
+import com.gluster.storage.management.core.model.Server;
+import com.gluster.storage.management.core.model.ServerDetailsResponse;
+import com.gluster.storage.management.core.model.ServerListResponse;
+
+public class GlusterServersClient extends AbstractClient {
+ private static final String RESOURCE_NAME = "cluster/servers";
+
+ public GlusterServersClient(String serverName) {
+ super(serverName);
+ }
+
+ @Override
+ public String getResourceName() {
+ return RESOURCE_NAME;
+ }
+
+ public List<Server> getServers() {
+ @SuppressWarnings("unchecked")
+ ServerListResponse<Server> response = (ServerListResponse<Server>) fetchResource(ServerListResponse.class);
+ return response.getData();
+ }
+
+ public Server getServer(String serverName) {
+ @SuppressWarnings("unchecked")
+ ServerDetailsResponse<Server> response = (ServerDetailsResponse<Server>) fetchSubResource(serverName,
+ ServerDetailsResponse.class);
+ return response.getData();
+ }
+
+ public String getServerXML(String serverName) {
+ return ((String) fetchSubResource(serverName, String.class));
+ }
+
+ public static void main(String[] args) {
+ GlusterServersClient ServerResource = new GlusterServersClient("localhost");
+ List<Server> glusterServers = ServerResource.getServers();
+ System.out.println(glusterServers.size());
+ }
+}
diff --git a/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java b/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java
new file mode 100644
index 00000000..41efa9f1
--- /dev/null
+++ b/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/GlusterServersResource.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Gluster, Inc. <http://www.gluster.com>
+ * This file is part of Gluster Management Console.
+ *
+ * Gluster Management Console is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Gluster Management Console is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *******************************************************************************/
+package com.gluster.storage.management.server.resources;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.MediaType;
+
+import org.springframework.stereotype.Component;
+
+import com.gluster.storage.management.client.GlusterServersClient;
+import com.gluster.storage.management.core.model.Server;
+import com.gluster.storage.management.core.model.ServerListResponse;
+import com.gluster.storage.management.core.model.Status;
+import com.gluster.storage.management.core.utils.ProcessResult;
+import com.gluster.storage.management.core.utils.ProcessUtil;
+import com.sun.jersey.spi.resource.Singleton;
+
+@Component
+@Singleton
+@Path("/cluster/servers")
+public class GlusterServersResource {
+
+ public static final String HOSTNAMETAG = "hostname:";
+
+ public List<String> getGlusterServerNames() {
+ ProcessResult result = new ProcessUtil().executeCommand("gluster-peer-status.py");
+ if (!result.isSuccess())
+ return null;
+
+ List<String> glusterServerNames = new ArrayList<String>();
+ // Parse the result to get the server names
+ for (String line : result.getOutput().split("\n")) {
+ if (line.toLowerCase().contains(HOSTNAMETAG)) {
+ for(String part : line.split(",")) {
+ if (part.toLowerCase().contains(HOSTNAMETAG)) {
+ glusterServerNames.add(part.split(HOSTNAMETAG)[1]);
+ break;
+ }
+ }
+ }
+ }
+ return glusterServerNames;
+ }
+
+ private List<Server> getServerDetails() {
+ List<Server> glusterServers = new ArrayList<Server>();
+ List<String> serverNames = getGlusterServerNames();
+ for(String serverName : serverNames) {
+ GlusterServersClient client = new GlusterServersClient(serverName);
+ Server server = client.getServer("me");
+ glusterServers.add(server);
+ }
+ return glusterServers;
+ }
+
+ @GET
+ @Produces(MediaType.TEXT_XML)
+ public ServerListResponse<Server> getServers() {
+ ServerListResponse<Server> response = new ServerListResponse<Server>();
+ response.setServers(getServerDetails());
+ response.setStatus(Status.STATUS_SUCCESS);
+ return response;
+ }
+
+ @GET
+ @Path("{serverName}")
+ @Produces(MediaType.TEXT_XML)
+ public String getGlusterServer(@PathParam("serverName") String serverName) {
+ if(serverName.equals("me")) {
+ return getThisServer();
+ }
+
+ // Fetch details of given server by sending a REST request to that server
+ return new GlusterServersClient(serverName).getServerXML("me");
+ }
+
+ public String getThisServer() {
+ ProcessResult result = new ProcessUtil().executeCommand("get-server-details.py");
+ if (!result.isSuccess()) {
+ // TODO:Generate error message and return
+ }
+ return result.getOutput();
+ }
+
+
+ public static void main(String[] args) {
+ GlusterServersResource glusterServersResource = new GlusterServersResource();
+ System.out.println(glusterServersResource.getGlusterServerNames());
+ }
+}