|
|
@ -1,334 +1,422 @@
|
|
|
|
package com.platform.glusterfs;
|
|
|
|
|
|
|
|
|
|
|
|
package com.platform.glusterfs;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
|
|
import org.apache.log4j.PropertyConfigurator;
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.apache.log4j.PropertyConfigurator;
|
|
|
|
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
|
|
|
|
import com.platform.utils.Constant;
|
|
|
|
|
|
|
|
import com.platform.utils.GanymedSSH;
|
|
|
|
import com.platform.utils.Constant;
|
|
|
|
|
|
|
|
import com.platform.utils.GanymedSSH;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
public class VolumeInfo {
|
|
|
|
|
|
|
|
public static Logger log = Logger.getLogger(VolumeInfo.class);
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取volume信息 <功能详细描述>
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* 显示所有volume名称
|
|
|
|
* @author liliy
|
|
|
|
* <功能详细描述>
|
|
|
|
* @version [版本号,2016年9月13日]
|
|
|
|
* @return
|
|
|
|
* @see [相关类/方法]
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
* @since [产品/模块版本]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public List<String> showAllVolumeName() {
|
|
|
|
public class VolumeInfo {
|
|
|
|
log.info("get volume name");
|
|
|
|
public static Logger log = Logger.getLogger(VolumeInfo.class);
|
|
|
|
List<String> volNames = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/*
|
|
|
|
* 显示所有volume名称 <功能详细描述>
|
|
|
|
* String command = "echo \"" + Constant.rootPasswd +
|
|
|
|
*
|
|
|
|
* "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand
|
|
|
|
* @return
|
|
|
|
* runCommand = new RunCommand(); List<String> reStrings =
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
* runCommand.runCommandWait(command);
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public List<String> showAllVolumeName() {
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
|
|
|
|
log.info("get volume name");
|
|
|
|
Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + "|grep ^Volume.Name");
|
|
|
|
List<String> volNames = new ArrayList<String>();
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
/*
|
|
|
|
log.error("1401 get result is null");
|
|
|
|
* String command = "echo \"" + Constant.rootPasswd +
|
|
|
|
return null;
|
|
|
|
* "\" |sudo -S gluster volume info|grep ^Volume.Name"; RunCommand
|
|
|
|
}
|
|
|
|
* runCommand = new RunCommand(); List<String> reStrings =
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
* runCommand.runCommandWait(command);
|
|
|
|
log.error("1402 get result is nothing");
|
|
|
|
*/
|
|
|
|
return null;
|
|
|
|
List<String> reStrings = Constant.ganymedSSH
|
|
|
|
}
|
|
|
|
.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + "|grep ^Volume.Name");
|
|
|
|
if (reStrings.get(0).contains(Constant.noVolume)) {
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
reStrings.clear();
|
|
|
|
if (reStrings == null) {
|
|
|
|
return reStrings;
|
|
|
|
log.error("1401 get result is null");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) {
|
|
|
|
}
|
|
|
|
log.error("1403 get result string wrong");
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
return null;
|
|
|
|
log.error("1402 get result is nothing");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
String nameInfo = "";
|
|
|
|
if (reStrings.get(0).contains(Constant.noVolume)) {
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
reStrings.clear();
|
|
|
|
String line = (String) it.next();
|
|
|
|
return reStrings;
|
|
|
|
String str[] = line.split(":");
|
|
|
|
}
|
|
|
|
volNames.add(str[1].replaceAll(" ", ""));
|
|
|
|
if (!(reStrings.get(0).split(":")[0].contains("Volume Name"))) {
|
|
|
|
}
|
|
|
|
log.error("1403 get result string wrong");
|
|
|
|
return volNames;
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String nameInfo = "";
|
|
|
|
/**
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
* 给定参数volume的名称获得volume的类型
|
|
|
|
String line = (String) it.next();
|
|
|
|
* <功能详细描述>
|
|
|
|
String str[] = line.split(":");
|
|
|
|
* @param volumeName
|
|
|
|
volNames.add(str[1].replaceAll(" ", ""));
|
|
|
|
* @return
|
|
|
|
}
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
return volNames;
|
|
|
|
*/
|
|
|
|
|
|
|
|
public String getVolumeType(String volumeName) {
|
|
|
|
}
|
|
|
|
log.info("get volume type");
|
|
|
|
|
|
|
|
String volType = "";
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 给定参数volume的名称获得volume的类型 <功能详细描述>
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
|
|
|
|
*
|
|
|
|
Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
|
|
|
|
* @param volumeName
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
* @return
|
|
|
|
if (reStrings == null) {
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
log.error("1501 get result is null");
|
|
|
|
*/
|
|
|
|
return null;
|
|
|
|
public String getVolumeType(String volumeName) {
|
|
|
|
}
|
|
|
|
log.info("get volume type");
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
String volType = "";
|
|
|
|
log.error("1502 get result is nothing");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
List<String> reStrings = Constant.ganymedSSH
|
|
|
|
}
|
|
|
|
.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
|
|
|
|
if (!(reStrings.get(0).split(":")[0].contains("Type"))) {
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
log.error("1503 get result string wrong");
|
|
|
|
if (reStrings == null) {
|
|
|
|
return null;
|
|
|
|
log.error("1501 get result is null");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
|
|
|
|
log.error("1502 get result is nothing");
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
return null;
|
|
|
|
String line = (String) it.next();
|
|
|
|
}
|
|
|
|
String str[] = line.split(":");
|
|
|
|
if (!(reStrings.get(0).split(":")[0].contains("Type"))) {
|
|
|
|
volType = str[1];
|
|
|
|
log.error("1503 get result string wrong");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
volType = volType.replaceAll(" ", "");
|
|
|
|
}
|
|
|
|
return volType;
|
|
|
|
|
|
|
|
}
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
|
|
|
|
|
|
|
public String getVolumeStatus(String volumeName) {
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
log.info("get volume status");
|
|
|
|
String line = (String) it.next();
|
|
|
|
String volStatus = "";
|
|
|
|
String str[] = line.split(":");
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
|
|
|
|
volType = str[1];
|
|
|
|
Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + "|grep ^Status");
|
|
|
|
}
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
volType = volType.replaceAll(" ", "");
|
|
|
|
if (reStrings == null) {
|
|
|
|
return volType;
|
|
|
|
log.error("1701 get result is null");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
* 获取volumeName的状态 如果出错返回null,如果volumeName不存在则返回Volume volumeName does not
|
|
|
|
log.error("1702 get result is nothing");
|
|
|
|
* exist,正常返回状态Started,Stopped,Created
|
|
|
|
return null;
|
|
|
|
*
|
|
|
|
}
|
|
|
|
* @param volumeName
|
|
|
|
if (!(reStrings.get(0).split(":")[0].contains("Status"))) {
|
|
|
|
* @return
|
|
|
|
log.error("1703 get result string wrong");
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
return null;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
public String getVolumeStatus(String volumeName) {
|
|
|
|
|
|
|
|
log.info("get volume status");
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
String volStatus = "";
|
|
|
|
String line = (String) it.next();
|
|
|
|
String cmd = Constant.glusterVolumeInfo + " " + volumeName + " |grep ^Status";
|
|
|
|
String str[] = line.split(":");
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
volStatus = str[1].replaceAll(" ", "");
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
}
|
|
|
|
if (reStrings == null) {
|
|
|
|
return volStatus;
|
|
|
|
log.error("1701 get result is null");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
public Double getVolumeAllSize(String volumeName) {
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
log.info("get volume allSize");
|
|
|
|
log.error("1702 get result is nothing");
|
|
|
|
Double allSize = null;
|
|
|
|
return null;
|
|
|
|
/*
|
|
|
|
}
|
|
|
|
* ======= // waiting for testing... public Double
|
|
|
|
|
|
|
|
* getVolumeAllSize(String volumeName) { log.info("get volume allSize");
|
|
|
|
if (reStrings.get(0).contains("does not exist")) {
|
|
|
|
* Double allSize = null;
|
|
|
|
log.error("1703 " + reStrings.get(0));
|
|
|
|
*
|
|
|
|
return reStrings.get(0);
|
|
|
|
* >>>>>>> origin/AlexKie String command = "echo \"" +
|
|
|
|
}
|
|
|
|
* Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName +
|
|
|
|
if (!(reStrings.get(0).split(":")[0].contains("Status"))) {
|
|
|
|
* "|awk '{print $2}'"; RunCommand runCommand = new RunCommand();
|
|
|
|
log.error("1704 get result string wrong");
|
|
|
|
* List<String> reStrings = runCommand.runCommandWait(command); <<<<<<<
|
|
|
|
return null;
|
|
|
|
* HEAD
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
|
|
|
String line = (String) it.next();
|
|
|
|
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $2}'");
|
|
|
|
String str[] = line.split(":");
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
volStatus = str[1].replaceAll(" ", "");
|
|
|
|
if(reStrings==null){
|
|
|
|
}
|
|
|
|
log.error("1801 get result is null");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return volStatus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(reStrings.size()==0){
|
|
|
|
|
|
|
|
log.error("1802 get result is nothing");
|
|
|
|
/**
|
|
|
|
return null;
|
|
|
|
* 获取volumeName的可用大小
|
|
|
|
}
|
|
|
|
* volumeName不存在返回-1,获取大小错误返回-2 ,正常返回volumeName的可用大小
|
|
|
|
char flag = reStrings.get(0).trim().toCharArray()[0];
|
|
|
|
* @param volumeName
|
|
|
|
if (flag < 48 || flag > 57) {
|
|
|
|
* @return
|
|
|
|
log.error("1803 get result string wrong");
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
return null;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
public Long getVolumeAvailableSize(String volumeName) {
|
|
|
|
|
|
|
|
log.info("get volume availableSize");
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
Long allSize = 0L;
|
|
|
|
String line = (String) it.next();
|
|
|
|
|
|
|
|
String str[] = line.split("[^0-9]");
|
|
|
|
String cmd = Constant.df + " | grep " + volumeName + "|awk '{print $4}'";
|
|
|
|
allSize = Double.parseDouble(str[0]);
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
}
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
return allSize;
|
|
|
|
log.error("1802 get result is error");
|
|
|
|
}
|
|
|
|
return -2L;
|
|
|
|
|
|
|
|
}
|
|
|
|
public Double getVolumeUseSize(String volumeName) {
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
log.info("get volume used size");
|
|
|
|
log.error("1801 " + volumeName + " is not exists!");
|
|
|
|
Double usedSize = null;
|
|
|
|
return -1L;
|
|
|
|
|
|
|
|
}
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
|
|
|
|
allSize = Long.parseLong(reStrings.get(0));
|
|
|
|
Constant.rootPasswd, Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $3}'");
|
|
|
|
return allSize;
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
}
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
|
|
|
log.error("1901 get result is null");
|
|
|
|
/**
|
|
|
|
return null;
|
|
|
|
* 获取volumeName已用空间
|
|
|
|
}
|
|
|
|
* volumeName不存在返回-1,获取大小错误返回-2 ,正常返回volumeName的已用的大小
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
* @param volumeName
|
|
|
|
log.error("1902 get result is nothing");
|
|
|
|
* @return
|
|
|
|
return null;
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
char flag = reStrings.get(0).trim().toCharArray()[0];
|
|
|
|
public Long getVolumeUseSize(String volumeName) {
|
|
|
|
if (flag < 48 || flag > 57) {
|
|
|
|
log.info("get volume used size");
|
|
|
|
log.error("1903 get result string wrong");
|
|
|
|
Long usedSize = 0L;
|
|
|
|
return null;
|
|
|
|
if (volumeIsExists(volumeName) == false) {
|
|
|
|
}
|
|
|
|
log.error("1901 " + volumeName + " is not exists!");
|
|
|
|
|
|
|
|
return -1L;
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
|
|
|
|
String line = (String) it.next();
|
|
|
|
}
|
|
|
|
String str[] = line.split("[^0-9]");
|
|
|
|
|
|
|
|
|
|
|
|
String cmd = "df | grep " + volumeName + "|awk '{print $3}'";
|
|
|
|
usedSize = Double.parseDouble(str[0]);
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
}
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
return usedSize;
|
|
|
|
log.error("1901 get result is null");
|
|
|
|
}
|
|
|
|
return -2L;
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
* @param volumeName
|
|
|
|
log.error("1902 " + volumeName + " is not exists!");
|
|
|
|
* @return String ipAndpath[] = brick.split(":");
|
|
|
|
return -1L;
|
|
|
|
String ip = ipAndpath[0];
|
|
|
|
}
|
|
|
|
String path = ipAndpath[1];
|
|
|
|
usedSize = Long.parseLong(reStrings.get(0));
|
|
|
|
*/
|
|
|
|
return usedSize;
|
|
|
|
public List<String> getVolumeBricks(String volumeName) {
|
|
|
|
}
|
|
|
|
log.info("get volume bricks");
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'";
|
|
|
|
* 获取volumeName的bricks
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
* 返回一个bircks的list ip:path,如果volumeName不存在返回null
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
* @param volumeName
|
|
|
|
if (reStrings == null) {
|
|
|
|
* @return
|
|
|
|
log.error("1601 get volume bricks wrong");
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
return null;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
public List<String> getVolumeBricks(String volumeName) {
|
|
|
|
|
|
|
|
log.info("get volume bricks");
|
|
|
|
return reStrings;
|
|
|
|
|
|
|
|
}
|
|
|
|
String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'";
|
|
|
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
public List<String> getVolumeMountPoint(String volumeName) {
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
log.info("get volume MountPoint");
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
|
|
|
log.error("1601 get volume bricks wrong");
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
|
|
|
return null;
|
|
|
|
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $6}'");
|
|
|
|
}
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
if (reStrings.size()==0) {
|
|
|
|
if(reStrings==null){
|
|
|
|
log.error("1602 "+volumeName+" is not exists!");
|
|
|
|
log.error("11001 get result string wrong");
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reStrings;
|
|
|
|
if(reStrings.size()==0){
|
|
|
|
}
|
|
|
|
log.error("11002 "+volumeName+" is no mountpoint");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
/**
|
|
|
|
}
|
|
|
|
* 获取volumeName所有挂载点
|
|
|
|
|
|
|
|
* <功能详细描述>
|
|
|
|
char flag = reStrings.get(0).trim().toCharArray()[0];
|
|
|
|
* @param volumeName
|
|
|
|
if (flag != '/') {
|
|
|
|
* @return
|
|
|
|
log.error("11003 get result string wrong");
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
return null;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
public List<String> getVolumeMountPoint(String volumeName) {
|
|
|
|
List<String> mountPoints = new ArrayList<>();
|
|
|
|
log.info("get volume MountPoint");
|
|
|
|
for(String mountPoint:reStrings){
|
|
|
|
List<String> mountPoints = new ArrayList<>();
|
|
|
|
mountPoint=mountPoint.replaceAll(" ", "");
|
|
|
|
String cmd=Constant.df + "|grep " + volumeName + "|awk '{print $6}'";
|
|
|
|
mountPoints.add(mountPoint);
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
}
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
return mountPoints;
|
|
|
|
if (reStrings == null) {
|
|
|
|
}
|
|
|
|
log.error("11001 get result string wrong");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
public Map<String, Double> getVolumebricksDataSize(String volumeName) {
|
|
|
|
}
|
|
|
|
List<String> bricks = getVolumeBricks(volumeName);
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
Map<String, Double> brick_size = new HashMap<>();
|
|
|
|
log.error("11002 " + volumeName + " is not exists or no mountpoint");
|
|
|
|
if (bricks == null) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String brick : bricks) {
|
|
|
|
// char flag = reStrings.get(0).trim().toCharArray()[0];
|
|
|
|
String ipAndpath[] = brick.split(":");
|
|
|
|
// if (flag != '/') {
|
|
|
|
String ip = ipAndpath[0];
|
|
|
|
// log.error("11003 get result string wrong");
|
|
|
|
String path = ipAndpath[1];
|
|
|
|
// return null;
|
|
|
|
String cmd = "du -d 0 " + path + "|awk '{print $1}'";
|
|
|
|
// }
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
|
|
|
|
|
|
|
|
Constant.port, cmd);
|
|
|
|
for (String mountPoint : reStrings) {
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
mountPoint = mountPoint.replaceAll(" ", "");
|
|
|
|
if (reStrings == null) {
|
|
|
|
mountPoints.add(mountPoint);
|
|
|
|
log.error("1901 get result is null");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return mountPoints;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
|
|
|
|
log.error("1902 get result is nothing");
|
|
|
|
public String getOneVolumeMountPoint(String volumeName) {
|
|
|
|
return null;
|
|
|
|
log.info("get one volume MountPoint");
|
|
|
|
}
|
|
|
|
|
|
|
|
Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
|
String mountPoint=null;
|
|
|
|
Matcher isNum = pattern.matcher(reStrings.get(0));
|
|
|
|
String cmd=Constant.df + "|grep " + volumeName + "|awk '{print $6}'";
|
|
|
|
if (!isNum.matches()) {
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
log.error("1903 " + reStrings.get(0) + " is unexpect");
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
return null;
|
|
|
|
if (reStrings == null) {
|
|
|
|
}
|
|
|
|
log.error("11001 get result string wrong");
|
|
|
|
brick_size.put(brick, Double.parseDouble(reStrings.get(0)));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return brick_size;
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
}
|
|
|
|
log.error("11002 " + volumeName + " is not exists or no mountpoint");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
public Map<String, Double> getVolumebricksAvailableSize(String volumeName) {
|
|
|
|
}
|
|
|
|
List<String> bricks = getVolumeBricks(volumeName);
|
|
|
|
|
|
|
|
Map<String, Double> brick_size = new HashMap<>();
|
|
|
|
// char flag = reStrings.get(0).trim().toCharArray()[0];
|
|
|
|
if (bricks == null) {
|
|
|
|
// if (flag != '/') {
|
|
|
|
return null;
|
|
|
|
// log.error("11003 get result string wrong");
|
|
|
|
}
|
|
|
|
// return null;
|
|
|
|
for (String brick : bricks) {
|
|
|
|
// }
|
|
|
|
String ipAndpath[] = brick.split(":");
|
|
|
|
|
|
|
|
String ip = ipAndpath[0];
|
|
|
|
mountPoint=reStrings.get(0);
|
|
|
|
String path = ipAndpath[1];
|
|
|
|
return mountPoint;
|
|
|
|
String cmd = "df " + path + "|awk '{print $4}'";
|
|
|
|
}
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
|
|
|
|
|
|
|
|
Constant.port, cmd);
|
|
|
|
/**
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
* 获取volumeName的所有brick中数据占用空间的大小
|
|
|
|
if (reStrings == null) {
|
|
|
|
* 返回一个map表示bricks和数据大小 <ip:path,data_size>
|
|
|
|
log.error("1901 get result is null");
|
|
|
|
* @param volumeName
|
|
|
|
return null;
|
|
|
|
* @return
|
|
|
|
}
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
*/
|
|
|
|
log.error("1902 get result is nothing");
|
|
|
|
public Map<String, Double> getVolumebricksDataSize(String volumeName) {
|
|
|
|
return null;
|
|
|
|
List<String> bricks = getVolumeBricks(volumeName);
|
|
|
|
}
|
|
|
|
Map<String, Double> brick_size = new HashMap<>();
|
|
|
|
Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
|
if (bricks == null) {
|
|
|
|
Matcher isNum = pattern.matcher(reStrings.get(1));
|
|
|
|
return null;
|
|
|
|
if (!isNum.matches()) {
|
|
|
|
}
|
|
|
|
log.error("1903 " + reStrings.get(1) + " is unexpect");
|
|
|
|
for (String brick : bricks) {
|
|
|
|
return null;
|
|
|
|
String ipAndpath[] = brick.split(":");
|
|
|
|
}
|
|
|
|
String ip = ipAndpath[0];
|
|
|
|
brick_size.put(brick, Double.parseDouble(reStrings.get(1)));
|
|
|
|
String path = ipAndpath[1];
|
|
|
|
}
|
|
|
|
String cmd = "du -d 0 " + path + "|awk '{print $1}'";
|
|
|
|
return brick_size;
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
|
|
|
|
}
|
|
|
|
Constant.port, cmd);
|
|
|
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
@Test
|
|
|
|
if (reStrings == null) {
|
|
|
|
public void test_getVolumebricksDataSize() {
|
|
|
|
log.error("1901 get result is null");
|
|
|
|
System.out.println(getVolumebricksDataSize("gfs_ftp"));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
@Test
|
|
|
|
log.error("1902 "+brick+" is not exits!");
|
|
|
|
public void test_getVolumebricksAvailableSize() {
|
|
|
|
return null;
|
|
|
|
System.out.println(getVolumebricksAvailableSize("gfs_ftp"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
|
|
|
|
|
Matcher isNum = pattern.matcher(reStrings.get(0));
|
|
|
|
// @Test
|
|
|
|
if (!isNum.matches()) {
|
|
|
|
public void test_getVolumeBricks() {
|
|
|
|
log.error("1903 " + reStrings.get(0) + " is unexpect");
|
|
|
|
getVolumeBricks("gfs_ftp");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
brick_size.put(brick, Double.parseDouble(reStrings.get(0)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return brick_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取volumeName的所有brick中可用空间大小
|
|
|
|
|
|
|
|
* 返回一个map表示bricks和可用空间大小 <ip:path,available_size>
|
|
|
|
|
|
|
|
* @param volumeName
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public Map<String, Double> getVolumebricksAvailableSize(String volumeName) {
|
|
|
|
|
|
|
|
List<String> bricks = getVolumeBricks(volumeName);
|
|
|
|
|
|
|
|
Map<String, Double> brick_size = new HashMap<>();
|
|
|
|
|
|
|
|
if (bricks == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String brick : bricks) {
|
|
|
|
|
|
|
|
String ipAndpath[] = brick.split(":");
|
|
|
|
|
|
|
|
String ip = ipAndpath[0];
|
|
|
|
|
|
|
|
String path = ipAndpath[1];
|
|
|
|
|
|
|
|
String cmd = "df " + path + "|awk '{print $4}'";
|
|
|
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(ip, Constant.rootUser, Constant.rootPasswd,
|
|
|
|
|
|
|
|
Constant.port, cmd);
|
|
|
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
|
|
|
log.error("1901 get result is null");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
|
|
|
|
log.error("1902 get result is nothing");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
|
|
|
|
|
Matcher isNum = pattern.matcher(reStrings.get(1));
|
|
|
|
|
|
|
|
if (!isNum.matches()) {
|
|
|
|
|
|
|
|
log.error("1903 " + reStrings.get(1) + " is unexpect");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
brick_size.put(brick, Double.parseDouble(reStrings.get(1)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return brick_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 判断volumeName是否存在,存在返回true,不存在返回false <功能详细描述>
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param volumeName
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public boolean volumeIsExists(String volumeName) {
|
|
|
|
|
|
|
|
List<String> volumes = showAllVolumeName();
|
|
|
|
|
|
|
|
if (volumes == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (volumes.contains(volumeName)) {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
|
|
|
|
public void test_getVolumebricksDataSize() {
|
|
|
|
|
|
|
|
System.out.println(getVolumebricksDataSize("gfs_ftp"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
|
|
|
|
public void test_getVolumebricksAvailableSize() {
|
|
|
|
|
|
|
|
System.out.println(getVolumebricksAvailableSize("gfs_ftp"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
|
|
|
|
public void test_getVolumeBricks() {
|
|
|
|
|
|
|
|
getVolumeBricks("gfs_ftp");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void test_getVolumeStatus() {
|
|
|
|
|
|
|
|
System.out.println(getVolumeStatus("gs_fp"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @Test
|
|
|
|
|
|
|
|
public void test_getVolumeMountPoint() {
|
|
|
|
|
|
|
|
System.out.println(getVolumeMountPoint("gfs_ftp"));
|
|
|
|
|
|
|
|
System.out.println(getVolumeMountPoint("v1"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|