Search in sources :

Example 1 with TaskType

use of com.bonree.brfs.common.task.TaskType 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 2 with TaskType

use of com.bonree.brfs.common.task.TaskType 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)

Example 3 with TaskType

use of com.bonree.brfs.common.task.TaskType in project BRFS by zhangnianli.

the class DefaultReleaseTask method updateTaskContentNode.

@Override
public String updateTaskContentNode(TaskModel data, String taskType, String taskName) {
    String pathNode = null;
    try {
        if (data == null) {
            LOG.warn("task content is empty");
            return null;
        }
        byte[] datas = JsonUtils.toJsonBytes(data);
        if (datas == null || datas.length == 0) {
            LOG.warn("task content convert is empty");
            return null;
        }
        if (BrStringUtils.isEmpty(taskType)) {
            LOG.warn("task type is empty");
            return null;
        }
        TaskType current = TaskType.valueOf(taskType);
        int taskTypeIndex = current == null ? 0 : current.code();
        StringBuilder pathBuilder = new StringBuilder();
        pathBuilder.append(this.taskQueue).append("/").append(taskType).append("/");
        if (BrStringUtils.isEmpty(taskName)) {
            pathBuilder.append(taskTypeIndex);
        } else {
            pathBuilder.append(taskName);
        }
        String taskPath = pathBuilder.toString();
        if (!BrStringUtils.isEmpty(taskName) && client.checkExists(taskPath)) {
            client.setData(taskPath, datas);
            return taskName;
        }
        pathNode = client.createPersistentSequential(taskPath, true, datas);
        String[] nodes = BrStringUtils.getSplit(pathNode, "/");
        if (nodes != null && nodes.length != 0) {
            return nodes[nodes.length - 1];
        }
    } catch (Exception e) {
        LOG.error("update task error {}", e);
    }
    return pathNode;
}
Also used : TaskType(com.bonree.brfs.common.task.TaskType)

Example 4 with TaskType

use of com.bonree.brfs.common.task.TaskType in project BRFS by zhangnianli.

the class CreateSystemTaskJob method operation.

@Override
public void operation(JobExecutionContext context) {
    LOG.info("create system task working");
    // 判断是否有恢复任务,有恢复任务则不进行创建
    JobDataMap data = context.getJobDetail().getJobDataMap();
    long checkTtl = data.getLong(JobDataMapConstract.CHECK_TTL);
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    // 获取开启的任务名称
    List<TaskType> switchList = mcf.getTaskOn();
    if (switchList == null || switchList.isEmpty()) {
        LOG.warn("switch on task is empty !!!");
        return;
    }
    // 获取可用服务
    String groupName = mcf.getGroupName();
    ServiceManager sm = mcf.getSm();
    // 2.设置可用服务
    List<String> serverIds = CreateSystemTask.getServerIds(sm, groupName);
    if (serverIds == null || serverIds.isEmpty()) {
        LOG.warn("{} available server list is null", groupName);
        return;
    }
    // 3.获取storageName
    StorageRegionManager snm = mcf.getSnm();
    List<StorageRegion> snList = snm.getStorageRegionList();
    if (snList == null || snList.isEmpty()) {
        LOG.info("skip create system task !!! because storageName is null !!!");
        return;
    }
    TaskModel task;
    String taskName;
    TaskTypeModel tmodel;
    long ttl = 0;
    Pair<TaskModel, TaskTypeModel> result;
    List<String> srs = TaskStateLifeContral.getSRs(snm);
    for (TaskType taskType : switchList) {
        if (TaskType.SYSTEM_COPY_CHECK.equals(taskType) || TaskType.USER_DELETE.equals(taskType)) {
            continue;
        }
        TaskStateLifeContral.watchSR(release, srs, taskType.name());
        if (TaskType.SYSTEM_DELETE.equals(taskType)) {
            ttl = 0;
        } else if (TaskType.SYSTEM_CHECK.equals(taskType)) {
            ttl = checkTtl;
        }
        tmodel = release.getTaskTypeInfo(taskType.name());
        if (tmodel == null) {
            tmodel = new TaskTypeModel();
            tmodel.setSwitchFlag(true);
            LOG.warn("taskType{} is switch but metadata is null");
        }
        result = CreateSystemTask.createSystemTask(tmodel, taskType, snList, ttl);
        if (result == null) {
            LOG.warn("create sys task is empty {}", taskType.name());
            continue;
        }
        task = result.getFirst();
        taskName = CreateSystemTask.updateTask(release, task, serverIds, taskType);
        if (!BrStringUtils.isEmpty(taskName)) {
            LOG.info("create {} {} task successfull !!!", taskType.name(), taskName);
            release.setTaskTypeModel(taskType.name(), tmodel);
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) 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) TaskType(com.bonree.brfs.common.task.TaskType) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel)

Example 5 with TaskType

use of com.bonree.brfs.common.task.TaskType in project BRFS by zhangnianli.

the class InitTaskManager method recoveryTask.

/**
 * 概述:修复任务状态
 * @param swtichList
 * @param release
 * @param serverId
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
private static Map<String, String> recoveryTask(List<TaskType> swtichList, MetaTaskManagerInterface release, String serverId) {
    Map<String, String> swtichMap = new HashMap<>();
    if (swtichList == null || swtichList.isEmpty()) {
        return swtichMap;
    }
    String typeName;
    String currentTask;
    for (TaskType taskType : swtichList) {
        typeName = taskType.name();
        currentTask = release.getLastSuccessTaskIndex(typeName, serverId);
        if (BrStringUtils.isEmpty(currentTask)) {
            currentTask = release.getFirstServerTask(typeName, serverId);
        }
        if (BrStringUtils.isEmpty(currentTask)) {
            currentTask = release.getFirstTaskName(typeName);
        }
        if (BrStringUtils.isEmpty(currentTask)) {
            LOG.info("{} task queue is empty", currentTask);
            continue;
        }
        // 修复任务
        recoveryTask(release, typeName, currentTask, serverId);
        if (BrStringUtils.isEmpty(currentTask)) {
            continue;
        }
        swtichMap.put(typeName, currentTask);
    }
    return swtichMap;
}
Also used : HashMap(java.util.HashMap) TaskType(com.bonree.brfs.common.task.TaskType)

Aggregations

TaskType (com.bonree.brfs.common.task.TaskType)9 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)5 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)4 JobDataMap (org.quartz.JobDataMap)4 EmailPool (com.bonree.brfs.email.EmailPool)3 ServiceManager (com.bonree.brfs.common.service.ServiceManager)2 RunnableTaskInterface (com.bonree.brfs.schedulers.task.manager.RunnableTaskInterface)2 SchedulerManagerInterface (com.bonree.brfs.schedulers.task.manager.SchedulerManagerInterface)2 SumbitTaskInterface (com.bonree.brfs.schedulers.task.meta.SumbitTaskInterface)2 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)2 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)2 TaskState (com.bonree.brfs.common.task.TaskState)1 JsonException (com.bonree.brfs.common.utils.JsonUtils.JsonException)1 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)1 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)1 LimitServerResource (com.bonree.brfs.resourceschedule.model.LimitServerResource)1 CopyRecoveryJob (com.bonree.brfs.schedulers.jobs.biz.CopyRecoveryJob)1 TaskExecutablePattern (com.bonree.brfs.schedulers.task.model.TaskExecutablePattern)1 TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)1 TaskRunPattern (com.bonree.brfs.schedulers.task.model.TaskRunPattern)1