Search in sources :

Example 6 with TaskExecutionException

use of cz.metacentrum.perun.engine.exceptions.TaskExecutionException in project perun by CESNET.

the class BlockingSendExecutorCompletionService method blockingTake.

@Override
public SendTask blockingTake() throws InterruptedException, TaskExecutionException {
    Future<SendTask> taskFuture = completionService.take();
    try {
        // .get() throws CancellationException if Task processing was cancelled from outside
        SendTask sendTask = taskFuture.get();
        removeTaskFuture(taskFuture);
        return sendTask;
    } catch (ExecutionException e) {
        SendTask sendTask = executingSendTasks.get(taskFuture);
        removeTaskFuture(taskFuture);
        Throwable cause = e.getCause();
        if (cause instanceof TaskExecutionException) {
            // SEND Task failed and related Task and results are part of this exception
            throw (TaskExecutionException) cause;
        } else {
            // Unexpected exception during processing, pass stored SendTask if possible
            if (sendTask == null) {
                log.error("We couldn't get SendTask for failed Future<SendTask>: {}", e);
                throw new RuntimeException("We couldn't get SendTask for failed Future<Task>", e);
            }
            throw new TaskExecutionException(sendTask.getTask(), sendTask.getDestination(), "Unexpected exception during SEND Task processing.", e);
        }
    } catch (CancellationException ex) {
        // processing was cancelled
        SendTask removedSendTask = executingSendTasks.get(taskFuture);
        removeTaskFuture(taskFuture);
        if (removedSendTask == null) {
            log.error("Somebody manually removed Future<SendTask> from executingSendTasks or SendTask was null: {}", ex);
            // we can't do anything about it
            throw ex;
        }
        // make sure SendCollector always get related Task
        throw new TaskExecutionException(removedSendTask.getTask(), removedSendTask.getDestination(), "Processing of Task was cancelled before completion.");
    }
}
Also used : TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException) SendTask(cz.metacentrum.perun.taskslib.model.SendTask) TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException)

Example 7 with TaskExecutionException

use of cz.metacentrum.perun.engine.exceptions.TaskExecutionException in project perun by CESNET.

the class SendWorkerImpl method call.

@Override
public SendTask call() throws TaskExecutionException {
    Task task = sendTask.getTask();
    Service service = task.getService();
    // we never actually run DUMMY destinations !!
    if (sendTask.getDestination().getPropagationType().equals(Destination.PROPAGATIONTYPE_DUMMY)) {
        log.info("[{}] Executing SEND worker skipped for dummy Destination: {}. Marked as SENT.", sendTask.getTask().getId(), sendTask.getDestination().getDestination());
        // set results
        sendTask.setStatus(SENT);
        sendTask.setStdout("");
        sendTask.setStderr("");
        sendTask.setReturnCode(0);
        sendTask.setEndTime(new Date(System.currentTimeMillis()));
        return sendTask;
    }
    log.info("[{}] Executing SEND worker for Task with Service ID: {} and Facility ID: {} and Destination: {}", sendTask.getTask().getId(), sendTask.getTask().getServiceId(), sendTask.getTask().getFacilityId(), sendTask.getDestination().getDestination());
    ProcessBuilder pb = new ProcessBuilder(service.getScript(), task.getFacility().getName(), sendTask.getDestination().getDestination(), sendTask.getDestination().getType());
    try {
        // start the script and wait for results
        super.execute(pb);
        // set results
        sendTask.setStdout(super.getStdout());
        sendTask.setStderr(super.getStderr());
        sendTask.setReturnCode(super.getReturnCode());
        sendTask.setEndTime(new Date(System.currentTimeMillis()));
        if (getReturnCode() != 0) {
            log.error("[{}] SEND worker failed for Task. Ret code {}, STDOUT: {}, STDERR: {}", task.getId(), getReturnCode(), getStdout(), getStderr());
            sendTask.setStatus(ERROR);
            // XXX: why exception? There is nothing exceptional about the situation.
            throw new TaskExecutionException(task, sendTask.getDestination(), getReturnCode(), getStdout(), getStderr());
        } else {
            if (getStderr().isEmpty()) {
                sendTask.setStatus(SENT);
            } else {
                sendTask.setStatus(WARNING);
            }
            log.info("[{}] SEND worker finished for Task with status {}. Ret code {}, STDOUT: {}, STDERR: {}", sendTask.getTask().getId(), sendTask.getStatus(), getReturnCode(), getStdout(), getStderr());
            return sendTask;
        }
    } catch (IOException e) {
        log.error("[{}] SEND worker failed for Task. IOException: {}.", task.getId(), e);
        sendTask.setStatus(ERROR);
        sendTask.setEndTime(new Date(System.currentTimeMillis()));
        throw new TaskExecutionException(task, sendTask.getDestination(), 2, "", e.getMessage());
    } catch (InterruptedException e) {
        log.warn("[{}] SEND worker failed for Task. Execution was interrupted {}.", task.getId(), e);
        sendTask.setStatus(ERROR);
        sendTask.setEndTime(new Date(System.currentTimeMillis()));
        throw new TaskExecutionException(task, sendTask.getDestination(), 1, "", e.getMessage());
    }
}
Also used : TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException) Task(cz.metacentrum.perun.taskslib.model.Task) SendTask(cz.metacentrum.perun.taskslib.model.SendTask) Service(cz.metacentrum.perun.core.api.Service) IOException(java.io.IOException) Date(java.util.Date)

Example 8 with TaskExecutionException

use of cz.metacentrum.perun.engine.exceptions.TaskExecutionException 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)

Example 9 with TaskExecutionException

use of cz.metacentrum.perun.engine.exceptions.TaskExecutionException 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 10 with TaskExecutionException

use of cz.metacentrum.perun.engine.exceptions.TaskExecutionException in project perun by CESNET.

the class BlockingGenExecutorCompletionService method blockingTake.

@Override
public Task blockingTake() throws InterruptedException, TaskExecutionException {
    Future<Task> taskFuture = completionService.take();
    try {
        // .get() throws CancellationException if Task processing was cancelled from outside
        Task task = taskFuture.get();
        removeTaskFuture(taskFuture);
        return task;
    } catch (ExecutionException e) {
        Task task = executingGenTasks.get(taskFuture);
        removeTaskFuture(taskFuture);
        Throwable cause = e.getCause();
        if (cause instanceof TaskExecutionException) {
            // GEN Task failed and related Task and results are part of this exception
            throw (TaskExecutionException) cause;
        } else {
            // Unexpected exception during processing, pass stored Task if possible
            if (task == null) {
                log.error("We couldn't get Task for failed Future<Task>: {}", e);
                throw new RuntimeException("We couldn't get Task for failed Future<Task>", e);
            }
            throw new TaskExecutionException(task, "Unexpected exception during GEN Task processing.", e);
        }
    } catch (CancellationException ex) {
        // processing was cancelled
        Task removedTask = executingGenTasks.get(taskFuture);
        removeTaskFuture(taskFuture);
        if (removedTask == null) {
            log.error("Somebody manually removed Future<Task> from executingGenTasks or Task was null: {}", ex);
            // we can't do anything about it
            throw ex;
        }
        // make sure GenCollector always get related Task
        throw new TaskExecutionException(removedTask, "Processing of Task was cancelled before completion.");
    }
}
Also used : TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException) Task(cz.metacentrum.perun.taskslib.model.Task) TaskExecutionException(cz.metacentrum.perun.engine.exceptions.TaskExecutionException)

Aggregations

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