Search in sources :

Example 6 with TaskStatus

use of cz.metacentrum.perun.taskslib.model.Task.TaskStatus in project perun by CESNET.

the class PropagationMaintainerImpl method onTaskComplete.

@Override
public void onTaskComplete(int taskId, int clientID, String status_s, String endTimestamp, String string) {
    Task completedTask = schedulingPool.getTaskById(taskId);
    if (completedTask == null) {
        // eh? how would that be possible?
        log.error("TASK id {} reported as complete, but we do not know it... (yet?)", taskId);
        return;
    }
    TaskStatus status = TaskStatus.NONE;
    if (status_s.equals("ERROR")) {
        status = TaskStatus.ERROR;
    } else if (status_s.equals("DONE")) {
        status = TaskStatus.DONE;
    } else {
        log.error("Engine reported unexpected status {} for task id {}, setting to ERROR", status_s, taskId);
        status = TaskStatus.ERROR;
    }
    try {
        Date endTime = new Date(Long.parseLong(endTimestamp));
        completedTask.setEndTime(endTime);
    } catch (NumberFormatException e) {
        log.error("Engine reported unparsable end time {} for task id {}, setting to current time", endTimestamp, taskId);
        completedTask.setEndTime(new Date(System.currentTimeMillis()));
    }
    // date data
    if (completedTask.getExecService().getExecServiceType().equals(ExecServiceType.SEND)) {
        try {
            schedulingPool.setQueueForTask(completedTask, null);
        } catch (InternalErrorException e) {
            log.error("Could not set destination queue for task {}: {}", completedTask.getId(), e.getMessage());
        }
        this.setAllGenerateDependenciesToNone(completedTask);
    }
    if (status.equals(TaskStatus.DONE)) {
        // task completed successfully
        // set destination list to null to refetch them later
        completedTask.setDestinations(null);
        schedulingPool.setTaskStatus(completedTask, TaskStatus.DONE);
        completedTask.setRecurrence(0);
        log.debug("TASK {} reported as DONE", completedTask.toString());
        // for GEN tasks, signal SENDs that source data are updated
        if (completedTask.getExecService().getExecServiceType().equals(ExecServiceType.GENERATE)) {
            List<ExecService> dependantServices = dependenciesResolver.listDependantServices(completedTask.getExecService());
            for (ExecService dependantService : dependantServices) {
                Task dependantTask = schedulingPool.getTask(dependantService, completedTask.getFacility());
                if (dependantTask != null && dependantService.getExecServiceType().equals(ExecServiceType.SEND)) {
                    dependantTask.setSourceUpdated(false);
                }
                if (completedTask.isPropagationForced() && dependantTask.isPropagationForced()) {
                    log.debug("Going to force schedule dependant task " + dependantTask.getId());
                    taskScheduler.scheduleTask(dependantTask);
                }
            }
        }
        completedTask.setPropagationForced(false);
    } else {
        if (string.isEmpty()) {
            // weird - task is in error and no destinations reported as
            // failed...
            log.warn("TASK {} ended in ERROR state with no remaining destinations.", completedTask.toString());
        } else {
            // task failed, some destinations remain
            // resolve list of destinations
            List<PerunBean> listOfBeans;
            List<Destination> destinationList = new ArrayList<Destination>();
            try {
                listOfBeans = AuditParser.parseLog(string);
                log.debug("Found list of destination beans: " + listOfBeans);
                for (PerunBean bean : listOfBeans) {
                    destinationList.add((Destination) bean);
                }
            } catch (InternalErrorException e) {
                log.error("Could not resolve destination from destination list");
            }
            if (completedTask.getDestinations() != null && !completedTask.getDestinations().isEmpty()) {
                completedTask.setDestinations(destinationList);
            }
        }
        schedulingPool.setTaskStatus(completedTask, TaskStatus.ERROR);
        completedTask.setPropagationForced(false);
        log.debug("Task set to ERROR state with remaining destinations: " + completedTask.getDestinations());
    }
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) Task(cz.metacentrum.perun.taskslib.model.Task) PerunBean(cz.metacentrum.perun.core.api.PerunBean) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) TaskStatus(cz.metacentrum.perun.taskslib.model.Task.TaskStatus) Date(java.util.Date)

Example 7 with TaskStatus

use of cz.metacentrum.perun.taskslib.model.Task.TaskStatus in project perun by CESNET.

the class PropagationMaintainerImpl method endStuckTasks.

private void endStuckTasks() {
    // list all tasks in processing and planned and check if any have beeen
    // running for too long.
    log.info("I am gonna list planned and processing tasks and kill them if necessary...");
    List<Task> suspiciousTasks = schedulingPool.getProcessingTasks();
    suspiciousTasks.addAll(schedulingPool.getPlannedTasks());
    for (Task task : suspiciousTasks) {
        // count how many minutes the task stays in one state - if the state
        // is PLANNED count it from when it was scheduled ; if it is
        // PROCESSING count it from when it started
        Date started = task.getStartTime();
        Date scheduled = task.getSchedule();
        TaskStatus status = task.getStatus();
        if (status == null) {
            log.error("ERROR: Task presumably in PLANNED or PROCESSING state, but does not have a valid status. Switching to ERROR. {}", task);
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
            task.setPropagationForced(false);
            continue;
        }
        if (started == null && scheduled == null) {
            log.error("ERROR: Task presumably in PLANNED or PROCESSING state, but does not have a valid scheduled or started time. Switching to ERROR. {}", task);
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
            task.setPropagationForced(false);
            continue;
        }
        int howManyMinutesAgo = (int) (System.currentTimeMillis() - (started == null ? scheduled : started).getTime()) / 1000 / 60;
        // If too much time has passed something is broken
        if (howManyMinutesAgo >= rescheduleTime) {
            log.error("ERROR: Task is stuck in PLANNED or PROCESSING state. Switching it to ERROR. {}", task);
            task.setEndTime(new Date(System.currentTimeMillis()));
            schedulingPool.setTaskStatus(task, TaskStatus.ERROR);
            task.setPropagationForced(false);
        }
    }
/*
		 *
		 * List<Task> suspiciousTasks =
		 * taskManager.listAllTasksInState(TaskStatus.PROCESSING,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id")));
		 * suspiciousTasks
		 * .addAll(taskManager.listAllTasksInState(TaskStatus.PLANNED,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))));
		 * for (Task task : suspiciousTasks) { //count how many minutes the task
		 * stays in one state - if the state is PLANNED count it from when it
		 * was scheduled ; if it is PROCESSING count it from when it started int
		 * howManyMinutesAgo = (int) (System.currentTimeMillis() - (
		 * task.getStatus().equals(TaskStatus.PLANNED) ? task.getSchedule() :
		 * task.getStartTime() ).getTime()) / 1000 / 60;
		 *
		 * //If too much time has passed something is broken if
		 * (howManyMinutesAgo >= 60) { log.error(
		 * "ERROR: Task is stuck in PLANNED or PROCESSING state. Switching it to ERROR. {}"
		 * , task); task.setEndTime(new Date(System.currentTimeMillis()));
		 * task.setStatus(TaskStatus.ERROR); taskManager.updateTask(task,
		 * Integer.parseInt(propertiesBean.getProperty("engine.unique.id"))); }
		 * }
		 */
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) TaskStatus(cz.metacentrum.perun.taskslib.model.Task.TaskStatus) Date(java.util.Date)

Example 8 with TaskStatus

use of cz.metacentrum.perun.taskslib.model.Task.TaskStatus in project perun by CESNET.

the class SchedulingPoolImpl method setTaskStatus.

@Override
public void setTaskStatus(Task task, TaskStatus status) {
    TaskStatus old = task.getStatus();
    task.setStatus(status);
    // move task to the appropriate place
    synchronized (pool) {
        if (!old.equals(status)) {
            if (pool.get(old) != null) {
                pool.get(old).remove(task);
            } else {
                log.warn("Task " + task.getId() + "not known by old status");
            }
            if (pool.get(status) != null) {
                pool.get(status).add(task);
            } else {
                log.error("No task pool for status " + status.toString());
            }
        }
    }
}
Also used : TaskStatus(cz.metacentrum.perun.taskslib.model.Task.TaskStatus)

Example 9 with TaskStatus

use of cz.metacentrum.perun.taskslib.model.Task.TaskStatus in project perun by CESNET.

the class SchedulingPoolImpl method reloadTasks.

@Override
public void reloadTasks() {
    log.debug("Going to reload tasks from database...");
    this.clear();
    for (Pair<Task, Integer> pair : taskManager.listAllTasksAndClients()) {
        Task task = pair.getLeft();
        TaskStatus status = task.getStatus();
        if (status == null) {
            task.setStatus(TaskStatus.NONE);
        }
        /*
			if(task.getFacility().getName().equals("alcor.ics.muni.cz") ||
               task.getFacility().getName().equals("aldor.ics.muni.cz") ||
               task.getFacility().getName().equals("ascor.ics.muni.cz") ||
               task.getFacility().getName().equals("torque.ics.muni.cz") ||
               task.getFacility().getName().equals("nympha-cloud.zcu.cz")) {
            } else {
                    log.debug("Skipping task for facility {} not meant for testing.", task.getFacility().getName());
                    continue;
            }
            */
        if (!pool.get(task.getStatus()).contains(task)) {
            pool.get(task.getStatus()).add(task);
        }
        DispatcherQueue queue = dispatcherQueuePool.getDispatcherQueueByClient(pair.getRight());
        // XXX should this be synchronized too?
        tasksById.put(task.getId(), new Pair<Task, DispatcherQueue>(task, queue));
        tasksByServiceAndFacility.put(new Pair<Integer, Integer>(task.getExecServiceId(), task.getFacilityId()), task);
        // TODO: what about possible duplicates?
        log.debug("Added task " + task.toString() + " belonging to queue " + pair.getRight());
    }
    log.info("Pool contains: ");
    for (TaskStatus status : TaskStatus.class.getEnumConstants()) {
        log.info("  - {} tasks in state {}", pool.get(status).size(), status.toString());
    }
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) DispatcherQueue(cz.metacentrum.perun.dispatcher.jms.DispatcherQueue) TaskStatus(cz.metacentrum.perun.taskslib.model.Task.TaskStatus)

Aggregations

TaskStatus (cz.metacentrum.perun.taskslib.model.Task.TaskStatus)9 Task (cz.metacentrum.perun.taskslib.model.Task)5 Date (java.util.Date)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 DispatcherQueue (cz.metacentrum.perun.dispatcher.jms.DispatcherQueue)2 Destination (cz.metacentrum.perun.core.api.Destination)1 Pair (cz.metacentrum.perun.core.api.Pair)1 PerunBean (cz.metacentrum.perun.core.api.PerunBean)1 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)1 ArrayList (java.util.ArrayList)1