use of com.bonree.brfs.schedulers.task.model.AtomTaskModel in project BRFS by zhangnianli.
the class TasksUtils method createUserDelete.
/**
* 概述:创建可执行任务信息
* @param sn storageName信息
* @param taskType 任务类型
* @param opertationContent 执行的内容,暂时无用
* @param startTime 要操作数据的开始时间 -1标识为sn的创建时间
* @param endTime 要操作数据的结束时间。
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static TaskModel createUserDelete(final StorageRegion sn, final TaskType taskType, final String opertationContent, final long startTime, final long endTime) {
if (sn == null || taskType == null) {
return null;
}
TaskModel task = new TaskModel();
List<AtomTaskModel> storageAtoms = new ArrayList<>();
if (endTime == 0 || startTime >= endTime) {
return null;
}
long granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
String snName = sn.getName();
long startHour;
long endHour = endTime - endTime % granule;
// 删除sn
boolean isALL = UserDeleteJob.DELETE_SN_ALL.equals(opertationContent);
if (isALL) {
startHour = sn.getCreateTime() - sn.getCreateTime() % granule;
} else {
startHour = startTime - startTime % granule;
}
// 若是删除sn时,创建时间与删除时间间隔较短时,结束时间向后退
if (startHour == endHour) {
endHour = endHour + granule;
}
if (startHour >= endHour) {
return null;
}
AtomTaskModel atom = AtomTaskModel.getInstance(null, snName, opertationContent, sn.getReplicateNum(), startHour, endHour, granule);
storageAtoms.add(atom);
task.setAtomList(storageAtoms);
task.setTaskState(TaskState.INIT.code());
task.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
task.setTaskType(taskType.code());
return task;
}
use of com.bonree.brfs.schedulers.task.model.AtomTaskModel 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.AtomTaskModel in project BRFS by zhangnianli.
the class BatchTaskFactory method createBatch.
/**
* 概述:
* @param task
* @param batchSize
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static Map<String, String> createBatch(TaskModel task, int batchSize) {
Map<String, String> batchDatas = new HashMap<String, String>();
if (task == null) {
return batchDatas;
}
List<AtomTaskModel> atoms = convernTaskModel(task);
if (atoms == null || atoms.isEmpty()) {
return batchDatas;
}
int size = atoms.size();
int batchCount = size % batchSize == 0 ? size / batchSize : size / batchSize + 1;
BatchAtomModel batch = null;
List<AtomTaskModel> tmp = null;
// 若不足一次则按一次来
if (batchCount == 0) {
batch = new BatchAtomModel();
batch.addAll(atoms);
batchDatas.put(JobDataMapConstract.CURRENT_INDEX, "1");
batchDatas.put("1", JsonUtils.toJsonStringQuietly(batch));
return batchDatas;
}
batchDatas.put(JobDataMapConstract.CURRENT_INDEX, batchCount + "");
int index = 0;
for (int i = 1; i <= batchCount; i++) {
batch = new BatchAtomModel();
if (index >= size) {
tmp = new ArrayList<>();
} else if (index + batchSize > size) {
tmp = atoms.subList(index, size);
} else if (index + batchSize <= size) {
tmp = atoms.subList(index, index + batchSize);
}
batch.addAll(tmp);
batchDatas.put(i + "", JsonUtils.toJsonStringQuietly(batch));
index = index + batchSize;
}
return batchDatas;
}
use of com.bonree.brfs.schedulers.task.model.AtomTaskModel 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);
}
use of com.bonree.brfs.schedulers.task.model.AtomTaskModel 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