Search in sources :

Example 1 with AtomTaskModel

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

the class TasksUtils method createUserDelete.

/**
 * 概述:创建可执行任务信息
 * @param sn storageName信息
 * @param taskType 任务类型
 * @param opertationContent 执行的内容,暂时无用
 * @param startTime 要操作数据的开始时间 -1标识为sn的创建时间
 * @param endTime 要操作数据的结束时间。
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static TaskModel createUserDelete(final StorageRegion sn, final TaskType taskType, final String opertationContent, final long startTime, final long endTime) {
    if (sn == null || taskType == null) {
        return null;
    }
    TaskModel task = new TaskModel();
    List<AtomTaskModel> storageAtoms = new ArrayList<>();
    if (endTime == 0 || startTime >= endTime) {
        return null;
    }
    long granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
    String snName = sn.getName();
    long startHour;
    long endHour = endTime - endTime % granule;
    // 删除sn
    boolean isALL = UserDeleteJob.DELETE_SN_ALL.equals(opertationContent);
    if (isALL) {
        startHour = sn.getCreateTime() - sn.getCreateTime() % granule;
    } else {
        startHour = startTime - startTime % granule;
    }
    // 若是删除sn时,创建时间与删除时间间隔较短时,结束时间向后退
    if (startHour == endHour) {
        endHour = endHour + granule;
    }
    if (startHour >= endHour) {
        return null;
    }
    AtomTaskModel atom = AtomTaskModel.getInstance(null, snName, opertationContent, sn.getReplicateNum(), startHour, endHour, granule);
    storageAtoms.add(atom);
    task.setAtomList(storageAtoms);
    task.setTaskState(TaskState.INIT.code());
    task.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    task.setTaskType(taskType.code());
    return task;
}
Also used : ArrayList(java.util.ArrayList) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 2 with AtomTaskModel

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

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

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

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

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