Search in sources :

Example 11 with ManagerContralFactory

use of com.bonree.brfs.schedulers.ManagerContralFactory 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 12 with ManagerContralFactory

use of com.bonree.brfs.schedulers.ManagerContralFactory in project BRFS by zhangnianli.

the class WatchDogJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.debug("watch dog do it >>>>>>>>>>>>>>");
    JobDataMap data = context.getJobDetail().getJobDataMap();
    String zkHosts = data.getString(JobDataMapConstract.ZOOKEEPER_ADDRESS);
    String baseRoutPath = data.getString(JobDataMapConstract.BASE_ROUTE_PATH);
    String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
    if (BrStringUtils.isEmpty(dataPath) || BrStringUtils.isEmpty(baseRoutPath) || BrStringUtils.isEmpty(zkHosts)) {
        LOG.warn("config is empty !! skip watchdog");
        return;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    ServerIDManager sim = mcf.getSim();
    StorageRegionManager snm = mcf.getSnm();
    List<StorageRegion> sns = snm.getStorageRegionList();
    long preTime = System.currentTimeMillis();
    LOG.info("Scan {} below data !!!", TimeUtils.formatTimeStamp(preTime));
    WatchDog.searchPreys(sim, sns, zkHosts, baseRoutPath, dataPath, preTime);
}
Also used : JobDataMap(org.quartz.JobDataMap) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 13 with ManagerContralFactory

use of com.bonree.brfs.schedulers.ManagerContralFactory in project BRFS by zhangnianli.

the class GatherResourceJob method getStorageNameIdWithName.

/**
 * 概述:获取storageName关系
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
private Map<Integer, String> getStorageNameIdWithName() {
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    StorageRegionManager snm = mcf.getSnm();
    List<StorageRegion> sns = snm.getStorageRegionList();
    Map<Integer, String> snToId = new ConcurrentHashMap<>();
    if (sns == null || sns.isEmpty()) {
        return snToId;
    }
    int id;
    String name;
    for (StorageRegion sn : sns) {
        if (sn == null) {
            continue;
        }
        name = sn.getName();
        if (BrStringUtils.isEmpty(name)) {
            continue;
        }
        id = sn.getId();
        if (snToId.containsKey(id)) {
            continue;
        }
        snToId.put(id, name);
    }
    return snToId;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 14 with ManagerContralFactory

use of com.bonree.brfs.schedulers.ManagerContralFactory in project BRFS by zhangnianli.

the class TasksUtils method createCopyTask.

/**
 * 概述:根据CRC校验任务,创建副本数校验任务
 * @param taskName
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static String createCopyTask(String taskName) {
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    List<String> sNames = release.getTaskServerList(TaskType.SYSTEM_CHECK.name(), taskName);
    if (sNames == null || sNames.isEmpty()) {
        LOG.error("CRC task [{}] get serviceList is empty!!!", taskName);
        return null;
    }
    TaskModel task = converyCopyTaskModel(release, taskName);
    return createTask(release, sNames, TaskType.SYSTEM_CHECK.name(), task);
}
Also used : 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)

Example 15 with ManagerContralFactory

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

Aggregations

ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)18 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)9 JobDataMap (org.quartz.JobDataMap)9 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)8 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)7 EmailPool (com.bonree.brfs.email.EmailPool)7 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)6 ServiceManager (com.bonree.brfs.common.service.ServiceManager)5 TaskType (com.bonree.brfs.common.task.TaskType)4 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)4 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)4 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)4 TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)3 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)3 Map (java.util.Map)3 Service (com.bonree.brfs.common.service.Service)2 TaskState (com.bonree.brfs.common.task.TaskState)2 SecondIDParser (com.bonree.brfs.rebalance.route.SecondIDParser)2 RunnableTaskInterface (com.bonree.brfs.schedulers.task.manager.RunnableTaskInterface)2 TaskServerNodeModel (com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)2