use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class DefaultReleaseTask method getTaskCreateTime.
private long getTaskCreateTime(String taskName, String taskType) {
try {
if (BrStringUtils.isEmpty(taskName)) {
return -1;
}
if (BrStringUtils.isEmpty(taskType)) {
return -2;
}
String path = this.taskQueue + "/" + taskType + "/" + taskName;
if (!client.checkExists(path)) {
return -3;
}
byte[] data;
data = client.getData(path);
if (data == null || data.length == 0) {
return -4;
}
TaskModel taskInfo = JsonUtils.toObject(data, TaskModel.class);
String createTime = taskInfo.getCreateTime();
if (BrStringUtils.isEmpty(createTime)) {
return 0;
} else {
return TimeUtils.getMiles(createTime, TimeUtils.TIME_MILES_FORMATE);
}
} catch (Exception e) {
LOG.error("get create time error {}", e);
}
return -5;
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TaskStateLifeContral method changeRunTaskModel.
public static TaskModel changeRunTaskModel(final TaskModel message, String dataPath) {
if (message == null) {
return null;
}
// 文件恢复单独不需要处理
TaskModel changeTask = new TaskModel();
changeTask.setCreateTime(message.getCreateTime());
changeTask.setTaskState(changeTask.getTaskState());
changeTask.setTaskType(message.getTaskType());
if (TaskType.SYSTEM_COPY_CHECK.code() == changeTask.getTaskType()) {
changeTask.setAtomList(message.getAtomList());
return changeTask;
}
// 删除任务,校验任务,需要扫目录确定
List<AtomTaskModel> mAtoms = message.getAtomList();
if (mAtoms == null || mAtoms.isEmpty()) {
LOG.warn("task message atom list is empty!!!");
return null;
}
// 循环atom,封装atom
AtomTaskModel rAtom;
long startTime;
long endTime;
String snName;
int partNum;
Map<String, String> map;
long granule;
for (AtomTaskModel atom : mAtoms) {
startTime = TimeUtils.getMiles(atom.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
endTime = TimeUtils.getMiles(atom.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
snName = atom.getStorageName();
partNum = atom.getPatitionNum();
granule = atom.getGranule();
map = new HashMap<>();
map.put(BRFSPath.STORAGEREGION, snName);
List<BRFSPath> dirPaths = BRFSFileUtil.scanBRFSFiles(dataPath, map, map.size(), new BRFSTimeFilter(startTime, endTime));
if (dirPaths == null || dirPaths.isEmpty()) {
LOG.debug("It's no dir to take task [{}]:[{}]-[{}]", snName, TimeUtils.timeInterval(startTime, granule), TimeUtils.timeInterval(endTime, granule));
continue;
}
List<Long> times = filterRepeatDirs(dirPaths);
for (Long time : times) {
rAtom = AtomTaskModel.getInstance(null, snName, atom.getTaskOperation(), partNum, time, time + atom.getGranule(), 0);
changeTask.addAtom(rAtom);
}
}
return changeTask;
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TaskStateLifeContral method updateTaskRunState.
/**
* 概述:将服务状态修改为RUN
* @param serverId
* @param taskname
* @param taskType
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static void updateTaskRunState(String serverId, String taskname, String taskType) {
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
MetaTaskManagerInterface release = mcf.getTm();
int taskStat = release.queryTaskState(taskname, taskType);
// 修改服务几点状态,若不为RUN则修改为RUN
TaskServerNodeModel serverNode = release.getTaskServerContentNodeInfo(taskType, taskname, serverId);
if (serverNode == null) {
serverNode = new TaskServerNodeModel();
}
LOG.debug("TaskMessage Run sTask :{}", JsonUtils.toJsonStringQuietly(serverNode));
serverNode.setTaskStartTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
serverNode.setTaskState(TaskState.RUN.code());
release.updateServerTaskContentNode(serverId, taskname, taskType, serverNode);
LOG.debug("> run server task :{} - {} - {} - {}", taskType, taskname, serverId, TaskState.valueOf(serverNode.getTaskState()).name());
// 查询任务节点状态,若不为RUN则获取分布式锁,修改为RUN
if (taskStat != TaskState.RUN.code()) {
TaskModel task = release.getTaskContentNodeInfo(taskType, taskname);
if (task == null) {
task = new TaskModel();
}
task.setTaskState(TaskState.RUN.code());
release.updateTaskContentNode(task, taskType, taskname);
LOG.debug("run task :{} - {} - {}", taskType, taskname, TaskState.valueOf(task.getTaskState()).name());
}
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TaskStateLifeContral method getCurrentOperationTask.
/**
* 概述:获取当前任务信息
* @param release
* @param typeName
* @param serverId
* @param limitCount
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static Pair<String, TaskModel> getCurrentOperationTask(MetaTaskManagerInterface release, String typeName, String serverId, int limitCount) {
List<Pair<String, Pair<Integer, Integer>>> needTasks = getServerState(release, typeName, serverId);
Pair<String, Pair<Integer, Integer>> task = getOperationTask(needTasks, limitCount);
if (task == null) {
return null;
}
if (BrStringUtils.isEmpty(task.getFirst())) {
return null;
}
TaskModel cTask = release.getTaskContentNodeInfo(typeName, task.getFirst());
if (cTask == null) {
return null;
}
// 更新异常的次数
if (task.getSecond().getFirst() == TaskState.EXCEPTION.code()) {
TaskServerNodeModel server = release.getTaskServerContentNodeInfo(typeName, task.getFirst(), serverId);
LOG.debug("TaskMessage get sTask :{}", JsonUtils.toJsonStringQuietly(server));
server.setRetryCount(server.getRetryCount() + 1);
release.updateServerTaskContentNode(serverId, task.getFirst(), typeName, server);
}
return new Pair<>(task.getFirst(), cTask);
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TaskStateLifeContral method changeRunTaskModel.
/**
* 概述:将任务分批
* @param message
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
@Deprecated
public static TaskModel changeRunTaskModel(final TaskModel message) {
if (message == null) {
return null;
}
TaskModel changeTask = new TaskModel();
changeTask.setCreateTime(message.getCreateTime());
changeTask.setTaskState(changeTask.getTaskState());
changeTask.setTaskType(message.getTaskType());
if (TaskType.SYSTEM_COPY_CHECK.code() == changeTask.getTaskType()) {
changeTask.setAtomList(message.getAtomList());
return changeTask;
}
List<AtomTaskModel> atoms = message.getAtomList();
AtomTaskModel atom;
if (atoms == null || atoms.isEmpty()) {
return changeTask;
}
long startTime;
long endTime;
String snName;
String operation;
long granule;
for (AtomTaskModel aTask : atoms) {
startTime = TimeUtils.getMiles(aTask.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
endTime = TimeUtils.getMiles(aTask.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE);
snName = aTask.getStorageName();
operation = aTask.getTaskOperation();
granule = aTask.getGranule();
for (long start = startTime; start < endTime; start += granule) {
if (start + granule > endTime) {
continue;
}
atom = AtomTaskModel.getInstance(null, snName, operation, aTask.getPatitionNum(), start, start + granule, granule);
changeTask.addAtom(atom);
}
}
return changeTask;
}
Aggregations