use of io.narayana.lra.annotation.CompensatorStatus in project narayana by jbosstm.
the class ProxyService method getStatus.
CompensatorStatus getStatus(URL lraId, String participantId) throws InvalidLRAStateException {
ParticipantProxy proxy = getProxy(lraId, participantId);
if (proxy == null)
throw new NotFoundException();
Optional<CompensatorStatus> status = proxy.getStatus();
// null status implies that the participant is still active
return status.orElseThrow(InvalidLRAStateException::new);
}
use of io.narayana.lra.annotation.CompensatorStatus in project narayana by jbosstm.
the class NarayanaLRAClient method getStatus.
@Override
public Optional<CompensatorStatus> getStatus(URL lraId) throws GenericLRAException {
Response response = null;
try {
aquireConnection();
response = getTarget().path(getLRAId(lraId.toString())).request().accept(MediaType.TEXT_PLAIN_TYPE).get();
} catch (Exception e) {
releaseConnection(null);
LRALogger.i18NLogger.error_cannotAccesCorrdinatorWhenGettingStatus(base, lraId, e);
throw new GenericLRAException(lraId, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Could not access the LRA coordinator: " + e.getMessage(), e);
}
try {
if (response.getStatus() == Response.Status.NO_CONTENT.getStatusCode())
return Optional.empty();
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
LRALogger.i18NLogger.error_invalidStatusCode(base, response.getStatus(), lraId);
throw new GenericLRAException(lraId, response.getStatus(), "LRA coordinator returned an invalid status code", null);
}
if (!response.hasEntity()) {
LRALogger.i18NLogger.error_noContentOnGetStatus(base, lraId);
throw new GenericLRAException(lraId, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "LRA coordinator#getStatus returned 200 OK but no content");
}
// convert the returned String into a status
Optional<CompensatorStatus> status;
try {
return fromString(response.readEntity(String.class));
} catch (IllegalArgumentException e) {
LRALogger.i18NLogger.error_invalidArgumentOnStatusFromCoordinator(base, lraId, e);
throw new GenericLRAException(lraId, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "LRA coordinator returned an invalid status", e);
}
} finally {
releaseConnection(response);
}
}
use of io.narayana.lra.annotation.CompensatorStatus in project narayana by jbosstm.
the class Coordinator method getNestedLRAStatus.
@GET
@Path("{NestedLraId}/status")
public Response getNestedLRAStatus(@PathParam("NestedLraId") String nestedLraId) {
if (!lraService.hasTransaction(nestedLraId)) {
// it must have compensated TODO maybe it's better to keep nested LRAs in separate collection
return Response.ok(CompensatorStatus.Compensated.name()).build();
}
Transaction lra = lraService.getTransaction(toURL(nestedLraId));
CompensatorStatus status = lra.getLRAStatus();
if (status == null || lra.getLRAStatus() == null) {
LRALogger.i18NLogger.error_cannotGetStatusOfNestedLra(nestedLraId, lra.getId());
throw new IllegalLRAStateException(nestedLraId, "The LRA is still active", "getNestedLRAStatus");
}
return Response.ok(lra.getLRAStatus().name()).build();
}
use of io.narayana.lra.annotation.CompensatorStatus in project narayana by jbosstm.
the class ActivityController method status.
/**
* Performing a GET on the participant URL will return the current status of the participant {@link CompensatorStatus}, or 404 if the participant is no longer present.
*/
@GET
@Path("/status")
@Produces(MediaType.APPLICATION_JSON)
@Status
@LRA(LRA.Type.NOT_SUPPORTED)
public Response status(@PathParam("LraUrl") String lraUrl, @HeaderParam(LRA_HTTP_HEADER) String lraId) throws NotFoundException {
String txId = NarayanaLRAClient.getLRAId(lraId);
Activity activity = activityService.getActivity(txId);
if (activity.status == null)
throw new IllegalLRAStateException(lraId, "LRA is not active", "getStatus");
if (activity.getAndDecrementAcceptCount() <= 0) {
if (activity.status == CompensatorStatus.Completing)
activity.status = CompensatorStatus.Completed;
else if (activity.status == CompensatorStatus.Compensating)
activity.status = CompensatorStatus.Compensated;
}
return Response.ok(activity.status.name()).build();
}
Aggregations