parent
5bd29da12e
commit
b32e3c6e07
Binary file not shown.
@ -1,2 +1 @@
|
|||||||
/com
|
/com/
|
||||||
/spring-applicationContext-test.xml
|
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -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,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