summaryrefslogtreecommitdiffstats
path: root/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-08-19 13:40:09 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-08-19 13:40:09 +0530
commitf0412952e8a0e67f134d96963f8b9e3e8b4738c6 (patch)
treef06e522d48d5d7f4aea1454d19cb4c81443ec200 /src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java
parent9fdc4e3e7213544a4813e81ac778e38747f9b002 (diff)
Introduced DiscoveredServerService, and fetching discovered server details in parallel through multiple threads to improve performance.
Diffstat (limited to 'src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java')
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java90
1 files changed, 1 insertions, 89 deletions
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java
index 89143129..e95a8858 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java
@@ -91,18 +91,12 @@ public class GlusterServersResource extends AbstractResource {
public static final String HOSTNAMETAG = "hostname:";
@InjectParam
- private DiscoveredServersResource discoveredServersResource;
-
- @InjectParam
private TasksResource taskResource;
@InjectParam
private ClusterService clusterService;
@InjectParam
- private SshUtil sshUtil;
-
- @InjectParam
private CpuStatsFactory cpuStatsFactory;
@InjectParam
@@ -112,12 +106,6 @@ public class GlusterServersResource extends AbstractResource {
private NetworkStatsFactory networkStatsFactory;
@InjectParam
- private ServerUtil serverUtil;
-
- @InjectParam
- private GlusterUtil glusterUtil;
-
- @InjectParam
private GlusterServerService glusterServerService;
@GET
@@ -204,86 +192,10 @@ public class GlusterServersResource extends AbstractResource {
}
}
- private void performAddServer(String clusterName, String serverName) {
- GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online server found in cluster [" + clusterName + "]");
- }
-
- try {
- glusterUtil.addServer(onlineServer.getName(), serverName);
- } catch (Exception e) {
- // check if online server has gone offline. If yes, try again one more time.
- if (e instanceof ConnectionException || serverUtil.isServerOnline(onlineServer) == false) {
- // online server has gone offline! try with a different one.
- onlineServer = clusterService.getNewOnlineServer(clusterName);
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online server found in cluster [" + clusterName + "]");
- }
- glusterUtil.addServer(onlineServer.getName(), serverName);
- } else {
- throw new GlusterRuntimeException(e.getMessage());
- }
- }
- }
-
@POST
public Response addServer(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName,
@FormParam(FORM_PARAM_SERVER_NAME) String serverName) {
- if (clusterName == null || clusterName.isEmpty()) {
- return badRequestResponse("Cluster name must not be empty!");
- }
-
- if (serverName == null || serverName.isEmpty()) {
- return badRequestResponse("Parameter [" + FORM_PARAM_SERVER_NAME + "] is missing in request!");
- }
-
- ClusterInfo cluster = clusterService.getCluster(clusterName);
- if (cluster == null) {
- return notFoundResponse("Cluster [" + clusterName + "] not found!");
- }
-
- boolean publicKeyInstalled = sshUtil.isPublicKeyInstalled(serverName);
- if (!publicKeyInstalled && !sshUtil.hasDefaultPassword(serverName)) {
- // public key not installed, default password doesn't work. return with error.
- return errorResponse("Gluster Management Gateway uses the default password to set up keys on the server."
- + CoreConstants.NEWLINE + "However it seems that the password on server [" + serverName
- + "] has been changed manually." + CoreConstants.NEWLINE
- + "Please reset it back to the standard default password and try again.");
- }
-
- String hostName = serverUtil.fetchHostName(serverName);
- List<ServerInfo> servers = cluster.getServers();
- if (servers != null && !servers.isEmpty()) {
- // cluster has at least one existing server, so that peer probe can be performed
- performAddServer(clusterName, hostName);
- } else {
- // this is the first server to be added to the cluster, which means no
- // gluster CLI operation required. just add it to the cluster-server mapping
- }
-
- try {
- // add the cluster-server mapping
- clusterService.mapServerToCluster(clusterName, hostName);
- } catch (Exception e) {
- return errorResponse(e.getMessage());
- }
-
- // since the server is added to a cluster, it should not more be considered as a
- // discovered server available to other clusters
- discoveredServersResource.removeDiscoveredServer(hostName);
-
- if (!publicKeyInstalled) {
- try {
- // install public key (this will also disable password based ssh login)
- sshUtil.installPublicKey(hostName);
- } catch (Exception e) {
- return errorResponse("Public key could not be installed on [" + hostName + "]! Error: ["
- + e.getMessage() + "]");
- }
- }
-
- return createdResponse(hostName);
+ return createdResponse(glusterServerService.addServerToCluster(clusterName, serverName));
}
@DELETE