use of io.narayana.lra.participant.model.Activity in project narayana by jbosstm.
the class ActivityController method acceptWork.
@PUT
@Path(ACCEPT_WORK)
@LRA(LRA.Type.REQUIRED)
public Response acceptWork(@HeaderParam(LRA_HTTP_RECOVERY_HEADER) String rcvId, @HeaderParam(LRA_HTTP_HEADER) String lraId) {
assert lraId != null;
Activity activity = addWork(lraId, rcvId);
if (activity == null)
return Response.status(Response.Status.EXPECTATION_FAILED).entity("Missing lra data").build();
// tests that it is possible to asynchronously complete
activity.setAcceptedCount(1);
return Response.ok(lraId).build();
}
use of io.narayana.lra.participant.model.Activity in project narayana by jbosstm.
the class ActivityController method forgetWork.
@DELETE
@Path("/forget")
@Produces(MediaType.APPLICATION_JSON)
@Forget
public Response forgetWork(@HeaderParam(LRA_HTTP_HEADER) String lraId) {
// throws NotFoundException {
completedCount.incrementAndGet();
assert lraId != null;
String txId = NarayanaLRAClient.getLRAId(lraId);
Activity activity = activityService.getActivity(txId);
activityService.remove(activity.id);
activity.status = CompensatorStatus.Completed;
activity.statusUrl = String.format("%s/%s/activity/completed", context.getBaseUri(), txId);
System.out.printf("ActivityController forgetting %s%n", txId);
return Response.ok(activity.statusUrl).build();
}
use of io.narayana.lra.participant.model.Activity in project narayana by jbosstm.
the class ActivityController method completeWork.
@PUT
@Path("/complete")
@Produces(MediaType.APPLICATION_JSON)
@Complete
public Response completeWork(@HeaderParam(LRA_HTTP_HEADER) String lraId, String userData) throws NotFoundException {
completedCount.incrementAndGet();
assert lraId != null;
String txId = NarayanaLRAClient.getLRAId(lraId);
Activity activity = activityService.getActivity(txId);
activity.setEndData(userData);
if (activity.getAndDecrementAcceptCount() > 0) {
activity.status = CompensatorStatus.Completing;
activity.statusUrl = String.format("%s/%s/%s/status", context.getBaseUri(), ACTIVITIES_PATH, txId);
return Response.accepted().location(URI.create(activity.statusUrl)).build();
}
activity.status = CompensatorStatus.Completed;
activity.statusUrl = String.format("%s/%s/activity/completed", context.getBaseUri(), txId);
System.out.printf("ActivityController completing %s%n", txId);
return Response.ok(activity.statusUrl).build();
}
use of io.narayana.lra.participant.model.Activity in project narayana by jbosstm.
the class ActivityController method addWork.
private Activity addWork(String lraId, String rcvId) {
assert lraId != null;
String txId = NarayanaLRAClient.getLRAId(lraId);
System.out.printf("ActivityController: work id %s and rcvId %s %n", txId, rcvId);
if (txId == null)
return null;
try {
return activityService.getActivity(txId);
} catch (NotFoundException e) {
Activity activity = new Activity(txId);
activity.rcvUrl = rcvId;
activity.status = null;
activityService.add(activity);
return activity;
}
}
use of io.narayana.lra.participant.model.Activity 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