From 364d90ea05548e2bb328dcf5056f1c9221cf1083 Mon Sep 17 00:00:00 2001 From: Michael Musgrove Date: Fri, 5 Apr 2019 11:21:43 +0100 Subject: [PATCH 1/3] JBTM-3087 Ensure the LRA implementation is up to date (including new context propagation semantics) --- .../lra/client/GenericLRAExceptionMapper.java | 2 +- .../IllegalLRAStateExceptionMapper.java | 2 +- .../client/InvalidLRAIdExceptionMapper.java | 2 +- .../lra/client/NarayanaLRAClient.java | 12 ++-- .../lra/coordinator/api/Coordinator.java | 12 ++-- .../api/CoordinatorContainerFilter.java | 14 ++-- .../coordinator/api/RecoveryCoordinator.java | 2 +- .../coordinator/domain/model/LRARecord.java | 67 +++++++++---------- .../coordinator/domain/model/Transaction.java | 4 +- .../domain/service/LRAService.java | 4 +- .../lra/filter/ClientLRARequestFilter.java | 5 ++ .../lra/filter/ClientLRAResponseFilter.java | 30 ++------- .../narayana/lra/filter/ServerLRAFilter.java | 48 ++++++------- .../main/java/io/narayana/lra/Current.java | 20 +++--- .../io/narayana/lra/GenericLRAException.java | 47 +++++++++++++ .../lra/IllegalLRAStateException.java | 49 ++++++++++++++ .../narayana/lra/InvalidLRAIdException.java | 56 ++++++++++++++++ .../io/narayana/lra/UnknowableException.java | 31 +++++++++ .../ConfigAuxiliaryArchiveAppender.java | 2 +- rts/lra/pom.xml | 4 +- 20 files changed, 290 insertions(+), 123 deletions(-) create mode 100644 rts/lra/lra-service-base/src/main/java/io/narayana/lra/GenericLRAException.java create mode 100644 rts/lra/lra-service-base/src/main/java/io/narayana/lra/IllegalLRAStateException.java create mode 100644 rts/lra/lra-service-base/src/main/java/io/narayana/lra/InvalidLRAIdException.java create mode 100644 rts/lra/lra-service-base/src/main/java/io/narayana/lra/UnknowableException.java diff --git a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/GenericLRAExceptionMapper.java b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/GenericLRAExceptionMapper.java index 5a97f33161..bb684720b5 100644 --- a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/GenericLRAExceptionMapper.java +++ b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/GenericLRAExceptionMapper.java @@ -21,7 +21,7 @@ */ package io.narayana.lra.client; -import org.eclipse.microprofile.lra.client.GenericLRAException; +import io.narayana.lra.GenericLRAException; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; diff --git a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/IllegalLRAStateExceptionMapper.java b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/IllegalLRAStateExceptionMapper.java index b64a9cd347..aa978a9a9e 100644 --- a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/IllegalLRAStateExceptionMapper.java +++ b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/IllegalLRAStateExceptionMapper.java @@ -21,7 +21,7 @@ */ package io.narayana.lra.client; -import org.eclipse.microprofile.lra.client.IllegalLRAStateException; +import io.narayana.lra.IllegalLRAStateException; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; diff --git a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/InvalidLRAIdExceptionMapper.java b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/InvalidLRAIdExceptionMapper.java index 2c86155f0e..34c1bd1921 100644 --- a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/InvalidLRAIdExceptionMapper.java +++ b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/InvalidLRAIdExceptionMapper.java @@ -21,7 +21,7 @@ */ package io.narayana.lra.client; -import org.eclipse.microprofile.lra.client.InvalidLRAIdException; +import io.narayana.lra.InvalidLRAIdException; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; diff --git a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/NarayanaLRAClient.java b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/NarayanaLRAClient.java index 6c09ce33ce..7ae43e5bac 100644 --- a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/NarayanaLRAClient.java +++ b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/NarayanaLRAClient.java @@ -64,6 +64,8 @@ import javax.ws.rs.core.Response; import io.narayana.lra.Current; +import io.narayana.lra.GenericLRAException; +import io.narayana.lra.IllegalLRAStateException; import org.eclipse.microprofile.lra.annotation.Compensate; import io.narayana.lra.logging.LRALogger; @@ -72,10 +74,8 @@ import org.eclipse.microprofile.lra.annotation.LRAStatus; import org.eclipse.microprofile.lra.annotation.ws.rs.Leave; import org.eclipse.microprofile.lra.annotation.Status; -import org.eclipse.microprofile.lra.client.GenericLRAException; -import org.eclipse.microprofile.lra.client.IllegalLRAStateException; -import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_HEADER; +import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; /** * A utility class for controlling the lifecycle of Long Running Actions (LRAs) but the prefered mechanism is to use @@ -286,7 +286,7 @@ public URI startLRA(URI parentLRA, String clientID, Long timeout, ChronoUnit uni } // validate that there is an LRAInfo response header holding the LRAInfo id - Object lraObject = Current.getLast(response.getHeaders().get(LRA_HTTP_HEADER)); + Object lraObject = Current.getLast(response.getHeaders().get(LRA_HTTP_CONTEXT_HEADER)); if (lraObject == null) { LRALogger.i18NLogger.error_nullLraOnCreation(response); @@ -358,7 +358,7 @@ public void leaveLRA(URI lraId, String body) throws GenericLRAException { response = getTarget().path(String.format(leaveFormat, getLRAId(lraId.toString()))) .request() - .header(LRA_HTTP_HEADER, lraId) + .header(LRA_HTTP_CONTEXT_HEADER, lraId) .put(Entity.entity(body, MediaType.TEXT_PLAIN)); if (Response.Status.OK.getStatusCode() != response.getStatus()) { @@ -636,7 +636,7 @@ private URI enlistCompensator(URI uri, long timelimit, String linkHeader, String .queryParam(TIMELIMIT_PARAM_NAME, timelimit) .request() .header(LINK_TEXT, linkHeader) - .header(LRA_HTTP_HEADER, lraId) + .header(LRA_HTTP_CONTEXT_HEADER, lraId) .put(Entity.entity(compensatorData == null ? linkHeader : compensatorData, MediaType.TEXT_PLAIN)); if (response.getStatus() == Response.Status.PRECONDITION_FAILED.getStatusCode()) { diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/Coordinator.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/Coordinator.java index c59263e262..a16ffb1f87 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/Coordinator.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/Coordinator.java @@ -23,6 +23,9 @@ package io.narayana.lra.coordinator.api; import io.narayana.lra.Current; +import io.narayana.lra.GenericLRAException; +import io.narayana.lra.IllegalLRAStateException; +import io.narayana.lra.InvalidLRAIdException; import io.narayana.lra.coordinator.domain.model.LRAData; import io.narayana.lra.coordinator.domain.model.LRAStatusHolder; import io.narayana.lra.coordinator.domain.model.Transaction; @@ -69,9 +72,6 @@ import java.util.Map; import org.eclipse.microprofile.lra.annotation.LRAStatus; -import org.eclipse.microprofile.lra.client.GenericLRAException; -import org.eclipse.microprofile.lra.client.IllegalLRAStateException; -import org.eclipse.microprofile.lra.client.InvalidLRAIdException; import static io.narayana.lra.LRAConstants.CLIENT_ID_PARAM_NAME; import static io.narayana.lra.LRAConstants.COMPENSATE; @@ -84,7 +84,7 @@ import static io.narayana.lra.LRAConstants.TIMELIMIT_PARAM_NAME; import static java.util.stream.Collectors.toList; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; -import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_HEADER; +import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_RECOVERY_HEADER; @ApplicationScoped @@ -238,7 +238,7 @@ public Response startLRA( @QueryParam(TIMELIMIT_PARAM_NAME) @DefaultValue("0") Long timelimit, @ApiParam(value = "The enclosing LRA if this new LRA is nested", required = false) @QueryParam(PARENT_LRA_PARAM_NAME) @DefaultValue("") String parentLRA, - @HeaderParam(LRA_HTTP_HEADER) String parentId) throws WebApplicationException, InvalidLRAIdException { + @HeaderParam(LRA_HTTP_CONTEXT_HEADER) String parentId) throws WebApplicationException, InvalidLRAIdException { URI parentLRAUrl = null; @@ -280,7 +280,7 @@ public Response startLRA( return Response.status(Response.Status.CREATED) .entity(lraId) - .header(LRA_HTTP_HEADER, Current.getContexts()) + .header(LRA_HTTP_CONTEXT_HEADER, Current.getContexts()) .build(); } diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/CoordinatorContainerFilter.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/CoordinatorContainerFilter.java index d6d30dba0e..9a613b96d1 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/CoordinatorContainerFilter.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/CoordinatorContainerFilter.java @@ -22,7 +22,7 @@ package io.narayana.lra.coordinator.api; import io.narayana.lra.Current; -import org.eclipse.microprofile.lra.client.GenericLRAException; +import io.narayana.lra.GenericLRAException; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; @@ -35,7 +35,7 @@ import java.net.URI; import java.net.URISyntaxException; -import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_HEADER; +import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; @Provider public class CoordinatorContainerFilter implements ContainerRequestFilter, ContainerResponseFilter { @@ -44,19 +44,19 @@ public void filter(ContainerRequestContext requestContext) throws IOException { MultivaluedMap headers = requestContext.getHeaders(); URI lraId = null; - if (headers.containsKey(LRA_HTTP_HEADER)) { + if (headers.containsKey(LRA_HTTP_CONTEXT_HEADER)) { try { - lraId = new URI(Current.getLast(headers.get(LRA_HTTP_HEADER))); + lraId = new URI(Current.getLast(headers.get(LRA_HTTP_CONTEXT_HEADER))); } catch (URISyntaxException e) { String msg = String.format("header %s contains an invalid URL %s", - LRA_HTTP_HEADER, Current.getLast(headers.get(LRA_HTTP_HEADER))); + LRA_HTTP_CONTEXT_HEADER, Current.getLast(headers.get(LRA_HTTP_CONTEXT_HEADER))); throw new GenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), msg, e); } } - if (!headers.containsKey(LRA_HTTP_HEADER)) { - Object lraContext = requestContext.getProperty(LRA_HTTP_HEADER); + if (!headers.containsKey(LRA_HTTP_CONTEXT_HEADER)) { + Object lraContext = requestContext.getProperty(LRA_HTTP_CONTEXT_HEADER); if (lraContext != null) { lraId = (URI) lraContext; diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/RecoveryCoordinator.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/RecoveryCoordinator.java index a9b7ba1920..b679632125 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/RecoveryCoordinator.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/RecoveryCoordinator.java @@ -21,6 +21,7 @@ */ package io.narayana.lra.coordinator.api; +import io.narayana.lra.GenericLRAException; import io.narayana.lra.coordinator.domain.model.LRAStatusHolder; import io.narayana.lra.coordinator.domain.service.LRAService; import io.narayana.lra.logging.LRALogger; @@ -29,7 +30,6 @@ import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -import org.eclipse.microprofile.lra.client.GenericLRAException; import org.jboss.logging.Logger; import javax.enterprise.context.ApplicationScoped; diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LRARecord.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LRARecord.java index d800ff3be6..7572d72c95 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LRARecord.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LRARecord.java @@ -29,11 +29,12 @@ import com.arjuna.ats.arjuna.state.OutputObjectState; import io.narayana.lra.Current; +import io.narayana.lra.GenericLRAException; +import io.narayana.lra.InvalidLRAIdException; import io.narayana.lra.coordinator.domain.service.LRAService; import io.narayana.lra.logging.LRALogger; import org.eclipse.microprofile.lra.annotation.LRAStatus; -import org.eclipse.microprofile.lra.client.GenericLRAException; -import org.eclipse.microprofile.lra.client.InvalidLRAIdException; +import org.eclipse.microprofile.lra.annotation.ParticipantStatus; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -58,7 +59,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; -import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_HEADER; +import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_RECOVERY_HEADER; public class LRARecord extends AbstractRecord implements Comparable { @@ -82,7 +83,7 @@ public class LRARecord extends AbstractRecord implements Comparable scheduledAbort; private LRAService lraService; - private LRAStatus status; + private ParticipantStatus status; boolean accepted; public LRARecord() { @@ -106,6 +107,8 @@ public LRARecord() { if (parseException[0] != null) { throw new InvalidLRAIdException(lraId, "Invalid link URI", parseException[0]); + } else if (compensateURI == null) { + throw new InvalidLRAIdException(lraId, "Invalid link URI: missing compensator"); } } else { this.compensateURI = new URI(String.format("%s/compensate", linkURI)); @@ -253,7 +256,7 @@ private int tryDoEnd(boolean compensate) { scheduledAbort = null; } - if (LRAStatus.Cancelling.equals(status)) { + if (ParticipantStatus.Compensating.equals(status)) { compensate = true; } @@ -263,16 +266,16 @@ private int tryDoEnd(boolean compensate) { } endPath = compensateURI; // we are going to ask the participant to compensate - status = LRAStatus.Cancelling; + status = ParticipantStatus.Compensating; } else { if (isCompelete() || completeURI == null) { - status = LRAStatus.Closed; + status = ParticipantStatus.Completed; return TwoPhaseOutcome.FINISH_OK; // the participant has already completed } endPath = completeURI; // we are going to ask the participant to complete - status = LRAStatus.Closing; + status = ParticipantStatus.Completing; } // NB trying to compensate when already completed is allowed (for nested LRAs) @@ -300,9 +303,9 @@ private int tryDoEnd(boolean compensate) { try { // ask the participant to complete or compensate Future asyncResponse = target.request() - .header(LRA_HTTP_HEADER, lraId.toASCIIString()) + .header(LRA_HTTP_CONTEXT_HEADER, lraId.toASCIIString()) .header(LRA_HTTP_RECOVERY_HEADER, recoveryURI.toASCIIString()) - .property(LRA_HTTP_HEADER, lraId) // make the context available to the jaxrs filters + .property(LRA_HTTP_CONTEXT_HEADER, lraId) // make the context available to the jaxrs filters .async() .put(Entity.entity(compensatorData, MediaType.APPLICATION_JSON)); // the catch block below catches any Timeout exception @@ -365,7 +368,7 @@ private int tryDoEnd(boolean compensate) { } if (compensate) { - status = LRAStatus.Cancelling; // recovery will figure out the status via the status url + status = ParticipantStatus.Compensating; // recovery will figure out the status via the status url /* * We are mapping compensate onto Abort. TwoPhaseCoordinator uses presumed abort @@ -375,7 +378,7 @@ private int tryDoEnd(boolean compensate) { return TwoPhaseOutcome.HEURISTIC_HAZARD; } - status = LRAStatus.Closing; // recovery will figure out the status via the status url + status = ParticipantStatus.Completing; // recovery will figure out the status via the status url return TwoPhaseOutcome.FINISH_ERROR; } @@ -388,14 +391,14 @@ private int tryDoEnd(boolean compensate) { private void updateStatus(boolean compensate) { if (compensate) { - status = accepted ? LRAStatus.Cancelling : LRAStatus.Cancelled; + status = accepted ? ParticipantStatus.Compensating : ParticipantStatus.Compensated; } else { - status = accepted ? LRAStatus.Closing : LRAStatus.Closed; + status = accepted ? ParticipantStatus.Completing : ParticipantStatus.Completed; } } private int reportFailure(boolean compensate, String endPath) { - status = compensate ? LRAStatus.FailedToCancel : LRAStatus.FailedToClose; + status = compensate ? ParticipantStatus.FailedToCompensate : ParticipantStatus.FailedToComplete; LRALogger.logger.warnf("LRARecord: participant %s reported a failure to %s", endPath, compensate ? COMPENSATE_REL : COMPLETE_REL); @@ -449,9 +452,9 @@ private int retryGetEndStatus(URI endPath, boolean compensate) { // since this method is called from the recovery thread do not block Future asyncResponse = target.request() - .header(LRA_HTTP_HEADER, lraId.toASCIIString()) + .header(LRA_HTTP_CONTEXT_HEADER, lraId.toASCIIString()) .header(LRA_HTTP_RECOVERY_HEADER, recoveryURI.toASCIIString()) - .property(LRA_HTTP_HEADER, lraId) // make the context available to the jaxrs filters + .property(LRA_HTTP_CONTEXT_HEADER, lraId) // make the context available to the jaxrs filters .async() .get(); @@ -468,35 +471,31 @@ private int retryGetEndStatus(URI endPath, boolean compensate) { // the participant is available again and has reported its status String s = response.readEntity(String.class); - status = LRAStatus.valueOf(s); + status = ParticipantStatus.valueOf(s); switch (status) { - case Closed: - case Cancelled: + case Completed: + case Compensated: return TwoPhaseOutcome.FINISH_OK; - case Closing: - case Cancelling: + case Completing: + case Compensating: // still in progress - make sure recovery keeps retrying it return TwoPhaseOutcome.HEURISTIC_HAZARD; - case FailedToCancel: - case FailedToClose: + case FailedToCompensate: + case FailedToComplete: // the participant could not finish - log a warning and forget LRALogger.logger.warnf( "LRARecord.doEnd(compensate %b) get status %s did not finish: %s: WILL NOT RETRY", compensate, target.getUri(), status); - if (forgetURI != null) { - forgetURI = statusURI; // forget is equivalent to HTTP delete on the status URI - } - if (forgetURI != null) { try { // let the participant know he can clean up WebTarget target2 = client.target(forgetURI); Future asyncResponse2 = target2.request() - .header(LRA_HTTP_HEADER, lraId.toASCIIString()) + .header(LRA_HTTP_CONTEXT_HEADER, lraId.toASCIIString()) .header(LRA_HTTP_RECOVERY_HEADER, recoveryURI.toASCIIString()) - .property(LRA_HTTP_HEADER, lraId) // make the context available to the jaxrs filters + .property(LRA_HTTP_CONTEXT_HEADER, lraId) // make the context available to the jaxrs filters .async() .delete(); @@ -612,11 +611,11 @@ boolean forget() { } private boolean isCompelete() { - return status != null && status == LRAStatus.Closed; + return status != null && status == ParticipantStatus.Completed; } private boolean isCompensated() { - return status != null && status == LRAStatus.Cancelled; + return status != null && status == ParticipantStatus.Compensated; } String getResponseData() { @@ -657,7 +656,7 @@ public boolean restore_state(InputObjectState os, int t) { unpackStatus(os); participantPath = os.unpackString(); compensatorData = os.unpackString(); - accepted = status == LRAStatus.Closing || status == LRAStatus.Cancelling; + accepted = status == ParticipantStatus.Completing || status == ParticipantStatus.Compensating; } catch (IOException | URISyntaxException e) { return false; } @@ -676,7 +675,7 @@ private void packStatus(OutputObjectState os) throws IOException { } private void unpackStatus(InputObjectState os) throws IOException { - status = os.unpackBoolean() ? LRAStatus.values()[os.unpackInt()] : null; + status = os.unpackBoolean() ? ParticipantStatus.values()[os.unpackInt()] : null; } private void packURI(OutputObjectState os, URI url) throws IOException { diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/Transaction.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/Transaction.java index 4647d61e26..c1d50d0829 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/Transaction.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/Transaction.java @@ -30,6 +30,7 @@ import com.arjuna.ats.arjuna.coordinator.RecordList; import com.arjuna.ats.arjuna.coordinator.RecordListIterator; import com.arjuna.ats.arjuna.coordinator.RecordType; +import io.narayana.lra.InvalidLRAIdException; import io.narayana.lra.logging.LRALogger; import com.arjuna.ats.arjuna.state.InputObjectState; import com.arjuna.ats.arjuna.state.OutputObjectState; @@ -37,7 +38,6 @@ import io.narayana.lra.coordinator.domain.service.LRAService; import org.eclipse.microprofile.lra.annotation.LRAStatus; -import org.eclipse.microprofile.lra.client.InvalidLRAIdException; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -551,7 +551,7 @@ private LRARecord findLRAParticipant(String participantUrl, boolean remove) { } catch (MalformedURLException | URISyntaxException ignore) { String pUrl = LRARecord.extractCompensator(id, participantUrl); - rec = findLRAParticipant(pUrl, remove, pendingList, pendingList, preparedList, heuristicList, failedList); + rec = findLRAParticipant(pUrl, remove, pendingList, preparedList, heuristicList, failedList); } return rec; diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java index 3dfa7210a2..5dfa32068e 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java @@ -23,6 +23,8 @@ import com.arjuna.ats.arjuna.AtomicAction; import com.arjuna.ats.arjuna.coordinator.ActionStatus; +import io.narayana.lra.IllegalLRAStateException; +import io.narayana.lra.InvalidLRAIdException; import io.narayana.lra.coordinator.domain.model.LRAData; import io.narayana.lra.logging.LRALogger; import com.arjuna.ats.arjuna.recovery.RecoveryManager; @@ -34,8 +36,6 @@ import io.narayana.lra.coordinator.domain.model.Transaction; import org.eclipse.microprofile.lra.annotation.LRAStatus; -import org.eclipse.microprofile.lra.client.IllegalLRAStateException; -import org.eclipse.microprofile.lra.client.InvalidLRAIdException; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.Destroyed; diff --git a/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ClientLRARequestFilter.java b/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ClientLRARequestFilter.java index 680b46daee..62c6ec75bb 100644 --- a/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ClientLRARequestFilter.java +++ b/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ClientLRARequestFilter.java @@ -26,9 +26,14 @@ import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; +import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; + public class ClientLRARequestFilter implements ClientRequestFilter { @Override public void filter(ClientRequestContext context) { + if (Current.peek() != null) { + context.setProperty(LRA_HTTP_CONTEXT_HEADER, Current.peek()); + } Current.updateLRAContext(context); } } diff --git a/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ClientLRAResponseFilter.java b/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ClientLRAResponseFilter.java index e8e16fd329..ece74f0101 100644 --- a/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ClientLRAResponseFilter.java +++ b/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ClientLRAResponseFilter.java @@ -30,9 +30,8 @@ import javax.ws.rs.core.Context; import java.io.IOException; import java.net.URI; -import java.net.URISyntaxException; -import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_HEADER; +import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; public class ClientLRAResponseFilter implements ClientResponseFilter { @Context @@ -40,31 +39,10 @@ public class ClientLRAResponseFilter implements ClientResponseFilter { @Override public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { - Object incomingLRA = Current.getLast(responseContext.getHeaders().get(LRA_HTTP_HEADER)); + Object callingContext = requestContext.getProperty(LRA_HTTP_CONTEXT_HEADER); - if (incomingLRA == null) { - incomingLRA = requestContext.getProperty(LRA_HTTP_HEADER); - } - - /* - * if the incoming response contains a context make it the current one - * (note we never popped the context in the request filter so we don't need to push outgoingLRA - */ - if (incomingLRA != null) { - try { - Current.push(new URI(incomingLRA.toString())); - } catch (URISyntaxException e) { - throw new IOException( - String.format("The JAX-RS '%s' filter for method '%s'#'%s' contained an invalid LRA context ('%s')", - ClientLRAResponseFilter.class.getName(), - resourceInfo.getResourceClass().getName(), - resourceInfo.getResourceMethod().getName(), - incomingLRA.toString()), e); - } - } else { - // any previous context must have been ended by the invoked service otherwise incomingLRA - // would have been present - Current.pop(); + if (callingContext != null) { + Current.push((URI) callingContext); } } } diff --git a/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ServerLRAFilter.java b/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ServerLRAFilter.java index 62042af32e..b675bd246a 100644 --- a/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ServerLRAFilter.java +++ b/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ServerLRAFilter.java @@ -22,6 +22,8 @@ package io.narayana.lra.filter; import io.narayana.lra.Current; +import io.narayana.lra.GenericLRAException; +import io.narayana.lra.IllegalLRAStateException; import io.narayana.lra.client.NarayanaLRAClient; import io.narayana.lra.logging.LRALogger; import org.eclipse.microprofile.lra.annotation.Compensate; @@ -31,8 +33,6 @@ import org.eclipse.microprofile.lra.annotation.ws.rs.Leave; import org.eclipse.microprofile.lra.annotation.ws.rs.NestedLRA; import org.eclipse.microprofile.lra.annotation.Status; -import org.eclipse.microprofile.lra.client.GenericLRAException; -import org.eclipse.microprofile.lra.client.IllegalLRAStateException; import javax.inject.Inject; import javax.ws.rs.NotFoundException; @@ -62,7 +62,7 @@ import static io.narayana.lra.LRAConstants.LEAVE; import static io.narayana.lra.LRAConstants.STATUS; import static io.narayana.lra.LRAConstants.TIMELIMIT_PARAM_NAME; -import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_HEADER; +import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_RECOVERY_HEADER; @Provider @@ -169,17 +169,27 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc || method.isAnnotationPresent(Status.class) || method.isAnnotationPresent(Forget.class); - if (headers.containsKey(LRA_HTTP_HEADER)) { + if (headers.containsKey(LRA_HTTP_CONTEXT_HEADER)) { try { - incommingLRA = new URI(Current.getLast(headers.get(LRA_HTTP_HEADER)).toString()); + incommingLRA = new URI(Current.getLast(headers.get(LRA_HTTP_CONTEXT_HEADER)).toString()); } catch (URISyntaxException e) { String msg = String.format("header %s contains an invalid URL %s", - LRA_HTTP_HEADER, Current.getLast(headers.get(LRA_HTTP_HEADER))); + LRA_HTTP_CONTEXT_HEADER, Current.getLast(headers.get(LRA_HTTP_CONTEXT_HEADER))); throw new GenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), msg, e); } } + if (method.isAnnotationPresent(Leave.class)) { + // leave the LRA + String compensatorId = getCompensatorId(incommingLRA, containerRequestContext.getUriInfo().getBaseUri()); + + lraTrace(containerRequestContext, incommingLRA, "leaving LRA"); + lraClient.leaveLRA(incommingLRA, compensatorId); + + // let the participant know which lra he left by leaving the header intact + } + if (type == null) { if (!endAnnotation) { Current.clearContext(headers); @@ -194,8 +204,8 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc } // check the incomming request for an LRA context - if (!headers.containsKey(LRA_HTTP_HEADER)) { - Object lraContext = containerRequestContext.getProperty(LRA_HTTP_HEADER); + if (!headers.containsKey(LRA_HTTP_CONTEXT_HEADER)) { + Object lraContext = containerRequestContext.getProperty(LRA_HTTP_CONTEXT_HEADER); if (lraContext != null) { incommingLRA = (URI) lraContext; @@ -327,6 +337,8 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc containerRequestContext.setProperty(NEW_LRA_PROP, newLRA); } + Current.push(lraId); + lraTrace(containerRequestContext, lraId, "ServerLRAFilter before: making LRA available to injected NarayanaLRAClient"); lraClient.setCurrentLRA(lraId); // make the current LRA available to the called method @@ -367,16 +379,6 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc } } - if (method.isAnnotationPresent(Leave.class)) { - // leave the LRA - String compensatorId = getCompensatorId(lraId, containerRequestContext.getUriInfo().getBaseUri()); - - lraTrace(containerRequestContext, lraId, "leaving LRA"); - lraClient.leaveLRA(lraId, compensatorId); - - // let the participant know which lra he left by leaving the header intact - } - lraTrace(containerRequestContext, lraId, "ServerLRAFilter before: making LRA available as a thread local"); } @@ -402,9 +404,9 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont // or completed (if the intercepted method caused it to complete) } finally { if (current.toASCIIString().equals( - Current.getLast(requestContext.getHeaders().get(LRA_HTTP_HEADER)))) { + Current.getLast(requestContext.getHeaders().get(LRA_HTTP_CONTEXT_HEADER)))) { // the callers context was ended so invalidate it - requestContext.getHeaders().remove(LRA_HTTP_HEADER); + requestContext.getHeaders().remove(LRA_HTTP_CONTEXT_HEADER); } if (toClose != null && toClose.toASCIIString().equals(current.toASCIIString())) { @@ -420,12 +422,12 @@ public void filter(ContainerRequestContext requestContext, ContainerResponseCont // must already be cancelled (if the intercepted method caused it to cancel) // or completed (if the intercepted method caused it to complete } finally { - requestContext.getHeaders().remove(LRA_HTTP_HEADER); + requestContext.getHeaders().remove(LRA_HTTP_CONTEXT_HEADER); if (toClose.toASCIIString().equals( - Current.getLast(requestContext.getHeaders().get(LRA_HTTP_HEADER)))) { + Current.getLast(requestContext.getHeaders().get(LRA_HTTP_CONTEXT_HEADER)))) { // the callers context was ended so invalidate it - requestContext.getHeaders().remove(LRA_HTTP_HEADER); + requestContext.getHeaders().remove(LRA_HTTP_CONTEXT_HEADER); } } } diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/Current.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/Current.java index f6855c7537..9507ee71fa 100644 --- a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/Current.java +++ b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/Current.java @@ -31,7 +31,7 @@ import java.util.Map; import java.util.Stack; -import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_HEADER; +import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; public class Current { private static final ThreadLocal lraContexts = new ThreadLocal<>(); @@ -154,14 +154,14 @@ public static void updateLRAContext(ContainerResponseContext responseContext) { URI lraId = Current.peek(); if (lraId != null) { - responseContext.getHeaders().put(LRA_HTTP_HEADER, getContexts()); + responseContext.getHeaders().put(LRA_HTTP_CONTEXT_HEADER, getContexts()); } else { - responseContext.getHeaders().remove(LRA_HTTP_HEADER); + responseContext.getHeaders().remove(LRA_HTTP_CONTEXT_HEADER); } } public static void updateLRAContext(URI lraId, MultivaluedMap headers) { - headers.putSingle(LRA_HTTP_HEADER, lraId.toString()); + headers.putSingle(LRA_HTTP_CONTEXT_HEADER, lraId.toString()); push(lraId); } @@ -174,7 +174,7 @@ public static void updateLRAContext(URI lraId, MultivaluedMap he public static void updateLRAContext(ClientRequestContext context) { MultivaluedMap headers = context.getHeaders(); - if (headers.containsKey(LRA_HTTP_HEADER)) { + if (headers.containsKey(LRA_HTTP_CONTEXT_HEADER)) { // LRA context is explicitly set return; } @@ -182,14 +182,14 @@ public static void updateLRAContext(ClientRequestContext context) { URI lraId = Current.peek(); if (lraId != null) { - headers.putSingle(LRA_HTTP_HEADER, lraId); + headers.putSingle(LRA_HTTP_CONTEXT_HEADER, lraId); } else { - Object lraContext = context.getProperty(LRA_HTTP_HEADER); + Object lraContext = context.getProperty(LRA_HTTP_CONTEXT_HEADER); if (lraContext != null) { - headers.putSingle(LRA_HTTP_HEADER, lraContext); + headers.putSingle(LRA_HTTP_CONTEXT_HEADER, lraContext); } else { - headers.remove(LRA_HTTP_HEADER); + headers.remove(LRA_HTTP_CONTEXT_HEADER); } } } @@ -199,7 +199,7 @@ public static void popAll() { } public static void clearContext(MultivaluedMap headers) { - headers.remove(LRA_HTTP_HEADER); + headers.remove(LRA_HTTP_CONTEXT_HEADER); popAll(); } diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/GenericLRAException.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/GenericLRAException.java new file mode 100644 index 0000000000..fab52a7d8b --- /dev/null +++ b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/GenericLRAException.java @@ -0,0 +1,47 @@ +/* + ******************************************************************************* + * Copyright (c) 2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ + +package io.narayana.lra; + +import javax.ws.rs.WebApplicationException; +import java.net.URI; + +public class GenericLRAException extends WebApplicationException { + private static final long serialVersionUID = 1L; + + private URI lraId; + private int statusCode; + + public int getStatusCode() { + return statusCode; + } + + public URI getLraId() { + return lraId; + } + + public GenericLRAException(URI lraId, int statusCode, String message, + Throwable cause) { + super(String.format("%s: %s", lraId, message), cause); + + this.lraId = lraId; + this.statusCode = statusCode; + } +} diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/IllegalLRAStateException.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/IllegalLRAStateException.java new file mode 100644 index 0000000000..f55ed83e75 --- /dev/null +++ b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/IllegalLRAStateException.java @@ -0,0 +1,49 @@ +/* + ******************************************************************************* + * Copyright (c) 2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package io.narayana.lra; + +import javax.ws.rs.WebApplicationException; + +public class IllegalLRAStateException extends WebApplicationException { + private final String lraId; + private final String operation; + + /** + * Creation of LRA state exception. + * + * @param lraId LRA id that is behind this exception + * @param operation the java method that generated the exception + * @param message error message of this exception + */ + public IllegalLRAStateException(String lraId, String operation, String message) { + super(String.format("%s, lra id: %s", message, lraId)); + + this.lraId = lraId; + this.operation = operation; + } + + public String getLraId() { + return this.lraId; + } + + public String getOperation() { + return this.operation; + } +} diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/InvalidLRAIdException.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/InvalidLRAIdException.java new file mode 100644 index 0000000000..b9c7e2392e --- /dev/null +++ b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/InvalidLRAIdException.java @@ -0,0 +1,56 @@ +/* + ******************************************************************************* + * Copyright (c) 2018 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package io.narayana.lra; + +import javax.ws.rs.WebApplicationException; + +public class InvalidLRAIdException extends WebApplicationException { + private static final long serialVersionUID = 1271422145863321852L; + private final String lraId; + + /** + * Invalid LRA id exception. + * + * @param lraId LRA id that is behind this exception + * @param message error message of this exception + * @param cause cause exception + */ + public InvalidLRAIdException(String lraId, String message, Throwable cause) { + super(String.format("%s, LRA id: %s", message, lraId), cause); + + this.lraId = lraId; + } + + /** + * Invalid LRA id exception. + * + * @param lraId LRA id that is behind this exception + * @param message error message of this exception + */ + public InvalidLRAIdException(String lraId, String message) { + super(String.format("%s, LRA id: %s", message, lraId)); + + this.lraId = lraId; + } + + public String getLraId() { + return this.lraId; + } +} diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/UnknowableException.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/UnknowableException.java new file mode 100644 index 0000000000..739a6f20e5 --- /dev/null +++ b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/UnknowableException.java @@ -0,0 +1,31 @@ +/* + ******************************************************************************* + * Copyright (c) 2019 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *******************************************************************************/ +package io.narayana.lra; + +import java.net.URI; + +/** + * An exception type to indicate that a requested operation can never be completed. + */ +public class UnknowableException extends GenericLRAException { + public UnknowableException(URI lraId, int statusCode, String message, Throwable cause) { + super(lraId, statusCode, message, cause); + } +} diff --git a/rts/lra/lra-test/tck/src/test/java/io/narayana/lra/tck/arquillian/ConfigAuxiliaryArchiveAppender.java b/rts/lra/lra-test/tck/src/test/java/io/narayana/lra/tck/arquillian/ConfigAuxiliaryArchiveAppender.java index 712a391dd0..bcb3dae73b 100644 --- a/rts/lra/lra-test/tck/src/test/java/io/narayana/lra/tck/arquillian/ConfigAuxiliaryArchiveAppender.java +++ b/rts/lra/lra-test/tck/src/test/java/io/narayana/lra/tck/arquillian/ConfigAuxiliaryArchiveAppender.java @@ -40,7 +40,7 @@ public Archive createAuxiliaryArchive() { JavaArchive archive = ShrinkWrap.create(JavaArchive.class) // adding LRA spec interfaces under the WildFly Swarm deployment .addPackages(true, org.eclipse.microprofile.lra.annotation.Compensate.class.getPackage()) - .addPackages(true, org.eclipse.microprofile.lra.client.InvalidLRAIdException.class.getPackage()) + .addPackages(true, io.narayana.lra.InvalidLRAIdException.class.getPackage()) .addPackages(true, org.eclipse.microprofile.lra.participant.LRAParticipant.class.getPackage()); // adding Narayana LRA implementation under the WildFly Swarm deployment archive.addPackages(true, io.narayana.lra.client.NarayanaLRAClient.class.getPackage()) diff --git a/rts/lra/pom.xml b/rts/lra/pom.xml index 381897fc83..45e2ca8c5f 100644 --- a/rts/lra/pom.xml +++ b/rts/lra/pom.xml @@ -33,8 +33,8 @@ 4.12 1.2.1.Final - 1.0-20190329.061214-321 - 1.0-20190329.061215-321 + 1.0-20190418.101203-346 + 1.0-20190418.101205-346 UTF-8 From 86ad3e8ae333a3cbe920fe9b7263bf4880dbcc09 Mon Sep 17 00:00:00 2001 From: Michael Musgrove Date: Fri, 19 Apr 2019 19:46:28 +0100 Subject: [PATCH 2/3] CI script fix - don't run install and verify together --- scripts/hudson/narayana.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/hudson/narayana.sh b/scripts/hudson/narayana.sh index 854bc56037..14ae60ad8f 100755 --- a/scripts/hudson/narayana.sh +++ b/scripts/hudson/narayana.sh @@ -455,7 +455,7 @@ function lra_tests { echo "#0. LRA Test" # we can't use 'mvn -f' option beacuse of Swarm plugin issue THORN-2049 cd ./rts/lra/ - PRESERVE_WORKING_DIR=true ../../build.sh -B -P$ARQ_PROF $CODE_COVERAGE_ARGS "$@" verify + PRESERVE_WORKING_DIR=true ../../build.sh -B -P$ARQ_PROF $CODE_COVERAGE_ARGS "$@" [ $? = 0 ] || fatal "LRA Test failed" cd - # back to original directory } From ba0852b078810dd3b5ebcc2df33cff14addd4f82 Mon Sep 17 00:00:00 2001 From: Michael Musgrove Date: Wed, 24 Apr 2019 14:53:55 +0100 Subject: [PATCH 3/3] JBTM-3087 Remove LRA exception mappers --- .../lra/client/GenericLRAExceptionMapper.java | 37 ----- .../IllegalLRAStateExceptionMapper.java | 38 ----- .../client/InvalidLRAIdExceptionMapper.java | 37 ----- .../lra/client/NarayanaLRAClient.java | 137 ++++++++++-------- .../lra/coordinator/api/Coordinator.java | 25 ++-- .../api/CoordinatorContainerFilter.java | 6 +- .../coordinator/api/RecoveryCoordinator.java | 7 +- .../coordinator/domain/model/LRARecord.java | 21 +-- .../coordinator/domain/model/Transaction.java | 4 +- .../domain/service/LRAService.java | 9 +- .../narayana/lra/filter/ServerLRAFilter.java | 38 ++--- .../io/narayana/lra/GenericLRAException.java | 47 ------ .../lra/IllegalLRAStateException.java | 49 ------- .../narayana/lra/InvalidLRAIdException.java | 56 ------- .../io/narayana/lra/UnknowableException.java | 31 ---- .../ConfigAuxiliaryArchiveAppender.java | 1 - 16 files changed, 137 insertions(+), 406 deletions(-) delete mode 100644 rts/lra/lra-client/src/main/java/io/narayana/lra/client/GenericLRAExceptionMapper.java delete mode 100644 rts/lra/lra-client/src/main/java/io/narayana/lra/client/IllegalLRAStateExceptionMapper.java delete mode 100644 rts/lra/lra-client/src/main/java/io/narayana/lra/client/InvalidLRAIdExceptionMapper.java delete mode 100644 rts/lra/lra-service-base/src/main/java/io/narayana/lra/GenericLRAException.java delete mode 100644 rts/lra/lra-service-base/src/main/java/io/narayana/lra/IllegalLRAStateException.java delete mode 100644 rts/lra/lra-service-base/src/main/java/io/narayana/lra/InvalidLRAIdException.java delete mode 100644 rts/lra/lra-service-base/src/main/java/io/narayana/lra/UnknowableException.java diff --git a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/GenericLRAExceptionMapper.java b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/GenericLRAExceptionMapper.java deleted file mode 100644 index bb684720b5..0000000000 --- a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/GenericLRAExceptionMapper.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2017, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package io.narayana.lra.client; - -import io.narayana.lra.GenericLRAException; - -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -@Provider -public class GenericLRAExceptionMapper implements ExceptionMapper { - @Override - public Response toResponse(GenericLRAException exception) { - return Response.status(exception.getStatusCode()) - .entity(exception.getMessage()).build(); - } -} diff --git a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/IllegalLRAStateExceptionMapper.java b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/IllegalLRAStateExceptionMapper.java deleted file mode 100644 index aa978a9a9e..0000000000 --- a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/IllegalLRAStateExceptionMapper.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2017, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package io.narayana.lra.client; - -import io.narayana.lra.IllegalLRAStateException; - -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -@Provider -public class IllegalLRAStateExceptionMapper implements ExceptionMapper { - @Override - public Response toResponse(IllegalLRAStateException exception) { - return Response.status(Response.Status.PRECONDITION_FAILED) - .entity(String.format("LRA is in the wrong state for operation '%s': %s", - exception.getOperation(), exception.getMessage())).build(); - } -} diff --git a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/InvalidLRAIdExceptionMapper.java b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/InvalidLRAIdExceptionMapper.java deleted file mode 100644 index 34c1bd1921..0000000000 --- a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/InvalidLRAIdExceptionMapper.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * JBoss, Home of Professional Open Source. - * Copyright 2017, Red Hat, Inc., and individual contributors - * as indicated by the @author tags. See the copyright.txt file in the - * distribution for a full listing of individual contributors. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package io.narayana.lra.client; - -import io.narayana.lra.InvalidLRAIdException; - -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -@Provider -public class InvalidLRAIdExceptionMapper implements ExceptionMapper { - @Override - public Response toResponse(InvalidLRAIdException exception) { - return Response.status(Response.Status.BAD_REQUEST) - .entity(exception.getMessage()).build(); - } -} diff --git a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/NarayanaLRAClient.java b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/NarayanaLRAClient.java index 7ae43e5bac..8db4ad5118 100644 --- a/rts/lra/lra-client/src/main/java/io/narayana/lra/client/NarayanaLRAClient.java +++ b/rts/lra/lra-client/src/main/java/io/narayana/lra/client/NarayanaLRAClient.java @@ -30,6 +30,7 @@ import static io.narayana.lra.LRAConstants.PARENT_LRA_PARAM_NAME; import static io.narayana.lra.LRAConstants.STATUS; import static io.narayana.lra.LRAConstants.TIMELIMIT_PARAM_NAME; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; import static javax.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE; import static javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE; @@ -54,6 +55,7 @@ import javax.enterprise.context.RequestScoped; import javax.ws.rs.NotFoundException; import javax.ws.rs.Path; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; @@ -64,8 +66,6 @@ import javax.ws.rs.core.Response; import io.narayana.lra.Current; -import io.narayana.lra.GenericLRAException; -import io.narayana.lra.IllegalLRAStateException; import org.eclipse.microprofile.lra.annotation.Compensate; import io.narayana.lra.logging.LRALogger; @@ -217,7 +217,7 @@ public void setCurrentLRA(URI coordinatorUri) { init(coordinatorUri); } catch (URISyntaxException | MalformedURLException e) { LRALogger.i18NLogger.error_invalidCoordinatorUrl(url, e); - throw new GenericLRAException(coordinatorUri, Response.Status.BAD_REQUEST.getStatusCode(), e.getMessage(), e); + throwGenericLRAException(coordinatorUri, BAD_REQUEST.getStatusCode(), e.getMessage()); } } @@ -226,9 +226,9 @@ public void setCurrentLRA(URI coordinatorUri) { * * @param clientID client id determining the LRA * @return LRA id as URL - * @throws GenericLRAException thrown when start of the LRA failed + * @throws WebApplicationException thrown when start of the LRA failed */ - public URI startLRA(String clientID) throws GenericLRAException { + public URI startLRA(String clientID) throws WebApplicationException { return startLRA(clientID, 0L); } @@ -239,17 +239,17 @@ public URI startLRA(String clientID) throws GenericLRAException { * @param clientID client id determining the LRA * @param timeout timeout value in seconds, when timeouted the LRA will be compensated * @return LRA id as URL - * @throws GenericLRAException thrown when start of the LRA failed + * @throws WebApplicationException thrown when start of the LRA failed */ - private URI startLRA(String clientID, Long timeout) throws GenericLRAException { + private URI startLRA(String clientID, Long timeout) throws WebApplicationException { return startLRA(clientID, timeout, ChronoUnit.SECONDS); } - private URI startLRA(String clientID, Long timeout, ChronoUnit unit) throws GenericLRAException { + private URI startLRA(String clientID, Long timeout, ChronoUnit unit) throws WebApplicationException { return startLRA(getCurrent(), clientID, timeout, unit); } - public URI startLRA(URI parentLRA, String clientID, Long timeout, ChronoUnit unit) throws GenericLRAException { + public URI startLRA(URI parentLRA, String clientID, Long timeout, ChronoUnit unit) throws WebApplicationException { Response response = null; URI lra; @@ -260,8 +260,9 @@ public URI startLRA(URI parentLRA, String clientID, Long timeout, ChronoUnit uni if (timeout == null) { timeout = 0L; } else if (timeout < 0) { - throw new GenericLRAException(parentLRA, Response.Status.BAD_REQUEST.getStatusCode(), - "Invalid timeout value: " + timeout, null); + throwGenericLRAException(parentLRA, BAD_REQUEST.getStatusCode(), + "Invalid timeout value: " + timeout); + return null; } lraTracef("startLRA for client %s with parent %s", clientID, parentLRA); @@ -281,8 +282,9 @@ public URI startLRA(URI parentLRA, String clientID, Long timeout, ChronoUnit uni // validate the HTTP status code says an LRAInfo resource was created if (isUnexpectedResponseStatus(response, Response.Status.CREATED)) { LRALogger.i18NLogger.error_lraCreationUnexpectedStatus(response.getStatus(), response); - throw new GenericLRAException(null, INTERNAL_SERVER_ERROR.getStatusCode(), - "LRA start returned an unexpected status code: " + response.getStatus(), null); + throwGenericLRAException(null, INTERNAL_SERVER_ERROR.getStatusCode(), + "LRA start returned an unexpected status code: " + response.getStatus()); + return null; } // validate that there is an LRAInfo response header holding the LRAInfo id @@ -290,7 +292,8 @@ public URI startLRA(URI parentLRA, String clientID, Long timeout, ChronoUnit uni if (lraObject == null) { LRALogger.i18NLogger.error_nullLraOnCreation(response); - throw new GenericLRAException(null, INTERNAL_SERVER_ERROR.getStatusCode(), "LRA creation is null", null); + throwGenericLRAException(null, INTERNAL_SERVER_ERROR.getStatusCode(), "LRA creation is null"); + return null; } lra = new URI(URLDecoder.decode(lraObject.toString(), "UTF-8")); @@ -301,31 +304,33 @@ public URI startLRA(URI parentLRA, String clientID, Long timeout, ChronoUnit uni } catch (UnsupportedEncodingException e) { LRALogger.i18NLogger.error_cannotCreateUrlFromLCoordinatorResponse(response, e); - throw new GenericLRAException(null, INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage(), e); + throwGenericLRAException(null, INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage()); + return null; } catch (Exception e) { LRALogger.i18NLogger.error_cannotContactLRACoordinator(base, e); if (e.getCause() != null && ConnectException.class.equals(e.getCause().getClass())) { - throw new GenericLRAException(null, SERVICE_UNAVAILABLE.getStatusCode(), - "Cannot connect to the LRA coordinator: " + base + " (" + e.getCause().getMessage() + ")", e); + throwGenericLRAException(null, SERVICE_UNAVAILABLE.getStatusCode(), + "Cannot connect to the LRA coordinator: " + base + " (" + e.getCause().getMessage() + ")"); + } else { + throwGenericLRAException(null, Response.Status.SERVICE_UNAVAILABLE.getStatusCode(), e.getMessage()); } - throw new GenericLRAException(null, Response.Status.SERVICE_UNAVAILABLE.getStatusCode(), e.getMessage(), e); + return null; } finally { releaseConnection(response); } // check that the lra is active // isActiveLRA(lra); - return lra; } - public void cancelLRA(URI lraId) throws GenericLRAException { + public void cancelLRA(URI lraId) throws WebApplicationException { endLRA(lraId, false); } - public void closeLRA(URI lraId) throws GenericLRAException { + public void closeLRA(URI lraId) throws WebApplicationException { endLRA(lraId, true); } @@ -339,18 +344,18 @@ public void closeLRA(URI lraId) throws GenericLRAException { * @param statusUri URI for reporting the status of the participant * @param compensatorData data provided during compensation * @return a recovery URL for this enlistment - * @throws GenericLRAException if the LRA coordinator failed to enlist the participant + * @throws WebApplicationException if the LRA coordinator failed to enlist the participant */ public URI joinLRA(URI lraId, Long timelimit, URI compensateUri, URI completeUri, URI forgetUri, URI leaveUri, URI statusUri, - String compensatorData) throws GenericLRAException { + String compensatorData) throws WebApplicationException { return enlistCompensator(lraId, timelimit, "", compensateUri, completeUri, forgetUri, leaveUri, statusUri, compensatorData); } - public void leaveLRA(URI lraId, String body) throws GenericLRAException { + public void leaveLRA(URI lraId, String body) throws WebApplicationException { Response response = null; try { @@ -363,7 +368,7 @@ public void leaveLRA(URI lraId, String body) throws GenericLRAException { if (Response.Status.OK.getStatusCode() != response.getStatus()) { LRALogger.i18NLogger.error_lraLeaveUnexpectedStatus(response.getStatus(), response); - throw new GenericLRAException(null, response.getStatus(), "", null); + throwGenericLRAException(null, response.getStatus(), ""); } } finally { releaseConnection(response); @@ -424,8 +429,11 @@ public static Map getTerminationUris(Class compensatorClass, if (asyncTermination[0] && !paths.containsKey(STATUS) && !paths.containsKey(FORGET)) { LRALogger.i18NLogger.error_asyncTerminationBeanMissStatusAndForget(compensatorClass); - throw new GenericLRAException(null, Response.Status.BAD_REQUEST.getStatusCode(), - "LRA participant class with asynchronous temination but no @Status or @Forget annotations", null); + + throw new WebApplicationException( + Response.status(BAD_REQUEST) + .entity("LRA participant class with asynchronous temination but no @Status or @Forget annotations") + .build()); } StringBuilder linkHeaderValue = new StringBuilder(); @@ -485,17 +493,18 @@ private static int checkMethod(Map paths, return 1; } - private LRAStatus getStatus(URI uri) throws GenericLRAException { + private LRAStatus getStatus(URI uri) throws WebApplicationException { Response response; URL lraId; try { lraId = uri.toURL(); } catch (MalformedURLException e) { - throw new GenericLRAException(null, + throwGenericLRAException(null, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), - "Could not convert LRA to a URL: " + e.getMessage(), - e); + "Could not convert LRA to a URL: " + e.getMessage() + ); + return null; } try { @@ -509,10 +518,11 @@ private LRAStatus getStatus(URI uri) throws GenericLRAException { releaseConnection(null); LRALogger.i18NLogger.error_cannotAccesCorrdinatorWhenGettingStatus(base, lraId, e); - throw new GenericLRAException(uri, + throwGenericLRAException(uri, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), - "Could not access the LRA coordinator: " + e.getMessage(), - e); + "Could not access the LRA coordinator: " + e.getMessage() + ); + return null; } try { @@ -528,17 +538,17 @@ private LRAStatus getStatus(URI uri) throws GenericLRAException { if (response.getStatus() != Response.Status.OK.getStatusCode()) { LRALogger.i18NLogger.error_invalidStatusCode(base, response.getStatus(), lraId); - throw new GenericLRAException(uri, + throwGenericLRAException(uri, response.getStatus(), - "LRA coordinator returned an invalid status code", - null); + "LRA coordinator returned an invalid status code" + ); } if (!response.hasEntity()) { LRALogger.i18NLogger.error_noContentOnGetStatus(base, lraId); - throw new GenericLRAException(uri, + throwGenericLRAException(uri, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), - "LRA coordinator#getStatus returned 200 OK but no content: lra: " + lraId, null); + "LRA coordinator#getStatus returned 200 OK but no content: lra: " + lraId); } // convert the returned String into a status @@ -546,10 +556,11 @@ private LRAStatus getStatus(URI uri) throws GenericLRAException { return fromString(response.readEntity(String.class)); } catch (IllegalArgumentException e) { LRALogger.i18NLogger.error_invalidArgumentOnStatusFromCoordinator(base, lraId, e); - throw new GenericLRAException(uri, + throwGenericLRAException(uri, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), - "LRA coordinator returned an invalid status", - e); + "LRA coordinator returned an invalid status" + ); + return null; } } finally { releaseConnection(response); @@ -622,10 +633,11 @@ private URI enlistCompensator(URI uri, long timelimit, String linkHeader, String try { lraId = uri.toURL(); } catch (MalformedURLException e) { - throw new GenericLRAException(null, + throwGenericLRAException(null, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), - "Could not convert LRA to a URL: " + e.getMessage(), - e); + "Could not convert LRA to a URL: " + e.getMessage() + ); + return null; } if (timelimit < 0) { timelimit = 0L; @@ -641,8 +653,7 @@ private URI enlistCompensator(URI uri, long timelimit, String linkHeader, String if (response.getStatus() == Response.Status.PRECONDITION_FAILED.getStatusCode()) { LRALogger.i18NLogger.error_tooLateToJoin(lraId, response); - throw new IllegalLRAStateException(lraId.toString(), - "Too late to join with this LRA", "enlistCompensator"); + throw new WebApplicationException(lraId + ": Too late to join with this LRA ", BAD_REQUEST); } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) { LRALogger.logger.infof("Failed enlisting to LRA '%s', coordinator '%s' responded with status '%s'", lraId, base, Response.Status.NOT_FOUND.getStatusCode()); @@ -650,8 +661,8 @@ private URI enlistCompensator(URI uri, long timelimit, String linkHeader, String } else if (response.getStatus() != Response.Status.OK.getStatusCode()) { LRALogger.i18NLogger.error_failedToEnlist(lraId, base, response.getStatus()); - throw new GenericLRAException(uri, response.getStatus(), - "unable to register participant", null); + throwGenericLRAException(uri, response.getStatus(), + "unable to register participant"); } try { @@ -659,8 +670,9 @@ private URI enlistCompensator(URI uri, long timelimit, String linkHeader, String return new URI(responseEntity); } catch (URISyntaxException e) { LRALogger.logger.infof("join %s returned an invalid recovery URI: %", lraId, responseEntity); - throw new GenericLRAException(null, Response.Status.SERVICE_UNAVAILABLE.getStatusCode(), - "join " + lraId + " returned an invalid recovery URI: " + responseEntity, e); + throwGenericLRAException(null, Response.Status.SERVICE_UNAVAILABLE.getStatusCode(), + "join " + lraId + " returned an invalid recovery URI: " + responseEntity); + return null; } } finally { @@ -668,7 +680,7 @@ private URI enlistCompensator(URI uri, long timelimit, String linkHeader, String } } - private void endLRA(URI lra, boolean confirm) throws GenericLRAException { + private void endLRA(URI lra, boolean confirm) throws WebApplicationException { String confirmUrl = String.format(confirm ? confirmFormat : compensateFormat, getLRAId(lra.toString())); Response response = null; @@ -679,8 +691,8 @@ private void endLRA(URI lra, boolean confirm) throws GenericLRAException { if (isUnexpectedResponseStatus(response, Response.Status.OK, Response.Status.ACCEPTED, Response.Status.NOT_FOUND)) { LRALogger.i18NLogger.error_lraTerminationUnexpectedStatus(response.getStatus(), response); - throw new GenericLRAException(lra, INTERNAL_SERVER_ERROR.getStatusCode(), - "LRA finished with an unexpected status code: " + response.getStatus(), null); + throwGenericLRAException(lra, INTERNAL_SERVER_ERROR.getStatusCode(), + "LRA finished with an unexpected status code: " + response.getStatus()); } if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) { @@ -709,16 +721,16 @@ private void endLRA(URI lra, boolean confirm) throws GenericLRAException { private void validateURI(URI uri, boolean nullAllowed, String message) { if (uri == null) { if (!nullAllowed) { - throw new GenericLRAException(null, NOT_ACCEPTABLE.getStatusCode(), - String.format(message, "null value"), null); + throwGenericLRAException(null, NOT_ACCEPTABLE.getStatusCode(), + String.format(message, "null value")); } } else { try { // the passed in URI should be a valid URL - verify that that is the case uri.toURL(); } catch (MalformedURLException e) { - throw new GenericLRAException(null, NOT_ACCEPTABLE.getStatusCode(), - String.format(message, e.getMessage()) + " uri=" + uri, e); + throwGenericLRAException(null, NOT_ACCEPTABLE.getStatusCode(), + String.format(message, e.getMessage()) + " uri=" + uri); } } } @@ -771,8 +783,8 @@ private void aquireConnection() { if (connectionInUse) { LRALogger.i18NLogger.error_cannotAquireInUseConnection(); - throw new GenericLRAException(null, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), - "NarayanaLRAClient: trying to aquire an in use connection", null); + throwGenericLRAException(null, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), + "NarayanaLRAClient: trying to aquire an in use connection"); } connectionInUse = true; @@ -785,4 +797,9 @@ private void releaseConnection(Response response) { connectionInUse = false; } + + private void throwGenericLRAException(URI lraId, int statusCode, String message) throws WebApplicationException { + throw new WebApplicationException(Response.status(statusCode) + .entity(String.format("%s: %s", lraId, message)).build()); + } } diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/Coordinator.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/Coordinator.java index a16ffb1f87..8667110841 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/Coordinator.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/Coordinator.java @@ -23,9 +23,6 @@ package io.narayana.lra.coordinator.api; import io.narayana.lra.Current; -import io.narayana.lra.GenericLRAException; -import io.narayana.lra.IllegalLRAStateException; -import io.narayana.lra.InvalidLRAIdException; import io.narayana.lra.coordinator.domain.model.LRAData; import io.narayana.lra.coordinator.domain.model.LRAStatusHolder; import io.narayana.lra.coordinator.domain.model.Transaction; @@ -84,6 +81,8 @@ import static io.narayana.lra.LRAConstants.TIMELIMIT_PARAM_NAME; import static java.util.stream.Collectors.toList; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; +import static javax.ws.rs.core.Response.Status.PRECONDITION_FAILED; import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_RECOVERY_HEADER; @@ -112,8 +111,8 @@ public List getAllLRAs( if (lras == null) { LRALogger.i18NLogger.error_invalidQueryForGettingLraStatuses(state); - throw new GenericLRAException(null, Response.Status.BAD_REQUEST.getStatusCode(), - String.format("Invalid query '%s' to get LRAs", state), null); + throw new WebApplicationException(Response.status(BAD_REQUEST) + .entity(String.format("Invalid query '%s' to get LRAs", state)).build()); } return lras.stream().map(Coordinator::convert).collect(toList()); @@ -238,7 +237,7 @@ public Response startLRA( @QueryParam(TIMELIMIT_PARAM_NAME) @DefaultValue("0") Long timelimit, @ApiParam(value = "The enclosing LRA if this new LRA is nested", required = false) @QueryParam(PARENT_LRA_PARAM_NAME) @DefaultValue("") String parentLRA, - @HeaderParam(LRA_HTTP_CONTEXT_HEADER) String parentId) throws WebApplicationException, InvalidLRAIdException { + @HeaderParam(LRA_HTTP_CONTEXT_HEADER) String parentId) throws WebApplicationException { URI parentLRAUrl = null; @@ -261,7 +260,7 @@ public Response startLRA( URLEncoder.encode(url.toString(), "UTF-8")); } catch (UnsupportedEncodingException | MalformedURLException e) { LRALogger.i18NLogger.error_invalidFormatToEncodeUrl(url, e); - throw new GenericLRAException(lraId, BAD_REQUEST.getStatusCode(), "Invalid parent LRA id", e); + throw new WebApplicationException("Invalid parent LRA id", e, BAD_REQUEST); } Response response; @@ -316,7 +315,9 @@ public Response getNestedLRAStatus(@PathParam("NestedLraId")String nestedLraId) if (status == null || lra.getLRAStatus() == null) { LRALogger.i18NLogger.error_cannotGetStatusOfNestedLraURI(nestedLraId, lra.getId()); - throw new IllegalLRAStateException(nestedLraId, "The LRA is still active", "getNestedLRAStatus"); + throw new WebApplicationException(Response.status(Response.Status.PRECONDITION_FAILED) + .entity(String.format("LRA is in the wrong state for operation '%s': %s", + "getNestedLRAStatus", "The LRA is still active")).build()); } return Response.ok(lra.getLRAStatus().name()).build(); @@ -455,7 +456,7 @@ public Response joinLRAViaBody( lraId, compensatorData); } - return Response.status(Response.Status.PRECONDITION_FAILED).build(); + return Response.status(PRECONDITION_FAILED).build(); } // register with the coordinator @@ -514,7 +515,7 @@ private Response joinLRA(URI lraId, long timeLimit, String compensatorUrl, Strin .build(); } catch (URISyntaxException e) { LRALogger.i18NLogger.error_invalidRecoveryUrlToJoinLRAURI(recoveryUrl.toString(), lraId); - throw new GenericLRAException(lraId, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Invalid recovery URL", e); + throw new WebApplicationException("Invalid recovery URL", e, INTERNAL_SERVER_ERROR); } } @@ -561,7 +562,7 @@ private URI toURI(String lraId, String message) { url = new URL(String.format("%s%s/%s", context.getBaseUri(), COORDINATOR_PATH_NAME, lraId)); } catch (MalformedURLException e1) { LRALogger.i18NLogger.error_invalidStringFormatOfUrl(lraId, e1); - throw new InvalidLRAIdException(lraId, message, e1); + throw new WebApplicationException(message, e1, BAD_REQUEST); } } @@ -569,7 +570,7 @@ private URI toURI(String lraId, String message) { return url.toURI(); } catch (URISyntaxException e) { LRALogger.i18NLogger.error_invalidStringFormatOfUrl(lraId, e); - throw new InvalidLRAIdException(lraId, message, e); + throw new WebApplicationException(message, e, BAD_REQUEST); } } } diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/CoordinatorContainerFilter.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/CoordinatorContainerFilter.java index 9a613b96d1..1fdb6e4bf9 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/CoordinatorContainerFilter.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/CoordinatorContainerFilter.java @@ -22,8 +22,8 @@ package io.narayana.lra.coordinator.api; import io.narayana.lra.Current; -import io.narayana.lra.GenericLRAException; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.ContainerResponseContext; @@ -35,6 +35,7 @@ import java.net.URI; import java.net.URISyntaxException; +import static javax.ws.rs.core.Response.Status.PRECONDITION_FAILED; import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; @Provider @@ -51,7 +52,8 @@ public void filter(ContainerRequestContext requestContext) throws IOException { String msg = String.format("header %s contains an invalid URL %s", LRA_HTTP_CONTEXT_HEADER, Current.getLast(headers.get(LRA_HTTP_CONTEXT_HEADER))); - throw new GenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), msg, e); + throw new WebApplicationException(Response.status(PRECONDITION_FAILED.getStatusCode()) + .entity(String.format("%s: %s", msg, e.getMessage())).build()); } } diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/RecoveryCoordinator.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/RecoveryCoordinator.java index b679632125..991dc4a6fa 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/RecoveryCoordinator.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/api/RecoveryCoordinator.java @@ -21,7 +21,6 @@ */ package io.narayana.lra.coordinator.api; -import io.narayana.lra.GenericLRAException; import io.narayana.lra.coordinator.domain.model.LRAStatusHolder; import io.narayana.lra.coordinator.domain.service.LRAService; import io.narayana.lra.logging.LRALogger; @@ -40,6 +39,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -49,6 +49,7 @@ import java.util.List; import static io.narayana.lra.LRAConstants.RECOVERY_COORDINATOR_PATH_NAME; +import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; @ApplicationScoped @Path(RECOVERY_COORDINATOR_PATH_NAME) @@ -119,7 +120,9 @@ public String replaceCompensator( lra = new URI(lraId); } catch (URISyntaxException e) { LRALogger.i18NLogger.error_invalidFormatOfLraIdReplacingCompensatorURI(lraId, compensatorUrl, e); - throw new GenericLRAException(null, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e.getMessage(), e); + + throw new WebApplicationException(Response.status(INTERNAL_SERVER_ERROR.getStatusCode()) + .entity(String.format("%s: %s", lraId, e.getMessage())).build()); } lraService.updateRecoveryURI(lra, newCompensatorUrl, rcvCoordId, true); diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LRARecord.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LRARecord.java index 7572d72c95..cdc4be6fa7 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LRARecord.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LRARecord.java @@ -29,13 +29,12 @@ import com.arjuna.ats.arjuna.state.OutputObjectState; import io.narayana.lra.Current; -import io.narayana.lra.GenericLRAException; -import io.narayana.lra.InvalidLRAIdException; import io.narayana.lra.coordinator.domain.service.LRAService; import io.narayana.lra.logging.LRALogger; import org.eclipse.microprofile.lra.annotation.LRAStatus; import org.eclipse.microprofile.lra.annotation.ParticipantStatus; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; @@ -59,6 +58,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.PRECONDITION_FAILED; import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER; import static org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_RECOVERY_HEADER; @@ -106,9 +107,9 @@ public LRARecord() { }); if (parseException[0] != null) { - throw new InvalidLRAIdException(lraId, "Invalid link URI", parseException[0]); + throw new WebApplicationException(lraId + ": Invalid link URI: " + parseException[0], BAD_REQUEST); } else if (compensateURI == null) { - throw new InvalidLRAIdException(lraId, "Invalid link URI: missing compensator"); + throw new WebApplicationException(lraId + ": Invalid link URI: missing compensator", BAD_REQUEST); } } else { this.compensateURI = new URI(String.format("%s/compensate", linkURI)); @@ -126,7 +127,7 @@ public LRARecord() { this.compensatorData = compensatorData; } catch (URISyntaxException e) { LRALogger.i18NLogger.error_invalidFormatToCreateLRARecord(lraId, linkURI); - throw new InvalidLRAIdException(lraId, "Invalid LRA id", e); + throw new WebApplicationException(lraId + ": Invalid LRA id: " + e.getMessage(), BAD_REQUEST); } } @@ -163,8 +164,8 @@ static String extractCompensator(URI lraId, String linkStr) { try { link = Link.valueOf(lnk); } catch (Exception e) { - throw new GenericLRAException(lraId, Response.Status.PRECONDITION_FAILED.getStatusCode(), - String.format("Invalid compensator join request: cannot parse link '%s'", linkStr), e); + throw new WebApplicationException(Response.status(PRECONDITION_FAILED.getStatusCode()) + .entity(String.format("Invalid compensator join request: cannot parse link '%s'", linkStr)).build()); } if (COMPENSATE_REL.equals(link.getRel())) { @@ -461,7 +462,7 @@ private int retryGetEndStatus(URI endPath, boolean compensate) { // if the attempt times out the catch block below will return a heuristic Response response = asyncResponse.get(PARTICIPANT_TIMEOUT, TimeUnit.SECONDS); - if (response.getStatus() == Response.Status.PRECONDITION_FAILED.getStatusCode()) { + if (response.getStatus() == PRECONDITION_FAILED.getStatusCode()) { // the participant never got the end request resend it return -1; } @@ -586,7 +587,7 @@ private int tryLocalEndInvocation(URI endPath) { endPath.toASCIIString()); } - httpStatus = Response.Status.BAD_REQUEST.getStatusCode(); + httpStatus = BAD_REQUEST.getStatusCode(); } else { LRAStatusHolder inVMStatus = lraService.endLRA(cId, isCompensate, true); @@ -804,7 +805,7 @@ void setRecoveryURI(String recoveryURI) { try { this.recoveryURI = new URI(recoveryURI); } catch (URISyntaxException e) { - throw new InvalidLRAIdException(recoveryURI, "Invalid recovery id", e); + throw new WebApplicationException(recoveryURI + ": Invalid recovery id: " + e.getMessage(), BAD_REQUEST); } } diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/Transaction.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/Transaction.java index c1d50d0829..cef179662b 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/Transaction.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/Transaction.java @@ -30,7 +30,6 @@ import com.arjuna.ats.arjuna.coordinator.RecordList; import com.arjuna.ats.arjuna.coordinator.RecordListIterator; import com.arjuna.ats.arjuna.coordinator.RecordType; -import io.narayana.lra.InvalidLRAIdException; import io.narayana.lra.logging.LRALogger; import com.arjuna.ats.arjuna.state.InputObjectState; import com.arjuna.ats.arjuna.state.OutputObjectState; @@ -39,6 +38,7 @@ import io.narayana.lra.coordinator.domain.service.LRAService; import org.eclipse.microprofile.lra.annotation.LRAStatus; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -731,7 +731,7 @@ public void updateRecoveryURI(String compensatorUri, String recoveryUri) { } } - } catch (InvalidLRAIdException e) { + } catch (WebApplicationException e) { if (LRALogger.logger.isInfoEnabled()) { LRALogger.logger.infof("Could not save new recovery URL: %s", e.getMessage()); } diff --git a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java index 5dfa32068e..5dcc2fcb8b 100644 --- a/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java +++ b/rts/lra/lra-coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java @@ -23,8 +23,6 @@ import com.arjuna.ats.arjuna.AtomicAction; import com.arjuna.ats.arjuna.coordinator.ActionStatus; -import io.narayana.lra.IllegalLRAStateException; -import io.narayana.lra.InvalidLRAIdException; import io.narayana.lra.coordinator.domain.model.LRAData; import io.narayana.lra.logging.LRALogger; import com.arjuna.ats.arjuna.recovery.RecoveryManager; @@ -43,6 +41,7 @@ import javax.enterprise.event.Observes; import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.NotFoundException; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import java.io.UnsupportedEncodingException; import java.net.URI; @@ -195,7 +194,8 @@ public synchronized URI startLRA(String baseUri, URI parentLRA, String clientId, try { lra = new Transaction(this, baseUri, parentLRA, clientId); } catch (URISyntaxException e) { - throw new InvalidLRAIdException(baseUri, "Invalid base uri", e); + throw new WebApplicationException(e, Response.status(Response.Status.PRECONDITION_FAILED) + .entity(String.format("Invalid base URI: '%s'", baseUri)).build()); } if (lra.currentLRA() != null) { @@ -232,7 +232,8 @@ public LRAStatusHolder endLRA(URI lraId, boolean compensate, boolean fromHierarc Transaction transaction = getTransaction(lraId); if (!transaction.isActive() && !transaction.isRecovering() && transaction.isTopLevel()) { - throw new IllegalLRAStateException(lraId.toString(), "LRA is closing or closed", "endLRA"); + throw new WebApplicationException(Response.status(Response.Status.PRECONDITION_FAILED) + .entity(String.format("%s: LRA is closing or closed: endLRA", lraId)).build()); } transaction.end(compensate); diff --git a/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ServerLRAFilter.java b/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ServerLRAFilter.java index b675bd246a..6f34aedf99 100644 --- a/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ServerLRAFilter.java +++ b/rts/lra/lra-filters/src/main/java/io/narayana/lra/filter/ServerLRAFilter.java @@ -22,8 +22,6 @@ package io.narayana.lra.filter; import io.narayana.lra.Current; -import io.narayana.lra.GenericLRAException; -import io.narayana.lra.IllegalLRAStateException; import io.narayana.lra.client.NarayanaLRAClient; import io.narayana.lra.logging.LRALogger; import org.eclipse.microprofile.lra.annotation.Compensate; @@ -119,11 +117,11 @@ public ServerLRAFilter() throws Exception { private void checkForTx(LRA.Type type, URI lraId, boolean shouldNotBeNull) { if (lraId == null && shouldNotBeNull) { - throw new GenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), - type.name() + " but no tx", null); + throwGenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), + type.name() + " but no tx"); } else if (lraId != null && !shouldNotBeNull) { - throw new GenericLRAException(lraId, Response.Status.PRECONDITION_FAILED.getStatusCode(), - type.name() + " but found tx", null); + throwGenericLRAException(lraId, Response.Status.PRECONDITION_FAILED.getStatusCode(), + type.name() + " but found tx"); } } @@ -176,7 +174,7 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc String msg = String.format("header %s contains an invalid URL %s", LRA_HTTP_CONTEXT_HEADER, Current.getLast(headers.get(LRA_HTTP_CONTEXT_HEADER))); - throw new GenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), msg, e); + throwGenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), msg); } } @@ -238,8 +236,8 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc if (nested) { // nested does not make sense - throw new GenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), - type.name() + " but found Nested annnotation", null); + throwGenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), + type.name() + " but found Nested annnotation"); } enlist = false; @@ -249,8 +247,8 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc case NOT_SUPPORTED: if (nested) { // nested does not make sense - throw new GenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), - type.name() + " but found Nested annnotation", null); + throwGenericLRAException(null, Response.Status.PRECONDITION_FAILED.getStatusCode(), + type.name() + " but found Nested annnotation"); } enlist = false; @@ -359,17 +357,16 @@ public void filter(ContainerRequestContext containerRequestContext) throws IOExc toURI(terminateURIs.get(LEAVE)), toURI(terminateURIs.get(STATUS)), null); - } catch (IllegalLRAStateException e) { - lraTrace(containerRequestContext, lraId, "ServerLRAFilter before: aborting with " + e.getMessage()); - throw e; } catch (NotFoundException e) { throw e; } catch (WebApplicationException e) { lraTrace(containerRequestContext, lraId, "ServerLRAFilter before: aborting with " + e.getMessage()); - throw new GenericLRAException(lraId, e.getResponse().getStatus(), e.getMessage(), e); + throw e; } catch (URISyntaxException e) { lraTrace(containerRequestContext, lraId, "ServerLRAFilter before: aborting with " + e.getMessage()); - throw new GenericLRAException(lraId, Response.Status.BAD_REQUEST.getStatusCode(), e.getMessage(), e); + + throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST) + .entity(String.format("%s: %s", lraId, e.getMessage())).build()); } headers.putSingle(LRA_HTTP_RECOVERY_HEADER, recoveryUrl.toASCIIString().replaceAll("^\"|\"$", "")); @@ -491,8 +488,8 @@ private String getCompensatorId(URI lraId, URI baseUri) { Map terminateURIs = NarayanaLRAClient.getTerminationUris(resourceInfo.getResourceClass(), baseUri); if (!terminateURIs.containsKey("Link")) { - throw new GenericLRAException(lraId, Response.Status.BAD_REQUEST.getStatusCode(), - "Missing complete or compensate annotations", null); + throwGenericLRAException(lraId, Response.Status.BAD_REQUEST.getStatusCode(), + "Missing complete or compensate annotations"); } return terminateURIs.get("Link"); @@ -512,4 +509,9 @@ private void lraWarn(ContainerRequestContext context, URI lraId, String reason) LRALogger.i18NLogger.warn_lraFilterContainerRequest(reason, method.getDeclaringClass().getName() + "#" + method.getName(), lraId == null ? "context" : lraId.toString()); } + + private void throwGenericLRAException(URI lraId, int statusCode, String message) throws WebApplicationException { + throw new WebApplicationException(Response.status(statusCode) + .entity(String.format("%s: %s", lraId, message)).build()); + } } diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/GenericLRAException.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/GenericLRAException.java deleted file mode 100644 index fab52a7d8b..0000000000 --- a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/GenericLRAException.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - ******************************************************************************* - * Copyright (c) 2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ - -package io.narayana.lra; - -import javax.ws.rs.WebApplicationException; -import java.net.URI; - -public class GenericLRAException extends WebApplicationException { - private static final long serialVersionUID = 1L; - - private URI lraId; - private int statusCode; - - public int getStatusCode() { - return statusCode; - } - - public URI getLraId() { - return lraId; - } - - public GenericLRAException(URI lraId, int statusCode, String message, - Throwable cause) { - super(String.format("%s: %s", lraId, message), cause); - - this.lraId = lraId; - this.statusCode = statusCode; - } -} diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/IllegalLRAStateException.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/IllegalLRAStateException.java deleted file mode 100644 index f55ed83e75..0000000000 --- a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/IllegalLRAStateException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - ******************************************************************************* - * Copyright (c) 2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package io.narayana.lra; - -import javax.ws.rs.WebApplicationException; - -public class IllegalLRAStateException extends WebApplicationException { - private final String lraId; - private final String operation; - - /** - * Creation of LRA state exception. - * - * @param lraId LRA id that is behind this exception - * @param operation the java method that generated the exception - * @param message error message of this exception - */ - public IllegalLRAStateException(String lraId, String operation, String message) { - super(String.format("%s, lra id: %s", message, lraId)); - - this.lraId = lraId; - this.operation = operation; - } - - public String getLraId() { - return this.lraId; - } - - public String getOperation() { - return this.operation; - } -} diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/InvalidLRAIdException.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/InvalidLRAIdException.java deleted file mode 100644 index b9c7e2392e..0000000000 --- a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/InvalidLRAIdException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - ******************************************************************************* - * Copyright (c) 2018 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package io.narayana.lra; - -import javax.ws.rs.WebApplicationException; - -public class InvalidLRAIdException extends WebApplicationException { - private static final long serialVersionUID = 1271422145863321852L; - private final String lraId; - - /** - * Invalid LRA id exception. - * - * @param lraId LRA id that is behind this exception - * @param message error message of this exception - * @param cause cause exception - */ - public InvalidLRAIdException(String lraId, String message, Throwable cause) { - super(String.format("%s, LRA id: %s", message, lraId), cause); - - this.lraId = lraId; - } - - /** - * Invalid LRA id exception. - * - * @param lraId LRA id that is behind this exception - * @param message error message of this exception - */ - public InvalidLRAIdException(String lraId, String message) { - super(String.format("%s, LRA id: %s", message, lraId)); - - this.lraId = lraId; - } - - public String getLraId() { - return this.lraId; - } -} diff --git a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/UnknowableException.java b/rts/lra/lra-service-base/src/main/java/io/narayana/lra/UnknowableException.java deleted file mode 100644 index 739a6f20e5..0000000000 --- a/rts/lra/lra-service-base/src/main/java/io/narayana/lra/UnknowableException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - ******************************************************************************* - * Copyright (c) 2019 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * You may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ -package io.narayana.lra; - -import java.net.URI; - -/** - * An exception type to indicate that a requested operation can never be completed. - */ -public class UnknowableException extends GenericLRAException { - public UnknowableException(URI lraId, int statusCode, String message, Throwable cause) { - super(lraId, statusCode, message, cause); - } -} diff --git a/rts/lra/lra-test/tck/src/test/java/io/narayana/lra/tck/arquillian/ConfigAuxiliaryArchiveAppender.java b/rts/lra/lra-test/tck/src/test/java/io/narayana/lra/tck/arquillian/ConfigAuxiliaryArchiveAppender.java index bcb3dae73b..dcf1e3e5f4 100644 --- a/rts/lra/lra-test/tck/src/test/java/io/narayana/lra/tck/arquillian/ConfigAuxiliaryArchiveAppender.java +++ b/rts/lra/lra-test/tck/src/test/java/io/narayana/lra/tck/arquillian/ConfigAuxiliaryArchiveAppender.java @@ -40,7 +40,6 @@ public Archive createAuxiliaryArchive() { JavaArchive archive = ShrinkWrap.create(JavaArchive.class) // adding LRA spec interfaces under the WildFly Swarm deployment .addPackages(true, org.eclipse.microprofile.lra.annotation.Compensate.class.getPackage()) - .addPackages(true, io.narayana.lra.InvalidLRAIdException.class.getPackage()) .addPackages(true, org.eclipse.microprofile.lra.participant.LRAParticipant.class.getPackage()); // adding Narayana LRA implementation under the WildFly Swarm deployment archive.addPackages(true, io.narayana.lra.client.NarayanaLRAClient.class.getPackage())