From 2051da3878451e45f24b587834e3a70701ef6305 Mon Sep 17 00:00:00 2001 From: "Carlos A. Munoz" Date: Wed, 28 Aug 2013 10:22:01 +1000 Subject: [PATCH 1/2] Fix incorrect process status code and add more logging for failures in async tasks. --- .../main/java/org/zanata/async/AsynchronousTaskExecutor.java | 4 ++++ .../rest/service/AsynchronousProcessResourceService.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/zanata-war/src/main/java/org/zanata/async/AsynchronousTaskExecutor.java b/zanata-war/src/main/java/org/zanata/async/AsynchronousTaskExecutor.java index 5f9a0f961f..00fb28a07d 100644 --- a/zanata-war/src/main/java/org/zanata/async/AsynchronousTaskExecutor.java +++ b/zanata-war/src/main/java/org/zanata/async/AsynchronousTaskExecutor.java @@ -32,6 +32,8 @@ import org.jboss.seam.security.Identity; import org.jboss.seam.security.RunAsOperation; +import lombok.extern.slf4j.Slf4j; + /** * This class executes a Runnable Process asynchronously. Do not use this class directly. * Use {@link org.zanata.async.TaskExecutor} instead as this is just a wrapper to make sure @@ -43,6 +45,7 @@ @Name("asynchronousTaskExecutor") @Scope(ScopeType.STATELESS) @AutoCreate +@Slf4j public class AsynchronousTaskExecutor { @Asynchronous @@ -63,6 +66,7 @@ public void execute() catch (Exception t) { task.getHandle().setException(t); + AsynchronousTaskExecutor.log.error("Exception when executing an asynchronous task.", t); } } diff --git a/zanata-war/src/main/java/org/zanata/rest/service/AsynchronousProcessResourceService.java b/zanata-war/src/main/java/org/zanata/rest/service/AsynchronousProcessResourceService.java index 29f0ff6f6a..168d5a4f25 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/AsynchronousProcessResourceService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/AsynchronousProcessResourceService.java @@ -252,11 +252,13 @@ public ProcessStatus getProcessStatus(@PathParam("processId") String processId) catch (InterruptedException e) { // The process was forcefully cancelled + status.setStatusCode(ProcessStatusCode.Failed); status.setMessages(Lists.newArrayList(e.getMessage())); } catch (ExecutionException e) { // Exception thrown while running the task + status.setStatusCode(ProcessStatusCode.Failed); status.setMessages(Lists.newArrayList(e.getCause().getMessage())); } From c0ea3819bb9d1b8b0dfa99d94785eb4282ed6f65 Mon Sep 17 00:00:00 2001 From: "Carlos A. Munoz" Date: Wed, 28 Aug 2013 11:35:31 +1000 Subject: [PATCH 2/2] Fix identity check failures for asynchronous tasks. Passing identity before which is automatically logged out when the session context is destroyed (which may happen when the original request ends). Replaced with passing of the subject and principal directly. --- .../java/org/zanata/async/AsynchronousTaskExecutor.java | 8 ++++---- .../src/main/java/org/zanata/async/TaskExecutor.java | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zanata-war/src/main/java/org/zanata/async/AsynchronousTaskExecutor.java b/zanata-war/src/main/java/org/zanata/async/AsynchronousTaskExecutor.java index 00fb28a07d..7ab78ac715 100644 --- a/zanata-war/src/main/java/org/zanata/async/AsynchronousTaskExecutor.java +++ b/zanata-war/src/main/java/org/zanata/async/AsynchronousTaskExecutor.java @@ -29,7 +29,6 @@ import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.jboss.seam.annotations.async.Asynchronous; -import org.jboss.seam.security.Identity; import org.jboss.seam.security.RunAsOperation; import lombok.extern.slf4j.Slf4j; @@ -49,7 +48,8 @@ public class AsynchronousTaskExecutor { @Asynchronous - public > void runAsynchronously(final AsyncTask task, final Identity runAs) + public > void runAsynchronously(final AsyncTask task, final Principal runAsPpal, + final Subject runAsSubject) { AsyncUtils.outject(task.getHandle(), ScopeType.EVENT); @@ -73,13 +73,13 @@ public void execute() @Override public Principal getPrincipal() { - return runAs.getPrincipal(); + return runAsPpal; } @Override public Subject getSubject() { - return runAs.getSubject(); + return runAsSubject; } }; diff --git a/zanata-war/src/main/java/org/zanata/async/TaskExecutor.java b/zanata-war/src/main/java/org/zanata/async/TaskExecutor.java index 0275ce0e18..2665be5dd1 100644 --- a/zanata-war/src/main/java/org/zanata/async/TaskExecutor.java +++ b/zanata-war/src/main/java/org/zanata/async/TaskExecutor.java @@ -57,7 +57,8 @@ public > AsyncTaskHandle startTask(AsyncTask< throw new RuntimeException("An Asynchronous task should always return a non-null handle"); } - asynchronousTaskExecutor.runAsynchronously(task, Identity.instance()); + Identity identity = Identity.instance(); + asynchronousTaskExecutor.runAsynchronously(task, identity.getPrincipal(), identity.getSubject()); return handle; }