Search in sources :

Example 11 with LRAStatus

use of org.eclipse.microprofile.lra.annotation.LRAStatus in project narayana by jbosstm.

the class LRAParticipantRecord method retryGetEndStatus.

private int retryGetEndStatus(URI endPath, boolean compensate) {
    assert accepted;
    // the participant has previously returned a HTTP 202 Accepted response so the status URI
    // must be valid - try that first for the status
    // first check that this isn't a nested coordinator running locally
    URI nestedLraId = extractParentLRA(endPath);
    trace_progress("retryGetEndStatus");
    if (nestedLraId != null && lraService != null) {
        LongRunningAction transaction = lraService.getTransaction(nestedLraId);
        if (transaction != null) {
            LRAStatus cStatus = transaction.getLRAStatus();
            trace_progress("retryGetEndStatus: local status " + cStatus);
            if (cStatus == null) {
                LRALogger.logger.warnf("LRAParticipantRecord.retryGetEndStatus: local LRA %s accepted but has a null status", endPath);
                // shouldn't happen since it imples it's still be active - force end to be called
                return -1;
            }
            switch(cStatus) {
                case Closed:
                case Cancelled:
                    return TwoPhaseOutcome.FINISH_OK;
                case Closing:
                case Cancelling:
                    return TwoPhaseOutcome.HEURISTIC_HAZARD;
                case FailedToClose:
                case FailedToCancel:
                    return reportFailure(compensate, endPath, "unknown");
                default:
                    return TwoPhaseOutcome.HEURISTIC_HAZARD;
            }
        }
    } else if (statusURI != null) {
        // it is a standard participant - check the status URI
        Response response;
        Client client = null;
        try {
            // since this method is called from the recovery thread do not block
            client = ClientBuilder.newClient();
            response = // .path(getLRAId(lraId))
            client.target(statusURI).request().header(LRA_HTTP_CONTEXT_HEADER, lraId.toASCIIString()).header(LRA_HTTP_RECOVERY_HEADER, recoveryURI.toASCIIString()).header(LRA_HTTP_PARENT_CONTEXT_HEADER, parentId).async().get().get(PARTICIPANT_TIMEOUT, // if the attempt times out the catch block below will return a heuristic
            TimeUnit.SECONDS);
            // 200 and 410 are the only valid response code for reporting the participant status
            if (response.getStatus() == Response.Status.GONE.getStatusCode()) {
                /*
                     * The specification states (in section 3.2.10. Reporting the status of a participant):
                     * If the participant has already responded successfully to an @Compensate or @Complete method
                     * invocation then it MAY report 410 Gone HTTP status code
                     *
                     * This means that if the participant was asked to compensate then it has now compensated, or
                     * if the participant was asked to complete then it has now completed.
                     */
                status = compensate ? ParticipantStatus.Compensated : ParticipantStatus.Completed;
                return TwoPhaseOutcome.FINISH_OK;
            } else if (response.getStatus() == Response.Status.ACCEPTED.getStatusCode() || Response.Status.Family.familyOf(response.getStatus()).equals(Response.Status.Family.SERVER_ERROR)) {
                // these response codes indicate that the implementation should retry later
                return TwoPhaseOutcome.HEURISTIC_HAZARD;
            } else if (response.getStatus() == Response.Status.OK.getStatusCode() && response.hasEntity()) {
                // the participant is available again and has reported its status
                status = ParticipantStatus.valueOf(response.readEntity(String.class));
                switch(status) {
                    case Completed:
                    case Compensated:
                        return TwoPhaseOutcome.FINISH_OK;
                    case Completing:
                    case Compensating:
                        // still in progress - make sure recovery keeps retrying it
                        return TwoPhaseOutcome.HEURISTIC_HAZARD;
                    case FailedToCompensate:
                    case FailedToComplete:
                        // the participant could not finish - log a warning and forget
                        LRALogger.logger.warnf("LRAParticipantRecord.doEnd(compensate %b) get status %s did not finish: %s: WILL NOT RETRY", compensate, endPath, status);
                        if (forgetURI != null) {
                            if (!forget()) {
                                // we will retry the forget on the next recovery cycle
                                return TwoPhaseOutcome.HEURISTIC_HAZARD;
                            }
                        }
                        return reportFailure(compensate, endPath, "Unknown");
                    default:
                        return TwoPhaseOutcome.HEURISTIC_HAZARD;
                }
            }
        } catch (Throwable e) {
            if (LRALogger.logger.isInfoEnabled()) {
                LRALogger.logger.infof("LRAParticipantRecord.doEnd status URI %s is invalid (%s)", statusURI, e.getMessage());
            }
            // force recovery to keep retrying
            return TwoPhaseOutcome.HEURISTIC_HAZARD;
        } finally {
            trace_progress("retryGetEndStatus");
            Current.pop();
            if (client != null) {
                client.close();
            }
        }
    }
    return -1;
}
Also used : Response(javax.ws.rs.core.Response) LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) Client(javax.ws.rs.client.Client) URI(java.net.URI)

Example 12 with LRAStatus

use of org.eclipse.microprofile.lra.annotation.LRAStatus in project narayana by jbosstm.

the class Coordinator method getNestedLRAStatus.

@GET
@Path("nested/{NestedLraId}/status")
public Response getNestedLRAStatus(@PathParam("NestedLraId") String nestedLraId) {
    if (!lraService.hasTransaction(nestedLraId)) {
        // it must have compensated
        return Response.ok(ParticipantStatus.Compensated.name()).build();
    }
    LongRunningAction lra = lraService.getTransaction(toURI(nestedLraId));
    LRAStatus status = lra.getLRAStatus();
    if (status == null || lra.getLRAStatus() == null) {
        String logMsg = LRALogger.i18nLogger.error_cannotGetStatusOfNestedLraURI(nestedLraId, lra.getId());
        LRALogger.logger.debug(logMsg);
        throw new WebApplicationException(logMsg, Response.status(Response.Status.PRECONDITION_FAILED).entity(logMsg).build());
    }
    return Response.ok(mapToParticipantStatus(lra.getLRAStatus()).name()).build();
}
Also used : LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) WebApplicationException(javax.ws.rs.WebApplicationException) LongRunningAction(io.narayana.lra.coordinator.domain.model.LongRunningAction) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 13 with LRAStatus

use of org.eclipse.microprofile.lra.annotation.LRAStatus in project narayana by jbosstm.

the class LRARecoveryModule method getFailedLRAs.

public void getFailedLRAs(Map<URI, LongRunningAction> lras) {
    InputObjectState aa_uids = new InputObjectState();
    Consumer<Uid> failedLRACreator = uid -> {
        FailedLongRunningAction lra = new FailedLongRunningAction(service, new Uid(uid));
        lra.activate();
        LRAStatus status = lra.getLRAStatus();
        if (LRAStatus.FailedToCancel.equals(status) || LRAStatus.FailedToClose.equals(status)) {
            lras.put(lra.getId(), lra);
        }
    };
    if (getUids(FailedLongRunningAction.FAILED_LRA_TYPE, aa_uids)) {
        forEach(aa_uids, failedLRACreator, FailedLongRunningAction.FAILED_LRA_TYPE);
    }
}
Also used : StateStatus(com.arjuna.ats.arjuna.objectstore.StateStatus) RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) LRAService(io.narayana.lra.coordinator.domain.service.LRAService) Collection(java.util.Collection) TransactionStatusConnectionManager(com.arjuna.ats.arjuna.recovery.TransactionStatusConnectionManager) FailedLongRunningAction(io.narayana.lra.coordinator.domain.model.FailedLongRunningAction) IOException(java.io.IOException) LongRunningAction(io.narayana.lra.coordinator.domain.model.LongRunningAction) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException) Uid(com.arjuna.ats.arjuna.common.Uid) ArrayList(java.util.ArrayList) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Consumer(java.util.function.Consumer) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) Map(java.util.Map) com.arjuna.ats.arjuna.common.recoveryPropertyManager(com.arjuna.ats.arjuna.common.recoveryPropertyManager) LRALogger(io.narayana.lra.logging.LRALogger) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) StoreManager(com.arjuna.ats.arjuna.objectstore.StoreManager) URI(java.net.URI) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Uid(com.arjuna.ats.arjuna.common.Uid) LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) FailedLongRunningAction(io.narayana.lra.coordinator.domain.model.FailedLongRunningAction)

Example 14 with LRAStatus

use of org.eclipse.microprofile.lra.annotation.LRAStatus in project narayana by jbosstm.

the class LRATest method assertStatus.

private void assertStatus(String message, URI lraId, LRAStatus... expectedValues) {
    LRAStatus status = getStatus(lraId);
    assertTrue(message + ": LRA status: " + status, Arrays.stream(expectedValues).anyMatch(s -> s == status));
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) AfterLRA(org.eclipse.microprofile.lra.annotation.AfterLRA) LRAService(io.narayana.lra.coordinator.domain.service.LRAService) URISyntaxException(java.net.URISyntaxException) Path(javax.ws.rs.Path) COORDINATOR_PATH_NAME(io.narayana.lra.LRAConstants.COORDINATOR_PATH_NAME) Application(javax.ws.rs.core.Application) com.arjuna.ats.arjuna.common.arjPropertyManager(com.arjuna.ats.arjuna.common.arjPropertyManager) ParticipantStatusOctetStreamProvider(io.narayana.lra.provider.ParticipantStatusOctetStreamProvider) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) UndertowJaxrsServer(org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) DELETE(javax.ws.rs.DELETE) ServerLRAFilter(io.narayana.lra.filter.ServerLRAFilter) Forget(org.eclipse.microprofile.lra.annotation.Forget) LRA_HTTP_RECOVERY_HEADER(org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_RECOVERY_HEADER) Set(java.util.Set) Entity(javax.ws.rs.client.Entity) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) NarayanaLRAClient(io.narayana.lra.client.NarayanaLRAClient) Response(javax.ws.rs.core.Response) Assert.assertFalse(org.junit.Assert.assertFalse) WebApplicationException(javax.ws.rs.WebApplicationException) Complete(org.eclipse.microprofile.lra.annotation.Complete) Link(javax.ws.rs.core.Link) IntStream(java.util.stream.IntStream) LRA_HTTP_CONTEXT_HEADER(org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER) BeforeClass(org.junit.BeforeClass) GET(javax.ws.rs.GET) Client(javax.ws.rs.client.Client) HashSet(java.util.HashSet) LRARecoveryModule(io.narayana.lra.coordinator.internal.LRARecoveryModule) ClientBuilder(javax.ws.rs.client.ClientBuilder) TestName(org.junit.rules.TestName) StringTokenizer(java.util.StringTokenizer) Coordinator(io.narayana.lra.coordinator.api.Coordinator) LRA_HTTP_PARENT_CONTEXT_HEADER(org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_PARENT_CONTEXT_HEADER) Before(org.junit.Before) ParticipantStatus(org.eclipse.microprofile.lra.annotation.ParticipantStatus) TestPortProvider(org.jboss.resteasy.test.TestPortProvider) Assert.assertNotNull(org.junit.Assert.assertNotNull) ApplicationPath(javax.ws.rs.ApplicationPath) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) File(java.io.File) LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) Rule(org.junit.Rule) ChronoUnit(java.time.temporal.ChronoUnit) Assert.assertNull(org.junit.Assert.assertNull) LRA(org.eclipse.microprofile.lra.annotation.ws.rs.LRA) Compensate(org.eclipse.microprofile.lra.annotation.Compensate) LRALogger(io.narayana.lra.logging.LRALogger) PUT(javax.ws.rs.PUT) WebTarget(javax.ws.rs.client.WebTarget) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus)

Example 15 with LRAStatus

use of org.eclipse.microprofile.lra.annotation.LRAStatus in project narayana by jbosstm.

the class LRATest method runLRA.

private void runLRA(boolean cancel) {
    URI parentId = lraClient.startLRA("parent");
    URI childId = lraClient.startLRA(parentId, "child", 0L, ChronoUnit.SECONDS);
    // enlist a participant with the child
    enlistParticipant(childId.toASCIIString().split("\\?")[0]);
    // enlist a participant with the parent
    enlistParticipant(parentId.toASCIIString().split("\\?")[0]);
    if (cancel)
        lraClient.cancelLRA(parentId);
    else
        lraClient.closeLRA(parentId);
    assertEquals("parent and child should both have finished", 2, cancel ? compensateCount.get() : completeCount.get());
    LRAStatus pStatus = getStatus(parentId);
    LRAStatus cStatus = getStatus(childId);
    assertTrue("parent LRA finished in wrong state", pStatus == null || pStatus == (cancel ? LRAStatus.Cancelled : LRAStatus.Closed));
    assertTrue("child LRA finished in wrong state", cStatus == null || cStatus == (cancel ? LRAStatus.Cancelled : LRAStatus.Closed));
}
Also used : LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) URI(java.net.URI)

Aggregations

LRAStatus (org.eclipse.microprofile.lra.annotation.LRAStatus)17 URI (java.net.URI)12 Test (org.junit.Test)6 Path (javax.ws.rs.Path)5 GET (javax.ws.rs.GET)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 Response (javax.ws.rs.core.Response)4 LongRunningAction (io.narayana.lra.coordinator.domain.model.LongRunningAction)3 URISyntaxException (java.net.URISyntaxException)3 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)2 LRAData (io.narayana.lra.LRAData)2 LRAService (io.narayana.lra.coordinator.domain.service.LRAService)2 LRALogger (io.narayana.lra.logging.LRALogger)2 IOException (java.io.IOException)2 DELETE (javax.ws.rs.DELETE)2 NotFoundException (javax.ws.rs.NotFoundException)2 Produces (javax.ws.rs.Produces)2 Client (javax.ws.rs.client.Client)2 Operation (org.eclipse.microprofile.openapi.annotations.Operation)2 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)2