From 3f9a10d873ef4e5bd7093b297abd27b9d0b4fd13 Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Tue, 27 Sep 2016 19:46:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8E=A5=E6=94=B6=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E4=BC=A0=E5=85=A5=E7=9A=84gfs=E7=9A=84volume=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=EF=BC=8C=E8=BF=9B=E8=A1=8C=E6=96=B0=E5=BB=BA?= =?UTF-8?q?volume,=E5=88=A0=E9=99=A4volume,=E5=90=AF=E7=94=A8volume,?= =?UTF-8?q?=E5=81=9C=E7=94=A8volume=EF=BC=8C=E6=96=B0=E5=A2=9Ebrick?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E9=99=A4brick=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/controller/VolumeController.java | 4 + src/com/platform/entities/VolumeEntity.java | 7 +- src/com/platform/glusterfs/ClusterInfo.java | 2 +- .../service/impl/MySqlServiceImpl.java | 10 + .../service/impl/VolumeServiceImpl.java | 39 +++- src/com/platform/utils/CacheTreeData.java | 4 +- src/com/platform/utils/ConfigsLoader.java | 2 +- src/com/platform/utils/GanymedSSH.java | 4 +- src/com/platform/utils/ThreadVolume.java | 197 ++++++++++-------- src/com/platform/utils/ThreadVolumeImm.java | 18 ++ 10 files changed, 182 insertions(+), 105 deletions(-) create mode 100644 src/com/platform/utils/ThreadVolumeImm.java diff --git a/src/com/platform/controller/VolumeController.java b/src/com/platform/controller/VolumeController.java index 4f94761a..0d6600f2 100644 --- a/src/com/platform/controller/VolumeController.java +++ b/src/com/platform/controller/VolumeController.java @@ -17,6 +17,8 @@ import com.platform.entities.VolumeForm; import com.platform.entities.VolumeInitEntity; import com.platform.service.IVolumeService; import com.platform.utils.Configs; +import com.platform.utils.ThreadVolume; +import com.platform.utils.ThreadVolumeImm; @Controller public class VolumeController extends BaseController{ @@ -34,6 +36,7 @@ public class VolumeController extends BaseController{ Configs.CONSOLE_LOGGER.error("/oracle/{name}/extract"); volumeService.save(form); req.setStatus(200); + new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-update").start(); } @RequestMapping(value = "/volume/delete", method = RequestMethod.POST) @@ -43,6 +46,7 @@ public class VolumeController extends BaseController{ Configs.CONSOLE_LOGGER.error("/oracle/{name}/extract"); volumeService.delete(entity); req.setStatus(200); + new ThreadVolumeImm("ThreadVolumeImm-in-VolumeController-delete").start(); } diff --git a/src/com/platform/entities/VolumeEntity.java b/src/com/platform/entities/VolumeEntity.java index 450b7154..b562e9c1 100644 --- a/src/com/platform/entities/VolumeEntity.java +++ b/src/com/platform/entities/VolumeEntity.java @@ -37,7 +37,7 @@ public class VolumeEntity { private String path; /** * exist,正常返回状态Started,Stopped,Created */ - private String status; + private boolean status; private String type; @@ -103,17 +103,18 @@ public class VolumeEntity { this.path = path; } + /** * @return the status */ - public String getStatus() { + public boolean isStatus() { return status; } /** * @param status the status to set */ - public void setStatus(String status) { + public void setStatus(boolean status) { this.status = status; } diff --git a/src/com/platform/glusterfs/ClusterInfo.java b/src/com/platform/glusterfs/ClusterInfo.java index bbd81e1b..982ed6bf 100644 --- a/src/com/platform/glusterfs/ClusterInfo.java +++ b/src/com/platform/glusterfs/ClusterInfo.java @@ -37,7 +37,7 @@ public class ClusterInfo { public Map<String, String> showClusterInfo() { // log.info("get cluster info"); Map<String, String> peerIps = new HashMap<String, String>(); - + peerIps.put(Constant.hostIp, Constant.peerincluster_connected); List<String> reStrings = Constant.ganymedSSH.execCmdWaitAcquiescent(Constant.glusterPeerStatus); if (reStrings == null) { log.error("1101 command get result is null"); diff --git a/src/com/platform/service/impl/MySqlServiceImpl.java b/src/com/platform/service/impl/MySqlServiceImpl.java index 7efaa3f8..5f3d1a44 100644 --- a/src/com/platform/service/impl/MySqlServiceImpl.java +++ b/src/com/platform/service/impl/MySqlServiceImpl.java @@ -1,5 +1,6 @@ package com.platform.service.impl; +import java.sql.Connection; import java.util.List; import javax.annotation.Resource; @@ -8,6 +9,7 @@ import org.springframework.stereotype.Service; import com.platform.dao.GatherOracleDao; import com.platform.entities.GatherOracleInfo; +import com.platform.oracle.OracleConnector; import com.platform.service.IMySqlService; @Service(value = "mySqlService") @@ -37,12 +39,20 @@ public class MySqlServiceImpl implements IMySqlService{ } public int insertOracle(GatherOracleInfo oracle) throws Exception { + //TODO 连接oracle, int result = gatherOracleDao.insertOracle(oracle); return result; } @Override public int updateOracle(GatherOracleInfo oracle) throws Exception { + int status = 1; + Connection conn = null /*OracleConnector.ConnectionBuilder("jdbc:oracle:thin:@" + oracle.getIp() + ":" + oracle.getPort() + ":" + + oracle.getDatabaseName(), oracle.getUser(), oracle.getPassword())*/; + if (null == conn) { + status = 0; + } + oracle.setStatus(status); int result; if (oracle.getId() > 0) { result = gatherOracleDao.updateOracleById(oracle); diff --git a/src/com/platform/service/impl/VolumeServiceImpl.java b/src/com/platform/service/impl/VolumeServiceImpl.java index 3e41d5ee..1884d8c9 100644 --- a/src/com/platform/service/impl/VolumeServiceImpl.java +++ b/src/com/platform/service/impl/VolumeServiceImpl.java @@ -55,10 +55,29 @@ public class VolumeServiceImpl implements IVolumeService { } boolean isContinue = true; - //TODO 对比volume信息--原数据没有该volume,则新增volume: + // 对比volume信息--原数据没有该volume,则新增volume: for (VolumeEntity add : addVolumes) { + List<String> bristr = new ArrayList<String>(); + if (null == add.getName() || "".equals(add.getName())) { + continue; + } + if (null == add.getPath() || "".equals(add.getPath())) { + continue; + } + for ( Brick bri : add.getBrick()) { + if (null == bri.getIp() || "".equals(bri.getIp())) { + continue; + } + if (null == bri.getPath() || "".equals(bri.getPath())) { + continue; + } + bristr.add(bri.getIp()+":"+bri.getPath()); + }; + //创建volume - volumeService.createVolume(add.getName(), 0, "distributed", add.getBrick(), add.getPath()); + if (bristr.size() > 0) { + volumeService.createVolume(add.getName(), 0, "distributed", bristr, add.getPath()); + } //记录volume信息, VolumeInitEntity volInSql = new VolumeInitEntity(); volInSql.setName(add.getName()); @@ -74,23 +93,27 @@ public class VolumeServiceImpl implements IVolumeService { Map<String, Brick> serverMap = new HashMap<String, Brick>(); for (Brick brick : newBricks) { //IP + path 才 确认唯一的 brick - newMap.put(brick.getIp() + ":" + brick.getPath(), brick); + newMap.put(brick.getIp().trim() + ":" + brick.getPath().trim(), null); } for (Brick brick : serverBricks) { - serverMap.put(brick.getIp() + ":" + brick.getPath(), brick); + serverMap.put(brick.getIp().trim() + ":" + brick.getPath().trim(), null); } // ----对比volume信息--原数据有该volume,则对比brick信息,确认那几个brick是新增的,那几个brick是待删除的----start Set<String> newBrickKeys = newMap.keySet(); Set<String> serverBrickKeys = serverMap.keySet(); //新增的Brick的 Keys - newBrickKeys.removeAll(serverBrickKeys); List<String> newKeys = new ArrayList<String>(); + newBrickKeys.removeAll(serverBrickKeys); newKeys.addAll(newBrickKeys); // 新增brick s, if (newKeys.size() > 0) { volumeService.addBrickVolume(entity.getName(), newKeys, 0, "distributed"); } //待删除的Brick的 Keys + for (Brick brick : newBricks) { + //IP + path 才 确认唯一的 brick + newMap.put(brick.getIp().trim() + ":" + brick.getPath().trim(), null); + } newBrickKeys = newMap.keySet(); serverBrickKeys.removeAll(newBrickKeys); List<String> deleteKeys = new ArrayList<String>(); @@ -102,11 +125,11 @@ public class VolumeServiceImpl implements IVolumeService { // ---对比volume信息--原数据有该volume,则对比brick信息,确认那几个brick是新增的,那几个brick是待删除的----- end //TODO 查看状态 状态Started,Stopped,Created - if (!volumeTmp.getStatus().equals(entity.getStatus())) { - if ("Started".equals(entity.getStatus())) { + if (volumeTmp.isStatus() != entity.isStatus()) { + if (entity.isStatus()) { this.start(entity); } - else if ("Stopped".equals(entity.getStatus())) { + else{ this.stop(entity); } } diff --git a/src/com/platform/utils/CacheTreeData.java b/src/com/platform/utils/CacheTreeData.java index 742df9a2..18bde5ce 100644 --- a/src/com/platform/utils/CacheTreeData.java +++ b/src/com/platform/utils/CacheTreeData.java @@ -16,7 +16,7 @@ public class CacheTreeData { return folders; } - public static void setFolders(List<FolderNode> folders) { + public synchronized static void setFolders(List<FolderNode> folders) { CacheTreeData.folders = folders; } @@ -30,7 +30,7 @@ public class CacheTreeData { /** * @param volumeList the volumeList to set */ - public static void setVolumeList(List<VolumeEntity> volumeList) { + public synchronized static void setVolumeList(List<VolumeEntity> volumeList) { CacheTreeData.volumeList = volumeList; } diff --git a/src/com/platform/utils/ConfigsLoader.java b/src/com/platform/utils/ConfigsLoader.java index 56745ce0..0f4490b0 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 ThreadVolume("").start(); + new ThreadVolume("ThreadVolume-in-ConfigsLoader").start(); } public static void init() { diff --git a/src/com/platform/utils/GanymedSSH.java b/src/com/platform/utils/GanymedSSH.java index 194be049..fbad5d07 100644 --- a/src/com/platform/utils/GanymedSSH.java +++ b/src/com/platform/utils/GanymedSSH.java @@ -102,7 +102,7 @@ public class GanymedSSH { Session sess = null; try { - +// conn = getOpenedConnection(host, username, password, port); sess = conn.openSession(); // 执锟斤拷cmd sess.execCommand(cmd); @@ -149,7 +149,7 @@ public class GanymedSSH { Session sess = null; try { - +// conn = getOpenedConnection(host, username, password, port); sess = conn.openSession(); // 执锟斤拷cmd sess.execCommand(cmd); diff --git a/src/com/platform/utils/ThreadVolume.java b/src/com/platform/utils/ThreadVolume.java index ed7cf144..38c33770 100644 --- a/src/com/platform/utils/ThreadVolume.java +++ b/src/com/platform/utils/ThreadVolume.java @@ -15,111 +15,49 @@ import com.platform.glusterfs.ClusterInfo; import com.platform.glusterfs.GetTreeData; import com.platform.glusterfs.VolumeInfo; -public class ThreadVolume extends Thread implements Runnable{ - +public class ThreadVolume extends Thread { + /** * 挂载点路径 -- 暂时无用的 */ private static String pointPath = "/home"; - - /** Volume信息查询 */ + + /** Volume信息查询 */ private VolumeInfo volumeInfo = new VolumeInfo(); - + private ClusterInfo cluster = new ClusterInfo(); - + public ThreadVolume() { // TODO Auto-generated constructor stub } - - public ThreadVolume(String path) { + + public ThreadVolume(String name) { + setName(name); + } + + public ThreadVolume(String name, String path) { if (null != path && !"".equals(path.trim())) { ThreadVolume.pointPath = path; } } - - /** gfs目录树形展示 */ + + /** gfs目录树形展示 */ private GetTreeData gfsTree = new GetTreeData(); - + @Override public void run() { super.run(); - while(true){ - 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 && path.size() > 0) { - volume.setPath(path.get(0)); - } - volume.setAllSize(volumeInfo.getVolumeAvailableSize(volumeName)+volumeInfo.getVolumeUseSize(volumeName)); - volume.setStatus(volumeInfo.getVolumeStatus(volumeName)); - 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) { - new CustomException(Custom4exception.threadVolume_class_Except,e); - } - } - } - //TODO 更新folder 目录 - CacheTreeData.setFolders(folderlist); - CacheTreeData.setVolumeList(volumeList); - try { - Thread.sleep(Constant.get_volume_sleep_time); - } catch (InterruptedException e) { - new CustomException(Custom4exception.threadVolume_Thread_Except,e); - } - + while (true) { + try { + getVolumeMsg(); + Thread.sleep(Constant.get_volume_sleep_time); + } catch (InterruptedException e) { + new CustomException( + Custom4exception.threadVolume_Thread_Except, e); + } + } - + } public static String getPointPath() { @@ -129,5 +67,88 @@ public class ThreadVolume extends Thread implements Runnable{ 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 && path.size() > 0) { + volume.setPath(path.get(0)); + } + 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) { + new CustomException( + Custom4exception.threadVolume_class_Except, e); + } + } + } + // TODO 更新folder 目录 + CacheTreeData.setFolders(folderlist); + CacheTreeData.setVolumeList(volumeList); + } + } diff --git a/src/com/platform/utils/ThreadVolumeImm.java b/src/com/platform/utils/ThreadVolumeImm.java new file mode 100644 index 00000000..beaa5613 --- /dev/null +++ b/src/com/platform/utils/ThreadVolumeImm.java @@ -0,0 +1,18 @@ +package com.platform.utils; + +public class ThreadVolumeImm extends Thread{ + + public ThreadVolumeImm() { + // TODO Auto-generated constructor stub + } + + public ThreadVolumeImm(String name) { + setName(name); + } + + @Override + public void run() { + new ThreadVolume().getVolumeMsg(); + } + +} From 9bd7a694dfbf18d1c24d5d6d8080b83a5c8f62b1 Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Tue, 27 Sep 2016 19:53:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .classpath | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.classpath b/.classpath index bb13dba0..84b01679 100644 --- a/.classpath +++ b/.classpath @@ -3,8 +3,17 @@ <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="test"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/> + <classpathentry kind="con" path="com.genuitec.runtime.library/com.genuitec.generic_6.0"> + <attributes> + <attribute name="owner.project.facets" value="jst.web"/> + </attributes> + </classpathentry> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> + <attributes> + <attribute name="owner.project.facets" value="java"/> + </attributes> + </classpathentry> <classpathentry kind="output" path="build/classes"/> </classpath>