diff --git a/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar b/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar new file mode 100644 index 00000000..b1b89c9c Binary files /dev/null and b/WebContent/WEB-INF/lib/commons-beanutils-1.7.0.jar differ diff --git a/WebContent/WEB-INF/lib/commons-collections-3.2.jar b/WebContent/WEB-INF/lib/commons-collections-3.2.jar new file mode 100644 index 00000000..75580be2 Binary files /dev/null and b/WebContent/WEB-INF/lib/commons-collections-3.2.jar differ diff --git a/WebContent/WEB-INF/lib/ezmorph-1.0.4.jar b/WebContent/WEB-INF/lib/ezmorph-1.0.4.jar new file mode 100644 index 00000000..7625af67 Binary files /dev/null and b/WebContent/WEB-INF/lib/ezmorph-1.0.4.jar differ diff --git a/WebContent/WEB-INF/lib/json-lib-2.2.2-jdk15.jar b/WebContent/WEB-INF/lib/json-lib-2.2.2-jdk15.jar new file mode 100644 index 00000000..27e7c7cc Binary files /dev/null and b/WebContent/WEB-INF/lib/json-lib-2.2.2-jdk15.jar differ diff --git a/build/classes/META-INF/persistence.xml b/build/classes/META-INF/persistence.xml deleted file mode 100644 index 2ad4aeca..00000000 --- a/build/classes/META-INF/persistence.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/build/classes/com/platform/controller/DataModelController.class b/build/classes/com/platform/controller/DataModelController.class deleted file mode 100644 index 1da50b3a..00000000 Binary files a/build/classes/com/platform/controller/DataModelController.class and /dev/null differ diff --git a/build/classes/com/platform/controller/DefaultController.class b/build/classes/com/platform/controller/DefaultController.class deleted file mode 100644 index e9becdfc..00000000 Binary files a/build/classes/com/platform/controller/DefaultController.class and /dev/null differ diff --git a/build/classes/com/platform/entities/FolderNode.class b/build/classes/com/platform/entities/FolderNode.class deleted file mode 100644 index d9be3d55..00000000 Binary files a/build/classes/com/platform/entities/FolderNode.class and /dev/null differ diff --git a/build/classes/com/platform/service/OracleExtractService.class b/build/classes/com/platform/service/OracleExtractService.class deleted file mode 100644 index cc6bcadf..00000000 Binary files a/build/classes/com/platform/service/OracleExtractService.class and /dev/null differ diff --git a/build/classes/com/platform/test/TestController.class b/build/classes/com/platform/test/TestController.class deleted file mode 100644 index 507e036c..00000000 Binary files a/build/classes/com/platform/test/TestController.class and /dev/null differ diff --git a/build/classes/com/platform/test/TestEncodeInfoDao.class b/build/classes/com/platform/test/TestEncodeInfoDao.class deleted file mode 100644 index b323c8a1..00000000 Binary files a/build/classes/com/platform/test/TestEncodeInfoDao.class and /dev/null differ diff --git a/build/classes/com/platform/test/TestEncodeService.class b/build/classes/com/platform/test/TestEncodeService.class deleted file mode 100644 index b4e52795..00000000 Binary files a/build/classes/com/platform/test/TestEncodeService.class and /dev/null differ diff --git a/build/classes/com/platform/utils/Configs.class b/build/classes/com/platform/utils/Configs.class deleted file mode 100644 index ef6f24b0..00000000 Binary files a/build/classes/com/platform/utils/Configs.class and /dev/null differ diff --git a/build/classes/com/platform/utils/ConfigsLoader.class b/build/classes/com/platform/utils/ConfigsLoader.class deleted file mode 100644 index 556ce238..00000000 Binary files a/build/classes/com/platform/utils/ConfigsLoader.class and /dev/null differ diff --git a/src/com/dao/mapper/dataInfoMoveTmpmapper.xml b/src/com/dao/mapper/dataInfoMoveTmpmapper.xml new file mode 100644 index 00000000..c0545560 --- /dev/null +++ b/src/com/dao/mapper/dataInfoMoveTmpmapper.xml @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + UPDATE + move_data_tmp + + + + regionalism_code = #{regionalismCode}, + + + system_code= #{systemCode}, + + + dst_path= #{dstPath}, + + + complete_status= #{completeStatus}, + + rate= #{rate} + + + + id = #{id} + + + + + INSERT INTO + move_data_tmp( + + + id, + + + regionalism_code, + + + system_code, + + + dst_path, + + + complete_status, + + rate + + ) + VALUES( + + + id, + + + #{regionalismCode}, + + + #{systemCode}, + + + #{dstPath}, + + + #{completeStatus}, + + #{rate} + + ) + + + + DELETE FROM + move_data_tmp + WHERE + id = #{id} + + + + + + + + + \ No newline at end of file diff --git a/src/com/platform/controller/DataModelController.java b/src/com/platform/controller/DataModelController.java index 1e42f3f6..fca796f7 100644 --- a/src/com/platform/controller/DataModelController.java +++ b/src/com/platform/controller/DataModelController.java @@ -185,7 +185,7 @@ public class DataModelController extends BaseController{ System.out.println(nodes); System.out.println(selectItems); System.out.println("--------------"); - int result = gfsService.copyFolder(listItemPath, (String)map.get("name"), "app"); + int result = gfsService.copyFolder(listItemPath, (String)map.get("path"), "app"); return result; } diff --git a/src/com/platform/dao/DataInfoMoveTmpDao.java b/src/com/platform/dao/DataInfoMoveTmpDao.java new file mode 100644 index 00000000..6d6a1d6a --- /dev/null +++ b/src/com/platform/dao/DataInfoMoveTmpDao.java @@ -0,0 +1,28 @@ +package com.platform.dao; + +import java.util.List; + +import org.springframework.stereotype.Repository; + +import com.platform.entities.DataInfoEntityMoveTmp; + +/** + * @author chen + * 数据迁移状态 临时 存放 , + */ +@Repository(value = "dataInfoMoveTmpDao") +public interface DataInfoMoveTmpDao { + + /** 查 + * @return + * @throws Exception + */ + List findAll() throws Exception; + + int update(DataInfoEntityMoveTmp data) throws Exception; + + int save(DataInfoEntityMoveTmp data) throws Exception; + + int remove(DataInfoEntityMoveTmp data) throws Exception; + +} diff --git a/src/com/platform/entities/Brick.java b/src/com/platform/entities/Brick.java index 8bda2cab..b7bc7abc 100644 --- a/src/com/platform/entities/Brick.java +++ b/src/com/platform/entities/Brick.java @@ -20,13 +20,46 @@ package com.platform.entities; */ public class Brick { - + + /** volume总大小 */ + private double availableSize; + + /** volume已使用大小 */ + private double usedSize; /** ip */ private String ip; /** 路径 */ private String path; + /** + * @return the availableSize + */ + public double getAvailableSize() { + return availableSize; + } + + /** + * @param availableSize the availableSize to set + */ + public void setAvailableSize(double availableSize) { + this.availableSize = availableSize; + } + + /** + * @return the usedSize + */ + public double getUsedSize() { + return usedSize; + } + + /** + * @param usedSize the usedSize to set + */ + public void setUsedSize(double usedSize) { + this.usedSize = usedSize; + } + /** * @return the ip */ diff --git a/src/com/platform/entities/DataInfoEntityMoveTmp.java b/src/com/platform/entities/DataInfoEntityMoveTmp.java new file mode 100644 index 00000000..74be9e5d --- /dev/null +++ b/src/com/platform/entities/DataInfoEntityMoveTmp.java @@ -0,0 +1,54 @@ +package com.platform.entities; + +public class DataInfoEntityMoveTmp extends DataInfoEntity { + + private String dstPath; + + private String completeStatus; + + private int rate; + + /** + * @return the dstPath + */ + public String getDstPath() { + return dstPath; + } + + /** + * @param dstPath the dstPath to set + */ + public void setDstPath(String dstPath) { + this.dstPath = dstPath; + } + + /** + * @return the completeStatus + */ + public String getCompleteStatus() { + return completeStatus; + } + + /** + * @param completeStatus the completeStatus to set + */ + public void setCompleteStatus(String completeStatus) { + this.completeStatus = completeStatus; + } + + /** + * @return the rate + */ + public int getRate() { + return rate; + } + + /** + * @param rate the rate to set + */ + public void setRate(int rate) { + this.rate = rate; + } + + +} diff --git a/src/com/platform/glusterfs/ClusterInfo.java b/src/com/platform/glusterfs/ClusterInfo.java index c23145e2..fdf94b55 100644 --- a/src/com/platform/glusterfs/ClusterInfo.java +++ b/src/com/platform/glusterfs/ClusterInfo.java @@ -14,6 +14,16 @@ import org.apache.log4j.PropertyConfigurator; import com.platform.utils.Constant; +/** + * 获取集群节点信息 + * 如果获取不正常,则返回null,如果获取正常,返回map表示节点ip和ip的状态 + * 如果ip在集群中且联通状态为PeerinCluster(Connected) + * 如果ip在集群中且但不连通为PeerinCluster(Disconnected) + * @author liliy + * @version [版本号,2016年9月12日] + * @see [相关类/方法] + * @since [产品/模块版本] + */ public class ClusterInfo { public static Logger log = Logger.getLogger(ClusterInfo.class); @@ -21,11 +31,6 @@ public class ClusterInfo { log.info("get cluster info"); Map peerIps = new HashMap(); - /* - String command = "echo \"" + Constant.rootPasswd + "\"|sudo -S gluster peer status"; - RunCommand runCommand = new RunCommand(); - List reStrings = runCommand.runCommandWait(command); - */ List 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"); @@ -76,7 +81,26 @@ public class ClusterInfo { } return peerIps; } - + + /** + * 根据给定的ip获的ip的状态,即是否在集群中并联通 + * 如果ip不在集群中,返回null + * 如果ip在集群中且联通状态为PeerinCluster(Connected) + * 如果ip在集群中且但不连通为PeerinCluster(Disconnected) + * @param peerip + * @return + * @see [类、类#方法、类#成员] + */ + public String getPeerStatus(String peerip){ + Map peerIps=showClusterInfo(); + if(peerIps==null || peerIps.size()==0){ + return null; + } + if(!peerIps.containsKey(peerip)){ + return Constant.peerincluster_disconnected; + } + return peerIps.get(peerip); + } public static void main(String[] args) { diff --git a/src/com/platform/glusterfs/GetTreeData.java b/src/com/platform/glusterfs/GetTreeData.java index ec40e7f6..2e391ff4 100644 --- a/src/com/platform/glusterfs/GetTreeData.java +++ b/src/com/platform/glusterfs/GetTreeData.java @@ -1,14 +1,15 @@ + package com.platform.glusterfs; import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.apache.log4j.PropertyConfigurator; import org.junit.Test; -import org.springframework.stereotype.Service; - import com.platform.entities.FolderNode; +import com.platform.utils.Constant; +import com.platform.utils.FileOperateHelper; +import com.platform.utils.GanymedSSH; /** * <一句话功能简述> 获得GFS某个目录下的子目录 @@ -29,7 +30,10 @@ public class GetTreeData { * @see [类、类#方法、类#成员] */ public FolderNode getDatas(String name) { - FolderNode fileNode = new FolderNode(name); + String names[]=name.split("/"); + String only_name=names[names.length-1]; + FolderNode fileNode = new FolderNode(only_name); + fileNode.setPath(name); Map files = showData.showFolderData(name); if(files==null || files.size()==0){ return fileNode; @@ -38,10 +42,10 @@ public class GetTreeData { List list = new ArrayList(); fileNode.setChildNodes(list); for (Map.Entry entry : files.entrySet()) { - int number = Integer.parseInt(entry.getValue()); - if ("app".equals(entry.getKey())) { + if(entry.getKey().equals("app")){ continue; } + int number = Integer.parseInt(entry.getValue()); if (number == 1) { fileNode.getChildNodes().add(new FolderNode(entry.getKey(), number)); } @@ -54,27 +58,65 @@ public class GetTreeData { return fileNode; } -// public static void main(String[] args) { -// GetTreeData getTreeData=new GetTreeData(); -// FileOrFolder fileOrFolder=getTreeData.getDatas("/home"); -// System.out.println(fileOrFolder); -// } + + /** + * <一句话功能简述> 获得所以子目录 + * <功能详细描述> + * @param name + * @return + * @see [类、类#方法、类#成员] + */ + public FolderNode getDatasWithShell(String name) { + if(name.endsWith("/")){ + name=name.substring(0, name.length()); + } + String names[]=name.split("/"); + String only_name=names[names.length-1]; + FolderNode fileNode = new FolderNode(name); + fileNode.setPath(name); + + String shellComment=new FileOperateHelper().fileReaderAndendline(Constant.fileGetTreeData); + String sh_path="/getTreedata.sh"; + String cmd="echo -e "+shellComment+" > "+sh_path+" & chmod +x "+sh_path; + Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); +// Map files = showData.showFolderData(name); + List files=Constant.ganymedSSH.execCmdWaitAcquiescent(sh_path+" "+name); + if(files==null){ + return null; + } + if(files.size()==0){ + return fileNode; + } + for(String file:files){ + + } + + return fileNode; + } + @Test + public void test_getTreeData() { + + GetTreeData getTreeData=new GetTreeData(); + FolderNode fileOrFolder=getTreeData.getDatas("/home"); + System.out.println(fileOrFolder); + } } +/* +class FileOrFolder { + String name; + int isFolder; // 1 is file and other integer is folder show children number + List children; -//class FileOrFolder { -// String name; -// int isFolder; // 1 is file and other integer is folder show children number -// List children; -// -// public FileOrFolder(String name) { -// // TODO Auto-generated constructor stub -// this.name = name; -// } -// -// public FileOrFolder(String name, int isFolder) { -// // TODO Auto-generated constructor stub -// this.name = name; -// this.isFolder = isFolder; -// } -//} + public FileOrFolder(String name) { + // TODO Auto-generated constructor stub + this.name = name; + } + + public FileOrFolder(String name, int isFolder) { + // TODO Auto-generated constructor stub + this.name = name; + this.isFolder = isFolder; + } +} +*/ diff --git a/src/com/platform/glusterfs/SetCluster.java b/src/com/platform/glusterfs/SetCluster.java index ccc3a76f..f0d607db 100644 --- a/src/com/platform/glusterfs/SetCluster.java +++ b/src/com/platform/glusterfs/SetCluster.java @@ -1,5 +1,11 @@ package com.platform.glusterfs; -public class SetCluster { +import org.apache.log4j.Logger; +public class SetCluster { + public static Logger log = Logger.getLogger ( SetCluster.class); + + public int addPeer(String peerip){ + return 0; + } } diff --git a/src/com/platform/glusterfs/SetVolume.java b/src/com/platform/glusterfs/SetVolume.java index d6be2d41..0ea02c92 100644 --- a/src/com/platform/glusterfs/SetVolume.java +++ b/src/com/platform/glusterfs/SetVolume.java @@ -108,16 +108,18 @@ public class SetVolume { return -1; } - String mountPoint = new VolumeInfo().getVolumeMountPoint(volumeName); + List mountPoints = new VolumeInfo().getVolumeMountPoint(volumeName); if (stopVolume(volumeName) != 0) { log.error("3802 " + volumeName + " stop failed !"); return -2; } log.info("stop "+volumeName+" successed!"); - if (mountPoint != null) { - String command = "umount " + mountPoint; + for(String mountPoint:mountPoints){ + if (mountPoint != null) { + String command = "umount -l " + mountPoint; Constant.ganymedSSH.execCmdNoWaitAcquiescent(command); - log.info("umount "+mountPoint+" successed!"); + log.info("umount "+mountPoint+" successed!"); + } } String command="echo -e \"y\"| gluster volume delete "+volumeName; List reStrings=Constant.ganymedSSH.execCmdWaitAcquiescent(command); diff --git a/src/com/platform/glusterfs/ShowData.java b/src/com/platform/glusterfs/ShowData.java index 919f7c7a..5996467b 100644 --- a/src/com/platform/glusterfs/ShowData.java +++ b/src/com/platform/glusterfs/ShowData.java @@ -17,13 +17,14 @@ import com.platform.utils.Constant; public class ShowData { public static Logger log = Logger.getLogger ( ShowData.class); + /** - * get the data of volumeName Map s1 is data name and s2 is type file or folder + * get the data of volumeName Map s1 is data name and s2 is type file or folder + * <功能详细描述> * @param volumeName * @return + * @see [类、类#方法、类#成员] */ - - public Map showVolumeFiles(String volumeName){ log.info("start show the data"); Map data_type=new HashMap(); diff --git a/src/com/platform/glusterfs/VolumeInfo.java b/src/com/platform/glusterfs/VolumeInfo.java index af6a37d6..45bd6874 100644 --- a/src/com/platform/glusterfs/VolumeInfo.java +++ b/src/com/platform/glusterfs/VolumeInfo.java @@ -1,7 +1,5 @@ package com.platform.glusterfs; - - import java.io.File; import java.util.ArrayList; import java.util.HashMap; @@ -11,8 +9,11 @@ import java.util.Map; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; +import org.junit.Test; +import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper; import com.platform.utils.Constant; +import com.platform.utils.GanymedSSH; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -20,6 +21,12 @@ import java.util.regex.Pattern; public class VolumeInfo { public static Logger log = Logger.getLogger(VolumeInfo.class); + /** + * 显示所有volume名称 + * <功能详细描述> + * @return + * @see [类、类#方法、类#成员] + */ public List showAllVolumeName() { log.info("get volume name"); List volNames = new ArrayList(); @@ -30,18 +37,18 @@ public class VolumeInfo { * runCommand = new RunCommand(); List reStrings = * runCommand.runCommandWait(command); */ - List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, - Constant.port, Constant.glusterVolumeInfo + "|grep ^Volume.Name"); + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, + Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + "|grep ^Volume.Name"); // System.out.println(reStrings); - if(reStrings==null){ + if (reStrings == null) { log.error("1401 get result is null"); return null; } - if(reStrings.size()==0){ + if (reStrings.size() == 0) { log.error("1402 get result is nothing"); return null; } - if(reStrings.get(0).contains(Constant.noVolume)){ + if (reStrings.get(0).contains(Constant.noVolume)) { reStrings.clear(); return reStrings; } @@ -59,28 +66,26 @@ public class VolumeInfo { return volNames; } - + + /** + * 给定参数volume的名称获得volume的类型 + * <功能详细描述> + * @param volumeName + * @return + * @see [类、类#方法、类#成员] + */ 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 reStrings = runCommand.runCommandWait(command); <<<<<<< - * HEAD - */ - List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, - Constant.port, Constant.glusterVolumeInfo + volumeName + "|grep ^Type"); + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, + Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + volumeName + "|grep ^Type"); // System.out.println(reStrings); - if(reStrings==null){ + if (reStrings == null) { log.error("1501 get result is null"); return null; } - if(reStrings.size()==0){ + if (reStrings.size() == 0) { log.error("1502 get result is nothing"); return null; } @@ -96,31 +101,21 @@ public class VolumeInfo { String str[] = line.split(":"); volType = str[1]; } - volType=volType.replaceAll(" ", ""); + 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 reStrings = - * runCommand.runCommandWait(command); <<<<<<< HEAD - */ - List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, - Constant.port, Constant.glusterVolumeInfo + "|grep ^Status"); + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, + Constant.rootPasswd, Constant.port, Constant.glusterVolumeInfo + "|grep ^Status"); // System.out.println(reStrings); - if(reStrings==null){ + if (reStrings == null) { log.error("1701 get result is null"); return null; } - if(reStrings.size()==0){ + if (reStrings.size() == 0) { log.error("1702 get result is nothing"); return null; } @@ -134,41 +129,30 @@ public class VolumeInfo { 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 reStrings = runCommand.runCommandWait(command); <<<<<<< - * HEAD - */ - List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, - Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $2}'"); + + List 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){ + if (reStrings == null) { log.error("1801 get result is null"); return null; } - if(reStrings.size()==0){ + 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; - } - + /* + * 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]"); @@ -182,23 +166,15 @@ public class VolumeInfo { 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 reStrings = runCommand.runCommandWait(command); <<<<<<< - * HEAD - */ - List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, - Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $3}'"); + + List 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){ + if (reStrings == null) { log.error("1901 get result is null"); return null; } - if(reStrings.size()==0){ + if (reStrings.size() == 0) { log.error("1902 get result is nothing"); return null; } @@ -218,19 +194,29 @@ public class VolumeInfo { return usedSize; } - public String getVolumeMountPoint(String volumeName) { - log.info("get volume mountPoint"); - // String mountPoint = ""; + /** + * @param volumeName + * @return String ipAndpath[] = brick.split(":"); + String ip = ipAndpath[0]; + String path = ipAndpath[1]; + */ + public List getVolumeBricks(String volumeName) { + log.info("get volume bricks"); - /* - * ======= - * - * >>>>>>> origin/AlexKie String command = "echo \"" + - * Constant.rootPasswd + "\" |sudo -S df -h|grep " + volumeName + - * "|awk '{print $6}'"; RunCommand runCommand = new RunCommand(); - * List reStrings = runCommand.runCommandWait(command); <<<<<<< - * HEAD - */ + String cmd = "gluster volume info " + volumeName + " |grep ^Brick'[0-9]\\+' |awk '{print $2}'"; + List reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(cmd); + // System.out.println(reStrings); + if (reStrings == null) { + log.error("1601 get volume bricks wrong"); + return null; + } + + return reStrings; + } + + public List getVolumeMountPoint(String volumeName) { + log.info("get volume MountPoint"); + List reStrings = Constant.ganymedSSH.execCmdWait(Constant.hostIp, Constant.rootUser, Constant.rootPasswd, Constant.port, Constant.df + "|grep " + volumeName + "|awk '{print $6}'"); // System.out.println(reStrings); @@ -248,24 +234,92 @@ public class VolumeInfo { log.error("11003 get result string wrong"); return null; } - - Iterator it = reStrings.iterator(); - String mountPoint = (String) it.next(); + List mountPoints = new ArrayList<>(); + for(String mountPoint:reStrings){ mountPoint=mountPoint.replaceAll(" ", ""); - return mountPoint; + mountPoints.add(mountPoint); + } + return mountPoints; } - 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")); + public Map getVolumebricksDataSize(String volumeName) { + List bricks = getVolumeBricks(volumeName); + Map 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 = "du -d 0 " + path + "|awk '{print $1}'"; + List 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(0)); + if (!isNum.matches()) { + log.error("1903 " + reStrings.get(0) + " is unexpect"); + return null; + } + brick_size.put(brick, Double.parseDouble(reStrings.get(0))); + } + return brick_size; + } + + public Map getVolumebricksAvailableSize(String volumeName) { + List bricks = getVolumeBricks(volumeName); + Map 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 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; + } + + @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"); } } diff --git a/src/com/platform/service/DataInfoServiceImp.java b/src/com/platform/service/DataInfoServiceImp.java index 124e0aca..bcbe94fb 100644 --- a/src/com/platform/service/DataInfoServiceImp.java +++ b/src/com/platform/service/DataInfoServiceImp.java @@ -44,6 +44,7 @@ public class DataInfoServiceImp implements DataInfoService { public void deleteData(String[] id) { // TODO Auto-generated method stub for(String idx: id){ + //数据在不在? List paths = dfdDao.getIdIsExist(Integer.parseInt(idx)); if(paths.size()>0){ //删除文件操作 diff --git a/src/com/platform/service/IMySqlService.java b/src/com/platform/service/IMySqlService.java new file mode 100644 index 00000000..4ab96ab0 --- /dev/null +++ b/src/com/platform/service/IMySqlService.java @@ -0,0 +1,25 @@ +package com.platform.service; + +import java.util.List; + +import com.platform.entities.GatherOracleInfo; + +public interface IMySqlService { + + /** + * @return 查询 + * @throws Exception + */ + public List findAllMySql() throws Exception; + + /** 删除 + * @return + * @throws Exception + */ + public int deleteMySql(int id) throws Exception; + + public int insertOracle(GatherOracleInfo oracle) throws Exception; + + public int updateOracle(GatherOracleInfo oracle) throws Exception; + +} diff --git a/src/com/platform/service/IOracleExtractService.java b/src/com/platform/service/IOracleExtractService.java new file mode 100644 index 00000000..be02d6d9 --- /dev/null +++ b/src/com/platform/service/IOracleExtractService.java @@ -0,0 +1,17 @@ +package com.platform.service; + +import java.util.List; +import java.util.Map; + +public interface IOracleExtractService { + + /** 抽取数据库 + * @param name + * @param dataInfo //采集库连接参数 + * @param oracleConnect + * @return + * @throws Exception + */ + public boolean extractOracle(String name, List> dataInfo, Map oracleConnect) throws Exception; + +} diff --git a/src/com/platform/service/impl/GfsServiceImpl.java b/src/com/platform/service/impl/GfsServiceImpl.java index 89bb3714..361eda4d 100644 --- a/src/com/platform/service/impl/GfsServiceImpl.java +++ b/src/com/platform/service/impl/GfsServiceImpl.java @@ -12,9 +12,11 @@ package com.platform.service.impl; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.springframework.stereotype.Service; +import com.platform.entities.Brick; import com.platform.entities.FolderNode; import com.platform.entities.VolumeEntity; import com.platform.glusterfs.CopyData; @@ -22,7 +24,7 @@ import com.platform.glusterfs.GetTreeData; import com.platform.glusterfs.VolumeInfo; import com.platform.service.IGfsService; import com.platform.utils.CacheTreeData; -import com.platform.utils.VolumeThread; +import com.platform.utils.ThreadVolume; import com.platform.utils.getTreeDataByPath; /** @@ -71,22 +73,45 @@ public class GfsServiceImpl implements IGfsService { public List getAllVolumes() throws Exception { List volumeList = new ArrayList<>(); List volumeNameList = volumeInfo.showAllVolumeName(); + if (null == volumeNameList) { + return null; + } for (String volumeName : volumeNameList) { VolumeEntity volume = new VolumeEntity(); volume.setName(volumeName); - String path = volumeInfo.getVolumeMountPoint(volumeName); - volume.setPath(path); + List path = volumeInfo.getVolumeMountPoint(volumeName); + //默认加载第一个路径 + if (null != path && path.size() > 0) { + volume.setPath(path.get(0)); + } volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName)); volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); - //TODO -// volume.setBrick(brick); + //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); + b.setPath(brickpath); + b.setAvailableSize(availableSize.get(brickIpPath)); + b.setUsedSize(usedSize.get(brickIpPath)); + brickList.add(b); + } + volume.setBrick(brickList); if (null != volume.getPath()) { -// volume.setFolder(gfsTree.getDatas(volume.getPath())); - volume.setFolder(getFolder(path)); +// 获得 folder 目录 + volume.setFolder(getFolder(volume.getPath())); } volumeList.add(volume); } - return volumeList; } @@ -94,13 +119,15 @@ public class GfsServiceImpl implements IGfsService { public VolumeEntity getOneVolume(String volumeName) throws Exception { VolumeEntity volume = new VolumeEntity(); volume.setName(volumeName); - String path = volumeInfo.getVolumeMountPoint(volumeName); - volume.setPath(path); -// volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName)); -// volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); + List path = volumeInfo.getVolumeMountPoint(volumeName); + if (null != path && path.size() > 0) { + volume.setPath(path.get(0)); + } + volume.setAllSize(volumeInfo.getVolumeAllSize(volumeName)); + volume.setUsedSize(volumeInfo.getVolumeUseSize(volumeName)); // volume.setBrick(brick); if (null != volume.getPath()) { - volume.setFolder(getFolder(path)); + volume.setFolder(getFolder(path.get(0))); } return volume; } diff --git a/src/com/platform/service/impl/MySqlServiceImpl.java b/src/com/platform/service/impl/MySqlServiceImpl.java new file mode 100644 index 00000000..b880b9c0 --- /dev/null +++ b/src/com/platform/service/impl/MySqlServiceImpl.java @@ -0,0 +1,56 @@ +package com.platform.service.impl; + +import java.util.List; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; + +import com.platform.dao.GatherOracleDao; +import com.platform.entities.GatherOracleInfo; +import com.platform.service.IMySqlService; + +@Service(value = "mySqlService") +public class MySqlServiceImpl implements IMySqlService{ + + @Resource(name = "gatherOracleDao") + private GatherOracleDao gatherOracleDao; + + @Override + public List findAllMySql() throws Exception { + List result = gatherOracleDao.selectAllOracle(); + return result; + } + + @Override + public int deleteMySql(int id) throws Exception { + + int result = 0; + if (id > 0) { +// result = gatherOracleDao.deleteOracleById(id); + GatherOracleInfo oracle = new GatherOracleInfo(); + oracle.setId(id); + oracle.setRemove("1"); + result = gatherOracleDao.updateOracleById(oracle ); + } + return result; + } + + public int insertOracle(GatherOracleInfo oracle) throws Exception { + int result = gatherOracleDao.insertOracle(oracle); + return result; + } + + @Override + public int updateOracle(GatherOracleInfo oracle) throws Exception { + int result; + if (oracle.getId() > 0) { + result = gatherOracleDao.updateOracleById(oracle); + } + else { + result = gatherOracleDao.insertOracle(oracle); + } + return result; + } + +} diff --git a/src/com/platform/service/impl/OracleExtractServiceImpl.java b/src/com/platform/service/impl/OracleExtractServiceImpl.java new file mode 100644 index 00000000..9d2a36e5 --- /dev/null +++ b/src/com/platform/service/impl/OracleExtractServiceImpl.java @@ -0,0 +1,63 @@ +package com.platform.service.impl; + +import java.sql.Connection; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.springframework.stereotype.Service; + +import com.platform.entities.DataInfoEntity; +import com.platform.entities.GatherOracleInfo; +import com.platform.entities.OracleConnectorParams; +import com.platform.oracle.OracleConnector; +import com.platform.service.IOracleExtractService; +import com.platform.service.OracleExtractHelper; +import com.platform.utils.Bean2MapUtils; + +@Service(value = "OracleExtract") +public class OracleExtractServiceImpl implements IOracleExtractService { + + /** + * 抽取 + */ + private OracleExtractHelper oracleExtract = new OracleExtractHelper(); + + /** + * 数据库连接实现类 + */ + private OracleConnector connect = new OracleConnector(); + + @Override + public boolean extractOracle(String name, List> dataInfoMap, + Map oracleConnect) throws Exception { + boolean isSuccess = false; + try{ + //map转 bean(汇总库信息-带tableName的) + GatherOracleInfo oracleModel = (GatherOracleInfo) Bean2MapUtils.convertMap(GatherOracleInfo.class, oracleConnect); + + //采集库连接参数 + List datainfos = new ArrayList(); + for (Map map : dataInfoMap) { + OracleConnectorParams dataInfoEntity = (OracleConnectorParams) Bean2MapUtils.convertMap(OracleConnectorParams.class, oracleConnect); + datainfos.add(dataInfoEntity); + } + + Connection conn = OracleConnector.ConnectionBuilder("jdbc:oracle:thin:@" + oracleModel.getIp() + ":" + oracleModel.getPort() + "/" + + oracleModel.getDatabaseName(), oracleModel.getUser(), oracleModel.getPassword()); + + for (OracleConnectorParams collectOracle : datainfos) { + + oracleExtract.createDBLink(conn, collectOracle); + oracleExtract.createTableSpace(conn, oracleModel); + oracleExtract.createUser(conn, oracleModel); + oracleExtract.extractColleDB(conn, collectOracle); + } + isSuccess = true; + }catch(Exception e){ + + } + return false; + } + +} diff --git a/src/com/platform/utils/Bean2MapUtils.java b/src/com/platform/utils/Bean2MapUtils.java new file mode 100644 index 00000000..7fea556d --- /dev/null +++ b/src/com/platform/utils/Bean2MapUtils.java @@ -0,0 +1,87 @@ +package com.platform.utils; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +public class Bean2MapUtils { + + /** + * 将一个 Map 对象转化为一个 JavaBean + * @param type 要转化的类型 + * @param map 包含属性值的 map + * @return 转化出来的 JavaBean 对象 + * @throws IntrospectionException + * 如果分析类属性失败 + * @throws IllegalAccessException + * 如果实例化 JavaBean 失败 + * @throws InstantiationException + * 如果实例化 JavaBean 失败 + * @throws InvocationTargetException + * 如果调用属性的 setter 方法失败 + */ + public static Object convertMap(Class type, Map map) + throws IntrospectionException, IllegalAccessException, + InstantiationException, InvocationTargetException { + BeanInfo beanInfo = Introspector.getBeanInfo(type); // 获取类属性 + Object obj = type.newInstance(); // 创建 JavaBean 对象 + + // 给 JavaBean 对象的属性赋值 + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + for (int i = 0; i< propertyDescriptors.length; i++) { + PropertyDescriptor descriptor = propertyDescriptors[i]; + String propertyName = descriptor.getName(); + try{ + if (map.containsKey(propertyName)) { + // 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。 + Object value = map.get(propertyName); + + Object[] args = new Object[1]; + args[0] = value; + + descriptor.getWriteMethod().invoke(obj, args); + } + } + catch(Exception e){ + + } + } + return obj; + } + + /** + * 将一个 JavaBean 对象转化为一个 Map + * @param bean 要转化的JavaBean 对象 + * @return 转化出来的 Map 对象 + * @throws IntrospectionException 如果分析类属性失败 + * @throws IllegalAccessException 如果实例化 JavaBean 失败 + * @throws InvocationTargetException 如果调用属性的 setter 方法失败 + */ + public static Map convertBean(Object bean) + throws IntrospectionException, IllegalAccessException, InvocationTargetException { + Class type = bean.getClass(); + Map returnMap = new HashMap(); + BeanInfo beanInfo = Introspector.getBeanInfo(type); + + PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); + for (int i = 0; i< propertyDescriptors.length; i++) { + PropertyDescriptor descriptor = propertyDescriptors[i]; + String propertyName = descriptor.getName(); + if (!propertyName.equals("class")) { + Method readMethod = descriptor.getReadMethod(); + Object result = readMethod.invoke(bean, new Object[0]); + if (result != null) { + returnMap.put(propertyName, result); + } else { + returnMap.put(propertyName, ""); + } + } + } + return returnMap; + } +} diff --git a/src/com/platform/utils/CacheTreeData.java b/src/com/platform/utils/CacheTreeData.java index 80246a6d..27b60277 100644 --- a/src/com/platform/utils/CacheTreeData.java +++ b/src/com/platform/utils/CacheTreeData.java @@ -1,18 +1,19 @@ package com.platform.utils; +import java.util.List; + import com.platform.entities.FolderNode; public class CacheTreeData { - private static FolderNode folders = null; + private static List folders = null; - public static FolderNode getFolders() { + public static List getFolders() { return folders; } - public static void setFolders(FolderNode folders) { + public static void setFolders(List folders) { CacheTreeData.folders = folders; } - } diff --git a/src/com/platform/utils/ConfigsLoader.java b/src/com/platform/utils/ConfigsLoader.java index b47695d6..85d75e69 100644 --- a/src/com/platform/utils/ConfigsLoader.java +++ b/src/com/platform/utils/ConfigsLoader.java @@ -23,7 +23,7 @@ public class ConfigsLoader implements ServletContextListener { + "WEB-INF/config/config.properties"; this.cReader = ConfigPropertyReader.Builder(contextPath); init(); - new VolumeThread("").start(); + new ThreadVolume("").start(); } public static void init() { diff --git a/src/com/platform/utils/Constant.java b/src/com/platform/utils/Constant.java index 5e3ceef0..27aaf8eb 100644 --- a/src/com/platform/utils/Constant.java +++ b/src/com/platform/utils/Constant.java @@ -3,22 +3,30 @@ 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); - - /** - * volume 获取的线程休眠时间 - */ - public final static int get_volume_sleep_time = 300000; + public static String rootUser = "root"; + public static String rootPasswd = "root"; + public static String hostIp = "192.168.0.116"; +// public static String hostIp = "192.168.1.105"; + 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 peerincluster_disconnected="PeerinCluster(Disconnected)"; + 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); + public static String fileGetTreeData="./WEB-INF/config/getTreedata.sh"; + + /** + * volume 获取的线程休眠时间 + */ + public final static int get_volume_sleep_time = 300000; + + /** + * volume 获取的线程休眠时间 + */ + public final static int update_dataInfo_sleep_time = 3000; } diff --git a/src/com/platform/utils/FileOperateHelper.java b/src/com/platform/utils/FileOperateHelper.java index b2b9fa9b..d2eed1b5 100644 --- a/src/com/platform/utils/FileOperateHelper.java +++ b/src/com/platform/utils/FileOperateHelper.java @@ -59,4 +59,28 @@ public class FileOperateHelper { } return sb.toString(); } + + /** + * 文件读取方法 + * @param path + * @return + */ + @SuppressWarnings("resource") + public static String fileReaderAndendline(String path) { + StringBuffer sb = new StringBuffer(); + String tempString = ""; + try { + File file = new File(path); + if (!file.exists()) + return ""; + FileInputStream fis = new FileInputStream(file); + BufferedReader br = new BufferedReader(new InputStreamReader(fis)); + while ((tempString = br.readLine()) != null) { + sb.append(tempString+"\n"); + } + } catch (Exception e) { + // TODO: handle exception + } + return sb.toString(); + } } diff --git a/src/com/platform/utils/GanymedSSH.java b/src/com/platform/utils/GanymedSSH.java index 54a7a84e..5db5d2a3 100644 --- a/src/com/platform/utils/GanymedSSH.java +++ b/src/com/platform/utils/GanymedSSH.java @@ -62,7 +62,7 @@ public class GanymedSSH { Session sess = null; try { - conn = getOpenedConnection(host, username, password, port); + sess = conn.openSession(); // 执锟斤拷cmd sess.execCommand(cmd); @@ -120,7 +120,7 @@ public class GanymedSSH { break; } } - + if(reStrings.size()==0){ while (true) { String line = stderrReader.readLine(); @@ -131,6 +131,7 @@ public class GanymedSSH { break; } } + } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -165,7 +166,7 @@ public class GanymedSSH { break; } } - + if(reStrings.size()==0){ while (true) { String line = stderrReader.readLine(); @@ -176,6 +177,7 @@ public class GanymedSSH { break; } } + } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/com/platform/utils/ThreadMoveData.java b/src/com/platform/utils/ThreadMoveData.java new file mode 100644 index 00000000..e05c07b1 --- /dev/null +++ b/src/com/platform/utils/ThreadMoveData.java @@ -0,0 +1,31 @@ +package com.platform.utils; + +public class ThreadMoveData extends Thread { + + /** + * : 实时更新数据库--根据查询到的 正则迁移的数据 + */ + public ThreadMoveData() { + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see java.lang.Thread#run() + * + */ + @Override + public void run() { + // TODO Auto-generated method stub + super.run(); + //查询 表 move_data_tmp + + + + + try { + Thread.sleep(Constant.update_dataInfo_sleep_time); + } catch (InterruptedException e) { + } + } + +} diff --git a/src/com/platform/utils/ThreadVolume.java b/src/com/platform/utils/ThreadVolume.java new file mode 100644 index 00000000..b7d49086 --- /dev/null +++ b/src/com/platform/utils/ThreadVolume.java @@ -0,0 +1,73 @@ +package com.platform.utils; + +import java.util.ArrayList; +import java.util.List; + +import com.platform.entities.FolderNode; +import com.platform.entities.VolumeEntity; +import com.platform.glusterfs.GetTreeData; +import com.platform.glusterfs.VolumeInfo; + +public class ThreadVolume extends Thread implements Runnable{ + + /** + * 挂载点路径 -- 暂时无用的 + */ + private static String pointPath = "/home"; + + /** Volume信息查询 */ + private VolumeInfo volumeInfo = new VolumeInfo(); + + public ThreadVolume() { + // TODO Auto-generated constructor stub + } + + public ThreadVolume(String path) { + if (null != path && !"".equals(path.trim())) { + ThreadVolume.pointPath = path; + } + } + + /** gfs目录树形展示 */ + private GetTreeData gfsTree = new GetTreeData(); + + @Override + public void run() { + super.run(); + while(true){ + List folderlist = new ArrayList(); + //查询 volume name + List volumeNameList = volumeInfo.showAllVolumeName(); + if (null != volumeNameList) { + for (String volumeName : volumeNameList) { + VolumeEntity volume = new VolumeEntity(); + volume.setName(volumeName); + List path = volumeInfo.getVolumeMountPoint(volumeName); + //默认加载第一个路径 + if (null != path && path.size() > 0) { + //装入 folder: + //查询 每个 volume 下的 folder + FolderNode foldertmp = gfsTree.getDatas(path.get(0)); + folderlist.add(foldertmp); + } + } + } + //TODO 更新folder 目录 + CacheTreeData.setFolders(folderlist); + try { + Thread.sleep(Constant.get_volume_sleep_time); + } catch (InterruptedException e) { + } + } + + } + + public static String getPointPath() { + return pointPath; + } + + public static void setPointPath(String pointPath) { + ThreadVolume.pointPath = pointPath; + } + +} diff --git a/src/com/platform/utils/VolumeThread.java b/src/com/platform/utils/VolumeThread.java deleted file mode 100644 index 05357c8f..00000000 --- a/src/com/platform/utils/VolumeThread.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.platform.utils; - -import java.util.List; - -import com.platform.entities.FolderNode; -import com.platform.glusterfs.GetTreeData; -import com.platform.glusterfs.VolumeInfo; - -public class VolumeThread extends Thread implements Runnable{ - - /** - * 挂载点路径 - */ - private static String pointPath = "/home"; - - public VolumeThread() { - // TODO Auto-generated constructor stub - } - - public VolumeThread(String path) { - if (null != path && !"".equals(path.trim())) { - VolumeThread.pointPath = path; - } - } - - /** gfs目录树形展示 */ - private GetTreeData gfsTree = new GetTreeData(); - - @Override - public void run() { - super.run(); - while(true){ - FolderNode folders = gfsTree.getDatas(pointPath); - //TODO - CacheTreeData.setFolders(folders); - try { - Thread.sleep(Constant.get_volume_sleep_time); - } catch (InterruptedException e) { - } - } - - } - - public static String getPointPath() { - return pointPath; - } - - public static void setPointPath(String pointPath) { - VolumeThread.pointPath = pointPath; - } - -} diff --git a/src/com/platform/utils/getTreeDataByPath.java b/src/com/platform/utils/getTreeDataByPath.java index 3ea9f60d..d60cc7f1 100644 --- a/src/com/platform/utils/getTreeDataByPath.java +++ b/src/com/platform/utils/getTreeDataByPath.java @@ -11,11 +11,17 @@ public class getTreeDataByPath { * @return */ public FolderNode findByPath(String path) { - FolderNode folderNode = CacheTreeData.getFolders(); - if (null == folderNode) { + List folderNodelist = CacheTreeData.getFolders(); + if (null == folderNodelist) { return null; } - FolderNode folder = getFolder(folderNode, path); + FolderNode folder = null; + for (FolderNode folderNode : folderNodelist) { + folder = getFolder(folderNode, path); + if (null != folder) { + break; + } + } return folder; } @@ -25,7 +31,7 @@ public class getTreeDataByPath { */ private FolderNode getFolder(FolderNode f, String path){ FolderNode result = null; - if(path.equals(f.getName())){ + if(path.equals(f.getPath())){ return f; } List folds = f.getChildNodes();