summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShireesh Anjal <shireesh@gluster.com>2011-07-31 16:43:00 +0530
committerShireesh Anjal <shireesh@gluster.com>2011-07-31 16:43:00 +0530
commit9767eba8d1da85749afa1b9dfb63ddfd3f5d5191 (patch)
tree5b665dc1fc213224f50f442b71574fcf2eccc554 /src
parentcc38ca499f91b0e788eb992e0bfa438663aa9a31 (diff)
Background task to periodically sync cluster-server mapping
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java2
-rw-r--r--src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java15
-rwxr-xr-xsrc/com.gluster.storage.management.server/WebContent/scripts/multicast-discover-servers.py (renamed from src/com.gluster.storage.management.server/WebContent/scripts/vmware-discover-servers.py)0
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractServersResource.java38
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/DiscoveredServersResource.java11
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java136
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/services/GlusterServerService.java165
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/ServerDiscoveryTask.java77
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/ServerSyncTask.java154
-rw-r--r--src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java2
-rw-r--r--src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml11
11 files changed, 366 insertions, 245 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java
index 51b53241..cbc51b10 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/constants/GlusterConstants.java
@@ -38,6 +38,8 @@ public class GlusterConstants {
public static final String ON = "on";
public static final String OFF = "off";
+ public static final String NONE = "none";
+
public static final String STATS_PERIOD_1DAY = "1d";
public static final String STATS_PERIOD_1WEEK = "1w";
public static final String STATS_PERIOD_1MONTH = "1m";
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java
index 7b1eec36..e5624954 100644
--- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java
+++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterCoreUtil.java
@@ -97,18 +97,17 @@ public class GlusterCoreUtil {
boolean caseInsensitive) {
return getEntity(entityList, searchEntity.getName(), caseInsensitive) != null;
}
+
+ public static <T extends Entity> boolean containsEntityWithName(List<T> entityList, String searchName,
+ boolean caseInsensitive) {
+ return getEntity(entityList, searchName, caseInsensitive) != null;
+ }
public static <T extends Entity> T getEntity(Collection<T> entityList, String searchEntityName, boolean caseInsensitive) {
- if (caseInsensitive) {
- searchEntityName = searchEntityName.toUpperCase();
- }
-
for (T entity : entityList) {
String nextEntityName = entity.getName();
- if (caseInsensitive) {
- nextEntityName = nextEntityName.toUpperCase();
- }
- if (nextEntityName.equals(searchEntityName)) {
+ if (nextEntityName.equals(searchEntityName)
+ || (caseInsensitive && nextEntityName.equalsIgnoreCase(searchEntityName))) {
return entity;
}
}
diff --git a/src/com.gluster.storage.management.server/WebContent/scripts/vmware-discover-servers.py b/src/com.gluster.storage.management.server/WebContent/scripts/multicast-discover-servers.py
index e9ae8666..e9ae8666 100755
--- a/src/com.gluster.storage.management.server/WebContent/scripts/vmware-discover-servers.py
+++ b/src/com.gluster.storage.management.server/WebContent/scripts/multicast-discover-servers.py
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractServersResource.java
deleted file mode 100644
index 8b4b6d99..00000000
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/AbstractServersResource.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * AbstractServersResource.java
- *
- * 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.v1_0;
-
-import com.gluster.storage.management.server.utils.GlusterUtil;
-import com.gluster.storage.management.server.utils.ServerUtil;
-import com.sun.jersey.api.core.InjectParam;
-
-/**
- * Abstract resource class for servers. Abstracts basic server related functionality like "get server details".
- */
-public class AbstractServersResource extends AbstractResource {
- @InjectParam
- protected ServerUtil serverUtil;
-
- @InjectParam
- protected GlusterUtil glusterUtil;
-
- // TODO: Remove this class!
-}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/DiscoveredServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/DiscoveredServersResource.java
index cb39746c..f6038b71 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/DiscoveredServersResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/DiscoveredServersResource.java
@@ -38,12 +38,21 @@ import org.springframework.stereotype.Component;
import com.gluster.storage.management.core.model.Server;
import com.gluster.storage.management.core.response.ServerListResponse;
import com.gluster.storage.management.core.response.ServerNameListResponse;
+import com.gluster.storage.management.server.utils.GlusterUtil;
+import com.gluster.storage.management.server.utils.ServerUtil;
+import com.sun.jersey.api.core.InjectParam;
import com.sun.jersey.spi.resource.Singleton;
@Component
@Singleton
@Path(RESOURCE_PATH_DISCOVERED_SERVERS)
-public class DiscoveredServersResource extends AbstractServersResource {
+public class DiscoveredServersResource extends AbstractResource {
+ @InjectParam
+ protected ServerUtil serverUtil;
+
+ @InjectParam
+ protected GlusterUtil glusterUtil;
+
private List<String> discoveredServerNames = new ArrayList<String>();
public List<String> getDiscoveredServerNames() {
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java
index 525f4132..fa96c884 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/v1_0/GlusterServersResource.java
@@ -51,7 +51,6 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.gluster.storage.management.core.constants.CoreConstants;
@@ -60,7 +59,6 @@ import com.gluster.storage.management.core.exceptions.ConnectionException;
import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
import com.gluster.storage.management.core.exceptions.GlusterValidationException;
import com.gluster.storage.management.core.model.GlusterServer;
-import com.gluster.storage.management.core.model.Server.SERVER_STATUS;
import com.gluster.storage.management.core.model.ServerStats;
import com.gluster.storage.management.core.model.TaskStatus;
import com.gluster.storage.management.core.response.GlusterServerListResponse;
@@ -68,10 +66,13 @@ import com.gluster.storage.management.core.response.ServerNameListResponse;
import com.gluster.storage.management.server.data.ClusterInfo;
import com.gluster.storage.management.server.data.ServerInfo;
import com.gluster.storage.management.server.services.ClusterService;
+import com.gluster.storage.management.server.services.GlusterServerService;
import com.gluster.storage.management.server.tasks.InitializeDiskTask;
import com.gluster.storage.management.server.utils.CpuStatsFactory;
+import com.gluster.storage.management.server.utils.GlusterUtil;
import com.gluster.storage.management.server.utils.MemoryStatsFactory;
import com.gluster.storage.management.server.utils.NetworkStatsFactory;
+import com.gluster.storage.management.server.utils.ServerUtil;
import com.gluster.storage.management.server.utils.SshUtil;
import com.gluster.storage.management.server.utils.StatsFactory;
import com.sun.jersey.api.core.InjectParam;
@@ -80,7 +81,7 @@ import com.sun.jersey.spi.resource.Singleton;
@Component
@Singleton
@Path(RESOURCE_PATH_CLUSTERS + "/{" + PATH_PARAM_CLUSTER_NAME + "}/" + RESOURCE_SERVERS)
-public class GlusterServersResource extends AbstractServersResource {
+public class GlusterServersResource extends AbstractResource {
public static final String HOSTNAMETAG = "hostname:";
@@ -90,31 +91,30 @@ public class GlusterServersResource extends AbstractServersResource {
@InjectParam
private TasksResource taskResource;
- @Autowired
+ @InjectParam
private ClusterService clusterService;
- @Autowired
+ @InjectParam
private SshUtil sshUtil;
- @Autowired
+ @InjectParam
private CpuStatsFactory cpuStatsFactory;
- @Autowired
+ @InjectParam
private MemoryStatsFactory memoryStatsFactory;
- @Autowired
+ @InjectParam
private NetworkStatsFactory networkStatsFactory;
- protected void fetchServerDetails(GlusterServer server) {
- try {
- server.setStatus(SERVER_STATUS.ONLINE);
- serverUtil.fetchServerDetails(server);
- } catch (ConnectionException e) {
- server.setStatus(SERVER_STATUS.OFFLINE);
- }
- }
-
-
+ @InjectParam
+ private ServerUtil serverUtil;
+
+ @InjectParam
+ private GlusterUtil glusterUtil;
+
+ @InjectParam
+ private GlusterServerService glusterServerService;
+
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getGlusterServersJSON(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName,
@@ -129,26 +129,6 @@ public class GlusterServersResource extends AbstractServersResource {
return getGlusterServers(clusterName, MediaType.APPLICATION_XML, details);
}
- private List<GlusterServer> getGlusterServers(String clusterName, boolean fetchDetails) {
- List<GlusterServer> glusterServers;
- GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
- }
-
- try {
- glusterServers = getGlusterServers(clusterName, onlineServer, fetchDetails);
- } catch (ConnectionException e) {
- // online server has gone offline! try with a different one.
- onlineServer = clusterService.getNewOnlineServer(clusterName);
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
- }
- glusterServers = getGlusterServers(clusterName, onlineServer, fetchDetails);
- }
- return glusterServers;
- }
-
private Response getGlusterServers(String clusterName, String mediaType, Boolean fetchDetails) {
if(fetchDetails == null) {
// by default, fetch the server details
@@ -171,7 +151,7 @@ public class GlusterServersResource extends AbstractServersResource {
}
try {
- glusterServers = getGlusterServers(clusterName, fetchDetails);
+ glusterServers = glusterServerService.getGlusterServers(clusterName, fetchDetails);
} catch (Exception e) {
return errorResponse(e.getMessage());
}
@@ -184,7 +164,6 @@ public class GlusterServersResource extends AbstractServersResource {
}
}
-
private List<String> getServerNames(List<GlusterServer> glusterServers) {
List<String> serverNames = new ArrayList<String>();
for(GlusterServer server : glusterServers) {
@@ -193,42 +172,6 @@ public class GlusterServersResource extends AbstractServersResource {
return serverNames;
}
- private String fetchDetailsOfServers(List<GlusterServer> glusterServers, GlusterServer onlineServer) {
- String errMsg = "";
-
- for (GlusterServer server : glusterServers) {
- try {
- fetchServerDetails(server);
- } catch (Exception e) {
- errMsg += CoreConstants.NEWLINE + server.getName() + " : [" + e.getMessage() + "]";
- }
- }
- return errMsg;
- }
-
- private List<GlusterServer> getGlusterServers(String clusterName, GlusterServer onlineServer, boolean fetchDetails) {
- List<GlusterServer> glusterServers;
- try {
- glusterServers = glusterUtil.getGlusterServers(onlineServer);
- } catch (ConnectionException e) {
- // online server has gone offline! try with a different one.
- onlineServer = clusterService.getNewOnlineServer(clusterName);
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
- }
-
- glusterServers = glusterUtil.getGlusterServers(onlineServer);
- }
-
- if (fetchDetails) {
- String errMsg = fetchDetailsOfServers(glusterServers, onlineServer);
- if (!errMsg.isEmpty()) {
- throw new GlusterRuntimeException("Couldn't fetch details for server(s): " + errMsg);
- }
- }
- return glusterServers;
- }
-
@GET
@Path("{" + PATH_PARAM_SERVER_NAME + "}")
@Produces(MediaType.APPLICATION_XML)
@@ -247,49 +190,12 @@ public class GlusterServersResource extends AbstractServersResource {
private Response getGlusterServerResponse(String clusterName, String serverName, String mediaType) {
try {
- return okResponse(getGlusterServer(clusterName, serverName), mediaType);
+ return okResponse(glusterServerService.getGlusterServer(clusterName, serverName, true), mediaType);
} catch (Exception e) {
return errorResponse(e.getMessage());
}
}
- private GlusterServer getGlusterServer(String clusterName, String serverName) {
- if (clusterName == null || clusterName.isEmpty()) {
- throw new GlusterRuntimeException("Cluster name must not be empty!");
- }
-
- if (serverName == null || serverName.isEmpty()) {
- throw new GlusterRuntimeException("Server name must not be empty!");
- }
-
- ClusterInfo cluster = clusterService.getCluster(clusterName);
- if (cluster == null) {
- throw new GlusterRuntimeException("Cluster [" + clusterName + "] not found!");
- }
-
- GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
- }
-
- GlusterServer server = null;
- try {
- server = glusterUtil.getGlusterServer(onlineServer, serverName);
- } catch (ConnectionException e) {
- // online server has gone offline! try with a different one.
- onlineServer = clusterService.getNewOnlineServer(clusterName);
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
- }
- server = glusterUtil.getGlusterServer(onlineServer, serverName);
- }
-
- if (server.isOnline()) {
- fetchServerDetails(server);
- }
- return server;
- }
-
private void performAddServer(String clusterName, String serverName) {
GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
if (onlineServer == null) {
@@ -542,7 +448,7 @@ public class GlusterServersResource extends AbstractServersResource {
return okResponse(new ServerStats(), mediaType);
}
- List<String> serverNames = getServerNames(getGlusterServers(clusterName, false));
+ List<String> serverNames = getServerNames(glusterServerService.getGlusterServers(clusterName, false));
return okResponse(getStatsFactory(type).fetchAggregatedStats(serverNames, period), mediaType);
}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/services/GlusterServerService.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/services/GlusterServerService.java
new file mode 100644
index 00000000..e8bea530
--- /dev/null
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/services/GlusterServerService.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * 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.services;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.gluster.storage.management.core.constants.CoreConstants;
+import com.gluster.storage.management.core.exceptions.ConnectionException;
+import com.gluster.storage.management.core.exceptions.GlusterRuntimeException;
+import com.gluster.storage.management.core.exceptions.GlusterValidationException;
+import com.gluster.storage.management.core.model.GlusterServer;
+import com.gluster.storage.management.core.model.Server.SERVER_STATUS;
+import com.gluster.storage.management.server.data.ClusterInfo;
+import com.gluster.storage.management.server.utils.GlusterUtil;
+import com.gluster.storage.management.server.utils.ServerUtil;
+
+/**
+ *
+ */
+@Component
+public class GlusterServerService {
+ @Autowired
+ protected ServerUtil serverUtil;
+
+ @Autowired
+ private ClusterService clusterService;
+
+ @Autowired
+ private GlusterUtil glusterUtil;
+
+ public void fetchServerDetails(GlusterServer server) {
+ try {
+ server.setStatus(SERVER_STATUS.ONLINE);
+ serverUtil.fetchServerDetails(server);
+ } catch (ConnectionException e) {
+ server.setStatus(SERVER_STATUS.OFFLINE);
+ }
+ }
+
+ public List<GlusterServer> getGlusterServers(String clusterName, boolean fetchDetails) {
+ List<GlusterServer> glusterServers;
+ GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
+ if (onlineServer == null) {
+ throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
+ }
+
+ try {
+ glusterServers = getGlusterServers(clusterName, onlineServer, fetchDetails);
+ } catch (ConnectionException e) {
+ // online server has gone offline! try with a different one.
+ onlineServer = clusterService.getNewOnlineServer(clusterName);
+ if (onlineServer == null) {
+ throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
+ }
+ glusterServers = getGlusterServers(clusterName, onlineServer, fetchDetails);
+ }
+ return glusterServers;
+ }
+
+ private List<GlusterServer> getGlusterServers(String clusterName, GlusterServer onlineServer, boolean fetchDetails) {
+ List<GlusterServer> glusterServers;
+ try {
+ glusterServers = glusterUtil.getGlusterServers(onlineServer);
+ } catch (ConnectionException e) {
+ // online server has gone offline! try with a different one.
+ onlineServer = clusterService.getNewOnlineServer(clusterName);
+ if (onlineServer == null) {
+ throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
+ }
+
+ glusterServers = glusterUtil.getGlusterServers(onlineServer);
+ }
+
+ if (fetchDetails) {
+ String errMsg = fetchDetailsOfServers(glusterServers, onlineServer);
+ if (!errMsg.isEmpty()) {
+ throw new GlusterRuntimeException("Couldn't fetch details for server(s): " + errMsg);
+ }
+ }
+ return glusterServers;
+ }
+
+ private String fetchDetailsOfServers(List<GlusterServer> glusterServers, GlusterServer onlineServer) {
+ String errMsg = "";
+
+ for (GlusterServer server : glusterServers) {
+ try {
+ fetchServerDetails(server);
+ } catch (Exception e) {
+ errMsg += CoreConstants.NEWLINE + server.getName() + " : [" + e.getMessage() + "]";
+ }
+ }
+ return errMsg;
+ }
+
+ public GlusterServer getGlusterServer(String clusterName, String serverName, Boolean fetchDetails) {
+ if (clusterName == null || clusterName.isEmpty()) {
+ throw new GlusterValidationException("Cluster name must not be empty!");
+ }
+
+ if (serverName == null || serverName.isEmpty()) {
+ throw new GlusterValidationException("Server name must not be empty!");
+ }
+
+ ClusterInfo cluster = clusterService.getCluster(clusterName);
+ if (cluster == null) {
+ throw new GlusterRuntimeException("Cluster [" + clusterName + "] not found!");
+ }
+
+ GlusterServer onlineServer = clusterService.getOnlineServer(clusterName);
+ if (onlineServer == null) {
+ throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
+ }
+
+ return getGlusterServer(clusterName, serverName, onlineServer, fetchDetails);
+ }
+
+ private GlusterServer getGlusterServer(String clusterName, String serverName, GlusterServer onlineServer,
+ Boolean fetchDetails) {
+ GlusterServer server = null;
+ try {
+ server = glusterUtil.getGlusterServer(onlineServer, serverName);
+ } catch (ConnectionException e) {
+ // online server has gone offline! try with a different one.
+ onlineServer = clusterService.getNewOnlineServer(clusterName);
+ if (onlineServer == null) {
+ throw new GlusterRuntimeException("No online servers found in cluster [" + clusterName + "]");
+ }
+ server = glusterUtil.getGlusterServer(onlineServer, serverName);
+ }
+
+ if (fetchDetails && server.isOnline()) {
+ fetchServerDetails(server);
+ }
+ return server;
+ }
+
+ public boolean isValidServer(String clusterName, String serverName) {
+ try {
+ GlusterServer server = getGlusterServer(clusterName, serverName, false);
+ return server != null;
+ } catch(Exception e) {
+ return false;
+ }
+ }
+}
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/ServerDiscoveryTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/ServerDiscoveryTask.java
deleted file mode 100644
index e5b8d726..00000000
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/ServerDiscoveryTask.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * ServerDiscoveryTask.java
- *
- * 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.tasks;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import com.gluster.storage.management.core.constants.CoreConstants;
-import com.gluster.storage.management.core.utils.ProcessResult;
-import com.gluster.storage.management.server.data.ClusterInfo;
-import com.gluster.storage.management.server.data.PersistenceDao;
-import com.gluster.storage.management.server.resources.v1_0.DiscoveredServersResource;
-import com.gluster.storage.management.server.utils.ServerUtil;
-
-/**
- * Task for auto-discovery of servers eligible to be added to the Gluster cluster. This task runs periodically and keeps
- * the discovered server list at a common place. The server resource can then pick it and send to client whenever
- * demanded.
- */
-@Component
-public class ServerDiscoveryTask {
- private static final String SCRIPT_NAME_SFX = "-discover-servers.py";
-
- @Autowired
- private ServerUtil serverUtil;
-
- @Autowired
- private DiscoveredServersResource discoveredServersResource;
-
- @Autowired
- private String environment;
-
- @Autowired
- private PersistenceDao<ClusterInfo> clusterDao;
-
- public void discoverServers() {
- List<String> serverNameList = new ArrayList<String>();
-
- ProcessResult result = serverUtil.executeGlusterScript(true, environment + SCRIPT_NAME_SFX, new ArrayList<String>());
- if(result.isSuccess()) {
- List<String> existingServers = clusterDao.findBySQL("select name from server_info");
- String serverNames = result.getOutput();
- String[] parts = serverNames.split(CoreConstants.NEWLINE);
- for(String serverName : parts) {
- // The server discovery mechanism will return every server that has not been "peer probed". However we
- // need to filter out those servers that are the "first" server of a new cluster, and hence are still
- // not peer probed.
- if(!existingServers.contains(serverName)) {
- serverNameList.add(serverName);
- }
- }
- }
-
- discoveredServersResource.setDiscoveredServerNames(serverNameList);
- }
-} \ No newline at end of file
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/ServerSyncTask.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/ServerSyncTask.java
new file mode 100644
index 00000000..feb02354
--- /dev/null
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/tasks/ServerSyncTask.java
@@ -0,0 +1,154 @@
+/**
+ * ServerDiscoveryTask.java
+ *
+ * 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.tasks;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.gluster.storage.management.core.constants.CoreConstants;
+import com.gluster.storage.management.core.constants.GlusterConstants;
+import com.gluster.storage.management.core.model.GlusterServer;
+import com.gluster.storage.management.core.utils.GlusterCoreUtil;
+import com.gluster.storage.management.core.utils.ProcessResult;
+import com.gluster.storage.management.server.data.ClusterInfo;
+import com.gluster.storage.management.server.data.PersistenceDao;
+import com.gluster.storage.management.server.data.ServerInfo;
+import com.gluster.storage.management.server.resources.v1_0.DiscoveredServersResource;
+import com.gluster.storage.management.server.services.ClusterService;
+import com.gluster.storage.management.server.services.GlusterServerService;
+import com.gluster.storage.management.server.utils.ServerUtil;
+
+/**
+ * Task for syncing server details. This performs two things: <br>
+ * 1. Auto-discovery of servers eligible to be added to the Gluster cluster. <br>
+ * 2. Syncing of cluster-server mapping with actual servers of the cluster. This mapping can go out of sync if user
+ * adds/removes servers manually using the CLI.
+ */
+@Component
+public class ServerSyncTask {
+ private static final String SCRIPT_NAME_SFX = "-discover-servers.py";
+
+ @Autowired
+ private ServerUtil serverUtil;
+
+ @Autowired
+ private DiscoveredServersResource discoveredServersResource;
+
+ @Autowired
+ private GlusterServerService glusterServerService;
+
+ @Autowired
+ private String discoveryMechanism;
+
+ @Autowired
+ private ClusterService clusterService;
+
+ @Autowired
+ private PersistenceDao<ClusterInfo> clusterDao;
+
+ public void perform() {
+ discoverServers();
+ syncClusterServerMapping();
+ }
+
+ private void syncClusterServerMapping() {
+ List<ClusterInfo> clusters = clusterService.getAllClusters();
+ for(ClusterInfo cluster : clusters) {
+ List<ServerInfo> servers = cluster.getServers();
+ List<GlusterServer> actualServers = glusterServerService.getGlusterServers(cluster.getName(), false);
+ updateRemovedServers(cluster, servers, actualServers);
+ updateAddedServers(cluster, servers, actualServers);
+ }
+ }
+
+ private void updateAddedServers(ClusterInfo cluster, List<ServerInfo> servers, List<GlusterServer> actualServers) {
+ List<String> addedServers = findAddedServers(cluster.getName(), servers, actualServers);
+ for(String addedServer : addedServers) {
+ clusterService.mapServerToCluster(cluster.getName(), addedServer);
+ }
+ }
+
+ private void updateRemovedServers(ClusterInfo cluster, List<ServerInfo> servers, List<GlusterServer> actualServers) {
+ List<String> removedServers = findRemovedServers(servers, actualServers);
+ for(String removedServer : removedServers) {
+ clusterService.unmapServerFromCluster(cluster.getName(), removedServer);
+ }
+ }
+
+ private List<String> findRemovedServers(List<ServerInfo> servers, List<GlusterServer> actualServers) {
+ List<String> removedServers = new ArrayList<String>();
+
+ for(ServerInfo server : servers) {
+ if (!GlusterCoreUtil.containsEntityWithName(actualServers, server.getName(), true)) {
+ removedServers.add(server.getName());
+ }
+ }
+ return removedServers;
+ }
+
+ private List<String> findAddedServers(String clusterName, List<ServerInfo> servers, List<GlusterServer> actualServers) {
+ List<String> addedServers = new ArrayList<String>();
+ for(GlusterServer actualServer : actualServers) {
+ if(!serverExists(servers, actualServer.getName())) {
+ addedServers.add(actualServer.getName());
+ }
+ }
+ return addedServers;
+ }
+
+ private boolean serverExists(List<ServerInfo> servers, String name) {
+ for(ServerInfo server : servers) {
+ if(server.getName().equalsIgnoreCase(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void discoverServers() {
+ if(discoveryMechanism.equals(GlusterConstants.NONE)) {
+ return;
+ }
+
+ List<String> serverNameList = new ArrayList<String>();
+
+ ProcessResult result = serverUtil.executeGlusterScript(true, discoveryMechanism + SCRIPT_NAME_SFX, new ArrayList<String>());
+ if(result.isSuccess()) {
+ List<String> existingServers = clusterDao.findBySQL("select name from server_info");
+ String serverNames = result.getOutput();
+ String[] parts = serverNames.split(CoreConstants.NEWLINE);
+ for(String serverName : parts) {
+ // The server discovery mechanism will return every server that has not been "peer probed". However we
+ // need to filter out those servers that are the "first" server of a new cluster, and hence are still
+ // not peer probed.
+ if(!existingServers.contains(serverName)) {
+ serverNameList.add(serverName);
+ }
+ }
+ }
+
+ discoveredServersResource.setDiscoveredServerNames(serverNameList);
+ }
+} \ No newline at end of file
diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
index 642198df..f5d09ac2 100644
--- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
+++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/GlusterUtil.java
@@ -84,7 +84,7 @@ public class GlusterUtil {
@Autowired
private ServerUtil serverUtil;
- @InjectParam
+ @Autowired
private TasksResource taskResource;
public void setSshUtil(SshUtil sshUtil) {
diff --git a/src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml b/src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml
index 76cd3082..3cf30ee4 100644
--- a/src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml
+++ b/src/com.gluster.storage.management.server/src/spring/gluster-server-base.xml
@@ -12,19 +12,20 @@
<task:executor id="taskExecutor" pool-size="1" />
<task:annotation-driven executor="taskExecutor" scheduler="taskScheduler" />
+ <!-- Syncs discovered servers and cluster-server mapping. -->
<task:scheduled-tasks>
- <task:scheduled ref="serverDiscoveryTask" method="discoverServers" fixed-delay="60000" />
+ <task:scheduled ref="serverSyncTask" method="perform" fixed-delay="60000" />
</task:scheduled-tasks>
<!-- This task keeps checking status of disk migration tasks (wherever auto-commit is set to true)
so that auto-commit can be performed as soon as the migration is complete -->
- <task:scheduled-tasks>
+ <!-- task:scheduled-tasks>
<task:scheduled ref="brickMigrationStatusTask" method="checkMigrationStatus" fixed-delay="60000" />
- </task:scheduled-tasks>
+ </task:scheduled-tasks-->
<!-- Cluster environment. Valid values: vmware, aws, baremetal -->
- <bean id="environment" class="java.lang.String">
- <constructor-arg value="vmware" />
+ <bean id="discoveryMechanism" class="java.lang.String">
+ <constructor-arg value="multicast" />
</bean>
<!-- SSH timeouts - all in milliseconds. zero means no timeout. -->