From a9b02c497b94290a6eb07165d0d3f2bf0bd388c6 Mon Sep 17 00:00:00 2001 From: lily Date: Fri, 9 Sep 2016 11:22:36 +0800 Subject: [PATCH] add getVolumeBricks --- .../controller/SetGlusterfsController.java | 25 +++++-------- .../controller/ShowGlusterfsController.java | 35 +++++++++++++++++-- src/com/platform/glusterfs/GetTreeData.java | 3 ++ src/com/platform/glusterfs/VolumeInfo.java | 29 +++++++++++++-- src/com/platform/utils/GanymedSSH.java | 6 ++-- 5 files changed, 76 insertions(+), 22 deletions(-) diff --git a/src/com/platform/controller/SetGlusterfsController.java b/src/com/platform/controller/SetGlusterfsController.java index 481331dd..9dd495e4 100644 --- a/src/com/platform/controller/SetGlusterfsController.java +++ b/src/com/platform/controller/SetGlusterfsController.java @@ -13,11 +13,12 @@ package com.platform.controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** - * <一句话功能简述> + * 配置集群 * <功能详细描述> * @author liliy * @version [版本号,2016年9月8日] @@ -26,20 +27,12 @@ import org.springframework.web.bind.annotation.RequestMapping; */ @Controller public class SetGlusterfsController { - @RequestMapping("/tes") - public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) { - //���?ƥ������� - try { - - System.out.println("fsdfds"); - - return "listAll"; - } catch (Exception e) { - e.printStackTrace(); - - return "result"; - } - - + public static Logger log = Logger.getLogger(SetGlusterfsController.class); + + @RequestMapping("") + public void sf(){ + } + + } diff --git a/src/com/platform/controller/ShowGlusterfsController.java b/src/com/platform/controller/ShowGlusterfsController.java index 83f6e468..fdd21fb4 100644 --- a/src/com/platform/controller/ShowGlusterfsController.java +++ b/src/com/platform/controller/ShowGlusterfsController.java @@ -10,16 +10,19 @@ */ package com.platform.controller; +import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.platform.glusterfs.ClusterInfo; +import com.platform.glusterfs.VolumeInfo; /** - * <一句话功能简述> + * 显示集群信息 * <功能详细描述> * @author liliy * @version [版本号,2016年9月8日] @@ -28,8 +31,9 @@ import com.platform.glusterfs.ClusterInfo; */ @Controller public class ShowGlusterfsController { + public static Logger log = Logger.getLogger(ShowGlusterfsController.class); /** - * <一句话功能简述> + * 显示集群节点以及状态 * <功能详细描述> * @return * @see [类、类#方法、类#成员] @@ -40,5 +44,32 @@ public class ShowGlusterfsController { return peer_status; } + /** + * <一句话功能简述> + * <功能详细描述> + * @return + * @see [类、类#方法、类#成员] + */ + @RequestMapping("/showVolumeStatus") + public Map showVolumeStatus(){ + VolumeInfo volumeInfo=new VolumeInfo(); + Map volume_status=new HashMap(); + List volumes=volumeInfo.showAllVolumeName(); + if(volumes==null){ + log.error("showAllVolumeName is error!"); + return null; + } + for(String vol:volumes){ + String status=volumeInfo.getVolumeStatus(vol); + if(status==null){ + log.error("getVolumeStatus is error!"); + return null; + } + volume_status.put(vol, status); + } + return volume_status; + } + + } diff --git a/src/com/platform/glusterfs/GetTreeData.java b/src/com/platform/glusterfs/GetTreeData.java index 89da4253..4098ab50 100644 --- a/src/com/platform/glusterfs/GetTreeData.java +++ b/src/com/platform/glusterfs/GetTreeData.java @@ -24,6 +24,9 @@ public class GetTreeData { fileOrFolder.children = new ArrayList(); for (Map.Entry entry : files.entrySet()) { int number = Integer.parseInt(entry.getValue()); + if(entry.getKey().equals("app")){ + continue; + } if (number == 1) { fileOrFolder.children.add(new FileOrFolder(entry.getKey(), number)); } diff --git a/src/com/platform/glusterfs/VolumeInfo.java b/src/com/platform/glusterfs/VolumeInfo.java index af6a37d6..72b1b712 100644 --- a/src/com/platform/glusterfs/VolumeInfo.java +++ b/src/com/platform/glusterfs/VolumeInfo.java @@ -218,10 +218,35 @@ public class VolumeInfo { return usedSize; } - public String getVolumeMountPoint(String volumeName) { + + public List getVolumeMountPoint(String volumeName) { log.info("get volume mountPoint"); // String mountPoint = ""; + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + + * "|awk '{print $6}'"; RunCommand runCommand = new RunCommand(); + * List reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + String cmd="gluster volume info "+volumeName+" |grep ^Brick'[0-9]\\+' |awk '{print $2}'"; + List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(volumeName); + // System.out.println(reStrings); + if(reStrings==null){ + log.error("1601 get result string wrong"); + return null; + } + + return reStrings; + } + + public String getVolumeBricks(String volumeName) { + log.info("get volume bricks"); + // String mountPoint = ""; + /* * ======= * @@ -254,7 +279,7 @@ public class VolumeInfo { mountPoint=mountPoint.replaceAll(" ", ""); return mountPoint; } - + public static void main(String[] args) { PropertyConfigurator.configure("log4j.properties"); diff --git a/src/com/platform/utils/GanymedSSH.java b/src/com/platform/utils/GanymedSSH.java index 54a7a84e..47a3e605 100644 --- a/src/com/platform/utils/GanymedSSH.java +++ b/src/com/platform/utils/GanymedSSH.java @@ -120,7 +120,7 @@ public class GanymedSSH { break; } } - + if(reStrings.size()==0){ while (true) { String line = stderrReader.readLine(); @@ -131,6 +131,7 @@ public class GanymedSSH { break; } } + } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -165,7 +166,7 @@ public class GanymedSSH { break; } } - + if(reStrings.size()==0){ while (true) { String line = stderrReader.readLine(); @@ -176,6 +177,7 @@ public class GanymedSSH { break; } } + } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace();