diff --git a/.classpath b/.classpath
index b57aa8a2..7c800378 100644
--- a/.classpath
+++ b/.classpath
@@ -1,13 +1,13 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
index a4a8b61c..5adcb935 100644
--- a/.project
+++ b/.project
@@ -1,36 +1,36 @@
-
-
- jfinal-demo
-
-
-
-
-
- org.eclipse.wst.jsdt.core.javascriptValidator
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.wst.common.project.facet.core.builder
-
-
-
-
- org.eclipse.wst.validation.validationbuilder
-
-
-
-
-
- org.eclipse.jem.workbench.JavaEMFNature
- org.eclipse.wst.common.modulecore.ModuleCoreNature
- org.eclipse.wst.common.project.facet.core.nature
- org.eclipse.jdt.core.javanature
- org.eclipse.wst.jsdt.core.jsNature
-
-
+
+
+ jfinal-demo
+
+
+
+
+
+ org.eclipse.wst.jsdt.core.javascriptValidator
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+
+
+ org.eclipse.jem.workbench.JavaEMFNature
+ org.eclipse.wst.common.modulecore.ModuleCoreNature
+ org.eclipse.wst.common.project.facet.core.nature
+ org.eclipse.jdt.core.javanature
+ org.eclipse.wst.jsdt.core.jsNature
+
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..11f6e462
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -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
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
new file mode 100644
index 00000000..201b3e53
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.component
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 00000000..82c34281
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/WebRoot/META-INF/MANIFEST.MF b/WebContent/META-INF/MANIFEST.MF
similarity index 92%
rename from WebRoot/META-INF/MANIFEST.MF
rename to WebContent/META-INF/MANIFEST.MF
index 254272e1..5e949512 100644
--- a/WebRoot/META-INF/MANIFEST.MF
+++ b/WebContent/META-INF/MANIFEST.MF
@@ -1,3 +1,3 @@
-Manifest-Version: 1.0
-Class-Path:
-
+Manifest-Version: 1.0
+Class-Path:
+
diff --git a/WebContent/WEB-INF/classes/.gitignore b/WebContent/WEB-INF/classes/.gitignore
new file mode 100644
index 00000000..43e58b99
--- /dev/null
+++ b/WebContent/WEB-INF/classes/.gitignore
@@ -0,0 +1 @@
+/com
diff --git a/WebContent/WEB-INF/classes/com/platform/config/JfinalConfig.class b/WebContent/WEB-INF/classes/com/platform/config/JfinalConfig.class
new file mode 100644
index 00000000..604883aa
Binary files /dev/null and b/WebContent/WEB-INF/classes/com/platform/config/JfinalConfig.class differ
diff --git a/WebContent/WEB-INF/classes/com/platform/controller/GfsController.class b/WebContent/WEB-INF/classes/com/platform/controller/GfsController.class
new file mode 100644
index 00000000..0ed5dcef
Binary files /dev/null and b/WebContent/WEB-INF/classes/com/platform/controller/GfsController.class differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/controller/HelloController.class b/WebContent/WEB-INF/classes/com/platform/controller/HelloController.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/controller/HelloController.class
rename to WebContent/WEB-INF/classes/com/platform/controller/HelloController.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/entities/Brick.class b/WebContent/WEB-INF/classes/com/platform/entities/Brick.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/entities/Brick.class
rename to WebContent/WEB-INF/classes/com/platform/entities/Brick.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/entities/FolderNode.class b/WebContent/WEB-INF/classes/com/platform/entities/FolderNode.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/entities/FolderNode.class
rename to WebContent/WEB-INF/classes/com/platform/entities/FolderNode.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/entities/VolumeEntity.class b/WebContent/WEB-INF/classes/com/platform/entities/VolumeEntity.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/entities/VolumeEntity.class
rename to WebContent/WEB-INF/classes/com/platform/entities/VolumeEntity.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/form/Bean2MapUtils.class b/WebContent/WEB-INF/classes/com/platform/form/Bean2MapUtils.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/form/Bean2MapUtils.class
rename to WebContent/WEB-INF/classes/com/platform/form/Bean2MapUtils.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/form/baseForm.class b/WebContent/WEB-INF/classes/com/platform/form/baseForm.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/form/baseForm.class
rename to WebContent/WEB-INF/classes/com/platform/form/baseForm.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/CheckoutMD5.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/CheckoutMD5.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/glusterfs/CheckoutMD5.class
rename to WebContent/WEB-INF/classes/com/platform/glusterfs/CheckoutMD5.class
diff --git a/WebContent/WEB-INF/classes/com/platform/glusterfs/ClusterInfo.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/ClusterInfo.class
new file mode 100644
index 00000000..19a5a386
Binary files /dev/null and b/WebContent/WEB-INF/classes/com/platform/glusterfs/ClusterInfo.class differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/CopyData.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/CopyData.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/glusterfs/CopyData.class
rename to WebContent/WEB-INF/classes/com/platform/glusterfs/CopyData.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/GetTreeData.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/GetTreeData.class
similarity index 92%
rename from WebRoot/WEB-INF/classes/com/platform/glusterfs/GetTreeData.class
rename to WebContent/WEB-INF/classes/com/platform/glusterfs/GetTreeData.class
index db5d3e02..65cf9ed6 100644
Binary files a/WebRoot/WEB-INF/classes/com/platform/glusterfs/GetTreeData.class and b/WebContent/WEB-INF/classes/com/platform/glusterfs/GetTreeData.class differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/RemoveData.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/RemoveData.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/glusterfs/RemoveData.class
rename to WebContent/WEB-INF/classes/com/platform/glusterfs/RemoveData.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/SetCluster.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/SetCluster.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/glusterfs/SetCluster.class
rename to WebContent/WEB-INF/classes/com/platform/glusterfs/SetCluster.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/SetVolume.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/SetVolume.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/glusterfs/SetVolume.class
rename to WebContent/WEB-INF/classes/com/platform/glusterfs/SetVolume.class
diff --git a/WebContent/WEB-INF/classes/com/platform/glusterfs/ShowData.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/ShowData.class
new file mode 100644
index 00000000..59e94959
Binary files /dev/null and b/WebContent/WEB-INF/classes/com/platform/glusterfs/ShowData.class differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/SizeInfo.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/SizeInfo.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/glusterfs/SizeInfo.class
rename to WebContent/WEB-INF/classes/com/platform/glusterfs/SizeInfo.class
diff --git a/WebContent/WEB-INF/classes/com/platform/glusterfs/VolumeInfo.class b/WebContent/WEB-INF/classes/com/platform/glusterfs/VolumeInfo.class
new file mode 100644
index 00000000..c3b3f95b
Binary files /dev/null and b/WebContent/WEB-INF/classes/com/platform/glusterfs/VolumeInfo.class differ
diff --git a/WebContent/WEB-INF/classes/com/platform/service/VolumeService.class b/WebContent/WEB-INF/classes/com/platform/service/VolumeService.class
new file mode 100644
index 00000000..7f62f9a9
Binary files /dev/null and b/WebContent/WEB-INF/classes/com/platform/service/VolumeService.class differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/utils/CacheTreeData.class b/WebContent/WEB-INF/classes/com/platform/utils/CacheTreeData.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/utils/CacheTreeData.class
rename to WebContent/WEB-INF/classes/com/platform/utils/CacheTreeData.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/utils/Constant.class b/WebContent/WEB-INF/classes/com/platform/utils/Constant.class
similarity index 96%
rename from WebRoot/WEB-INF/classes/com/platform/utils/Constant.class
rename to WebContent/WEB-INF/classes/com/platform/utils/Constant.class
index 6b14cf0c..f9faf990 100644
Binary files a/WebRoot/WEB-INF/classes/com/platform/utils/Constant.class and b/WebContent/WEB-INF/classes/com/platform/utils/Constant.class differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/utils/FileOperateHelper.class b/WebContent/WEB-INF/classes/com/platform/utils/FileOperateHelper.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/utils/FileOperateHelper.class
rename to WebContent/WEB-INF/classes/com/platform/utils/FileOperateHelper.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/utils/GanymedSSH.class b/WebContent/WEB-INF/classes/com/platform/utils/GanymedSSH.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/utils/GanymedSSH.class
rename to WebContent/WEB-INF/classes/com/platform/utils/GanymedSSH.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/utils/Support.class b/WebContent/WEB-INF/classes/com/platform/utils/Support.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/utils/Support.class
rename to WebContent/WEB-INF/classes/com/platform/utils/Support.class
diff --git a/WebRoot/WEB-INF/classes/com/platform/utils/ThreadVolume.class b/WebContent/WEB-INF/classes/com/platform/utils/ThreadVolume.class
similarity index 83%
rename from WebRoot/WEB-INF/classes/com/platform/utils/ThreadVolume.class
rename to WebContent/WEB-INF/classes/com/platform/utils/ThreadVolume.class
index 013293ef..8ebb39ba 100644
Binary files a/WebRoot/WEB-INF/classes/com/platform/utils/ThreadVolume.class and b/WebContent/WEB-INF/classes/com/platform/utils/ThreadVolume.class differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/utils/getTreeDataByPath.class b/WebContent/WEB-INF/classes/com/platform/utils/getTreeDataByPath.class
similarity index 100%
rename from WebRoot/WEB-INF/classes/com/platform/utils/getTreeDataByPath.class
rename to WebContent/WEB-INF/classes/com/platform/utils/getTreeDataByPath.class
diff --git a/WebRoot/WEB-INF/lib/c3p0-0.9.1.2.jar b/WebContent/WEB-INF/lib/c3p0-0.9.1.2.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/c3p0-0.9.1.2.jar
rename to WebContent/WEB-INF/lib/c3p0-0.9.1.2.jar
diff --git a/WebRoot/WEB-INF/lib/com.fasterxml.jackson.core.jar b/WebContent/WEB-INF/lib/com.fasterxml.jackson.core.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/com.fasterxml.jackson.core.jar
rename to WebContent/WEB-INF/lib/com.fasterxml.jackson.core.jar
diff --git a/WebRoot/WEB-INF/lib/commons-beanutils-1.8.0.jar b/WebContent/WEB-INF/lib/commons-beanutils-1.8.0.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/commons-beanutils-1.8.0.jar
rename to WebContent/WEB-INF/lib/commons-beanutils-1.8.0.jar
diff --git a/WebRoot/WEB-INF/lib/commons-collections-3.2.1.jar b/WebContent/WEB-INF/lib/commons-collections-3.2.1.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/commons-collections-3.2.1.jar
rename to WebContent/WEB-INF/lib/commons-collections-3.2.1.jar
diff --git a/WebRoot/WEB-INF/lib/commons-lang-2.4.jar b/WebContent/WEB-INF/lib/commons-lang-2.4.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/commons-lang-2.4.jar
rename to WebContent/WEB-INF/lib/commons-lang-2.4.jar
diff --git a/WebRoot/WEB-INF/lib/commons-logging-1.1.1.jar b/WebContent/WEB-INF/lib/commons-logging-1.1.1.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/commons-logging-1.1.1.jar
rename to WebContent/WEB-INF/lib/commons-logging-1.1.1.jar
diff --git a/WebRoot/WEB-INF/lib/commons-logging-1.2.jar b/WebContent/WEB-INF/lib/commons-logging-1.2.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/commons-logging-1.2.jar
rename to WebContent/WEB-INF/lib/commons-logging-1.2.jar
diff --git a/WebRoot/WEB-INF/lib/cos-26Dec2008.jar b/WebContent/WEB-INF/lib/cos-26Dec2008.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/cos-26Dec2008.jar
rename to WebContent/WEB-INF/lib/cos-26Dec2008.jar
diff --git a/WebRoot/WEB-INF/lib/dom4j-1.6.1.jar b/WebContent/WEB-INF/lib/dom4j-1.6.1.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/dom4j-1.6.1.jar
rename to WebContent/WEB-INF/lib/dom4j-1.6.1.jar
diff --git a/WebRoot/WEB-INF/lib/druid-1.0.5.jar b/WebContent/WEB-INF/lib/druid-1.0.5.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/druid-1.0.5.jar
rename to WebContent/WEB-INF/lib/druid-1.0.5.jar
diff --git a/WebRoot/WEB-INF/lib/ezmorph-1.0.6.jar b/WebContent/WEB-INF/lib/ezmorph-1.0.6.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/ezmorph-1.0.6.jar
rename to WebContent/WEB-INF/lib/ezmorph-1.0.6.jar
diff --git a/WebRoot/WEB-INF/lib/freemarker-2.3.20.jar b/WebContent/WEB-INF/lib/freemarker-2.3.20.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/freemarker-2.3.20.jar
rename to WebContent/WEB-INF/lib/freemarker-2.3.20.jar
diff --git a/WebRoot/WEB-INF/lib/ganymed-ssh2-build209.jar b/WebContent/WEB-INF/lib/ganymed-ssh2-build209.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/ganymed-ssh2-build209.jar
rename to WebContent/WEB-INF/lib/ganymed-ssh2-build209.jar
diff --git a/WebRoot/WEB-INF/lib/jackson-annotations-2.4.0.jar b/WebContent/WEB-INF/lib/jackson-annotations-2.4.0.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/jackson-annotations-2.4.0.jar
rename to WebContent/WEB-INF/lib/jackson-annotations-2.4.0.jar
diff --git a/WebRoot/WEB-INF/lib/jackson-databind-2.4.2.jar b/WebContent/WEB-INF/lib/jackson-databind-2.4.2.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/jackson-databind-2.4.2.jar
rename to WebContent/WEB-INF/lib/jackson-databind-2.4.2.jar
diff --git a/WebRoot/WEB-INF/lib/jetty-server-8.1.8.jar b/WebContent/WEB-INF/lib/jetty-server-8.1.8.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/jetty-server-8.1.8.jar
rename to WebContent/WEB-INF/lib/jetty-server-8.1.8.jar
diff --git a/WebRoot/WEB-INF/lib/jfinal-1.9-bin.jar b/WebContent/WEB-INF/lib/jfinal-1.9-bin.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/jfinal-1.9-bin.jar
rename to WebContent/WEB-INF/lib/jfinal-1.9-bin.jar
diff --git a/WebRoot/WEB-INF/lib/json-lib-2.2.3-jdk15.jar b/WebContent/WEB-INF/lib/json-lib-2.2.3-jdk15.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/json-lib-2.2.3-jdk15.jar
rename to WebContent/WEB-INF/lib/json-lib-2.2.3-jdk15.jar
diff --git a/WebRoot/WEB-INF/lib/log4j-1.2.17.jar b/WebContent/WEB-INF/lib/log4j-1.2.17.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/log4j-1.2.17.jar
rename to WebContent/WEB-INF/lib/log4j-1.2.17.jar
diff --git a/WebRoot/WEB-INF/lib/logging-interceptor-2.7.2.jar b/WebContent/WEB-INF/lib/logging-interceptor-2.7.2.jar
similarity index 100%
rename from WebRoot/WEB-INF/lib/logging-interceptor-2.7.2.jar
rename to WebContent/WEB-INF/lib/logging-interceptor-2.7.2.jar
diff --git a/WebRoot/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml
similarity index 93%
rename from WebRoot/WEB-INF/web.xml
rename to WebContent/WEB-INF/web.xml
index 342d7a79..496f4742 100644
--- a/WebRoot/WEB-INF/web.xml
+++ b/WebContent/WEB-INF/web.xml
@@ -1,31 +1,31 @@
-
-
- jfinal-demo
-
- index.html
- index.htm
- index.jsp
- default.html
- default.htm
- default.jsp
-
-
-
-
- jfinalF
- com.jfinal.core.JFinalFilter
-
- configClass
- com.platform.config.JfinalConfig
-
-
-
- jfinalF
- /*
-
-
+
+
+ JFinal-demo
+
+ index.html
+ index.htm
+ index.jsp
+ default.html
+ default.htm
+ default.jsp
+
+
+
+
+ jfinalF
+ com.jfinal.core.JFinalFilter
+
+ configClass
+ com.platform.config.JfinalConfig
+
+
+
+ jfinalF
+ /*
+
+
\ No newline at end of file
diff --git a/WebRoot/WEB-INF/classes/com/platform/config/JfinalConfig.class b/WebRoot/WEB-INF/classes/com/platform/config/JfinalConfig.class
deleted file mode 100644
index eba4ac82..00000000
Binary files a/WebRoot/WEB-INF/classes/com/platform/config/JfinalConfig.class and /dev/null differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/controller/GfsController.class b/WebRoot/WEB-INF/classes/com/platform/controller/GfsController.class
deleted file mode 100644
index 32869842..00000000
Binary files a/WebRoot/WEB-INF/classes/com/platform/controller/GfsController.class and /dev/null differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/ClusterInfo.class b/WebRoot/WEB-INF/classes/com/platform/glusterfs/ClusterInfo.class
deleted file mode 100644
index 9e62fcae..00000000
Binary files a/WebRoot/WEB-INF/classes/com/platform/glusterfs/ClusterInfo.class and /dev/null differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/ShowData.class b/WebRoot/WEB-INF/classes/com/platform/glusterfs/ShowData.class
deleted file mode 100644
index c34f2f1d..00000000
Binary files a/WebRoot/WEB-INF/classes/com/platform/glusterfs/ShowData.class and /dev/null differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/glusterfs/VolumeInfo.class b/WebRoot/WEB-INF/classes/com/platform/glusterfs/VolumeInfo.class
deleted file mode 100644
index 2cdce2a2..00000000
Binary files a/WebRoot/WEB-INF/classes/com/platform/glusterfs/VolumeInfo.class and /dev/null differ
diff --git a/WebRoot/WEB-INF/classes/com/platform/service/VolumeService.class b/WebRoot/WEB-INF/classes/com/platform/service/VolumeService.class
deleted file mode 100644
index 5b3ac2c7..00000000
Binary files a/WebRoot/WEB-INF/classes/com/platform/service/VolumeService.class and /dev/null differ
diff --git a/src/com/platform/config/JfinalConfig.java b/src/com/platform/config/JfinalConfig.java
index 7f6a540d..9b9d8aab 100644
--- a/src/com/platform/config/JfinalConfig.java
+++ b/src/com/platform/config/JfinalConfig.java
@@ -9,12 +9,16 @@ import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.platform.controller.GfsController;
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 {
@Override
public void configConstant(Constants me) {
me.setDevMode(true);
+ Constant.ganymedSSH = new GanymedSSH(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port);
}
@Override
@@ -37,5 +41,7 @@ public class JfinalConfig extends JFinalConfig {
public static void main(String[] args) {
JFinal.start("WebRoot", 80, "/", 5);
+// new ThreadVolume().start();
+
}
}
diff --git a/src/com/platform/controller/GfsController.java b/src/com/platform/controller/GfsController.java
index 7a8a03c0..f97a7b68 100644
--- a/src/com/platform/controller/GfsController.java
+++ b/src/com/platform/controller/GfsController.java
@@ -1,53 +1,63 @@
-package com.platform.controller;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import net.sf.json.JSONObject;
-
-import com.jfinal.core.Controller;
-import com.platform.entities.FolderNode;
-import com.platform.entities.VolumeEntity;
-import com.platform.utils.CacheTreeData;
-import com.platform.utils.getTreeDataByPath;
-
-public class GfsController extends Controller {
-
- /** gfs目录树形查询 */
- private getTreeDataByPath getFolder = new getTreeDataByPath();
-
- /**
- * 首页-"/gfs"下没有匹配到的路径时的请求方法
- */
- public void index() {
- renderText("hello gfs !");
- }
-
- public void getAllvolume(){
-
- List volumeList = CacheTreeData.getVolumeList();
- if (null == volumeList) {
- JSONObject jsondata = JSONObject.fromObject(new ArrayList());
- renderJson(jsondata.toString());
- }
- for (VolumeEntity volume : volumeList) {
- if (null != volume.getPath()) {
-// 获得 folder 目录
- List list = new ArrayList();
- FolderNode currNode = getFolder(volume.getPath());
- if (null != currNode && null != currNode.getChildNodes()) {
- list.addAll(currNode.getChildNodes());
- }
- volume.setFolder(list);
- }
- }
- JSONObject jsondata = JSONObject.fromObject(volumeList);
- renderJson(jsondata.toString());
- }
-
- public FolderNode getFolder(String path) {
- FolderNode result = getFolder.findByPath(path);
- return result;
- }
-
-}
+package com.platform.controller;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+import com.alibaba.druid.util.DaemonThreadFactory;
+import com.jfinal.core.Controller;
+import com.platform.entities.FolderNode;
+import com.platform.entities.VolumeEntity;
+import com.platform.utils.CacheTreeData;
+import com.platform.utils.ThreadVolume;
+import com.platform.utils.getTreeDataByPath;
+
+public class GfsController extends Controller {
+
+ /** gfs目录树形查询 */
+ private getTreeDataByPath getFolder = new getTreeDataByPath();
+
+ /**
+ * 首页-"/gfs"下没有匹配到的路径时的请求方法
+ */
+ public void index() {
+ renderText("hello gfs !");
+ }
+
+ public void getAllvolume(){
+ Date a = new Date();
+ //查询volume信息
+ new ThreadVolume().getVolumeMsg();
+ //获得volume信息
+ List volumeList = CacheTreeData.getVolumeList();
+ if (null == volumeList) {
+ JSONObject jsondata = JSONObject.fromObject(new ArrayList());
+ renderJson(jsondata.toString());
+ }
+ for (VolumeEntity volume : volumeList) {
+ if (null != volume.getPath()) {
+// 获得 folder 目录
+ List list = new ArrayList();
+ FolderNode currNode = getFolder(volume.getPath());
+ if (null != currNode && null != currNode.getChildNodes()) {
+ list.addAll(currNode.getChildNodes());
+ }
+ volume.setFolder(list);
+ }
+ }
+ List 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;
+ }
+
+}
diff --git a/src/com/platform/controller/HelloController.java b/src/com/platform/controller/HelloController.java
index 3cfad193..90c0ffcb 100644
--- a/src/com/platform/controller/HelloController.java
+++ b/src/com/platform/controller/HelloController.java
@@ -1,48 +1,48 @@
-package com.platform.controller;
-
-import java.util.ArrayList;
-import java.util.List;
-import net.sf.json.JSONObject;
-import com.jfinal.core.Controller;
-import com.platform.entities.FolderNode;
-import com.platform.form.baseForm;
-
-public class HelloController extends Controller {
-
- public void index() {
- renderText("hello jfinal index !");
- }
-
- public void tojson() {
- renderText("hello jfinal tojson !");
- }
-
- public void gain() {
- baseForm form = new baseForm();
- form.setId("12");
- form.setName("n3");
-
- String base = getPara("jsondata");
- System.err.println(base);
- if (null != base) {
- FolderNode f = new FolderNode();
- f.setIsFolder(2);
- f.setName("1");
- f.setPath("/da");
- FolderNode f1 = new FolderNode();
- f1.setIsFolder(2);
- f1.setName("1");
- f1.setPath("/da");
- List lis = new ArrayList();
- lis.add(f1);
- f.setChildNodes(lis);
- JSONObject jsondata = JSONObject.fromObject(f);
- renderJson(jsondata.toString());
- }
- else {
- renderText("hello jfinal gaindata ! ");
- }
- }
-
-
-}
+package com.platform.controller;
+
+import java.util.ArrayList;
+import java.util.List;
+import net.sf.json.JSONObject;
+import com.jfinal.core.Controller;
+import com.platform.entities.FolderNode;
+import com.platform.form.baseForm;
+
+public class HelloController extends Controller {
+
+ public void index() {
+ renderText("hello jfinal index !");
+ }
+
+ public void tojson() {
+ renderText("hello jfinal tojson !");
+ }
+
+ public void gain() {
+ baseForm form = new baseForm();
+ form.setId("12");
+ form.setName("n3");
+
+ String base = getPara("jsondata");
+ System.err.println(base);
+ if (null != base) {
+ FolderNode f = new FolderNode();
+ f.setIsFolder(2);
+ f.setName("1");
+ f.setPath("/da");
+ FolderNode f1 = new FolderNode();
+ f1.setIsFolder(2);
+ f1.setName("1");
+ f1.setPath("/da");
+ List lis = new ArrayList();
+ lis.add(f1);
+ f.setChildNodes(lis);
+ JSONObject jsondata = JSONObject.fromObject(f);
+ renderJson(jsondata.toString());
+ }
+ else {
+ renderText("hello jfinal gaindata ! ");
+ }
+ }
+
+
+}
diff --git a/src/com/platform/entities/Brick.java b/src/com/platform/entities/Brick.java
index e6701dab..53337ac9 100644
--- a/src/com/platform/entities/Brick.java
+++ b/src/com/platform/entities/Brick.java
@@ -1,110 +1,110 @@
-
-/**
- * 文件名 : Brick.java
- * 版权 : <版权/公司名>
- * 描述 : <描述>
- * @author chen
- * 版本 : <版本>
- * 修改时间: 2016年9月9日
- * 修改内容: <修改内容>
- */
-package com.platform.entities;
-
-/**
- * <一句话功能简述> volume 下的 块 对象
- * <功能详细描述>
- * @author chen
- * @version [版本号,2016年9月9日]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
-
-public class Brick {
-
- /** volume总大小 */
- private double availableSize;
-
- /** volume已使用大小 */
- private double usedSize;
-
- /** ip */
- private String ip;
-
- /** 路径 */
- private String path;
-
- /**
- * true 有连接, false: 失去连接
- */
- private boolean status;
-
- /**
- * @return the availableSize
- */
- public double getAvailableSize() {
- return availableSize;
- }
-
- /**
- * @param availableSize the availableSize to set
- */
- public void setAvailableSize(double availableSize) {
- this.availableSize = availableSize;
- }
-
- /**
- * @return the usedSize
- */
- public double getUsedSize() {
- return usedSize;
- }
-
- /**
- * @param usedSize the usedSize to set
- */
- public void setUsedSize(double usedSize) {
- this.usedSize = usedSize;
- }
-
- /**
- * @return the ip
- */
- public String getIp() {
- return ip;
- }
-
- /**
- * @param ip the ip to set
- */
- public void setIp(String ip) {
- this.ip = ip;
- }
-
- /**
- * @return the path
- */
- public String getPath() {
- return path;
- }
-
- /**
- * @param path the path to set
- */
- public void setPath(String path) {
- this.path = path;
- }
-
- /**
- * @return the status
- */
- public boolean isStatus() {
- return status;
- }
-
- /**
- * @param status the status to set
- */
- public void setStatus(boolean status) {
- this.status = status;
- }
-}
+
+/**
+ * 文件名 : Brick.java
+ * 版权 : <版权/公司名>
+ * 描述 : <描述>
+ * @author chen
+ * 版本 : <版本>
+ * 修改时间: 2016年9月9日
+ * 修改内容: <修改内容>
+ */
+package com.platform.entities;
+
+/**
+ * <一句话功能简述> volume 下的 块 对象
+ * <功能详细描述>
+ * @author chen
+ * @version [版本号,2016年9月9日]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+
+public class Brick {
+
+ /** volume总大小 */
+ private double availableSize;
+
+ /** volume已使用大小 */
+ private double usedSize;
+
+ /** ip */
+ private String ip;
+
+ /** 路径 */
+ private String path;
+
+ /**
+ * true 有连接, false: 失去连接
+ */
+ private boolean status;
+
+ /**
+ * @return the availableSize
+ */
+ public double getAvailableSize() {
+ return availableSize;
+ }
+
+ /**
+ * @param availableSize the availableSize to set
+ */
+ public void setAvailableSize(double availableSize) {
+ this.availableSize = availableSize;
+ }
+
+ /**
+ * @return the usedSize
+ */
+ public double getUsedSize() {
+ return usedSize;
+ }
+
+ /**
+ * @param usedSize the usedSize to set
+ */
+ public void setUsedSize(double usedSize) {
+ this.usedSize = usedSize;
+ }
+
+ /**
+ * @return the ip
+ */
+ public String getIp() {
+ return ip;
+ }
+
+ /**
+ * @param ip the ip to set
+ */
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ /**
+ * @return the path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * @param path the path to set
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ /**
+ * @return the status
+ */
+ public boolean isStatus() {
+ return status;
+ }
+
+ /**
+ * @param status the status to set
+ */
+ public void setStatus(boolean status) {
+ this.status = status;
+ }
+}
diff --git a/src/com/platform/entities/FolderNode.java b/src/com/platform/entities/FolderNode.java
index 5a9a56b7..e9bc91da 100644
--- a/src/com/platform/entities/FolderNode.java
+++ b/src/com/platform/entities/FolderNode.java
@@ -1,65 +1,65 @@
-package com.platform.entities;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class FolderNode {
- private String name;
- private int isFolder; // 1 is file and other integer is folder show children number
- private String path;
- private List childNodes = new ArrayList();
-
-
- public FolderNode() {
- // TODO Auto-generated constructor stub
- }
-
-
- public FolderNode(String name) {
- this.name = name;
- }
-
- public FolderNode(String name, int isFolder) {
- this.name = name;
- this.isFolder = isFolder;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the isFolder
- */
- public int getIsFolder() {
- return isFolder;
- }
-
- /**
- * @param isFolder the isFolder to set
- */
- public void setIsFolder(int isFolder) {
- this.isFolder = isFolder;
- }
-
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
- public List getChildNodes() {
- return childNodes;
- }
-
- public void setChildNodes(List childNodes) {
- this.childNodes = childNodes;
- }
-
-}
+package com.platform.entities;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class FolderNode {
+ private String name;
+ private int isFolder; // 1 is file and other integer is folder show children number
+ private String path;
+ private List childNodes = new ArrayList();
+
+
+ public FolderNode() {
+ // TODO Auto-generated constructor stub
+ }
+
+
+ public FolderNode(String name) {
+ this.name = name;
+ }
+
+ public FolderNode(String name, int isFolder) {
+ this.name = name;
+ this.isFolder = isFolder;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the isFolder
+ */
+ public int getIsFolder() {
+ return isFolder;
+ }
+
+ /**
+ * @param isFolder the isFolder to set
+ */
+ public void setIsFolder(int isFolder) {
+ this.isFolder = isFolder;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public List getChildNodes() {
+ return childNodes;
+ }
+
+ public void setChildNodes(List childNodes) {
+ this.childNodes = childNodes;
+ }
+
+}
diff --git a/src/com/platform/entities/VolumeEntity.java b/src/com/platform/entities/VolumeEntity.java
index d274af95..b562e9c1 100644
--- a/src/com/platform/entities/VolumeEntity.java
+++ b/src/com/platform/entities/VolumeEntity.java
@@ -1,164 +1,164 @@
-
-/**
- * 文件名 : VolumeEntity.java
- * 版权 : <版权/公司名>
- * 描述 : <描述>
- * @author chen
- * 版本 : <版本>
- * 修改时间: 2016年9月9日
- * 修改内容: <修改内容>
- */
-package com.platform.entities;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * <一句话功能简述> gfs的 volume 对象
- * <功能详细描述>
- * @author chen
- * @version [版本号,2016年9月9日]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
-
-public class VolumeEntity {
-
- /** volume总大小 */
- private double allSize;
-
- /** volume已使用大小 */
- private double usedSize;
-
- /** volume名称 */
- private String name;
-
- /** 挂载点 */
- private String path;
-
- /** * exist,正常返回状态Started,Stopped,Created */
- private boolean status;
-
- private String type;
-
- /** volume树形目录 */
- private List folder = new ArrayList();
-
- /** volume的 块 */
- private List brick = new ArrayList();
-
- /**
- * @return the allSize
- */
- public double getAllSize() {
- return allSize;
- }
-
- /**
- * @param allSize the allSize to set
- */
- public void setAllSize(double allSize) {
- this.allSize = allSize;
- }
-
- /**
- * @return the usedSize
- */
- public double getUsedSize() {
- return usedSize;
- }
-
- /**
- * @param usedSize the usedSize to set
- */
- public void setUsedSize(double usedSize) {
- this.usedSize = usedSize;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the path
- */
- public String getPath() {
- return path;
- }
-
- /**
- * @param path the path to set
- */
- public void setPath(String path) {
- this.path = path;
- }
-
-
- /**
- * @return the status
- */
- public boolean isStatus() {
- return status;
- }
-
- /**
- * @param status the status to set
- */
- public void setStatus(boolean status) {
- this.status = status;
- }
-
- /**
- * @return the type
- */
- public String getType() {
- return type;
- }
-
- /**
- * @param type the type to set
- */
- public void setType(String type) {
- this.type = type;
- }
-
- /**
- * @return the folder
- */
- public List getFolder() {
- return folder;
- }
-
- /**
- * @param folder the folder to set
- */
- public void setFolder(List folder) {
- this.folder = folder;
- }
-
- /**
- * @return the brick
- */
- public List getBrick() {
- return brick;
- }
-
- /**
- * @param brick the brick to set
- */
- public void setBrick(List brick) {
- this.brick = brick;
- }
-
-
-}
+
+/**
+ * 文件名 : VolumeEntity.java
+ * 版权 : <版权/公司名>
+ * 描述 : <描述>
+ * @author chen
+ * 版本 : <版本>
+ * 修改时间: 2016年9月9日
+ * 修改内容: <修改内容>
+ */
+package com.platform.entities;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <一句话功能简述> gfs的 volume 对象
+ * <功能详细描述>
+ * @author chen
+ * @version [版本号,2016年9月9日]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+
+public class VolumeEntity {
+
+ /** volume总大小 */
+ private double allSize;
+
+ /** volume已使用大小 */
+ private double usedSize;
+
+ /** volume名称 */
+ private String name;
+
+ /** 挂载点 */
+ private String path;
+
+ /** * exist,正常返回状态Started,Stopped,Created */
+ private boolean status;
+
+ private String type;
+
+ /** volume树形目录 */
+ private List folder = new ArrayList();
+
+ /** volume的 块 */
+ private List brick = new ArrayList();
+
+ /**
+ * @return the allSize
+ */
+ public double getAllSize() {
+ return allSize;
+ }
+
+ /**
+ * @param allSize the allSize to set
+ */
+ public void setAllSize(double allSize) {
+ this.allSize = allSize;
+ }
+
+ /**
+ * @return the usedSize
+ */
+ public double getUsedSize() {
+ return usedSize;
+ }
+
+ /**
+ * @param usedSize the usedSize to set
+ */
+ public void setUsedSize(double usedSize) {
+ this.usedSize = usedSize;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the path
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * @param path the path to set
+ */
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+
+ /**
+ * @return the status
+ */
+ public boolean isStatus() {
+ return status;
+ }
+
+ /**
+ * @param status the status to set
+ */
+ public void setStatus(boolean status) {
+ this.status = status;
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the folder
+ */
+ public List getFolder() {
+ return folder;
+ }
+
+ /**
+ * @param folder the folder to set
+ */
+ public void setFolder(List folder) {
+ this.folder = folder;
+ }
+
+ /**
+ * @return the brick
+ */
+ public List getBrick() {
+ return brick;
+ }
+
+ /**
+ * @param brick the brick to set
+ */
+ public void setBrick(List brick) {
+ this.brick = brick;
+ }
+
+
+}
diff --git a/src/com/platform/form/Bean2MapUtils.java b/src/com/platform/form/Bean2MapUtils.java
index 0f2ffc0a..e0ff907b 100644
--- a/src/com/platform/form/Bean2MapUtils.java
+++ b/src/com/platform/form/Bean2MapUtils.java
@@ -1,87 +1,87 @@
-package com.platform.form;
-
-import java.beans.BeanInfo;
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-
-public class Bean2MapUtils {
-
- /**
- * 将一个 Map 对象转化为一个 JavaBean
- * @param type 要转化的类型
- * @param map 包含属性值的 map
- * @return 转化出来的 JavaBean 对象
- * @throws IntrospectionException
- * 如果分析类属性失败
- * @throws IllegalAccessException
- * 如果实例化 JavaBean 失败
- * @throws InstantiationException
- * 如果实例化 JavaBean 失败
- * @throws InvocationTargetException
- * 如果调用属性的 setter 方法失败
- */
- public static Object convertMap(Class type, Map map)
- throws IntrospectionException, IllegalAccessException,
- InstantiationException, InvocationTargetException {
- BeanInfo beanInfo = Introspector.getBeanInfo(type); // 获取类属性
- Object obj = type.newInstance(); // 创建 JavaBean 对象
-
- // 给 JavaBean 对象的属性赋值
- PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
- for (int i = 0; i< propertyDescriptors.length; i++) {
- PropertyDescriptor descriptor = propertyDescriptors[i];
- String propertyName = descriptor.getName();
- try{
- if (map.containsKey(propertyName)) {
- // 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。
- Object value = map.get(propertyName);
-
- Object[] args = new Object[1];
- args[0] = value;
-
- descriptor.getWriteMethod().invoke(obj, args);
- }
- }
- catch(Exception e){
-
- }
- }
- return obj;
- }
-
- /**
- * 将一个 JavaBean 对象转化为一个 Map
- * @param bean 要转化的JavaBean 对象
- * @return 转化出来的 Map 对象
- * @throws IntrospectionException 如果分析类属性失败
- * @throws IllegalAccessException 如果实例化 JavaBean 失败
- * @throws InvocationTargetException 如果调用属性的 setter 方法失败
- */
- public static Map convertBean(Object bean)
- throws IntrospectionException, IllegalAccessException, InvocationTargetException {
- Class type = bean.getClass();
- Map returnMap = new HashMap();
- BeanInfo beanInfo = Introspector.getBeanInfo(type);
-
- PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
- for (int i = 0; i< propertyDescriptors.length; i++) {
- PropertyDescriptor descriptor = propertyDescriptors[i];
- String propertyName = descriptor.getName();
- if (!propertyName.equals("class")) {
- Method readMethod = descriptor.getReadMethod();
- Object result = readMethod.invoke(bean, new Object[0]);
- if (result != null) {
- returnMap.put(propertyName, result);
- } else {
- returnMap.put(propertyName, "");
- }
- }
- }
- return returnMap;
- }
-}
+package com.platform.form;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Bean2MapUtils {
+
+ /**
+ * 将一个 Map 对象转化为一个 JavaBean
+ * @param type 要转化的类型
+ * @param map 包含属性值的 map
+ * @return 转化出来的 JavaBean 对象
+ * @throws IntrospectionException
+ * 如果分析类属性失败
+ * @throws IllegalAccessException
+ * 如果实例化 JavaBean 失败
+ * @throws InstantiationException
+ * 如果实例化 JavaBean 失败
+ * @throws InvocationTargetException
+ * 如果调用属性的 setter 方法失败
+ */
+ public static Object convertMap(Class type, Map map)
+ throws IntrospectionException, IllegalAccessException,
+ InstantiationException, InvocationTargetException {
+ BeanInfo beanInfo = Introspector.getBeanInfo(type); // 获取类属性
+ Object obj = type.newInstance(); // 创建 JavaBean 对象
+
+ // 给 JavaBean 对象的属性赋值
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ for (int i = 0; i< propertyDescriptors.length; i++) {
+ PropertyDescriptor descriptor = propertyDescriptors[i];
+ String propertyName = descriptor.getName();
+ try{
+ if (map.containsKey(propertyName)) {
+ // 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。
+ Object value = map.get(propertyName);
+
+ Object[] args = new Object[1];
+ args[0] = value;
+
+ descriptor.getWriteMethod().invoke(obj, args);
+ }
+ }
+ catch(Exception e){
+
+ }
+ }
+ return obj;
+ }
+
+ /**
+ * 将一个 JavaBean 对象转化为一个 Map
+ * @param bean 要转化的JavaBean 对象
+ * @return 转化出来的 Map 对象
+ * @throws IntrospectionException 如果分析类属性失败
+ * @throws IllegalAccessException 如果实例化 JavaBean 失败
+ * @throws InvocationTargetException 如果调用属性的 setter 方法失败
+ */
+ public static Map convertBean(Object bean)
+ throws IntrospectionException, IllegalAccessException, InvocationTargetException {
+ Class type = bean.getClass();
+ Map returnMap = new HashMap();
+ BeanInfo beanInfo = Introspector.getBeanInfo(type);
+
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+ for (int i = 0; i< propertyDescriptors.length; i++) {
+ PropertyDescriptor descriptor = propertyDescriptors[i];
+ String propertyName = descriptor.getName();
+ if (!propertyName.equals("class")) {
+ Method readMethod = descriptor.getReadMethod();
+ Object result = readMethod.invoke(bean, new Object[0]);
+ if (result != null) {
+ returnMap.put(propertyName, result);
+ } else {
+ returnMap.put(propertyName, "");
+ }
+ }
+ }
+ return returnMap;
+ }
+}
diff --git a/src/com/platform/form/baseForm.java b/src/com/platform/form/baseForm.java
index 101230a7..264f7c84 100644
--- a/src/com/platform/form/baseForm.java
+++ b/src/com/platform/form/baseForm.java
@@ -1,55 +1,55 @@
-package com.platform.form;
-
-public class baseForm {
-
- private String id;
-
- private String name;
-
- private baseForm base;
-
- /**
- * @return the id
- */
- public String getId() {
- return id;
- }
-
- /**
- * @param id the id to set
- */
- public void setId(String id) {
- this.id = id;
- }
-
- /**
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * @param name the name to set
- */
- public void setName(String name) {
- this.name = name;
- }
-
- /**
- * @return the base
- */
- public baseForm getBase() {
- return base;
- }
-
- /**
- * @param base the base to set
- */
- public void setBase(baseForm base) {
- this.base = base;
- }
-
-
-
-}
+package com.platform.form;
+
+public class baseForm {
+
+ private String id;
+
+ private String name;
+
+ private baseForm base;
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the base
+ */
+ public baseForm getBase() {
+ return base;
+ }
+
+ /**
+ * @param base the base to set
+ */
+ public void setBase(baseForm base) {
+ this.base = base;
+ }
+
+
+
+}
diff --git a/src/com/platform/glusterfs/CheckoutMD5.java b/src/com/platform/glusterfs/CheckoutMD5.java
index 3e682198..33b5d3ad 100644
--- a/src/com/platform/glusterfs/CheckoutMD5.java
+++ b/src/com/platform/glusterfs/CheckoutMD5.java
@@ -1,103 +1,103 @@
-package com.platform.glusterfs;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import com.platform.utils.Constant;
-
-public class CheckoutMD5 {
- public static Logger log = Logger.getLogger(CheckoutMD5.class);
- String sourcePath;
- String destPath;
- String dataName;
- // String cmd_crateSourceMD5File="find "+sourcePath+dataName+"/app/ -type f
- // -print0 | xargs -0 md5sum | sort >"+deskPath+dataName+"_md5.txt";
- String cmd_getSourceMD5File;
- // String cmd_crateDestMD5File="find "+destPath+dataName+"/app/ -type f
- // -print0 | xargs -0 md5sum | sort >"+deskPath+dataName+"_md5.txt";
- String cmd_getDestMD5File;
- Map source_md5 = new HashMap();
- Map dest_md5 = new HashMap();
-
- public CheckoutMD5() {
- // TODO Auto-generated constructor stub
- }
-
- public CheckoutMD5(String sourcePath, String destPath, String dataName) {
- // TODO Auto-generated constructor stub
- this.sourcePath = sourcePath;
- this.destPath = destPath;
- this.dataName = dataName;
- 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 ";
- }
-
- /**
- * 文件夹校验 校验sourcePath和destPath是否完全相同,如果相同,返回1;
- * 如果不相同,返回0,如果获取文件MD5出错,返回-1;如何源文件不存在返回-2;目标文件不存在,返回-3;
- *
- * @param sourcePath
- * @param destPath
- * @return
- * @see [类、类#方法、类#成员]
- */
- public int checkoutMD5Folder(String sourcePath, String destPath) {
- log.info("start checkout md5 "+sourcePath+" and "+ destPath);
- List wrong_files = new ArrayList();
- String source_cmd = "find " + sourcePath + " -type f -print0 | xargs -0 md5sum";
- String dest_cmd = "find " + destPath + " -type f -print0 | xargs -0 md5sum";
- List sourceReStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(source_cmd);
- if (sourceReStrings == null || sourceReStrings.size() == 0) {
- log.error("get " + sourcePath + " MD5 error!");
- return -1;
- }
- if(sourceReStrings.get(0).contains(Constant.noSuchFile)){
- log.error(sourcePath+" is not exist!");
- return -2;
- }
- List destReStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(dest_cmd);
- if (destReStrings == null || destReStrings.size() == 0) {
- log.error("get " + destReStrings + " MD5 error!");
- return -1;
- }
- if(destReStrings.get(0).contains(Constant.noSuchFile)){
- log.error(destPath+" is not exist!");
- return -3;
- }
- Map source_md5 = new HashMap();
- Map dest_md5 = new HashMap();
- for (String line : sourceReStrings) {
- String[] lines = line.split(" ");
- String key = lines[1].replace(sourcePath, "").trim();
- String value = lines[0].trim();
- source_md5.put(key, value);
- }
- for (String line : destReStrings) {
- String[] lines = line.split(" ");
- String key = lines[1].replace(destPath, "").trim();
- String value = lines[0].trim();
- dest_md5.put(key, value);
- }
- for (Map.Entry mapEntry : source_md5.entrySet()) {
- if (!(dest_md5.containsKey(mapEntry.getKey())
- && dest_md5.get(mapEntry.getKey()).equals(mapEntry.getValue()))) {
-
- log.info(sourcePath + " and " + destPath + " is not same!");
- return 0;
- // System.out.println(mapEntry.getKey());
- }
-
- }
-
- log.info(sourcePath + " and " + destPath + " is same!");
- return 1;
- }
-
- public static void main(String[] args) {
- CheckoutMD5 checkoutMD5 = new CheckoutMD5();
- System.out.println(checkoutMD5.checkoutMD5Folder("/home/v1_copy","/home/ubuntu"));
- }
-}
+package com.platform.glusterfs;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import com.platform.utils.Constant;
+
+public class CheckoutMD5 {
+ public static Logger log = Logger.getLogger(CheckoutMD5.class);
+ String sourcePath;
+ String destPath;
+ String dataName;
+ // String cmd_crateSourceMD5File="find "+sourcePath+dataName+"/app/ -type f
+ // -print0 | xargs -0 md5sum | sort >"+deskPath+dataName+"_md5.txt";
+ String cmd_getSourceMD5File;
+ // String cmd_crateDestMD5File="find "+destPath+dataName+"/app/ -type f
+ // -print0 | xargs -0 md5sum | sort >"+deskPath+dataName+"_md5.txt";
+ String cmd_getDestMD5File;
+ Map source_md5 = new HashMap();
+ Map dest_md5 = new HashMap();
+
+ public CheckoutMD5() {
+ // TODO Auto-generated constructor stub
+ }
+
+ public CheckoutMD5(String sourcePath, String destPath, String dataName) {
+ // TODO Auto-generated constructor stub
+ this.sourcePath = sourcePath;
+ this.destPath = destPath;
+ this.dataName = dataName;
+ 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 ";
+ }
+
+ /**
+ * 文件夹校验 校验sourcePath和destPath是否完全相同,如果相同,返回1;
+ * 如果不相同,返回0,如果获取文件MD5出错,返回-1;如何源文件不存在返回-2;目标文件不存在,返回-3;
+ *
+ * @param sourcePath
+ * @param destPath
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public int checkoutMD5Folder(String sourcePath, String destPath) {
+ log.info("start checkout md5 "+sourcePath+" and "+ destPath);
+ List wrong_files = new ArrayList();
+ String source_cmd = "find " + sourcePath + " -type f -print0 | xargs -0 md5sum";
+ String dest_cmd = "find " + destPath + " -type f -print0 | xargs -0 md5sum";
+ List sourceReStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(source_cmd);
+ if (sourceReStrings == null || sourceReStrings.size() == 0) {
+ log.error("get " + sourcePath + " MD5 error!");
+ return -1;
+ }
+ if(sourceReStrings.get(0).contains(Constant.noSuchFile)){
+ log.error(sourcePath+" is not exist!");
+ return -2;
+ }
+ List destReStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(dest_cmd);
+ if (destReStrings == null || destReStrings.size() == 0) {
+ log.error("get " + destReStrings + " MD5 error!");
+ return -1;
+ }
+ if(destReStrings.get(0).contains(Constant.noSuchFile)){
+ log.error(destPath+" is not exist!");
+ return -3;
+ }
+ Map source_md5 = new HashMap();
+ Map dest_md5 = new HashMap();
+ for (String line : sourceReStrings) {
+ String[] lines = line.split(" ");
+ String key = lines[1].replace(sourcePath, "").trim();
+ String value = lines[0].trim();
+ source_md5.put(key, value);
+ }
+ for (String line : destReStrings) {
+ String[] lines = line.split(" ");
+ String key = lines[1].replace(destPath, "").trim();
+ String value = lines[0].trim();
+ dest_md5.put(key, value);
+ }
+ for (Map.Entry mapEntry : source_md5.entrySet()) {
+ if (!(dest_md5.containsKey(mapEntry.getKey())
+ && dest_md5.get(mapEntry.getKey()).equals(mapEntry.getValue()))) {
+
+ log.info(sourcePath + " and " + destPath + " is not same!");
+ return 0;
+ // System.out.println(mapEntry.getKey());
+ }
+
+ }
+
+ log.info(sourcePath + " and " + destPath + " is same!");
+ return 1;
+ }
+
+ public static void main(String[] args) {
+ CheckoutMD5 checkoutMD5 = new CheckoutMD5();
+ System.out.println(checkoutMD5.checkoutMD5Folder("/home/v1_copy","/home/ubuntu"));
+ }
+}
diff --git a/src/com/platform/glusterfs/ClusterInfo.java b/src/com/platform/glusterfs/ClusterInfo.java
index c73f0310..c7570558 100644
--- a/src/com/platform/glusterfs/ClusterInfo.java
+++ b/src/com/platform/glusterfs/ClusterInfo.java
@@ -1,153 +1,155 @@
-
-
-package com.platform.glusterfs;
-
-
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-
-import com.platform.utils.Constant;
-
-import ch.ethz.ssh2.Connection;
-
-/**
- * 获取集群信息
- * @author liliy
- * @version [版本号,2016年9月12日]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
-public class ClusterInfo {
- public static Logger log = Logger.getLogger(ClusterInfo.class);
-
- /**
- * 获取集群节点信息
- * 如果获取不正常,则返回null,如果获取正常,返回map表示节点ip和ip的状态
- * 如果ip在集群中且联通状态为PeerinCluster(Connected)
- * 如果ip在集群中且但不连通为PeerinCluster(Disconnected)
- * @return
- * @throws IOException
- * @see [类、类#方法、类#成员]
- */
- public Map showClusterInfo() {
-// log.info("get cluster info");
- Map peerIps = new HashMap();
- peerIps.put(Constant.hostIp, Constant.peerincluster_connected);
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(Constant.glusterPeerStatus);
- if (reStrings == null) {
- log.error("1101 command get result is null");
- 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).split(":")[0].contains("Number of Peers"))) {
- log.error("1103 get result string wrong");
- return null;
- }
-
-
- // System.out.print(reStrings.get(0));
-
- int flag = 0;
- String ipString = "";
- String state = "";
- for (Iterator it2 = reStrings.iterator(); it2.hasNext();) {
- String line = (String) it2.next();
- line=line.replaceAll(" +", " ");
- String keyValue[] = line.split(":");
- if (keyValue[0].equals("Hostname")) {
-
- 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")) {
-
- if (keyValue.length < 2) {
- log.error("1106 command get result is wrong");
- continue;
- }
-
- state = keyValue[1].replaceAll(" ", "");
- flag = 0;
- peerIps.put(ipString, state);
- }
-
- }
-
-// for (Map.Entry entry:peerIps.entrySet()){
-// String key=entry.getKey();
-// if(key.equals(Constant.hostIp)){
-// continue;
-// }
-// String value=entry.getValue();
-// if(Constant.ganymedSSH.otherConns==null){
-// Constant.ganymedSSH.otherConns=new HashMap();
-// }
-// if(!Constant.ganymedSSH.otherConns.containsKey(key)){
-// Connection connection=null;
-// try {
-// connection = Constant.ganymedSSH.getOpenedConnection(key, Constant.rootUser, Constant.rootPasswd, Constant.port);
-// } catch (IOException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-// Constant.ganymedSSH.otherConns.put(key,connection);
-// }
-// }
-
- return peerIps;
- }
-
- /**
- * 根据给定的ip获的ip的状态,即是否在集群中并联通
- * 如果ip不在集群中,返回null
- * 如果ip在集群中且联通状态为PeerinCluster(Connected)
- * 如果ip在集群中且但不连通为PeerinCluster(Disconnected)
- * @param peerip
- * @return
- * @see [类、类#方法、类#成员]
- */
- public String getPeerStatus(String peerip){
- Map peerIps=showClusterInfo();
- if(peerIps==null || peerIps.size()==0){
- return null;
- }
-
- if(peerip.equals(Constant.hostIp)){
- return Constant.peerincluster_connected;
- }
- if(!peerIps.containsKey(peerip)){
- return Constant.peerNotinCluster;
- }
- return peerIps.get(peerip);
- }
-
-
- public static void main(String[] args) {
-// PropertyConfigurator.configure("log4j.properties");
- System.out.println(new ClusterInfo().showClusterInfo());
- System.out.println(new ClusterInfo().getPeerStatus("192.168.0.116"));
- }
-}
-
-
+
+
+package com.platform.glusterfs;
+
+
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import com.platform.utils.Constant;
+import com.platform.utils.ProcessMyUtil;
+
+import ch.ethz.ssh2.Connection;
+
+/**
+ * 获取集群信息
+ * @author liliy
+ * @version [版本号,2016年9月12日]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public class ClusterInfo {
+ ProcessMyUtil proMy = new ProcessMyUtil();
+ public static Logger log = Logger.getLogger(ClusterInfo.class);
+
+ /**
+ * 获取集群节点信息
+ * 如果获取不正常,则返回null,如果获取正常,返回map表示节点ip和ip的状态
+ * 如果ip在集群中且联通状态为PeerinCluster(Connected)
+ * 如果ip在集群中且但不连通为PeerinCluster(Disconnected)
+ * @return
+ * @throws IOException
+ * @see [类、类#方法、类#成员]
+ */
+ public Map showClusterInfo() {
+// log.info("get cluster info");
+ Map peerIps = new HashMap();
+ peerIps.put(Constant.hostIp, Constant.peerincluster_connected);
+ List reStrings = proMy.execCmdWaitAcquiescent(Constant.glusterPeerStatus);
+ if (reStrings == null) {
+ log.error("1101 command get result is null");
+ 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).split(":")[0].contains("Number of Peers"))) {
+ log.error("1103 get result string wrong");
+ return null;
+ }
+
+
+ // System.out.print(reStrings.get(0));
+
+ int flag = 0;
+ String ipString = "";
+ String state = "";
+ for (Iterator it2 = reStrings.iterator(); it2.hasNext();) {
+ String line = (String) it2.next();
+ line=line.replaceAll(" +", " ");
+ String keyValue[] = line.split(":");
+ if (keyValue[0].equals("Hostname")) {
+
+ 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")) {
+
+ if (keyValue.length < 2) {
+ log.error("1106 command get result is wrong");
+ continue;
+ }
+
+ state = keyValue[1].replaceAll(" ", "");
+ flag = 0;
+ peerIps.put(ipString, state);
+ }
+
+ }
+
+// for (Map.Entry entry:peerIps.entrySet()){
+// String key=entry.getKey();
+// if(key.equals(Constant.hostIp)){
+// continue;
+// }
+// String value=entry.getValue();
+// if(Constant.ganymedSSH.otherConns==null){
+// Constant.ganymedSSH.otherConns=new HashMap();
+// }
+// if(!Constant.ganymedSSH.otherConns.containsKey(key)){
+// Connection connection=null;
+// try {
+// connection = Constant.ganymedSSH.getOpenedConnection(key, Constant.rootUser, Constant.rootPasswd, Constant.port);
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// Constant.ganymedSSH.otherConns.put(key,connection);
+// }
+// }
+
+ return peerIps;
+ }
+
+ /**
+ * 根据给定的ip获的ip的状态,即是否在集群中并联通
+ * 如果ip不在集群中,返回null
+ * 如果ip在集群中且联通状态为PeerinCluster(Connected)
+ * 如果ip在集群中且但不连通为PeerinCluster(Disconnected)
+ * @param peerip
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public String getPeerStatus(String peerip){
+ Map peerIps=showClusterInfo();
+ if(peerIps==null || peerIps.size()==0){
+ return null;
+ }
+
+ if(peerip.equals(Constant.hostIp)){
+ return Constant.peerincluster_connected;
+ }
+ if(!peerIps.containsKey(peerip)){
+ return Constant.peerNotinCluster;
+ }
+ return peerIps.get(peerip);
+ }
+
+
+ public static void main(String[] args) {
+// PropertyConfigurator.configure("log4j.properties");
+ System.out.println(new ClusterInfo().showClusterInfo());
+ System.out.println(new ClusterInfo().getPeerStatus("192.168.0.116"));
+ }
+}
+
+
diff --git a/src/com/platform/glusterfs/CopyData.java b/src/com/platform/glusterfs/CopyData.java
index fd774040..d99d6b65 100644
--- a/src/com/platform/glusterfs/CopyData.java
+++ b/src/com/platform/glusterfs/CopyData.java
@@ -1,143 +1,143 @@
-
-package com.platform.glusterfs;
-
-import java.util.List;
-
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.junit.Test;
-
-import com.platform.utils.Constant;
-
-
-/**
- * <一句话功能简述> 复制数据
- * <功能详细描述>
- * @author chen
- * @version [版本号,2016年9月8日]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
-
-public class CopyData {
- public static Logger log = Logger.getLogger(CopyData.class);
-
- public int copyVolumeFiles(String sourceVolumeName, String destVolumeName, String fileName) {
- log.info("start copy " + fileName + " from " + sourceVolumeName + " to " + destVolumeName);
- int status = -1;
- /**
- * get mount point of volumeName
- */
-
- String sourceFolderName = sourceVolumeName;
- String destFolderName = destVolumeName;
- status = copyFolderFilesAnyway(sourceFolderName, destFolderName, fileName);
- return status;
- }
-
- /**
- * 将sourceFolderName拷贝到destFolderName
- * 如果拷贝正常返回1,如果sourceFolderName不存在返回-2 ,如果destFolderName不存在返回-3
- * @param sourceFolderName
- * @param destFolderName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public int copyFolder(String sourceFolderName, String destFolderName) {
- createFolders(destFolderName);
- int progress=0;
- log.info("start copy " + sourceFolderName + " to " + destFolderName);
- ShowData showData=new ShowData();
- Map reStrings=showData.showFolderData(destFolderName);
- if(reStrings==null){
- log.info("3201 "+destFolderName+" is not exists");
- return -3;
- }
-
- reStrings=showData.showFolderData(sourceFolderName);
- if(reStrings==null){
- log.info("3202 "+sourceFolderName+" is not exists");
- return -2;
- }
- String command = "cp -rp " + sourceFolderName+" "+destFolderName;
-
- Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
-
- log.info("copy " + sourceFolderName + " to " + destFolderName + " running");
- return 1;
- }
-
- /**
- * -1 :error; -2: the filename is not exists ;-3 :destFolderName ; 1: right
- * not exists
- *
- * @param folderName
- * @param fileName
- * @return
- */
- public int copyFolderFiles(String sourceFolderName, String destFolderName, String fileName) {
- int progress=0;
- log.info("start copy " + fileName + " from " + sourceFolderName + " to " + destFolderName);
- ShowData showData=new ShowData();
- Map reStrings=showData.showFolderData(destFolderName);
- if(reStrings==null){
- log.info("3201 "+destFolderName+" is not exists");
- return -3;
- }
-
- reStrings=showData.showFolderData(sourceFolderName+"/"+fileName);
- if(reStrings==null){
- log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists");
- return -2;
- }
- String command = "cp -rp " + sourceFolderName + "/" + fileName+" "+destFolderName;
- /*
- * RunCommand runCommand = new RunCommand();
-
- List reStrings = runCommand.runCommandWait(command);
- */
- Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
-
- log.info("copy " + sourceFolderName +"/" + fileName+ " to " + destFolderName + " running");
- return 1;
- }
-
- /** 不管目的路径存在与否,强制拷贝
- * @param sourceFolderName
- * @param destFolderName
- * @param fileName
- * @return
- */
- public int copyFolderFilesAnyway(String sourceFolderName, String destFolderName, String fileName) {
- createFolders(destFolderName);
- int result = copyFolderFiles(sourceFolderName, destFolderName, fileName);
- return result;
- }
-
- public int createFolders(String folder){
- log.info("create "+folder);
- String splitFolder[]=folder.substring(1).split("/");
- String cmd="mkdir ";
- for(String one:splitFolder){
- cmd+="/"+one.replaceAll(" ", "");
- Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
- }
- return 1;
- }
-
- @Test
- public void testcreateFolders() {
-
- createFolders("/aaa/vvv/ddd/www/rrrr");
- }
-
- //@Test
- public void testCopyFolderFiles() {
-
- copyFolderFiles("/home", "/home/ubuntu", "system_data");
- }
-}
-
-
+
+package com.platform.glusterfs;
+
+import java.util.List;
+
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.junit.Test;
+
+import com.platform.utils.Constant;
+
+
+/**
+ * <一句话功能简述> 复制数据
+ * <功能详细描述>
+ * @author chen
+ * @version [版本号,2016年9月8日]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+
+public class CopyData {
+ public static Logger log = Logger.getLogger(CopyData.class);
+
+ public int copyVolumeFiles(String sourceVolumeName, String destVolumeName, String fileName) {
+ log.info("start copy " + fileName + " from " + sourceVolumeName + " to " + destVolumeName);
+ int status = -1;
+ /**
+ * get mount point of volumeName
+ */
+
+ String sourceFolderName = sourceVolumeName;
+ String destFolderName = destVolumeName;
+ status = copyFolderFilesAnyway(sourceFolderName, destFolderName, fileName);
+ return status;
+ }
+
+ /**
+ * 将sourceFolderName拷贝到destFolderName
+ * 如果拷贝正常返回1,如果sourceFolderName不存在返回-2 ,如果destFolderName不存在返回-3
+ * @param sourceFolderName
+ * @param destFolderName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public int copyFolder(String sourceFolderName, String destFolderName) {
+ createFolders(destFolderName);
+ int progress=0;
+ log.info("start copy " + sourceFolderName + " to " + destFolderName);
+ ShowData showData=new ShowData();
+ Map reStrings=showData.showFolderData(destFolderName);
+ if(reStrings==null){
+ log.info("3201 "+destFolderName+" is not exists");
+ return -3;
+ }
+
+ reStrings=showData.showFolderData(sourceFolderName);
+ if(reStrings==null){
+ log.info("3202 "+sourceFolderName+" is not exists");
+ return -2;
+ }
+ String command = "cp -rp " + sourceFolderName+" "+destFolderName;
+
+ Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
+
+ log.info("copy " + sourceFolderName + " to " + destFolderName + " running");
+ return 1;
+ }
+
+ /**
+ * -1 :error; -2: the filename is not exists ;-3 :destFolderName ; 1: right
+ * not exists
+ *
+ * @param folderName
+ * @param fileName
+ * @return
+ */
+ public int copyFolderFiles(String sourceFolderName, String destFolderName, String fileName) {
+ int progress=0;
+ log.info("start copy " + fileName + " from " + sourceFolderName + " to " + destFolderName);
+ ShowData showData=new ShowData();
+ Map reStrings=showData.showFolderData(destFolderName);
+ if(reStrings==null){
+ log.info("3201 "+destFolderName+" is not exists");
+ return -3;
+ }
+
+ reStrings=showData.showFolderData(sourceFolderName+"/"+fileName);
+ if(reStrings==null){
+ log.info("3202 "+sourceFolderName+"/"+fileName+" is not exists");
+ return -2;
+ }
+ String command = "cp -rp " + sourceFolderName + "/" + fileName+" "+destFolderName;
+ /*
+ * RunCommand runCommand = new RunCommand();
+
+ List reStrings = runCommand.runCommandWait(command);
+ */
+ Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
+
+ log.info("copy " + sourceFolderName +"/" + fileName+ " to " + destFolderName + " running");
+ return 1;
+ }
+
+ /** 不管目的路径存在与否,强制拷贝
+ * @param sourceFolderName
+ * @param destFolderName
+ * @param fileName
+ * @return
+ */
+ public int copyFolderFilesAnyway(String sourceFolderName, String destFolderName, String fileName) {
+ createFolders(destFolderName);
+ int result = copyFolderFiles(sourceFolderName, destFolderName, fileName);
+ return result;
+ }
+
+ public int createFolders(String folder){
+ log.info("create "+folder);
+ String splitFolder[]=folder.substring(1).split("/");
+ String cmd="mkdir ";
+ for(String one:splitFolder){
+ cmd+="/"+one.replaceAll(" ", "");
+ Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
+ }
+ return 1;
+ }
+
+ @Test
+ public void testcreateFolders() {
+
+ createFolders("/aaa/vvv/ddd/www/rrrr");
+ }
+
+ //@Test
+ public void testCopyFolderFiles() {
+
+ copyFolderFiles("/home", "/home/ubuntu", "system_data");
+ }
+}
+
+
diff --git a/src/com/platform/glusterfs/GetTreeData.java b/src/com/platform/glusterfs/GetTreeData.java
index d1274d15..48f5f826 100644
--- a/src/com/platform/glusterfs/GetTreeData.java
+++ b/src/com/platform/glusterfs/GetTreeData.java
@@ -1,123 +1,115 @@
-package com.platform.glusterfs;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Test;
-import com.platform.entities.FolderNode;
-import com.platform.utils.Constant;
-import com.platform.utils.FileOperateHelper;
-import com.platform.utils.GanymedSSH;
-
-/**
- * <一句话功能简述> 获得GFS某个目录下的子目录
- * <功能详细描述>
- * @author chen
- * @version [版本号,2016年9月8日]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
-public class GetTreeData {
- ShowData showData = new ShowData();
-
- /**
- * <一句话功能简述> 获得所以子目录
- * <功能详细描述>
- * @param name
- * @return
- * @see [类、类#方法、类#成员]
- */
- public FolderNode getDatas(String name) {
- String names[]=name.split("/");
- String only_name=names[names.length-1];
- FolderNode fileNode = new FolderNode(only_name);
- fileNode.setPath(name);
- Map files = showData.showFolderData(name);
- if(files==null || files.size()==0){
- return fileNode;
- }
- fileNode.setIsFolder(files.size());
- List list = new ArrayList();
- fileNode.setChildNodes(list);
- for (Map.Entry entry : files.entrySet()) {
- if(entry.getKey().equals("app")){
- continue;
- }
- int number = Integer.parseInt(entry.getValue());
- if (number == 1) {
- fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number));
- }
- if (number > 1) {
- FolderNode temp=getDatas(name+"/"+entry.getKey());
- fileNode.getChildNodes().add(temp);
- }
- }
-
- return fileNode;
- }
-
-
- /**
- * <一句话功能简述> 获得所以子目录
- * <功能详细描述>
- * @param name
- * @return
- * @see [类、类#方法、类#成员]
- */
- 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];
- FolderNode fileNode = new FolderNode(name);
- fileNode.setPath(name);
-
-// String shellComment= new FileOperateHelper().fileReaderAndendline(Constant.fileGetTreeData);
- String shellComment= Constant.strGetTreeData;
- String sh_path="/getTreedata.sh";
- String cmd="echo -e \""+shellComment+"\" > "+sh_path+" & chmod +x "+sh_path;
- Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
-// Map files = showData.showFolderData(name);
- List files=Constant.ganymedSSH.execCmdWaitAcquiescent(sh_path+" "+name);
- if(files==null){
- return null;
- }
- if(files.size()==0){
- return fileNode;
- }
- for(String file:files){
-
- }
-
- return fileNode;
- }
- @Test
- public void test_getTreeData() {
-
- GetTreeData getTreeData=new GetTreeData();
-// FolderNode fileOrFolder=getTreeData.getDatas("/home/gfs_ftp_point");
- FolderNode fileOrFolder=getTreeData.getDatasWithShell("/home/gfs_ftp_point/");
- System.out.println(fileOrFolder);
- }
-}
-/*
-class FileOrFolder {
- String name;
- int isFolder; // 1 is file and other integer is folder show children number
- List children;
-
- public FileOrFolder(String name) {
- // 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;
- }
-}
-
-*/
+package com.platform.glusterfs;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import net.sf.json.JSONObject;
+
+import org.junit.Test;
+
+import com.platform.entities.FolderNode;
+import com.platform.utils.Constant;
+import com.platform.utils.FileOperateHelper;
+import com.platform.utils.GanymedSSH;
+
+import freemarker.core._RegexBuiltins.replace_reBI;
+
+/**
+ * <一句话功能简述> 获得GFS某个目录下的子目录
+ * <功能详细描述>
+ * @author chen
+ * @version [版本号,2016年9月8日]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public class GetTreeData {
+ ShowData showData = new ShowData();
+
+ /**
+ * <一句话功能简述> 获得所以子目录
+ * <功能详细描述>
+ * @param name
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public FolderNode getDatas(String name) {
+ String names[]=name.split("/");
+ String only_name=names[names.length-1];
+ FolderNode fileNode = new FolderNode(only_name);
+ fileNode.setPath(name);
+ Map files = showData.showFolderData(name);
+ if(files==null || files.size()==0){
+ return fileNode;
+ }
+ fileNode.setIsFolder(files.size());
+ List list = new ArrayList();
+ fileNode.setChildNodes(list);
+ for (Map.Entry entry : files.entrySet()) {
+ if(entry.getKey().equals("app")){
+ continue;
+ }
+ int number = Integer.parseInt(entry.getValue());
+ if (number == 1) {
+ fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number));
+ }
+ if (number > 1) {
+ FolderNode temp=getDatas(name+"/"+entry.getKey());
+ fileNode.getChildNodes().add(temp);
+ }
+ }
+
+ return fileNode;
+ }
+
+
+ /**
+ * <一句话功能简述> 获得所以子目录
+ * <功能详细描述>
+ * @param name
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ 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];
+ FolderNode fileNode = new FolderNode(name);
+ fileNode.setPath(name);
+
+// String shellComment= new FileOperateHelper().fileReaderAndendline(Constant.fileGetTreeData);
+ String shellComment= Constant.strGetTreeData;
+ String sh_path="/getTreedata.sh";
+ String cmd="echo -e \""+shellComment+"\" > "+sh_path+" & chmod +x "+sh_path;
+ Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
+// Map files = showData.showFolderData(name);
+ List files=Constant.ganymedSSH.execCmdWaitAcquiescent(sh_path+" "+name);
+ if(files==null){
+ return null;
+ }
+ if(files.size()==0){
+ return fileNode;
+ }
+ for(String file:files){
+
+ }
+
+ return fileNode;
+ }
+ @Test
+ public void test_getTreeData() {
+
+ GetTreeData getTreeData=new GetTreeData();
+// FolderNode fileOrFolder=getTreeData.getDatas("/home/gfs_ftp_point");
+ FolderNode fileOrFolder=getTreeData.getDatasWithShell("/home/gfs_ftp_point/");
+ System.out.println(fileOrFolder);
+ }
+
+}
+
diff --git a/src/com/platform/glusterfs/RemoveData.java b/src/com/platform/glusterfs/RemoveData.java
index 6f854b26..e06cebd3 100644
--- a/src/com/platform/glusterfs/RemoveData.java
+++ b/src/com/platform/glusterfs/RemoveData.java
@@ -1,56 +1,56 @@
-package com.platform.glusterfs;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.junit.Test;
-
-import com.platform.utils.Constant;
-
-
-
-public class RemoveData {
-
- public static Logger log = Logger.getLogger ( RemoveData.class);
-
-
- /**
- * -1 :error; 0: the filename is not exists ; 1: right
- * @param folderName
- * @param fileName
- * @return
- */
- public int deleteFolder(String folderName){
- log.info("start delete "+folderName);
-
- ShowData showData=new ShowData();
- Map reStrings=showData.showFolderData(folderName);
-
- if(reStrings==null){
- log.error("3301 "+folderName+" is not exists");
- return -1;
- }
-
- String command="rm -r "+folderName;
-
-// int status=runCommand.runCommand(command);
- Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
-
- log.info("delete "+folderName+" running");
- return 1;
- }
-
-
-
-
- @Test
- public void testDeleteFolderFiles() {
- PropertyConfigurator.configure("log4j.properties");
- deleteFolder("/home/ubuntu");
- }
-
-}
+package com.platform.glusterfs;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.junit.Test;
+
+import com.platform.utils.Constant;
+
+
+
+public class RemoveData {
+
+ public static Logger log = Logger.getLogger ( RemoveData.class);
+
+
+ /**
+ * -1 :error; 0: the filename is not exists ; 1: right
+ * @param folderName
+ * @param fileName
+ * @return
+ */
+ public int deleteFolder(String folderName){
+ log.info("start delete "+folderName);
+
+ ShowData showData=new ShowData();
+ Map reStrings=showData.showFolderData(folderName);
+
+ if(reStrings==null){
+ log.error("3301 "+folderName+" is not exists");
+ return -1;
+ }
+
+ String command="rm -r "+folderName;
+
+// int status=runCommand.runCommand(command);
+ Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
+
+ log.info("delete "+folderName+" running");
+ return 1;
+ }
+
+
+
+
+ @Test
+ public void testDeleteFolderFiles() {
+ PropertyConfigurator.configure("log4j.properties");
+ deleteFolder("/home/ubuntu");
+ }
+
+}
diff --git a/src/com/platform/glusterfs/SetCluster.java b/src/com/platform/glusterfs/SetCluster.java
index 8f260e5a..598b8753 100644
--- a/src/com/platform/glusterfs/SetCluster.java
+++ b/src/com/platform/glusterfs/SetCluster.java
@@ -1,67 +1,67 @@
-
-package com.platform.glusterfs;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.hamcrest.core.Is;
-
-import com.platform.utils.Constant;
-import com.platform.utils.Support;
-
-public class SetCluster {
- public static Logger log = Logger.getLogger ( SetCluster.class);
-
- /**
- * 向集群中添加节点
- * 返回1表示添加成功;-1表示ip不合法,-2 表示出错,0表示添加失败
- * @param peerip
- * @return
- * @see [类、类#方法、类#成员]
- */
- public int probePeer(String peerip){
- if(!Support.checkIP(peerip)){
- log.error(peerip +"is illegal!" );
- return -1;
- }
- String cmd="gluster peer probe "+peerip;
- List reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
- if(reStrings==null || reStrings.size()==0){
- log.error("detach error! ");
- return -2;
- }
- if(reStrings.contains(Constant.success)){
- log.info("probe success!");
- return 1;
- }
- log.info("probe failed!");
- return 0;
- }
-
- /**
- * 删除集群中节点
- * 返回1表示删除成功;-1表示ip不合法,-2 表示出错,0表示添加失败
- * @param peerip
- * @return
- * @see [类、类#方法、类#成员]
- */
- public int detachPeer(String peerip){
- if(!Support.checkIP(peerip)){
- log.error(peerip +"is illegal!" );
- return -1;
- }
- String cmd="gluster peer detach "+peerip;
- List reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
- if(reStrings==null || reStrings.size()==0){
- log.error("detach error! ");
- return -2;
- }
- if(reStrings.contains(Constant.success)){
- log.info("detach success!");
- return 1;
- }
- log.info("detach failed!");
- return 0;
- }
-}
-
+
+package com.platform.glusterfs;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.hamcrest.core.Is;
+
+import com.platform.utils.Constant;
+import com.platform.utils.Support;
+
+public class SetCluster {
+ public static Logger log = Logger.getLogger ( SetCluster.class);
+
+ /**
+ * 向集群中添加节点
+ * 返回1表示添加成功;-1表示ip不合法,-2 表示出错,0表示添加失败
+ * @param peerip
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public int probePeer(String peerip){
+ if(!Support.checkIP(peerip)){
+ log.error(peerip +"is illegal!" );
+ return -1;
+ }
+ String cmd="gluster peer probe "+peerip;
+ List reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
+ if(reStrings==null || reStrings.size()==0){
+ log.error("detach error! ");
+ return -2;
+ }
+ if(reStrings.contains(Constant.success)){
+ log.info("probe success!");
+ return 1;
+ }
+ log.info("probe failed!");
+ return 0;
+ }
+
+ /**
+ * 删除集群中节点
+ * 返回1表示删除成功;-1表示ip不合法,-2 表示出错,0表示添加失败
+ * @param peerip
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public int detachPeer(String peerip){
+ if(!Support.checkIP(peerip)){
+ log.error(peerip +"is illegal!" );
+ return -1;
+ }
+ String cmd="gluster peer detach "+peerip;
+ List reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
+ if(reStrings==null || reStrings.size()==0){
+ log.error("detach error! ");
+ return -2;
+ }
+ if(reStrings.contains(Constant.success)){
+ log.info("detach success!");
+ return 1;
+ }
+ log.info("detach failed!");
+ return 0;
+ }
+}
+
diff --git a/src/com/platform/glusterfs/SetVolume.java b/src/com/platform/glusterfs/SetVolume.java
index 2d3858de..6d9fc1e2 100644
--- a/src/com/platform/glusterfs/SetVolume.java
+++ b/src/com/platform/glusterfs/SetVolume.java
@@ -1,540 +1,540 @@
-
-/**
- * @author 李乾坤
- * 进行volume的一系列操作,如创建、开启停止volume,为volume添加或删除brick
- */
-package com.platform.glusterfs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.junit.Test;
-
-import com.platform.utils.Constant;
-
-public class SetVolume {
- public static Logger log = Logger.getLogger(SetVolume.class);
-
- /**
- * 创建volume 返回值:创建并挂载成功 1 1:可以创建 ;-1:brick的ip不在集群中或者未连接; -2 -3
- * -4:类型与brick数目不匹配 ; -5 :volumeName 已经存在;-6:挂载点存在且不为空,不能作为挂载点; -7:未知错误
- *
- * @param volumeName
- * @param count
- * @param type
- * @param bricks
- * @param mountPoint
- * @return
- * @see [类、类#方法、类#成员]
- */
- public int createVolume(String volumeName, int count, String type, List bricks, String mountPoint) {
- log.info("Creat new volume");
-
- // 判断创建volume的条件是否满足
- int able = isAbleCreateVolume(volumeName, count, type, bricks, mountPoint);
-
- if (able == 1) {
- String command = null;
- // 将brics从List变量中提取出来并连接成可以在命令行中使用的格式
- String commandarg = concat(bricks);
-
- /*
- * verify the type
- */
- if (type.equals(Constant.distributed)) {
- command = "gluster volume create " + volumeName + " " + commandarg + "force";
- } else if (type.equals(Constant.replica) || type.equals(Constant.stripe)) {
- command = "gluster volume create " + volumeName + " " + type + " " + count + " " + commandarg + "force";
- }
-
- // 执行命令
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
-
- // 创建成功时返回信息格式:volume create: volumename success:
- if (reStrings == null || reStrings.size() == 0) {
- log.error("3106 " + command + " run return error");
- return -7;
- }
- if (reStrings.get(0).contains("volume create: " + volumeName + ": " + "success:")) {
- log.info("create volume " + volumeName + " successed!");
- // 创建成功则启动并进行挂载
- if (startVolume(volumeName) == 0) {
- log.info("start volume " + volumeName + " successed!");
-
- log.info("create "+mountPoint);
- new CopyData().createFolders(mountPoint);
-
- // 进行挂载
- String command3 = "mount -t glusterfs " + Constant.hostIp + ":" + volumeName + " " + mountPoint;
- List reStrings3 = Constant.ganymedSSH.execCmdWaitAcquiescent(command3);
-
- if (reStrings3.size() == 0 || reStrings.get(0).contains("GlusterFS is already mounted")) {
- log.info("mount point successed!");
- String addRecord = "echo \"" + volumeName + ":" + mountPoint + "\" >> " + Constant.MountRecord;
- Constant.ganymedSSH.execCmdNoWaitAcquiescent(addRecord);
- return 1;
- }
- }
- } else {
- log.error("3104 volume create failed with error" + reStrings.get(0));
- // System.out.println(reStrings.get(0));
- return -7;
- }
- return 1;
- } else {
- log.error("给出的参数不满足创建条件");
- // System.out.println("给出的参数不满足创建条件");
- return able;
- }
-
- }
-
- /**
- * 删除volume 1 表示成功 ;-1表示volume name不存在;-2表示停止volume 失败;
- * -3表示删除失败,-4表示/gfsAutoMount/mountPoint.record文件不存在
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public int deleteVolume(String volumeName) {
- int status = 0;
- VolumeInfo volumeInfo = new VolumeInfo();
- List volumeNames = volumeInfo.showAllVolumeName();
- if (!volumeNames.contains(volumeName)) {
- log.error("3801 " + volumeName + " is not exists !");
- return -1;
- }
-
- List mountPoints = volumeInfo.getVolumeMountPoint(volumeName);
-
- String cmd = "cat " + Constant.MountRecord;
- List mountRecord = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
-
- if (stopVolume(volumeName) != 0) {
-
- return -2;
- }
-
- String command = "echo -e \"y\"| gluster volume delete " + volumeName;
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
- if (reStrings == null || reStrings.size() == 0
- || !(reStrings.get(0).contains("volume delete: " + volumeName + ": success"))) {
- log.error("3803 : delete volume " + volumeName + " failed !");
- return -3;
- }
- log.info("delete " + volumeName + " successed!");
- if (mountRecord.size() != 0 && mountPoints.get(0).contains(Constant.noSuchFile)) {
- log.error("3804 : " + Constant.MountRecord + " is not exits");
- return -4;
- }
- for (String mountPoint : mountPoints) {
- command = "umount -l " + mountPoint;
- Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
- log.info("umount " + mountPoint + " successed!");
- String oneRecord=volumeName+":"+mountPoint;
- if (mountRecord.contains(oneRecord)) {
- mountRecord.remove(oneRecord);
- }
-
- }
- String newRecords="";
- for(String one:mountRecord){
- newRecords+=one+"\n";
- }
- command="echo -ne \""+newRecords+"\" > "+Constant.MountRecord;
- Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
- return 1;
- }
-
- /**
- * 为指定的volume添加brick,参数中需要指定类型、数量等 返回值:1成功 ;其他失败
- * 过程中需要先检查volume是否存在,还需检查给出的brick数量与类型、count是否相符
- *
- * @param volumeName
- * @param brickName
- * @param count
- * @param type
- * @return
- * @see [类、类#方法、类#成员]
- */
- public int addBrickVolume(String volumeName, List brickName, int count, String type) {
- // 检查是否满足添加bricks的条件
- int able = isAble(volumeName, count, type, brickName);
- if (able != 1) {
- return able;
- }
-
- String command = "";
- log.info("add brick to the specified volume");
-
- String brick = concat(brickName);
-
- if (type.equals(Constant.distributed))
- command = "gluster volume add-brick " + volumeName + " " + brick + "force";
- else if (type.equals(Constant.replica))
- command = "gluster volume add-brick " + volumeName + " " + "replica " + count + " " + brick + "force";
- else if (type.equals(Constant.stripe))
- command = "gluster volume add-brick " + volumeName + " " + "stripe " + count + " " + brick + "force";
-
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
-
- // 添加成功的返回信息是:volume add-brick: success
- if (reStrings != null && reStrings.size() > 0 && reStrings.get(0).contains("volume add-brick: success")) {
- log.info("添加brick成功!");
- return 1;
- } else {
- log.error("3205 add brick failed,please check the system");
- // System.out.println("3202 add brick failed,please check the
- // system");
- return -5;
- }
- }
-
- /**
- * 为指定的volume删除brick,参数中需要指定类型、数量等 返回值:1 成功 ;其他 失败
- * 过程中需要先检查volume是否存在,还需检查给出的brick数量与类型、count是否相符
- *
- * @param volumeName
- * @param brickName
- * @param count
- * @param type
- * @return
- * @see [类、类#方法、类#成员]
- */
- public int deleteBrickVolume(String volumeName, List brickName, int count, String type) {
- int able = isAble(volumeName, count, type, brickName);
-
- if (able != 1) {
- return able;
- }
- String command = null;
-
- log.info("delete brick of the specified volume");
-
- String brick = concat(brickName);
-
- if (type.equals(Constant.distributed)) {
- command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " " + brick + " force";
- } else if (type.equals(Constant.replica)) {
- command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " repli " + count + " " + brick
- + " force";
- } else if (type.equals(Constant.stripe)) {
- command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " stripe " + count + " " + brick
- + " force";
- }
-
- if (command == null) {
- log.error("3305 remove brick failed,please check the system");
- return -5;
- }
- log.info("即将执行删除命令");
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
- // System.out.println(reStrings);
- log.info("删除命令执行完毕");
-
- // 删除成功的返回信息是“volume remove-brick: success”
- if (reStrings.get(0).contains("volume remove-brick: success")) {
- {
- log.info("删除brick成功");
- return 1;
- }
- } else {
- log.error("3305 remove brick failed,please check the system");
-
- return -5;
- }
-
- }
-
- /*
- * 停止指定volume 参数中需给出volume的名字 返回值: 0 成功 -1 失败
- * 需要先检查volume是否存在,然后判断volume的状态是否已经是停止状态
- */
- public int stopVolume(String volumeName) {
- log.info("stop volume");
-
- // 首先需要判断volume是否存在,调用其他函数返回所有volume的名字
- boolean volumeExist = false;
-
- List volume = new VolumeInfo().showAllVolumeName();
- for (String temp : volume) {
- if (temp.equals(volumeName)) {
- volumeExist = true;
- break;
- }
- }
-
- if (!volumeExist) {
- // volume不存在
- log.error("3501 the volume doesnot exist");
- System.out.println("3501 the volume doesnot exist");
- return -1;
- } else {
- // volume存在,则需判断volume的状态是否已经为“stop”
- if (new VolumeInfo().getVolumeStatus(volumeName).equals("Stopped")) {
- log.error("3502 the volume is already stoped");
- System.out.println("3502 the volume is already stoped");
- return 0;
- } else {
- String command = "echo -e \"y\"| gluster volume stop " + volumeName;
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
-
- // 标记操作结果:operation = 1 操作成功
- // operation = 0 操作失败
- int operation = 0;
- for (String temp2 : reStrings) {
- if (temp2.contains("volume stop: " + volumeName + ": " + "success")) {
- operation = 1;
- break;
- }
- System.out.println("operation: " + operation);
- }
-
- if (operation == 1) {
- return 0;
- } else {
- log.error("3503 stop " + volumeName + " failed");
- System.out.println("3503 stop " + volumeName + " failed");
- return -1;
- }
-
- }
- }
- }
-
- /*
- * 开启指定volume 参数中需给出volume的名字 返回值: 0 成功 -1 失败
- * 需要先检查volume是否存在,然后判断volume的状态是否已经是开启状态
- */
- public int startVolume(String volumeName) {
- log.info("start volume");
- boolean volumeExist = false;
- List volume = new VolumeInfo().showAllVolumeName();
-
- for (String temp : volume) {
- if (temp.equals(volumeName)) {
- volumeExist = true;
- break;
- }
- }
-
- if (volumeExist) {
- if (!(new VolumeInfo().getVolumeStatus(volumeName).equals("Started"))) {
- String command = "gluster volume start " + volumeName;
-
- int operation = 0;
-
- // 执行命令
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
- for (String temp2 : reStrings) {
- if (temp2.equals("volume start: " + volumeName + ": " + "success")) {
- operation = 1;
- }
- }
-
- if (operation == 1) {
- return 0;
- } else {
- log.error("3602 start volume failed");
- System.out.println("3602 start volume failed");
- return -1;
- }
- } else {
- log.error("volume已经开启");
- System.out.println("volume已经开启");
- return -1;
- }
- } else {
- log.error("3601 the volume does not exist");
- // System.out.println("3601 the volume does not exist");
- return -1;
- }
- }
-
- // 需要将存于List变量中的brick的位置组装成可以在glusterfs命令行中直接使用的格式
- public String concat(List brickName) {
- StringBuffer result = new StringBuffer();
- int len = brickName.size();
- for (int i = 0; i < len; i++) {
- result.append(brickName.get(i));
- result.append(" ");
- }
- return result.toString();
- }
-
- /*
- * 只在创建volume时使用此函数 创建volume时对不同数据卷,brick的数量需要满足和count的关系
- * 首先判断它们是否满足关系,在不满足的关系的情况下是肯定无法完成操作的 1:可以创建 ;-1:brick的ip不在集群中或者未连接; -2 -3
- * -4 :类型与brick数目不匹配 ; -5 :volumeName 已经存在;-6:挂载点存在且不为空,不能作为挂载点; -7:未知错误
- */
- public int isAbleCreateVolume(String volumeName, int count, String type, List bricks, String mountPoint) {
- int status = 0;
-
- int length = bricks.size();
-
- if (type.equals(Constant.distributed)) {
- if (count != 0) {
- log.error("3101 the kind of distributed requires the arg of count to be 0");
- return -2;
- }
- }
- if (type.equals(Constant.stripe)) {
- if (length % count != 0) {
- log.error("3102 the number of bricks should be the same as or the times of the stripe count");
- return -3;
- }
- }
- if (type.equals(Constant.replica)) {
- if ((length % count) != 0) {
- log.error(
- "3103 the number of bricks should be the same as the replicate count or the times of replicate count");
- return -4;
- }
- }
-
- Map peer_status = new ClusterInfo().showClusterInfo();
- peer_status.put(Constant.hostIp, Constant.peerincluster_connected);
- for (String brick : bricks) {
- brick = brick.split(":")[0];
- if (!(peer_status.containsKey(brick) && peer_status.get(brick).equals(Constant.peerincluster_connected))) {
- log.error("3105 birck " + brick + " ip is not in cluster");
- return -1;
- }
-
- }
-
- List volumeNames = new VolumeInfo().showAllVolumeName();
- if (volumeNames == null) {
- log.error("3108 showAllVolumeName return error");
- return -7;
- }
- if (volumeNames.contains(volumeName)) {
- log.error("3106 " + volumeName + " is already exists! ");
- return -5;
- }
-
- /*
- Map datas = new ShowData().showFolderData(mountPoint);
- if (datas != null && datas.size() > 0) {
- log.error("3107 " + mountPoint + " is not exists or not empty ! ");
- return -6;
- }
- */
- return 1;
- }
-
- /**
- * 添加或删除volume的brick时,首先需要判断volume是否存在,然后需要判断volume类型、count及brick数目
- *
- * @param volumeName
- * @param count
- * @param type
- * @param bricks
- * @return 1 满足条件,可以添加;-1 :volume name is not exists;-2,-3,-4 类型与brick数量不匹配;
- */
- public int isAble(String volumeName, int count, String type, List bricks) {
- List volumeNames = new VolumeInfo().showAllVolumeName();
-
- if (!volumeNames.contains(volumeName)) {
- log.error("3201:" + volumeName + " is not exists! ");
- return -1;
- }
-
- int length = bricks.size();
- if (type.equals("distribute")) {
- if (count == 0)
- return 1;
- else {
- log.error("3202: the kind of distributed requires the arg of count to be 0");
- // System.out.println(" the kind of distributed requires the
- // arg of count to be 0");
- return -2;
- }
- }
-
- if (type.equals("stripe")) {
- if (length % count == 0)
- return 1;
- else {
- log.error("3203: the number of bricks should be the same as or the times of the stripe count");
- // System.out.println(" the number of bricks should be the
- // same as or the times of the stripe count");
- return -3;
-
- }
- }
- if (type.equals("replicate")) {
- if ((length % count) == 0)
- return 1;
- else {
- log.error(
- "3204: the number of bricks should be the same as the replicate count or the times of replicate count");
-
- return -4;
- }
- }
-
- return 1;
- }
-
- @Test
- public void test_deleteVolume(){
- System.out.println(deleteVolume("lili_test1"));
- }
-// @Test
- public void test_createVolume(){
- List bricksToCreate = new ArrayList();
- bricksToCreate.add("192.168.0.110:/lili_test1");
- bricksToCreate.add("192.168.0.116:/lili_test1");
- System.out.println(createVolume("lili_test1", 0, "distributed", bricksToCreate, "/home/lili_test1_point"));
- }
- public static void main(String[] args) {
- SetVolume setVolume = new SetVolume();
- int operation = 0;
- // PropertyConfigurator.configure("log4j.properties");
- // TODO Auto-generated method stub
- // 测试创建volume的代码
-
-// List bricksToCreate = new ArrayList();
-// bricksToCreate.add("192.168.0.110:/v2");
-// bricksToCreate.add("192.168.0.116:/v2");
-// operation = setVolume.createVolume("v2", 0, "distributed", bricksToCreate, "/home/v2_point");
- // operation = setVolume.deleteVolume("v3");
- //
- // // 以下是测试添加brick的代码
- //
- // List bricksToAdd = new ArrayList();
- // bricksToAdd.add("192.168.191.23:/v3");
- // operation = setVolume.addBrickVolume("v3", bricksToAdd, 0,
- // "distribute");
- // System.out.println(operation);
-
- // 以下代码是测试删除brick的代码
- // List bricksToAdd= new ArrayList();
- // bricksToAdd.add("192.168.191.23:/v3");
- // operation =
- // setVolume.deleteBrickVolume("v3",bricksToAdd,0,"distribute");
- // System.out.println(operation);
- // 以下是测试start volume的代码
- // String volumeToStart = "testcreate" ;
- // int startOperation = startVolume(volumeToStart);
- // System.out.println(startOperation);
- // 以下是测试stop volume
- String volumeToStop = "v3";
- // int startOperation = setVolume.stopVolume(volumeToStop);
- // 以下是测试创建volume并完成挂载的代码
- // List bricksToCreate= new ArrayList();
- // bricksToCreate.add("192.168.214.135:/home/create");
- // bricksToCreate.add("192.168.214.138:/home/create");
- //
- // int operation =
- // createVolume("createAndmount",0,"distribute",bricksToCreate,"/mnt/create");
- // System.out.println(operation);
- }
-}
+
+/**
+ * @author 李乾坤
+ * 进行volume的一系列操作,如创建、开启停止volume,为volume添加或删除brick
+ */
+package com.platform.glusterfs;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.junit.Test;
+
+import com.platform.utils.Constant;
+
+public class SetVolume {
+ public static Logger log = Logger.getLogger(SetVolume.class);
+
+ /**
+ * 创建volume 返回值:创建并挂载成功 1 1:可以创建 ;-1:brick的ip不在集群中或者未连接; -2 -3
+ * -4:类型与brick数目不匹配 ; -5 :volumeName 已经存在;-6:挂载点存在且不为空,不能作为挂载点; -7:未知错误
+ *
+ * @param volumeName
+ * @param count
+ * @param type
+ * @param bricks
+ * @param mountPoint
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public int createVolume(String volumeName, int count, String type, List bricks, String mountPoint) {
+ log.info("Creat new volume");
+
+ // 判断创建volume的条件是否满足
+ int able = isAbleCreateVolume(volumeName, count, type, bricks, mountPoint);
+
+ if (able == 1) {
+ String command = null;
+ // 将brics从List变量中提取出来并连接成可以在命令行中使用的格式
+ String commandarg = concat(bricks);
+
+ /*
+ * verify the type
+ */
+ if (type.equals(Constant.distributed)) {
+ command = "gluster volume create " + volumeName + " " + commandarg + "force";
+ } else if (type.equals(Constant.replica) || type.equals(Constant.stripe)) {
+ command = "gluster volume create " + volumeName + " " + type + " " + count + " " + commandarg + "force";
+ }
+
+ // 执行命令
+ List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
+
+ // 创建成功时返回信息格式:volume create: volumename success:
+ if (reStrings == null || reStrings.size() == 0) {
+ log.error("3106 " + command + " run return error");
+ return -7;
+ }
+ if (reStrings.get(0).contains("volume create: " + volumeName + ": " + "success:")) {
+ log.info("create volume " + volumeName + " successed!");
+ // 创建成功则启动并进行挂载
+ if (startVolume(volumeName) == 0) {
+ log.info("start volume " + volumeName + " successed!");
+
+ log.info("create "+mountPoint);
+ new CopyData().createFolders(mountPoint);
+
+ // 进行挂载
+ String command3 = "mount -t glusterfs " + Constant.hostIp + ":" + volumeName + " " + mountPoint;
+ List reStrings3 = Constant.ganymedSSH.execCmdWaitAcquiescent(command3);
+
+ if (reStrings3.size() == 0 || reStrings.get(0).contains("GlusterFS is already mounted")) {
+ log.info("mount point successed!");
+ String addRecord = "echo \"" + volumeName + ":" + mountPoint + "\" >> " + Constant.MountRecord;
+ Constant.ganymedSSH.execCmdNoWaitAcquiescent(addRecord);
+ return 1;
+ }
+ }
+ } else {
+ log.error("3104 volume create failed with error" + reStrings.get(0));
+ // System.out.println(reStrings.get(0));
+ return -7;
+ }
+ return 1;
+ } else {
+ log.error("给出的参数不满足创建条件");
+ // System.out.println("给出的参数不满足创建条件");
+ return able;
+ }
+
+ }
+
+ /**
+ * 删除volume 1 表示成功 ;-1表示volume name不存在;-2表示停止volume 失败;
+ * -3表示删除失败,-4表示/gfsAutoMount/mountPoint.record文件不存在
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public int deleteVolume(String volumeName) {
+ int status = 0;
+ VolumeInfo volumeInfo = new VolumeInfo();
+ List volumeNames = volumeInfo.showAllVolumeName();
+ if (!volumeNames.contains(volumeName)) {
+ log.error("3801 " + volumeName + " is not exists !");
+ return -1;
+ }
+
+ List mountPoints = volumeInfo.getVolumeMountPoint(volumeName);
+
+ String cmd = "cat " + Constant.MountRecord;
+ List mountRecord = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
+
+ if (stopVolume(volumeName) != 0) {
+
+ return -2;
+ }
+
+ String command = "echo -e \"y\"| gluster volume delete " + volumeName;
+ List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
+ if (reStrings == null || reStrings.size() == 0
+ || !(reStrings.get(0).contains("volume delete: " + volumeName + ": success"))) {
+ log.error("3803 : delete volume " + volumeName + " failed !");
+ return -3;
+ }
+ log.info("delete " + volumeName + " successed!");
+ if (mountRecord.size() != 0 && mountPoints.get(0).contains(Constant.noSuchFile)) {
+ log.error("3804 : " + Constant.MountRecord + " is not exits");
+ return -4;
+ }
+ for (String mountPoint : mountPoints) {
+ command = "umount -l " + mountPoint;
+ Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
+ log.info("umount " + mountPoint + " successed!");
+ String oneRecord=volumeName+":"+mountPoint;
+ if (mountRecord.contains(oneRecord)) {
+ mountRecord.remove(oneRecord);
+ }
+
+ }
+ String newRecords="";
+ for(String one:mountRecord){
+ newRecords+=one+"\n";
+ }
+ command="echo -ne \""+newRecords+"\" > "+Constant.MountRecord;
+ Constant.ganymedSSH.execCmdNoWaitAcquiescent(command);
+ return 1;
+ }
+
+ /**
+ * 为指定的volume添加brick,参数中需要指定类型、数量等 返回值:1成功 ;其他失败
+ * 过程中需要先检查volume是否存在,还需检查给出的brick数量与类型、count是否相符
+ *
+ * @param volumeName
+ * @param brickName
+ * @param count
+ * @param type
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public int addBrickVolume(String volumeName, List brickName, int count, String type) {
+ // 检查是否满足添加bricks的条件
+ int able = isAble(volumeName, count, type, brickName);
+ if (able != 1) {
+ return able;
+ }
+
+ String command = "";
+ log.info("add brick to the specified volume");
+
+ String brick = concat(brickName);
+
+ if (type.equals(Constant.distributed))
+ command = "gluster volume add-brick " + volumeName + " " + brick + "force";
+ else if (type.equals(Constant.replica))
+ command = "gluster volume add-brick " + volumeName + " " + "replica " + count + " " + brick + "force";
+ else if (type.equals(Constant.stripe))
+ command = "gluster volume add-brick " + volumeName + " " + "stripe " + count + " " + brick + "force";
+
+ List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
+
+ // 添加成功的返回信息是:volume add-brick: success
+ if (reStrings != null && reStrings.size() > 0 && reStrings.get(0).contains("volume add-brick: success")) {
+ log.info("添加brick成功!");
+ return 1;
+ } else {
+ log.error("3205 add brick failed,please check the system");
+ // System.out.println("3202 add brick failed,please check the
+ // system");
+ return -5;
+ }
+ }
+
+ /**
+ * 为指定的volume删除brick,参数中需要指定类型、数量等 返回值:1 成功 ;其他 失败
+ * 过程中需要先检查volume是否存在,还需检查给出的brick数量与类型、count是否相符
+ *
+ * @param volumeName
+ * @param brickName
+ * @param count
+ * @param type
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public int deleteBrickVolume(String volumeName, List brickName, int count, String type) {
+ int able = isAble(volumeName, count, type, brickName);
+
+ if (able != 1) {
+ return able;
+ }
+ String command = null;
+
+ log.info("delete brick of the specified volume");
+
+ String brick = concat(brickName);
+
+ if (type.equals(Constant.distributed)) {
+ command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " " + brick + " force";
+ } else if (type.equals(Constant.replica)) {
+ command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " repli " + count + " " + brick
+ + " force";
+ } else if (type.equals(Constant.stripe)) {
+ command = "echo -e \"y\" | gluster volume remove-brick " + volumeName + " stripe " + count + " " + brick
+ + " force";
+ }
+
+ if (command == null) {
+ log.error("3305 remove brick failed,please check the system");
+ return -5;
+ }
+ log.info("即将执行删除命令");
+ List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
+ // System.out.println(reStrings);
+ log.info("删除命令执行完毕");
+
+ // 删除成功的返回信息是“volume remove-brick: success”
+ if (reStrings.get(0).contains("volume remove-brick: success")) {
+ {
+ log.info("删除brick成功");
+ return 1;
+ }
+ } else {
+ log.error("3305 remove brick failed,please check the system");
+
+ return -5;
+ }
+
+ }
+
+ /*
+ * 停止指定volume 参数中需给出volume的名字 返回值: 0 成功 -1 失败
+ * 需要先检查volume是否存在,然后判断volume的状态是否已经是停止状态
+ */
+ public int stopVolume(String volumeName) {
+ log.info("stop volume");
+
+ // 首先需要判断volume是否存在,调用其他函数返回所有volume的名字
+ boolean volumeExist = false;
+
+ List volume = new VolumeInfo().showAllVolumeName();
+ for (String temp : volume) {
+ if (temp.equals(volumeName)) {
+ volumeExist = true;
+ break;
+ }
+ }
+
+ if (!volumeExist) {
+ // volume不存在
+ log.error("3501 the volume doesnot exist");
+ System.out.println("3501 the volume doesnot exist");
+ return -1;
+ } else {
+ // volume存在,则需判断volume的状态是否已经为“stop”
+ if (new VolumeInfo().getVolumeStatus(volumeName).equals("Stopped")) {
+ log.error("3502 the volume is already stoped");
+ System.out.println("3502 the volume is already stoped");
+ return 0;
+ } else {
+ String command = "echo -e \"y\"| gluster volume stop " + volumeName;
+ List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
+
+ // 标记操作结果:operation = 1 操作成功
+ // operation = 0 操作失败
+ int operation = 0;
+ for (String temp2 : reStrings) {
+ if (temp2.contains("volume stop: " + volumeName + ": " + "success")) {
+ operation = 1;
+ break;
+ }
+ System.out.println("operation: " + operation);
+ }
+
+ if (operation == 1) {
+ return 0;
+ } else {
+ log.error("3503 stop " + volumeName + " failed");
+ System.out.println("3503 stop " + volumeName + " failed");
+ return -1;
+ }
+
+ }
+ }
+ }
+
+ /*
+ * 开启指定volume 参数中需给出volume的名字 返回值: 0 成功 -1 失败
+ * 需要先检查volume是否存在,然后判断volume的状态是否已经是开启状态
+ */
+ public int startVolume(String volumeName) {
+ log.info("start volume");
+ boolean volumeExist = false;
+ List volume = new VolumeInfo().showAllVolumeName();
+
+ for (String temp : volume) {
+ if (temp.equals(volumeName)) {
+ volumeExist = true;
+ break;
+ }
+ }
+
+ if (volumeExist) {
+ if (!(new VolumeInfo().getVolumeStatus(volumeName).equals("Started"))) {
+ String command = "gluster volume start " + volumeName;
+
+ int operation = 0;
+
+ // 执行命令
+ List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
+ for (String temp2 : reStrings) {
+ if (temp2.equals("volume start: " + volumeName + ": " + "success")) {
+ operation = 1;
+ }
+ }
+
+ if (operation == 1) {
+ return 0;
+ } else {
+ log.error("3602 start volume failed");
+ System.out.println("3602 start volume failed");
+ return -1;
+ }
+ } else {
+ log.error("volume已经开启");
+ System.out.println("volume已经开启");
+ return -1;
+ }
+ } else {
+ log.error("3601 the volume does not exist");
+ // System.out.println("3601 the volume does not exist");
+ return -1;
+ }
+ }
+
+ // 需要将存于List变量中的brick的位置组装成可以在glusterfs命令行中直接使用的格式
+ public String concat(List brickName) {
+ StringBuffer result = new StringBuffer();
+ int len = brickName.size();
+ for (int i = 0; i < len; i++) {
+ result.append(brickName.get(i));
+ result.append(" ");
+ }
+ return result.toString();
+ }
+
+ /*
+ * 只在创建volume时使用此函数 创建volume时对不同数据卷,brick的数量需要满足和count的关系
+ * 首先判断它们是否满足关系,在不满足的关系的情况下是肯定无法完成操作的 1:可以创建 ;-1:brick的ip不在集群中或者未连接; -2 -3
+ * -4 :类型与brick数目不匹配 ; -5 :volumeName 已经存在;-6:挂载点存在且不为空,不能作为挂载点; -7:未知错误
+ */
+ public int isAbleCreateVolume(String volumeName, int count, String type, List bricks, String mountPoint) {
+ int status = 0;
+
+ int length = bricks.size();
+
+ if (type.equals(Constant.distributed)) {
+ if (count != 0) {
+ log.error("3101 the kind of distributed requires the arg of count to be 0");
+ return -2;
+ }
+ }
+ if (type.equals(Constant.stripe)) {
+ if (length % count != 0) {
+ log.error("3102 the number of bricks should be the same as or the times of the stripe count");
+ return -3;
+ }
+ }
+ if (type.equals(Constant.replica)) {
+ if ((length % count) != 0) {
+ log.error(
+ "3103 the number of bricks should be the same as the replicate count or the times of replicate count");
+ return -4;
+ }
+ }
+
+ Map peer_status = new ClusterInfo().showClusterInfo();
+ peer_status.put(Constant.hostIp, Constant.peerincluster_connected);
+ for (String brick : bricks) {
+ brick = brick.split(":")[0];
+ if (!(peer_status.containsKey(brick) && peer_status.get(brick).equals(Constant.peerincluster_connected))) {
+ log.error("3105 birck " + brick + " ip is not in cluster");
+ return -1;
+ }
+
+ }
+
+ List volumeNames = new VolumeInfo().showAllVolumeName();
+ if (volumeNames == null) {
+ log.error("3108 showAllVolumeName return error");
+ return -7;
+ }
+ if (volumeNames.contains(volumeName)) {
+ log.error("3106 " + volumeName + " is already exists! ");
+ return -5;
+ }
+
+ /*
+ Map datas = new ShowData().showFolderData(mountPoint);
+ if (datas != null && datas.size() > 0) {
+ log.error("3107 " + mountPoint + " is not exists or not empty ! ");
+ return -6;
+ }
+ */
+ return 1;
+ }
+
+ /**
+ * 添加或删除volume的brick时,首先需要判断volume是否存在,然后需要判断volume类型、count及brick数目
+ *
+ * @param volumeName
+ * @param count
+ * @param type
+ * @param bricks
+ * @return 1 满足条件,可以添加;-1 :volume name is not exists;-2,-3,-4 类型与brick数量不匹配;
+ */
+ public int isAble(String volumeName, int count, String type, List bricks) {
+ List volumeNames = new VolumeInfo().showAllVolumeName();
+
+ if (!volumeNames.contains(volumeName)) {
+ log.error("3201:" + volumeName + " is not exists! ");
+ return -1;
+ }
+
+ int length = bricks.size();
+ if (type.equals("distribute")) {
+ if (count == 0)
+ return 1;
+ else {
+ log.error("3202: the kind of distributed requires the arg of count to be 0");
+ // System.out.println(" the kind of distributed requires the
+ // arg of count to be 0");
+ return -2;
+ }
+ }
+
+ if (type.equals("stripe")) {
+ if (length % count == 0)
+ return 1;
+ else {
+ log.error("3203: the number of bricks should be the same as or the times of the stripe count");
+ // System.out.println(" the number of bricks should be the
+ // same as or the times of the stripe count");
+ return -3;
+
+ }
+ }
+ if (type.equals("replicate")) {
+ if ((length % count) == 0)
+ return 1;
+ else {
+ log.error(
+ "3204: the number of bricks should be the same as the replicate count or the times of replicate count");
+
+ return -4;
+ }
+ }
+
+ return 1;
+ }
+
+ @Test
+ public void test_deleteVolume(){
+ System.out.println(deleteVolume("lili_test1"));
+ }
+// @Test
+ public void test_createVolume(){
+ List bricksToCreate = new ArrayList();
+ bricksToCreate.add("192.168.0.110:/lili_test1");
+ bricksToCreate.add("192.168.0.116:/lili_test1");
+ System.out.println(createVolume("lili_test1", 0, "distributed", bricksToCreate, "/home/lili_test1_point"));
+ }
+ public static void main(String[] args) {
+ SetVolume setVolume = new SetVolume();
+ int operation = 0;
+ // PropertyConfigurator.configure("log4j.properties");
+ // TODO Auto-generated method stub
+ // 测试创建volume的代码
+
+// List bricksToCreate = new ArrayList();
+// bricksToCreate.add("192.168.0.110:/v2");
+// bricksToCreate.add("192.168.0.116:/v2");
+// operation = setVolume.createVolume("v2", 0, "distributed", bricksToCreate, "/home/v2_point");
+ // operation = setVolume.deleteVolume("v3");
+ //
+ // // 以下是测试添加brick的代码
+ //
+ // List bricksToAdd = new ArrayList();
+ // bricksToAdd.add("192.168.191.23:/v3");
+ // operation = setVolume.addBrickVolume("v3", bricksToAdd, 0,
+ // "distribute");
+ // System.out.println(operation);
+
+ // 以下代码是测试删除brick的代码
+ // List bricksToAdd= new ArrayList();
+ // bricksToAdd.add("192.168.191.23:/v3");
+ // operation =
+ // setVolume.deleteBrickVolume("v3",bricksToAdd,0,"distribute");
+ // System.out.println(operation);
+ // 以下是测试start volume的代码
+ // String volumeToStart = "testcreate" ;
+ // int startOperation = startVolume(volumeToStart);
+ // System.out.println(startOperation);
+ // 以下是测试stop volume
+ String volumeToStop = "v3";
+ // int startOperation = setVolume.stopVolume(volumeToStop);
+ // 以下是测试创建volume并完成挂载的代码
+ // List bricksToCreate= new ArrayList();
+ // bricksToCreate.add("192.168.214.135:/home/create");
+ // bricksToCreate.add("192.168.214.138:/home/create");
+ //
+ // int operation =
+ // createVolume("createAndmount",0,"distribute",bricksToCreate,"/mnt/create");
+ // System.out.println(operation);
+ }
+}
diff --git a/src/com/platform/glusterfs/ShowData.java b/src/com/platform/glusterfs/ShowData.java
index 46466f67..761f6a1b 100644
--- a/src/com/platform/glusterfs/ShowData.java
+++ b/src/com/platform/glusterfs/ShowData.java
@@ -1,129 +1,132 @@
-package com.platform.glusterfs;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-
-import org.apache.log4j.PropertyConfigurator;
-import org.junit.Test;
-
-import com.platform.utils.Constant;
-
-
-public class ShowData {
-
- public static Logger log = Logger.getLogger ( ShowData.class);
-
- /**
- * get the data of volumeName Map s1 is data name and s2 is type file or folder
- * <功能详细描述>
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public Map showVolumeFiles(String volumeName){
-// log.info("start show the data");
- Map data_type=new HashMap();
- /**
- * get mount point of volumeName
- */
- String folderName=volumeName;
-
- data_type=showFolderData(volumeName);
- return data_type;
-}
- /**
- * get the data of folder name
- * Map is folder name and type 1 is file and others is folder
-
-
- * @param FolderName
- * @return
- */
- public Map showFolderData(String folderName){
-// log.info(" start get "+folderName+" data");
-
-
- Map data_type=new HashMap();
- String command="ls -l "+folderName;
-
- /*
- * RunCommand runCommand=new RunCommand(); List
- * reStrings=runCommand.runCommandWait(command);
- */
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
- if (reStrings == null) {
- log.error("2101 command get result is null");
- return null;
- }
- if(reStrings.size()==0){
- log.info("2102 the folder is empty");
- return data_type;
- }
- if(reStrings.get(0).contains("No such file or directory")){
- log.info("2103 the "+folderName+" is not exists");
- return null;
- }
- /**
- * remove first line total number
- */
- reStrings.remove(0);
-
- for(Iterator it2 = reStrings.iterator();it2.hasNext();){
- String line=(String)it2.next();
- line=line.replaceAll(" +", " ");
- String keyValue[]=line.split(" ");
- if(keyValue.length<9){
- log.error("2104 "+line+" length is short");
- continue;
- }
-
- data_type.put(keyValue[8], keyValue[1]);
-
- }
-// log.info(" get "+folderName+" data successed");
- return data_type;
- }
-
- /**
- * 返回folder的大小字节表示
- * -2表示获取大小出错,-1表示folder不存在,其他表示folder的大小
- * @param folderPath
- * @return
- * @see [类、类#方法、类#成员]
- */
- public long getFolderSize(String folderPath) {
-// log.info("get " + folderPath + " Size ");
-
- String command = "du -k -d 0 "+folderPath+" | grep " + folderPath + "|awk \'{print $1}\'";
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(command);
- if(reStrings==null || reStrings.size()==0){
- log.error("get " + folderPath + " Size error!");
- return -2;
- }
- if (reStrings.get(0).contains(Constant.noSuchFile)) {
- log.error(folderPath+" is not exists");
- return -1;
- }
- long size = Long.valueOf(reStrings.get(0));
- return size;
- }
-
-
- /**
- *
- * <一句话功能简述>
- * <功能详细描述>
- * @see [类、类#方法、类#成员]
- */
- @Test
- public void testShowData(){
-
- System.out.println(showFolderData("/home"));
-
- }
+package com.platform.glusterfs;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+
+import org.apache.log4j.PropertyConfigurator;
+import org.junit.Test;
+
+import com.platform.utils.Constant;
+import com.platform.utils.ProcessMyUtil;
+
+
+public class ShowData {
+
+ ProcessMyUtil proMy = new ProcessMyUtil();
+
+ public static Logger log = Logger.getLogger ( ShowData.class);
+
+ /**
+ * get the data of volumeName Map s1 is data name and s2 is type file or folder
+ * <功能详细描述>
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public Map showVolumeFiles(String volumeName){
+// log.info("start show the data");
+ Map data_type=new HashMap();
+ /**
+ * get mount point of volumeName
+ */
+ String folderName=volumeName;
+
+ data_type=showFolderData(volumeName);
+ return data_type;
+}
+ /**
+ * get the data of folder name
+ * Map is folder name and type 1 is file and others is folder
+
+
+ * @param FolderName
+ * @return
+ */
+ public Map showFolderData(String folderName){
+// log.info(" start get "+folderName+" data");
+
+
+ Map data_type=new HashMap();
+ String command="ls -l "+folderName;
+
+ /*
+ * RunCommand runCommand=new RunCommand(); List
+ * reStrings=runCommand.runCommandWait(command);
+ */
+ List reStrings = proMy.execCmdWaitAcquiescent(command);
+ if (reStrings == null) {
+ log.error("2101 command get result is null");
+ return null;
+ }
+ if(reStrings.size()==0){
+ log.info("2102 the folder is empty");
+ return data_type;
+ }
+ if(reStrings.get(0).contains("No such file or directory")){
+ log.info("2103 the "+folderName+" is not exists");
+ return null;
+ }
+ /**
+ * remove first line total number
+ */
+ reStrings.remove(0);
+
+ for(Iterator it2 = reStrings.iterator();it2.hasNext();){
+ String line=(String)it2.next();
+ line=line.replaceAll(" +", " ");
+ String keyValue[]=line.split(" ");
+ if(keyValue.length<9){
+ log.error("2104 "+line+" length is short");
+ continue;
+ }
+
+ data_type.put(keyValue[8], keyValue[1]);
+
+ }
+// log.info(" get "+folderName+" data successed");
+ return data_type;
+ }
+
+ /**
+ * 返回folder的大小字节表示
+ * -2表示获取大小出错,-1表示folder不存在,其他表示folder的大小
+ * @param folderPath
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public long getFolderSize(String folderPath) {
+// log.info("get " + folderPath + " Size ");
+
+ String command = "du -k -d 0 "+folderPath+" | grep " + folderPath + "|awk \'{print $1}\'";
+ List reStrings = proMy.execCmdWaitAcquiescent(command);
+ if(reStrings==null || reStrings.size()==0){
+ log.error("get " + folderPath + " Size error!");
+ return -2;
+ }
+ if (reStrings.get(0).contains(Constant.noSuchFile)) {
+ log.error(folderPath+" is not exists");
+ return -1;
+ }
+ long size = Long.valueOf(reStrings.get(0));
+ return size;
+ }
+
+
+ /**
+ *
+ * <一句话功能简述>
+ * <功能详细描述>
+ * @see [类、类#方法、类#成员]
+ */
+ @Test
+ public void testShowData(){
+
+ System.out.println(showFolderData("/home"));
+
+ }
}
\ No newline at end of file
diff --git a/src/com/platform/glusterfs/SizeInfo.java b/src/com/platform/glusterfs/SizeInfo.java
index 8327e4f1..03f74228 100644
--- a/src/com/platform/glusterfs/SizeInfo.java
+++ b/src/com/platform/glusterfs/SizeInfo.java
@@ -1,93 +1,93 @@
-package com.platform.glusterfs;
-
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-
-import com.platform.utils.Constant;
-
-public class SizeInfo {
- public static Logger log = Logger.getLogger(ClusterInfo.class);
- VolumeInfo volumeInfo = new VolumeInfo();
-
- /**
- * 获取集群�?��volume size
- * 返回值:-1:错�? 0:没有volume long:size大小
- * @return
- */
- public long showAllSize() {
-// log.info("get AllSize ");
- List volumeNames = volumeInfo.showAllVolumeName();
- if (volumeNames == null) {
- log.error("1201 showAllVolumeName error");
- return -1;
- }
- if (volumeNames.size() == 0) {
- log.error("1202 It is not exist any volume");
- return 0;
- }
- List reStrings = null;
- long size = 0L;
-
- for (String str : volumeNames) {
- String command = "df |grep " + str + "|awk \'{print $2}\'";
- reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port,
- command);
- if (reStrings.isEmpty()) {
- log.error("1203 The brick is unmount");
- } else {
- size += Long.parseLong(reStrings.get(0));
- }
-
- }
-
- return size;
- }
- /**
- * 返回集群已用大小
- * @return
- * 返回值:-1:错�? 0:没有volume long:size大小
- */
- public long showUseSize() {
- log.info("get UseSize ");
-
- List volumeNames = volumeInfo.showAllVolumeName();
- List reStrings = null;
- long size = 0L;
- if (volumeNames == null) {
- log.error("1201 showAllVolumeName error");
- return -1;
- }
- if (volumeNames.size() == 0) {
- log.error("1202 It is not exist any volume");
- return 0;
- }
-
- for (String str : volumeNames) {
- String command = "df |grep " + str + "|awk \'{print $3}\'";
- reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
- Constant.port, command);
- if (reStrings.isEmpty()) {
- log.error("1202 The brick is unmount");
- } else {
- size += Integer.valueOf(reStrings.get(0));
- }
-
- }
-
- return size;
- }
-
- public static void main(String[] args) {
- PropertyConfigurator.configure("log4j.properties");
- System.out.println(new SizeInfo().showAllSize());
- System.out.println(new SizeInfo().showUseSize());
- }
+package com.platform.glusterfs;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import com.platform.utils.Constant;
+
+public class SizeInfo {
+ public static Logger log = Logger.getLogger(ClusterInfo.class);
+ VolumeInfo volumeInfo = new VolumeInfo();
+
+ /**
+ * 获取集群�?��volume size
+ * 返回值:-1:错�? 0:没有volume long:size大小
+ * @return
+ */
+ public long showAllSize() {
+// log.info("get AllSize ");
+ List volumeNames = volumeInfo.showAllVolumeName();
+ if (volumeNames == null) {
+ log.error("1201 showAllVolumeName error");
+ return -1;
+ }
+ if (volumeNames.size() == 0) {
+ log.error("1202 It is not exist any volume");
+ return 0;
+ }
+ List reStrings = null;
+ long size = 0L;
+
+ for (String str : volumeNames) {
+ String command = "df |grep " + str + "|awk \'{print $2}\'";
+ reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port,
+ command);
+ if (reStrings.isEmpty()) {
+ log.error("1203 The brick is unmount");
+ } else {
+ size += Long.parseLong(reStrings.get(0));
+ }
+
+ }
+
+ return size;
+ }
+ /**
+ * 返回集群已用大小
+ * @return
+ * 返回值:-1:错�? 0:没有volume long:size大小
+ */
+ public long showUseSize() {
+ log.info("get UseSize ");
+
+ List volumeNames = volumeInfo.showAllVolumeName();
+ List reStrings = null;
+ long size = 0L;
+ if (volumeNames == null) {
+ log.error("1201 showAllVolumeName error");
+ return -1;
+ }
+ if (volumeNames.size() == 0) {
+ log.error("1202 It is not exist any volume");
+ return 0;
+ }
+
+ for (String str : volumeNames) {
+ String command = "df |grep " + str + "|awk \'{print $3}\'";
+ reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
+ Constant.port, command);
+ if (reStrings.isEmpty()) {
+ log.error("1202 The brick is unmount");
+ } else {
+ size += Integer.valueOf(reStrings.get(0));
+ }
+
+ }
+
+ return size;
+ }
+
+ public static void main(String[] args) {
+ PropertyConfigurator.configure("log4j.properties");
+ System.out.println(new SizeInfo().showAllSize());
+ System.out.println(new SizeInfo().showUseSize());
+ }
}
\ No newline at end of file
diff --git a/src/com/platform/glusterfs/VolumeInfo.java b/src/com/platform/glusterfs/VolumeInfo.java
index 7e5fc985..bcf72c3a 100644
--- a/src/com/platform/glusterfs/VolumeInfo.java
+++ b/src/com/platform/glusterfs/VolumeInfo.java
@@ -1,417 +1,417 @@
-
-package com.platform.glusterfs;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.PropertyConfigurator;
-import org.junit.Test;
-import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
-
-import com.platform.utils.Constant;
-import com.platform.utils.GanymedSSH;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * 获取volume信息 <功能详细描述>
- *
- * @author liliy
- * @version [版本号,2016年9月13日]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
-public class VolumeInfo {
- public static Logger log = Logger.getLogger(VolumeInfo.class);
-
- /**
- * 显示所有volume名称 <功能详细描述>
- *
- * @return
- * @see [类、类#方法、类#成员]
- */
- public List showAllVolumeName() {
-// log.info(Constant.ganymedSSH+"get volume name");
- List volNames = new ArrayList();
-
- /*
- * String command = "echo \"" + Constant.rootPasswd +
- * "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand
- * runCommand = new RunCommand(); List reStrings =
- * runCommand.runCommandWait(command);
- */
-
- List reStrings = Constant.ganymedSSH
- .execCmdWaitAcquiescent(Constant.glusterVolumeInfo + "|grep ^Volume.Name");
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("1401 get result is null");
- return null;
- }
- if (reStrings.size() == 0) {
- log.error("1402 get result is nothing");
- return null;
- }
- if (reStrings.get(0).contains(Constant.noVolume)) {
- reStrings.clear();
- return reStrings;
- }
- if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) {
- log.error("1403 get result string wrong");
- return null;
- }
-
- String nameInfo = "";
- for (Iterator it = reStrings.iterator(); it.hasNext();) {
- String line = (String) it.next();
- String str[] = line.split(":");
- volNames.add(str[1].replaceAll(" ", ""));
- }
- return volNames;
-
- }
-
- /**
- * 给定参数volume的名称获得volume的类型
- *
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public String getVolumeType(String volumeName) {
-// log.info("get volume type");
- String volType = "";
-
- List reStrings = Constant.ganymedSSH
- .execCmdWaitAcquiescent(Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("1501 get result is null");
- return null;
- }
- if (reStrings.size() == 0) {
- log.error("1502 get result is nothing");
- return null;
- }
- if (!(reStrings.get(0).split(":")[0].contains("Type"))) {
- log.error("1503 get result string wrong");
- return null;
- }
-
- // System.out.println(reStrings);
-
- for (Iterator it = reStrings.iterator(); it.hasNext();) {
- String line = (String) it.next();
- String str[] = line.split(":");
- volType = str[1];
- }
- volType = volType.replaceAll(" ", "");
- return volType;
- }
-
- /**
- * 获取volumeName的状态 如果出错返回null,如果volumeName不存在则返回Volume volumeName does not
- * exist,正常返回状态Started,Stopped,Created
- *
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public String getVolumeStatus(String volumeName) {
-// log.info("get volume status");
- String volStatus = "";
- String cmd = Constant.glusterVolumeInfo + " " + volumeName + " |grep ^Status";
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("1701 get result is null");
- return null;
- }
- if (reStrings.size() == 0) {
- log.error("1702 get result is nothing");
- return null;
- }
-
- if (reStrings.get(0).contains("does not exist")) {
- log.error("1703 " + reStrings.get(0));
- return reStrings.get(0);
- }
- if (!(reStrings.get(0).split(":")[0].contains("Status"))) {
- log.error("1704 get result string wrong");
- return null;
- }
- for (Iterator it = reStrings.iterator(); it.hasNext();) {
- String line = (String) it.next();
- String str[] = line.split(":");
- volStatus = str[1].replaceAll(" ", "");
- }
-
- return volStatus;
- }
-
- /**
- * 获取volumeName的可用大小
- * volumeName不存在返回-1,获取大小错误返回-2 ,正常返回volumeName的可用大小
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public Long getVolumeAvailableSize(String volumeName) throws Exception{
-// log.info("get volume availableSize");
- Long allSize = 0L;
-
- String cmd = Constant.df + " | grep " + volumeName + "|awk '{print $4}'";
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("1802 get result is error");
- return -2L;
- }
- if (reStrings.size() == 0) {
- log.error("1801 " + volumeName + " is not exists!");
- return -1L;
- }
- Pattern pattern2 = Pattern.compile("^\\d+$");
- Matcher matcher2 = pattern2.matcher(reStrings.get(0));
- // 如果是数字
- if (matcher2.find()) {
- allSize = Long.parseLong(reStrings.get(0));
- }
- return allSize;
- }
-
- /**
- * 获取volumeName已用空间
- * volumeName不存在返回-1,获取大小错误返回-2 ,正常返回volumeName的已用的大小
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public Long getVolumeUseSize(String volumeName) throws Exception{
-// log.info("get volume used size");
- Long usedSize = 0L;
- if (volumeIsExists(volumeName) == false) {
- log.error("1901 " + volumeName + " is not exists!");
- return -1L;
-
- }
-
- String cmd = "df | grep " + volumeName + "|awk '{print $3}'";
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("1901 get result is null");
- return -2L;
- }
- if (reStrings.size() == 0) {
- log.error("1902 " + volumeName + " is not exists!");
- return -1L;
- }
- Pattern pattern2 = Pattern.compile("^\\d+$");
- Matcher matcher2 = pattern2.matcher(reStrings.get(0));
- // 如果是数字
- if (matcher2.find()) {
- usedSize = Long.parseLong(reStrings.get(0));
- }
- return usedSize;
- }
-
- /**
- * 获取volumeName的bricks
- * 返回一个bircks的list ip:path,如果volumeName不存在返回null
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public List getVolumeBricks(String volumeName) {
-// log.info("get volume bricks");
-
- String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'";
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("1601 get volume bricks wrong");
- return null;
- }
- if (reStrings.size()==0) {
- log.error("1602 "+volumeName+" is not exists!");
- return null;
- }
- return reStrings;
- }
-
- /**
- * 获取volumeName所有挂载点
- * <功能详细描述>
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public List getVolumeMountPoint(String volumeName) {
-// log.info("get volume MountPoint");
- List mountPoints = new ArrayList<>();
- String cmd=Constant.df + "|grep " + volumeName + "|awk '{print $6}'";
- List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("11001 get result string wrong");
- return null;
- }
- if (reStrings.size() == 0) {
- log.error("11002 " + volumeName + " is not exists or no mountpoint");
- return null;
- }
-
- for (String mountPoint : reStrings) {
- mountPoint = mountPoint.replaceAll(" ", "");
- mountPoints.add(mountPoint);
- }
- return mountPoints;
- }
-
- public String getOneVolumeMountPoint(String volumeName) {
-// log.info("get one volume MountPoint");
-
- String mountPoint=null;
-
- List mountpoints = getVolumeMountPoint(volumeName);
- // System.out.println(reStrings);
- if (mountpoints == null || mountpoints.size() == 0) {
- log.error("11001 get result string wrong");
- return null;
- }
-
- mountPoint=mountpoints.get(0);
- return mountPoint;
- }
-
- /**
- * 获取volumeName的所有brick中数据占用空间的大小
- * 返回一个map表示bricks和数据大小
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public Map getVolumebricksDataSize(String volumeName) {
- List bricks = getVolumeBricks(volumeName);
- Map brick_size = new HashMap<>();
- if (bricks == null) {
- return null;
- }
- for (String brick : bricks) {
- String ipAndpath[] = brick.split(":");
- String ip = ipAndpath[0];
- String path = ipAndpath[1];
- String cmd = "du -d 0 " + path + "|awk '{print $1}'";
- List reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
- Constant.port, cmd);
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("1901 get result is null");
- return null;
- }
- if (reStrings.size() == 0) {
- log.error("1902 "+brick+" is not exits!");
- return null;
- }
- Pattern pattern = Pattern.compile("[0-9]*");
- Matcher isNum = pattern.matcher(reStrings.get(0));
- if (!isNum.matches()) {
- log.error("1903 " + reStrings.get(0) + " is unexpect");
- return null;
- }
- brick_size.put(brick, Double.parseDouble(reStrings.get(0)));
- }
- return brick_size;
- }
-
- /**
- * 获取volumeName的所有brick中可用空间大小
- * 返回一个map表示bricks和可用空间大小
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public Map getVolumebricksAvailableSize(String volumeName) {
- List bricks = getVolumeBricks(volumeName);
- Map brick_size = new HashMap<>();
- if (bricks == null) {
- return null;
- }
- for (String brick : bricks) {
- String ipAndpath[] = brick.split(":");
- String ip = ipAndpath[0];
- String path = ipAndpath[1];
- String cmd = "df " + path + "|awk '{print $4}'";
- List reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
- Constant.port, cmd);
- // System.out.println(reStrings);
- if (reStrings == null) {
- log.error("1901 get result is null");
- return null;
- }
- if (reStrings.size() == 0) {
- log.error("1902 get result is nothing");
- return null;
- }
- Pattern pattern = Pattern.compile("[0-9]*");
- Matcher isNum = pattern.matcher(reStrings.get(1));
- if (!isNum.matches()) {
- log.error("1903 " + reStrings.get(1) + " is unexpect");
- return null;
- }
- brick_size.put(brick, Double.parseDouble(reStrings.get(1)));
- }
- return brick_size;
- }
-
- /**
- * 判断volumeName是否存在,存在返回true,不存在返回false
- *
- * @param volumeName
- * @return
- * @see [类、类#方法、类#成员]
- */
- public boolean volumeIsExists(String volumeName) {
- List volumes = showAllVolumeName();
- if (volumes == null) {
- return false;
- }
- if (volumes.contains(volumeName)) {
- return true;
- }
- return false;
- }
-
- // @Test
- public void test_getVolumebricksDataSize() {
- System.out.println(getVolumebricksDataSize("gfs_ftp"));
- }
-
- // @Test
- public void test_getVolumebricksAvailableSize() {
- System.out.println(getVolumebricksAvailableSize("gfs_ftp"));
- }
-
- // @Test
- public void test_getVolumeBricks() {
- getVolumeBricks("gfs_ftp");
- }
-
- @Test
- public void test_getVolumeStatus() {
- System.out.println(getVolumeStatus("gs_fp"));
- }
-
- // @Test
- public void test_getVolumeMountPoint() {
- System.out.println(getVolumeMountPoint("gfs_ftp"));
- System.out.println(getVolumeMountPoint("v1"));
- }
-}
+
+package com.platform.glusterfs;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.junit.Test;
+import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
+
+import com.platform.utils.Constant;
+import com.platform.utils.GanymedSSH;
+import com.platform.utils.ProcessMyUtil;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 获取volume信息 <功能详细描述>
+ *
+ * @author liliy
+ * @version [版本号,2016年9月13日]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public class VolumeInfo {
+ ProcessMyUtil proMy = new ProcessMyUtil();
+ public static Logger log = Logger.getLogger(VolumeInfo.class);
+
+ /**
+ * 显示所有volume名称 <功能详细描述>
+ *
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public List showAllVolumeName() {
+// log.info(Constant.ganymedSSH+"get volume name");
+ List volNames = new ArrayList();
+
+ /*
+ * String command = "echo \"" + Constant.rootPasswd +
+ * "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand
+ * runCommand = new RunCommand(); List reStrings =
+ * runCommand.runCommandWait(command);
+ */
+
+ List reStrings = proMy.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + "|grep ^Volume.Name");
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("1401 get result is null");
+ return null;
+ }
+ if (reStrings.size() == 0) {
+ log.error("1402 get result is nothing");
+ return null;
+ }
+ if (reStrings.get(0).contains(Constant.noVolume)) {
+ reStrings.clear();
+ return reStrings;
+ }
+ if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) {
+ log.error("1403 get result string wrong");
+ return null;
+ }
+
+ String nameInfo = "";
+ for (Iterator it = reStrings.iterator(); it.hasNext();) {
+ String line = (String) it.next();
+ String str[] = line.split(":");
+ volNames.add(str[1].replaceAll(" ", ""));
+ }
+ return volNames;
+
+ }
+
+ /**
+ * 给定参数volume的名称获得volume的类型
+ *
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public String getVolumeType(String volumeName) {
+// log.info("get volume type");
+ String volType = "";
+
+ List reStrings = proMy.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("1501 get result is null");
+ return null;
+ }
+ if (reStrings.size() == 0) {
+ log.error("1502 get result is nothing");
+ return null;
+ }
+ if (!(reStrings.get(0).split(":")[0].contains("Type"))) {
+ log.error("1503 get result string wrong");
+ return null;
+ }
+
+ // System.out.println(reStrings);
+
+ for (Iterator it = reStrings.iterator(); it.hasNext();) {
+ String line = (String) it.next();
+ String str[] = line.split(":");
+ volType = str[1];
+ }
+ volType = volType.replaceAll(" ", "");
+ return volType;
+ }
+
+ /**
+ * 获取volumeName的状态 如果出错返回null,如果volumeName不存在则返回Volume volumeName does not
+ * exist,正常返回状态Started,Stopped,Created
+ *
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public String getVolumeStatus(String volumeName) {
+// log.info("get volume status");
+ String volStatus = "";
+ String cmd = Constant.glusterVolumeInfo + " " + volumeName + " |grep ^Status";
+ List reStrings = proMy.execCmdWaitAcquiescent(cmd);
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("1701 get result is null");
+ return null;
+ }
+ if (reStrings.size() == 0) {
+ log.error("1702 get result is nothing");
+ return null;
+ }
+
+ if (reStrings.get(0).contains("does not exist")) {
+ log.error("1703 " + reStrings.get(0));
+ return reStrings.get(0);
+ }
+ if (!(reStrings.get(0).split(":")[0].contains("Status"))) {
+ log.error("1704 get result string wrong");
+ return null;
+ }
+ for (Iterator it = reStrings.iterator(); it.hasNext();) {
+ String line = (String) it.next();
+ String str[] = line.split(":");
+ volStatus = str[1].replaceAll(" ", "");
+ }
+
+ return volStatus;
+ }
+
+ /**
+ * 获取volumeName的可用大小
+ * volumeName不存在返回-1,获取大小错误返回-2 ,正常返回volumeName的可用大小
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public Long getVolumeAvailableSize(String volumeName) throws Exception{
+// log.info("get volume availableSize");
+ Long allSize = 0L;
+
+ String cmd = Constant.df + " | grep " + volumeName + "|awk '{print $4}'";
+ List reStrings = proMy.execCmdWaitAcquiescent(cmd);
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("1802 get result is error");
+ return -2L;
+ }
+ if (reStrings.size() == 0) {
+ log.error("1801 " + volumeName + " is not exists!");
+ return -1L;
+ }
+ Pattern pattern2 = Pattern.compile("^\\d+$");
+ Matcher matcher2 = pattern2.matcher(reStrings.get(0));
+ // 如果是数字
+ if (matcher2.find()) {
+ allSize = Long.parseLong(reStrings.get(0));
+ }
+ return allSize;
+ }
+
+ /**
+ * 获取volumeName已用空间
+ * volumeName不存在返回-1,获取大小错误返回-2 ,正常返回volumeName的已用的大小
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public Long getVolumeUseSize(String volumeName) throws Exception{
+// log.info("get volume used size");
+ Long usedSize = 0L;
+ if (volumeIsExists(volumeName) == false) {
+ log.error("1901 " + volumeName + " is not exists!");
+ return -1L;
+
+ }
+
+ String cmd = "df | grep " + volumeName + "|awk '{print $3}'";
+ List reStrings = proMy.execCmdWaitAcquiescent(cmd);
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("1901 get result is null");
+ return -2L;
+ }
+ if (reStrings.size() == 0) {
+ log.error("1902 " + volumeName + " is not exists!");
+ return -1L;
+ }
+ Pattern pattern2 = Pattern.compile("^\\d+$");
+ Matcher matcher2 = pattern2.matcher(reStrings.get(0));
+ // 如果是数字
+ if (matcher2.find()) {
+ usedSize = Long.parseLong(reStrings.get(0));
+ }
+ return usedSize;
+ }
+
+ /**
+ * 获取volumeName的bricks
+ * 返回一个bircks的list ip:path,如果volumeName不存在返回null
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public List getVolumeBricks(String volumeName) {
+// log.info("get volume bricks");
+
+ String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'";
+ List reStrings = proMy.execCmdWaitAcquiescent(cmd);
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("1601 get volume bricks wrong");
+ return null;
+ }
+ if (reStrings.size()==0) {
+ log.error("1602 "+volumeName+" is not exists!");
+ return null;
+ }
+ return reStrings;
+ }
+
+ /**
+ * 获取volumeName所有挂载点
+ * <功能详细描述>
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public List getVolumeMountPoint(String volumeName) {
+// log.info("get volume MountPoint");
+ List mountPoints = new ArrayList<>();
+ String cmd=Constant.df + "|grep " + volumeName + "|awk '{print $6}'";
+ List reStrings = proMy.execCmdWaitAcquiescent(cmd);
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("11001 get result string wrong");
+ return null;
+ }
+ if (reStrings.size() == 0) {
+ log.error("11002 " + volumeName + " is not exists or no mountpoint");
+ return null;
+ }
+
+ for (String mountPoint : reStrings) {
+ mountPoint = mountPoint.replaceAll(" ", "");
+ mountPoints.add(mountPoint);
+ }
+ return mountPoints;
+ }
+
+ public String getOneVolumeMountPoint(String volumeName) {
+// log.info("get one volume MountPoint");
+
+ String mountPoint=null;
+
+ List mountpoints = getVolumeMountPoint(volumeName);
+ // System.out.println(reStrings);
+ if (mountpoints == null || mountpoints.size() == 0) {
+ log.error("11001 get result string wrong");
+ return null;
+ }
+
+ mountPoint=mountpoints.get(0);
+ return mountPoint;
+ }
+
+ /**
+ * 获取volumeName的所有brick中数据占用空间的大小
+ * 返回一个map表示bricks和数据大小
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public Map getVolumebricksDataSize(String volumeName) {
+ List bricks = getVolumeBricks(volumeName);
+ Map brick_size = new HashMap<>();
+ if (bricks == null) {
+ return null;
+ }
+ for (String brick : bricks) {
+ String ipAndpath[] = brick.split(":");
+ String ip = ipAndpath[0];
+ String path = ipAndpath[1];
+ String cmd = "du -d 0 " + path + "|awk '{print $1}'";
+ List reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
+ Constant.port, cmd);
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("1901 get result is null");
+ return null;
+ }
+ if (reStrings.size() == 0) {
+ log.error("1902 "+brick+" is not exits!");
+ return null;
+ }
+ Pattern pattern = Pattern.compile("[0-9]*");
+ Matcher isNum = pattern.matcher(reStrings.get(0));
+ if (!isNum.matches()) {
+ log.error("1903 " + reStrings.get(0) + " is unexpect");
+ return null;
+ }
+ brick_size.put(brick, Double.parseDouble(reStrings.get(0)));
+ }
+ return brick_size;
+ }
+
+ /**
+ * 获取volumeName的所有brick中可用空间大小
+ * 返回一个map表示bricks和可用空间大小
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public Map getVolumebricksAvailableSize(String volumeName) {
+ List bricks = getVolumeBricks(volumeName);
+ Map brick_size = new HashMap<>();
+ if (bricks == null) {
+ return null;
+ }
+ for (String brick : bricks) {
+ String ipAndpath[] = brick.split(":");
+ String ip = ipAndpath[0];
+ String path = ipAndpath[1];
+ String cmd = "df " + path + "|awk '{print $4}'";
+ List reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
+ Constant.port, cmd);
+ // System.out.println(reStrings);
+ if (reStrings == null) {
+ log.error("1901 get result is null");
+ return null;
+ }
+ if (reStrings.size() == 0) {
+ log.error("1902 get result is nothing");
+ return null;
+ }
+ Pattern pattern = Pattern.compile("[0-9]*");
+ Matcher isNum = pattern.matcher(reStrings.get(1));
+ if (!isNum.matches()) {
+ log.error("1903 " + reStrings.get(1) + " is unexpect");
+ return null;
+ }
+ brick_size.put(brick, Double.parseDouble(reStrings.get(1)));
+ }
+ return brick_size;
+ }
+
+ /**
+ * 判断volumeName是否存在,存在返回true,不存在返回false
+ *
+ * @param volumeName
+ * @return
+ * @see [类、类#方法、类#成员]
+ */
+ public boolean volumeIsExists(String volumeName) {
+ List volumes = showAllVolumeName();
+ if (volumes == null) {
+ return false;
+ }
+ if (volumes.contains(volumeName)) {
+ return true;
+ }
+ return false;
+ }
+
+ // @Test
+ public void test_getVolumebricksDataSize() {
+ System.out.println(getVolumebricksDataSize("gfs_ftp"));
+ }
+
+ // @Test
+ public void test_getVolumebricksAvailableSize() {
+ System.out.println(getVolumebricksAvailableSize("gfs_ftp"));
+ }
+
+ // @Test
+ public void test_getVolumeBricks() {
+ getVolumeBricks("gfs_ftp");
+ }
+
+ @Test
+ public void test_getVolumeStatus() {
+ System.out.println(getVolumeStatus("gs_fp"));
+ }
+
+ // @Test
+ public void test_getVolumeMountPoint() {
+ System.out.println(getVolumeMountPoint("gfs_ftp"));
+ System.out.println(getVolumeMountPoint("v1"));
+ }
+}
diff --git a/src/com/platform/service/VolumeService.java b/src/com/platform/service/VolumeService.java
index 3dbe3f5a..ccb01e75 100644
--- a/src/com/platform/service/VolumeService.java
+++ b/src/com/platform/service/VolumeService.java
@@ -1,119 +1,34 @@
-package com.platform.service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import com.platform.entities.Brick;
-import com.platform.entities.FolderNode;
-import com.platform.entities.VolumeEntity;
-import com.platform.glusterfs.CheckoutMD5;
-import com.platform.glusterfs.ClusterInfo;
-import com.platform.glusterfs.GetTreeData;
-import com.platform.glusterfs.VolumeInfo;
-import com.platform.utils.CacheTreeData;
-
-public class VolumeService {
-
- public static Logger log = Logger.getLogger(VolumeService.class);
-
- /** Volume信息查询 */
- private VolumeInfo volumeInfo = new VolumeInfo();
-
- private ClusterInfo cluster = new ClusterInfo();
-
- /** gfs目录树形展示 */
- private GetTreeData gfsTree = new GetTreeData();
-
- public void getVolumeMsg() {
- List folderlist = new ArrayList();
- List volumeList = new ArrayList();
- // brick状态 map集合
- Map brickStatusMap = cluster.showClusterInfo();
-
- // 查询 volume name
- List volumeNameList = volumeInfo.showAllVolumeName();
- if (null != volumeNameList) {
- for (String volumeName : volumeNameList) {
- try {
- VolumeEntity volume = new VolumeEntity();
- volume.setName(volumeName);
- List 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 brickStrs = volumeInfo
- .getVolumeBricks(volumeName);
- // brick已用大小:
- Map usedSize = volumeInfo
- .getVolumebricksDataSize(volumeName);
- Map availableSize = volumeInfo
- .getVolumebricksAvailableSize(volumeName);
-
- List brickList = new ArrayList();
- 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);
- }
-
-}
+package com.platform.service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import com.platform.entities.Brick;
+import com.platform.entities.FolderNode;
+import com.platform.entities.VolumeEntity;
+import com.platform.glusterfs.CheckoutMD5;
+import com.platform.glusterfs.ClusterInfo;
+import com.platform.glusterfs.GetTreeData;
+import com.platform.glusterfs.VolumeInfo;
+import com.platform.utils.CacheTreeData;
+
+public class VolumeService {
+
+ public static Logger log = Logger.getLogger(VolumeService.class);
+
+ /** Volume信息查询 */
+ private VolumeInfo volumeInfo = new VolumeInfo();
+
+ private ClusterInfo cluster = new ClusterInfo();
+
+ /** gfs目录树形展示 */
+ private GetTreeData gfsTree = new GetTreeData();
+
+ public void getVolumeMsg() {
+
+ }
+
+}
diff --git a/src/com/platform/utils/CacheTreeData.java b/src/com/platform/utils/CacheTreeData.java
index d0119a48..18bde5ce 100644
--- a/src/com/platform/utils/CacheTreeData.java
+++ b/src/com/platform/utils/CacheTreeData.java
@@ -1,39 +1,39 @@
-package com.platform.utils;
-
-import java.util.List;
-import java.util.Map;
-
-import com.platform.entities.FolderNode;
-import com.platform.entities.VolumeEntity;
-
-public class CacheTreeData {
-
- private static List folders = null;
-
- private static List