parent
6e68a67686
commit
355e6a9b78
@ -0,0 +1 @@
|
|||||||
|
/target/
|
@ -1,2 +1,5 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
encoding//WebContent/WEB-INF/config/config.properties=UTF-8
|
encoding//WebContent/WEB-INF/config/config.properties=UTF-8
|
||||||
|
encoding//src/com/platform/utils/GanymedSSH.java=UTF-8
|
||||||
|
encoding/<project>=UTF-8
|
||||||
|
separateDerivedEncodings=true
|
||||||
|
@ -1,7 +1,101 @@
|
|||||||
eclipse.preferences.version=1
|
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.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.targetPlatform=1.7
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
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.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.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
|
org.eclipse.jdt.core.compiler.source=1.7
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jpt.core.platform=generic2_1
|
||||||
|
org.eclipse.jpt.jpa.core.discoverAnnotatedClasses=false
|
@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
@ -0,0 +1,7 @@
|
|||||||
|
<root>
|
||||||
|
<facet id="jpt.jpa">
|
||||||
|
<node name="libprov">
|
||||||
|
<attribute name="provider-id" value="jpa-no-op-library-provider"/>
|
||||||
|
</node>
|
||||||
|
</facet>
|
||||||
|
</root>
|
@ -0,0 +1,37 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>extendGlusterfs</groupId>
|
||||||
|
<artifactId>extendGlusterfs</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>extendGlusterfs</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/ch.ethz.ganymed/ganymed-ssh2 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.ethz.ganymed</groupId>
|
||||||
|
<artifactId>ganymed-ssh2</artifactId>
|
||||||
|
<version>build209</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
|
||||||
|
<persistence-unit name="aggregation-platform">
|
||||||
|
</persistence-unit>
|
||||||
|
</persistence>
|
@ -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<String, String> showClusterInfo() {
|
||||||
|
log.info("get cluster info");
|
||||||
|
Map<String, String> peerIps = new HashMap<String, String>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
String command = "echo \"" + Constant.rootPasswd + "\"|sudo -S gluster peer status";
|
||||||
|
RunCommand runCommand = new RunCommand();
|
||||||
|
List<String> reStrings = runCommand.runCommandWait(command);
|
||||||
|
*/
|
||||||
|
List<String> 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());
|
||||||
|
}
|
||||||
|
}
|
@ -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<String,String> 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<String> 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");
|
||||||
|
}
|
||||||
|
}
|
@ -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<String, String> files = showData.showFolderData(name);
|
||||||
|
if(files==null || files.size()==0){
|
||||||
|
return fileOrFolder;
|
||||||
|
}
|
||||||
|
fileOrFolder.isFolder = files.size();
|
||||||
|
fileOrFolder.children = new ArrayList<FileOrFolder>();
|
||||||
|
for (Map.Entry<String, String> 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<FileOrFolder> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -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<String,String> 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<String> reStrings=runCommand.runCommandWait(command);
|
||||||
|
*/
|
||||||
|
List<String> 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.platform.glusterfs;
|
||||||
|
|
||||||
|
public class SetCluster {
|
||||||
|
|
||||||
|
}
|
@ -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<string s1,string s2> s1 is data name and s2 is type file or folder
|
||||||
|
* @param volumeName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public Map<String,String> showVolumeFiles(String volumeName){
|
||||||
|
log.info("start show the data");
|
||||||
|
Map<String,String> data_type=new HashMap<String, String>();
|
||||||
|
/**
|
||||||
|
* get mount point of volumeName
|
||||||
|
*/
|
||||||
|
String folderName=volumeName;
|
||||||
|
|
||||||
|
data_type=showFolderData(volumeName);
|
||||||
|
return data_type;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* get the data of folder name
|
||||||
|
* Map<String,String> is folder name and type 1 is file and others is folder
|
||||||
|
|
||||||
|
|
||||||
|
* @param FolderName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Map<String,String> showFolderData(String folderName){
|
||||||
|
log.info(" start get "+folderName+" data");
|
||||||
|
|
||||||
|
|
||||||
|
Map<String,String> data_type=new HashMap<String, String>();
|
||||||
|
String command="ls -l "+folderName;
|
||||||
|
|
||||||
|
/*
|
||||||
|
RunCommand runCommand=new RunCommand();
|
||||||
|
List<String> reStrings=runCommand.runCommandWait(command);
|
||||||
|
*/
|
||||||
|
List<String> 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"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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<String> showAllVolumeName() {
|
||||||
|
log.info("get volume name");
|
||||||
|
List<String> volNames = new ArrayList<String>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* String command = "echo \"" + Constant.rootPasswd +
|
||||||
|
* "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand
|
||||||
|
* runCommand = new RunCommand(); List<String> reStrings =
|
||||||
|
* runCommand.runCommandWait(command);
|
||||||
|
*/
|
||||||
|
List<String> 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<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
||||||
|
* HEAD
|
||||||
|
*/
|
||||||
|
List<String> 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<String> reStrings =
|
||||||
|
* runCommand.runCommandWait(command); <<<<<<< HEAD
|
||||||
|
*/
|
||||||
|
List<String> 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<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
||||||
|
* HEAD
|
||||||
|
*/
|
||||||
|
List<String> 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<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
||||||
|
* HEAD
|
||||||
|
*/
|
||||||
|
List<String> 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<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
||||||
|
* HEAD
|
||||||
|
*/
|
||||||
|
List<String> 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"));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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<String> runCommandWait(String command) {
|
||||||
|
List<String> 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>();
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
reStrings.add(line);
|
||||||
|
// System.out.println(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
br = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
|
||||||
|
reStrings = new ArrayList<String>();
|
||||||
|
|
||||||
|
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<String> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.platform.utils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TestSupport {
|
||||||
|
public List<String> strToList(String str) {
|
||||||
|
List<String> reStrings=new ArrayList<String>();
|
||||||
|
for(String one:str.split("\n")){
|
||||||
|
reStrings.add(one);
|
||||||
|
}
|
||||||
|
return reStrings;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue