Search in sources :

Example 11 with TaskStoreException

use of cz.metacentrum.perun.taskslib.exceptions.TaskStoreException 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

TaskStoreException (cz.metacentrum.perun.taskslib.exceptions.TaskStoreException)11 Task (cz.metacentrum.perun.taskslib.model.Task)10 Destination (cz.metacentrum.perun.core.api.Destination)5 SendTask (cz.metacentrum.perun.taskslib.model.SendTask)4 JMSException (javax.jms.JMSException)4 Service (cz.metacentrum.perun.core.api.Service)3 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)3 Facility (cz.metacentrum.perun.core.api.Facility)2 Pair (cz.metacentrum.perun.core.api.Pair)2 FacilityNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException)2 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)2 ServiceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException)2 TaskExecutionException (cz.metacentrum.perun.engine.exceptions.TaskExecutionException)2 PerunClient (cz.metacentrum.perun.core.api.PerunClient)1 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)1 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)1 EngineMessageProducer (cz.metacentrum.perun.dispatcher.jms.EngineMessageProducer)1 InvalidEventMessageException (cz.metacentrum.perun.engine.exceptions.InvalidEventMessageException)1 SendWorker (cz.metacentrum.perun.engine.scheduling.SendWorker)1 BlockingSendExecutorCompletionService (cz.metacentrum.perun.engine.scheduling.impl.BlockingSendExecutorCompletionService)1