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