Search in sources :

Example 1 with ParticipantException

use of org.jboss.narayana.rest.integration.api.ParticipantException in project narayana by jbosstm.

the class RecoveryManager method recreateParticipantInformation.

private ParticipantInformation recreateParticipantInformation(final RecoveryStore recoveryStore, final Uid uid) throws ObjectStoreException, IOException {
    final InputObjectState inputObjectState = recoveryStore.read_committed(uid, PARTICIPANT_INFORMATION_RECORD_TYPE);
    final String id = inputObjectState.unpackString();
    if (ParticipantsContainer.getInstance().getParticipantInformation(id) != null) {
        // Participant is already loaded.
        return null;
    }
    final String applicationId = inputObjectState.unpackString();
    if (!deserializers.containsKey(applicationId)) {
        // There is no appropriate deserializer.
        return null;
    }
    final String status = inputObjectState.unpackString();
    final String recoveryUrl = inputObjectState.unpackString();
    final Participant participant = recreateParticipant(inputObjectState, applicationId);
    if (participant == null) {
        // Deserializer failed to recreate participant.
        return null;
    }
    final ParticipantInformation participantInformation = new ParticipantInformation(id, applicationId, recoveryUrl, participant, status);
    if (!synchronizeParticipantUrlWithCoordinator(participantInformation)) {
        try {
            participant.rollback();
            removeParticipantInformation(participantInformation);
        // TODO is it OK to leave participant not rolled back in case of Exception?
        } catch (HeuristicException e) {
            LOG.warn(e.getMessage(), e);
        } catch (ParticipantException e) {
            LOG.warn(e.getMessage(), e);
        }
        return null;
    }
    return participantInformation;
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) HeuristicException(org.jboss.narayana.rest.integration.api.HeuristicException) Participant(org.jboss.narayana.rest.integration.api.Participant) PersistableParticipant(org.jboss.narayana.rest.integration.api.PersistableParticipant) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException)

Example 2 with ParticipantException

use of org.jboss.narayana.rest.integration.api.ParticipantException in project narayana by jbosstm.

the class ParticipantResource method rollback.

private void rollback(final ParticipantInformation participantInformation) throws HeuristicException {
    if (isHeuristic(participantInformation)) {
        rollbackHeuristic(participantInformation);
    } else {
        final String previousStatus = participantInformation.getStatus();
        participantInformation.setStatus(TxStatus.TransactionRollingBack.name());
        try {
            participantInformation.getParticipant().rollback();
        } catch (HeuristicException e) {
            if (!e.getHeuristicType().equals(HeuristicType.HEURISTIC_ROLLBACK)) {
                participantInformation.setStatus(e.getHeuristicType().toTxStatus());
                RecoveryManager.getInstance().persistParticipantInformation(participantInformation);
                throw new HeuristicException(e.getHeuristicType());
            }
        } catch (ParticipantException e) {
            participantInformation.setStatus(previousStatus);
            throw e;
        }
        participantInformation.setStatus(TxStatus.TransactionRolledBack.name());
        RecoveryManager.getInstance().removeParticipantInformation(participantInformation);
        ParticipantsContainer.getInstance().removeParticipantInformation(participantInformation.getId());
    }
}
Also used : HeuristicException(org.jboss.narayana.rest.integration.api.HeuristicException) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException)

Example 3 with ParticipantException

use of org.jboss.narayana.rest.integration.api.ParticipantException in project narayana by jbosstm.

the class ParticipantResource method prepare.

private Vote prepare(final ParticipantInformation participantInformation) throws HeuristicException {
    if (isHeuristic(participantInformation)) {
        return prepareHeuristic(participantInformation);
    }
    participantInformation.setStatus(TxStatus.TransactionPreparing.name());
    final Vote vote;
    try {
        vote = participantInformation.getParticipant().prepare();
    } catch (ParticipantException e) {
        participantInformation.setStatus(TxStatus.TransactionActive.name());
        throw e;
    }
    if (vote instanceof Aborted) {
        rollback(participantInformation);
    } else if (vote instanceof Prepared) {
        participantInformation.setStatus(TxStatus.TransactionPrepared.name());
        RecoveryManager.getInstance().persistParticipantInformation(participantInformation);
    } else if (vote instanceof ReadOnly) {
        readOnly(participantInformation);
    }
    return vote;
}
Also used : ReadOnly(org.jboss.narayana.rest.integration.api.ReadOnly) Vote(org.jboss.narayana.rest.integration.api.Vote) Prepared(org.jboss.narayana.rest.integration.api.Prepared) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException) Aborted(org.jboss.narayana.rest.integration.api.Aborted)

Example 4 with ParticipantException

use of org.jboss.narayana.rest.integration.api.ParticipantException in project narayana by jbosstm.

the class ParticipantResource method commit.

private void commit(final ParticipantInformation participantInformation) throws HeuristicException {
    if (isHeuristic(participantInformation)) {
        commitHeuristic(participantInformation);
    } else {
        participantInformation.setStatus(TxStatus.TransactionCommitting.name());
        try {
            participantInformation.getParticipant().commit();
        } catch (HeuristicException e) {
            if (!e.getHeuristicType().equals(HeuristicType.HEURISTIC_COMMIT)) {
                participantInformation.setStatus(e.getHeuristicType().toTxStatus());
                RecoveryManager.getInstance().persistParticipantInformation(participantInformation);
                throw new HeuristicException(e.getHeuristicType());
            }
        } catch (ParticipantException e) {
            participantInformation.setStatus(TxStatus.TransactionPrepared.name());
            throw e;
        }
        participantInformation.setStatus(TxStatus.TransactionCommitted.name());
        RecoveryManager.getInstance().removeParticipantInformation(participantInformation);
        ParticipantsContainer.getInstance().removeParticipantInformation(participantInformation.getId());
    }
}
Also used : HeuristicException(org.jboss.narayana.rest.integration.api.HeuristicException) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException)

Example 5 with ParticipantException

use of org.jboss.narayana.rest.integration.api.ParticipantException in project narayana by jbosstm.

the class ParticipantsManagerImpl method enlistParticipant.

private String enlistParticipant(final String participantUrl, final String participantEnlistmentURL) {
    TxSupport txSupport = new TxSupport();
    String participantLinkHeader = txSupport.makeTwoPhaseAwareParticipantLinkHeader(participantUrl, participantUrl);
    final String recoveryUrl;
    try {
        recoveryUrl = txSupport.enlistParticipant(participantEnlistmentURL, participantLinkHeader);
    } catch (HttpResponseException e) {
        throw new ParticipantException("Failed to enlist participant", e);
    }
    return recoveryUrl;
}
Also used : TxSupport(org.jboss.jbossts.star.util.TxSupport) HttpResponseException(org.jboss.jbossts.star.provider.HttpResponseException) ParticipantException(org.jboss.narayana.rest.integration.api.ParticipantException)

Aggregations

ParticipantException (org.jboss.narayana.rest.integration.api.ParticipantException)6 HeuristicException (org.jboss.narayana.rest.integration.api.HeuristicException)3 HttpResponseException (org.jboss.jbossts.star.provider.HttpResponseException)2 TxSupport (org.jboss.jbossts.star.util.TxSupport)2 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 Aborted (org.jboss.narayana.rest.integration.api.Aborted)1 Participant (org.jboss.narayana.rest.integration.api.Participant)1 PersistableParticipant (org.jboss.narayana.rest.integration.api.PersistableParticipant)1 Prepared (org.jboss.narayana.rest.integration.api.Prepared)1 ReadOnly (org.jboss.narayana.rest.integration.api.ReadOnly)1 Vote (org.jboss.narayana.rest.integration.api.Vote)1