Search in sources :

Example 6 with LRAStatus

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

the class LRATest method testTimeout.

@Test
public void testTimeout() throws URISyntaxException {
    int compensations = compensateCount.get();
    String lraId = client.target(TestPortProvider.generateURL("/base/test/time-limit")).request().get(String.class);
    assertEquals(compensations + 1, compensateCount.get());
    LRAStatus status = getStatus(new URI(lraId));
    assertTrue("LRA should have cancelled", status == null || status == LRAStatus.Cancelled);
}
Also used : LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) URI(java.net.URI) Test(org.junit.Test)

Example 7 with LRAStatus

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

the class LRATest method testComplete.

/**
 * sanity check: test that an LRA that closes is reported as closed or absent
 */
@Test
public void testComplete() throws URISyntaxException {
    // verify that the participant complete request is issued when a method annotated with @LRA returns
    int completions = completeCount.get();
    String lraId = client.target(TestPortProvider.generateURL("/base/test/start-end")).request().get(String.class);
    assertEquals(completions + 1, completeCount.get());
    LRAStatus status = getStatus(new URI(lraId));
    assertTrue("LRA should have closed", status == null || status == LRAStatus.Closed);
}
Also used : LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) URI(java.net.URI) Test(org.junit.Test)

Example 8 with LRAStatus

use of org.eclipse.microprofile.lra.annotation.LRAStatus in project helidon by oracle.

the class NonJaxRsResource method createNonJaxRsParticipantResource.

Service createNonJaxRsParticipantResource() {
    return rules -> rules.any("/{type}/{fqdn}/{methodName}", (req, res) -> {
        LOGGER.log(Level.FINE, () -> "Non JAX-RS LRA resource " + req.method().name() + " " + req.absoluteUri());
        RequestHeaders headers = req.headers();
        HttpRequest.Path path = req.path();
        URI lraId = headers.first(LRA_HTTP_CONTEXT_HEADER).or(() -> headers.first(LRA_HTTP_ENDED_CONTEXT_HEADER)).map(URI::create).orElse(null);
        URI parentId = headers.first(LRA_HTTP_PARENT_CONTEXT_HEADER).map(URI::create).orElse(null);
        PropagatedHeaders propagatedHeaders = participantService.prepareCustomHeaderPropagation(headers.toMap());
        String fqdn = path.param("fqdn");
        String method = path.param("methodName");
        String type = path.param("type");
        switch(type) {
            case "compensate":
            case "complete":
                Single.<Optional<?>>empty().observeOn(exec).onCompleteResumeWithSingle(o -> participantService.invoke(fqdn, method, lraId, parentId, propagatedHeaders)).forSingle(result -> result.ifPresentOrElse(r -> sendResult(res, r), res::send)).exceptionallyAccept(t -> sendError(lraId, req, res, t));
                break;
            case "afterlra":
                req.content().as(String.class).map(LRAStatus::valueOf).observeOn(exec).flatMapSingle(s -> Single.defer(() -> participantService.invoke(fqdn, method, lraId, s, propagatedHeaders))).onComplete(res::send).onError(t -> sendError(lraId, req, res, t)).ignoreElement();
                break;
            case "status":
                Single.<Optional<?>>empty().observeOn(exec).onCompleteResumeWithSingle(o -> participantService.invoke(fqdn, method, lraId, null, propagatedHeaders)).forSingle(result -> result.ifPresentOrElse(r -> sendResult(res, r), // or in the case of non-JAX-RS method returning ParticipantStatus null.
                () -> res.status(Response.Status.GONE.getStatusCode()).send())).exceptionallyAccept(t -> sendError(lraId, req, res, t));
                break;
            case "forget":
                Single.<Optional<?>>empty().observeOn(exec).onCompleteResumeWithSingle(o -> participantService.invoke(fqdn, method, lraId, parentId, propagatedHeaders)).onComplete(res::send).onError(t -> sendError(lraId, req, res, t)).ignoreElement();
                break;
            default:
                LOGGER.severe(() -> "Unexpected non Jax-Rs LRA compensation type " + type + ": " + req.absoluteUri());
                res.status(404).send();
                break;
        }
    });
}
Also used : LRAResponse(org.eclipse.microprofile.lra.LRAResponse) LRA_HTTP_CONTEXT_HEADER(org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_CONTEXT_HEADER) PropagatedHeaders(io.helidon.lra.coordinator.client.PropagatedHeaders) LRA_HTTP_ENDED_CONTEXT_HEADER(org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_ENDED_CONTEXT_HEADER) Supplier(java.util.function.Supplier) Level(java.util.logging.Level) Response(jakarta.ws.rs.core.Response) Map(java.util.Map) ServerResponse(io.helidon.webserver.ServerResponse) Single(io.helidon.common.reactive.Single) URI(java.net.URI) Service(io.helidon.webserver.Service) Reflected(io.helidon.common.Reflected) ExecutorService(java.util.concurrent.ExecutorService) LRA_HTTP_PARENT_CONTEXT_HEADER(org.eclipse.microprofile.lra.annotation.ws.rs.LRA.LRA_HTTP_PARENT_CONTEXT_HEADER) ParticipantStatus(org.eclipse.microprofile.lra.annotation.ParticipantStatus) Config(io.helidon.config.Config) PreDestroy(jakarta.annotation.PreDestroy) Logger(java.util.logging.Logger) RequestHeaders(io.helidon.webserver.RequestHeaders) Collectors(java.util.stream.Collectors) ServerRequest(io.helidon.webserver.ServerRequest) TimeUnit(java.util.concurrent.TimeUnit) LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) Optional(java.util.Optional) ConfigProperty(org.eclipse.microprofile.config.inject.ConfigProperty) Inject(jakarta.inject.Inject) ThreadPoolSupplier(io.helidon.common.configurable.ThreadPoolSupplier) HttpRequest(io.helidon.common.http.HttpRequest) HttpRequest(io.helidon.common.http.HttpRequest) PropagatedHeaders(io.helidon.lra.coordinator.client.PropagatedHeaders) Optional(java.util.Optional) RequestHeaders(io.helidon.webserver.RequestHeaders) URI(java.net.URI)

Example 9 with LRAStatus

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

the class RecoveryCoordinator method deleteFailedLRA.

@DELETE
@Path("{LraId}")
@Operation(summary = "Remove the log for a failed LRA")
@APIResponses({ @APIResponse(responseCode = "204", description = "If the LRA log was successfully removed"), @APIResponse(responseCode = "412", description = "If the LRA is not in an end state (in which case the response " + "entity will indicate the current state at the time of the request)"), @APIResponse(responseCode = "412", description = "If the input LRA does not correspond to a valid URI (in which case the " + "response entity will contain the error message)"), @APIResponse(responseCode = "500", description = "If the attempt to remove the LRA log failed. This return code does not " + "discriminate between a failure at the log storage level or if the log did not exist)") })
public Response deleteFailedLRA(@Parameter(name = "LraId", description = "The unique identifier of the LRA", required = true) @PathParam("LraId") String lraId) throws NotFoundException {
    URI lra;
    try {
        lra = new URI(lraId);
        // verify that the LRA is not still being processed
        // will throw NotFoundException if it's unknown (to be caught and processed in the catch block)
        LRAData lraData = lraService.getLRA(lra);
        LRAStatus status = lraData.getStatus();
        // 412 the LRA is not in an end state (return 412 and the actual status of the LRA)
        if (status == LRAStatus.FailedToCancel || status == LRAStatus.FailedToClose) {
            return removeLog(lraId);
        }
        return Response.status(PRECONDITION_FAILED).entity(lraData.getStatus().name()).build();
    } catch (NotFoundException e) {
        // the LRA has finished and, if it corresponds to a failure record, it is safe to delete it
        return removeLog(lraId);
    } catch (URISyntaxException e) {
        // 412 the user provided URI was invalid
        if (LRALogger.logger.isDebugEnabled()) {
            LRALogger.logger.debugf("%s#deleteLRA: %s: %s", getClass().getCanonicalName(), lraId, e.getMessage());
        }
        return Response.status(PRECONDITION_FAILED).entity(String.format("%s: %s", lraId, e.getMessage())).build();
    }
}
Also used : LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus) NotFoundException(javax.ws.rs.NotFoundException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) LRAData(io.narayana.lra.LRAData) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 10 with LRAStatus

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

the class LRAParticipantRecord method runPostLRAActions.

private int runPostLRAActions() {
    // TODO investigate whether we can use a sync which works in recovery scenarios
    LRAStatus lraStatus = lra.getLRAStatus();
    boolean report = false;
    if (lraStatus == LRAStatus.Cancelling) {
        report = isFailed();
        lraStatus = report ? LRAStatus.FailedToCancel : LRAStatus.Cancelled;
    } else if (lraStatus == LRAStatus.Closing) {
        report = isFailed();
        lraStatus = report ? LRAStatus.FailedToClose : LRAStatus.Closed;
    }
    if (afterURI == null || afterLRARequest(afterURI, lraStatus.name())) {
        afterURI = null;
        trace_progress("runPostLRAActions with afterURI");
        // the post LRA actions succeeded so remove the participant from the intentions list otherwise retry
        return report ? reportFailure(lraStatus.name()) : TwoPhaseOutcome.FINISH_OK;
    }
    trace_progress("runPostLRAActions");
    return report ? reportFailure(lraStatus.name()) : TwoPhaseOutcome.HEURISTIC_HAZARD;
}
Also used : LRAStatus(org.eclipse.microprofile.lra.annotation.LRAStatus)

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