Search in sources :

Example 61 with Task

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

the class SchedulingPoolImpl method closeTasksForEngine.

@Override
public void closeTasksForEngine() {
    List<Task> tasks = taskStore.getTasksWithStatus(TaskStatus.PLANNED, TaskStatus.GENERATING, TaskStatus.GENERATED, TaskStatus.SENDING);
    // switch all processing tasks to error, remove the engine queue association
    log.debug("Switching processing tasks on engine to ERROR, the engine went down...");
    for (Task task : tasks) {
        log.info("[{}] Switching Task to ERROR, the engine it was running on went down.", task.getId());
        task.setStatus(TaskStatus.ERROR);
    }
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task)

Example 62 with Task

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

the class SchedulingPoolImpl method reloadTasks.

@Override
public void reloadTasks() {
    log.debug("Going to reload Tasks from database...");
    this.clear();
    EngineMessageProducer queue = engineMessageProducerFactory.getProducer();
    for (Task task : tasksManagerBl.listAllTasks(sess)) {
        try {
            // just add DB Task to in-memory structure
            addToPool(task);
        } catch (TaskStoreException e) {
            log.error("Adding Task {} and Queue {} into SchedulingPool failed, so the Task will be lost.", task, queue);
        }
        // done/error tasks will be rescheduled later by periodic jobs of PropagationMaintainer !!
        if (Arrays.asList(TaskStatus.WAITING, TaskStatus.PLANNED, TaskStatus.GENERATING, TaskStatus.SENDING).contains(task.getStatus())) {
            if (task.getStatus().equals(TaskStatus.WAITING)) {
                // reset timestamp to 'now' for WAITING Tasks, since scheduling task
                // sets this to all tasks except the waiting
                task.setSchedule(LocalDateTime.now());
                tasksManagerBl.updateTask(sess, task);
            }
            scheduleTask(task, 0);
        }
    }
    log.debug("Reload of Tasks from database finished.");
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) EngineMessageProducer(cz.metacentrum.perun.dispatcher.jms.EngineMessageProducer) TaskStoreException(cz.metacentrum.perun.taskslib.exceptions.TaskStoreException)

Example 63 with Task

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

the class TaskSchedulerTest method sourceUpdatedRunTest.

@Test
public void sourceUpdatedRunTest() {
    simpleSpy.setTask(simpleFutureTask);
    simpleSpy.setSchedulingPool(schedulingPool);
    Long timeLimit = 100L;
    Task[] tasks = simpleSetup(timeLimit, schedulingPool);
    Task testTask1 = tasks[0], testTask2 = tasks[1];
    testTask2.setSourceUpdated(true);
    schedulingPool.scheduleTask(testTask2, 4);
    schedulingPool.scheduleTask(testTask1, 4);
    simpleFutureTask.run();
    assertFalse(simpleSpy.testFailed);
    try {
        // FIXME - make every second test not to fail on interrupted exception
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) FutureTask(java.util.concurrent.FutureTask) AbstractDispatcherTest(cz.metacentrum.perun.dispatcher.AbstractDispatcherTest) Test(org.junit.Test)

Example 64 with Task

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

the class TaskSchedulerTest method sourceUpdatedRecurrenceRunTest.

@Test
public void sourceUpdatedRecurrenceRunTest() {
    recurrenceSpy.setTask(recurrenceFutureTask);
    recurrenceSpy.setSchedulingPool(schedulingPool);
    Long timeLimit = 100L;
    Task[] tasks = simpleSetup(timeLimit, schedulingPool);
    Task testTask1 = tasks[0];
    schedulingPool.scheduleTask(testTask1, 2);
    recurrenceFutureTask.run();
    assertFalse(recurrenceSpy.testFailed);
    try {
        // FIXME - make every second test not to fail on interrupted exception
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) FutureTask(java.util.concurrent.FutureTask) AbstractDispatcherTest(cz.metacentrum.perun.dispatcher.AbstractDispatcherTest) Test(org.junit.Test)

Example 65 with Task

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

the class TaskSchedulerTest method simpleRunTest.

@Test
public void simpleRunTest() throws InterruptedException {
    simpleSpy.setTask(simpleFutureTask);
    simpleSpy.setSchedulingPool(schedulingPool);
    Long timeLimit = 100L;
    Task[] tasks = simpleSetup(timeLimit, schedulingPool);
    Task testTask1 = tasks[0], testTask2 = tasks[1];
    schedulingPool.scheduleTask(testTask1, 4);
    schedulingPool.scheduleTask(testTask1, 4);
    Thread.sleep(timeLimit / 100);
    schedulingPool.scheduleTask(testTask1, 4);
    Thread.sleep((timeLimit / 100) * 8);
    schedulingPool.scheduleTask(testTask2, 4);
    simpleFutureTask.run();
    assertFalse(simpleSpy.testFailed);
    try {
        // FIXME - make every second test not to fail on interrupted exception
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) FutureTask(java.util.concurrent.FutureTask) AbstractDispatcherTest(cz.metacentrum.perun.dispatcher.AbstractDispatcherTest) Test(org.junit.Test)

Aggregations

Task (cz.metacentrum.perun.taskslib.model.Task)77 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)16 Date (java.util.Date)16 Test (org.junit.Test)15 Facility (cz.metacentrum.perun.core.api.Facility)14 Destination (cz.metacentrum.perun.core.api.Destination)11 Service (cz.metacentrum.perun.core.api.Service)10 TaskStoreException (cz.metacentrum.perun.taskslib.exceptions.TaskStoreException)10 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)9 ExecService (cz.metacentrum.perun.taskslib.model.ExecService)9 ArrayList (java.util.ArrayList)9 AbstractDispatcherTest (cz.metacentrum.perun.dispatcher.AbstractDispatcherTest)6 SendTask (cz.metacentrum.perun.taskslib.model.SendTask)6 TaskResult (cz.metacentrum.perun.taskslib.model.TaskResult)6 JMSException (javax.jms.JMSException)6 Pair (cz.metacentrum.perun.core.api.Pair)5 AbstractEngineTest (cz.metacentrum.perun.engine.AbstractEngineTest)5 TaskExecutionException (cz.metacentrum.perun.engine.exceptions.TaskExecutionException)5 LocalDateTime (java.time.LocalDateTime)5 Resource (cz.metacentrum.perun.core.api.Resource)4