Search in sources :

Example 1 with TaskResultModel

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

the class TaskStateLifeContral method updateMapTaskMessage.

/**
 * 概述:更新任务map的任务状态
 * @param context
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static void updateMapTaskMessage(JobExecutionContext context, TaskResultModel result) {
    JobDataMap data = context.getJobDetail().getJobDataMap();
    if (data == null) {
        return;
    }
    // 结果为空不更新批次任务结果
    if (result == null) {
        return;
    }
    boolean isSuccess = result.isSuccess();
    TaskResultModel sumResult;
    String content = null;
    if (data.containsKey(JobDataMapConstract.TASK_RESULT)) {
        content = data.getString(JobDataMapConstract.TASK_RESULT);
    }
    if (!BrStringUtils.isEmpty(content)) {
        sumResult = JsonUtils.toObjectQuietly(content, TaskResultModel.class);
    } else {
        sumResult = new TaskResultModel();
    }
    sumResult.addAll(result.getAtoms());
    sumResult.setSuccess(isSuccess && sumResult.isSuccess());
    String sumContent = JsonUtils.toJsonStringQuietly(sumResult);
    data.put(JobDataMapConstract.TASK_RESULT, sumContent);
}
Also used : JobDataMap(org.quartz.JobDataMap) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel)

Example 2 with TaskResultModel

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

the class CycleJobWithZKTask method createBatchData.

public void createBatchData(MetaTaskManagerInterface release, JobDataMap data, String serverId, TaskType taskType, int batchSize, int limitCount) {
    // 从zk获取任务信息最后一次执行成功的  若任务为空则返回
    Pair<String, TaskModel> taskPair = TaskStateLifeContral.getCurrentOperationTask(release, taskType.name(), serverId, limitCount);
    if (taskPair == null) {
        LOG.info("{} task queue is empty !!!", taskType.name());
        return;
    }
    // 将当前的任务分成批次执行
    TaskModel task = TaskStateLifeContral.changeRunTaskModel(taskPair.getSecond());
    String currentTaskName = taskPair.getFirst();
    if (BrStringUtils.isEmpty(currentTaskName)) {
        LOG.info("{} {} task behind is empty !!!", taskType.name());
        return;
    }
    Map<String, String> batchDatas = BatchTaskFactory.createBatch(task, batchSize);
    // 若批次为空则更新任务状态
    if (batchDatas == null || batchDatas.isEmpty()) {
        LOG.info("batch data is empty !! update task :{} {}", taskType.name(), currentTaskName);
        TaskStateLifeContral.updateTaskStatusByCompelete(serverId, currentTaskName, taskType.name(), new TaskResultModel());
        data.put(JobDataMapConstract.CURRENT_TASK_NAME, "");
        data.put(JobDataMapConstract.CURRENT_INDEX, 0 + "");
        return;
    }
    data.putAll(batchDatas);
    data.put(JobDataMapConstract.CURRENT_TASK_NAME, currentTaskName);
    // 更新zk任务状态
    TaskStateLifeContral.updateTaskRunState(serverId, currentTaskName, taskType.name());
}
Also used : TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel)

Example 3 with TaskResultModel

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

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

the class SystemCheckJob method checkFiles.

/**
 * @param atom
 * @param dataPath
 * @return
 */
public TaskResultModel checkFiles(AtomTaskModel atom, String dataPath) {
    String snName = atom.getStorageName();
    int partitionNum = atom.getPatitionNum();
    long startTime = TimeUtils.getMiles(atom.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
    long endTime = TimeUtils.getMiles(atom.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
    Map<String, String> snMap = new HashMap<>();
    snMap.put(BRFSPath.STORAGEREGION, snName);
    List<BRFSPath> eFiles = BRFSFileUtil.scanBRFSFiles(dataPath, snMap, snMap.size(), new BRFSCheckFilter(startTime, endTime));
    List<String> errors = new ArrayList<>();
    if (eFiles != null) {
        for (BRFSPath brfsPath : eFiles) {
            errors.add(brfsPath.getFileName());
        }
    }
    TaskResultModel result = new TaskResultModel();
    AtomTaskResultModel atomR = AtomTaskResultModel.getInstance(errors, snName, startTime, endTime, "", partitionNum);
    if (errors != null && !errors.isEmpty()) {
        atomR.setSuccess(false);
        result.setSuccess(false);
    }
    result.add(atomR);
    LOG.debug("result : {}", JsonUtils.toJsonStringQuietly(result));
    return result;
}
Also used : HashMap(java.util.HashMap) 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)

Example 5 with TaskResultModel

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

Aggregations

TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)11 JobDataMap (org.quartz.JobDataMap)7 AtomTaskResultModel (com.bonree.brfs.schedulers.task.model.AtomTaskResultModel)6 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)5 BatchAtomModel (com.bonree.brfs.schedulers.task.model.BatchAtomModel)4 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)3 EmailPool (com.bonree.brfs.email.EmailPool)2 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)2 ServiceManager (com.bonree.brfs.common.service.ServiceManager)1 TaskState (com.bonree.brfs.common.task.TaskState)1 TaskType (com.bonree.brfs.common.task.TaskType)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 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)1 TaskServerNodeModel (com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)1