Search in sources :

Example 1 with MetaTaskManagerInterface

use of com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface in project BRFS by zhangnianli.

the class TaskStateLifeContral method updateTaskStatusByCompelete.

/**
 * 概述:更新任务状态
 * @param serverId
 * @param taskname
 * @param taskType
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static void updateTaskStatusByCompelete(String serverId, String taskname, String taskType, TaskResultModel taskResult) {
    if (BrStringUtils.isEmpty(taskname)) {
        LOG.warn("task name is empty !!! {} {} {}", taskType, taskname, serverId);
        return;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    TaskServerNodeModel sTask = release.getTaskServerContentNodeInfo(taskType, taskname, serverId);
    if (sTask == null) {
        LOG.debug("server task is null !!! {} {} {}", taskType, taskname, serverId);
        sTask = new TaskServerNodeModel();
    }
    LOG.debug("TaskMessage complete  sTask :{}", JsonUtils.toJsonStringQuietly(sTask));
    sTask.setResult(taskResult);
    if (BrStringUtils.isEmpty(sTask.getTaskStartTime())) {
        sTask.setTaskStartTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    }
    sTask.setTaskStopTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    TaskState status = taskResult == null ? TaskState.EXCEPTION : taskResult.isSuccess() ? TaskState.FINISH : TaskState.EXCEPTION;
    sTask.setTaskState(status.code());
    release.updateServerTaskContentNode(serverId, taskname, taskType, sTask);
    LOG.info("Complete server task :{} - {} - {} - {}", taskType, taskname, serverId, TaskState.valueOf(sTask.getTaskState()).name());
    // 更新TaskContent
    List<Pair<String, Integer>> cStatus = release.getServerStatus(taskType, taskname);
    if (cStatus == null || cStatus.isEmpty()) {
        return;
    }
    LOG.debug("complete c List {}", cStatus);
    int cstat;
    boolean isException = false;
    int finishCount = 0;
    int size = cStatus.size();
    for (Pair<String, Integer> pair : cStatus) {
        cstat = pair.getSecond();
        if (TaskState.EXCEPTION.code() == cstat) {
            isException = true;
            finishCount += 1;
        } else if (TaskState.FINISH.code() == cstat) {
            finishCount += 1;
        }
    }
    if (finishCount != size) {
        return;
    }
    TaskModel task = release.getTaskContentNodeInfo(taskType, taskname);
    if (task == null) {
        LOG.debug("task is null !!! {} {} {}", taskType, taskname);
        task = new TaskModel();
        task.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    }
    if (isException) {
        task.setTaskState(TaskState.EXCEPTION.code());
    } else {
        task.setTaskState(TaskState.FINISH.code());
    }
    release.updateTaskContentNode(task, taskType, taskname);
    LOG.info("complete task :{} - {} - {}", taskType, taskname, TaskState.valueOf(task.getTaskState()).name());
    if (TaskType.SYSTEM_CHECK.name().equals(taskType) && isException) {
        TaskModel cTask = TasksUtils.converyCopyTaskModel(release, taskname);
        if (cTask == null) {
            LOG.error("[{}]:[{}] task can't recovery !!!", taskType, taskname);
            return;
        }
        String str = TasksUtils.createCopyTask(release, taskname, cTask);
        if (BrStringUtils.isEmpty(str)) {
            boolean flag = release.setTransferTask(taskType, taskname);
            LOG.info("[{}] task [{}] find error ,transfer task create {}  ", taskType, taskname, flag ? "succefull !!!" : " fail !!!");
        } else {
            LOG.info("[{}]:[{}] find error create copy task [{}] to recovery ", taskType, taskname, str);
        }
    }
}
Also used : TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) TaskState(com.bonree.brfs.common.task.TaskState) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 2 with MetaTaskManagerInterface

use of com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface in project BRFS by zhangnianli.

the class CopyCheckJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.info("createCheck Copy Job working");
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    StorageRegionManager snm = mcf.getSnm();
    ServiceManager sm = mcf.getSm();
    List<String> srs = TaskStateLifeContral.getSRs(snm);
    TaskStateLifeContral.watchSR(release, srs, TaskType.SYSTEM_COPY_CHECK.name());
    // 判断是否有恢复任务,有恢复任务则不进行创建
    if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
        LOG.warn("rebalance task is running !! skip check copy task");
        return;
    }
    String taskType = TaskType.SYSTEM_COPY_CHECK.name();
    List<Service> services = sm.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    if (services == null || services.isEmpty()) {
        LOG.warn("skip create {} task, because service is empty", taskType);
        return;
    }
    List<StorageRegion> snList = snm.getStorageRegionList();
    if (snList == null || snList.isEmpty()) {
        LOG.warn("storagename list is null");
        return;
    }
    // 1.获取sn创建任务的实际那
    TaskTypeModel tmodel = release.getTaskTypeInfo(taskType);
    if (tmodel == null) {
        tmodel = new TaskTypeModel();
        tmodel.setSwitchFlag(true);
        release.setTaskTypeModel(taskType, tmodel);
    }
    Map<String, Long> sourceTimes = tmodel.getSnTimes();
    LOG.debug("update init sn time :{}", sourceTimes);
    // 2.过滤不符合副本校验的sn信息
    List<StorageRegion> needSns = CopyCountCheck.filterSn(snList, services.size());
    // 3.针对第一次出现的sn补充时间
    sourceTimes = CopyCountCheck.repairTime(sourceTimes, needSns);
    Map<String, List<String>> losers = CopyCountCheck.collectLossFile(needSns, services, sourceTimes);
    LOG.info("update before sn time :{}", sourceTimes);
    Pair<TaskModel, Map<String, Long>> pair = CreateSystemTask.creatTaskWithFiles(sourceTimes, losers, needSns, TaskType.SYSTEM_COPY_CHECK, RECOVERY_NUM, 0);
    if (pair == null) {
        LOG.warn("create pair is empty !!!!");
        return;
    }
    TaskModel task = pair.getFirst();
    String taskName = null;
    if (task != null) {
        List<String> servers = CreateSystemTask.getServerIds(services);
        taskName = CreateSystemTask.updateTask(release, task, servers, TaskType.SYSTEM_COPY_CHECK);
    }
    if (!BrStringUtils.isEmpty(taskName)) {
        LOG.info("create {} {} task successfull !!!", taskType, taskName);
    }
    sourceTimes = pair.getSecond();
    // 更新sn临界信息
    tmodel = release.getTaskTypeInfo(taskType);
    if (tmodel == null) {
        tmodel = new TaskTypeModel();
        tmodel.setSwitchFlag(true);
        LOG.warn("taskType {} metadata loss create against !!", taskType);
    }
    tmodel.putAllSnTimes(sourceTimes);
    release.setTaskTypeModel(taskType, tmodel);
    LOG.debug("update sn time {}", sourceTimes);
    createTransferTasks(release);
}
Also used : Service(com.bonree.brfs.common.service.Service) TaskTypeModel(com.bonree.brfs.schedulers.task.model.TaskTypeModel) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) ServiceManager(com.bonree.brfs.common.service.ServiceManager) List(java.util.List) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) Map(java.util.Map) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel)

Example 3 with MetaTaskManagerInterface

use of com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface in project BRFS by zhangnianli.

the class ManagerMetaTaskJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.info("revise task work");
    JobDataMap data = context.getJobDetail().getJobDataMap();
    // 任务过期时间 ms
    String ttlTimeStr = data.getString(JobDataMapConstract.TASK_EXPIRED_TIME);
    LOG.info("task ttl time : {}", ttlTimeStr);
    long ttlTime = Long.parseLong(ttlTimeStr);
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    // 获取可用服务
    String groupName = mcf.getGroupName();
    ServiceManager sm = mcf.getSm();
    // 2.设置可用服务
    List<String> serverIds = getServerIds(sm, groupName);
    if (serverIds == null || serverIds.isEmpty()) {
        LOG.warn("available server list is null");
        return;
    }
    for (TaskType taskType : TaskType.values()) {
        try {
            release.reviseTaskStat(taskType.name(), ttlTime, serverIds);
        } catch (Exception e) {
            LOG.warn("{}", e.getMessage());
            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);
        }
    }
    LOG.info("revise task success !!!");
}
Also used : JobDataMap(org.quartz.JobDataMap) ServiceManager(com.bonree.brfs.common.service.ServiceManager) TaskType(com.bonree.brfs.common.task.TaskType) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) EmailPool(com.bonree.brfs.email.EmailPool) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException)

Example 4 with MetaTaskManagerInterface

use of com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface in project BRFS by zhangnianli.

the class MetaTaskLeaderManager method checkSwitchTask.

public void checkSwitchTask() {
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    Map<String, Boolean> switchTask = config.getTaskPoolSwitchMap();
    TaskTypeModel type;
    String taskTypeName;
    boolean flag;
    for (Map.Entry<String, Boolean> entry : switchTask.entrySet()) {
        taskTypeName = entry.getKey();
        flag = entry.getValue();
        if (BrStringUtils.isEmpty(taskTypeName)) {
            continue;
        }
        type = release.getTaskTypeInfo(taskTypeName);
        if (type == null) {
            type = new TaskTypeModel();
        } else if (type.isSwitchFlag() == flag) {
            continue;
        }
        type.setSwitchFlag(flag);
        release.setTaskTypeModel(taskTypeName, type);
    }
}
Also used : TaskTypeModel(com.bonree.brfs.schedulers.task.model.TaskTypeModel) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) Map(java.util.Map)

Example 5 with MetaTaskManagerInterface

use of com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface in project BRFS by zhangnianli.

the class OperationTaskJob method operation.

@Override
public void operation(JobExecutionContext context) {
    JobDataMap data = context.getJobDetail().getJobDataMap();
    String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    if (release == null) {
        throw new NullPointerException("MetaTaskManager is empty !!!");
    }
    List<TaskType> switchList = mcf.getTaskOn();
    if (switchList == null || switchList.isEmpty()) {
        LOG.warn("switch task is empty !!!");
        return;
    }
    SchedulerManagerInterface schd = mcf.getStm();
    if (schd == null) {
        throw new NullPointerException("SchedulerManagerInterface is empty !!!");
    }
    RunnableTaskInterface runTask = mcf.getRt();
    if (runTask == null) {
        throw new NullPointerException("RunnableTaskInterface is empty !!!");
    }
    String typeName;
    String currentTaskName;
    TaskModel task;
    TaskRunPattern runPattern;
    int poolSize;
    int sumbitSize;
    String serverId = mcf.getServerId();
    SumbitTaskInterface sumbitTask;
    // 判断是否有恢复任务,有恢复任务则不进行创建
    boolean rebalanceFlag = WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE);
    for (TaskType taskType : switchList) {
        sumbitTask = null;
        try {
            if (TaskType.SYSTEM_COPY_CHECK.equals(taskType)) {
                continue;
            }
            typeName = taskType.name();
            poolSize = schd.getTaskPoolSize(typeName);
            sumbitSize = schd.getSumbitedTaskCount(typeName);
            // 判断任务是否可以执行
            boolean isRun = runTask.taskRunnable(taskType.code(), poolSize, sumbitSize);
            if (!isRun) {
                LOG.warn("resource is limit !!! skip {} !!!", typeName);
                continue;
            }
            int retryCount = 3;
            if (TaskType.SYSTEM_CHECK.equals(taskType) || TaskType.SYSTEM_MERGER.equals(taskType) || TaskType.SYSTEM_DELETE.equals(taskType)) {
                retryCount = 0;
            }
            Pair<String, TaskModel> taskPair = TaskStateLifeContral.getCurrentOperationTask(release, typeName, serverId, retryCount);
            if (taskPair == null) {
                LOG.warn("taskType :{} taskName: null is vaild ,skiping !!!", typeName);
                continue;
            }
            currentTaskName = taskPair.getFirst();
            task = TaskStateLifeContral.changeRunTaskModel(taskPair.getSecond(), dataPath);
            // 获取执行策略
            runPattern = runTask.taskRunnPattern(task);
            if (runPattern == null) {
                LOG.warn("TaskRunPattern is null will do it once");
                runPattern = new TaskRunPattern();
                runPattern.setRepeateCount(1);
                runPattern.setSleepTime(1000);
            }
            // 创建任务提交信息
            if (TaskType.SYSTEM_DELETE.equals(taskType)) {
                sumbitTask = createSimpleTask(task, runPattern, currentTaskName, mcf.getServerId(), SystemDeleteJob.class.getCanonicalName(), dataPath);
            }
            if (TaskType.SYSTEM_CHECK.equals(taskType)) {
                sumbitTask = createSimpleTask(task, runPattern, currentTaskName, mcf.getServerId(), SystemCheckJob.class.getCanonicalName(), dataPath);
            }
            if (TaskType.USER_DELETE.equals(taskType)) {
                sumbitTask = createSimpleTask(task, runPattern, currentTaskName, mcf.getServerId(), UserDeleteJob.class.getCanonicalName(), dataPath);
            }
            if (rebalanceFlag && TaskType.SYSTEM_CHECK.equals(taskType)) {
                LOG.warn("rebalance task running !! Skip {} sumbit", taskType.name());
                continue;
            }
            if (sumbitTask == null) {
                LOG.warn("sumbit type:{}, taskName :{}, taskcontent is null", typeName, currentTaskName);
                continue;
            }
            boolean isSumbit = schd.addTask(typeName, sumbitTask);
            LOG.info("sumbit type:{}, taskName :{}, state:{}", typeName, currentTaskName, isSumbit);
            if (!isSumbit) {
                LOG.warn("next cycle will sumbit against type : {}, taskName : {}", typeName, currentTaskName);
                continue;
            }
            // 更新任务状态
            // 更新任务执行的位置
            data.put(typeName, currentTaskName);
        } catch (Exception e) {
            LOG.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) SumbitTaskInterface(com.bonree.brfs.schedulers.task.meta.SumbitTaskInterface) TaskRunPattern(com.bonree.brfs.schedulers.task.model.TaskRunPattern) EmailPool(com.bonree.brfs.email.EmailPool) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) JsonException(com.bonree.brfs.common.utils.JsonUtils.JsonException) RunnableTaskInterface(com.bonree.brfs.schedulers.task.manager.RunnableTaskInterface) TaskType(com.bonree.brfs.common.task.TaskType) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) SchedulerManagerInterface(com.bonree.brfs.schedulers.task.manager.SchedulerManagerInterface) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel)

Aggregations

MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)13 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)9 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)7 TaskType (com.bonree.brfs.common.task.TaskType)5 JobDataMap (org.quartz.JobDataMap)5 ServiceManager (com.bonree.brfs.common.service.ServiceManager)4 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)4 TaskTypeModel (com.bonree.brfs.schedulers.task.model.TaskTypeModel)4 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)3 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)3 EmailPool (com.bonree.brfs.email.EmailPool)3 SchedulerManagerInterface (com.bonree.brfs.schedulers.task.manager.SchedulerManagerInterface)3 SumbitTaskInterface (com.bonree.brfs.schedulers.task.meta.SumbitTaskInterface)3 Map (java.util.Map)3 TaskState (com.bonree.brfs.common.task.TaskState)2 RunnableTaskInterface (com.bonree.brfs.schedulers.task.manager.RunnableTaskInterface)2 TaskServerNodeModel (com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)2 List (java.util.List)2 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)2 Service (com.bonree.brfs.common.service.Service)1