diff --git a/src/com/dao/mapper/VolumeMapper.xml b/src/com/dao/mapper/VolumeMapper.xml new file mode 100644 index 00000000..146d83fd --- /dev/null +++ b/src/com/dao/mapper/VolumeMapper.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + UPDATE + volume_info + + + + name= #{name}, + + + ip= #{ip}, + + + path= #{path}, + + + mark= #{mark}, + + + + + id = #{id} + + + + + INSERT INTO + volume_info( + + + name, + + + ip, + + + path, + + + mark, + + + ) + VALUES( + + + #{name}, + + + #{ip}, + + + #{path}, + + + #{mark}, + + + ) + + + + DELETE FROM + volume_info + WHERE + id = #{id} + + + \ No newline at end of file diff --git a/src/com/dao/mapper/data-details-mapper.xml b/src/com/dao/mapper/data-details-mapper.xml index 8aa8b58f..61071bd0 100644 --- a/src/com/dao/mapper/data-details-mapper.xml +++ b/src/com/dao/mapper/data-details-mapper.xml @@ -220,10 +220,10 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" #{year}, - #{start_year}, + #{startYear}, - #{end_year}, + #{endYear}, #{volumeIp}, diff --git a/src/com/dao/mapper/dataInfoMoveTmpmapper.xml b/src/com/dao/mapper/dataInfoMoveTmpmapper.xml index e35029a5..6d7b843d 100644 --- a/src/com/dao/mapper/dataInfoMoveTmpmapper.xml +++ b/src/com/dao/mapper/dataInfoMoveTmpmapper.xml @@ -49,7 +49,7 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" - regionalism_code,system_code,dst_path,lasttime,fkid + regionalism_code,system_code,dst_path,lasttime,fkid,dst_volume_ip,dst_volume_path @@ -120,6 +120,12 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" fkid, + + dst_volume_ip, + + + dst_volume_path, + ) VALUES( @@ -146,7 +152,13 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" #{lastTime}, - #{fkid), + #{fkid}, + + + #{dstVolumeIp}, + + + #{dstVolumePath}, ) @@ -156,7 +168,7 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" INSERT INTO move_data_tmp ( ) VALUES - (#{item.regionalismCode,jdbcType=VARCHAR},#{item.systemCode,jdbcType=INTEGER},#{item.dstPath,jdbcType=VARCHAR},#{item.lastTime,jdbcType=VARCHAR},#{item.fkid}) + (#{item.regionalismCode,jdbcType=VARCHAR},#{item.systemCode,jdbcType=INTEGER},#{item.dstPath,jdbcType=VARCHAR},#{item.lastTime,jdbcType=VARCHAR},#{item.fkid},#{item.dstVolumeIp},#{item.dstVolumePath}) diff --git a/src/com/platform/dao/VolumeDao.java b/src/com/platform/dao/VolumeDao.java new file mode 100644 index 00000000..db4e9c93 --- /dev/null +++ b/src/com/platform/dao/VolumeDao.java @@ -0,0 +1,27 @@ +package com.platform.dao; + +import java.util.List; + +import org.springframework.stereotype.Repository; + +import com.platform.entities.VolumeInitEntity; + +/** + * @author chen + * 数据迁移状态 临时 存放 , + */ +@Repository(value = "volumeDao") +public interface VolumeDao { + + /** 查 + * @return + * @throws Exception + */ + List findAll() throws Exception; + + int update(VolumeInitEntity data) throws Exception; + + int save(VolumeInitEntity data) throws Exception; + + int remove(int id) throws Exception; +} diff --git a/src/com/platform/entities/VolumeInitEntity.java b/src/com/platform/entities/VolumeInitEntity.java new file mode 100644 index 00000000..fa0a70d9 --- /dev/null +++ b/src/com/platform/entities/VolumeInitEntity.java @@ -0,0 +1,86 @@ +package com.platform.entities; + +public class VolumeInitEntity { + + private int id; + + private String name; + + private String ip; + + private String path; + + private String mark; + + /** + * @return the id + */ + public int getId() { + return id; + } + + /** + * @param id the id to set + */ + public void setId(int id) { + this.id = id; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the ip + */ + public String getIp() { + return ip; + } + + /** + * @param ip the ip to set + */ + public void setIp(String ip) { + this.ip = ip; + } + + /** + * @return the path + */ + public String getPath() { + return path; + } + + /** + * @param path the path to set + */ + public void setPath(String path) { + this.path = path; + } + + /** + * @return the mark + */ + public String getMark() { + return mark; + } + + /** + * @param mark the mark to set + */ + public void setMark(String mark) { + this.mark = mark; + } + + +} diff --git a/src/com/platform/service/impl/MoveDataServiceImpl.java b/src/com/platform/service/impl/MoveDataServiceImpl.java index 7adb04dd..b3aca0e8 100644 --- a/src/com/platform/service/impl/MoveDataServiceImpl.java +++ b/src/com/platform/service/impl/MoveDataServiceImpl.java @@ -14,9 +14,11 @@ import org.springframework.stereotype.Service; import com.platform.dao.DataInfoDao; import com.platform.dao.DataInfoMoveTmpDao; +import com.platform.dao.VolumeDao; import com.platform.entities.DataInfoEntity; import com.platform.entities.DataInfoEntityMoveTmp; import com.platform.entities.FolderNode; +import com.platform.entities.VolumeInitEntity; import com.platform.glusterfs.CheckoutMD5; import com.platform.glusterfs.CopyData; import com.platform.glusterfs.RemoveData; @@ -32,6 +34,9 @@ public class MoveDataServiceImpl implements IMoveDataService { @Resource(name = "dataInfoDao") private DataInfoDao dataInfoDao; + + @Resource(name = "volumeDao") + private VolumeDao volumeDao; private RemoveData removeservice = new RemoveData(); @@ -63,12 +68,17 @@ public class MoveDataServiceImpl implements IMoveDataService { if (null ==node.getPath() ||"".equals(node.getPath())) { return false; } + List listVolume = volumeDao.findAll(); + if (null == listVolume || listVolume.size() == 0) { + return false; + } String tailPath = ""; if (null != data) { // XXX/320198_16/1,or XXX/320122KFQ_15/1 ---> /320198_16/1, or // /320122KFQ_15/1 List exist = dataInfoMoveTmpDao.findAll(); List existIds = new ArrayList(); + List fkIds = new ArrayList(); if (null != exist) { for (DataInfoEntityMoveTmp dataInfoEntityMoveTmp : exist) { if ("0".equals(dataInfoEntityMoveTmp.getCompleteStatus()) @@ -77,6 +87,7 @@ public class MoveDataServiceImpl implements IMoveDataService { if (null != dataInfoEntityMoveTmp.getDataPath()) { existIds.add(dataInfoEntityMoveTmp.getDataPath()); } + fkIds.add(dataInfoEntityMoveTmp.getFkid()); } } } @@ -95,6 +106,12 @@ public class MoveDataServiceImpl implements IMoveDataService { if (existIds.contains(dataInfoEntity.getDataPath())) { continue; } + if (dataInfoEntity.getId() == 0) { + continue; + } + if (fkIds.contains(dataInfoEntity.getId())) { + continue; + } // TODO 正则:取出 data 的后面 的 路径,eg: XXX/320198_16/1,or // XXX/320122KFQ_15/1) Matcher matcher = pattern.matcher(dataInfoEntity.getDataPath()); @@ -114,11 +131,30 @@ public class MoveDataServiceImpl implements IMoveDataService { dataMove.setDstPath(finalDestPath); dataMove.setLastTime(DateForm.date2StringBysecond(new Date())); dataMove.setFkid(dataInfoEntity.getId()); - dataMove.setVolumePath(node.getName()); + // 末尾 含有 / + Matcher matcher3 = pattern2.matcher(node.getPath()); + // 去掉 最后 的 / 符合 + String volumePath = ""; + if (!matcher3.find()) { + volumePath = node.getPath()+"/"; + } + else { + volumePath = node.getPath(); + } + for ( VolumeInitEntity ve : listVolume) { + if (volumePath.contains(ve.getPath())) { + dataMove.setDstVolumePath(ve.getPath()); + dataMove.setDstVolumeIp(ve.getIp()); + break; + } + } moveList.add(dataMove); } if (moveList.size() > 0) { dataInfoMoveTmpDao.insertBatch(moveList); +// for (DataInfoEntityMoveTmp dataInfoEntityMoveTmp2 : moveList) { +// dataInfoMoveTmpDao.save(dataInfoEntityMoveTmp2); +// } isSuccess = true; } } diff --git a/src/com/platform/service/thread/ThreadMoveData.java b/src/com/platform/service/thread/ThreadMoveData.java index a178ff0a..9967e056 100644 --- a/src/com/platform/service/thread/ThreadMoveData.java +++ b/src/com/platform/service/thread/ThreadMoveData.java @@ -139,10 +139,13 @@ public class ThreadMoveData{ data.setVolumeIp(dataMove.getDstVolumeIp()); data.setVolumePath(dataMove.getDstVolumePath()); data.setYear(DateForm.date2StringByMin(new Date())); + data.setVolumeIp(dataMove.getVolumeIp()); + data.setId(0); dataInfoDao.save(data); } else { // 3:表示 迁移失败 + dataMove.setLastTime(DateForm.date2StringBysecond(new Date())); dataMove.setCompleteStatus("3"); } } diff --git a/src/com/platform/utils/Constant.java b/src/com/platform/utils/Constant.java index d0eb303b..95035c6e 100644 --- a/src/com/platform/utils/Constant.java +++ b/src/com/platform/utils/Constant.java @@ -44,6 +44,6 @@ public class Constant { /** * volume 获取的线程休眠时间 */ - public final static int update_dataInfo_sleep_time = 30000; + public final static int update_dataInfo_sleep_time = 1500; }