Search in sources :

Example 1 with AtomTaskResultModel

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

the class SystemCheckJob method checkFiles.

/**
 * @param atom
 * @param dataPath
 * @return
 */
public TaskResultModel checkFiles(AtomTaskModel atom, String dataPath) {
    String snName = atom.getStorageName();
    int partitionNum = atom.getPatitionNum();
    long startTime = TimeUtils.getMiles(atom.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
    long endTime = TimeUtils.getMiles(atom.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
    Map<String, String> snMap = new HashMap<>();
    snMap.put(BRFSPath.STORAGEREGION, snName);
    List<BRFSPath> eFiles = BRFSFileUtil.scanBRFSFiles(dataPath, snMap, snMap.size(), new BRFSCheckFilter(startTime, endTime));
    List<String> errors = new ArrayList<>();
    if (eFiles != null) {
        for (BRFSPath brfsPath : eFiles) {
            errors.add(brfsPath.getFileName());
        }
    }
    TaskResultModel result = new TaskResultModel();
    AtomTaskResultModel atomR = AtomTaskResultModel.getInstance(errors, snName, startTime, endTime, "", partitionNum);
    if (errors != null && !errors.isEmpty()) {
        atomR.setSuccess(false);
        result.setSuccess(false);
    }
    result.add(atomR);
    LOG.debug("result : {}", JsonUtils.toJsonStringQuietly(result));
    return result;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel)

Example 2 with AtomTaskResultModel

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

the class SystemDeleteJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.debug("----------> system delete work");
    JobDataMap data = context.getJobDetail().getJobDataMap();
    String currentIndex = data.getString(JobDataMapConstract.CURRENT_INDEX);
    String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
    String content = data.getString(currentIndex);
    LOG.debug("batch {}", content);
    // 获取当前执行的任务类型
    BatchAtomModel batch = JsonUtils.toObject(content, BatchAtomModel.class);
    if (batch == null) {
        LOG.debug("batch data is empty !!!");
        return;
    }
    List<AtomTaskModel> atoms = batch.getAtoms();
    if (atoms == null || atoms.isEmpty()) {
        LOG.debug("atom task is empty !!!");
        return;
    }
    String snName;
    TaskResultModel result = new TaskResultModel();
    AtomTaskResultModel usrResult;
    for (AtomTaskModel atom : atoms) {
        snName = atom.getStorageName();
        if (BrStringUtils.isEmpty(snName)) {
            LOG.debug("sn is empty !!!");
            continue;
        }
        usrResult = deleteDirs(atom, dataPath);
        if (usrResult == null) {
            continue;
        }
        if (!usrResult.isSuccess()) {
            result.setSuccess(false);
        }
        result.add(usrResult);
    }
    // 更新任务状态
    TaskStateLifeContral.updateMapTaskMessage(context, result);
}
Also used : JobDataMap(org.quartz.JobDataMap) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 3 with AtomTaskResultModel

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

the class TasksUtils method getErrorFile.

/**
 * 概述:生成任务信息
 * @param taskContents
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static TaskModel getErrorFile(List<TaskServerNodeModel> taskContents) {
    if (taskContents == null || taskContents.isEmpty()) {
        return null;
    }
    TaskResultModel tmpR;
    List<AtomTaskResultModel> tmpRs;
    Map<String, Map<String, AtomTaskModel>> rmap = new HashMap<>();
    Map<String, AtomTaskModel> emap;
    String snName;
    String key;
    AtomTaskModel atom;
    Map<String, Integer> snMap = new HashMap<>();
    for (TaskServerNodeModel serverModel : taskContents) {
        tmpR = serverModel.getResult();
        if (tmpR == null) {
            continue;
        }
        tmpRs = tmpR.getAtoms();
        if (tmpRs == null || tmpRs.isEmpty()) {
            continue;
        }
        for (AtomTaskResultModel r : tmpRs) {
            if (r == null) {
                continue;
            }
            snName = r.getSn();
            if (!rmap.containsKey(snName)) {
                rmap.put(snName, new HashMap<>());
            }
            if (!snMap.containsKey(snName)) {
                snMap.put(snName, r.getPartNum());
            }
            emap = rmap.get(snName);
            key = r.getDataStartTime() + "_" + r.getDataStopTime();
            long granule = TimeUtils.getMiles(r.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE) - TimeUtils.getMiles(r.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
            if (!emap.containsKey(key)) {
                atom = AtomTaskModel.getInstance(null, snName, CopyCheckJob.RECOVERY_CRC, r.getPartNum(), r.getDataStartTime(), r.getDataStopTime(), granule);
                emap.put(key, atom);
            }
            atom = emap.get(key);
            atom.addAllFiles(r.getFiles());
        }
    }
    List<AtomTaskModel> tList = filterError(rmap, snMap);
    if (tList == null || tList.isEmpty()) {
        return null;
    }
    TaskModel tTask = new TaskModel();
    tTask.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    tTask.setAtomList(tList);
    tTask.setTaskState(TaskState.INIT.code());
    tTask.setTaskType(TaskType.SYSTEM_COPY_CHECK.code());
    return tTask;
}
Also used : HashMap(java.util.HashMap) TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) HashMap(java.util.HashMap) Map(java.util.Map) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 4 with AtomTaskResultModel

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

the class CopyRecovery method recoveryDirs.

/**
 * 概述:修复目录
 * @param content
 * @param zkHosts
 * @param baseRoutesPath
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static TaskResultModel recoveryDirs(String content, String zkHosts, String baseRoutesPath, String dataPath) {
    TaskResultModel result = new TaskResultModel();
    BatchAtomModel batch = converStringToBatch(content);
    if (batch == null) {
        result.setSuccess(false);
        LOG.debug("batch is empty");
        return result;
    }
    List<AtomTaskModel> atoms = batch.getAtoms();
    if (atoms == null || atoms.isEmpty()) {
        result.setSuccess(true);
        LOG.debug(" files is empty");
        return result;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    ServerIDManager sim = mcf.getSim();
    ServiceManager sm = mcf.getSm();
    StorageRegionManager snm = mcf.getSnm();
    CuratorClient curatorClient = mcf.getClient();
    StorageRegion sn;
    SecondIDParser parser;
    String snName;
    int snId;
    AtomTaskResultModel atomR;
    List<String> errors;
    for (AtomTaskModel atom : atoms) {
        atomR = new AtomTaskResultModel();
        atomR.setFiles(atom.getFiles());
        atomR.setSn(atom.getStorageName());
        snName = atom.getStorageName();
        sn = snm.findStorageRegionByName(snName);
        if (sn == null) {
            atomR.setSuccess(false);
            result.setSuccess(false);
            result.add(atomR);
            LOG.debug("sn == null snName :{}", snName);
            continue;
        }
        snId = sn.getId();
        parser = new SecondIDParser(curatorClient, snId, baseRoutesPath);
        parser.updateRoute();
        errors = recoveryFiles(sm, sim, parser, sn, atom, dataPath);
        if (errors == null || errors.isEmpty()) {
            result.add(atomR);
            LOG.debug("result is empty snName:{}", snName);
            continue;
        }
        atomR.addAll(errors);
        atomR.setSuccess(false);
        result.setSuccess(false);
    }
    return result;
}
Also used : SecondIDParser(com.bonree.brfs.rebalance.route.SecondIDParser) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) ServiceManager(com.bonree.brfs.common.service.ServiceManager) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 5 with AtomTaskResultModel

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

the class SystemDeleteJob method deleteDirs.

/**
 * 概述:封装结果
 * @param atom
 * @param dataPath
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public AtomTaskResultModel deleteDirs(AtomTaskModel atom, String dataPath) {
    String snName = atom.getStorageName();
    int patitionNum = atom.getPatitionNum();
    long granule = atom.getGranule();
    long startTime = TimeUtils.getMiles(atom.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
    long endTime = TimeUtils.getMiles(atom.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
    AtomTaskResultModel atomR = AtomTaskResultModel.getInstance(null, snName, startTime, endTime, "", patitionNum);
    Map<String, String> snMap = new HashMap<>();
    snMap.put(BRFSPath.STORAGEREGION, snName);
    List<BRFSPath> deleteDirs = BRFSFileUtil.scanBRFSFiles(dataPath, snMap, snMap.size(), new BRFSTimeFilter(0, endTime));
    if (deleteDirs == null || deleteDirs.isEmpty()) {
        LOG.debug("delete dir {} - {} is empty ", TimeUtils.timeInterval(startTime, granule), TimeUtils.timeInterval(endTime, granule));
        return atomR;
    }
    atomR.setOperationFileCount(deleteDirs.size());
    boolean isSuccess = true;
    for (BRFSPath deleteDir : deleteDirs) {
        isSuccess = isSuccess && FileUtils.deleteDir(dataPath + FileUtils.FILE_SEPARATOR + deleteDir.toString(), true);
        LOG.debug("delete :{} status :{} ", deleteDir, isSuccess);
    }
    atomR.setSuccess(isSuccess);
    return atomR;
}
Also used : HashMap(java.util.HashMap) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) BRFSTimeFilter(com.bonree.brfs.common.files.impl.BRFSTimeFilter)

Aggregations

AtomTaskResultModel (com.bonree.brfs.schedulers.task.model.AtomTaskResultModel)7 TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)5 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)4 HashMap (java.util.HashMap)4 BatchAtomModel (com.bonree.brfs.schedulers.task.model.BatchAtomModel)3 BRFSTimeFilter (com.bonree.brfs.common.files.impl.BRFSTimeFilter)2 ArrayList (java.util.ArrayList)2 JobDataMap (org.quartz.JobDataMap)2 ServiceManager (com.bonree.brfs.common.service.ServiceManager)1 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)1 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)1 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)1 SecondIDParser (com.bonree.brfs.rebalance.route.SecondIDParser)1 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)1 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)1 TaskServerNodeModel (com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)1 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)1 Map (java.util.Map)1