|
|
|
@ -19,12 +19,20 @@ import com.platform.utils.GanymedSSH;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取volume信息 <功能详细描述>
|
|
|
|
|
*
|
|
|
|
|
* @author liliy
|
|
|
|
|
* @version [版本号,2016年9月13日]
|
|
|
|
|
* @see [相关类/方法]
|
|
|
|
|
* @since [产品/模块版本]
|
|
|
|
|
*/
|
|
|
|
|
public class VolumeInfo {
|
|
|
|
|
public static Logger log = Logger.getLogger(VolumeInfo.class);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示所有volume名称
|
|
|
|
|
* <功能详细描述>
|
|
|
|
|
* 显示所有volume名称 <功能详细描述>
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
@ -38,8 +46,8 @@ public class VolumeInfo {
|
|
|
|
|
* 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");
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH
|
|
|
|
|
.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + "|grep ^Volume.Name");
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
log.error("1401 get result is null");
|
|
|
|
@ -67,10 +75,10 @@ public class VolumeInfo {
|
|
|
|
|
return volNames;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 给定参数volume的名称获得volume的类型
|
|
|
|
|
* <功能详细描述>
|
|
|
|
|
* 给定参数volume的名称获得volume的类型 <功能详细描述>
|
|
|
|
|
*
|
|
|
|
|
* @param volumeName
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
@ -79,8 +87,8 @@ public class VolumeInfo {
|
|
|
|
|
log.info("get volume type");
|
|
|
|
|
String volType = "";
|
|
|
|
|
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
|
|
|
|
|
Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH
|
|
|
|
|
.execCmdWaitAcquiescent(Constant.glusterVolumeInfo + volumeName + "|grep ^Type");
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
log.error("1501 get result is null");
|
|
|
|
@ -106,11 +114,19 @@ public class VolumeInfo {
|
|
|
|
|
return volType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取volumeName的状态 如果出错返回null,如果volumeName不存在则返回Volume volumeName does not
|
|
|
|
|
* exist,正常返回状态Started,Stopped,Created
|
|
|
|
|
*
|
|
|
|
|
* @param volumeName
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
|
public String getVolumeStatus(String volumeName) {
|
|
|
|
|
log.info("get volume status");
|
|
|
|
|
String volStatus = "";
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
|
|
|
|
|
Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + "|grep ^Status");
|
|
|
|
|
String cmd = Constant.glusterVolumeInfo + " " + volumeName + " |grep ^Status";
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
log.error("1701 get result is null");
|
|
|
|
@ -120,11 +136,15 @@ public class VolumeInfo {
|
|
|
|
|
log.error("1702 get result is nothing");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reStrings.get(0).contains("does not exist")) {
|
|
|
|
|
log.error("1703 " + reStrings.get(0));
|
|
|
|
|
return reStrings.get(0);
|
|
|
|
|
}
|
|
|
|
|
if (!(reStrings.get(0).split(":")[0].contains("Status"))) {
|
|
|
|
|
log.error("1703 get result string wrong");
|
|
|
|
|
log.error("1704 get result string wrong");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Iterator it = reStrings.iterator(); it.hasNext();) {
|
|
|
|
|
String line = (String) it.next();
|
|
|
|
|
String str[] = line.split(":");
|
|
|
|
@ -134,67 +154,70 @@ public class VolumeInfo {
|
|
|
|
|
return volStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Double getVolumeAllSize(String volumeName) {
|
|
|
|
|
log.info("get volume allSize");
|
|
|
|
|
Double allSize = null;
|
|
|
|
|
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
|
|
|
|
|
Constant.rootPasswd, Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $2}'");
|
|
|
|
|
/**
|
|
|
|
|
* 获取volumeName的可用大小
|
|
|
|
|
* volumeName不存在返回-1,获取大小错误返回-2 ,正常返回volumeName的可用大小
|
|
|
|
|
* @param volumeName
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
|
public Long getVolumeAvailableSize(String volumeName) {
|
|
|
|
|
log.info("get volume availableSize");
|
|
|
|
|
Long allSize = 0L;
|
|
|
|
|
|
|
|
|
|
String cmd = Constant.df + " | grep " + volumeName + "|awk '{print $4}'";
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
log.error("1801 get result is null");
|
|
|
|
|
return null;
|
|
|
|
|
log.error("1802 get result is error");
|
|
|
|
|
return -2L;
|
|
|
|
|
}
|
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
|
log.error("1802 get result is nothing");
|
|
|
|
|
return null;
|
|
|
|
|
log.error("1801 " + volumeName + " is not exists!");
|
|
|
|
|
return -1L;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* 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]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
allSize = Long.parseLong(reStrings.get(0));
|
|
|
|
|
return allSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Double getVolumeUseSize(String volumeName) {
|
|
|
|
|
/**
|
|
|
|
|
* 获取volumeName已用空间
|
|
|
|
|
* volumeName不存在返回-1,获取大小错误返回-2 ,正常返回volumeName的已用的大小
|
|
|
|
|
* @param volumeName
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
|
public Long getVolumeUseSize(String volumeName) {
|
|
|
|
|
log.info("get volume used size");
|
|
|
|
|
Double usedSize = null;
|
|
|
|
|
Long usedSize = 0L;
|
|
|
|
|
if (volumeIsExists(volumeName) == false) {
|
|
|
|
|
log.error("1901 " + volumeName + " is not exists!");
|
|
|
|
|
return -1L;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser,
|
|
|
|
|
Constant.rootPasswd, Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $3}'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String cmd = "df | grep " + volumeName + "|awk '{print $3}'";
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
log.error("1901 get result is null");
|
|
|
|
|
return null;
|
|
|
|
|
return -2L;
|
|
|
|
|
}
|
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
|
log.error("1902 get result is nothing");
|
|
|
|
|
return null;
|
|
|
|
|
log.error("1902 " + volumeName + " is not exists!");
|
|
|
|
|
return -1L;
|
|
|
|
|
}
|
|
|
|
|
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]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usedSize = Long.parseLong(reStrings.get(0));
|
|
|
|
|
return usedSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取volumeName的bricks
|
|
|
|
|
* 返回一个bircks的list ip:path,如果volumeName不存在返回null
|
|
|
|
|
* @param volumeName
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
|
public List<String> getVolumeBricks(String volumeName) {
|
|
|
|
|
log.info("get volume bricks");
|
|
|
|
|
|
|
|
|
@ -205,38 +228,81 @@ public class VolumeInfo {
|
|
|
|
|
log.error("1601 get volume bricks wrong");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reStrings.size()==0) {
|
|
|
|
|
log.error("1602 "+volumeName+" is not exists!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return reStrings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取volumeName所有挂载点
|
|
|
|
|
* <功能详细描述>
|
|
|
|
|
* @param volumeName
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
|
public List<String> getVolumeMountPoint(String volumeName) {
|
|
|
|
|
log.info("get volume MountPoint");
|
|
|
|
|
List<String> mountPoints = new ArrayList<>();
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd,
|
|
|
|
|
Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $6}'");
|
|
|
|
|
String cmd=Constant.df + "|grep " + volumeName + "|awk '{print $6}'";
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
if(reStrings==null){
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
log.error("11001 get result string wrong");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if(reStrings.size()==0){
|
|
|
|
|
log.error("11002 "+volumeName+" is no mountpoint");
|
|
|
|
|
return mountPoints;
|
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
|
log.error("11002 " + volumeName + " is not exists or no mountpoint");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// char flag = reStrings.get(0).trim().toCharArray()[0];
|
|
|
|
|
// if (flag != '/') {
|
|
|
|
|
// log.error("11003 get result string wrong");
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
for (String mountPoint : reStrings) {
|
|
|
|
|
mountPoint = mountPoint.replaceAll(" ", "");
|
|
|
|
|
mountPoints.add(mountPoint);
|
|
|
|
|
}
|
|
|
|
|
return mountPoints;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getOneVolumeMountPoint(String volumeName) {
|
|
|
|
|
log.info("get one volume MountPoint");
|
|
|
|
|
|
|
|
|
|
char flag = reStrings.get(0).trim().toCharArray()[0];
|
|
|
|
|
if (flag != '/') {
|
|
|
|
|
log.error("11003 get result string wrong");
|
|
|
|
|
String mountPoint=null;
|
|
|
|
|
String cmd=Constant.df + "|grep " + volumeName + "|awk '{print $6}'";
|
|
|
|
|
List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd);
|
|
|
|
|
// System.out.println(reStrings);
|
|
|
|
|
if (reStrings == null) {
|
|
|
|
|
log.error("11001 get result string wrong");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(String mountPoint:reStrings){
|
|
|
|
|
mountPoint=mountPoint.replaceAll(" ", "");
|
|
|
|
|
mountPoints.add(mountPoint);
|
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
|
log.error("11002 " + volumeName + " is not exists or no mountpoint");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return mountPoints;
|
|
|
|
|
|
|
|
|
|
// char flag = reStrings.get(0).trim().toCharArray()[0];
|
|
|
|
|
// if (flag != '/') {
|
|
|
|
|
// log.error("11003 get result string wrong");
|
|
|
|
|
// return null;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
mountPoint=reStrings.get(0);
|
|
|
|
|
return mountPoint;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取volumeName的所有brick中数据占用空间的大小
|
|
|
|
|
* 返回一个map表示bricks和数据大小 <ip:path,data_size>
|
|
|
|
|
* @param volumeName
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
|
public Map<String, Double> getVolumebricksDataSize(String volumeName) {
|
|
|
|
|
List<String> bricks = getVolumeBricks(volumeName);
|
|
|
|
|
Map<String, Double> brick_size = new HashMap<>();
|
|
|
|
@ -256,7 +322,7 @@ public class VolumeInfo {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (reStrings.size() == 0) {
|
|
|
|
|
log.error("1902 get result is nothing");
|
|
|
|
|
log.error("1902 "+brick+" is not exits!");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
|
@ -270,6 +336,13 @@ public class VolumeInfo {
|
|
|
|
|
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<>();
|
|
|
|
@ -303,12 +376,30 @@ public class VolumeInfo {
|
|
|
|
|
return brick_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
|
/**
|
|
|
|
|
* 判断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
|
|
|
|
|
// @Test
|
|
|
|
|
public void test_getVolumebricksAvailableSize() {
|
|
|
|
|
System.out.println(getVolumebricksAvailableSize("gfs_ftp"));
|
|
|
|
|
}
|
|
|
|
@ -317,10 +408,15 @@ public class VolumeInfo {
|
|
|
|
|
public void test_getVolumeBricks() {
|
|
|
|
|
getVolumeBricks("gfs_ftp");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void test_getVolumeMountPoint() {
|
|
|
|
|
System.out.println(getVolumeMountPoint("gfs_ftp"));
|
|
|
|
|
System.out.println(getVolumeMountPoint("v1"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|