Search in sources :

Example 1 with GenWorkerImpl

use of cz.metacentrum.perun.engine.scheduling.impl.GenWorkerImpl in project perun by CESNET.

the class GenWorkerImplTest method testGenWorkerSuccess.

@Test
public void testGenWorkerSuccess() throws Exception {
    GenWorker worker = new GenWorkerImpl(task1, null);
    Task resultTask = worker.call();
    LocalDateTime now = LocalDateTime.now();
    assertTrue(resultTask.getGenEndTime().isBefore(now) || resultTask.getGenEndTime().equals(now));
    // GenWorker itself doesn't change status anymore, since it caused race condition with endStuckTasks() process
    // Its now responsibility of GenCollector thread to switch status -> only genEndTime is set by worker.
    assertEquals(PLANNED, resultTask.getStatus());
}
Also used : LocalDateTime(java.time.LocalDateTime) Task(cz.metacentrum.perun.taskslib.model.Task) GenWorker(cz.metacentrum.perun.engine.scheduling.GenWorker) GenWorkerImpl(cz.metacentrum.perun.engine.scheduling.impl.GenWorkerImpl) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Example 2 with GenWorkerImpl

use of cz.metacentrum.perun.engine.scheduling.impl.GenWorkerImpl in project perun by CESNET.

the class GenPlanner method run.

@Override
public void run() {
    BlockingDeque<Task> newTasks = schedulingPool.getNewTasksQueue();
    while (!shouldStop()) {
        try {
            log.debug("Getting new Task in the newTasks BlockingDeque");
            Task task = newTasks.take();
            /*
				!! Change status immediately, so it won't be picked by PropagationMaintainer#endStuckTasks()
				because we might be waiting on blockingSubmit() here !!
				*/
            task.setStatus(GENERATING);
            GenWorker worker = new GenWorkerImpl(task, directory);
            genCompletionService.blockingSubmit(worker);
            try {
                jmsQueueManager.reportTaskStatus(task.getId(), task.getStatus(), task.getGenStartTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
            } catch (JMSException e) {
                log.warn("[{}] Could not send Tasks {} GEN status update: {}", task.getId(), task, e);
            }
        } catch (InterruptedException e) {
            String errorStr = "Thread executing GEN tasks was interrupted.";
            log.error(errorStr, e);
            throw new RuntimeException(errorStr, e);
        } catch (Throwable ex) {
            log.error("Unexpected exception in GenPlanner thread. Stuck Tasks will be cleaned by PropagationMaintainer#endStuckTasks() later.", ex);
        }
    }
}
Also used : Task(cz.metacentrum.perun.taskslib.model.Task) GenWorker(cz.metacentrum.perun.engine.scheduling.GenWorker) GenWorkerImpl(cz.metacentrum.perun.engine.scheduling.impl.GenWorkerImpl) JMSException(javax.jms.JMSException)

Example 3 with GenWorkerImpl

use of cz.metacentrum.perun.engine.scheduling.impl.GenWorkerImpl in project perun by CESNET.

the class GenWorkerImplTest method testGenWorkerFailure.

@Test
public void testGenWorkerFailure() throws Exception {
    GenWorker worker = new GenWorkerImpl(task2, null);
    try {
        worker.call();
        fail("TaskExecutionException should be thrown.");
    } catch (TaskExecutionException e) {
        assertEquals(task2.getId(), e.getTask().getId());
        assertEquals(1, e.getReturnCode());
    } catch (Exception e) {
        fail("Unexpected exception caught " + e);
    }
}
Also used : TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException) GenWorker(cz.metacentrum.perun.engine.scheduling.GenWorker) GenWorkerImpl(cz.metacentrum.perun.engine.scheduling.impl.GenWorkerImpl) TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Aggregations

GenWorker (cz.metacentrum.perun.engine.scheduling.GenWorker)3 GenWorkerImpl (cz.metacentrum.perun.engine.scheduling.impl.GenWorkerImpl)3 AbstractEngineTest (cz.metacentrum.perun.engine.AbstractEngineTest)2 Task (cz.metacentrum.perun.taskslib.model.Task)2 Test (org.junit.Test)2 TaskExecutionException (cz.metacentrum.perun.engine.exceptions.TaskExecutionException)1 LocalDateTime (java.time.LocalDateTime)1 JMSException (javax.jms.JMSException)1