use of com.bonree.brfs.schedulers.task.model.TaskResultModel in project BRFS by zhangnianli.
the class TaskStateLifeContral method updateMapTaskMessage.
/**
* 概述:更新任务map的任务状态
* @param context
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static void updateMapTaskMessage(JobExecutionContext context, TaskResultModel result) {
JobDataMap data = context.getJobDetail().getJobDataMap();
if (data == null) {
return;
}
// 结果为空不更新批次任务结果
if (result == null) {
return;
}
boolean isSuccess = result.isSuccess();
TaskResultModel sumResult;
String content = null;
if (data.containsKey(JobDataMapConstract.TASK_RESULT)) {
content = data.getString(JobDataMapConstract.TASK_RESULT);
}
if (!BrStringUtils.isEmpty(content)) {
sumResult = JsonUtils.toObjectQuietly(content, TaskResultModel.class);
} else {
sumResult = new TaskResultModel();
}
sumResult.addAll(result.getAtoms());
sumResult.setSuccess(isSuccess && sumResult.isSuccess());
String sumContent = JsonUtils.toJsonStringQuietly(sumResult);
data.put(JobDataMapConstract.TASK_RESULT, sumContent);
}
use of com.bonree.brfs.schedulers.task.model.TaskResultModel in project BRFS by zhangnianli.
the class CycleJobWithZKTask method createBatchData.
public void createBatchData(MetaTaskManagerInterface release, JobDataMap data, String serverId, TaskType taskType, int batchSize, int limitCount) {
// 从zk获取任务信息最后一次执行成功的 若任务为空则返回
Pair<String, TaskModel> taskPair = TaskStateLifeContral.getCurrentOperationTask(release, taskType.name(), serverId, limitCount);
if (taskPair == null) {
LOG.info("{} task queue is empty !!!", taskType.name());
return;
}
// 将当前的任务分成批次执行
TaskModel task = TaskStateLifeContral.changeRunTaskModel(taskPair.getSecond());
String currentTaskName = taskPair.getFirst();
if (BrStringUtils.isEmpty(currentTaskName)) {
LOG.info("{} {} task behind is empty !!!", taskType.name());
return;
}
Map<String, String> batchDatas = BatchTaskFactory.createBatch(task, batchSize);
// 若批次为空则更新任务状态
if (batchDatas == null || batchDatas.isEmpty()) {
LOG.info("batch data is empty !! update task :{} {}", taskType.name(), currentTaskName);
TaskStateLifeContral.updateTaskStatusByCompelete(serverId, currentTaskName, taskType.name(), new TaskResultModel());
data.put(JobDataMapConstract.CURRENT_TASK_NAME, "");
data.put(JobDataMapConstract.CURRENT_INDEX, 0 + "");
return;
}
data.putAll(batchDatas);
data.put(JobDataMapConstract.CURRENT_TASK_NAME, currentTaskName);
// 更新zk任务状态
TaskStateLifeContral.updateTaskRunState(serverId, currentTaskName, taskType.name());
}
use of com.bonree.brfs.schedulers.task.model.TaskResultModel 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.TaskResultModel 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.TaskResultModel in project BRFS by zhangnianli.
the class SystemCheckJob method operation.
@Override
public void operation(JobExecutionContext context) throws Exception {
LOG.debug("check task 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);
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 = null;
TaskResultModel result = new TaskResultModel();
TaskResultModel batchResult = null;
for (AtomTaskModel atom : atoms) {
snName = atom.getStorageName();
if (BrStringUtils.isEmpty(snName)) {
LOG.warn("sn is empty !!!");
continue;
}
batchResult = checkFiles(atom, dataPath);
if (batchResult == null) {
continue;
}
if (!batchResult.isSuccess()) {
result.setSuccess(batchResult.isSuccess());
}
result.addAll(batchResult.getAtoms());
}
// 更新任务状态
TaskStateLifeContral.updateMapTaskMessage(context, result);
}
Aggregations