summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSelvasundaram <selvam@gluster.com>2011-08-17 20:55:59 +0530
committerSelvasundaram <selvam@gluster.com>2011-08-17 20:57:31 +0530
commit525e707f782dd927ae80014174d83f76065d5e7a (patch)
treea468e953cc4fb10c36bad040218ab7e0ac14c1fc /src
parent383c7271a0a91310bd2eb55e24a548daf912b854 (diff)
Remove CIFS configuration while removing server from peer - backend script integration
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java27
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/resources/v1_0/GlusterServersResource.java78
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java87
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java52
-rw-r--r--src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java8
5 files changed, 169 insertions, 83 deletions
diff --git a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java
index 7f286191..41fa377e 100644
--- a/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java
+++ b/src/com.gluster.storage.management.console/src/com/gluster/storage/management/console/actions/RemoveServerAction.java
@@ -64,18 +64,21 @@ public class RemoveServerAction extends AbstractActionDelegate {
String errMsg = "";
for (GlusterServer server : selectedServers) {
guiHelper.setStatusMessage("Removing server [" + server.getName() + "]...");
-
+
GlusterServersClient client = new GlusterServersClient();
try {
client.removeServer(server.getName());
GlusterServer glusterServer = (GlusterServer) server;
modelManager.removeGlusterServer(glusterServer);
successServers.add(server);
- } catch(Exception e) {
+ } catch (Exception e) {
+ if (!isServerExist(server.getName())) {
+ modelManager.removeGlusterServer((GlusterServer) server);
+ successServers.add(server);
+ }
errMsg += "[" + server.getName() + "] : " + e.getMessage();
}
}
-
guiHelper.clearStatusMessage();
showStatusMessage(action.getDescription(), selectedServers, successServers, errMsg);
}
@@ -89,14 +92,28 @@ public class RemoveServerAction extends AbstractActionDelegate {
});
}
+ private Boolean isServerExist(String serverName) {
+ try {
+ GlusterServersClient client = new GlusterServersClient();
+ GlusterServer server = client.getGlusterServer(serverName);
+ if (server != null && server.getName().length() > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
private void showStatusMessage(String dialogTitle, Set<GlusterServer> selectedServers, Set<GlusterServer> successServers,
String errMsg) {
if (successServers.size() == selectedServers.size()) {
if(selectedServers.size() == 1) {
- showInfoDialog(dialogTitle, "Server [" + selectedServers.iterator().next() + "] removed successfully!");
+ showInfoDialog(dialogTitle, "Server [" + selectedServers.iterator().next() + "] removed successfully!" + CoreConstants.NEWLINE + errMsg);
} else {
showInfoDialog(dialogTitle, "Following servers removed successfully: " + CoreConstants.NEWLINE
- + selectedServers);
+ + selectedServers + CoreConstants.NEWLINE + errMsg);
}
return;
}
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 dc8fa3dd..d4a8bedf 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
@@ -25,10 +25,10 @@ import static com.gluster.storage.management.core.constants.RESTConstants.PATH_P
import static com.gluster.storage.management.core.constants.RESTConstants.PATH_PARAM_SERVER_NAME;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_DETAILS;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_INTERFACE;
-import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_PERIOD;
-import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_TYPE;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_MAX_COUNT;
import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_NEXT_TO;
+import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_PERIOD;
+import static com.gluster.storage.management.core.constants.RESTConstants.QUERY_PARAM_TYPE;
import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_DISKS;
import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_CLUSTERS;
import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_SERVERS;
@@ -62,6 +62,7 @@ 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;
import com.gluster.storage.management.core.model.ServerStats;
import com.gluster.storage.management.core.model.TaskStatus;
import com.gluster.storage.management.core.response.GlusterServerListResponse;
@@ -70,6 +71,7 @@ import com.gluster.storage.management.gateway.data.ClusterInfo;
import com.gluster.storage.management.gateway.data.ServerInfo;
import com.gluster.storage.management.gateway.services.ClusterService;
import com.gluster.storage.management.gateway.services.GlusterServerService;
+import com.gluster.storage.management.gateway.services.VolumeService;
import com.gluster.storage.management.gateway.tasks.InitializeDiskTask;
import com.gluster.storage.management.gateway.utils.CpuStatsFactory;
import com.gluster.storage.management.gateway.utils.GlusterUtil;
@@ -287,80 +289,10 @@ public class GlusterServersResource extends AbstractResource {
@Path("{" + PATH_PARAM_SERVER_NAME + "}")
public Response removeServer(@PathParam(PATH_PARAM_CLUSTER_NAME) String clusterName,
@PathParam(PATH_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("Server name must not be empty!");
- }
-
- ClusterInfo cluster = clusterService.getCluster(clusterName);
- if (cluster == null) {
- return notFoundResponse("Cluster [" + clusterName + "] not found!");
- }
-
- List<ServerInfo> servers = cluster.getServers();
- if (servers == null || servers.isEmpty() || !containsServer(servers, serverName)) {
- return badRequestResponse("Server [" + serverName + "] is not attached to cluster [" + clusterName + "]!");
- }
-
- if (servers.size() == 1) {
- // Only one server mapped to the cluster, no "peer detach" required.
- // remove the cached online server for this cluster if present
- clusterService.removeOnlineServer(clusterName);
- } else {
- try {
- removeServerFromCluster(clusterName, serverName);
- } catch (Exception e) {
- return errorResponse(e.getMessage());
- }
- }
- clusterService.unmapServerFromCluster(clusterName, serverName);
-
+ glusterServerService.removeServerFromCluster(clusterName, serverName);
return noContentResponse();
}
- private void removeServerFromCluster(String clusterName, String serverName) {
- // get an online server that is not same as the server being removed
- GlusterServer onlineServer = clusterService.getOnlineServer(clusterName, serverName);
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online server found in cluster [" + clusterName + "]");
- }
-
- try {
- glusterUtil.removeServer(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, serverName);
- }
- if (onlineServer == null) {
- throw new GlusterRuntimeException("No online server found in cluster [" + clusterName + "]");
- }
- glusterUtil.removeServer(onlineServer.getName(), serverName);
- }
-
- if (onlineServer.getName().equals(serverName)) {
- // since the cached server has been removed from the cluster, remove it from the cache
- clusterService.removeOnlineServer(clusterName);
- }
-
- // since the server is removed from the cluster, it is now available to be added to other clusters.
- // Hence add it back to the discovered servers list.
- discoveredServersResource.addDiscoveredServer(serverName);
- }
-
- private boolean containsServer(List<ServerInfo> servers, String serverName) {
- for (ServerInfo server : servers) {
- if (server.getName().toUpperCase().equals(serverName.toUpperCase())) {
- return true;
- }
- }
- return false;
- }
-
@PUT
@Produces(MediaType.APPLICATION_XML)
@Path("{" + PATH_PARAM_SERVER_NAME + "}/" + RESOURCE_DISKS + "/{" + PATH_PARAM_DISK_NAME + "}")
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java
index 8080df3e..d4f484f4 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/GlusterServerService.java
@@ -27,11 +27,13 @@ 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.Entity;
import com.gluster.storage.management.core.model.GlusterServer;
+import com.gluster.storage.management.core.model.Server;
import com.gluster.storage.management.core.model.Server.SERVER_STATUS;
import com.gluster.storage.management.core.utils.GlusterCoreUtil;
import com.gluster.storage.management.gateway.data.ClusterInfo;
+import com.gluster.storage.management.gateway.data.ServerInfo;
+import com.gluster.storage.management.gateway.resources.v1_0.DiscoveredServersResource;
import com.gluster.storage.management.gateway.utils.GlusterUtil;
import com.gluster.storage.management.gateway.utils.ServerUtil;
@@ -49,6 +51,13 @@ public class GlusterServerService {
@Autowired
private GlusterUtil glusterUtil;
+ @Autowired
+ private VolumeService volumeService;
+
+ // TODO: create a discovered servers "service" instead of injecting the resource directly
+ @Autowired
+ private DiscoveredServersResource discoveredServersResource;
+
public void fetchServerDetails(GlusterServer server) {
try {
server.setStatus(SERVER_STATUS.ONLINE);
@@ -178,4 +187,80 @@ public class GlusterServerService {
return false;
}
}
+
+ public void removeServerFromCluster(String clusterName, String serverName) {
+ 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 GlusterValidationException("Cluster [" + clusterName + "] not found!");
+ }
+
+ List<ServerInfo> servers = cluster.getServers();
+ if (servers == null || servers.isEmpty() || !containsServer(servers, serverName)) {
+ throw new GlusterValidationException("Server [" + serverName + "] is not attached to cluster ["
+ + clusterName + "]!");
+ }
+
+ if (servers.size() == 1) {
+ // Only one server mapped to the cluster, no "peer detach" required.
+ // remove the cached online server for this cluster if present
+ clusterService.removeOnlineServer(clusterName);
+ } else {
+ // get an online server that is not same as the server being removed
+ GlusterServer onlineServer = clusterService.getOnlineServer(clusterName, serverName);
+ if (onlineServer == null) {
+ throw new GlusterRuntimeException("No online server found in cluster [" + clusterName + "]");
+ }
+
+ try {
+ glusterUtil.removeServer(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, serverName);
+ }
+ if (onlineServer == null) {
+ throw new GlusterRuntimeException("No online server found in cluster [" + clusterName + "]");
+ }
+ glusterUtil.removeServer(onlineServer.getName(), serverName);
+ }
+
+ try {
+ if (serverUtil.isServerOnline(new Server(serverName))) {
+ volumeService.clearCifsConfiguration(clusterName, onlineServer.getName(), serverName);
+ }
+ } catch (Exception e1) {
+ throw new GlusterRuntimeException(
+ "Server removed from cluster, however deleting cifs configuration failed ! [ "
+ + e1.getMessage() + "]");
+ }
+ if (onlineServer.getName().equals(serverName)) {
+ // since the cached server has been removed from the cluster, remove it from the cache
+ clusterService.removeOnlineServer(clusterName);
+ }
+
+ // since the server is removed from the cluster, it is now available to be added to other clusters.
+ // Hence add it back to the discovered servers list.
+ discoveredServersResource.addDiscoveredServer(serverName);
+ }
+
+ clusterService.unmapServerFromCluster(clusterName, serverName);
+ }
+
+ private boolean containsServer(List<ServerInfo> servers, String serverName) {
+ for (ServerInfo server : servers) {
+ if (server.getName().toUpperCase().equals(serverName.toUpperCase())) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java
index 944b29c6..760e22fd 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/services/VolumeService.java
@@ -33,7 +33,6 @@ import java.util.Date;
import java.util.List;
import org.apache.log4j.Logger;
-import org.hibernate.mapping.Array;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -76,7 +75,8 @@ public class VolumeService {
private static final String VOLUME_DELETE_CIFS_SCRIPT = "delete_volume_cifs_all.py";
private static final String VOLUME_BRICK_LOG_SCRIPT = "get_volume_brick_log.py";
private static final String VOLUME_DIRECTORY_CLEANUP_SCRIPT = "clear_volume_directory.py";
-
+ private static final String REMOVE_SERVER_VOLUME_CIFS_CONFIG = "remove_server_volume_cifs_config.py";
+ private static final String ALL_ONLINE_VOLUMES_FILE_NAME = "volumes";
@Autowired
private ClusterService clusterService;
@@ -351,6 +351,54 @@ public class VolumeService {
}
}
+ // To clear all the volume CIFS configurations from the server
+ public void clearCifsConfiguration(String clusterName, String onlineServerName, String serverName) {
+ VolumeService volumeService = new VolumeService();
+ File volumesFile = createOnlineVolumeList(clusterName, onlineServerName);
+ if (volumesFile == null) {
+ return;
+ }
+ try {
+ volumeService.removeServerVolumeCifsConfig(serverName, volumesFile.getAbsolutePath());
+ volumesFile.delete();
+ } catch(Exception e) {
+ volumesFile.delete();
+ throw new GlusterRuntimeException("Error in clearing volume CIFS configuration: [" + e.getMessage() + "]");
+ }
+ }
+
+ private File createOnlineVolumeList(String clusterName, String onlineServerName) {
+ String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
+ String volumeListFileName = FileUtil.getTempDirName() + CoreConstants.FILE_SEPARATOR
+ + ALL_ONLINE_VOLUMES_FILE_NAME + "_" + timestamp;
+ try {
+ List<Volume> volumes = getVolumes(clusterName);
+ if (volumes.size() == 0) {
+ return null;
+ }
+ File volumesFile = new File(volumeListFileName);
+ FileOutputStream fos = new FileOutputStream(volumesFile);
+ for (Volume volume : volumes) {
+ if (volume.getStatus() == VOLUME_STATUS.ONLINE) {
+ fos.write((volume.getName() + CoreConstants.NEWLINE).getBytes());
+ }
+ }
+ fos.close();
+ return volumesFile;
+ } catch (Exception e) {
+ throw new GlusterRuntimeException("Error in preparing volume list: [" + e.getMessage() + "]");
+ }
+ }
+
+
+ public void removeServerVolumeCifsConfig(String serverName, String volumesFileName) {
+ ProcessResult result = serverUtil.executeGlusterScript(true, REMOVE_SERVER_VOLUME_CIFS_CONFIG, serverName,
+ volumesFileName);
+ if (!result.isSuccess()) {
+ throw new GlusterRuntimeException(result.toString());
+ }
+ }
+
public void createVolume(String clusterName, String volumeName, String volumeType, String transportType,
Integer replicaCount, Integer stripeCount, String bricks, String accessProtocols, String options,
String cifsUsers) {
diff --git a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
index e057787f..f10feb2a 100644
--- a/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
+++ b/src/com.gluster.storage.management.gateway/src/com/gluster/storage/management/gateway/utils/ServerUtil.java
@@ -101,8 +101,12 @@ public class ServerUtil {
public boolean isServerOnline(Server server) {
// fetch latest details and check if server is still online
- fetchServerDetails(server);
- return server.isOnline();
+ try {
+ fetchServerDetails(server);
+ return server.isOnline();
+ } catch (Exception e) {
+ return false;
+ }
}
public String fetchHostName(String serverName) {