Search in sources :

Example 11 with MetaTaskManagerInterface

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

the class TasksUtils method createUserDeleteTask.

/**
 * 概述:
 * @param services
 * @param zkPaths
 * @param sn
 * @param startTime
 * @param endTime
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static ReturnCode createUserDeleteTask(List<Service> services, ZookeeperPaths zkPaths, StorageRegion sn, long startTime, long endTime, boolean isAll) {
    if (services == null || services.isEmpty()) {
        return ReturnCode.DELETE_DATA_ERROR;
    }
    if (sn == null) {
        return ReturnCode.STORAGE_NONEXIST_ERROR;
    }
    String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
    MetaTaskManagerInterface release = DefaultReleaseTask.getInstance();
    release.setPropreties(zkAddresses, zkPaths.getBaseTaskPath(), zkPaths.getBaseLocksPath());
    TaskTypeModel tmodel = release.getTaskTypeInfo(TaskType.USER_DELETE.name());
    if (!tmodel.isSwitchFlag()) {
        return ReturnCode.FORBID_DELETE_DATA_ERROR;
    }
    TaskModel task = TasksUtils.createUserDelete(sn, TaskType.USER_DELETE, isAll ? UserDeleteJob.DELETE_SN_ALL : UserDeleteJob.DELETE_PART, startTime, endTime);
    if (task == null) {
        return ReturnCode.DELETE_DATA_ERROR;
    }
    List<String> serverIds = CreateSystemTask.getServerIds(services);
    String taskName = CreateSystemTask.updateTask(release, task, serverIds, TaskType.USER_DELETE);
    if (!BrStringUtils.isEmpty(taskName)) {
        return ReturnCode.SUCCESS;
    } else {
        return ReturnCode.DELETE_DATA_ERROR;
    }
}
Also used : TaskTypeModel(com.bonree.brfs.schedulers.task.model.TaskTypeModel) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 12 with MetaTaskManagerInterface

use of com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface 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 13 with MetaTaskManagerInterface

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

the class TaskStateLifeContral method updateTaskRunState.

/**
 * 概述:将服务状态修改为RUN
 * @param serverId
 * @param taskname
 * @param taskType
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static void updateTaskRunState(String serverId, String taskname, String taskType) {
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    int taskStat = release.queryTaskState(taskname, taskType);
    // 修改服务几点状态,若不为RUN则修改为RUN
    TaskServerNodeModel serverNode = release.getTaskServerContentNodeInfo(taskType, taskname, serverId);
    if (serverNode == null) {
        serverNode = new TaskServerNodeModel();
    }
    LOG.debug("TaskMessage Run  sTask :{}", JsonUtils.toJsonStringQuietly(serverNode));
    serverNode.setTaskStartTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    serverNode.setTaskState(TaskState.RUN.code());
    release.updateServerTaskContentNode(serverId, taskname, taskType, serverNode);
    LOG.debug("> run server task :{} - {} - {} - {}", taskType, taskname, serverId, TaskState.valueOf(serverNode.getTaskState()).name());
    // 查询任务节点状态,若不为RUN则获取分布式锁,修改为RUN
    if (taskStat != TaskState.RUN.code()) {
        TaskModel task = release.getTaskContentNodeInfo(taskType, taskname);
        if (task == null) {
            task = new TaskModel();
        }
        task.setTaskState(TaskState.RUN.code());
        release.updateTaskContentNode(task, taskType, taskname);
        LOG.debug("run task :{} - {} - {}", taskType, taskname, TaskState.valueOf(task.getTaskState()).name());
    }
}
Also used : TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

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