use of com.bonree.brfs.schedulers.task.model.AtomTaskResultModel in project BRFS by zhangnianli.
the class UserDeleteJob method deleteFiles.
/**
* 概述:封装执行结果
* @param atom
* @param dataPath
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public AtomTaskResultModel deleteFiles(AtomTaskModel atom, String dataPath) {
if (atom == null) {
return null;
}
String snName = atom.getStorageName();
long startTime = TimeUtils.getMiles(atom.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
long endTime = TimeUtils.getMiles(atom.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
AtomTaskResultModel atomR = new AtomTaskResultModel();
atomR.setDataStartTime(TimeUtils.formatTimeStamp(startTime, TimeUtils.TIME_MILES_FORMATE));
atomR.setDataStopTime(TimeUtils.formatTimeStamp(endTime, TimeUtils.TIME_MILES_FORMATE));
atomR.setPartNum(atom.getPatitionNum());
atomR.setSn(snName);
Map<String, String> snMap = new HashMap<>();
snMap.put(BRFSPath.STORAGEREGION, snName);
List<BRFSPath> deleteDirs = BRFSFileUtil.scanBRFSFiles(dataPath, snMap, snMap.size(), new BRFSTimeFilter(startTime, endTime));
LOG.debug("collection {}_{} dirs {}", atom.getDataStartTime(), atom.getDataStopTime(), deleteDirs);
if (deleteDirs == null || deleteDirs.isEmpty()) {
atomR.setOperationFileCount(0);
return atomR;
}
boolean isSuccess = true;
for (BRFSPath deletePath : deleteDirs) {
isSuccess = isSuccess && FileUtils.deleteDir(dataPath + FileUtils.FILE_SEPARATOR + deletePath.toString(), true);
LOG.debug("delete [{}], status [{}]", deletePath, isSuccess);
}
atomR.setOperationFileCount(deleteDirs.size());
atomR.setSuccess(isSuccess);
return atomR;
}
use of com.bonree.brfs.schedulers.task.model.AtomTaskResultModel in project BRFS by zhangnianli.
the class UserDeleteJob method operation.
@Override
public void operation(JobExecutionContext context) throws Exception {
JobDataMap data = context.getJobDetail().getJobDataMap();
String currentIndex = data.getString(JobDataMapConstract.CURRENT_INDEX);
String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
String content = data.getString(currentIndex);
// 获取当前执行的任务类型
if (BrStringUtils.isEmpty(content)) {
LOG.debug("batch data is empty !!!");
return;
}
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;
List<String> dSns = new ArrayList<String>();
String operation;
for (AtomTaskModel atom : atoms) {
snName = atom.getStorageName();
if ("1".equals(currentIndex)) {
operation = atom.getTaskOperation();
LOG.debug("task operation {} ", DELETE_SN_ALL.equals(operation) ? "Delete_Storage_Region" : "Delete_Part_Of_Storage_Region_Data");
if (DELETE_SN_ALL.equals(operation)) {
dSns.add(snName);
}
}
usrResult = deleteFiles(atom, dataPath);
if (usrResult == null) {
continue;
}
if (!usrResult.isSuccess()) {
result.setSuccess(false);
}
result.add(usrResult);
}
if ("1".equals(currentIndex)) {
for (String sn : dSns) {
if (FileUtils.deleteDir(dataPath + "/" + sn, true)) {
LOG.debug("deltete {} successfull", sn);
} else {
result.setSuccess(false);
}
}
}
// 更新任务状态
TaskStateLifeContral.updateMapTaskMessage(context, result);
}
Aggregations