Search in sources :

Example 6 with TaskResultModel

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

Example 7 with TaskResultModel

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

the class CopyRecoveryJob method operation.

@Override
public void operation(JobExecutionContext context) {
    JobDataMap data = context.getJobDetail().getJobDataMap();
    String currentIndex = data.getString(JobDataMapConstract.CURRENT_INDEX);
    String zkHosts = data.getString(JobDataMapConstract.ZOOKEEPER_ADDRESS);
    String baseRoutPath = data.getString(JobDataMapConstract.BASE_ROUTE_PATH);
    String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
    TaskResultModel result = null;
    String content = data.getString(currentIndex);
    result = CopyRecovery.recoveryDirs(content, zkHosts, baseRoutPath, dataPath);
    LOG.debug("CURRENT_INDEX: {} status:{}", currentIndex, result.isSuccess());
    TaskStateLifeContral.updateMapTaskMessage(context, result);
}
Also used : JobDataMap(org.quartz.JobDataMap) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel)

Example 8 with TaskResultModel

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

the class TasksUtils method getErrorFile.

/**
 * 概述:生成任务信息
 * @param taskContents
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static TaskModel getErrorFile(List<TaskServerNodeModel> taskContents) {
    if (taskContents == null || taskContents.isEmpty()) {
        return null;
    }
    TaskResultModel tmpR;
    List<AtomTaskResultModel> tmpRs;
    Map<String, Map<String, AtomTaskModel>> rmap = new HashMap<>();
    Map<String, AtomTaskModel> emap;
    String snName;
    String key;
    AtomTaskModel atom;
    Map<String, Integer> snMap = new HashMap<>();
    for (TaskServerNodeModel serverModel : taskContents) {
        tmpR = serverModel.getResult();
        if (tmpR == null) {
            continue;
        }
        tmpRs = tmpR.getAtoms();
        if (tmpRs == null || tmpRs.isEmpty()) {
            continue;
        }
        for (AtomTaskResultModel r : tmpRs) {
            if (r == null) {
                continue;
            }
            snName = r.getSn();
            if (!rmap.containsKey(snName)) {
                rmap.put(snName, new HashMap<>());
            }
            if (!snMap.containsKey(snName)) {
                snMap.put(snName, r.getPartNum());
            }
            emap = rmap.get(snName);
            key = r.getDataStartTime() + "_" + r.getDataStopTime();
            long granule = TimeUtils.getMiles(r.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE) - TimeUtils.getMiles(r.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
            if (!emap.containsKey(key)) {
                atom = AtomTaskModel.getInstance(null, snName, CopyCheckJob.RECOVERY_CRC, r.getPartNum(), r.getDataStartTime(), r.getDataStopTime(), granule);
                emap.put(key, atom);
            }
            atom = emap.get(key);
            atom.addAllFiles(r.getFiles());
        }
    }
    List<AtomTaskModel> tList = filterError(rmap, snMap);
    if (tList == null || tList.isEmpty()) {
        return null;
    }
    TaskModel tTask = new TaskModel();
    tTask.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    tTask.setAtomList(tList);
    tTask.setTaskState(TaskState.INIT.code());
    tTask.setTaskType(TaskType.SYSTEM_COPY_CHECK.code());
    return tTask;
}
Also used : HashMap(java.util.HashMap) TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) HashMap(java.util.HashMap) Map(java.util.Map) 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 9 with TaskResultModel

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

the class CycleJobWithZKTask method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    int taskTypeCode = 0;
    int batchSize = 10;
    String currentTaskName = null;
    int batchIndex = 0;
    TaskType taskType = null;
    String serverId = null;
    JobDataMap data = context.getJobDetail().getJobDataMap();
    boolean isSuccess = true;
    try {
        // 获取当前的任务信息
        taskTypeCode = data.getInt(JobDataMapConstract.TASK_TYPE);
        taskType = TaskType.valueOf(taskTypeCode);
        batchSize = data.getInt(JobDataMapConstract.BATCH_SIZE);
        if (!data.containsKey(JobDataMapConstract.CURRENT_TASK_NAME)) {
            data.put(JobDataMapConstract.CURRENT_TASK_NAME, "");
        }
        serverId = data.getString(JobDataMapConstract.SERVER_ID);
        currentTaskName = data.getString(JobDataMapConstract.CURRENT_TASK_NAME);
        if (!data.containsKey(JobDataMapConstract.CURRENT_INDEX)) {
            data.put(JobDataMapConstract.CURRENT_INDEX, "0");
            LOG.info("task:{}-{} start", taskType.name(), currentTaskName);
        }
        batchIndex = data.getInt(JobDataMapConstract.CURRENT_INDEX);
        LOG.debug("current :{}, batchId : {}", currentTaskName, batchIndex);
        if (batchSize == 0) {
            batchSize = 10;
        }
        if (batchIndex >= 1) {
            operation(context);
        }
    } catch (Exception e) {
        LOG.info("happend Exception :{}", e);
        context.put("ExceptionMessage", e.getMessage());
        caughtException(context);
        isSuccess = false;
        EmailPool emailPool = EmailPool.getInstance();
        MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
        builder.setModel(this.getClass().getSimpleName() + "模块服务发生问题");
        builder.setException(e);
        ManagerContralFactory mcf = ManagerContralFactory.getInstance();
        builder.setMessage(mcf.getGroupName() + "(" + mcf.getServerId() + ")服务 执行任务时发生问题");
        builder.setVariable(data.getWrappedMap());
        emailPool.sendEmail(builder);
    } finally {
        // 判断是否有恢复任务,有恢复任务则不进行创建
        if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
            LOG.warn("rebalance task is running !! skip check copy task");
            return;
        }
        if (batchIndex >= 1) {
            LOG.debug("batch ID :{} {} {} {} {}", batchIndex, taskType, currentTaskName, serverId, isSuccess ? TaskState.RUN : TaskState.EXCEPTION);
            TaskResultModel resultTask = new TaskResultModel();
            resultTask.setSuccess(isSuccess);
            TaskStateLifeContral.updateMapTaskMessage(context, resultTask);
        }
        // 最后一次执行更新任务状态并处理任务
        if (batchIndex == 1) {
            String result = data.getString(JobDataMapConstract.TASK_RESULT);
            TaskResultModel tResult = new TaskResultModel();
            if (!BrStringUtils.isEmpty(result)) {
                tResult = JsonUtils.toObjectQuietly(result, TaskResultModel.class);
            }
            TaskState state = isSuccess && tResult.isSuccess() ? TaskState.FINISH : TaskState.EXCEPTION;
            LOG.info("task:{}-{}-{}  end !", taskType.name(), currentTaskName, state.name());
            LOG.debug("batch ID :{} {} {} {} {}", batchIndex, taskType, currentTaskName, serverId, state);
            TaskStateLifeContral.updateTaskStatusByCompelete(serverId, currentTaskName, taskType.name(), tResult);
            data.put(JobDataMapConstract.CURRENT_INDEX, (batchIndex - 1) + "");
            data.put(JobDataMapConstract.TASK_RESULT, "");
            data.put(JobDataMapConstract.CURRENT_TASK_NAME, "");
            data.put(JobDataMapConstract.CURRENT_INDEX, (batchIndex - 1) + "");
        } else if (batchIndex <= 0) {
            ManagerContralFactory mcf = ManagerContralFactory.getInstance();
            MetaTaskManagerInterface release = mcf.getTm();
            // 创建任务
            createBatchData(release, data, serverId, taskType, batchSize, 3);
        } else {
            // 更新任务状态
            data.put(JobDataMapConstract.CURRENT_INDEX, (batchIndex - 1) + "");
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) TaskType(com.bonree.brfs.common.task.TaskType) EmailPool(com.bonree.brfs.email.EmailPool) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) TaskState(com.bonree.brfs.common.task.TaskState) JobExecutionException(org.quartz.JobExecutionException) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException)

Example 10 with TaskResultModel

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

the class QuartzOperationStateWithZKTask method execute.

@Override
public void execute(JobExecutionContext context) {
    int currentIndex = -1;
    JobDataMap data = null;
    String serverId = null;
    String taskTypeName = null;
    String taskName = null;
    boolean isSuccess = true;
    try {
        data = context.getJobDetail().getJobDataMap();
        int repeatCount = data.getInt(JobDataMapConstract.TASK_REPEAT_RUN_COUNT);
        taskName = data.getString(JobDataMapConstract.TASK_NAME);
        serverId = data.getString(JobDataMapConstract.SERVER_ID);
        int taskType = data.getInt(JobDataMapConstract.TASK_TYPE);
        taskTypeName = TaskType.valueOf(taskType).name();
        // 设置当前任务执行
        if (!data.containsKey(JobDataMapConstract.CURRENT_INDEX)) {
            data.put(JobDataMapConstract.CURRENT_INDEX, repeatCount + "");
            TaskStateLifeContral.updateTaskRunState(serverId, taskName, taskTypeName);
            LOG.info("task {}-{} run", taskTypeName, taskName);
        }
        currentIndex = data.getInt(JobDataMapConstract.CURRENT_INDEX);
        LOG.debug("taskType [{}],taskname [{}],batch id[{}], data :[{}]", taskTypeName, taskName, currentIndex, data.getString(currentIndex + ""));
        operation(context);
    } catch (Exception e) {
        context.put("ExceptionMessage", e.getMessage());
        caughtException(context);
        isSuccess = false;
        LOG.error("task {}-{} happen exception:{}", taskTypeName, taskName, e);
        EmailPool emailPool = EmailPool.getInstance();
        MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
        builder.setModel(this.getClass().getSimpleName() + " execute 模块服务发生问题");
        builder.setException(e);
        ManagerContralFactory mcf = ManagerContralFactory.getInstance();
        builder.setMessage(mcf.getGroupName() + "(" + mcf.getServerId() + ")服务 执行任务时发生问题");
        builder.setVariable(data.getWrappedMap());
        emailPool.sendEmail(builder);
    } finally {
        if (data == null) {
            return;
        }
        LOG.debug("operation batch id {}", currentIndex);
        try {
            // 更新任务状态
            TaskResultModel resultTask = new TaskResultModel();
            resultTask.setSuccess(isSuccess);
            TaskStateLifeContral.updateMapTaskMessage(context, resultTask);
            // 更新要操作的批次
            if (currentIndex > 1) {
                data.put(JobDataMapConstract.CURRENT_INDEX, (currentIndex - 1) + "");
            // 最后一次更新任务信息
            } else if (currentIndex == 1) {
                String result = data.getString(JobDataMapConstract.TASK_RESULT);
                TaskResultModel tResult = new TaskResultModel();
                if (!BrStringUtils.isEmpty(result)) {
                    tResult = JsonUtils.toObjectQuietly(result, TaskResultModel.class);
                }
                TaskStateLifeContral.updateTaskStatusByCompelete(serverId, taskName, taskTypeName, tResult);
                data.put(JobDataMapConstract.CURRENT_INDEX, (currentIndex - 1) + "");
                LOG.info("task {}-{}:{} end!!", taskTypeName, taskName, tResult.isSuccess());
            }
        } catch (Exception e) {
            LOG.error("execute error", e);
            EmailPool emailPool = EmailPool.getInstance();
            MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
            builder.setModel(this.getClass().getSimpleName() + "模块服务发生问题");
            builder.setException(e);
            builder.setMessage("更新任务发生错误");
            builder.setVariable(data.getWrappedMap());
            emailPool.sendEmail(builder);
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) EmailPool(com.bonree.brfs.email.EmailPool) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException)

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