From 4ba10ae6e6f489cdc3c0915d35e81f42b2ed7b21 Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Fri, 21 Oct 2016 09:01:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2volume=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/platform/utils/ThreadVolume.java | 175 ++++++++++++----------- 1 file changed, 95 insertions(+), 80 deletions(-) diff --git a/src/com/platform/utils/ThreadVolume.java b/src/com/platform/utils/ThreadVolume.java index da84dca8..563ceaf0 100644 --- a/src/com/platform/utils/ThreadVolume.java +++ b/src/com/platform/utils/ThreadVolume.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import net.sf.json.JSONArray; + import org.springframework.stereotype.Service; import com.base.Custom4exception; @@ -14,6 +16,7 @@ import com.platform.entities.VolumeEntity; import com.platform.glusterfs.ClusterInfo; import com.platform.glusterfs.GetTreeData; import com.platform.glusterfs.VolumeInfo; +import com.platform.http.gfs.HttpUtils; public class ThreadVolume extends Thread { @@ -71,88 +74,100 @@ public class ThreadVolume extends Thread { public void getVolumeMsg() { List folderlist = new ArrayList(); List volumeList = new ArrayList(); - // brick状态 map集合 - Map brickStatusMap = cluster.showClusterInfo(); - - // 查询 volume name - List volumeNameList = volumeInfo.showAllVolumeName(); - if (null != volumeNameList) { - for (String volumeName : volumeNameList) { - try { - VolumeEntity volume = new VolumeEntity(); - volume.setName(volumeName); - List path = volumeInfo - .getVolumeMountPoint(volumeName); - // 默认加载第一个路径 - if (null != path) { - for (String one : path) { - if (!one.contains("df")) { - volume.setPath(one); - } - } - } - if (null == volume.getPath()) { - volume.setPath(""); - } - volume.setAllSize((double) (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((double) volumeInfo.getVolumeUseSize(volumeName)); - volume.setType(volumeInfo.getVolumeType(volumeName)); - // TODO 查询brick-- - // 返回 ip:path - List brickStrs = volumeInfo - .getVolumeBricks(volumeName); - // brick已用大小: - Map usedSize = volumeInfo - .getVolumebricksDataSize(volumeName); - Map availableSize = volumeInfo - .getVolumebricksAvailableSize(volumeName); - - List brickList = new ArrayList(); - 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) { - new CustomException( - Custom4exception.threadVolume_class_Except, e); - } + HttpUtils ht = new HttpUtils(); + String rest = ht.sendPost("gfs/getAllvolume", null); +// JSONArray jsondata = JSONArray.fromObject(volumeList); + JSONArray json = JSONArray.fromObject(rest); + List volumes = (List)JSONArray.toCollection(json, VolumeEntity.class); + for (VolumeEntity volumeEntity : volumes) { + if (null != volumeEntity.getFolder()) { + folderlist.addAll(volumeEntity.getFolder()); } } + volumeList = volumes; + +// // brick状态 map集合 +// Map brickStatusMap = cluster.showClusterInfo(); +// +// // 查询 volume name +// List volumeNameList = volumeInfo.showAllVolumeName(); +// if (null != volumeNameList) { +// for (String volumeName : volumeNameList) { +// try { +// VolumeEntity volume = new VolumeEntity(); +// volume.setName(volumeName); +// List path = volumeInfo +// .getVolumeMountPoint(volumeName); +// // 默认加载第一个路径 +// if (null != path) { +// for (String one : path) { +// if (!one.contains("df")) { +// volume.setPath(one); +// } +// } +// } +// if (null == volume.getPath()) { +// volume.setPath(""); +// } +// volume.setAllSize((double) (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((double) volumeInfo.getVolumeUseSize(volumeName)); +// volume.setType(volumeInfo.getVolumeType(volumeName)); +// // TODO 查询brick-- +// // 返回 ip:path +// List brickStrs = volumeInfo +// .getVolumeBricks(volumeName); +// // brick已用大小: +// Map usedSize = volumeInfo +// .getVolumebricksDataSize(volumeName); +// Map availableSize = volumeInfo +// .getVolumebricksAvailableSize(volumeName); +// +// List brickList = new ArrayList(); +// 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) { +// new CustomException( +// Custom4exception.threadVolume_class_Except, e); +// } +// } +// } // 更新folder 目录 CacheTreeData.setFolders(folderlist); CacheTreeData.setVolumeList(volumeList);