use of com.bonree.brfs.schedulers.task.model.TaskServerNodeModel in project BRFS by zhangnianli.
the class DefaultReleaseTask method reviseTaskState.
/**
* 概述:维护任务的状态
* @param taskQueue
* @param aliveServers
* @param taskType
* @param deleteIndex
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
private int reviseTaskState(List<String> taskQueue, Collection<String> aliveServers, String taskType, int deleteIndex) {
int count = 0;
try {
int size = taskQueue.size();
StringBuilder taskPath;
String taskName;
String tmpPath;
TaskModel taskContent;
TaskServerNodeModel taskServer;
List<String> cServers;
for (int i = (size - 1); i >= deleteIndex; i--) {
taskName = taskQueue.get(i);
taskContent = getTaskContentNodeInfo(taskType, taskName);
if (taskContent == null) {
LOG.warn("{} {} is null", taskType, taskName);
continue;
}
// 不为RUN与Exception的任务不进行检查
int stat = taskContent.getTaskState();
boolean exceptionFlag = TaskState.EXCEPTION.code() == stat;
if (!(TaskState.RUN.code() == stat || exceptionFlag)) {
continue;
}
// 获取任务下的子节点
taskPath = new StringBuilder();
taskPath.append(this.taskQueue).append("/").append(taskType).append("/").append(taskName);
tmpPath = taskPath.toString();
cServers = client.getChildren(tmpPath);
// 服务为空,任务标记为异常
if (cServers == null || cServers.isEmpty()) {
count++;
taskContent.setTaskState(TaskState.EXCEPTION.code());
updateTaskContentNode(taskContent, taskType, taskName);
continue;
}
boolean isException = false;
for (String cServer : cServers) {
// 存活的server不进行操作
if (aliveServers.contains(cServer)) {
continue;
}
// 不存活的server,节点标记为Exception
taskServer = getTaskServerContentNodeInfo(taskType, taskName, cServer);
if (taskServer == null) {
LOG.warn("taskType :{}, taskName :{}, serverId :{} is not exists", taskType, taskName, cServer);
taskServer = new TaskServerNodeModel();
taskServer.setTaskState(TaskState.UNKNOW.code());
}
if (TaskState.FINISH.code() == taskServer.getTaskState()) {
continue;
}
isException = true;
taskServer.setTaskState(TaskState.EXCEPTION.code());
updateServerTaskContentNode(cServer, taskName, taskType, taskServer);
}
if (isException && !exceptionFlag) {
count++;
taskContent.setTaskState(TaskState.EXCEPTION.code());
updateTaskContentNode(taskContent, taskType, taskName);
}
}
} catch (Exception e) {
LOG.error("revise task error {}", e);
}
return count;
}
use of com.bonree.brfs.schedulers.task.model.TaskServerNodeModel in project BRFS by zhangnianli.
the class InitTaskManager method recoveryTask.
/**
* 概述:将因服务挂掉而错失的任务重建
* @param release
* @param taskType
* @param currentTask
* @param serverId
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
private static void recoveryTask(MetaTaskManagerInterface release, String taskType, String currentTask, String serverId) {
List<String> tasks = release.getTaskList(taskType);
if (tasks == null || tasks.isEmpty()) {
return;
}
int index = tasks.indexOf(currentTask);
if (index < 0) {
index = 0;
}
int size = tasks.size();
String taskName;
List<String> cList;
TaskServerNodeModel serverNode = TaskServerNodeModel.getInitInstance();
TaskServerNodeModel change;
for (int i = index; i < size; i++) {
taskName = tasks.get(i);
if (BrStringUtils.isEmpty(taskName)) {
continue;
}
cList = release.getTaskServerList(taskType, taskName);
if (cList == null || cList.isEmpty() || !cList.contains(serverId)) {
release.updateServerTaskContentNode(serverId, taskName, taskType, serverNode);
int stat = release.queryTaskState(taskName, taskType);
if (TaskState.FINISH.code() == stat) {
release.changeTaskContentNodeState(taskName, taskType, TaskState.RERUN.code());
}
LOG.info("Recover {} task's {} serverId {} ", taskType, taskName, serverId);
continue;
}
change = release.getTaskServerContentNodeInfo(taskType, taskName, serverId);
if (change == null) {
change = TaskServerNodeModel.getInitInstance();
}
if (change.getTaskState() == TaskState.RUN.code() || change.getTaskState() == TaskState.RERUN.code()) {
change.setTaskState(TaskState.INIT.code());
release.updateServerTaskContentNode(serverId, taskName, taskType, change);
}
}
}
use of com.bonree.brfs.schedulers.task.model.TaskServerNodeModel in project BRFS by zhangnianli.
the class DefaultReleaseTask method getServerStatus.
@Override
public List<Pair<String, Integer>> getServerStatus(String taskType, String taskName) {
List<Pair<String, Integer>> serverStatus = new ArrayList<>();
List<String> childeServers = getTaskServerList(taskType, taskName);
if (childeServers == null || childeServers.isEmpty()) {
return serverStatus;
}
Pair<String, Integer> stat;
int iStat;
TaskServerNodeModel tmpServer;
for (String child : childeServers) {
stat = new Pair<>();
tmpServer = getTaskServerContentNodeInfo(taskType, taskName, child);
stat.setFirst(child);
iStat = tmpServer == null ? -3 : tmpServer.getTaskState();
stat.setSecond(iStat);
serverStatus.add(stat);
}
return serverStatus;
}
use of com.bonree.brfs.schedulers.task.model.TaskServerNodeModel 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.TaskServerNodeModel 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());
}
}
Aggregations