use of io.narayana.lra.coordinator.domain.model.LongRunningAction in project narayana by jbosstm.
the class Coordinator method getLRAStatus.
@GET
@Path("{LraId}/status")
@Produces(MediaType.TEXT_PLAIN)
@Operation(summary = "Obtain the status of an LRA as a string")
@APIResponses({ @APIResponse(responseCode = "200", description = "The LRA exists. The status is reported in the content body.", content = @Content(schema = @Schema(implementation = String.class)), headers = { @Header(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) }), @APIResponse(responseCode = "404", description = "The coordinator has no knowledge of this LRA", content = @Content(schema = @Schema(implementation = String.class))), @APIResponse(responseCode = "417", description = "The requested version provided in HTTP Header is not supported by this end point", content = @Content(schema = @Schema(implementation = String.class))) })
public Response getLRAStatus(@Parameter(name = "LraId", description = "The unique identifier of the LRA." + "Expecting to be a valid URL where the participant can be contacted at. If not in URL format it will be considered " + "to be an id which will be declared to exist at URL where coordinator is deployed at.", required = true) @PathParam("LraId") String lraId, @Parameter(ref = LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) @HeaderParam(LRAConstants.NARAYANA_LRA_API_VERSION_HEADER_NAME) @DefaultValue(CURRENT_API_VERSION_STRING) String version) throws NotFoundException {
// throws NotFoundException -> response 404
LongRunningAction transaction = lraService.getTransaction(toURI(lraId));
LRAStatus status = transaction.getLRAStatus();
if (status == null) {
status = LRAStatus.Active;
}
return Response.ok().entity(status.name()).header(NARAYANA_LRA_API_VERSION_HEADER_NAME, version).build();
}
use of io.narayana.lra.coordinator.domain.model.LongRunningAction in project narayana by jbosstm.
the class LRAService method lraTrace.
private void lraTrace(URI lraId, String reason) {
if (LRALogger.logger.isTraceEnabled()) {
if (lraId != null && lras.containsKey(lraId)) {
LongRunningAction lra = lras.get(lraId);
LRALogger.logger.tracef("LRAService: '%s' (%s) in state %s: %s%n", reason, lra.getClientId(), ActionStatus.stringForm(lra.status()), lra.getId());
} else {
LRALogger.logger.tracef("LRAService: '%s', not found: %s%n", reason, lraId);
}
}
}
use of io.narayana.lra.coordinator.domain.model.LongRunningAction in project narayana by jbosstm.
the class LRAService method joinLRA.
public synchronized int joinLRA(StringBuilder recoveryUrl, URI lra, long timeLimit, String compensatorUrl, String linkHeader, String recoveryUrlBase, String compensatorData) {
if (lra == null) {
lraTrace(null, "Error missing LRA header in join request");
} else {
lraTrace(lra, "join LRA");
}
LongRunningAction transaction = getTransaction(lra);
if (timeLimit < 0) {
timeLimit = 0;
}
// Closing/Canceling (for the AfterLRA listeners)
if (transaction.getLRAStatus() != LRAStatus.Active && !transaction.isRecovering()) {
// validate that the party wanting to join with this LRA is a listener only:
if (linkHeader != null) {
Matcher relMatcher = LINK_REL_PATTERN.matcher(linkHeader);
while (relMatcher.find()) {
String key = relMatcher.group(1);
if (key != null && key.equals("rel")) {
String rel = relMatcher.group(2) == null ? relMatcher.group(3) : relMatcher.group(2);
if (!LRAConstants.AFTER.equals(rel)) {
// participants are not allowed to join inactive LRAs
return Response.Status.PRECONDITION_FAILED.getStatusCode();
} else if (!transaction.isRecovering()) {
// listeners cannot be notified if the LRA has already ended
return Response.Status.PRECONDITION_FAILED.getStatusCode();
}
}
}
}
}
LRAParticipantRecord participant;
try {
participant = transaction.enlistParticipant(lra, linkHeader != null ? linkHeader : compensatorUrl, recoveryUrlBase, timeLimit, compensatorData);
} catch (UnsupportedEncodingException e) {
return Response.Status.PRECONDITION_FAILED.getStatusCode();
}
if (participant == null || participant.getRecoveryURI() == null) {
// probably already closing or cancelling
return Response.Status.PRECONDITION_FAILED.getStatusCode();
}
String recoveryURI = participant.getRecoveryURI().toASCIIString();
updateRecoveryURI(lra, participant.getParticipantURI(), recoveryURI, false);
recoveryUrl.append(recoveryURI);
return Response.Status.OK.getStatusCode();
}
use of io.narayana.lra.coordinator.domain.model.LongRunningAction in project narayana by jbosstm.
the class LRAService method endLRA.
public LRAData endLRA(URI lraId, boolean compensate, boolean fromHierarchy) {
lraTrace(lraId, "end LRA");
LongRunningAction transaction = getTransaction(lraId);
if (transaction.getLRAStatus() != LRAStatus.Active && !transaction.isRecovering() && transaction.isTopLevel()) {
String errorMsg = String.format("%s: LRA is closing or closed: endLRA", lraId);
throw new WebApplicationException(errorMsg, Response.status(Response.Status.PRECONDITION_FAILED).entity(errorMsg).build());
}
transaction.finishLRA(compensate);
if (BasicAction.Current() != null) {
if (LRALogger.logger.isInfoEnabled()) {
LRALogger.logger.infof("LRAServicve.endLRA LRA %s ended but is still associated with %s%n", lraId, BasicAction.Current().get_uid().fileStringForm());
}
}
finished(transaction, fromHierarchy);
return transaction.getLRAData();
}
use of io.narayana.lra.coordinator.domain.model.LongRunningAction in project narayana by jbosstm.
the class LRAService method leave.
public int leave(URI lraId, String compensatorUrl) {
lraTrace(lraId, "leave LRA");
LongRunningAction transaction = getTransaction(lraId);
if (transaction.getLRAStatus() != LRAStatus.Active) {
return Response.Status.PRECONDITION_FAILED.getStatusCode();
}
boolean wasForgotten;
try {
wasForgotten = transaction.forgetParticipant(compensatorUrl);
} catch (Exception e) {
String errorMsg = String.format("LRAService.forget %s failed on finding participant '%s'", lraId, compensatorUrl);
throw new WebApplicationException(errorMsg, e, Response.status(Response.Status.BAD_REQUEST).entity(errorMsg).build());
}
if (wasForgotten) {
return Response.Status.OK.getStatusCode();
} else {
String errorMsg = String.format("LRAService.forget %s failed as the participant was not found, compensator url '%s'", lraId, compensatorUrl);
throw new WebApplicationException(errorMsg, Response.status(Response.Status.BAD_REQUEST).entity(errorMsg).build());
}
}
Aggregations