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());
}
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);
}
}
}
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);
}
}
Aggregations