From 09064c9d9e198275dc081c8308bb3cfa0335903e Mon Sep 17 00:00:00 2001 From: chenlw <874313221@qq.com> Date: Mon, 19 Sep 2016 18:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E5=AD=97=E6=AE=B5=E6=A8=A1=E7=B3=8A?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=95=B0=E6=8D=AE=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/base/Custom4exception.java | 9 ++ src/com/dao/mapper/data-details-mapper.xml | 59 +++++----- src/com/platform/dao/DataInfoDao.java | 7 +- src/com/platform/entities/PagerOptions.java | 38 ++++++- src/com/platform/entities/VolumeEntity.java | 33 ++++++ src/com/platform/glusterfs/VolumeInfo.java | 4 +- .../platform/service/DataInfoServiceImp.java | 40 ++++--- .../service/impl/MoveDataServiceImpl.java | 7 +- .../service/thread/ThreadMoveData.java | 4 +- src/com/platform/utils/Constant.java | 4 +- src/com/platform/utils/ThreadVolume.java | 107 ++++++++++-------- 11 files changed, 208 insertions(+), 104 deletions(-) diff --git a/src/com/base/Custom4exception.java b/src/com/base/Custom4exception.java index d863b645..7a1ed58b 100644 --- a/src/com/base/Custom4exception.java +++ b/src/com/base/Custom4exception.java @@ -16,5 +16,14 @@ public class Custom4exception { * 001:软件依赖虚拟机资源类别 * 001:启动异常 */ + /** + * ThreadVolume类查询 volume异常 + */ + public final static String threadVolume_class_Except = "3001001001"; + + /** + * ThreadVolume类线程休眠异常 + */ + public final static String threadVolume_Thread_Except = "3001001002"; } diff --git a/src/com/dao/mapper/data-details-mapper.xml b/src/com/dao/mapper/data-details-mapper.xml index ce8a7be7..217885ca 100644 --- a/src/com/dao/mapper/data-details-mapper.xml +++ b/src/com/dao/mapper/data-details-mapper.xml @@ -4,7 +4,7 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> - + @@ -46,43 +46,47 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" jdbcType="VARCHAR" /> - - and data_details.data_type=#{PagerOptions.dataType} + + AND data_details.data_type=#{dataType} - - and - data_details.submitted_batch=#{PagerOptions.submittedBatch} + + AND + data_details.submitted_batch=#{submittedBatch} - - and data_details.city_name=#{PagerOptions.cityName} + + AND data_details.city_name=#{cityName} - - and - data_details.district_name=#{PagerOptions.districtName} + + AND + data_details.district_name=#{districtName} - - and data_details.data_version=#{PagerOptions.dataVersion} + + AND data_details.data_version=#{dataVersion} - - and data_details=#{PagerOptions.systemName} + + AND data_details.system_name=#{systemName} - - and data_details.data_year=#{PagerOptions.dataYear} + + AND data_details.data_year=#{dataYear} + + + + AND CONCAT(regionalism_code,system_code,city_name,district_name,system_name) LIKE CONCAT('%',CONCAT(#{item},'%')) + - diff --git a/src/com/platform/dao/DataInfoDao.java b/src/com/platform/dao/DataInfoDao.java index 498611a1..5b9419b0 100644 --- a/src/com/platform/dao/DataInfoDao.java +++ b/src/com/platform/dao/DataInfoDao.java @@ -1,6 +1,7 @@ package com.platform.dao; import java.util.List; +import java.util.Map; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -11,11 +12,11 @@ import com.platform.entities.PagerOptions; @Repository(value = "dataInfoDao") public interface DataInfoDao { - int getLimitedDataCount(@Param("PagerOptions")PagerOptions pagerOptions); + int getLimitedDataCount(PagerOptions pagerOptions); - int getLimitedBeginId(@Param("PagerOptions")PagerOptions pagerOptions); + int getLimitedBeginId(PagerOptions pagerOptions); - List getLimitedDataInfoEntities(@Param("PagerOptions")PagerOptions pagerOptions); + List getLimitedDataInfoEntities(PagerOptions pagerOptions); List getIdIsExist(List list)throws Exception; diff --git a/src/com/platform/entities/PagerOptions.java b/src/com/platform/entities/PagerOptions.java index 2a25d555..e69e560a 100644 --- a/src/com/platform/entities/PagerOptions.java +++ b/src/com/platform/entities/PagerOptions.java @@ -1,5 +1,7 @@ package com.platform.entities; +import java.util.List; + public class PagerOptions { private Integer currentPageNum; //当前页码 @@ -24,7 +26,11 @@ public class PagerOptions { private Integer totalLimit; //当前页前面已有多少条数据 private Integer priorTableSize; //前一次操作一页显示的数据条数 - + + private String keyQuery; + + private String[] array; + public Integer getCurrentPageNum() { return currentPageNum; } @@ -119,6 +125,34 @@ public class PagerOptions { public void setPriorTableSize(Integer priorTableSize) { this.priorTableSize = priorTableSize; - } + } + + /** + * @return the keyQuery + */ + public String getKeyQuery() { + return keyQuery; + } + + /** + * @param keyQuery the keyQuery to set + */ + public void setKeyQuery(String keyQuery) { + this.keyQuery = keyQuery; + } + + /** + * @return the array + */ + public String[] getArray() { + return array; + } + + /** + * @param array the array to set + */ + public void setArray(String[] array) { + this.array = array; + } } diff --git a/src/com/platform/entities/VolumeEntity.java b/src/com/platform/entities/VolumeEntity.java index dc609579..ae2604ea 100644 --- a/src/com/platform/entities/VolumeEntity.java +++ b/src/com/platform/entities/VolumeEntity.java @@ -36,6 +36,11 @@ public class VolumeEntity { /** 挂载点 */ private String path; + /** * exist,正常返回状态Started,Stopped,Created */ + private String status; + + private String type; + /** volume树形目录 */ private List folder = new ArrayList(); @@ -98,6 +103,34 @@ public class VolumeEntity { this.path = path; } + /** + * @return the status + */ + public String getStatus() { + return status; + } + + /** + * @param status the status to set + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + /** * @return the folder */ diff --git a/src/com/platform/glusterfs/VolumeInfo.java b/src/com/platform/glusterfs/VolumeInfo.java index 015dbef9..e2ece069 100644 --- a/src/com/platform/glusterfs/VolumeInfo.java +++ b/src/com/platform/glusterfs/VolumeInfo.java @@ -161,7 +161,7 @@ public class VolumeInfo { * @return * @see [类、类#方法、类#成员] */ - public Long getVolumeAvailableSize(String volumeName) { + public Long getVolumeAvailableSize(String volumeName) throws Exception{ log.info("get volume availableSize"); Long allSize = 0L; @@ -187,7 +187,7 @@ public class VolumeInfo { * @return * @see [类、类#方法、类#成员] */ - public Long getVolumeUseSize(String volumeName) { + public Long getVolumeUseSize(String volumeName) throws Exception{ log.info("get volume used size"); Long usedSize = 0L; if (volumeIsExists(volumeName) == false) { diff --git a/src/com/platform/service/DataInfoServiceImp.java b/src/com/platform/service/DataInfoServiceImp.java index 50e3a0bd..95f79c0f 100644 --- a/src/com/platform/service/DataInfoServiceImp.java +++ b/src/com/platform/service/DataInfoServiceImp.java @@ -2,15 +2,18 @@ package com.platform.service; import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.springframework.ui.ModelMap; +import com.base.CustomException; import com.platform.dao.DataInfoDao; import com.platform.entities.DataInfoEntity; import com.platform.entities.PagerOptions; +import com.platform.utils.Bean2MapUtils; @Service(value = "dataInfoService") public class DataInfoServiceImp implements DataInfoService { @@ -23,22 +26,31 @@ public class DataInfoServiceImp implements DataInfoService { @Override public ModelMap getPagerTableData(PagerOptions pagerOptions) { - // TODO Auto-generated method stub ModelMap modelMap = new ModelMap(); - int count = dfdDao.getLimitedDataCount(pagerOptions); //获取总记录条数 - System.out.println("total colume " + count); - int offset = 0; - if (pagerOptions.getCurrentPageNum() > 1) { - pagerOptions.setTotalLimit((pagerOptions.getCurrentPageNum() - 1) - * pagerOptions.getPriorTableSize()); - offset = dfdDao.getLimitedBeginId(pagerOptions); //获取起始查询id - System.out.println(offset); + String querystr = pagerOptions.getKeyQuery(); + String[] querys = null; + try { + if (null != querystr && !"".equals(querystr)) { + querys = querystr.split(" "); + } + pagerOptions.setArray(querys); + int count = dfdDao.getLimitedDataCount(pagerOptions); //获取总记录条数 + System.out.println("total colume " + count); + int offset = 0; + if (pagerOptions.getCurrentPageNum() > 1) { + pagerOptions.setTotalLimit((pagerOptions.getCurrentPageNum() - 1) + * pagerOptions.getPriorTableSize()); + offset = dfdDao.getLimitedBeginId(pagerOptions); //获取起始查询id + System.out.println(offset); + } + pagerOptions.setOffset(offset + 1); + List result = dfdDao + .getLimitedDataInfoEntities(pagerOptions); + modelMap.addAttribute("data", result); + modelMap.addAttribute("length", count); + } catch (Exception e) { + new CustomException(); } - pagerOptions.setOffset(offset + 1); - List result = dfdDao - .getLimitedDataInfoEntities(pagerOptions); - modelMap.addAttribute("data", result); - modelMap.addAttribute("length", count); return modelMap; } diff --git a/src/com/platform/service/impl/MoveDataServiceImpl.java b/src/com/platform/service/impl/MoveDataServiceImpl.java index 7b401452..3576159d 100644 --- a/src/com/platform/service/impl/MoveDataServiceImpl.java +++ b/src/com/platform/service/impl/MoveDataServiceImpl.java @@ -84,11 +84,16 @@ public class MoveDataServiceImpl implements IMoveDataService{ } //TODO 正则:取出 data 的后面 的 路径,eg: XXX/320198_16/1,or XXX/320122KFQ_15/1) Matcher matcher = pattern.matcher(dataInfoEntity.getDataPath()); - // tailPath 第一个字符是 / 符号 + // tailPath 第一个字符是 / 符号取尾:"\\/\\d+[a-z]*[A-Z]*_\\d+\\/\\d*\\/*$" if (matcher.find()) { tailPath = matcher.group(); } String finalDestPath = dstPath + tailPath; + Matcher matchertmp2 = pattern2.matcher(finalDestPath); + //去掉 最后 的 / 符合 + if (!matchertmp2.find()) { + finalDestPath = finalDestPath + "/"; + } DataInfoEntityMoveTmp dataMove = new DataInfoEntityMoveTmp(); dataMove.setSystemCode(dataInfoEntity.getSystemCode()); dataMove.setRegionalismCode(dataInfoEntity.getRegionalismCode()); diff --git a/src/com/platform/service/thread/ThreadMoveData.java b/src/com/platform/service/thread/ThreadMoveData.java index 800f209d..4096107d 100644 --- a/src/com/platform/service/thread/ThreadMoveData.java +++ b/src/com/platform/service/thread/ThreadMoveData.java @@ -108,14 +108,14 @@ public class ThreadMoveData{ } if (srcSize > 0 && dstSize > 0) { realRate = (dstSize*100 / srcSize ); - dataMove.setRate((int) realRate); dataMove.setLastTime(DateForm.date2StringBysecond(new Date())); } if (srcSize == dstSize) { realRate = 100; } + dataMove.setRate((int) realRate); } - if("1".equals(dataMove.getCompleteStatus()) &&dataMove.getRate() > 0){ + if("1".equals(dataMove.getCompleteStatus()) && dataMove.getRate() > 0){ //传输完毕:进行校验 if (realRate == 100) { //TODO 进行MD5校验 diff --git a/src/com/platform/utils/Constant.java b/src/com/platform/utils/Constant.java index 07f5960d..68b559f5 100644 --- a/src/com/platform/utils/Constant.java +++ b/src/com/platform/utils/Constant.java @@ -39,11 +39,11 @@ public class Constant { /** * volume 获取的线程休眠时间 */ - public final static int get_volume_sleep_time = 300000; + public final static int get_volume_sleep_time = 180000; /** * volume 获取的线程休眠时间 */ - public final static int update_dataInfo_sleep_time = 3000; + public final static int update_dataInfo_sleep_time = 30000; } diff --git a/src/com/platform/utils/ThreadVolume.java b/src/com/platform/utils/ThreadVolume.java index 8379c339..03832e9e 100644 --- a/src/com/platform/utils/ThreadVolume.java +++ b/src/com/platform/utils/ThreadVolume.java @@ -6,6 +6,8 @@ import java.util.Map; import org.springframework.stereotype.Service; +import com.base.Custom4exception; +import com.base.CustomException; import com.platform.entities.Brick; import com.platform.entities.FolderNode; import com.platform.entities.VolumeEntity; @@ -42,7 +44,6 @@ public class ThreadVolume extends Thread implements Runnable{ public void run() { super.run(); while(true){ - try { List folderlist = new ArrayList(); List volumeList = new ArrayList(); // brick状态 map集合 @@ -52,63 +53,71 @@ public class ThreadVolume extends Thread implements Runnable{ 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) { - volume.setPath(path.get(0)); - } - volume.setAllSize(volumeInfo.getVolumeAvailableSize(volumeName)); - volume.setUsedSize(volumeInfo.getVolumeUseSize(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); + try { + VolumeEntity volume = new VolumeEntity(); + volume.setName(volumeName); + List path = volumeInfo.getVolumeMountPoint(volumeName); + //默认加载第一个路径 + if (null != path && path.size() > 0) { + volume.setPath(path.get(0)); } - else { - b.setStatus(false); + volume.setAllSize(volumeInfo.getVolumeAvailableSize(volumeName)); + volume.setStatus(volumeInfo.getVolumeStatus(volumeName)); + volume.setUsedSize(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); } - 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); + 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); } - volumeList.add(volume); } } //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); + } - Thread.sleep(Constant.get_volume_sleep_time); - } catch (InterruptedException e) { - } } }