Search in sources :

Example 1 with BranchReportResponse

use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.

the class AbstractTCInboundHandler method handle.

@Override
public BranchReportResponse handle(BranchReportRequest request, final RpcContext rpcContext) {
    BranchReportResponse response = new BranchReportResponse();
    exceptionHandleTemplate(new AbstractCallback<BranchReportRequest, BranchReportResponse>() {

        @Override
        public void execute(BranchReportRequest request, BranchReportResponse response) throws TransactionException {
            try {
                doBranchReport(request, response, rpcContext);
            } catch (StoreException e) {
                throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("branch report request failed. xid=%s, branchId=%s, msg=%s", request.getXid(), request.getBranchId(), e.getMessage()), e);
            }
        }
    }, request, response);
    return response;
}
Also used : TransactionException(io.seata.core.exception.TransactionException) BranchReportResponse(io.seata.core.protocol.transaction.BranchReportResponse) BranchReportRequest(io.seata.core.protocol.transaction.BranchReportRequest) StoreException(io.seata.common.exception.StoreException)

Example 2 with BranchReportResponse

use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.

the class BranchReportResponseSerializerTest method test_codec.

/**
 * Test codec.
 */
@Test
public void test_codec() {
    BranchReportResponse branchReportResponse = new BranchReportResponse();
    branchReportResponse.setMsg("abac");
    branchReportResponse.setResultCode(ResultCode.Failed);
    branchReportResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
    byte[] bytes = seataSerializer.serialize(branchReportResponse);
    BranchReportResponse branchReportResponse2 = seataSerializer.deserialize(bytes);
    assertThat(branchReportResponse2.getMsg()).isEqualTo(branchReportResponse.getMsg());
    assertThat(branchReportResponse2.getResultCode()).isEqualTo(branchReportResponse.getResultCode());
    assertThat(branchReportResponse2.getTransactionExceptionCode()).isEqualTo(branchReportResponse.getTransactionExceptionCode());
}
Also used : BranchReportResponse(io.seata.core.protocol.transaction.BranchReportResponse) Test(org.junit.jupiter.api.Test)

Example 3 with BranchReportResponse

use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.

the class AbstractResourceManager method branchReport.

/**
 * report branch status
 *
 * @param branchType      the branch type
 * @param xid             the xid
 * @param branchId        the branch id
 * @param status          the status
 * @param applicationData the application data
 * @throws TransactionException  TransactionException
 */
@Override
public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData) throws TransactionException {
    try {
        BranchReportRequest request = new BranchReportRequest();
        request.setXid(xid);
        request.setBranchId(branchId);
        request.setStatus(status);
        request.setApplicationData(applicationData);
        BranchReportResponse response = (BranchReportResponse) RmNettyRemotingClient.getInstance().sendSyncRequest(request);
        if (response.getResultCode() == ResultCode.Failed) {
            throw new RmTransactionException(response.getTransactionExceptionCode(), String.format("Response[ %s ]", response.getMsg()));
        }
    } catch (TimeoutException toe) {
        throw new RmTransactionException(TransactionExceptionCode.IO, "RPC Timeout", toe);
    } catch (RuntimeException rex) {
        throw new RmTransactionException(TransactionExceptionCode.BranchReportFailed, "Runtime", rex);
    }
}
Also used : RmTransactionException(io.seata.core.exception.RmTransactionException) BranchReportRequest(io.seata.core.protocol.transaction.BranchReportRequest) BranchReportResponse(io.seata.core.protocol.transaction.BranchReportResponse) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with BranchReportResponse

use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.

the class BranchReportResponseConvertor method convert2Model.

@Override
public BranchReportResponse convert2Model(BranchReportResponseProto branchReportResponseProto) {
    BranchReportResponse branchRegisterResponse = new BranchReportResponse();
    final AbstractResultMessageProto abstractResultMessage = branchReportResponseProto.getAbstractTransactionResponse().getAbstractResultMessage();
    branchRegisterResponse.setMsg(abstractResultMessage.getMsg());
    branchRegisterResponse.setResultCode(ResultCode.valueOf(abstractResultMessage.getResultCode().name()));
    branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf(branchReportResponseProto.getAbstractTransactionResponse().getTransactionExceptionCode().name()));
    return branchRegisterResponse;
}
Also used : AbstractResultMessageProto(io.seata.serializer.protobuf.generated.AbstractResultMessageProto) BranchReportResponse(io.seata.core.protocol.transaction.BranchReportResponse)

Example 5 with BranchReportResponse

use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.

the class BranchReportResponseConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    BranchReportResponse branchReportResponse = new BranchReportResponse();
    branchReportResponse.setMsg("msg");
    branchReportResponse.setResultCode(ResultCode.Failed);
    branchReportResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotExist);
    BranchReportResponseConvertor convertor = new BranchReportResponseConvertor();
    BranchReportResponseProto proto = convertor.convert2Proto(branchReportResponse);
    BranchReportResponse real = convertor.convert2Model(proto);
    assertThat((real.getTypeCode())).isEqualTo(branchReportResponse.getTypeCode());
    assertThat((real.getMsg())).isEqualTo(branchReportResponse.getMsg());
    assertThat((real.getResultCode())).isEqualTo(branchReportResponse.getResultCode());
    assertThat((real.getTransactionExceptionCode())).isEqualTo(branchReportResponse.getTransactionExceptionCode());
}
Also used : BranchReportResponse(io.seata.core.protocol.transaction.BranchReportResponse) BranchReportResponseProto(io.seata.serializer.protobuf.generated.BranchReportResponseProto) Test(org.junit.jupiter.api.Test)

Aggregations

BranchReportResponse (io.seata.core.protocol.transaction.BranchReportResponse)5 BranchReportRequest (io.seata.core.protocol.transaction.BranchReportRequest)2 Test (org.junit.jupiter.api.Test)2 StoreException (io.seata.common.exception.StoreException)1 RmTransactionException (io.seata.core.exception.RmTransactionException)1 TransactionException (io.seata.core.exception.TransactionException)1 AbstractResultMessageProto (io.seata.serializer.protobuf.generated.AbstractResultMessageProto)1 BranchReportResponseProto (io.seata.serializer.protobuf.generated.BranchReportResponseProto)1 TimeoutException (java.util.concurrent.TimeoutException)1