diff options
| author | Dhandapani <dhandapani@gluster.com> | 2011-04-07 10:58:53 +0530 |
|---|---|---|
| committer | Dhandapani <dhandapani@gluster.com> | 2011-04-07 10:58:53 +0530 |
| commit | 9cc77baa3c96fa74afbb3807dd01525e28638934 (patch) | |
| tree | 41fa1ccf522fa8a1b103ee0bdefc0014b621d2ab /src | |
| parent | 5c39a47fdd3987bb5eee35f7f7397ce127c8919e (diff) | |
Volume re-export directory creation task in remote servers
Diffstat (limited to 'src')
5 files changed, 117 insertions, 29 deletions
diff --git a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java index ad5b4c2b..d8de2e20 100644 --- a/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java +++ b/src/com.gluster.storage.management.core/src/com/gluster/storage/management/core/utils/GlusterUtil.java @@ -20,7 +20,6 @@ */ package com.gluster.storage.management.core.utils; -import java.io.File; import java.util.ArrayList; import java.util.List; @@ -36,6 +35,7 @@ import com.gluster.storage.management.core.model.Volume.VOLUME_TYPE; * */ public class GlusterUtil { + private static final String HOSTNAME_PFX = "Hostname:"; private static final String UUID_PFX = "Uuid:"; private static final String STATE_PFX = "State:"; @@ -145,7 +145,7 @@ public class GlusterUtil { return processUtil.executeCommand("gluster", "--mode=script", "volume", "stop", volumeName); } - public ProcessResult createVolume(Volume volume) { + public ProcessResult createVolume(Volume volume, List<String> bricks) { int count=1; // replica or stripe count String volumeType = null; VOLUME_TYPE volType = volume.getVolumeType(); @@ -172,9 +172,7 @@ public class GlusterUtil { } command.add("transport"); command.add(transportTypeStr); - for(Disk disk : volume.getDisks()) { - command.add(getBrickNotation(volume, disk)); - } + command.addAll(bricks); return processUtil.executeCommand(command); } @@ -193,24 +191,6 @@ public class GlusterUtil { return setOption(command); } - /** - * @param disk - * @return - */ - private String getBrickNotation(Volume vol, Disk disk) { - // TODO: Figure out an appropriate directory INSIDE the DISK having given NAME (e.g. sda, sdb, etc) - // String dirName = "/export/" + vol.getName() + "/" + disk.getName(); - - // if /export directory is not exist then create the directory - boolean exists = (new File("/export")).exists(); - - if (!exists) { - processUtil.executeCommand("mkdir", "/export"); - } - String dirName = "/export/" + vol.getName() ; - return disk.getServerName() + ":" + dirName; - } - public static void main(String args[]) { List<String> names = new GlusterUtil().getGlusterServerNames(); System.out.println(names); diff --git a/src/com.gluster.storage.management.server.scripts/src/nodes/CreateVolumeExportDirectory.py b/src/com.gluster.storage.management.server.scripts/src/nodes/CreateVolumeExportDirectory.py new file mode 100644 index 00000000..611d9695 --- /dev/null +++ b/src/com.gluster.storage.management.server.scripts/src/nodes/CreateVolumeExportDirectory.py @@ -0,0 +1,51 @@ +#!/usr/bin/python +# Copyright (C) 2010 Gluster, Inc. <http://www.gluster.com> +# This file is part of Gluster Storage Platform. +# +# Gluster Storage Platform is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 3 of +# the License, or (at your option) any later version. +# +# Gluster Storage Platform 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# <http://www.gnu.org/licenses/>. +import os +from XmlHandler import ResponseXml +from optparse import OptionParser +import Utils + +def stripEmptyLines(content): + ret = "" + for line in content.split("\n"): + if line.strip() != "": + ret += line + return ret + +def createDirectory(disk, volumename): + dirname = "/export" + if not os.path.isdir(dirname) or not os.path.isdir(disk): + rs = ResponseXml() + rs.appendTagRoute("code", 1) + rs.appendTagRoute("message", "Disk is not mounted properly") + return rs.toprettyxml() + + + if not os.path.isdir(dirname + "/" + disk + "/" + volumename + "/"): + command = "mkdir " + volumename; + rv = Utils.runCommandFG(command, stdout=True, root=True) + message = stripEmptyLines(rv["Stdout"]) + if rv["Stderr"]: + message += "Error: [" + stripEmptyLines(rv["Stderr"]) + "]" + rs = ResponseXml() + rs.appendTagRoute("status.code", rv["Status"]) + rs.appendTagRoute("status.message", message) + return rs.toprettyxml() + +def main(disk, volumename): + return createDirectory(disk, volumename)
\ No newline at end of file diff --git a/src/com.gluster.storage.management.server.scripts/src/nodes/PeerAgent.py b/src/com.gluster.storage.management.server.scripts/src/nodes/PeerAgent.py index 93c1f002..909d24a3 100755 --- a/src/com.gluster.storage.management.server.scripts/src/nodes/PeerAgent.py +++ b/src/com.gluster.storage.management.server.scripts/src/nodes/PeerAgent.py @@ -77,7 +77,7 @@ def executeCommand(command): rs = ResponseXml() rs.appendTagRoute("status", statusCode); rs.appendTagRoute("output", stripEmptyLines(rv["Stdout"])) - rs.appendTagRoute("error", stripEmptyLines(rv["Stderr"])) + rs.appendTagRoute("message", stripEmptyLines(rv["Stderr"])) print rs.toprettyxml() return rs.toprettyxml() else: diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java index dfa5a5cc..9ac1f9d6 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/resources/VolumesResource.java @@ -27,7 +27,8 @@ import static com.gluster.storage.management.core.constants.RESTConstants.PATH_P import static com.gluster.storage.management.core.constants.RESTConstants.RESOURCE_PATH_VOLUMES; import static com.gluster.storage.management.core.constants.RESTConstants.SUBRESOURCE_DEFAULT_OPTIONS; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; @@ -39,24 +40,46 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import org.springframework.beans.factory.annotation.Autowired; + +import com.gluster.storage.management.core.model.Disk; import com.gluster.storage.management.core.model.GenericResponse; import com.gluster.storage.management.core.model.Status; import com.gluster.storage.management.core.model.Volume; import com.gluster.storage.management.core.utils.GlusterUtil; import com.gluster.storage.management.core.utils.ProcessResult; import com.gluster.storage.management.server.constants.VolumeOptionsDefaults; +import com.gluster.storage.management.server.utils.ServerUtil; import com.sun.jersey.spi.resource.Singleton; @Singleton @Path(RESOURCE_PATH_VOLUMES) public class VolumesResource { + + private static final String SCRIPT_NAME = "CreateVolumeExportDirectory.py"; + + @Autowired + private static ServerUtil serverUtil; + private final GlusterUtil glusterUtil = new GlusterUtil(); @POST @Consumes(MediaType.TEXT_XML) @Produces(MediaType.TEXT_XML) public GenericResponse<String> createVolume(Volume volume) { - ProcessResult response = glusterUtil.createVolume(volume); + //Create the directories for the volume + List<String> bricks = new ArrayList<String>(); + for(Disk disk : volume.getDisks()) { + + String brickNotation = getBrickNotation(volume, disk); + if (brickNotation != null) { + bricks.add(brickNotation); + } else { + return new GenericResponse<String>(Status.STATUS_FAILURE, "Disk is not mounted properly. Pls mount the disk."); + } + } + + ProcessResult response = glusterUtil.createVolume(volume, bricks); if (!response.isSuccess()) { return new GenericResponse<String>(Status.STATUS_FAILURE, "Volume creation failed: [" + response.getOutput() + "]"); @@ -90,4 +113,22 @@ public class VolumesResource { // whenever such a CLI command is made available in GlusterFS return new VolumeOptionsDefaults().getDefaults(); } + + private String getBrickNotation(Volume vol, Disk disk) { + Status result = serverUtil.executeOnServer(true, disk.getServerName(), "python CreateVolumeExportDirectory.py " + disk + " " + vol.getName()); + + if(result.getCode() == 0) { + String dirName = "/export/" + disk + "/" + vol.getName() ; + return disk.getServerName() + ":" + dirName; + } else { + return null; + // return result.getMessage(); + } + + } + + public static void main(String args[]) { + // Disk disk = null; + serverUtil.executeOnServer(true, "localhost", "CreateVolumeExportDirectory.py md0 testvol"); + } }
\ No newline at end of file diff --git a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java index b07873f1..b2264ffa 100644 --- a/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java +++ b/src/com.gluster.storage.management.server/src/com/gluster/storage/management/server/utils/ServerUtil.java @@ -21,6 +21,8 @@ package com.gluster.storage.management.server.utils; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.FileReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.InetAddress; @@ -29,11 +31,15 @@ import java.util.ArrayList; import java.util.List; import javax.servlet.ServletContext; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; 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.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; @@ -69,7 +75,7 @@ public class ServerUtil { * @param commandWithArgs * @return Response from remote execution of the command */ - public String executeOnServer(boolean runInForeground, String serverName, String commandWithArgs) { + public Status executeOnServer(boolean runInForeground, String serverName, String commandWithArgs) { try { InetAddress address = InetAddress.getByName(serverName); Socket connection = new Socket(address, 50000); @@ -87,7 +93,16 @@ public class ServerUtil { } connection.close(); - return output.toString(); + System.out.println("The ouput string is : " + output.toString()); + // create JAXB context and instantiate marshaller + JAXBContext context = JAXBContext.newInstance(Status.class); + + Unmarshaller um = context.createUnmarshaller(); + Status result = (Status) um.unmarshal(new ByteArrayInputStream(output.toString().getBytes())); + + return result; + + // return new ProcessResult( 0, output.toString()); } catch (Exception e) { e.printStackTrace(); } @@ -95,6 +110,7 @@ public class ServerUtil { } public static void main(String args[]) { - System.out.println(new ServerUtil().executeOnServer(true, "localhost", "ls -lrt")); + // CreateVolumeExportDirectory.py md0 testvol + System.out.println(new ServerUtil().executeOnServer(true, "localhost", "python CreateVolumeExportDirectory.py md0 testvol").getMessage()); } }
\ No newline at end of file |
