Search in sources :

Example 1 with BRFSTimeFilter

use of com.bonree.brfs.common.files.impl.BRFSTimeFilter in project BRFS by zhangnianli.

the class UserDeleteJob method deleteFiles.

/**
 * 概述:封装执行结果
 * @param atom
 * @param dataPath
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public AtomTaskResultModel deleteFiles(AtomTaskModel atom, String dataPath) {
    if (atom == null) {
        return null;
    }
    String snName = atom.getStorageName();
    long startTime = TimeUtils.getMiles(atom.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
    long endTime = TimeUtils.getMiles(atom.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
    AtomTaskResultModel atomR = new AtomTaskResultModel();
    atomR.setDataStartTime(TimeUtils.formatTimeStamp(startTime, TimeUtils.TIME_MILES_FORMATE));
    atomR.setDataStopTime(TimeUtils.formatTimeStamp(endTime, TimeUtils.TIME_MILES_FORMATE));
    atomR.setPartNum(atom.getPatitionNum());
    atomR.setSn(snName);
    Map<String, String> snMap = new HashMap<>();
    snMap.put(BRFSPath.STORAGEREGION, snName);
    List<BRFSPath> deleteDirs = BRFSFileUtil.scanBRFSFiles(dataPath, snMap, snMap.size(), new BRFSTimeFilter(startTime, endTime));
    LOG.debug("collection {}_{} dirs {}", atom.getDataStartTime(), atom.getDataStopTime(), deleteDirs);
    if (deleteDirs == null || deleteDirs.isEmpty()) {
        atomR.setOperationFileCount(0);
        return atomR;
    }
    boolean isSuccess = true;
    for (BRFSPath deletePath : deleteDirs) {
        isSuccess = isSuccess && FileUtils.deleteDir(dataPath + FileUtils.FILE_SEPARATOR + deletePath.toString(), true);
        LOG.debug("delete [{}], status [{}]", deletePath, isSuccess);
    }
    atomR.setOperationFileCount(deleteDirs.size());
    atomR.setSuccess(isSuccess);
    return atomR;
}
Also used : HashMap(java.util.HashMap) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) BRFSTimeFilter(com.bonree.brfs.common.files.impl.BRFSTimeFilter)

Example 2 with BRFSTimeFilter

use of com.bonree.brfs.common.files.impl.BRFSTimeFilter in project BRFS by zhangnianli.

the class SystemDeleteJob method deleteDirs.

/**
 * 概述:封装结果
 * @param atom
 * @param dataPath
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public AtomTaskResultModel deleteDirs(AtomTaskModel atom, String dataPath) {
    String snName = atom.getStorageName();
    int patitionNum = atom.getPatitionNum();
    long granule = atom.getGranule();
    long startTime = TimeUtils.getMiles(atom.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
    long endTime = TimeUtils.getMiles(atom.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
    AtomTaskResultModel atomR = AtomTaskResultModel.getInstance(null, snName, startTime, endTime, "", patitionNum);
    Map<String, String> snMap = new HashMap<>();
    snMap.put(BRFSPath.STORAGEREGION, snName);
    List<BRFSPath> deleteDirs = BRFSFileUtil.scanBRFSFiles(dataPath, snMap, snMap.size(), new BRFSTimeFilter(0, endTime));
    if (deleteDirs == null || deleteDirs.isEmpty()) {
        LOG.debug("delete dir {} - {} is empty ", TimeUtils.timeInterval(startTime, granule), TimeUtils.timeInterval(endTime, granule));
        return atomR;
    }
    atomR.setOperationFileCount(deleteDirs.size());
    boolean isSuccess = true;
    for (BRFSPath deleteDir : deleteDirs) {
        isSuccess = isSuccess && FileUtils.deleteDir(dataPath + FileUtils.FILE_SEPARATOR + deleteDir.toString(), true);
        LOG.debug("delete :{} status :{} ", deleteDir, isSuccess);
    }
    atomR.setSuccess(isSuccess);
    return atomR;
}
Also used : HashMap(java.util.HashMap) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) BRFSTimeFilter(com.bonree.brfs.common.files.impl.BRFSTimeFilter)

Example 3 with BRFSTimeFilter

use of com.bonree.brfs.common.files.impl.BRFSTimeFilter in project BRFS by zhangnianli.

the class TaskStateLifeContral method changeRunTaskModel.

public static TaskModel changeRunTaskModel(final TaskModel message, String dataPath) {
    if (message == null) {
        return null;
    }
    // 文件恢复单独不需要处理
    TaskModel changeTask = new TaskModel();
    changeTask.setCreateTime(message.getCreateTime());
    changeTask.setTaskState(changeTask.getTaskState());
    changeTask.setTaskType(message.getTaskType());
    if (TaskType.SYSTEM_COPY_CHECK.code() == changeTask.getTaskType()) {
        changeTask.setAtomList(message.getAtomList());
        return changeTask;
    }
    // 删除任务,校验任务,需要扫目录确定
    List<AtomTaskModel> mAtoms = message.getAtomList();
    if (mAtoms == null || mAtoms.isEmpty()) {
        LOG.warn("task message atom list is empty!!!");
        return null;
    }
    // 循环atom,封装atom
    AtomTaskModel rAtom;
    long startTime;
    long endTime;
    String snName;
    int partNum;
    Map<String, String> map;
    long granule;
    for (AtomTaskModel atom : mAtoms) {
        startTime = TimeUtils.getMiles(atom.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
        endTime = TimeUtils.getMiles(atom.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
        snName = atom.getStorageName();
        partNum = atom.getPatitionNum();
        granule = atom.getGranule();
        map = new HashMap<>();
        map.put(BRFSPath.STORAGEREGION, snName);
        List<BRFSPath> dirPaths = BRFSFileUtil.scanBRFSFiles(dataPath, map, map.size(), new BRFSTimeFilter(startTime, endTime));
        if (dirPaths == null || dirPaths.isEmpty()) {
            LOG.debug("It's no dir to take task [{}]:[{}]-[{}]", snName, TimeUtils.timeInterval(startTime, granule), TimeUtils.timeInterval(endTime, granule));
            continue;
        }
        List<Long> times = filterRepeatDirs(dirPaths);
        for (Long time : times) {
            rAtom = AtomTaskModel.getInstance(null, snName, atom.getTaskOperation(), partNum, time, time + atom.getGranule(), 0);
            changeTask.addAtom(rAtom);
        }
    }
    return changeTask;
}
Also used : BRFSTimeFilter(com.bonree.brfs.common.files.impl.BRFSTimeFilter) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Aggregations

BRFSTimeFilter (com.bonree.brfs.common.files.impl.BRFSTimeFilter)3 AtomTaskResultModel (com.bonree.brfs.schedulers.task.model.AtomTaskResultModel)2 HashMap (java.util.HashMap)2 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)1 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)1