Search in sources :

Example 6 with Transaction

use of io.narayana.lra.coordinator.domain.model.Transaction in project narayana by jbosstm.

the class LRAService method startLRA.

public synchronized URL startLRA(String baseUri, URL parentLRA, String clientId, Long timelimit) {
    Transaction lra;
    try {
        lra = new Transaction(this, baseUri, parentLRA, clientId);
    } catch (MalformedURLException e) {
        throw new InvalidLRAIdException(baseUri, "Invalid base uri", e);
    }
    if (lra.currentLRA() != null)
        if (LRALogger.logger.isInfoEnabled())
            LRALogger.logger.infof("LRAServicve.startLRA LRA %s is already associated%n", lra.currentLRA().get_uid().fileStringForm());
    int status = lra.begin(timelimit);
    if (status != ActionStatus.RUNNING) {
        lraTrace(lra.getId(), "failed to start LRA");
        lra.abort();
        throw new InternalServerErrorException("Could not start LRA: " + ActionStatus.stringForm(status));
    } else {
        try {
            addTransaction(lra);
            lraTrace(lra.getId(), "started LRA");
            return lra.getId();
        } finally {
            AtomicAction.suspend();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Transaction(io.narayana.lra.coordinator.domain.model.Transaction) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) InvalidLRAIdException(io.narayana.lra.client.InvalidLRAIdException)

Example 7 with Transaction

use of io.narayana.lra.coordinator.domain.model.Transaction in project narayana by jbosstm.

the class LRAService method updateRecoveryURL.

public void updateRecoveryURL(URL lraId, String compensatorUrl, String recoveryURL, boolean persist) {
    assert recoveryURL != null;
    assert compensatorUrl != null;
    participants.put(recoveryURL, compensatorUrl);
    if (persist && lraId != null) {
        Transaction transaction = getTransaction(lraId);
        transaction.updateRecoveryURL(compensatorUrl, recoveryURL);
    }
}
Also used : Transaction(io.narayana.lra.coordinator.domain.model.Transaction)

Example 8 with Transaction

use of io.narayana.lra.coordinator.domain.model.Transaction 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();
}
Also used : Transaction(io.narayana.lra.coordinator.domain.model.Transaction) IllegalLRAStateException(io.narayana.lra.client.IllegalLRAStateException) CompensatorStatus(io.narayana.lra.annotation.CompensatorStatus) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

Transaction (io.narayana.lra.coordinator.domain.model.Transaction)8 IllegalLRAStateException (io.narayana.lra.client.IllegalLRAStateException)3 InvalidLRAIdException (io.narayana.lra.client.InvalidLRAIdException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MalformedURLException (java.net.MalformedURLException)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 CompensatorStatus (io.narayana.lra.annotation.CompensatorStatus)1 GenericLRAException (io.narayana.lra.client.GenericLRAException)1 LRARecord (io.narayana.lra.coordinator.domain.model.LRARecord)1 LRAStatus (io.narayana.lra.coordinator.domain.model.LRAStatus)1 LRARecoveryModule (io.narayana.lra.coordinator.internal.LRARecoveryModule)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1