Search in sources :

Example 1 with TaskTypeModel

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

the class TaskStateLifeContral method watchSR.

/**
 * 概述:去掉已删除的sn
 * @param release
 * @param srs
 * @param taskType
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static void watchSR(MetaTaskManagerInterface release, List<String> srs, String taskType) {
    TaskTypeModel typeModel = release.getTaskTypeInfo(taskType);
    if (typeModel == null) {
        LOG.warn("tasktype : {} meta data loss !!!", taskType);
        return;
    }
    Map<String, Long> snMap = typeModel.getSnTimes();
    if (snMap == null || snMap.isEmpty()) {
        return;
    }
    List<String> deleteSRs = new ArrayList<>();
    for (String srName : snMap.keySet()) {
        if (srs.contains(srName)) {
            continue;
        }
        deleteSRs.add(srName);
    }
    if (deleteSRs.isEmpty()) {
        return;
    }
    for (String str : deleteSRs) {
        typeModel.removesnTime(str);
    }
    release.setTaskTypeModel(taskType, typeModel);
}
Also used : TaskTypeModel(com.bonree.brfs.schedulers.task.model.TaskTypeModel)

Example 2 with TaskTypeModel

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

use of com.bonree.brfs.schedulers.task.model.TaskTypeModel 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 4 with TaskTypeModel

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

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

Aggregations

TaskTypeModel (com.bonree.brfs.schedulers.task.model.TaskTypeModel)5 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)4 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)3 ServiceManager (com.bonree.brfs.common.service.ServiceManager)2 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)2 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)2 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)2 Map (java.util.Map)2 Service (com.bonree.brfs.common.service.Service)1 TaskType (com.bonree.brfs.common.task.TaskType)1 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)1 List (java.util.List)1 JobDataMap (org.quartz.JobDataMap)1