Search in sources :

Example 1 with TaskServerNodeModel

use of com.bonree.brfs.schedulers.task.model.TaskServerNodeModel in project BRFS by zhangnianli.

the class TaskStateLifeContral method getServerState.

/**
 * 概述:获取指定任务的队列
 * @param release
 * @param typeName
 * @param serverId
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static List<Pair<String, Pair<Integer, Integer>>> getServerState(MetaTaskManagerInterface release, String typeName, String serverId) {
    List<String> taskNames = release.getTaskList(typeName);
    List<Pair<String, Pair<Integer, Integer>>> sTaskStatuss = new ArrayList<>();
    if (taskNames == null || taskNames.isEmpty()) {
        return sTaskStatuss;
    }
    Pair<String, Pair<Integer, Integer>> sTaskStatus;
    Pair<Integer, Integer> codeAndCount;
    TaskServerNodeModel server;
    for (String taskName : taskNames) {
        server = release.getTaskServerContentNodeInfo(typeName, taskName, serverId);
        if (server == null) {
            continue;
        }
        if (server.getTaskState() == TaskState.FINISH.code()) {
            continue;
        }
        codeAndCount = new Pair<>(server.getTaskState(), server.getRetryCount());
        sTaskStatus = new Pair<>(taskName, codeAndCount);
        sTaskStatuss.add(sTaskStatus);
    }
    return sTaskStatuss;
}
Also used : TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)

Example 2 with TaskServerNodeModel

use of com.bonree.brfs.schedulers.task.model.TaskServerNodeModel in project BRFS by zhangnianli.

the class TaskStateLifeContral method updateTaskStatusByCompelete.

/**
 * 概述:更新任务状态
 * @param serverId
 * @param taskname
 * @param taskType
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static void updateTaskStatusByCompelete(String serverId, String taskname, String taskType, TaskResultModel taskResult) {
    if (BrStringUtils.isEmpty(taskname)) {
        LOG.warn("task name is empty !!! {} {} {}", taskType, taskname, serverId);
        return;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    MetaTaskManagerInterface release = mcf.getTm();
    TaskServerNodeModel sTask = release.getTaskServerContentNodeInfo(taskType, taskname, serverId);
    if (sTask == null) {
        LOG.debug("server task is null !!! {} {} {}", taskType, taskname, serverId);
        sTask = new TaskServerNodeModel();
    }
    LOG.debug("TaskMessage complete  sTask :{}", JsonUtils.toJsonStringQuietly(sTask));
    sTask.setResult(taskResult);
    if (BrStringUtils.isEmpty(sTask.getTaskStartTime())) {
        sTask.setTaskStartTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    }
    sTask.setTaskStopTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    TaskState status = taskResult == null ? TaskState.EXCEPTION : taskResult.isSuccess() ? TaskState.FINISH : TaskState.EXCEPTION;
    sTask.setTaskState(status.code());
    release.updateServerTaskContentNode(serverId, taskname, taskType, sTask);
    LOG.info("Complete server task :{} - {} - {} - {}", taskType, taskname, serverId, TaskState.valueOf(sTask.getTaskState()).name());
    // 更新TaskContent
    List<Pair<String, Integer>> cStatus = release.getServerStatus(taskType, taskname);
    if (cStatus == null || cStatus.isEmpty()) {
        return;
    }
    LOG.debug("complete c List {}", cStatus);
    int cstat;
    boolean isException = false;
    int finishCount = 0;
    int size = cStatus.size();
    for (Pair<String, Integer> pair : cStatus) {
        cstat = pair.getSecond();
        if (TaskState.EXCEPTION.code() == cstat) {
            isException = true;
            finishCount += 1;
        } else if (TaskState.FINISH.code() == cstat) {
            finishCount += 1;
        }
    }
    if (finishCount != size) {
        return;
    }
    TaskModel task = release.getTaskContentNodeInfo(taskType, taskname);
    if (task == null) {
        LOG.debug("task is null !!! {} {} {}", taskType, taskname);
        task = new TaskModel();
        task.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
    }
    if (isException) {
        task.setTaskState(TaskState.EXCEPTION.code());
    } else {
        task.setTaskState(TaskState.FINISH.code());
    }
    release.updateTaskContentNode(task, taskType, taskname);
    LOG.info("complete task :{} - {} - {}", taskType, taskname, TaskState.valueOf(task.getTaskState()).name());
    if (TaskType.SYSTEM_CHECK.name().equals(taskType) && isException) {
        TaskModel cTask = TasksUtils.converyCopyTaskModel(release, taskname);
        if (cTask == null) {
            LOG.error("[{}]:[{}] task can't recovery !!!", taskType, taskname);
            return;
        }
        String str = TasksUtils.createCopyTask(release, taskname, cTask);
        if (BrStringUtils.isEmpty(str)) {
            boolean flag = release.setTransferTask(taskType, taskname);
            LOG.info("[{}] task [{}] find error ,transfer task create {}  ", taskType, taskname, flag ? "succefull !!!" : " fail !!!");
        } else {
            LOG.info("[{}]:[{}] find error create copy task [{}] to recovery ", taskType, taskname, str);
        }
    }
}
Also used : TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) TaskState(com.bonree.brfs.common.task.TaskState) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 3 with TaskServerNodeModel

use of com.bonree.brfs.schedulers.task.model.TaskServerNodeModel in project BRFS by zhangnianli.

the class TasksUtils method getServicesInfo.

/**
 *	/**
 * 概述:
 * @param release
 * @param taskType
 * @param name
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static List<TaskServerNodeModel> getServicesInfo(MetaTaskManagerInterface release, TaskType taskType, String name) {
    List<String> sNames = release.getTaskServerList(taskType.name(), name);
    if (sNames == null || sNames.isEmpty()) {
        LOG.error("CRC task [{}] get serviceList is empty!!!", name);
        return null;
    }
    List<TaskServerNodeModel> sTasks = new ArrayList<>();
    TaskServerNodeModel sTask;
    for (String sName : sNames) {
        sTask = release.getTaskServerContentNodeInfo(taskType.name(), name, sName);
        if (sTask == null) {
            continue;
        }
        sTasks.add(sTask);
    }
    return sTasks;
}
Also used : TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel) ArrayList(java.util.ArrayList)

Example 4 with TaskServerNodeModel

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);
        }
    }
}
Also used : TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)

Example 5 with TaskServerNodeModel

use of com.bonree.brfs.schedulers.task.model.TaskServerNodeModel in project BRFS by zhangnianli.

the class DefaultReleaseTask method getLastSuccessTaskIndex.

@Override
public String getLastSuccessTaskIndex(String taskType, String serverId) {
    try {
        List<String> taskInfos = getTaskList(taskType);
        if (taskInfos == null || taskInfos.isEmpty()) {
            return null;
        }
        int maxIndex = taskInfos.size() - 1;
        StringBuilder path;
        String taskName;
        String taskPath;
        TaskServerNodeModel tmpR;
        for (int i = maxIndex; i >= 0; i--) {
            taskName = taskInfos.get(i);
            path = new StringBuilder();
            path.append(this.taskQueue).append("/").append(taskType).append("/").append(taskName).append("/").append(serverId);
            taskPath = path.toString();
            if (!client.checkExists(taskPath)) {
                continue;
            }
            tmpR = getTaskServerContentNodeInfo(taskType, taskName, serverId);
            if (tmpR == null) {
                continue;
            }
            if (tmpR.getTaskState() != TaskState.FINISH.code()) {
                continue;
            }
            return taskInfos.get(i);
        }
    } catch (Exception e) {
        LOG.error("{}", e);
    }
    return null;
}
Also used : TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)

Aggregations

TaskServerNodeModel (com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)12 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)5 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)4 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)2 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)2 ArrayList (java.util.ArrayList)2 TaskState (com.bonree.brfs.common.task.TaskState)1 Pair (com.bonree.brfs.common.utils.Pair)1 AtomTaskResultModel (com.bonree.brfs.schedulers.task.model.AtomTaskResultModel)1 TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1