Search in sources :

Example 1 with BatchAtomModel

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

the class JobDataMapConstract method groupAtoms.

public static Map<Integer, BatchAtomModel> groupAtoms(final List<AtomTaskModel> atoms, int batchCount) throws IllegalArgumentException {
    Map<Integer, BatchAtomModel> batchMap = new HashMap<Integer, BatchAtomModel>();
    BatchAtomModel batch = null;
    int size = atoms == null ? 0 : atoms.size();
    if (batchCount <= 0) {
        throw new IllegalArgumentException("batch time below zero !!!");
    }
    int batchSize = size % batchCount == 0 ? size / batchCount : size / batchCount + size % batchCount;
    int fromIndex = 0;
    int rSize = 0;
    for (int i = 1; i <= batchCount; i++) {
        if (!batchMap.containsKey(i)) {
            batchMap.put(i, new BatchAtomModel());
        }
        if (size == 0) {
            continue;
        }
        batch = batchMap.get(i);
        if (fromIndex > size) {
            continue;
        } else if (fromIndex + batchSize <= size) {
            batch.addAll(atoms.subList(fromIndex, fromIndex + batchSize));
        } else {
            batch.addAll(atoms.subList(fromIndex, size));
        }
        rSize += batch.getAtoms().size();
        fromIndex += batchSize;
    }
    if (size != rSize) {
        throw new IllegalArgumentException("total batch [" + rSize + "] not equal source [" + size + "], batch count [" + batchCount + "]");
    }
    return batchMap;
}
Also used : HashMap(java.util.HashMap) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel)

Example 2 with BatchAtomModel

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

the class SystemDeleteJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.debug("----------> system delete work");
    JobDataMap data = context.getJobDetail().getJobDataMap();
    String currentIndex = data.getString(JobDataMapConstract.CURRENT_INDEX);
    String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
    String content = data.getString(currentIndex);
    LOG.debug("batch {}", content);
    // 获取当前执行的任务类型
    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;
    for (AtomTaskModel atom : atoms) {
        snName = atom.getStorageName();
        if (BrStringUtils.isEmpty(snName)) {
            LOG.debug("sn is empty !!!");
            continue;
        }
        usrResult = deleteDirs(atom, dataPath);
        if (usrResult == null) {
            continue;
        }
        if (!usrResult.isSuccess()) {
            result.setSuccess(false);
        }
        result.add(usrResult);
    }
    // 更新任务状态
    TaskStateLifeContral.updateMapTaskMessage(context, result);
}
Also used : JobDataMap(org.quartz.JobDataMap) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel) 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)

Example 3 with BatchAtomModel

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

the class BatchTaskFactory method createBatch.

/**
 * 概述:
 * @param task
 * @param batchSize
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static Map<String, String> createBatch(TaskModel task, int batchSize) {
    Map<String, String> batchDatas = new HashMap<String, String>();
    if (task == null) {
        return batchDatas;
    }
    List<AtomTaskModel> atoms = convernTaskModel(task);
    if (atoms == null || atoms.isEmpty()) {
        return batchDatas;
    }
    int size = atoms.size();
    int batchCount = size % batchSize == 0 ? size / batchSize : size / batchSize + 1;
    BatchAtomModel batch = null;
    List<AtomTaskModel> tmp = null;
    // 若不足一次则按一次来
    if (batchCount == 0) {
        batch = new BatchAtomModel();
        batch.addAll(atoms);
        batchDatas.put(JobDataMapConstract.CURRENT_INDEX, "1");
        batchDatas.put("1", JsonUtils.toJsonStringQuietly(batch));
        return batchDatas;
    }
    batchDatas.put(JobDataMapConstract.CURRENT_INDEX, batchCount + "");
    int index = 0;
    for (int i = 1; i <= batchCount; i++) {
        batch = new BatchAtomModel();
        if (index >= size) {
            tmp = new ArrayList<>();
        } else if (index + batchSize > size) {
            tmp = atoms.subList(index, size);
        } else if (index + batchSize <= size) {
            tmp = atoms.subList(index, index + batchSize);
        }
        batch.addAll(tmp);
        batchDatas.put(i + "", JsonUtils.toJsonStringQuietly(batch));
        index = index + batchSize;
    }
    return batchDatas;
}
Also used : HashMap(java.util.HashMap) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 4 with BatchAtomModel

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

the class SystemCheckJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.debug("check task work");
    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 = null;
    TaskResultModel result = new TaskResultModel();
    TaskResultModel batchResult = null;
    for (AtomTaskModel atom : atoms) {
        snName = atom.getStorageName();
        if (BrStringUtils.isEmpty(snName)) {
            LOG.warn("sn is empty !!!");
            continue;
        }
        batchResult = checkFiles(atom, dataPath);
        if (batchResult == null) {
            continue;
        }
        if (!batchResult.isSuccess()) {
            result.setSuccess(batchResult.isSuccess());
        }
        result.addAll(batchResult.getAtoms());
    }
    // 更新任务状态
    TaskStateLifeContral.updateMapTaskMessage(context, result);
}
Also used : JobDataMap(org.quartz.JobDataMap) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 5 with BatchAtomModel

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

BatchAtomModel (com.bonree.brfs.schedulers.task.model.BatchAtomModel)6 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)5 AtomTaskResultModel (com.bonree.brfs.schedulers.task.model.AtomTaskResultModel)4 TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)4 JobDataMap (org.quartz.JobDataMap)3 HashMap (java.util.HashMap)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 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)1 ArrayList (java.util.ArrayList)1