From 6e68a67686b95a313ef901c4a6f2220224ad92d4 Mon Sep 17 00:00:00 2001 From: lili Date: Thu, 8 Sep 2016 09:05:40 +0800 Subject: [PATCH 1/2] nothing --- .classpath | 6 +---- build/classes/.gitignore | 1 + .../controller/DefaultController.class | Bin 1342 -> 1514 bytes .../controller/DefaultController.java | 25 +++++++++++++----- 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 build/classes/.gitignore diff --git a/.classpath b/.classpath index 7e729e64..bb361b44 100644 --- a/.classpath +++ b/.classpath @@ -2,11 +2,6 @@ - - - - - @@ -14,5 +9,6 @@ + diff --git a/build/classes/.gitignore b/build/classes/.gitignore new file mode 100644 index 00000000..c2d9872a --- /dev/null +++ b/build/classes/.gitignore @@ -0,0 +1 @@ +/com/ diff --git a/build/classes/com/platform/controller/DefaultController.class b/build/classes/com/platform/controller/DefaultController.class index 9194050341ac120c7dd7616d178826116f726d0f..004ef7972075e7225da53deafe69724a667733ce 100644 GIT binary patch delta 565 zcmZvYPfrt36vfY-na-OIMf(Sck|r1xuxJ@*QNb#ThLwVeu)u|j>GahUCZ){065@uv zuA27=To|?u3rsX2vh_=_=R**#LxL{cy!+n0=brP+J9f_ovcJ!N90RE0rGP;w^}d#R z3*RW{oxaO%`n$dt`t6V2+xn&ql>R{Vl;tTI>l1n<>}K3(He&4>%c~CV5JcFD)lwL` z7{{c*1flTPVtFr+9o5=yXK)WT;d&=(wbh#PgRS+*52S-Bf*r}Y8!G+9s5l~$J6#zo zePWd7ND_wM{Ku_E7)(r7{LZ>x4_Rk1pdv)Q(`K>T@>aGRGUO>MQ-9c18jmn9@K|q{ zW99;$=uc+Z7I;b+)3Y=*^3RTo8qx%lvGjrYnXc)IRo&l*0gFGaaEPJ&=n;zf+x^w@ z5$@(oeGm^E4Dc72aQQxhRB}4F!QGq4U=&#t`3_87+Hh}>Uu=l`c#t?0P{uUJWFX*S zhP`HaZi8M6h;f!wP}RSz;m#ZjfHjtyTysoxh=+{y6Seo>@vP5HBjIqlf~nG&NV0ET ZE?i~juCjAjOtK9;Pqtq$Z<38A-~t91R_F<+C&7^N^_J;>a}}s+0K1CnP1Q% zXc1H{3JQ#%RX?R=KOj0Ph?^K@&Uw!{?>qzZ9q4M|uiw`$fDAUhP#BW!n`C?ImbK)E z5|JZ__25?AtvvSjC$BRMRr%x@IAH@5;0epwa^L z4#xH9Gp61UKhmQwn0=(G0*y|MA`pQOIs%kU4;%<0M2ftaM*^&$Eg(tL42xKz7^d17 zsR(WT1k6SXUaIXPI)c-NIBkg2Fu*DFe?9klALt?22Ji>m CUt1ag diff --git a/src/com/platform/controller/DefaultController.java b/src/com/platform/controller/DefaultController.java index 4722c5d6..ab8070bd 100644 --- a/src/com/platform/controller/DefaultController.java +++ b/src/com/platform/controller/DefaultController.java @@ -4,6 +4,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @@ -11,18 +12,30 @@ import com.platform.utils.Configs; @Controller public class DefaultController { - @RequestMapping("/") - public ModelAndView defaultHandler(HttpServletRequest req, HttpServletResponse res){ + + + @RequestMapping("/tes") + public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) { //处理不匹配的请求 - System.out.println("index"); - return new ModelAndView("index"); - + try { + + System.out.println("fsdfds"); + + return "listAll"; + } catch (Exception e) { + e.printStackTrace(); + + return "result"; + } + + } @RequestMapping("/test") - public void test(HttpServletRequest req, HttpServletResponse res){ + public ModelMap test(HttpServletRequest req, HttpServletResponse res){ //System.out.println(Class.class.getClass().getResource("/").getPath()); System.out.println(Configs.EXTRACT_LOG_LOCALTION); + return new ModelMap(); } } From 355e6a9b78f9d7beba31cd80a0e390d5baca72f4 Mon Sep 17 00:00:00 2001 From: lili Date: Thu, 8 Sep 2016 14:54:39 +0800 Subject: [PATCH 2/2] lili --- .classpath | 7 +- .gitignore | 1 + .project | 6 + .settings/org.eclipse.core.resources.prefs | 3 + .settings/org.eclipse.jdt.core.prefs | 94 ++++ .settings/org.eclipse.jpt.core.prefs | 3 + .settings/org.eclipse.m2e.core.prefs | 4 + ...se.wst.common.project.facet.core.prefs.xml | 7 + ....eclipse.wst.common.project.facet.core.xml | 1 + pom.xml | 37 ++ src/META-INF/persistence.xml | 5 + .../controller/SetGlusterfsController.java | 45 ++ .../controller/ShowGlusterfsController.java | 44 ++ src/com/platform/glusterfs/ClusterInfo.java | 86 +++ src/com/platform/glusterfs/CopyData.java | 71 +++ src/com/platform/glusterfs/GetTreeData.java | 62 +++ src/com/platform/glusterfs/RemoveData.java | 98 ++++ src/com/platform/glusterfs/SetCluster.java | 5 + src/com/platform/glusterfs/SetVolume.java | 493 ++++++++++++++++++ src/com/platform/glusterfs/ShowData.java | 104 ++++ src/com/platform/glusterfs/SizeInfo.java | 93 ++++ src/com/platform/glusterfs/VolumeInfo.java | 271 ++++++++++ .../service/OracleExtractService.java | 5 +- src/com/platform/utils/Constant.java | 19 + src/com/platform/utils/DateHandle.java | 9 + src/com/platform/utils/GanymedSSH.java | 265 ++++++++++ src/com/platform/utils/RunCommand.java | 60 +++ src/com/platform/utils/TestSupport.java | 14 + 28 files changed, 1908 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 .settings/org.eclipse.jpt.core.prefs create mode 100644 .settings/org.eclipse.m2e.core.prefs create mode 100644 .settings/org.eclipse.wst.common.project.facet.core.prefs.xml create mode 100644 pom.xml create mode 100644 src/META-INF/persistence.xml create mode 100644 src/com/platform/controller/SetGlusterfsController.java create mode 100644 src/com/platform/controller/ShowGlusterfsController.java create mode 100644 src/com/platform/glusterfs/ClusterInfo.java create mode 100644 src/com/platform/glusterfs/CopyData.java create mode 100644 src/com/platform/glusterfs/GetTreeData.java create mode 100644 src/com/platform/glusterfs/RemoveData.java create mode 100644 src/com/platform/glusterfs/SetCluster.java create mode 100644 src/com/platform/glusterfs/SetVolume.java create mode 100644 src/com/platform/glusterfs/ShowData.java create mode 100644 src/com/platform/glusterfs/SizeInfo.java create mode 100644 src/com/platform/glusterfs/VolumeInfo.java create mode 100644 src/com/platform/utils/Constant.java create mode 100644 src/com/platform/utils/DateHandle.java create mode 100644 src/com/platform/utils/GanymedSSH.java create mode 100644 src/com/platform/utils/RunCommand.java create mode 100644 src/com/platform/utils/TestSupport.java diff --git a/.classpath b/.classpath index bb361b44..2c740802 100644 --- a/.classpath +++ b/.classpath @@ -9,6 +9,11 @@ + + + + + - + diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..b83d2226 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/.project b/.project index ded1f1a4..aac312bb 100644 --- a/.project +++ b/.project @@ -25,8 +25,14 @@ + + org.eclipse.m2e.core.maven2Builder + + + + org.eclipse.m2e.core.maven2Nature org.eclipse.jem.workbench.JavaEMFNature org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.wst.common.project.facet.core.nature diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index d1ff3f7e..544ad1e4 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,2 +1,5 @@ eclipse.preferences.version=1 encoding//WebContent/WEB-INF/config/config.properties=UTF-8 +encoding//src/com/platform/utils/GanymedSSH.java=UTF-8 +encoding/=UTF-8 +separateDerivedEncodings=true diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index f42de363..68c704e1 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,7 +1,101 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore +org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore +org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedImport=warning +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.jpt.core.prefs b/.settings/org.eclipse.jpt.core.prefs new file mode 100644 index 00000000..4fd5f244 --- /dev/null +++ b/.settings/org.eclipse.jpt.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +org.eclipse.jpt.core.platform=generic2_1 +org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=false diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000..f897a7f1 --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml new file mode 100644 index 00000000..7961132f --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.prefs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index 6f8fb94f..f4228271 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -7,4 +7,5 @@ + diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..ad1b8ccd --- /dev/null +++ b/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + + extendGlusterfs + extendGlusterfs + 0.0.1-SNAPSHOT + jar + + extendGlusterfs + http://maven.apache.org + + + UTF-8 + + + + + log4j + log4j + 1.2.17 + + + junit + junit + 3.8.1 + test + + + + + ch.ethz.ganymed + ganymed-ssh2 + build209 + + + diff --git a/src/META-INF/persistence.xml b/src/META-INF/persistence.xml new file mode 100644 index 00000000..2ad4aeca --- /dev/null +++ b/src/META-INF/persistence.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/com/platform/controller/SetGlusterfsController.java b/src/com/platform/controller/SetGlusterfsController.java new file mode 100644 index 00000000..481331dd --- /dev/null +++ b/src/com/platform/controller/SetGlusterfsController.java @@ -0,0 +1,45 @@ + +/** + * 鏂囦欢鍚 : SetGlusterfs.java + * 鐗堟潈 : <鐗堟潈/鍏徃鍚> + * 鎻忚堪 : <鎻忚堪> + * @author liliy + * 鐗堟湰 : <鐗堟湰> + * 淇敼鏃堕棿锛 2016骞9鏈8鏃 + * 淇敼鍐呭锛 <淇敼鍐呭> + */ +package com.platform.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * <涓鍙ヨ瘽鍔熻兘绠杩> + * <鍔熻兘璇︾粏鎻忚堪> + * @author liliy + * @version [鐗堟湰鍙凤紝2016骞9鏈8鏃 + * @see [鐩稿叧绫/鏂规硶] + * @since [浜у搧/妯″潡鐗堟湰] + */ +@Controller +public class SetGlusterfsController { + @RequestMapping("/tes") + public Object defaultHandler(HttpServletRequest req, HttpServletResponse request) { + //锟斤拷锟?匹锟斤拷锟斤拷锟斤拷锟 + try { + + System.out.println("fsdfds"); + + return "listAll"; + } catch (Exception e) { + e.printStackTrace(); + + return "result"; + } + + + } +} diff --git a/src/com/platform/controller/ShowGlusterfsController.java b/src/com/platform/controller/ShowGlusterfsController.java new file mode 100644 index 00000000..83f6e468 --- /dev/null +++ b/src/com/platform/controller/ShowGlusterfsController.java @@ -0,0 +1,44 @@ + +/** + * 鏂囦欢鍚 : ShowGlusterfsController.java + * 鐗堟潈 : <鐗堟潈/鍏徃鍚> + * 鎻忚堪 : <鎻忚堪> + * @author liliy + * 鐗堟湰 : <鐗堟湰> + * 淇敼鏃堕棿锛 2016骞9鏈8鏃 + * 淇敼鍐呭锛 <淇敼鍐呭> + */ +package com.platform.controller; + +import java.util.List; +import java.util.Map; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +import com.platform.glusterfs.ClusterInfo; + +/** + * <涓鍙ヨ瘽鍔熻兘绠杩> + * <鍔熻兘璇︾粏鎻忚堪> + * @author liliy + * @version [鐗堟湰鍙凤紝2016骞9鏈8鏃 + * @see [鐩稿叧绫/鏂规硶] + * @since [浜у搧/妯″潡鐗堟湰] + */ +@Controller +public class ShowGlusterfsController { + /** + * <涓鍙ヨ瘽鍔熻兘绠杩> + * <鍔熻兘璇︾粏鎻忚堪> + * @return + * @see [绫汇佺被#鏂规硶銆佺被#鎴愬憳] + */ + @RequestMapping("/showPeerStatus") + public Map showPeerStatus(){ + Map peer_status=new ClusterInfo().showClusterInfo(); + return peer_status; + } + + +} diff --git a/src/com/platform/glusterfs/ClusterInfo.java b/src/com/platform/glusterfs/ClusterInfo.java new file mode 100644 index 00000000..c23145e2 --- /dev/null +++ b/src/com/platform/glusterfs/ClusterInfo.java @@ -0,0 +1,86 @@ +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 ClusterInfo { + public static Logger log = Logger.getLogger(ClusterInfo.class); + + public Map showClusterInfo() { + log.info("get cluster info"); + Map peerIps = new HashMap(); + + /* + String command = "echo \"" + Constant.rootPasswd + "\"|sudo -S gluster peer status"; + RunCommand runCommand = new RunCommand(); + List reStrings = runCommand.runCommandWait(command); + */ + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, 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).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); + } + + } + return peerIps; + } + + + + public static void main(String[] args) { + PropertyConfigurator.configure("log4j.properties"); + System.out.println(new ClusterInfo().showClusterInfo()); + } +} diff --git a/src/com/platform/glusterfs/CopyData.java b/src/com/platform/glusterfs/CopyData.java new file mode 100644 index 00000000..c0eb2c23 --- /dev/null +++ b/src/com/platform/glusterfs/CopyData.java @@ -0,0 +1,71 @@ +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; + + + +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 = copyFolderFiles(sourceFolderName, destFolderName, fileName); + return status; + } + + /** + * -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 -r " + 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; + } + + + @Test + public void testCopyFolderFiles() { + PropertyConfigurator.configure("log4j.properties"); + copyFolderFiles("/home", "/home/ubuntu", "system_data"); + } +} diff --git a/src/com/platform/glusterfs/GetTreeData.java b/src/com/platform/glusterfs/GetTreeData.java new file mode 100644 index 00000000..89da4253 --- /dev/null +++ b/src/com/platform/glusterfs/GetTreeData.java @@ -0,0 +1,62 @@ +package com.platform.glusterfs; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.PropertyConfigurator; +import org.junit.Test; + +public class GetTreeData { + ShowData showData = new ShowData(); + + public GetTreeData() { + // TODO Auto-generated constructor stub + } + + public FileOrFolder getDatas(String name) { + FileOrFolder fileOrFolder = new FileOrFolder(name); + Map files = showData.showFolderData(name); + if(files==null || files.size()==0){ + return fileOrFolder; + } + fileOrFolder.isFolder = files.size(); + fileOrFolder.children = new ArrayList(); + for (Map.Entry entry : files.entrySet()) { + int number = Integer.parseInt(entry.getValue()); + if (number == 1) { + fileOrFolder.children.add(new FileOrFolder(entry.getKey(), number)); + } + if (number > 1) { + FileOrFolder temp=getDatas(name+"/"+entry.getKey()); + fileOrFolder.children.add(temp); + } + } + + return fileOrFolder; + } + public static void main(String[] args) { + GetTreeData getTreeData=new GetTreeData(); + FileOrFolder fileOrFolder=getTreeData.getDatas("/home"); + 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; + } +} + + diff --git a/src/com/platform/glusterfs/RemoveData.java b/src/com/platform/glusterfs/RemoveData.java new file mode 100644 index 00000000..2297ed03 --- /dev/null +++ b/src/com/platform/glusterfs/RemoveData.java @@ -0,0 +1,98 @@ +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); + public int deleteVolumeFiles(String volumeName,String fileName){ + log.info("start delete "+volumeName+" "+fileName); + int status=-1; + /** + * get mount point of volumeName + */ + String folderName=volumeName; + + status=deleteFolderFiles(folderName,fileName); + return status; + } + + /** + * -1 :error; 0: the filename is not exists ; 1: right + * @param folderName + * @param fileName + * @return + */ + public int deleteFolderFiles(String folderName,String fileName){ + log.info("start delete "+folderName+"/"+fileName); + + ShowData showData=new ShowData(); + Map reStrings=showData.showFolderData(folderName+"/"+fileName); + + if(reStrings==null){ + log.error("3301 "+folderName+"/"+fileName+" is not exists"); + return -1; + } + + String command="rm -r "+folderName+"/"+fileName; + +// int status=runCommand.runCommand(command); + Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); + + log.info("delete "+folderName+" "+fileName+" running"); + return 1; + } + + public int getFolderSize(String name) { + log.info("get "+name+" size"); + String command="du -k -d 0 "+name; + /* + * RunCommand runCommand=new RunCommand(); + + List reStrings=runCommand.runCommandWait(command); + */ + List reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(command); + + if(reStrings==null){ + log.error("3302 the "+command+" return error"); + return -1; + } + if(reStrings.size()<1){ + log.error("3303 the "+command+" return error"); + return -1; + } + + if(reStrings.size()==1 && reStrings.get(0).contains("No such file or directory")){ + log.info("3304 "+name+" is not exists"); + return 0; + } + String strSize=(reStrings.get(0).split("\t"))[0]; + int size=Integer.parseInt(strSize); + log.info(name +" size is "+size); + return size; + } + +// @Test + public void test_getFolderSize() { + PropertyConfigurator.configure("log4j.properties"); + getFolderSize("/home/ubuntu"); + } + + @Test + public void testDeleteFolderFiles() { + PropertyConfigurator.configure("log4j.properties"); + deleteFolderFiles("/home/ubuntu","system_data"); + } + +} diff --git a/src/com/platform/glusterfs/SetCluster.java b/src/com/platform/glusterfs/SetCluster.java new file mode 100644 index 00000000..ccc3a76f --- /dev/null +++ b/src/com/platform/glusterfs/SetCluster.java @@ -0,0 +1,5 @@ +package com.platform.glusterfs; + +public class SetCluster { + +} diff --git a/src/com/platform/glusterfs/SetVolume.java b/src/com/platform/glusterfs/SetVolume.java new file mode 100644 index 00000000..d6be2d41 --- /dev/null +++ b/src/com/platform/glusterfs/SetVolume.java @@ -0,0 +1,493 @@ + +/** + * @author 鏉庝咕鍧 + * 杩涜volume鐨勪竴绯诲垪鎿嶄綔锛屽鍒涘缓銆佸紑鍚仠姝olume锛屼负volume娣诲姞鎴栧垹闄rick + */ +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 SetVolume { + public static Logger log = Logger.getLogger(SetVolume.class); + + /* + * 鍒涘缓volume 杩斿洖鍊硷細鍒涘缓骞舵寕杞芥垚鍔 1 + * + */ + 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; + // 灏哹rics浠嶭ist鍙橀噺涓彁鍙栧嚭鏉ュ苟杩炴帴鎴愬彲浠ュ湪鍛戒护琛屼腑浣跨敤鐨勬牸寮 + 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.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, 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!"); + if ((new ShowData().showFolderData(mountPoint)) == null) { + Constant.ganymedSSH.execCmdWaitAcquiescent("mkdir " + mountPoint); + } + // 杩涜鎸傝浇 + String command3 = "mount -t glusterfs " + Constant.hostIp + ":/" + volumeName + " " + mountPoint; + List reStrings3 = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, + Constant.rootPasswd, Constant.port, command3); + + // 杩欓噷闇瑕佹坊鍔犺В鏋愭寕杞藉懡浠よ繑鍥炲瓧绗︿覆鐨勮鍙ワ紝鐢变簬鎴戠殑绯荤粺鏈夐棶棰橈紝瀵艰嚧鎸傝浇鎴愬姛鍚庤繑鍥濿ARNING: getfattr + // not found, certain checks will be skipped.. + // 鎵浠ヨ繖鍙ヤ唬鐮佹湭缁忔祴璇 + // 鎴愬姛鎸傝浇鏃舵病鏈変换浣曡繑鍥炰俊鎭 + if (reStrings3.size() == 0 || reStrings.get(0).contains("GlusterFS is already mounted")) + { + log.info("mount point successed!"); + 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 + * + * @param volumeName + * @return 1 琛ㄧず鎴愬姛 锛-1琛ㄧずvolume name涓嶅瓨鍦紱-2琛ㄧず鍋滄volume 澶辫触 + */ + public int deleteVolume(String volumeName) { + int status = 0; + List volumeNames = new VolumeInfo().showAllVolumeName(); + if (!volumeNames.contains(volumeName)) { + log.error("3801 " + volumeName + " is not exists !"); + return -1; + } + + String mountPoint = new VolumeInfo().getVolumeMountPoint(volumeName); + if (stopVolume(volumeName) != 0) { + log.error("3802 " + volumeName + " stop failed !"); + return -2; + } + log.info("stop "+volumeName+" successed!"); + if (mountPoint != null) { + String command = "umount " + mountPoint; + Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); + log.info("umount "+mountPoint+" successed!"); + } + 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!"); + return 1; + } + + /* + * 涓烘寚瀹氱殑volume娣诲姞brick,鍙傛暟涓渶瑕佹寚瀹氱被鍨嬨佹暟閲忕瓑 杩斿洖鍊硷細1鎴愬姛 ;鍏朵粬澶辫触 + * 杩囩▼涓渶瑕佸厛妫鏌olume鏄惁瀛樺湪锛岃繕闇妫鏌ョ粰鍑虹殑brick鏁伴噺涓庣被鍨嬨乧ount鏄惁鐩哥 + */ + public int addBrickVolume(String volumeName, List brickName, int count, String type) { + // 妫鏌ユ槸鍚︽弧瓒虫坊鍔燽ricks鐨勬潯浠 + 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.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + + // 娣诲姞鎴愬姛鐨勮繑鍥炰俊鎭槸锛歷olume 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 鎴愬姛 ;鍏朵粬 澶辫触 + * 杩囩▼涓渶瑕佸厛妫鏌olume鏄惁瀛樺湪锛岃繕闇妫鏌ョ粰鍑虹殑brick鏁伴噺涓庣被鍨嬨乧ount鏄惁鐩哥 + */ + 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.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + // System.out.println(reStrings); + log.info("鍒犻櫎鍛戒护鎵ц瀹屾瘯"); + + // 鍒犻櫎鎴愬姛鐨勮繑鍥炰俊鎭槸鈥渧olume 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 澶辫触 + * 闇瑕佸厛妫鏌olume鏄惁瀛樺湪锛岀劧鍚庡垽鏂璿olume鐨勭姸鎬佹槸鍚﹀凡缁忔槸鍋滄鐘舵 + */ + public int stopVolume(String volumeName) { + log.info("stop volume"); + + // 棣栧厛闇瑕佸垽鏂璿olume鏄惁瀛樺湪锛岃皟鐢ㄥ叾浠栧嚱鏁拌繑鍥炴墍鏈塿olume鐨勫悕瀛 + 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鐨勭姸鎬佹槸鍚﹀凡缁忎负鈥渟top鈥 + 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 -1; + } else { + String command = "echo -e \"y\"| gluster volume stop " + volumeName; + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, command); + + // 鏍囪鎿嶄綔缁撴灉锛歰peration = 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; + } + + } + } + } + + /* + * 寮鍚寚瀹歷olume 鍙傛暟涓渶缁欏嚭volume鐨勫悕瀛 杩斿洖鍊硷細 0 鎴愬姛 -1 澶辫触 + * 闇瑕佸厛妫鏌olume鏄惁瀛樺湪锛岀劧鍚庡垽鏂璿olume鐨勭姸鎬佹槸鍚﹀凡缁忔槸寮鍚姸鎬 + */ + 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.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, 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鐨勪綅缃粍瑁呮垚鍙互鍦╣lusterfs鍛戒护琛屼腑鐩存帴浣跨敤鐨勬牸寮 + 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锛歜rick鐨刬p涓嶅湪闆嗙兢涓垨鑰呮湭杩炴帴; -2 -3 + * -4 :绫诲瀷涓巄rick鏁扮洰涓嶅尮閰 ; -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; + } + + /** + * 娣诲姞鎴栧垹闄olume鐨刡rick鏃讹紝棣栧厛闇瑕佸垽鏂璿olume鏄惁瀛樺湪锛岀劧鍚庨渶瑕佸垽鏂璿olume绫诲瀷銆乧ount鍙奲rick鏁扮洰 + * + * @param volumeName + * @param count + * @param type + * @param bricks + * @return 1 婊¤冻鏉′欢锛屽彲浠ユ坊鍔;-1 :volume name is not exists;-2,-3,-4 绫诲瀷涓巄rick鏁伴噺涓嶅尮閰嶏紱 + */ + 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; + } + + 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:/v1"); + bricksToCreate.add("192.168.0.116:/v1"); + operation = setVolume.createVolume("v1", 0, "distributed", bricksToCreate, "/home/v1_point"); +// operation = setVolume.deleteVolume("v3"); + // + // // 浠ヤ笅鏄祴璇曟坊鍔燽rick鐨勪唬鐮 + // + // List bricksToAdd = new ArrayList(); + // bricksToAdd.add("192.168.191.23:/v3"); + // operation = setVolume.addBrickVolume("v3", bricksToAdd, 0, + // "distribute"); + // System.out.println(operation); + + // 浠ヤ笅浠g爜鏄祴璇曞垹闄rick鐨勪唬鐮 + // List bricksToAdd= new ArrayList(); + // bricksToAdd.add("192.168.191.23:/v3"); + // operation = + // setVolume.deleteBrickVolume("v3",bricksToAdd,0,"distribute"); + // System.out.println(operation); + // 浠ヤ笅鏄祴璇晄tart volume鐨勪唬鐮 + // String volumeToStart = "testcreate" ; + // int startOperation = startVolume(volumeToStart); + // System.out.println(startOperation); + // 浠ヤ笅鏄祴璇晄top volume + String volumeToStop = "v3"; + // int startOperation = setVolume.stopVolume(volumeToStop); + // 浠ヤ笅鏄祴璇曞垱寤簐olume骞跺畬鎴愭寕杞界殑浠g爜 + // 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 new file mode 100644 index 00000000..919f7c7a --- /dev/null +++ b/src/com/platform/glusterfs/ShowData.java @@ -0,0 +1,104 @@ +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 + */ + + + 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.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, 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; + } + + + /** + * + * <涓鍙ヨ瘽鍔熻兘绠杩> + * <鍔熻兘璇︾粏鎻忚堪> + * @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 new file mode 100644 index 00000000..1aad2969 --- /dev/null +++ b/src/com/platform/glusterfs/SizeInfo.java @@ -0,0 +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锛氭病鏈塿olume long锛歴ize澶у皬 + * @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锛氭病鏈塿olume long锛歴ize澶у皬 + */ + 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 new file mode 100644 index 00000000..af6a37d6 --- /dev/null +++ b/src/com/platform/glusterfs/VolumeInfo.java @@ -0,0 +1,271 @@ +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; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class VolumeInfo { + public static Logger log = Logger.getLogger(VolumeInfo.class); + + public List showAllVolumeName() { + log.info("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.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, 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; + + } + + public String getVolumeType(String volumeName) { + log.info("get volume type"); + String volType = ""; + + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S gluster volume info " + + * volumeName + "|grep ^Type"; RunCommand runCommand = new RunCommand(); + * List reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, 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; + } + + public String getVolumeStatus(String volumeName) { + log.info("get volume status"); + String volStatus = ""; + + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S gluster volume info " + + * volumeName + "|grep ^Status"; RunCommand runCommand = new + * RunCommand(); List reStrings = + * runCommand.runCommandWait(command); <<<<<<< HEAD + */ + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.glusterVolumeInfo + "|grep ^Status"); + // 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).split(":")[0].contains("Status"))) { + log.error("1703 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; + } + + public Double getVolumeAllSize(String volumeName) { + log.info("get volume allSize"); + Double allSize = null; + /* + * ======= // waiting for testing... public Double + * getVolumeAllSize(String volumeName) { log.info("get volume allSize"); + * Double allSize = null; + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + + * "|awk '{print $2}'"; RunCommand runCommand = new RunCommand(); + * List reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $2}'"); + // System.out.println(reStrings); + if(reStrings==null){ + log.error("1801 get result is null"); + return null; + } + if(reStrings.size()==0){ + log.error("1802 get result is nothing"); + return null; + } + char flag = reStrings.get(0).trim().toCharArray()[0]; + if (flag < 48 || flag > 57) { + log.error("1803 get result string wrong"); + return null; + } + + for (Iterator it = reStrings.iterator(); it.hasNext();) { + String line = (String) it.next(); + String str[] = line.split("[^0-9]"); + allSize = Double.parseDouble(str[0]); + } + + return allSize; + } + + public Double getVolumeUseSize(String volumeName) { + log.info("get volume used size"); + Double usedSize = null; + + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + + * "|awk '{print $3}'"; RunCommand runCommand = new RunCommand(); + * List reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $3}'"); + // 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; + } + char flag = reStrings.get(0).trim().toCharArray()[0]; + if (flag < 48 || flag > 57) { + log.error("1903 get result string wrong"); + return null; + } + + for (Iterator it = reStrings.iterator(); it.hasNext();) { + String line = (String) it.next(); + String str[] = line.split("[^0-9]"); + + usedSize = Double.parseDouble(str[0]); + } + + return usedSize; + } + + public String getVolumeMountPoint(String volumeName) { + log.info("get volume mountPoint"); + // String mountPoint = ""; + + /* + * ======= + * + * >>>>>>> origin/AlexKie String command = "echo \"" + + * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + + * "|awk '{print $6}'"; RunCommand runCommand = new RunCommand(); + * List reStrings = runCommand.runCommandWait(command); <<<<<<< + * HEAD + */ + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, + Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $6}'"); + // 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 no mountpoint"); + return null; + } + + char flag = reStrings.get(0).trim().toCharArray()[0]; + if (flag != '/') { + log.error("11003 get result string wrong"); + return null; + } + + Iterator it = reStrings.iterator(); + String mountPoint = (String) it.next(); + mountPoint=mountPoint.replaceAll(" ", ""); + return mountPoint; + } + + public static void main(String[] args) { + PropertyConfigurator.configure("log4j.properties"); + + System.out.println(new VolumeInfo().showAllVolumeName()); + System.out.println(new VolumeInfo().getVolumeType("v1")); + + System.out.println(new VolumeInfo().getVolumeStatus("v1")); + System.out.println(new VolumeInfo().getVolumeMountPoint("v1")); + + System.out.println(new VolumeInfo().getVolumeAllSize("v1")); + System.out.println(new VolumeInfo().getVolumeUseSize("v1")); + + } +} diff --git a/src/com/platform/service/OracleExtractService.java b/src/com/platform/service/OracleExtractService.java index cd64be1f..9b858706 100644 --- a/src/com/platform/service/OracleExtractService.java +++ b/src/com/platform/service/OracleExtractService.java @@ -6,7 +6,7 @@ import com.platform.entities.OracleConnectorParams; import com.platform.oracle.OracleConnector; import com.platform.utils.Configs; -public class OracleExtractService implements Runnable { +public class OracleExtractService extends Thread implements Runnable { private OracleConnectorParams ocp; private java.sql.Connection conn; @@ -15,11 +15,10 @@ public class OracleExtractService implements Runnable { String url = ""; this.conn=OracleConnector.ConnectionBuilder(url, Configs.GATHER_USER_NAME, Configs.GATHER_USER_PASSWORD); } - @Override public void run() { // TODO Auto-generated method stub - } + } } diff --git a/src/com/platform/utils/Constant.java b/src/com/platform/utils/Constant.java new file mode 100644 index 00000000..59c2b5ce --- /dev/null +++ b/src/com/platform/utils/Constant.java @@ -0,0 +1,19 @@ +package com.platform.utils; + +import java.util.List; + +public class Constant { + public static String rootUser = "root"; + public static String rootPasswd = "root"; + public static String hostIp = "192.168.0.116"; + public static int port = 22; + public static String glusterPeerStatus = "gluster peer status"; + public static String glusterVolumeInfo = "gluster volume info "; + public static String df = "df -k "; + public static String peerincluster_connected="PeerinCluster(Connected)"; + public static String distributed="distributed"; + public static String replica="replica"; + public static String stripe="stripe"; + public static String noVolume="No volumes present"; + public static GanymedSSH ganymedSSH=new GanymedSSH(hostIp, rootUser, rootPasswd, port); +} diff --git a/src/com/platform/utils/DateHandle.java b/src/com/platform/utils/DateHandle.java new file mode 100644 index 00000000..90ebb9d7 --- /dev/null +++ b/src/com/platform/utils/DateHandle.java @@ -0,0 +1,9 @@ +package com.platform.utils; +import java.util.Date; +import java.text.SimpleDateFormat; +public class DateHandle { +public static String getNow() { + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//璁剧疆鏃ユ湡鏍煎紡 + return df.format(new Date());// new Date()涓鸿幏鍙栧綋鍓嶇郴缁熸椂闂? +} +} diff --git a/src/com/platform/utils/GanymedSSH.java b/src/com/platform/utils/GanymedSSH.java new file mode 100644 index 00000000..54a7a84e --- /dev/null +++ b/src/com/platform/utils/GanymedSSH.java @@ -0,0 +1,265 @@ +package com.platform.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; + +import ch.ethz.ssh2.Connection; +import ch.ethz.ssh2.Session; +import ch.ethz.ssh2.StreamGobbler; + +import ch.ethz.ssh2.*; + + + +public class GanymedSSH { + public static Logger log = Logger.getLogger(GanymedSSH.class); + Connection conn; + + public boolean status = true;// 閿熻鍑ゆ嫹閿熸枻鎷烽敓琛楄揪鎷烽敓鏂ゆ嫹閿熸枻鎷烽敓闃跺埡锟 + + public GanymedSSH() { + // TODO Auto-generated constructor stub + + } + + public GanymedSSH(String host, String username, String password, int port) { + // TODO Auto-generated constructor stub + try { + conn = getOpenedConnection(host, username, password, port); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + + public Connection getOpenedConnection(String host, String username, String password, int port) + throws IOException { + + conn = new Connection(host, port); + conn.connect(); // make sure the connection is opened + boolean isAuthenticated = conn.authenticateWithPassword(username, password); + if (isAuthenticated == false) + throw new IOException("Authentication failed."); + return conn; + } + + public void execCmdNoWaitAcquiescent(String cmd) { + String host=Constant.hostIp; + String username=Constant.rootUser; + String password=Constant.rootPasswd; + int port=Constant.port; + + Session sess = null; + try { + conn = getOpenedConnection(host, username, password, port); + sess = conn.openSession(); + // 鎵ч敓鏂ゆ嫹cmd + sess.execCommand(cmd); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + } + + public void execCmdNoWait(String host, String username, String password, int port, String cmd) { + + Session sess = null; + try { + conn = getOpenedConnection(host, username, password, port); + sess = conn.openSession(); + // 鎵ч敓鏂ゆ嫹cmd + sess.execCommand(cmd); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + } + + public List execCmdWaitAcquiescent(String cmd) { + String host=Constant.hostIp; + String username=Constant.rootUser; + String password=Constant.rootPasswd; + int port=Constant.port; + List reStrings = new ArrayList(); + + Session sess = null; + try { + + sess = conn.openSession(); + // 鎵ч敓鏂ゆ嫹cmd + sess.execCommand(cmd); + + InputStream stdout = new StreamGobbler(sess.getStdout()); + InputStream stderr = new StreamGobbler(sess.getStderr()); + BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); + BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); + while (true) { + String line = stdoutReader.readLine(); + + if (line != null) { +// System.out.println(line); + reStrings.add(line); + } else { + break; + } + } + + while (true) { + String line = stderrReader.readLine(); + + if (line != null) { +// System.out.println(line); + reStrings.add(line); + } else { + break; + } + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + return reStrings; + } + + public List execCmdWait(String host, String username, String password, int port, String cmd) { + List reStrings = new ArrayList(); + + Session sess = null; + try { + + sess = conn.openSession(); + // 鎵ч敓鏂ゆ嫹cmd + sess.execCommand(cmd); + + InputStream stdout = new StreamGobbler(sess.getStdout()); + InputStream stderr = new StreamGobbler(sess.getStderr()); + BufferedReader stdoutReader = new BufferedReader(new InputStreamReader(stdout)); + BufferedReader stderrReader = new BufferedReader(new InputStreamReader(stderr)); + while (true) { + String line = stdoutReader.readLine(); + + if (line != null) { +// System.out.println(line); + reStrings.add(line); + } else { + break; + } + } + + while (true) { + String line = stderrReader.readLine(); + + if (line != null) { +// System.out.println(line); + reStrings.add(line); + } else { + break; + } + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + return reStrings; + } + + public Map execMD5cmd(String host, String username, String password, int port, String cmd, + String prefix) { + Map md5 = new HashMap(); + + + Session sess = null; + try { + + sess = conn.openSession(); + // 鎵ч敓鏂ゆ嫹cmd + sess.execCommand(cmd); + InputStream stdout = new StreamGobbler(sess.getStdout()); + + @SuppressWarnings("resource") + BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); + while (true) { + String line = br.readLine(); + if (line != null) { + String[] lines = line.split(" "); + String key = lines[1].replace(prefix, ""); + String value = lines[0]; + md5.put(key, value); + // System.out.println(key+"\t"+value); + } else { + break; + } + + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + + } + return md5; + } + + public String execGetSize(String cmd) { + status = false; + String str_size = "0"; + Session sess = null; + try { + + // 鎵ч敓鏂ゆ嫹cmd + sess = conn.openSession(); + sess.execCommand(cmd); + InputStream stdout = new StreamGobbler(sess.getStdout()); + + @SuppressWarnings("resource") + BufferedReader br = new BufferedReader(new InputStreamReader(stdout)); + while (true) { + String line = br.readLine(); + if (line != null) { + // String[] lines=line.split(" "); + // str_size=lines[0]; + + str_size = line; + } else { + break; + } + + } + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + sess.close(); + } + status = true; + return str_size; + } + public static void main(String[] args) { + PropertyConfigurator.configure("log4j.properties"); + } + +} diff --git a/src/com/platform/utils/RunCommand.java b/src/com/platform/utils/RunCommand.java new file mode 100644 index 00000000..66292a2a --- /dev/null +++ b/src/com/platform/utils/RunCommand.java @@ -0,0 +1,60 @@ +package com.platform.utils; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import org.apache.log4j.*; + +public class RunCommand { + + + public static Logger log = Logger.getLogger(RunCommand.class); + + public List runCommandWait(String command) { + List reStrings = null; + String cmds[] = { "/bin/bash", "-c", command }; + try { + Process ps = Runtime.getRuntime().exec(cmds); + ps.waitFor(); + BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream())); + reStrings = new ArrayList(); + String line; + while ((line = br.readLine()) != null) { + reStrings.add(line); + // System.out.println(line); + } + + br = new BufferedReader(new InputStreamReader(ps.getErrorStream())); + reStrings = new ArrayList(); + + while ((line = br.readLine()) != null) { + reStrings.add(line); + // System.out.println(line); + } + } catch (Exception e) { + + log.error("0001 runCommandWait is error"); + + e.printStackTrace(); + } + return reStrings; + } + + public int runCommand(String command) { + List reStrings = null; + String cmds[] = { "/bin/bash", "-c", command }; + try { + Process ps = Runtime.getRuntime().exec(cmds); + } catch (Exception e) { + + log.error("0002 runCommand execute " + command + " is error"); + + e.printStackTrace(); + return -1; + } + return 1; + } + + +} diff --git a/src/com/platform/utils/TestSupport.java b/src/com/platform/utils/TestSupport.java new file mode 100644 index 00000000..74d938cb --- /dev/null +++ b/src/com/platform/utils/TestSupport.java @@ -0,0 +1,14 @@ +package com.platform.utils; + +import java.util.ArrayList; +import java.util.List; + +public class TestSupport { +public List strToList(String str) { + List reStrings=new ArrayList(); + for(String one:str.split("\n")){ + reStrings.add(one); + } + return reStrings; +} +}