web_gfs
chenlw 9 years ago
parent 8e67ef81b5
commit ea3a1966e5

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container">
<attributes> <attributes>
<attribute name="owner.project.facets" value="java"/> <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="D:/git_gfs/aggregation-platform/WebContent/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/> <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath> </classpath>

@ -1,36 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<projectDescription> <projectDescription>
<name>jfinal-demo</name> <name>jfinal-demo</name>
<comment></comment> <comment></comment>
<projects> <projects>
</projects> </projects>
<buildSpec> <buildSpec>
<buildCommand> <buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name> <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name> <name>org.eclipse.jdt.core.javabuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name> <name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name> <name>org.eclipse.wst.validation.validationbuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature> <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="jfinal-demo">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="context-root" value="jfinal-demo"/>
<property name="java-output-path" value="/jfinal-demo/WebContent/WEB-INF/classes"/>
</wb-module>
</project-modules>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>

@ -1,3 +1,3 @@
Manifest-Version: 1.0 Manifest-Version: 1.0
Class-Path: Class-Path:

@ -1,31 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0"> id="WebApp_ID" version="3.0">
<display-name>jfinal-demo</display-name> <display-name>JFinal-demo</display-name>
<welcome-file-list> <welcome-file-list>
<welcome-file>index.html</welcome-file> <welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file> <welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file> <welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file> <welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file> <welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file> <welcome-file>default.jsp</welcome-file>
</welcome-file-list> </welcome-file-list>
<!-- 添加至 web.xml 1.4 添加 java文件 在项目 src 目录下创建 com.platform.config 包,并在 包下创建 JfinalConfig <!-- 添加至 web.xml 1.4 添加 java文件 在项目 src 目录下创建 com.platform.config 包,并在 包下创建 JfinalConfig
文件, --> 文件, -->
<filter> <filter>
<filter-name>jfinalF</filter-name> <filter-name>jfinalF</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class> <filter-class>com.jfinal.core.JFinalFilter</filter-class>
<init-param> <init-param>
<param-name>configClass</param-name> <param-name>configClass</param-name>
<param-value>com.platform.config.JfinalConfig</param-value> <param-value>com.platform.config.JfinalConfig</param-value>
</init-param> </init-param>
</filter> </filter>
<filter-mapping> <filter-mapping>
<filter-name>jfinalF</filter-name> <filter-name>jfinalF</filter-name>
<url-pattern>/*</url-pattern> <url-pattern>/*</url-pattern>
</filter-mapping> </filter-mapping>
</web-app> </web-app>

@ -9,12 +9,16 @@ import com.jfinal.config.Routes;
import com.jfinal.core.JFinal; import com.jfinal.core.JFinal;
import com.platform.controller.GfsController; import com.platform.controller.GfsController;
import com.platform.controller.HelloController; import com.platform.controller.HelloController;
import com.platform.utils.Constant;
import com.platform.utils.GanymedSSH;
import com.platform.utils.ThreadVolume;
public class JfinalConfig extends JFinalConfig { public class JfinalConfig extends JFinalConfig {
@Override @Override
public void configConstant(Constants me) { public void configConstant(Constants me) {
me.setDevMode(true); me.setDevMode(true);
Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port);
} }
@Override @Override
@ -37,5 +41,7 @@ public class JfinalConfig extends JFinalConfig {
public static void main(String[] args) { public static void main(String[] args) {
JFinal.start("WebRoot", 80, "/", 5); JFinal.start("WebRoot", 80, "/", 5);
// new ThreadVolume().start();
} }
} }

@ -1,53 +1,63 @@
package com.platform.controller; package com.platform.controller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.Date;
import java.util.List;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
import com.jfinal.core.Controller; import net.sf.json.JSONObject;
import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity; import com.alibaba.druid.util.DaemonThreadFactory;
import com.platform.utils.CacheTreeData; import com.jfinal.core.Controller;
import com.platform.utils.getTreeDataByPath; import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity;
public class GfsController extends Controller { import com.platform.utils.CacheTreeData;
import com.platform.utils.ThreadVolume;
/** gfs目录树形查询 */ import com.platform.utils.getTreeDataByPath;
private getTreeDataByPath getFolder = new getTreeDataByPath();
public class GfsController extends Controller {
/**
* -"/gfs" /** gfs目录树形查询 */
*/ private getTreeDataByPath getFolder = new getTreeDataByPath();
public void index() {
renderText("hello gfs !"); /**
} * -"/gfs"
*/
public void getAllvolume(){ public void index() {
renderText("hello gfs !");
List<VolumeEntity> volumeList = CacheTreeData.getVolumeList(); }
if (null == volumeList) {
JSONObject jsondata = JSONObject.fromObject(new ArrayList<VolumeEntity>()); public void getAllvolume(){
renderJson(jsondata.toString()); Date a = new Date();
} //查询volume信息
for (VolumeEntity volume : volumeList) { new ThreadVolume().getVolumeMsg();
if (null != volume.getPath()) { //获得volume信息
// 获得 folder 目录 List<VolumeEntity> volumeList = CacheTreeData.getVolumeList();
List<FolderNode> list = new ArrayList<FolderNode>(); if (null == volumeList) {
FolderNode currNode = getFolder(volume.getPath()); JSONObject jsondata = JSONObject.fromObject(new ArrayList<VolumeEntity>());
if (null != currNode && null != currNode.getChildNodes()) { renderJson(jsondata.toString());
list.addAll(currNode.getChildNodes()); }
} for (VolumeEntity volume : volumeList) {
volume.setFolder(list); if (null != volume.getPath()) {
} // 获得 folder 目录
} List<FolderNode> list = new ArrayList<FolderNode>();
JSONObject jsondata = JSONObject.fromObject(volumeList); FolderNode currNode = getFolder(volume.getPath());
renderJson(jsondata.toString()); if (null != currNode && null != currNode.getChildNodes()) {
} list.addAll(currNode.getChildNodes());
}
public FolderNode getFolder(String path) { volume.setFolder(list);
FolderNode result = getFolder.findByPath(path); }
return result; }
} List<FolderNode> folList = CacheTreeData.getFolders();
JSONArray jsondata = JSONArray.fromObject(volumeList);
} JSONArray jsonfold = JSONArray.fromObject(folList);
Date b = new Date();
renderJson(jsondata.toString()+" :"+jsonfold.toString()+ " :"+ (b.getTime()-a.getTime()));
}
public FolderNode getFolder(String path) {
FolderNode result = getFolder.findByPath(path);
return result;
}
}

@ -1,48 +1,48 @@
package com.platform.controller; package com.platform.controller;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import com.jfinal.core.Controller; import com.jfinal.core.Controller;
import com.platform.entities.FolderNode; import com.platform.entities.FolderNode;
import com.platform.form.baseForm; import com.platform.form.baseForm;
public class HelloController extends Controller { public class HelloController extends Controller {
public void index() { public void index() {
renderText("hello jfinal index !"); renderText("hello jfinal index !");
} }
public void tojson() { public void tojson() {
renderText("hello jfinal tojson !"); renderText("hello jfinal tojson !");
} }
public void gain() { public void gain() {
baseForm form = new baseForm(); baseForm form = new baseForm();
form.setId("12"); form.setId("12");
form.setName("n3"); form.setName("n3");
String base = getPara("jsondata"); String base = getPara("jsondata");
System.err.println(base); System.err.println(base);
if (null != base) { if (null != base) {
FolderNode f = new FolderNode(); FolderNode f = new FolderNode();
f.setIsFolder(2); f.setIsFolder(2);
f.setName("1"); f.setName("1");
f.setPath("/da"); f.setPath("/da");
FolderNode f1 = new FolderNode(); FolderNode f1 = new FolderNode();
f1.setIsFolder(2); f1.setIsFolder(2);
f1.setName("1"); f1.setName("1");
f1.setPath("/da"); f1.setPath("/da");
List<FolderNode> lis = new ArrayList<FolderNode>(); List<FolderNode> lis = new ArrayList<FolderNode>();
lis.add(f1); lis.add(f1);
f.setChildNodes(lis); f.setChildNodes(lis);
JSONObject jsondata = JSONObject.fromObject(f); JSONObject jsondata = JSONObject.fromObject(f);
renderJson(jsondata.toString()); renderJson(jsondata.toString());
} }
else { else {
renderText("hello jfinal gaindata ! "); renderText("hello jfinal gaindata ! ");
} }
} }
} }

@ -1,110 +1,110 @@
/** /**
* : Brick.java * : Brick.java
* : </> * : </>
* : <> * : <>
* @author chen * @author chen
* : <> * : <>
* 201699 * 201699
* <> * <>
*/ */
package com.platform.entities; package com.platform.entities;
/** /**
* <> volume * <> volume
* <> * <>
* @author chen * @author chen
* @version [201699] * @version [201699]
* @see [/] * @see [/]
* @since [/] * @since [/]
*/ */
public class Brick { public class Brick {
/** volume总大小 */ /** volume总大小 */
private double availableSize; private double availableSize;
/** volume已使用大小 */ /** volume已使用大小 */
private double usedSize; private double usedSize;
/** ip */ /** ip */
private String ip; private String ip;
/** 路径 */ /** 路径 */
private String path; private String path;
/** /**
* true false * true false
*/ */
private boolean status; private boolean status;
/** /**
* @return the availableSize * @return the availableSize
*/ */
public double getAvailableSize() { public double getAvailableSize() {
return availableSize; return availableSize;
} }
/** /**
* @param availableSize the availableSize to set * @param availableSize the availableSize to set
*/ */
public void setAvailableSize(double availableSize) { public void setAvailableSize(double availableSize) {
this.availableSize = availableSize; this.availableSize = availableSize;
} }
/** /**
* @return the usedSize * @return the usedSize
*/ */
public double getUsedSize() { public double getUsedSize() {
return usedSize; return usedSize;
} }
/** /**
* @param usedSize the usedSize to set * @param usedSize the usedSize to set
*/ */
public void setUsedSize(double usedSize) { public void setUsedSize(double usedSize) {
this.usedSize = usedSize; this.usedSize = usedSize;
} }
/** /**
* @return the ip * @return the ip
*/ */
public String getIp() { public String getIp() {
return ip; return ip;
} }
/** /**
* @param ip the ip to set * @param ip the ip to set
*/ */
public void setIp(String ip) { public void setIp(String ip) {
this.ip = ip; this.ip = ip;
} }
/** /**
* @return the path * @return the path
*/ */
public String getPath() { public String getPath() {
return path; return path;
} }
/** /**
* @param path the path to set * @param path the path to set
*/ */
public void setPath(String path) { public void setPath(String path) {
this.path = path; this.path = path;
} }
/** /**
* @return the status * @return the status
*/ */
public boolean isStatus() { public boolean isStatus() {
return status; return status;
} }
/** /**
* @param status the status to set * @param status the status to set
*/ */
public void setStatus(boolean status) { public void setStatus(boolean status) {
this.status = status; this.status = status;
} }
} }

@ -1,65 +1,65 @@
package com.platform.entities; package com.platform.entities;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FolderNode { public class FolderNode {
private String name; private String name;
private int isFolder; // 1 is file and other integer is folder show children number private int isFolder; // 1 is file and other integer is folder show children number
private String path; private String path;
private List<FolderNode> childNodes = new ArrayList<FolderNode>(); private List<FolderNode> childNodes = new ArrayList<FolderNode>();
public FolderNode() { public FolderNode() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public FolderNode(String name) { public FolderNode(String name) {
this.name = name; this.name = name;
} }
public FolderNode(String name, int isFolder) { public FolderNode(String name, int isFolder) {
this.name = name; this.name = name;
this.isFolder = isFolder; this.isFolder = isFolder;
} }
public String getName() { public String getName() {
return name; return name;
} }
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** /**
* @return the isFolder * @return the isFolder
*/ */
public int getIsFolder() { public int getIsFolder() {
return isFolder; return isFolder;
} }
/** /**
* @param isFolder the isFolder to set * @param isFolder the isFolder to set
*/ */
public void setIsFolder(int isFolder) { public void setIsFolder(int isFolder) {
this.isFolder = isFolder; this.isFolder = isFolder;
} }
public String getPath() { public String getPath() {
return path; return path;
} }
public void setPath(String path) { public void setPath(String path) {
this.path = path; this.path = path;
} }
public List<FolderNode> getChildNodes() { public List<FolderNode> getChildNodes() {
return childNodes; return childNodes;
} }
public void setChildNodes(List<FolderNode> childNodes) { public void setChildNodes(List<FolderNode> childNodes) {
this.childNodes = childNodes; this.childNodes = childNodes;
} }
} }

@ -1,164 +1,164 @@
/** /**
* : VolumeEntity.java * : VolumeEntity.java
* : </> * : </>
* : <> * : <>
* @author chen * @author chen
* : <> * : <>
* 201699 * 201699
* <> * <>
*/ */
package com.platform.entities; package com.platform.entities;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* <> gfs volume * <> gfs volume
* <> * <>
* @author chen * @author chen
* @version [201699] * @version [201699]
* @see [/] * @see [/]
* @since [/] * @since [/]
*/ */
public class VolumeEntity { public class VolumeEntity {
/** volume总大小 */ /** volume总大小 */
private double allSize; private double allSize;
/** volume已使用大小 */ /** volume已使用大小 */
private double usedSize; private double usedSize;
/** volume名称 */ /** volume名称 */
private String name; private String name;
/** 挂载点 */ /** 挂载点 */
private String path; private String path;
/** * exist正常返回状态Started,Stopped,Created */ /** * exist正常返回状态Started,Stopped,Created */
private boolean status; private boolean status;
private String type; private String type;
/** volume树形目录 */ /** volume树形目录 */
private List<FolderNode> folder = new ArrayList<FolderNode>(); private List<FolderNode> folder = new ArrayList<FolderNode>();
/** volume的 块 */ /** volume的 块 */
private List<Brick> brick = new ArrayList<Brick>(); private List<Brick> brick = new ArrayList<Brick>();
/** /**
* @return the allSize * @return the allSize
*/ */
public double getAllSize() { public double getAllSize() {
return allSize; return allSize;
} }
/** /**
* @param allSize the allSize to set * @param allSize the allSize to set
*/ */
public void setAllSize(double allSize) { public void setAllSize(double allSize) {
this.allSize = allSize; this.allSize = allSize;
} }
/** /**
* @return the usedSize * @return the usedSize
*/ */
public double getUsedSize() { public double getUsedSize() {
return usedSize; return usedSize;
} }
/** /**
* @param usedSize the usedSize to set * @param usedSize the usedSize to set
*/ */
public void setUsedSize(double usedSize) { public void setUsedSize(double usedSize) {
this.usedSize = usedSize; this.usedSize = usedSize;
} }
/** /**
* @return the name * @return the name
*/ */
public String getName() { public String getName() {
return name; return name;
} }
/** /**
* @param name the name to set * @param name the name to set
*/ */
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** /**
* @return the path * @return the path
*/ */
public String getPath() { public String getPath() {
return path; return path;
} }
/** /**
* @param path the path to set * @param path the path to set
*/ */
public void setPath(String path) { public void setPath(String path) {
this.path = path; this.path = path;
} }
/** /**
* @return the status * @return the status
*/ */
public boolean isStatus() { public boolean isStatus() {
return status; return status;
} }
/** /**
* @param status the status to set * @param status the status to set
*/ */
public void setStatus(boolean status) { public void setStatus(boolean status) {
this.status = status; this.status = status;
} }
/** /**
* @return the type * @return the type
*/ */
public String getType() { public String getType() {
return type; return type;
} }
/** /**
* @param type the type to set * @param type the type to set
*/ */
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
/** /**
* @return the folder * @return the folder
*/ */
public List<FolderNode> getFolder() { public List<FolderNode> getFolder() {
return folder; return folder;
} }
/** /**
* @param folder the folder to set * @param folder the folder to set
*/ */
public void setFolder(List<FolderNode> folder) { public void setFolder(List<FolderNode> folder) {
this.folder = folder; this.folder = folder;
} }
/** /**
* @return the brick * @return the brick
*/ */
public List<Brick> getBrick() { public List<Brick> getBrick() {
return brick; return brick;
} }
/** /**
* @param brick the brick to set * @param brick the brick to set
*/ */
public void setBrick(List<Brick> brick) { public void setBrick(List<Brick> brick) {
this.brick = brick; this.brick = brick;
} }
} }

@ -1,87 +1,87 @@
package com.platform.form; package com.platform.form;
import java.beans.BeanInfo; import java.beans.BeanInfo;
import java.beans.IntrospectionException; import java.beans.IntrospectionException;
import java.beans.Introspector; import java.beans.Introspector;
import java.beans.PropertyDescriptor; import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class Bean2MapUtils { public class Bean2MapUtils {
/** /**
* Map JavaBean * Map JavaBean
* @param type * @param type
* @param map map * @param map map
* @return JavaBean * @return JavaBean
* @throws IntrospectionException * @throws IntrospectionException
* *
* @throws IllegalAccessException * @throws IllegalAccessException
* JavaBean * JavaBean
* @throws InstantiationException * @throws InstantiationException
* JavaBean * JavaBean
* @throws InvocationTargetException * @throws InvocationTargetException
* setter * setter
*/ */
public static Object convertMap(Class type, Map map) public static Object convertMap(Class type, Map map)
throws IntrospectionException, IllegalAccessException, throws IntrospectionException, IllegalAccessException,
InstantiationException, InvocationTargetException { InstantiationException, InvocationTargetException {
BeanInfo beanInfo = Introspector.getBeanInfo(type); // 获取类属性 BeanInfo beanInfo = Introspector.getBeanInfo(type); // 获取类属性
Object obj = type.newInstance(); // 创建 JavaBean 对象 Object obj = type.newInstance(); // 创建 JavaBean 对象
// 给 JavaBean 对象的属性赋值 // 给 JavaBean 对象的属性赋值
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i< propertyDescriptors.length; i++) { for (int i = 0; i< propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i]; PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName(); String propertyName = descriptor.getName();
try{ try{
if (map.containsKey(propertyName)) { if (map.containsKey(propertyName)) {
// 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。 // 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。
Object value = map.get(propertyName); Object value = map.get(propertyName);
Object[] args = new Object[1]; Object[] args = new Object[1];
args[0] = value; args[0] = value;
descriptor.getWriteMethod().invoke(obj, args); descriptor.getWriteMethod().invoke(obj, args);
} }
} }
catch(Exception e){ catch(Exception e){
} }
} }
return obj; return obj;
} }
/** /**
* JavaBean Map * JavaBean Map
* @param bean JavaBean * @param bean JavaBean
* @return Map * @return Map
* @throws IntrospectionException * @throws IntrospectionException
* @throws IllegalAccessException JavaBean * @throws IllegalAccessException JavaBean
* @throws InvocationTargetException setter * @throws InvocationTargetException setter
*/ */
public static Map convertBean(Object bean) public static Map convertBean(Object bean)
throws IntrospectionException, IllegalAccessException, InvocationTargetException { throws IntrospectionException, IllegalAccessException, InvocationTargetException {
Class type = bean.getClass(); Class type = bean.getClass();
Map returnMap = new HashMap(); Map returnMap = new HashMap();
BeanInfo beanInfo = Introspector.getBeanInfo(type); BeanInfo beanInfo = Introspector.getBeanInfo(type);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i< propertyDescriptors.length; i++) { for (int i = 0; i< propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i]; PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName(); String propertyName = descriptor.getName();
if (!propertyName.equals("class")) { if (!propertyName.equals("class")) {
Method readMethod = descriptor.getReadMethod(); Method readMethod = descriptor.getReadMethod();
Object result = readMethod.invoke(bean, new Object[0]); Object result = readMethod.invoke(bean, new Object[0]);
if (result != null) { if (result != null) {
returnMap.put(propertyName, result); returnMap.put(propertyName, result);
} else { } else {
returnMap.put(propertyName, ""); returnMap.put(propertyName, "");
} }
} }
} }
return returnMap; return returnMap;
} }
} }

@ -1,55 +1,55 @@
package com.platform.form; package com.platform.form;
public class baseForm { public class baseForm {
private String id; private String id;
private String name; private String name;
private baseForm base; private baseForm base;
/** /**
* @return the id * @return the id
*/ */
public String getId() { public String getId() {
return id; return id;
} }
/** /**
* @param id the id to set * @param id the id to set
*/ */
public void setId(String id) { public void setId(String id) {
this.id = id; this.id = id;
} }
/** /**
* @return the name * @return the name
*/ */
public String getName() { public String getName() {
return name; return name;
} }
/** /**
* @param name the name to set * @param name the name to set
*/ */
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** /**
* @return the base * @return the base
*/ */
public baseForm getBase() { public baseForm getBase() {
return base; return base;
} }
/** /**
* @param base the base to set * @param base the base to set
*/ */
public void setBase(baseForm base) { public void setBase(baseForm base) {
this.base = base; this.base = base;
} }
} }

@ -1,103 +1,103 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.platform.utils.Constant; import com.platform.utils.Constant;
public class CheckoutMD5 { public class CheckoutMD5 {
public static Logger log = Logger.getLogger(CheckoutMD5.class); public static Logger log = Logger.getLogger(CheckoutMD5.class);
String sourcePath; String sourcePath;
String destPath; String destPath;
String dataName; String dataName;
// String cmd_crateSourceMD5File="find "+sourcePath+dataName+"/app/ -type f // String cmd_crateSourceMD5File="find "+sourcePath+dataName+"/app/ -type f
// -print0 | xargs -0 md5sum | sort >"+deskPath+dataName+"_md5.txt"; // -print0 | xargs -0 md5sum | sort >"+deskPath+dataName+"_md5.txt";
String cmd_getSourceMD5File; String cmd_getSourceMD5File;
// String cmd_crateDestMD5File="find "+destPath+dataName+"/app/ -type f // String cmd_crateDestMD5File="find "+destPath+dataName+"/app/ -type f
// -print0 | xargs -0 md5sum | sort >"+deskPath+dataName+"_md5.txt"; // -print0 | xargs -0 md5sum | sort >"+deskPath+dataName+"_md5.txt";
String cmd_getDestMD5File; String cmd_getDestMD5File;
Map<String, String> source_md5 = new HashMap<String, String>(); Map<String, String> source_md5 = new HashMap<String, String>();
Map<String, String> dest_md5 = new HashMap<String, String>(); Map<String, String> dest_md5 = new HashMap<String, String>();
public CheckoutMD5() { public CheckoutMD5() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public CheckoutMD5(String sourcePath, String destPath, String dataName) { public CheckoutMD5(String sourcePath, String destPath, String dataName) {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
this.sourcePath = sourcePath; this.sourcePath = sourcePath;
this.destPath = destPath; this.destPath = destPath;
this.dataName = dataName; this.dataName = dataName;
cmd_getSourceMD5File = "find " + sourcePath + dataName + "/app/ -type f -print0 | xargs -0 md5sum | sort "; cmd_getSourceMD5File = "find " + sourcePath + dataName + "/app/ -type f -print0 | xargs -0 md5sum | sort ";
cmd_getDestMD5File = "find " + destPath + dataName + "/app/ -type f -print0 | xargs -0 md5sum | sort "; cmd_getDestMD5File = "find " + destPath + dataName + "/app/ -type f -print0 | xargs -0 md5sum | sort ";
} }
/** /**
* sourcePathdestPath1 * sourcePathdestPath1
* 0MD5-1-2-3 * 0MD5-1-2-3
* *
* @param sourcePath * @param sourcePath
* @param destPath * @param destPath
* @return * @return
* @see [##] * @see [##]
*/ */
public int checkoutMD5Folder(String sourcePath, String destPath) { public int checkoutMD5Folder(String sourcePath, String destPath) {
log.info("start checkout md5 "+sourcePath+" and "+ destPath); log.info("start checkout md5 "+sourcePath+" and "+ destPath);
List<String> wrong_files = new ArrayList<String>(); List<String> wrong_files = new ArrayList<String>();
String source_cmd = "find " + sourcePath + " -type f -print0 | xargs -0 md5sum"; String source_cmd = "find " + sourcePath + " -type f -print0 | xargs -0 md5sum";
String dest_cmd = "find " + destPath + " -type f -print0 | xargs -0 md5sum"; String dest_cmd = "find " + destPath + " -type f -print0 | xargs -0 md5sum";
List<String> sourceReStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(source_cmd); List<String> sourceReStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(source_cmd);
if (sourceReStrings == null || sourceReStrings.size() == 0) { if (sourceReStrings == null || sourceReStrings.size() == 0) {
log.error("get " + sourcePath + " MD5 error!"); log.error("get " + sourcePath + " MD5 error!");
return -1; return -1;
} }
if(sourceReStrings.get(0).contains(Constant.noSuchFile)){ if(sourceReStrings.get(0).contains(Constant.noSuchFile)){
log.error(sourcePath+" is not exist!"); log.error(sourcePath+" is not exist!");
return -2; return -2;
} }
List<String> destReStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(dest_cmd); List<String> destReStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(dest_cmd);
if (destReStrings == null || destReStrings.size() == 0) { if (destReStrings == null || destReStrings.size() == 0) {
log.error("get " + destReStrings + " MD5 error!"); log.error("get " + destReStrings + " MD5 error!");
return -1; return -1;
} }
if(destReStrings.get(0).contains(Constant.noSuchFile)){ if(destReStrings.get(0).contains(Constant.noSuchFile)){
log.error(destPath+" is not exist!"); log.error(destPath+" is not exist!");
return -3; return -3;
} }
Map<String, String> source_md5 = new HashMap<String, String>(); Map<String, String> source_md5 = new HashMap<String, String>();
Map<String, String> dest_md5 = new HashMap<String, String>(); Map<String, String> dest_md5 = new HashMap<String, String>();
for (String line : sourceReStrings) { for (String line : sourceReStrings) {
String[] lines = line.split(" "); String[] lines = line.split(" ");
String key = lines[1].replace(sourcePath, "").trim(); String key = lines[1].replace(sourcePath, "").trim();
String value = lines[0].trim(); String value = lines[0].trim();
source_md5.put(key, value); source_md5.put(key, value);
} }
for (String line : destReStrings) { for (String line : destReStrings) {
String[] lines = line.split(" "); String[] lines = line.split(" ");
String key = lines[1].replace(destPath, "").trim(); String key = lines[1].replace(destPath, "").trim();
String value = lines[0].trim(); String value = lines[0].trim();
dest_md5.put(key, value); dest_md5.put(key, value);
} }
for (Map.Entry<String, String> mapEntry : source_md5.entrySet()) { for (Map.Entry<String, String> mapEntry : source_md5.entrySet()) {
if (!(dest_md5.containsKey(mapEntry.getKey()) if (!(dest_md5.containsKey(mapEntry.getKey())
&& dest_md5.get(mapEntry.getKey()).equals(mapEntry.getValue()))) { && dest_md5.get(mapEntry.getKey()).equals(mapEntry.getValue()))) {
log.info(sourcePath + " and " + destPath + " is not same!"); log.info(sourcePath + " and " + destPath + " is not same!");
return 0; return 0;
// System.out.println(mapEntry.getKey()); // System.out.println(mapEntry.getKey());
} }
} }
log.info(sourcePath + " and " + destPath + " is same!"); log.info(sourcePath + " and " + destPath + " is same!");
return 1; return 1;
} }
public static void main(String[] args) { public static void main(String[] args) {
CheckoutMD5 checkoutMD5 = new CheckoutMD5(); CheckoutMD5 checkoutMD5 = new CheckoutMD5();
System.out.println(checkoutMD5.checkoutMD5Folder("/home/v1_copy","/home/ubuntu")); System.out.println(checkoutMD5.checkoutMD5Folder("/home/v1_copy","/home/ubuntu"));
} }
} }

@ -1,153 +1,155 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import com.platform.utils.Constant; import com.platform.utils.Constant;
import com.platform.utils.ProcessMyUtil;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Connection;
/**
* /**
* @author liliy *
* @version [2016912] * @author liliy
* @see [/] * @version [2016912]
* @since [/] * @see [/]
*/ * @since [/]
public class ClusterInfo { */
public static Logger log = Logger.getLogger(ClusterInfo.class); public class ClusterInfo {
ProcessMyUtil proMy = new ProcessMyUtil();
/** public static Logger log = Logger.getLogger(ClusterInfo.class);
*
* nullmapipip /**
* ipPeerinCluster(Connected) *
* ipPeerinCluster(Disconnected) * nullmapipip
* @return * ipPeerinCluster(Connected)
* @throws IOException * ipPeerinCluster(Disconnected)
* @see [##] * @return
*/ * @throws IOException
public Map<String, String> showClusterInfo() { * @see [##]
// log.info("get cluster info"); */
Map<String, String> peerIps = new HashMap<String, String>(); public Map<String, String> showClusterInfo() {
peerIps.put(Constant.hostIp, Constant.peerincluster_connected); // log.info("get cluster info");
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(Constant.glusterPeerStatus); Map<String, String> peerIps = new HashMap<String, String>();
if (reStrings == null) { peerIps.put(Constant.hostIp, Constant.peerincluster_connected);
log.error("1101 command get result is null"); List<String> reStrings = proMy.execCmdWaitAcquiescent(Constant.glusterPeerStatus);
return null; if (reStrings == null) {
} log.error("1101 command get result is null");
if (reStrings.size() == 0) { return null;
log.error("1102 command get result is nothing"); }
return null; if (reStrings.size() == 0) {
} log.error("1102 command get result is nothing");
return null;
if (reStrings.get(0).contains("No peers present")) { }
return peerIps;
} if (reStrings.get(0).contains("No peers present")) {
return peerIps;
if (!(reStrings.get(0).split(":")[0].contains("Number of Peers"))) { }
log.error("1103 get result string wrong");
return null; if (!(reStrings.get(0).split(":")[0].contains("Number of Peers"))) {
} log.error("1103 get result string wrong");
return null;
}
// System.out.print(reStrings.get(0));
int flag = 0; // System.out.print(reStrings.get(0));
String ipString = "";
String state = ""; int flag = 0;
for (Iterator it2 = reStrings.iterator(); it2.hasNext();) { String ipString = "";
String line = (String) it2.next(); String state = "";
line=line.replaceAll(" +", " "); for (Iterator it2 = reStrings.iterator(); it2.hasNext();) {
String keyValue[] = line.split(":"); String line = (String) it2.next();
if (keyValue[0].equals("Hostname")) { line=line.replaceAll(" +", " ");
String keyValue[] = line.split(":");
if (keyValue.length < 2) { if (keyValue[0].equals("Hostname")) {
log.error("1105 command get result is wrong");
continue; if (keyValue.length < 2) {
} log.error("1105 command get result is wrong");
continue;
ipString = keyValue[1].replaceAll(" ", ""); }
flag = 1;
} else if (flag == 1 && keyValue[0].equals("State")) { ipString = keyValue[1].replaceAll(" ", "");
flag = 1;
if (keyValue.length < 2) { } else if (flag == 1 && keyValue[0].equals("State")) {
log.error("1106 command get result is wrong");
continue; if (keyValue.length < 2) {
} log.error("1106 command get result is wrong");
continue;
state = keyValue[1].replaceAll(" ", ""); }
flag = 0;
peerIps.put(ipString, state); state = keyValue[1].replaceAll(" ", "");
} flag = 0;
peerIps.put(ipString, state);
} }
// for (Map.Entry<String, String> entry:peerIps.entrySet()){ }
// String key=entry.getKey();
// if(key.equals(Constant.hostIp)){ // for (Map.Entry<String, String> entry:peerIps.entrySet()){
// continue; // String key=entry.getKey();
// } // if(key.equals(Constant.hostIp)){
// String value=entry.getValue(); // continue;
// if(Constant.ganymedSSH.otherConns==null){ // }
// Constant.ganymedSSH.otherConns=new HashMap<String,Connection>(); // String value=entry.getValue();
// } // if(Constant.ganymedSSH.otherConns==null){
// if(!Constant.ganymedSSH.otherConns.containsKey(key)){ // Constant.ganymedSSH.otherConns=new HashMap<String,Connection>();
// Connection connection=null; // }
// try { // if(!Constant.ganymedSSH.otherConns.containsKey(key)){
// connection = Constant.ganymedSSH.getOpenedConnection(key, Constant.rootUser, Constant.rootPasswd, Constant.port); // Connection connection=null;
// } catch (IOException e) { // try {
// // TODO Auto-generated catch block // connection = Constant.ganymedSSH.getOpenedConnection(key, Constant.rootUser, Constant.rootPasswd, Constant.port);
// e.printStackTrace(); // } catch (IOException e) {
// } // // TODO Auto-generated catch block
// Constant.ganymedSSH.otherConns.put(key,connection); // e.printStackTrace();
// } // }
// } // Constant.ganymedSSH.otherConns.put(key,connection);
// }
return peerIps; // }
}
return peerIps;
/** }
* ipip
* ipnull /**
* ipPeerinCluster(Connected) * ipip
* ipPeerinCluster(Disconnected) * ipnull
* @param peerip * ipPeerinCluster(Connected)
* @return * ipPeerinCluster(Disconnected)
* @see [##] * @param peerip
*/ * @return
public String getPeerStatus(String peerip){ * @see [##]
Map<String, String> peerIps=showClusterInfo(); */
if(peerIps==null || peerIps.size()==0){ public String getPeerStatus(String peerip){
return null; Map<String, String> peerIps=showClusterInfo();
} if(peerIps==null || peerIps.size()==0){
return null;
if(peerip.equals(Constant.hostIp)){ }
return Constant.peerincluster_connected;
} if(peerip.equals(Constant.hostIp)){
if(!peerIps.containsKey(peerip)){ return Constant.peerincluster_connected;
return Constant.peerNotinCluster; }
} if(!peerIps.containsKey(peerip)){
return peerIps.get(peerip); return Constant.peerNotinCluster;
} }
return peerIps.get(peerip);
}
public static void main(String[] args) {
// PropertyConfigurator.configure("log4j.properties");
System.out.println(new ClusterInfo().showClusterInfo()); public static void main(String[] args) {
System.out.println(new ClusterInfo().getPeerStatus("192.168.0.116")); // PropertyConfigurator.configure("log4j.properties");
} System.out.println(new ClusterInfo().showClusterInfo());
} System.out.println(new ClusterInfo().getPeerStatus("192.168.0.116"));
}
}

@ -1,143 +1,143 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import org.junit.Test; import org.junit.Test;
import com.platform.utils.Constant; import com.platform.utils.Constant;
/** /**
* <> * <>
* <> * <>
* @author chen * @author chen
* @version [201698] * @version [201698]
* @see [/] * @see [/]
* @since [/] * @since [/]
*/ */
public class CopyData { public class CopyData {
public static Logger log = Logger.getLogger(CopyData.class); public static Logger log = Logger.getLogger(CopyData.class);
public int copyVolumeFiles(String sourceVolumeName, String destVolumeName, String fileName) { public int copyVolumeFiles(String sourceVolumeName, String destVolumeName, String fileName) {
log.info("start copy " + fileName + " from " + sourceVolumeName + " to " + destVolumeName); log.info("start copy " + fileName + " from " + sourceVolumeName + " to " + destVolumeName);
int status = -1; int status = -1;
/** /**
* get mount point of volumeName * get mount point of volumeName
*/ */
String sourceFolderName = sourceVolumeName; String sourceFolderName = sourceVolumeName;
String destFolderName = destVolumeName; String destFolderName = destVolumeName;
status = copyFolderFilesAnyway(sourceFolderName, destFolderName, fileName); status = copyFolderFilesAnyway(sourceFolderName, destFolderName, fileName);
return status; return status;
} }
/** /**
* sourceFolderNamedestFolderName * sourceFolderNamedestFolderName
* 1sourceFolderName-2 destFolderName-3 * 1sourceFolderName-2 destFolderName-3
* @param sourceFolderName * @param sourceFolderName
* @param destFolderName * @param destFolderName
* @return * @return
* @see [##] * @see [##]
*/ */
public int copyFolder(String sourceFolderName, String destFolderName) { public int copyFolder(String sourceFolderName, String destFolderName) {
createFolders(destFolderName); createFolders(destFolderName);
int progress=0; int progress=0;
log.info("start copy " + sourceFolderName + " to " + destFolderName); log.info("start copy " + sourceFolderName + " to " + destFolderName);
ShowData showData=new ShowData(); ShowData showData=new ShowData();
Map<String,String> reStrings=showData.showFolderData(destFolderName); Map<String,String> reStrings=showData.showFolderData(destFolderName);
if(reStrings==null){ if(reStrings==null){
log.info("3201 "+destFolderName+" is not exists"); log.info("3201 "+destFolderName+" is not exists");
return -3; return -3;
} }
reStrings=showData.showFolderData(sourceFolderName); reStrings=showData.showFolderData(sourceFolderName);
if(reStrings==null){ if(reStrings==null){
log.info("3202 "+sourceFolderName+" is not exists"); log.info("3202 "+sourceFolderName+" is not exists");
return -2; return -2;
} }
String command = "cp -rp " + sourceFolderName+" "+destFolderName; String command = "cp -rp " + sourceFolderName+" "+destFolderName;
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
log.info("copy " + sourceFolderName + " to " + destFolderName + " running"); log.info("copy " + sourceFolderName + " to " + destFolderName + " running");
return 1; return 1;
} }
/** /**
* -1 :error; -2: the filename is not exists ;-3 :destFolderName ; 1: right * -1 :error; -2: the filename is not exists ;-3 :destFolderName ; 1: right
* not exists * not exists
* *
* @param folderName * @param folderName
* @param fileName * @param fileName
* @return * @return
*/ */
public int copyFolderFiles(String sourceFolderName, String destFolderName, String fileName) { public int copyFolderFiles(String sourceFolderName, String destFolderName, String fileName) {
int progress=0; int progress=0;
log.info("start copy " + fileName + " from " + sourceFolderName + " to " + destFolderName); log.info("start copy " + fileName + " from " + sourceFolderName + " to " + destFolderName);
ShowData showData=new ShowData(); ShowData showData=new ShowData();
Map<String,String> reStrings=showData.showFolderData(destFolderName); Map<String,String> reStrings=showData.showFolderData(destFolderName);
if(reStrings==null){ if(reStrings==null){
log.info("3201 "+destFolderName+" is not exists"); log.info("3201 "+destFolderName+" is not exists");
return -3; return -3;
} }
reStrings=showData.showFolderData(sourceFolderName+"/"+fileName); reStrings=showData.showFolderData(sourceFolderName+"/"+fileName);
if(reStrings==null){ if(reStrings==null){
log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists"); log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists");
return -2; return -2;
} }
String command = "cp -rp " + sourceFolderName + "/" + fileName+" "+destFolderName; String command = "cp -rp " + sourceFolderName + "/" + fileName+" "+destFolderName;
/* /*
* RunCommand runCommand = new RunCommand(); * RunCommand runCommand = new RunCommand();
List<String> reStrings = runCommand.runCommandWait(command); List<String> reStrings = runCommand.runCommandWait(command);
*/ */
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
log.info("copy " + sourceFolderName +"/" + fileName+ " to " + destFolderName + " running"); log.info("copy " + sourceFolderName +"/" + fileName+ " to " + destFolderName + " running");
return 1; return 1;
} }
/** /**
* @param sourceFolderName * @param sourceFolderName
* @param destFolderName * @param destFolderName
* @param fileName * @param fileName
* @return * @return
*/ */
public int copyFolderFilesAnyway(String sourceFolderName, String destFolderName, String fileName) { public int copyFolderFilesAnyway(String sourceFolderName, String destFolderName, String fileName) {
createFolders(destFolderName); createFolders(destFolderName);
int result = copyFolderFiles(sourceFolderName, destFolderName, fileName); int result = copyFolderFiles(sourceFolderName, destFolderName, fileName);
return result; return result;
} }
public int createFolders(String folder){ public int createFolders(String folder){
log.info("create "+folder); log.info("create "+folder);
String splitFolder[]=folder.substring(1).split("/"); String splitFolder[]=folder.substring(1).split("/");
String cmd="mkdir "; String cmd="mkdir ";
for(String one:splitFolder){ for(String one:splitFolder){
cmd+="/"+one.replaceAll(" ", ""); cmd+="/"+one.replaceAll(" ", "");
Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
} }
return 1; return 1;
} }
@Test @Test
public void testcreateFolders() { public void testcreateFolders() {
createFolders("/aaa/vvv/ddd/www/rrrr"); createFolders("/aaa/vvv/ddd/www/rrrr");
} }
//@Test //@Test
public void testCopyFolderFiles() { public void testCopyFolderFiles() {
copyFolderFiles("/home", "/home/ubuntu", "system_data"); copyFolderFiles("/home", "/home/ubuntu", "system_data");
} }
} }

@ -1,123 +1,115 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.ArrayList; import java.io.BufferedReader;
import java.util.List; import java.io.File;
import java.util.Map; import java.io.IOException;
import java.io.InputStreamReader;
import org.junit.Test; import java.util.ArrayList;
import com.platform.entities.FolderNode; import java.util.List;
import com.platform.utils.Constant; import java.util.Map;
import com.platform.utils.FileOperateHelper;
import com.platform.utils.GanymedSSH; import net.sf.json.JSONObject;
/** import org.junit.Test;
* <> GFS
* <> import com.platform.entities.FolderNode;
* @author chen import com.platform.utils.Constant;
* @version [201698] import com.platform.utils.FileOperateHelper;
* @see [/] import com.platform.utils.GanymedSSH;
* @since [/]
*/ import freemarker.core._RegexBuiltins.replace_reBI;
public class GetTreeData {
ShowData showData = new ShowData(); /**
* <> GFS
/** * <>
* <> * @author chen
* <> * @version [201698]
* @param name * @see [/]
* @return * @since [/]
* @see [##] */
*/ public class GetTreeData {
public FolderNode getDatas(String name) { ShowData showData = new ShowData();
String names[]=name.split("/");
String only_name=names[names.length-1]; /**
FolderNode fileNode = new FolderNode(only_name); * <>
fileNode.setPath(name); * <>
Map<String, String> files = showData.showFolderData(name); * @param name
if(files==null || files.size()==0){ * @return
return fileNode; * @see [##]
} */
fileNode.setIsFolder(files.size()); public FolderNode getDatas(String name) {
List<FolderNode> list = new ArrayList<FolderNode>(); String names[]=name.split("/");
fileNode.setChildNodes(list); String only_name=names[names.length-1];
for (Map.Entry<String, String> entry : files.entrySet()) { FolderNode fileNode = new FolderNode(only_name);
if(entry.getKey().equals("app")){ fileNode.setPath(name);
continue; Map<String, String> files = showData.showFolderData(name);
} if(files==null || files.size()==0){
int number = Integer.parseInt(entry.getValue()); return fileNode;
if (number == 1) { }
fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number)); fileNode.setIsFolder(files.size());
} List<FolderNode> list = new ArrayList<FolderNode>();
if (number > 1) { fileNode.setChildNodes(list);
FolderNode temp=getDatas(name+"/"+entry.getKey()); for (Map.Entry<String, String> entry : files.entrySet()) {
fileNode.getChildNodes().add(temp); if(entry.getKey().equals("app")){
} continue;
} }
int number = Integer.parseInt(entry.getValue());
return fileNode; if (number == 1) {
} fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number));
}
if (number > 1) {
/** FolderNode temp=getDatas(name+"/"+entry.getKey());
* <> fileNode.getChildNodes().add(temp);
* <> }
* @param name }
* @return
* @see [##] return fileNode;
*/ }
public FolderNode getDatasWithShell(String name) {
if(name.endsWith("/")){
name=name.substring(0, name.length()-1); /**
} * <>
// String names[]=name.split("/"); * <>
// String only_name=names[names.length-1]; * @param name
FolderNode fileNode = new FolderNode(name); * @return
fileNode.setPath(name); * @see [##]
*/
// String shellComment= new FileOperateHelper().fileReaderAndendline(Constant.fileGetTreeData); public FolderNode getDatasWithShell(String name) {
String shellComment= Constant.strGetTreeData; if(name.endsWith("/")){
String sh_path="/getTreedata.sh"; name=name.substring(0, name.length()-1);
String cmd="echo -e \""+shellComment+"\" > "+sh_path+" & chmod +x "+sh_path; }
Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); // String names[]=name.split("/");
// Map<String, String> files = showData.showFolderData(name); // String only_name=names[names.length-1];
List<String> files=Constant.ganymedSSH.execCmdWaitAcquiescent(sh_path+" "+name); FolderNode fileNode = new FolderNode(name);
if(files==null){ fileNode.setPath(name);
return null;
} // String shellComment= new FileOperateHelper().fileReaderAndendline(Constant.fileGetTreeData);
if(files.size()==0){ String shellComment= Constant.strGetTreeData;
return fileNode; String sh_path="/getTreedata.sh";
} String cmd="echo -e \""+shellComment+"\" > "+sh_path+" & chmod +x "+sh_path;
for(String file:files){ Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
// Map<String, String> files = showData.showFolderData(name);
} List<String> files=Constant.ganymedSSH.execCmdWaitAcquiescent(sh_path+" "+name);
if(files==null){
return fileNode; return null;
} }
@Test if(files.size()==0){
public void test_getTreeData() { return fileNode;
}
GetTreeData getTreeData=new GetTreeData(); for(String file:files){
// FolderNode fileOrFolder=getTreeData.getDatas("/home/gfs_ftp_point");
FolderNode fileOrFolder=getTreeData.getDatasWithShell("/home/gfs_ftp_point/"); }
System.out.println(fileOrFolder);
} return fileNode;
} }
/* @Test
class FileOrFolder { public void test_getTreeData() {
String name;
int isFolder; // 1 is file and other integer is folder show children number GetTreeData getTreeData=new GetTreeData();
List<FileOrFolder> children; // FolderNode fileOrFolder=getTreeData.getDatas("/home/gfs_ftp_point");
FolderNode fileOrFolder=getTreeData.getDatasWithShell("/home/gfs_ftp_point/");
public FileOrFolder(String name) { System.out.println(fileOrFolder);
// TODO Auto-generated constructor stub }
this.name = name;
} }
public FileOrFolder(String name, int isFolder) {
// TODO Auto-generated constructor stub
this.name = name;
this.isFolder = isFolder;
}
}
*/

@ -1,56 +1,56 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import org.junit.Test; import org.junit.Test;
import com.platform.utils.Constant; import com.platform.utils.Constant;
public class RemoveData { public class RemoveData {
public static Logger log = Logger.getLogger ( RemoveData.class); public static Logger log = Logger.getLogger ( RemoveData.class);
/** /**
* -1 :error; 0: the filename is not exists ; 1: right * -1 :error; 0: the filename is not exists ; 1: right
* @param folderName * @param folderName
* @param fileName * @param fileName
* @return * @return
*/ */
public int deleteFolder(String folderName){ public int deleteFolder(String folderName){
log.info("start delete "+folderName); log.info("start delete "+folderName);
ShowData showData=new ShowData(); ShowData showData=new ShowData();
Map<String,String> reStrings=showData.showFolderData(folderName); Map<String,String> reStrings=showData.showFolderData(folderName);
if(reStrings==null){ if(reStrings==null){
log.error("3301 "+folderName+" is not exists"); log.error("3301 "+folderName+" is not exists");
return -1; return -1;
} }
String command="rm -r "+folderName; String command="rm -r "+folderName;
// int status=runCommand.runCommand(command); // int status=runCommand.runCommand(command);
Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
log.info("delete "+folderName+" running"); log.info("delete "+folderName+" running");
return 1; return 1;
} }
@Test @Test
public void testDeleteFolderFiles() { public void testDeleteFolderFiles() {
PropertyConfigurator.configure("log4j.properties"); PropertyConfigurator.configure("log4j.properties");
deleteFolder("/home/ubuntu"); deleteFolder("/home/ubuntu");
} }
} }

@ -1,67 +1,67 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.hamcrest.core.Is; import org.hamcrest.core.Is;
import com.platform.utils.Constant; import com.platform.utils.Constant;
import com.platform.utils.Support; import com.platform.utils.Support;
public class SetCluster { public class SetCluster {
public static Logger log = Logger.getLogger ( SetCluster.class); public static Logger log = Logger.getLogger ( SetCluster.class);
/** /**
* *
* 1-1ip-2 0 * 1-1ip-2 0
* @param peerip * @param peerip
* @return * @return
* @see [##] * @see [##]
*/ */
public int probePeer(String peerip){ public int probePeer(String peerip){
if(!Support.checkIP(peerip)){ if(!Support.checkIP(peerip)){
log.error(peerip +"is illegal!" ); log.error(peerip +"is illegal!" );
return -1; return -1;
} }
String cmd="gluster peer probe "+peerip; String cmd="gluster peer probe "+peerip;
List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
if(reStrings==null || reStrings.size()==0){ if(reStrings==null || reStrings.size()==0){
log.error("detach error! "); log.error("detach error! ");
return -2; return -2;
} }
if(reStrings.contains(Constant.success)){ if(reStrings.contains(Constant.success)){
log.info("probe success!"); log.info("probe success!");
return 1; return 1;
} }
log.info("probe failed!"); log.info("probe failed!");
return 0; return 0;
} }
/** /**
* *
* 1-1ip-2 0 * 1-1ip-2 0
* @param peerip * @param peerip
* @return * @return
* @see [##] * @see [##]
*/ */
public int detachPeer(String peerip){ public int detachPeer(String peerip){
if(!Support.checkIP(peerip)){ if(!Support.checkIP(peerip)){
log.error(peerip +"is illegal!" ); log.error(peerip +"is illegal!" );
return -1; return -1;
} }
String cmd="gluster peer detach "+peerip; String cmd="gluster peer detach "+peerip;
List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); List<String> reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
if(reStrings==null || reStrings.size()==0){ if(reStrings==null || reStrings.size()==0){
log.error("detach error! "); log.error("detach error! ");
return -2; return -2;
} }
if(reStrings.contains(Constant.success)){ if(reStrings.contains(Constant.success)){
log.info("detach success!"); log.info("detach success!");
return 1; return 1;
} }
log.info("detach failed!"); log.info("detach failed!");
return 0; return 0;
} }
} }

File diff suppressed because it is too large Load Diff

@ -1,129 +1,132 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import org.junit.Test; import org.junit.Test;
import com.platform.utils.Constant; import com.platform.utils.Constant;
import com.platform.utils.ProcessMyUtil;
public class ShowData {
public class ShowData {
public static Logger log = Logger.getLogger ( ShowData.class);
ProcessMyUtil proMy = new ProcessMyUtil();
/**
* get the data of volumeName Map<string s1,string s2> s1 is data name and s2 is type file or folder public static Logger log = Logger.getLogger ( ShowData.class);
* <>
* @param volumeName /**
* @return * get the data of volumeName Map<string s1,string s2> s1 is data name and s2 is type file or folder
* @see [##] * <>
*/ * @param volumeName
public Map<String,String> showVolumeFiles(String volumeName){ * @return
// log.info("start show the data"); * @see [##]
Map<String,String> data_type=new HashMap<String, String>(); */
/** public Map<String,String> showVolumeFiles(String volumeName){
* get mount point of volumeName // log.info("start show the data");
*/ Map<String,String> data_type=new HashMap<String, String>();
String folderName=volumeName; /**
* get mount point of volumeName
data_type=showFolderData(volumeName); */
return data_type; String folderName=volumeName;
}
/** data_type=showFolderData(volumeName);
* get the data of folder name return data_type;
* Map<String,String> is folder name and type 1 is file and others is folder }
/**
* get the data of folder name
* @param FolderName * Map<String,String> is folder name and type 1 is file and others is folder
* @return
*/
public Map<String,String> showFolderData(String folderName){ * @param FolderName
// log.info(" start get "+folderName+" data"); * @return
*/
public Map<String,String> showFolderData(String folderName){
Map<String,String> data_type=new HashMap<String, String>(); // log.info(" start get "+folderName+" data");
String command="ls -l "+folderName;
/* Map<String,String> data_type=new HashMap<String, String>();
* RunCommand runCommand=new RunCommand(); List<String> String command="ls -l "+folderName;
* reStrings=runCommand.runCommandWait(command);
*/ /*
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command); * RunCommand runCommand=new RunCommand(); List<String>
if (reStrings == null) { * reStrings=runCommand.runCommandWait(command);
log.error("2101 command get result is null"); */
return null; List<String> reStrings = proMy.execCmdWaitAcquiescent(command);
} if (reStrings == null) {
if(reStrings.size()==0){ log.error("2101 command get result is null");
log.info("2102 the folder is empty"); return null;
return data_type; }
} if(reStrings.size()==0){
if(reStrings.get(0).contains("No such file or directory")){ log.info("2102 the folder is empty");
log.info("2103 the "+folderName+" is not exists"); return data_type;
return null; }
} if(reStrings.get(0).contains("No such file or directory")){
/** log.info("2103 the "+folderName+" is not exists");
* remove first line total number return null;
*/ }
reStrings.remove(0); /**
* remove first line total number
for(Iterator it2 = reStrings.iterator();it2.hasNext();){ */
String line=(String)it2.next(); reStrings.remove(0);
line=line.replaceAll(" +", " ");
String keyValue[]=line.split(" "); for(Iterator it2 = reStrings.iterator();it2.hasNext();){
if(keyValue.length<9){ String line=(String)it2.next();
log.error("2104 "+line+" length is short"); line=line.replaceAll(" +", " ");
continue; String keyValue[]=line.split(" ");
} if(keyValue.length<9){
log.error("2104 "+line+" length is short");
data_type.put(keyValue[8], keyValue[1]); continue;
}
}
// log.info(" get "+folderName+" data successed"); data_type.put(keyValue[8], keyValue[1]);
return data_type;
} }
// log.info(" get "+folderName+" data successed");
/** return data_type;
* folder }
* -2-1folderfolder
* @param folderPath /**
* @return * folder
* @see [##] * -2-1folderfolder
*/ * @param folderPath
public long getFolderSize(String folderPath) { * @return
// log.info("get " + folderPath + " Size "); * @see [##]
*/
String command = "du -k -d 0 "+folderPath+" | grep " + folderPath + "|awk \'{print $1}\'"; public long getFolderSize(String folderPath) {
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command); // log.info("get " + folderPath + " Size ");
if(reStrings==null || reStrings.size()==0){
log.error("get " + folderPath + " Size error!"); String command = "du -k -d 0 "+folderPath+" | grep " + folderPath + "|awk \'{print $1}\'";
return -2; List<String> reStrings = proMy.execCmdWaitAcquiescent(command);
} if(reStrings==null || reStrings.size()==0){
if (reStrings.get(0).contains(Constant.noSuchFile)) { log.error("get " + folderPath + " Size error!");
log.error(folderPath+" is not exists"); return -2;
return -1; }
} if (reStrings.get(0).contains(Constant.noSuchFile)) {
long size = Long.valueOf(reStrings.get(0)); log.error(folderPath+" is not exists");
return size; return -1;
} }
long size = Long.valueOf(reStrings.get(0));
return size;
/** }
*
* <>
* <> /**
* @see [##] *
*/ * <>
@Test * <>
public void testShowData(){ * @see [##]
*/
System.out.println(showFolderData("/home")); @Test
public void testShowData(){
}
System.out.println(showFolderData("/home"));
}
} }

@ -1,93 +1,93 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import com.platform.utils.Constant; import com.platform.utils.Constant;
public class SizeInfo { public class SizeInfo {
public static Logger log = Logger.getLogger(ClusterInfo.class); public static Logger log = Logger.getLogger(ClusterInfo.class);
VolumeInfo volumeInfo = new VolumeInfo(); VolumeInfo volumeInfo = new VolumeInfo();
/** /**
* <EFBFBD>?<EFBFBD><EFBFBD>volume size * <EFBFBD>?<EFBFBD><EFBFBD>volume size
* -1<EFBFBD>? 0volume longsize * -1<EFBFBD>? 0volume longsize
* @return * @return
*/ */
public long showAllSize() { public long showAllSize() {
// log.info("get AllSize "); // log.info("get AllSize ");
List<String> volumeNames = volumeInfo.showAllVolumeName(); List<String> volumeNames = volumeInfo.showAllVolumeName();
if (volumeNames == null) { if (volumeNames == null) {
log.error("1201 showAllVolumeName error"); log.error("1201 showAllVolumeName error");
return -1; return -1;
} }
if (volumeNames.size() == 0) { if (volumeNames.size() == 0) {
log.error("1202 It is not exist any volume"); log.error("1202 It is not exist any volume");
return 0; return 0;
} }
List<String> reStrings = null; List<String> reStrings = null;
long size = 0L; long size = 0L;
for (String str : volumeNames) { for (String str : volumeNames) {
String command = "df |grep " + str + "|awk \'{print $2}\'"; String command = "df |grep " + str + "|awk \'{print $2}\'";
reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port,
command); command);
if (reStrings.isEmpty()) { if (reStrings.isEmpty()) {
log.error("1203 The brick is unmount"); log.error("1203 The brick is unmount");
} else { } else {
size += Long.parseLong(reStrings.get(0)); size += Long.parseLong(reStrings.get(0));
} }
} }
return size; return size;
} }
/** /**
* *
* @return * @return
* -1<EFBFBD>? 0volume longsize * -1<EFBFBD>? 0volume longsize
*/ */
public long showUseSize() { public long showUseSize() {
log.info("get UseSize "); log.info("get UseSize ");
List<String> volumeNames = volumeInfo.showAllVolumeName(); List<String> volumeNames = volumeInfo.showAllVolumeName();
List<String> reStrings = null; List<String> reStrings = null;
long size = 0L; long size = 0L;
if (volumeNames == null) { if (volumeNames == null) {
log.error("1201 showAllVolumeName error"); log.error("1201 showAllVolumeName error");
return -1; return -1;
} }
if (volumeNames.size() == 0) { if (volumeNames.size() == 0) {
log.error("1202 It is not exist any volume"); log.error("1202 It is not exist any volume");
return 0; return 0;
} }
for (String str : volumeNames) { for (String str : volumeNames) {
String command = "df |grep " + str + "|awk \'{print $3}\'"; String command = "df |grep " + str + "|awk \'{print $3}\'";
reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
Constant.port, command); Constant.port, command);
if (reStrings.isEmpty()) { if (reStrings.isEmpty()) {
log.error("1202 The brick is unmount"); log.error("1202 The brick is unmount");
} else { } else {
size += Integer.valueOf(reStrings.get(0)); size += Integer.valueOf(reStrings.get(0));
} }
} }
return size; return size;
} }
public static void main(String[] args) { public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties"); PropertyConfigurator.configure("log4j.properties");
System.out.println(new SizeInfo().showAllSize()); System.out.println(new SizeInfo().showAllSize());
System.out.println(new SizeInfo().showUseSize()); System.out.println(new SizeInfo().showUseSize());
} }
} }

@ -1,417 +1,417 @@
package com.platform.glusterfs; package com.platform.glusterfs;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import org.junit.Test; import org.junit.Test;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper; import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import com.platform.utils.Constant; import com.platform.utils.Constant;
import com.platform.utils.GanymedSSH; import com.platform.utils.GanymedSSH;
import com.platform.utils.ProcessMyUtil;
import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* volume <> /**
* * volume <>
* @author liliy *
* @version [2016913] * @author liliy
* @see [/] * @version [2016913]
* @since [/] * @see [/]
*/ * @since [/]
public class VolumeInfo { */
public static Logger log = Logger.getLogger(VolumeInfo.class); public class VolumeInfo {
ProcessMyUtil proMy = new ProcessMyUtil();
/** public static Logger log = Logger.getLogger(VolumeInfo.class);
* volume <>
* /**
* @return * volume <>
* @see [##] *
*/ * @return
public List<String> showAllVolumeName() { * @see [##]
// log.info(Constant.ganymedSSH+"get volume name"); */
List<String> volNames = new ArrayList<String>(); public List<String> showAllVolumeName() {
// log.info(Constant.ganymedSSH+"get volume name");
/* List<String> volNames = new ArrayList<String>();
* String command = "echo \"" + Constant.rootPasswd +
* "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand /*
* runCommand = new RunCommand(); List<String> reStrings = * String command = "echo \"" + Constant.rootPasswd +
* runCommand.runCommandWait(command); * "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand
*/ * runCommand = new RunCommand(); List<String> reStrings =
* runCommand.runCommandWait(command);
List<String> reStrings = Constant.ganymedSSH */
.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + "|grep ^Volume.Name");
// System.out.println(reStrings); List<String> reStrings = proMy.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + "|grep ^Volume.Name");
if (reStrings == null) { // System.out.println(reStrings);
log.error("1401 get result is null"); if (reStrings == null) {
return null; log.error("1401 get result is null");
} return null;
if (reStrings.size() == 0) { }
log.error("1402 get result is nothing"); if (reStrings.size() == 0) {
return null; log.error("1402 get result is nothing");
} return null;
if (reStrings.get(0).contains(Constant.noVolume)) { }
reStrings.clear(); if (reStrings.get(0).contains(Constant.noVolume)) {
return reStrings; reStrings.clear();
} return reStrings;
if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) { }
log.error("1403 get result string wrong"); if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) {
return null; log.error("1403 get result string wrong");
} return null;
}
String nameInfo = "";
for (Iterator it = reStrings.iterator(); it.hasNext();) { String nameInfo = "";
String line = (String) it.next(); for (Iterator it = reStrings.iterator(); it.hasNext();) {
String str[] = line.split(":"); String line = (String) it.next();
volNames.add(str[1].replaceAll(" ", "")); String str[] = line.split(":");
} volNames.add(str[1].replaceAll(" ", ""));
return volNames; }
return volNames;
}
}
/**
* volumevolume /**
* * volumevolume
* @param volumeName *
* @return * @param volumeName
* @see [##] * @return
*/ * @see [##]
public String getVolumeType(String volumeName) { */
// log.info("get volume type"); public String getVolumeType(String volumeName) {
String volType = ""; // log.info("get volume type");
String volType = "";
List<String> reStrings = Constant.ganymedSSH
.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + volumeName + "|grep ^Type"); List<String> reStrings = proMy.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
// System.out.println(reStrings); // System.out.println(reStrings);
if (reStrings == null) { if (reStrings == null) {
log.error("1501 get result is null"); log.error("1501 get result is null");
return null; return null;
} }
if (reStrings.size() == 0) { if (reStrings.size() == 0) {
log.error("1502 get result is nothing"); log.error("1502 get result is nothing");
return null; return null;
} }
if (!(reStrings.get(0).split(":")[0].contains("Type"))) { if (!(reStrings.get(0).split(":")[0].contains("Type"))) {
log.error("1503 get result string wrong"); log.error("1503 get result string wrong");
return null; return null;
} }
// System.out.println(reStrings); // System.out.println(reStrings);
for (Iterator it = reStrings.iterator(); it.hasNext();) { for (Iterator it = reStrings.iterator(); it.hasNext();) {
String line = (String) it.next(); String line = (String) it.next();
String str[] = line.split(":"); String str[] = line.split(":");
volType = str[1]; volType = str[1];
} }
volType = volType.replaceAll(" ", ""); volType = volType.replaceAll(" ", "");
return volType; return volType;
} }
/** /**
* volumeName nullvolumeNameVolume volumeName does not * volumeName nullvolumeNameVolume volumeName does not
* existStarted,Stopped,Created * existStarted,Stopped,Created
* *
* @param volumeName * @param volumeName
* @return * @return
* @see [##] * @see [##]
*/ */
public String getVolumeStatus(String volumeName) { public String getVolumeStatus(String volumeName) {
// log.info("get volume status"); // log.info("get volume status");
String volStatus = ""; String volStatus = "";
String cmd = Constant.glusterVolumeInfo + " " + volumeName + " |grep ^Status"; String cmd = Constant.glusterVolumeInfo + " " + volumeName + " |grep ^Status";
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); List<String> reStrings = proMy.execCmdWaitAcquiescent(cmd);
// System.out.println(reStrings); // System.out.println(reStrings);
if (reStrings == null) { if (reStrings == null) {
log.error("1701 get result is null"); log.error("1701 get result is null");
return null; return null;
} }
if (reStrings.size() == 0) { if (reStrings.size() == 0) {
log.error("1702 get result is nothing"); log.error("1702 get result is nothing");
return null; return null;
} }
if (reStrings.get(0).contains("does not exist")) { if (reStrings.get(0).contains("does not exist")) {
log.error("1703 " + reStrings.get(0)); log.error("1703 " + reStrings.get(0));
return reStrings.get(0); return reStrings.get(0);
} }
if (!(reStrings.get(0).split(":")[0].contains("Status"))) { if (!(reStrings.get(0).split(":")[0].contains("Status"))) {
log.error("1704 get result string wrong"); log.error("1704 get result string wrong");
return null; return null;
} }
for (Iterator it = reStrings.iterator(); it.hasNext();) { for (Iterator it = reStrings.iterator(); it.hasNext();) {
String line = (String) it.next(); String line = (String) it.next();
String str[] = line.split(":"); String str[] = line.split(":");
volStatus = str[1].replaceAll(" ", ""); volStatus = str[1].replaceAll(" ", "");
} }
return volStatus; return volStatus;
} }
/** /**
* volumeName * volumeName
* volumeName-1-2 volumeName * volumeName-1-2 volumeName
* @param volumeName * @param volumeName
* @return * @return
* @see [##] * @see [##]
*/ */
public Long getVolumeAvailableSize(String volumeName) throws Exception{ public Long getVolumeAvailableSize(String volumeName) throws Exception{
// log.info("get volume availableSize"); // log.info("get volume availableSize");
Long allSize = 0L; Long allSize = 0L;
String cmd = Constant.df + " | grep " + volumeName + "|awk '{print $4}'"; String cmd = Constant.df + " | grep " + volumeName + "|awk '{print $4}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); List<String> reStrings = proMy.execCmdWaitAcquiescent(cmd);
// System.out.println(reStrings); // System.out.println(reStrings);
if (reStrings == null) { if (reStrings == null) {
log.error("1802 get result is error"); log.error("1802 get result is error");
return -2L; return -2L;
} }
if (reStrings.size() == 0) { if (reStrings.size() == 0) {
log.error("1801 " + volumeName + " is not exists!"); log.error("1801 " + volumeName + " is not exists!");
return -1L; return -1L;
} }
Pattern pattern2 = Pattern.compile("^\\d+$"); Pattern pattern2 = Pattern.compile("^\\d+$");
Matcher matcher2 = pattern2.matcher(reStrings.get(0)); Matcher matcher2 = pattern2.matcher(reStrings.get(0));
// 如果是数字 // 如果是数字
if (matcher2.find()) { if (matcher2.find()) {
allSize = Long.parseLong(reStrings.get(0)); allSize = Long.parseLong(reStrings.get(0));
} }
return allSize; return allSize;
} }
/** /**
* volumeName * volumeName
* volumeName-1-2 volumeName * volumeName-1-2 volumeName
* @param volumeName * @param volumeName
* @return * @return
* @see [##] * @see [##]
*/ */
public Long getVolumeUseSize(String volumeName) throws Exception{ public Long getVolumeUseSize(String volumeName) throws Exception{
// log.info("get volume used size"); // log.info("get volume used size");
Long usedSize = 0L; Long usedSize = 0L;
if (volumeIsExists(volumeName) == false) { if (volumeIsExists(volumeName) == false) {
log.error("1901 " + volumeName + " is not exists!"); log.error("1901 " + volumeName + " is not exists!");
return -1L; return -1L;
} }
String cmd = "df | grep " + volumeName + "|awk '{print $3}'"; String cmd = "df | grep " + volumeName + "|awk '{print $3}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); List<String> reStrings = proMy.execCmdWaitAcquiescent(cmd);
// System.out.println(reStrings); // System.out.println(reStrings);
if (reStrings == null) { if (reStrings == null) {
log.error("1901 get result is null"); log.error("1901 get result is null");
return -2L; return -2L;
} }
if (reStrings.size() == 0) { if (reStrings.size() == 0) {
log.error("1902 " + volumeName + " is not exists!"); log.error("1902 " + volumeName + " is not exists!");
return -1L; return -1L;
} }
Pattern pattern2 = Pattern.compile("^\\d+$"); Pattern pattern2 = Pattern.compile("^\\d+$");
Matcher matcher2 = pattern2.matcher(reStrings.get(0)); Matcher matcher2 = pattern2.matcher(reStrings.get(0));
// 如果是数字 // 如果是数字
if (matcher2.find()) { if (matcher2.find()) {
usedSize = Long.parseLong(reStrings.get(0)); usedSize = Long.parseLong(reStrings.get(0));
} }
return usedSize; return usedSize;
} }
/** /**
* volumeNamebricks * volumeNamebricks
* birckslist ip:path,volumeNamenull * birckslist ip:path,volumeNamenull
* @param volumeName * @param volumeName
* @return * @return
* @see [##] * @see [##]
*/ */
public List<String> getVolumeBricks(String volumeName) { public List<String> getVolumeBricks(String volumeName) {
// log.info("get volume bricks"); // log.info("get volume bricks");
String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'"; String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); List<String> reStrings = proMy.execCmdWaitAcquiescent(cmd);
// System.out.println(reStrings); // System.out.println(reStrings);
if (reStrings == null) { if (reStrings == null) {
log.error("1601 get volume bricks wrong"); log.error("1601 get volume bricks wrong");
return null; return null;
} }
if (reStrings.size()==0) { if (reStrings.size()==0) {
log.error("1602 "+volumeName+" is not exists!"); log.error("1602 "+volumeName+" is not exists!");
return null; return null;
} }
return reStrings; return reStrings;
} }
/** /**
* volumeName * volumeName
* <> * <>
* @param volumeName * @param volumeName
* @return * @return
* @see [##] * @see [##]
*/ */
public List<String> getVolumeMountPoint(String volumeName) { public List<String> getVolumeMountPoint(String volumeName) {
// log.info("get volume MountPoint"); // log.info("get volume MountPoint");
List<String> mountPoints = new ArrayList<>(); List<String> mountPoints = new ArrayList<>();
String cmd=Constant.df + "|grep " + volumeName + "|awk '{print $6}'"; String cmd=Constant.df + "|grep " + volumeName + "|awk '{print $6}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); List<String> reStrings = proMy.execCmdWaitAcquiescent(cmd);
// System.out.println(reStrings); // System.out.println(reStrings);
if (reStrings == null) { if (reStrings == null) {
log.error("11001 get result string wrong"); log.error("11001 get result string wrong");
return null; return null;
} }
if (reStrings.size() == 0) { if (reStrings.size() == 0) {
log.error("11002 " + volumeName + " is not exists or no mountpoint"); log.error("11002 " + volumeName + " is not exists or no mountpoint");
return null; return null;
} }
for (String mountPoint : reStrings) { for (String mountPoint : reStrings) {
mountPoint = mountPoint.replaceAll(" ", ""); mountPoint = mountPoint.replaceAll(" ", "");
mountPoints.add(mountPoint); mountPoints.add(mountPoint);
} }
return mountPoints; return mountPoints;
} }
public String getOneVolumeMountPoint(String volumeName) { public String getOneVolumeMountPoint(String volumeName) {
// log.info("get one volume MountPoint"); // log.info("get one volume MountPoint");
String mountPoint=null; String mountPoint=null;
List<String> mountpoints = getVolumeMountPoint(volumeName); List<String> mountpoints = getVolumeMountPoint(volumeName);
// System.out.println(reStrings); // System.out.println(reStrings);
if (mountpoints == null || mountpoints.size() == 0) { if (mountpoints == null || mountpoints.size() == 0) {
log.error("11001 get result string wrong"); log.error("11001 get result string wrong");
return null; return null;
} }
mountPoint=mountpoints.get(0); mountPoint=mountpoints.get(0);
return mountPoint; return mountPoint;
} }
/** /**
* volumeNamebrick * volumeNamebrick
* mapbricks <ip:path,data_size> * mapbricks <ip:path,data_size>
* @param volumeName * @param volumeName
* @return * @return
* @see [##] * @see [##]
*/ */
public Map<String, Double> getVolumebricksDataSize(String volumeName) { public Map<String, Double> getVolumebricksDataSize(String volumeName) {
List<String> bricks = getVolumeBricks(volumeName); List<String> bricks = getVolumeBricks(volumeName);
Map<String, Double> brick_size = new HashMap<>(); Map<String, Double> brick_size = new HashMap<>();
if (bricks == null) { if (bricks == null) {
return null; return null;
} }
for (String brick : bricks) { for (String brick : bricks) {
String ipAndpath[] = brick.split(":"); String ipAndpath[] = brick.split(":");
String ip = ipAndpath[0]; String ip = ipAndpath[0];
String path = ipAndpath[1]; String path = ipAndpath[1];
String cmd = "du -d 0 " + path + "|awk '{print $1}'"; String cmd = "du -d 0 " + path + "|awk '{print $1}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd, List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
Constant.port, cmd); Constant.port, cmd);
// System.out.println(reStrings); // System.out.println(reStrings);
if (reStrings == null) { if (reStrings == null) {
log.error("1901 get result is null"); log.error("1901 get result is null");
return null; return null;
} }
if (reStrings.size() == 0) { if (reStrings.size() == 0) {
log.error("1902 "+brick+" is not exits!"); log.error("1902 "+brick+" is not exits!");
return null; return null;
} }
Pattern pattern = Pattern.compile("[0-9]*"); Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(reStrings.get(0)); Matcher isNum = pattern.matcher(reStrings.get(0));
if (!isNum.matches()) { if (!isNum.matches()) {
log.error("1903 " + reStrings.get(0) + " is unexpect"); log.error("1903 " + reStrings.get(0) + " is unexpect");
return null; return null;
} }
brick_size.put(brick, Double.parseDouble(reStrings.get(0))); brick_size.put(brick, Double.parseDouble(reStrings.get(0)));
} }
return brick_size; return brick_size;
} }
/** /**
* volumeNamebrick * volumeNamebrick
* mapbricks <ip:path,available_size> * mapbricks <ip:path,available_size>
* @param volumeName * @param volumeName
* @return * @return
* @see [##] * @see [##]
*/ */
public Map<String, Double> getVolumebricksAvailableSize(String volumeName) { public Map<String, Double> getVolumebricksAvailableSize(String volumeName) {
List<String> bricks = getVolumeBricks(volumeName); List<String> bricks = getVolumeBricks(volumeName);
Map<String, Double> brick_size = new HashMap<>(); Map<String, Double> brick_size = new HashMap<>();
if (bricks == null) { if (bricks == null) {
return null; return null;
} }
for (String brick : bricks) { for (String brick : bricks) {
String ipAndpath[] = brick.split(":"); String ipAndpath[] = brick.split(":");
String ip = ipAndpath[0]; String ip = ipAndpath[0];
String path = ipAndpath[1]; String path = ipAndpath[1];
String cmd = "df " + path + "|awk '{print $4}'"; String cmd = "df " + path + "|awk '{print $4}'";
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd, List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
Constant.port, cmd); Constant.port, cmd);
// System.out.println(reStrings); // System.out.println(reStrings);
if (reStrings == null) { if (reStrings == null) {
log.error("1901 get result is null"); log.error("1901 get result is null");
return null; return null;
} }
if (reStrings.size() == 0) { if (reStrings.size() == 0) {
log.error("1902 get result is nothing"); log.error("1902 get result is nothing");
return null; return null;
} }
Pattern pattern = Pattern.compile("[0-9]*"); Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(reStrings.get(1)); Matcher isNum = pattern.matcher(reStrings.get(1));
if (!isNum.matches()) { if (!isNum.matches()) {
log.error("1903 " + reStrings.get(1) + " is unexpect"); log.error("1903 " + reStrings.get(1) + " is unexpect");
return null; return null;
} }
brick_size.put(brick, Double.parseDouble(reStrings.get(1))); brick_size.put(brick, Double.parseDouble(reStrings.get(1)));
} }
return brick_size; return brick_size;
} }
/** /**
* volumeNametruefalse * volumeNametruefalse
* *
* @param volumeName * @param volumeName
* @return * @return
* @see [##] * @see [##]
*/ */
public boolean volumeIsExists(String volumeName) { public boolean volumeIsExists(String volumeName) {
List<String> volumes = showAllVolumeName(); List<String> volumes = showAllVolumeName();
if (volumes == null) { if (volumes == null) {
return false; return false;
} }
if (volumes.contains(volumeName)) { if (volumes.contains(volumeName)) {
return true; return true;
} }
return false; return false;
} }
// @Test // @Test
public void test_getVolumebricksDataSize() { public void test_getVolumebricksDataSize() {
System.out.println(getVolumebricksDataSize("gfs_ftp")); System.out.println(getVolumebricksDataSize("gfs_ftp"));
} }
// @Test // @Test
public void test_getVolumebricksAvailableSize() { public void test_getVolumebricksAvailableSize() {
System.out.println(getVolumebricksAvailableSize("gfs_ftp")); System.out.println(getVolumebricksAvailableSize("gfs_ftp"));
} }
// @Test // @Test
public void test_getVolumeBricks() { public void test_getVolumeBricks() {
getVolumeBricks("gfs_ftp"); getVolumeBricks("gfs_ftp");
} }
@Test @Test
public void test_getVolumeStatus() { public void test_getVolumeStatus() {
System.out.println(getVolumeStatus("gs_fp")); System.out.println(getVolumeStatus("gs_fp"));
} }
// @Test // @Test
public void test_getVolumeMountPoint() { public void test_getVolumeMountPoint() {
System.out.println(getVolumeMountPoint("gfs_ftp")); System.out.println(getVolumeMountPoint("gfs_ftp"));
System.out.println(getVolumeMountPoint("v1")); System.out.println(getVolumeMountPoint("v1"));
} }
} }

@ -1,119 +1,34 @@
package com.platform.service; package com.platform.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.platform.entities.Brick; import com.platform.entities.Brick;
import com.platform.entities.FolderNode; import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.CheckoutMD5; import com.platform.glusterfs.CheckoutMD5;
import com.platform.glusterfs.ClusterInfo; import com.platform.glusterfs.ClusterInfo;
import com.platform.glusterfs.GetTreeData; import com.platform.glusterfs.GetTreeData;
import com.platform.glusterfs.VolumeInfo; import com.platform.glusterfs.VolumeInfo;
import com.platform.utils.CacheTreeData; import com.platform.utils.CacheTreeData;
public class VolumeService { public class VolumeService {
public static Logger log = Logger.getLogger(VolumeService.class); public static Logger log = Logger.getLogger(VolumeService.class);
/** Volume信息查询 */ /** Volume信息查询 */
private VolumeInfo volumeInfo = new VolumeInfo(); private VolumeInfo volumeInfo = new VolumeInfo();
private ClusterInfo cluster = new ClusterInfo(); private ClusterInfo cluster = new ClusterInfo();
/** gfs目录树形展示 */ /** gfs目录树形展示 */
private GetTreeData gfsTree = new GetTreeData(); private GetTreeData gfsTree = new GetTreeData();
public void getVolumeMsg() { public void getVolumeMsg() {
List<FolderNode> folderlist = new ArrayList<FolderNode>();
List<VolumeEntity> volumeList = new ArrayList<VolumeEntity>(); }
// brick状态 map集合
Map<String, String> brickStatusMap = cluster.showClusterInfo(); }
// 查询 volume name
List<String> volumeNameList = volumeInfo.showAllVolumeName();
if (null != volumeNameList) {
for (String volumeName : volumeNameList) {
try {
VolumeEntity volume = new VolumeEntity();
volume.setName(volumeName);
List<String> path = volumeInfo
.getVolumeMountPoint(volumeName);
// 默认加载第一个路径
if (null != path) {
for (String one : path) {
if (!one.contains("df")) {
volume.setPath(one);
}
}
}
if (null == volume.getPath()) {
volume.setPath("");
}
volume.setAllSize(volumeInfo
.getVolumeAvailableSize(volumeName)
+ volumeInfo.getVolumeUseSize(volumeName));
// 状态Started,Stopped,Created
String status = volumeInfo.getVolumeStatus(volumeName);
if ("Started".equals(status)) {
volume.setStatus(true);
} else {
volume.setStatus(false);
}
volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
volume.setType(volumeInfo.getVolumeType(volumeName));
// TODO 查询brick--
// 返回 ip:path
List<String> brickStrs = volumeInfo
.getVolumeBricks(volumeName);
// brick已用大小
Map<String, Double> usedSize = volumeInfo
.getVolumebricksDataSize(volumeName);
Map<String, Double> availableSize = volumeInfo
.getVolumebricksAvailableSize(volumeName);
List<Brick> brickList = new ArrayList<Brick>();
for (String brickIpPath : brickStrs) {
Brick b = new Brick();
String ipAndpath[] = brickIpPath.split(":");
String brickip = ipAndpath[0];
String brickpath = ipAndpath[1];
// iP , path ,
b.setIp(brickip);
if (brickStatusMap == null
|| brickStatusMap.size() == 0) {
b.setStatus(false);
} else if (brickStatusMap.containsKey(brickip)) {
b.setStatus(true);
} else {
b.setStatus(false);
}
b.setPath(brickpath);
b.setAvailableSize(availableSize.get(brickIpPath));
b.setUsedSize(usedSize.get(brickIpPath));
brickList.add(b);
}
volume.setBrick(brickList);
// 默认加载第一个路径
if (null != path && path.size() > 0) {
// 装入 folder
// 查询 每个 volume 下的 folder
FolderNode foldertmp = gfsTree.getDatas(path.get(0));
folderlist.add(foldertmp);
}
volumeList.add(volume);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
}
// 更新folder 目录
CacheTreeData.setFolders(folderlist);
CacheTreeData.setVolumeList(volumeList);
}
}

@ -1,39 +1,39 @@
package com.platform.utils; package com.platform.utils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.platform.entities.FolderNode; import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
public class CacheTreeData { public class CacheTreeData {
private static List<FolderNode> folders = null; private static List<FolderNode> folders = null;
private static List<VolumeEntity> volumeList = null; private static List<VolumeEntity> volumeList = null;
public static List<FolderNode> getFolders() { public static List<FolderNode> getFolders() {
return folders; return folders;
} }
public synchronized static void setFolders(List<FolderNode> folders) { public synchronized static void setFolders(List<FolderNode> folders) {
CacheTreeData.folders = folders; CacheTreeData.folders = folders;
} }
/** /**
* @return the volumeList * @return the volumeList
*/ */
public static List<VolumeEntity> getVolumeList() { public static List<VolumeEntity> getVolumeList() {
return volumeList; return volumeList;
} }
/** /**
* @param volumeList the volumeList to set * @param volumeList the volumeList to set
*/ */
public synchronized static void setVolumeList(List<VolumeEntity> volumeList) { public synchronized static void setVolumeList(List<VolumeEntity> volumeList) {
CacheTreeData.volumeList = volumeList; CacheTreeData.volumeList = volumeList;
} }
} }

@ -1,50 +1,50 @@
package com.platform.utils; package com.platform.utils;
import java.util.HashMap; import java.util.HashMap;
public class Constant { public class Constant {
public static String rootUser = "root"; public static String rootUser = "root";
public static String rootPasswd = "root"; public static String rootPasswd = "root";
// public static String hostIp = "192.168.191.23"; // public static String hostIp = "192.168.191.23";
public static String hostIp = ""; public static String hostIp = "192.168.0.110";
public static int port = 22; public static int port = 22;
public static String glusterPeerStatus = "gluster peer status"; public static String glusterPeerStatus = "gluster peer status";
public static String glusterVolumeInfo = "gluster volume info "; public static String glusterVolumeInfo = "gluster volume info ";
public static String df = "df -k "; public static String df = "df -k ";
public static String peerincluster_connected = "PeerinCluster(Connected)"; public static String peerincluster_connected = "PeerinCluster(Connected)";
public static String peerincluster_disconnected = "PeerinCluster(Disconnected)"; public static String peerincluster_disconnected = "PeerinCluster(Disconnected)";
public static String peerNotinCluster = "PeerNotinCluster"; public static String peerNotinCluster = "PeerNotinCluster";
public static String distributed = "distributed"; public static String distributed = "distributed";
public static String replica = "replica"; public static String replica = "replica";
public static String stripe = "stripe"; public static String stripe = "stripe";
public static String noVolume = "No volumes present"; public static String noVolume = "No volumes present";
public static String success = "success"; public static String success = "success";
public static String failed = "failed"; public static String failed = "failed";
public static String noSuchFile = "No such file or directory"; public static String noSuchFile = "No such file or directory";
public static GanymedSSH ganymedSSH = null; public static GanymedSSH ganymedSSH = null;
public static String fileGetTreeData = "WebContent\\WEB-INF\\config\\getTreedata.sh"; public static String fileGetTreeData = "WebContent\\WEB-INF\\config\\getTreedata.sh";
public static String AutoMountfile="/gfsAutoMount/AutoRun.sh"; public static String AutoMountfile="/gfsAutoMount/AutoRun.sh";
public static String MountRecord="/gfsAutoMount/mountPoint.record"; public static String MountRecord="/gfsAutoMount/mountPoint.record";
public static String strGetTreeData = "function ergodic(){\n " public static String strGetTreeData = "function ergodic(){\n "
+ "for file in \\`ls \\$1\\`\n do\n if [ \"\\$file\" != \"app\" -a -d \\$1\\\"/\\\"\\$file ]\n " + "for file in \\`ls \\$1\\`\n do\n if [ \"\\$file\" != \"app\" -a -d \\$1\\\"/\\\"\\$file ]\n "
+ "then\n ergodic \\$1\"/\"\\$file\n else\n local path=\\$1\"/\"\\$file\n " + "then\n ergodic \\$1\"/\"\\$file\n else\n local path=\\$1\"/\"\\$file\n "
+ "echo \\$path \n fi\n done\n}\n\nIFS=\\$\\'\\n\\' " + "echo \\$path \n fi\n done\n}\n\nIFS=\\$\\'\\n\\' "
+ "#这个必须要,否则会在文件名中有空格时出错\nINIT_PATH=\".\";\nergodic \\$1\n"; + "#这个必须要,否则会在文件名中有空格时出错\nINIT_PATH=\".\";\nergodic \\$1\n";
/** /**
* volume 线 * volume 线
*/ */
public final static int moveFileMaxNum = 1; public final static int moveFileMaxNum = 1;
/** /**
* volume 线 * volume 线
*/ */
public final static int get_volume_sleep_time = 10000; public final static int get_volume_sleep_time = 10000;
/** /**
* volume 线 * volume 线
*/ */
public final static int update_dataInfo_sleep_time = 1500; public final static int update_dataInfo_sleep_time = 1500;
} }

@ -1,99 +1,99 @@
package com.platform.utils; package com.platform.utils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import org.junit.Test; import org.junit.Test;
/** /**
* *
* *
* @author wuming * @author wuming
* *
*/ */
public class FileOperateHelper { public class FileOperateHelper {
/** /**
* *
* *
* @param path * @param path
* @param message * @param message
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public static void fileWrite(String path, String message) { public static void fileWrite(String path, String message) {
if (null == path || "".equals(path)) { if (null == path || "".equals(path)) {
return; return;
} }
try { try {
path = path+".log"; path = path+".log";
File file = new File(path); File file = new File(path);
if (file.exists()) if (file.exists())
file.createNewFile(); file.createNewFile();
FileOutputStream out = new FileOutputStream(file, true); // 如果追加方式用true FileOutputStream out = new FileOutputStream(file, true); // 如果追加方式用true
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append(message); sb.append(message);
out.write(sb.toString().getBytes("utf-8")); out.write(sb.toString().getBytes("utf-8"));
} catch (IOException e) { } catch (IOException e) {
// TODO: handle exception // TODO: handle exception
} }
} }
/** /**
* *
* @param path * @param path
* @return * @return
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public static String fileReader(String path) { public static String fileReader(String path) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String tempString = ""; String tempString = "";
try { try {
File file = new File(path); File file = new File(path);
if (!file.exists()) if (!file.exists())
return "当前没有日志信息!"; return "当前没有日志信息!";
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis,"UTF-8")); BufferedReader br = new BufferedReader(new InputStreamReader(fis,"UTF-8"));
while ((tempString = br.readLine()) != null) { while ((tempString = br.readLine()) != null) {
sb.append(tempString).append("\r\n"); sb.append(tempString).append("\r\n");
} }
} catch (Exception e) { } catch (Exception e) {
// Configs.CONSOLE_LOGGER.info(e.getMessage()); // Configs.CONSOLE_LOGGER.info(e.getMessage());
} }
return sb.toString(); return sb.toString();
} }
/** /**
* *
* @param path * @param path
* @return * @return
*/ */
@SuppressWarnings("resource") @SuppressWarnings("resource")
public static String fileReaderAndendline(String path) { public static String fileReaderAndendline(String path) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
String tempString = ""; String tempString = "";
try { try {
File file = new File(path); File file = new File(path);
if (!file.exists()) if (!file.exists())
return ""; return "";
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis)); BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((tempString = br.readLine()) != null) { while ((tempString = br.readLine()) != null) {
sb.append(tempString+"\n"); sb.append(tempString+"\n");
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
return sb.toString(); return sb.toString();
} }
} }

@ -1,291 +1,291 @@
package com.platform.utils; package com.platform.utils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.PropertyConfigurator;
import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session; import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler; import ch.ethz.ssh2.StreamGobbler;
import ch.ethz.ssh2.*; import ch.ethz.ssh2.*;
public class GanymedSSH { public class GanymedSSH {
public static Logger log = Logger.getLogger(GanymedSSH.class); public static Logger log = Logger.getLogger(GanymedSSH.class);
Connection conn; Connection conn;
public Map<String, Connection> otherConns; public Map<String, Connection> otherConns;
public boolean status = true;// 锟角凤拷锟斤拷锟街达拷锟斤拷锟斤拷锟阶刺<E998B6> public boolean status = true;// 锟角凤拷锟斤拷锟街达拷锟斤拷锟斤拷锟阶刺<E998B6>
public GanymedSSH() { public GanymedSSH() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public GanymedSSH(String host, String username, String password, int port) { public GanymedSSH(String host, String username, String password, int port) {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
try { try {
conn = getOpenedConnection(host, username, password, port); conn = getOpenedConnection(host, username, password, port);
otherConns=new HashMap<String,Connection>(); otherConns=new HashMap<String,Connection>();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
public static Connection getOpenedConnection(String host, String username, String password, int port) public static Connection getOpenedConnection(String host, String username, String password, int port)
throws IOException { throws IOException {
Connection conns = new Connection(host, port); Connection conns = new Connection(host, port);
conns.connect(); // make sure the connection is opened conns.connect(); // make sure the connection is opened
boolean isAuthenticated = conns.authenticateWithPassword(username, password); boolean isAuthenticated = conns.authenticateWithPassword(username, password);
if (isAuthenticated == false) if (isAuthenticated == false)
throw new IOException("Authentication failed."); throw new IOException("Authentication failed.");
return conns; return conns;
} }
public void execCmdNoWaitAcquiescent(String cmd) { public void execCmdNoWaitAcquiescent(String cmd) {
// String host=Constant.hostIp; // String host=Constant.hostIp;
// String username=Constant.rootUser; // String username=Constant.rootUser;
// String password=Constant.rootPasswd; // String password=Constant.rootPasswd;
// int port=Constant.port; // int port=Constant.port;
Session sess = null; Session sess = null;
try { try {
sess = conn.openSession(); sess = conn.openSession();
// 执锟斤拷cmd // 执锟斤拷cmd
sess.execCommand(cmd); sess.execCommand(cmd);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
sess.close(); sess.close();
} }
} }
public void execCmdNoWait(String host, String username, String password, int port, String cmd) { public void execCmdNoWait(String host, String username, String password, int port, String cmd) {
Session sess = null; Session sess = null;
Connection new_conn; Connection new_conn;
try { try {
if(Constant.hostIp.equals(host)){ if(Constant.hostIp.equals(host)){
new_conn=conn; new_conn=conn;
} }
else if(otherConns.containsKey(host) && otherConns.get(host)!=null){ else if(otherConns.containsKey(host) && otherConns.get(host)!=null){
new_conn=otherConns.get(host); new_conn=otherConns.get(host);
} }
else{ else{
new_conn = getOpenedConnection(host, username, password, port); new_conn = getOpenedConnection(host, username, password, port);
otherConns.put(host, new_conn); otherConns.put(host, new_conn);
} }
sess = new_conn.openSession(); sess = new_conn.openSession();
// 执锟斤拷cmd // 执锟斤拷cmd
sess.execCommand(cmd); sess.execCommand(cmd);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
sess.close(); sess.close();
} }
} }
public List<String> execCmdWaitAcquiescent(String cmd) { public List<String> execCmdWaitAcquiescent(String cmd) {
// String host=Constant.hostIp; // String host=Constant.hostIp;
// String username=Constant.rootUser; // String username=Constant.rootUser;
// String password=Constant.rootPasswd; // String password=Constant.rootPasswd;
// int port=Constant.port; // int port=Constant.port;
List<String> reStrings = new ArrayList<String>(); List<String> reStrings = new ArrayList<String>();
Session sess = null; Session sess = null;
try { try {
// conn = getOpenedConnection(host, username, password, port); // conn = getOpenedConnection(host, username, password, port);
sess = conn.openSession(); sess = conn.openSession();
// 执锟斤拷cmd // 执锟斤拷cmd
sess.execCommand(cmd); sess.execCommand(cmd);
InputStream stdout = new StreamGobbler(sess.getStdout()); InputStream stdout = new StreamGobbler(sess.getStdout());
InputStream stderr = new StreamGobbler(sess.getStderr()); InputStream stderr = new StreamGobbler(sess.getStderr());
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
while (true) { while (true) {
String line = stdoutReader.readLine(); String line = stdoutReader.readLine();
if (line != null) { if (line != null) {
// System.out.println(line); // System.out.println(line);
reStrings.add(line); reStrings.add(line);
} else { } else {
break; break;
} }
} }
if(reStrings.size()==0){ if(reStrings.size()==0){
while (true) { while (true) {
String line = stderrReader.readLine(); String line = stderrReader.readLine();
if (line != null) { if (line != null) {
// System.out.println(line); // System.out.println(line);
reStrings.add(line); reStrings.add(line);
} else { } else {
break; break;
} }
} }
} }
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
if (null != sess) { if (null != sess) {
sess.close(); sess.close();
} }
} }
return reStrings; return reStrings;
} }
public List<String> execCmdWait(String host, String username, String password, int port, String cmd) { public List<String> execCmdWait(String host, String username, String password, int port, String cmd) {
List<String> reStrings = new ArrayList<String>(); List<String> reStrings = new ArrayList<String>();
Session sess = null; Session sess = null;
Connection new_conn; Connection new_conn;
try { try {
if(Constant.hostIp.equals(host)){ if(Constant.hostIp.equals(host)){
new_conn=conn; new_conn=conn;
} }
else if(otherConns.containsKey(host) && otherConns.get(host)!=null){ else if(otherConns.containsKey(host) && otherConns.get(host)!=null){
new_conn=otherConns.get(host); new_conn=otherConns.get(host);
} }
else{ else{
new_conn = getOpenedConnection(host, username, password, port); new_conn = getOpenedConnection(host, username, password, port);
otherConns.put(host, new_conn); otherConns.put(host, new_conn);
} }
sess = new_conn.openSession(); sess = new_conn.openSession();
// 执锟斤拷cmd // 执锟斤拷cmd
sess.execCommand(cmd); sess.execCommand(cmd);
InputStream stdout = new StreamGobbler(sess.getStdout()); InputStream stdout = new StreamGobbler(sess.getStdout());
InputStream stderr = new StreamGobbler(sess.getStderr()); InputStream stderr = new StreamGobbler(sess.getStderr());
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
while (true) { while (true) {
String line = stdoutReader.readLine(); String line = stdoutReader.readLine();
if (line != null) { if (line != null) {
// System.out.println(line); // System.out.println(line);
reStrings.add(line); reStrings.add(line);
} else { } else {
break; break;
} }
} }
if(reStrings.size()==0){ if(reStrings.size()==0){
while (true) { while (true) {
String line = stderrReader.readLine(); String line = stderrReader.readLine();
if (line != null) { if (line != null) {
// System.out.println(line); // System.out.println(line);
reStrings.add(line); reStrings.add(line);
} else { } else {
break; break;
} }
} }
} }
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
sess.close(); sess.close();
} }
return reStrings; return reStrings;
} }
public Map<String, String> execMD5cmd(String cmd) { public Map<String, String> execMD5cmd(String cmd) {
Map<String, String> md5 = new HashMap<String, String>(); Map<String, String> md5 = new HashMap<String, String>();
Session sess = null; Session sess = null;
try { try {
sess = conn.openSession(); sess = conn.openSession();
// 执锟斤拷cmd // 执锟斤拷cmd
sess.execCommand(cmd); sess.execCommand(cmd);
InputStream stdout = new StreamGobbler(sess.getStdout()); InputStream stdout = new StreamGobbler(sess.getStdout());
InputStream stderr = new StreamGobbler(sess.getStderr()); InputStream stderr = new StreamGobbler(sess.getStderr());
BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout));
BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr));
while (true) { while (true) {
String line = stdoutReader.readLine(); String line = stdoutReader.readLine();
if (line != null) { if (line != null) {
String[] lines = line.split(" "); String[] lines = line.split(" ");
String key = lines[1].trim(); String key = lines[1].trim();
String value = lines[0].trim(); String value = lines[0].trim();
md5.put(key, value); md5.put(key, value);
} else { } else {
break; break;
} }
} }
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
sess.close(); sess.close();
} }
return md5; return md5;
} }
public String execGetSize(String cmd) { public String execGetSize(String cmd) {
status = false; status = false;
String str_size = "0"; String str_size = "0";
Session sess = null; Session sess = null;
try { try {
// 执锟斤拷cmd // 执锟斤拷cmd
sess = conn.openSession(); sess = conn.openSession();
sess.execCommand(cmd); sess.execCommand(cmd);
InputStream stdout = new StreamGobbler(sess.getStdout()); InputStream stdout = new StreamGobbler(sess.getStdout());
@SuppressWarnings("resource") @SuppressWarnings("resource")
BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true) { while (true) {
String line = br.readLine(); String line = br.readLine();
if (line != null) { if (line != null) {
// String[] lines=line.split(" "); // String[] lines=line.split(" ");
// str_size=lines[0]; // str_size=lines[0];
str_size = line; str_size = line;
} else { } else {
break; break;
} }
} }
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
sess.close(); sess.close();
} }
status = true; status = true;
return str_size; return str_size;
} }
public static void main(String[] args) { public static void main(String[] args) {
PropertyConfigurator.configure("log4j.properties"); PropertyConfigurator.configure("log4j.properties");
} }
} }

@ -0,0 +1,61 @@
package com.platform.utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class ProcessMyUtil {
public List<String> execCmdWaitAcquiescent(String cmd) {
// String host=Constant.hostIp;
// String username=Constant.rootUser;
// String password=Constant.rootPasswd;
// int port=Constant.port;
List<String> reStrings = new ArrayList<String>();
try {
ProcessBuilder pb = null;
Process pro = null;
if (cmd.contains("grep")) {
List<String> cmds = new ArrayList<String>();
cmds.add("sh");
cmds.add("-c");
cmds.add(cmd);
new ProcessBuilder(cmds);
pro = pb.start();
}else {
pro = Runtime.getRuntime().exec(cmd);
}
if (null == pro) {
return reStrings;
}
BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
if (line != null) {
// System.out.println(line);
reStrings.add(line);
} else {
break;
}
}
if(reStrings.size()==0){
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return reStrings;
}
}

@ -1,31 +1,31 @@
/** /**
* : Support.java * : Support.java
* : </> * : </>
* : <> * : <>
* @author liliy * @author liliy
* : <> * : <>
* 2016912 * 2016912
* <> * <>
*/ */
package com.platform.utils; package com.platform.utils;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* <> * <>
* <> * <>
* @author liliy * @author liliy
* @version [2016912] * @version [2016912]
* @see [/] * @see [/]
* @since [/] * @since [/]
*/ */
public class Support { public class Support {
public static boolean checkIP(String str) { public static boolean checkIP(String str) {
Pattern pattern = Pattern Pattern pattern = Pattern
.compile("^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]" .compile("^((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]"
+ "|[*])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])$"); + "|[*])\\.){3}(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]|[*])$");
return pattern.matcher(str).matches(); return pattern.matcher(str).matches();
} }
} }

@ -1,161 +1,162 @@
package com.platform.utils; package com.platform.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.platform.entities.Brick; import com.platform.entities.Brick;
import com.platform.entities.FolderNode; import com.platform.entities.FolderNode;
import com.platform.entities.VolumeEntity; import com.platform.entities.VolumeEntity;
import com.platform.glusterfs.ClusterInfo; import com.platform.glusterfs.ClusterInfo;
import com.platform.glusterfs.GetTreeData; import com.platform.glusterfs.GetTreeData;
import com.platform.glusterfs.VolumeInfo; import com.platform.glusterfs.VolumeInfo;
import com.platform.service.VolumeService; import com.platform.service.VolumeService;
public class ThreadVolume extends Thread { public class ThreadVolume extends Thread {
public static Logger log = Logger.getLogger(ThreadVolume.class); public static Logger log = Logger.getLogger(ThreadVolume.class);
/** /**
* -- * --
*/ */
private static String pointPath = "/home"; private static String pointPath = "/home";
/** Volume信息查询 */ /** Volume信息查询 */
private VolumeInfo volumeInfo = new VolumeInfo(); private VolumeInfo volumeInfo = new VolumeInfo();
private ClusterInfo cluster = new ClusterInfo(); private ClusterInfo cluster = new ClusterInfo();
/** gfs目录树形展示 */ /** gfs目录树形展示 */
private GetTreeData gfsTree = new GetTreeData(); private GetTreeData gfsTree = new GetTreeData();
public ThreadVolume() { public ThreadVolume() {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public ThreadVolume(String name) { public ThreadVolume(String name) {
setName(name); setName(name);
} }
public ThreadVolume(String name, String path) { public ThreadVolume(String name, String path) {
if (null != path && !"".equals(path.trim())) { if (null != path && !"".equals(path.trim())) {
ThreadVolume.pointPath = path; ThreadVolume.pointPath = path;
} }
} }
@Override @Override
public void run() { public void run() {
super.run(); super.run();
while (true) { while (true) {
try { try {
getVolumeMsg(); getVolumeMsg();
Thread.sleep(Constant.get_volume_sleep_time); Thread.sleep(Constant.get_volume_sleep_time);
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }
} }
} }
public static String getPointPath() { public static String getPointPath() {
return pointPath; return pointPath;
} }
public static void setPointPath(String pointPath) { public static void setPointPath(String pointPath) {
ThreadVolume.pointPath = pointPath; ThreadVolume.pointPath = pointPath;
} }
public void getVolumeMsg() { public void getVolumeMsg() {
List<FolderNode> folderlist = new ArrayList<FolderNode>(); List<FolderNode> folderlist = new ArrayList<FolderNode>();
List<VolumeEntity> volumeList = new ArrayList<VolumeEntity>(); List<VolumeEntity> volumeList = new ArrayList<VolumeEntity>();
// brick状态 map集合 // brick状态 map集合
Map<String, String> brickStatusMap = cluster.showClusterInfo(); Map<String, String> brickStatusMap = cluster.showClusterInfo();
// 查询 volume name // 查询 volume name
List<String> volumeNameList = volumeInfo.showAllVolumeName(); List<String> volumeNameList = volumeInfo.showAllVolumeName();
if (null != volumeNameList) { if (null != volumeNameList) {
for (String volumeName : volumeNameList) { for (String volumeName : volumeNameList) {
try { try {
VolumeEntity volume = new VolumeEntity(); VolumeEntity volume = new VolumeEntity();
volume.setName(volumeName); volume.setName(volumeName);
List<String> path = volumeInfo List<String> path = volumeInfo
.getVolumeMountPoint(volumeName); .getVolumeMountPoint(volumeName);
// 默认加载第一个路径 // 默认加载第一个路径
if (null != path) { if (null != path) {
for (String one : path) { for (String one : path) {
if (!one.contains("df")) { if (!one.contains("df")) {
volume.setPath(one); volume.setPath(one);
} break;
} }
} }
if (null == volume.getPath()) { }
volume.setPath(""); if (null == volume.getPath()) {
} volume.setPath("");
volume.setAllSize(volumeInfo }
.getVolumeAvailableSize(volumeName) volume.setAllSize(volumeInfo
+ volumeInfo.getVolumeUseSize(volumeName)); .getVolumeAvailableSize(volumeName)
// 状态Started,Stopped,Created + volumeInfo.getVolumeUseSize(volumeName));
String status = volumeInfo.getVolumeStatus(volumeName); // 状态Started,Stopped,Created
if ("Started".equals(status)) { String status = volumeInfo.getVolumeStatus(volumeName);
volume.setStatus(true); if ("Started".equals(status)) {
} else { volume.setStatus(true);
volume.setStatus(false); } else {
} volume.setStatus(false);
volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); }
volume.setType(volumeInfo.getVolumeType(volumeName)); volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
// TODO 查询brick-- volume.setType(volumeInfo.getVolumeType(volumeName));
// 返回 ip:path // TODO 查询brick--
List<String> brickStrs = volumeInfo // 返回 ip:path
.getVolumeBricks(volumeName); List<String> brickStrs = volumeInfo
// brick已用大小 .getVolumeBricks(volumeName);
Map<String, Double> usedSize = volumeInfo // brick已用大小
.getVolumebricksDataSize(volumeName); Map<String, Double> usedSize = volumeInfo
Map<String, Double> availableSize = volumeInfo .getVolumebricksDataSize(volumeName);
.getVolumebricksAvailableSize(volumeName); Map<String, Double> availableSize = volumeInfo
.getVolumebricksAvailableSize(volumeName);
List<Brick> brickList = new ArrayList<Brick>();
for (String brickIpPath : brickStrs) { List<Brick> brickList = new ArrayList<Brick>();
Brick b = new Brick(); for (String brickIpPath : brickStrs) {
String ipAndpath[] = brickIpPath.split(":"); Brick b = new Brick();
String brickip = ipAndpath[0]; String ipAndpath[] = brickIpPath.split(":");
String brickpath = ipAndpath[1]; String brickip = ipAndpath[0];
// iP , path , String brickpath = ipAndpath[1];
b.setIp(brickip); // iP , path ,
if (brickStatusMap == null b.setIp(brickip);
|| brickStatusMap.size() == 0) { if (brickStatusMap == null
b.setStatus(false); || brickStatusMap.size() == 0) {
} else if (brickStatusMap.containsKey(brickip)) { b.setStatus(false);
b.setStatus(true); } else if (brickStatusMap.containsKey(brickip)) {
} else { b.setStatus(true);
b.setStatus(false); } else {
} b.setStatus(false);
b.setPath(brickpath); }
b.setAvailableSize(availableSize.get(brickIpPath)); b.setPath(brickpath);
b.setUsedSize(usedSize.get(brickIpPath)); b.setAvailableSize(availableSize.get(brickIpPath));
brickList.add(b); b.setUsedSize(usedSize.get(brickIpPath));
} brickList.add(b);
volume.setBrick(brickList); }
volume.setBrick(brickList);
// 默认加载第一个路径
if (null != path && path.size() > 0) { // 默认加载第一个路径
// 装入 folder if (null != path && path.size() > 0) {
// 查询 每个 volume 下的 folder // 装入 folder
FolderNode foldertmp = gfsTree.getDatas(path.get(0)); // 查询 每个 volume 下的 folder
folderlist.add(foldertmp); FolderNode foldertmp = gfsTree.getDatas(path.get(0));
} folderlist.add(foldertmp);
volumeList.add(volume); }
} catch (Exception e) { volumeList.add(volume);
log.error(e.getMessage(), e); } catch (Exception e) {
} log.error(e.getMessage(), e);
} }
} }
// 更新folder 目录 }
CacheTreeData.setFolders(folderlist); // 更新folder 目录
CacheTreeData.setVolumeList(volumeList); CacheTreeData.setFolders(folderlist);
} CacheTreeData.setVolumeList(volumeList);
}
}
}

@ -1,49 +1,49 @@
package com.platform.utils; package com.platform.utils;
import java.util.List; import java.util.List;
import com.platform.entities.FolderNode; import com.platform.entities.FolderNode;
public class getTreeDataByPath { public class getTreeDataByPath {
/** /**
* @param path * @param path
* @return * @return
*/ */
public FolderNode findByPath(String path) { public FolderNode findByPath(String path) {
List<FolderNode> folderNodelist = CacheTreeData.getFolders(); List<FolderNode> folderNodelist = CacheTreeData.getFolders();
if (null == folderNodelist) { if (null == folderNodelist) {
return null; return null;
} }
FolderNode folder = null; FolderNode folder = null;
for (FolderNode folderNode : folderNodelist) { for (FolderNode folderNode : folderNodelist) {
folder = getFolder(folderNode, path); folder = getFolder(folderNode, path);
if (null != folder) { if (null != folder) {
break; break;
} }
} }
return folder; return folder;
} }
/** /**
* @param f * @param f
* @return * @return
*/ */
private FolderNode getFolder(FolderNode f, String path){ private FolderNode getFolder(FolderNode f, String path){
FolderNode result = null; FolderNode result = null;
if(path.equals(f.getPath())){ if(path.equals(f.getPath())){
return f; return f;
} }
List<FolderNode> folds = f.getChildNodes(); List<FolderNode> folds = f.getChildNodes();
if (null != folds) { if (null != folds) {
for (FolderNode folderNode : folds) { for (FolderNode folderNode : folds) {
result = getFolder(folderNode, path); result = getFolder(folderNode, path);
if (null != result) { if (null != result) {
break; break;
} }
} }
} }
return result; return result;
} }
} }

Loading…
Cancel
Save