|
|
package com.platform.utils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
import com.platform.entities.Brick;
|
|
|
import com.platform.entities.FolderNode;
|
|
|
import com.platform.entities.VolumeEntity;
|
|
|
import com.platform.glusterfs.ClusterInfo;
|
|
|
import com.platform.glusterfs.GetTreeData;
|
|
|
import com.platform.glusterfs.VolumeInfo;
|
|
|
import com.platform.service.VolumeService;
|
|
|
|
|
|
public class ThreadVolume extends Thread {
|
|
|
|
|
|
public static Logger log = Logger.getLogger(ThreadVolume.class);
|
|
|
/**
|
|
|
* 挂载点路径 -- 暂时无用的
|
|
|
*/
|
|
|
private static String pointPath = "/home";
|
|
|
|
|
|
/** Volume信息查询 */
|
|
|
private VolumeInfo volumeInfo = new VolumeInfo();
|
|
|
|
|
|
private ClusterInfo cluster = new ClusterInfo();
|
|
|
|
|
|
/** gfs目录树形展示 */
|
|
|
private GetTreeData gfsTree = new GetTreeData();
|
|
|
|
|
|
public ThreadVolume() {
|
|
|
// TODO Auto-generated constructor stub
|
|
|
}
|
|
|
|
|
|
public ThreadVolume(String name) {
|
|
|
setName(name);
|
|
|
}
|
|
|
|
|
|
public ThreadVolume(String name, String path) {
|
|
|
if (null != path && !"".equals(path.trim())) {
|
|
|
ThreadVolume.pointPath = path;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
super.run();
|
|
|
while (true) {
|
|
|
try {
|
|
|
getVolumeMsg();
|
|
|
Thread.sleep(Constant.get_volume_sleep_time);
|
|
|
} catch (InterruptedException e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static String getPointPath() {
|
|
|
return pointPath;
|
|
|
}
|
|
|
|
|
|
public static void setPointPath(String pointPath) {
|
|
|
ThreadVolume.pointPath = pointPath;
|
|
|
}
|
|
|
|
|
|
public void getVolumeMsg() {
|
|
|
List<FolderNode> folderlist = new ArrayList<FolderNode>();
|
|
|
List<VolumeEntity> volumeList = new ArrayList<VolumeEntity>();
|
|
|
// brick状态 map集合
|
|
|
Map<String, String> brickStatusMap = cluster.showClusterInfo();
|
|
|
|
|
|
// 查询 volume name
|
|
|
List<String> volumeNameList = volumeInfo.showAllVolumeName();
|
|
|
if (null != volumeNameList) {
|
|
|
for (String volumeName : volumeNameList) {
|
|
|
try {
|
|
|
VolumeEntity volume = new VolumeEntity();
|
|
|
volume.setName(volumeName);
|
|
|
List<String> path = volumeInfo
|
|
|
.getVolumeMountPoint(volumeName);
|
|
|
// 默认加载第一个路径
|
|
|
if (null != path) {
|
|
|
for (String one : path) {
|
|
|
if (!one.contains("df")) {
|
|
|
volume.setPath(one);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (null == volume.getPath()) {
|
|
|
volume.setPath("");
|
|
|
}
|
|
|
volume.setAllSize(volumeInfo
|
|
|
.getVolumeAvailableSize(volumeName)
|
|
|
+ volumeInfo.getVolumeUseSize(volumeName));
|
|
|
// 状态Started,Stopped,Created
|
|
|
String status = volumeInfo.getVolumeStatus(volumeName);
|
|
|
if ("Started".equals(status)) {
|
|
|
volume.setStatus(true);
|
|
|
} else {
|
|
|
volume.setStatus(false);
|
|
|
}
|
|
|
volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName));
|
|
|
volume.setType(volumeInfo.getVolumeType(volumeName));
|
|
|
// TODO 查询brick--
|
|
|
// 返回 ip:path
|
|
|
List<String> brickStrs = volumeInfo
|
|
|
.getVolumeBricks(volumeName);
|
|
|
// brick已用大小:
|
|
|
Map<String, Double> usedSize = volumeInfo
|
|
|
.getVolumebricksDataSize(volumeName);
|
|
|
Map<String, Double> availableSize = volumeInfo
|
|
|
.getVolumebricksAvailableSize(volumeName);
|
|
|
|
|
|
List<Brick> brickList = new ArrayList<Brick>();
|
|
|
for (String brickIpPath : brickStrs) {
|
|
|
Brick b = new Brick();
|
|
|
String ipAndpath[] = brickIpPath.split(":");
|
|
|
String brickip = ipAndpath[0];
|
|
|
String brickpath = ipAndpath[1];
|
|
|
// iP , path ,
|
|
|
b.setIp(brickip);
|
|
|
if (brickStatusMap == null
|
|
|
|| brickStatusMap.size() == 0) {
|
|
|
b.setStatus(false);
|
|
|
} else if (brickStatusMap.containsKey(brickip)) {
|
|
|
b.setStatus(true);
|
|
|
} else {
|
|
|
b.setStatus(false);
|
|
|
}
|
|
|
b.setPath(brickpath);
|
|
|
b.setAvailableSize(availableSize.get(brickIpPath));
|
|
|
b.setUsedSize(usedSize.get(brickIpPath));
|
|
|
brickList.add(b);
|
|
|
}
|
|
|
volume.setBrick(brickList);
|
|
|
|
|
|
// 默认加载第一个路径
|
|
|
if (null != path && path.size() > 0) {
|
|
|
// 装入 folder:
|
|
|
// 查询 每个 volume 下的 folder
|
|
|
FolderNode foldertmp = gfsTree.getDatas(path.get(0));
|
|
|
folderlist.add(foldertmp);
|
|
|
}
|
|
|
volumeList.add(volume);
|
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 更新folder 目录
|
|
|
CacheTreeData.setFolders(folderlist);
|
|
|
CacheTreeData.setVolumeList(volumeList);
|
|
|
}
|
|
|
|
|
|
}
|