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