Search in sources :

Example 1 with SendWorker

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

the class BlockingSendExecutorCompletionService method blockingSubmit.

@Override
public Future<SendTask> blockingSubmit(EngineWorker<SendTask> taskWorker) throws InterruptedException {
    semaphore.acquire();
    Future<SendTask> future = null;
    try {
        SendWorker sendWorker = (SendWorker) taskWorker;
        sendWorker.getSendTask().setStartTime(new Date(System.currentTimeMillis()));
        sendWorker.getSendTask().setStatus(SENDING);
        future = completionService.submit(sendWorker);
        executingSendTasks.put(future, sendWorker.getSendTask());
    } catch (Exception ex) {
        semaphore.release();
        throw ex;
    }
    return future;
}
Also used : SendWorker(cz.metacentrum.perun.engine.scheduling.SendWorker) SendTask(cz.metacentrum.perun.taskslib.model.SendTask) Date(java.util.Date) TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException)

Example 2 with SendWorker

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

the class SendWorkerImplTest method testSendWorkerFailure.

@Test
public void testSendWorkerFailure() throws Exception {
    SendWorker worker = new SendWorkerImpl(sendTaskFalse, null);
    try {
        worker.call();
        fail("TaskExecutionException should be thrown");
    } catch (TaskExecutionException e) {
        assertEquals(sendTaskFalse.getTask(), e.getTask());
        assertEquals(sendTaskFalse.getDestination(), e.getDestination());
        assertEquals(1, e.getReturnCode());
    } catch (Exception e) {
        fail("Unknown exception caught " + e);
    }
}
Also used : TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException) SendWorker(cz.metacentrum.perun.engine.scheduling.SendWorker) TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException) SendWorkerImpl(cz.metacentrum.perun.engine.scheduling.impl.SendWorkerImpl) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Example 3 with SendWorker

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

the class SendWorkerImplTest method testSendWorkerSuccess.

@Test
public void testSendWorkerSuccess() throws Exception {
    SendWorker worker = new SendWorkerImpl(sendTask1, null);
    SendTask resultSendTask = worker.call();
    assertEquals(SENT, resultSendTask.getStatus());
    assertEquals((long) 0, (long) resultSendTask.getReturnCode());
    Date now = new Date(System.currentTimeMillis());
    assertTrue(resultSendTask.getEndTime().before(now) || resultSendTask.getEndTime().equals(now));
}
Also used : SendWorker(cz.metacentrum.perun.engine.scheduling.SendWorker) SendTask(cz.metacentrum.perun.taskslib.model.SendTask) Date(java.util.Date) SendWorkerImpl(cz.metacentrum.perun.engine.scheduling.impl.SendWorkerImpl) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Example 4 with SendWorker

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

the class SendPlanner method run.

@Override
public void run() {
    BlockingQueue<Task> generatedTasks = schedulingPool.getGeneratedTasksQueue();
    while (!shouldStop()) {
        try {
            Task task = generatedTasks.take();
            // has destinations -> SENDING
            if (task.getDestinations().isEmpty()) {
                task.setStatus(Task.TaskStatus.ERROR);
                try {
                    jmsQueueManager.reportTaskStatus(task.getId(), task.getStatus(), System.currentTimeMillis());
                } catch (JMSException e) {
                    jmsLogError(task);
                }
                try {
                    schedulingPool.removeTask(task);
                } catch (TaskStoreException e) {
                    log.error("[{}] Generated Task without destinations could not be removed from SchedulingPool: {}", task.getId(), e);
                }
                // skip to next generated Task
                continue;
            }
            // Task has destinations
            task.setStatus(Task.TaskStatus.SENDING);
            // TODO - would be probably better to have this as one time call after first SendWorker is submitted
            // TODO   but then processing stuck tasks must reflect, that SENDING task might have sendStartTime=NULL
            task.setSendStartTime(LocalDateTime.now());
            schedulingPool.addSendTaskCount(task, task.getDestinations().size());
            try {
                jmsQueueManager.reportTaskStatus(task.getId(), task.getStatus(), task.getSendStartTime().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
            } catch (JMSException e) {
                jmsLogError(task);
            }
            // create SendTask and SendWorker for each Destination
            for (Destination destination : task.getDestinations()) {
                // submit for execution
                SendTask sendTask = new SendTask(task, destination);
                SendWorker worker = new SendWorkerImpl(sendTask, directory);
                sendCompletionService.blockingSubmit(worker);
            }
        } catch (InterruptedException e) {
            String errorStr = "Thread planning SendTasks was interrupted.";
            log.error(errorStr);
            throw new RuntimeException(errorStr, e);
        } catch (Throwable ex) {
            log.error("Unexpected exception in SendPlanner thread. Stuck Tasks will be cleaned by PropagationMaintainer#endStuckTasks() later.", ex);
        }
    }
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) SendWorker(cz.metacentrum.perun.engine.scheduling.SendWorker) Task(cz.metacentrum.perun.taskslib.model.Task) SendTask(cz.metacentrum.perun.taskslib.model.SendTask) SendTask(cz.metacentrum.perun.taskslib.model.SendTask) JMSException(javax.jms.JMSException) TaskStoreException(cz.metacentrum.perun.taskslib.exceptions.TaskStoreException) SendWorkerImpl(cz.metacentrum.perun.engine.scheduling.impl.SendWorkerImpl)

Aggregations

SendWorker (cz.metacentrum.perun.engine.scheduling.SendWorker)4 SendWorkerImpl (cz.metacentrum.perun.engine.scheduling.impl.SendWorkerImpl)3 SendTask (cz.metacentrum.perun.taskslib.model.SendTask)3 AbstractEngineTest (cz.metacentrum.perun.engine.AbstractEngineTest)2 TaskExecutionException (cz.metacentrum.perun.engine.exceptions.TaskExecutionException)2 Date (java.util.Date)2 Test (org.junit.Test)2 Destination (cz.metacentrum.perun.core.api.Destination)1 TaskStoreException (cz.metacentrum.perun.taskslib.exceptions.TaskStoreException)1 Task (cz.metacentrum.perun.taskslib.model.Task)1 JMSException (javax.jms.JMSException)1