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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations