Search in sources :

Example 6 with AtomTaskResultModel

use of com.bonree.brfs.schedulers.task.model.AtomTaskResultModel 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 7 with AtomTaskResultModel

use of com.bonree.brfs.schedulers.task.model.AtomTaskResultModel in project BRFS by zhangnianli.

the class UserDeleteJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    JobDataMap data = context.getJobDetail().getJobDataMap();
    String currentIndex = data.getString(JobDataMapConstract.CURRENT_INDEX);
    String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
    String content = data.getString(currentIndex);
    // 获取当前执行的任务类型
    if (BrStringUtils.isEmpty(content)) {
        LOG.debug("batch data is empty !!!");
        return;
    }
    BatchAtomModel batch = JsonUtils.toObject(content, BatchAtomModel.class);
    if (batch == null) {
        LOG.debug("batch data is empty !!!");
        return;
    }
    List<AtomTaskModel> atoms = batch.getAtoms();
    if (atoms == null || atoms.isEmpty()) {
        LOG.debug("atom task is empty !!!");
        return;
    }
    String snName;
    TaskResultModel result = new TaskResultModel();
    AtomTaskResultModel usrResult;
    List<String> dSns = new ArrayList<String>();
    String operation;
    for (AtomTaskModel atom : atoms) {
        snName = atom.getStorageName();
        if ("1".equals(currentIndex)) {
            operation = atom.getTaskOperation();
            LOG.debug("task operation {} ", DELETE_SN_ALL.equals(operation) ? "Delete_Storage_Region" : "Delete_Part_Of_Storage_Region_Data");
            if (DELETE_SN_ALL.equals(operation)) {
                dSns.add(snName);
            }
        }
        usrResult = deleteFiles(atom, dataPath);
        if (usrResult == null) {
            continue;
        }
        if (!usrResult.isSuccess()) {
            result.setSuccess(false);
        }
        result.add(usrResult);
    }
    if ("1".equals(currentIndex)) {
        for (String sn : dSns) {
            if (FileUtils.deleteDir(dataPath + "/" + sn, true)) {
                LOG.debug("deltete {} successfull", sn);
            } else {
                result.setSuccess(false);
            }
        }
    }
    // 更新任务状态
    TaskStateLifeContral.updateMapTaskMessage(context, result);
}
Also used : JobDataMap(org.quartz.JobDataMap) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel) ArrayList(java.util.ArrayList) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Aggregations

AtomTaskResultModel (com.bonree.brfs.schedulers.task.model.AtomTaskResultModel)7 TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)5 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)4 HashMap (java.util.HashMap)4 BatchAtomModel (com.bonree.brfs.schedulers.task.model.BatchAtomModel)3 BRFSTimeFilter (com.bonree.brfs.common.files.impl.BRFSTimeFilter)2 ArrayList (java.util.ArrayList)2 JobDataMap (org.quartz.JobDataMap)2 ServiceManager (com.bonree.brfs.common.service.ServiceManager)1 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)1 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)1 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)1 SecondIDParser (com.bonree.brfs.rebalance.route.SecondIDParser)1 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)1 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)1 TaskServerNodeModel (com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)1 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)1 Map (java.util.Map)1