Search in sources :

Example 1 with RegisterRMResponse

use of io.seata.core.protocol.RegisterRMResponse in project seata by seata.

the class RegRmProcessor method onRegRmMessage.

private void onRegRmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
    RegisterRMRequest message = (RegisterRMRequest) rpcMessage.getBody();
    String ipAndPort = NetUtil.toStringAddress(ctx.channel().remoteAddress());
    boolean isSuccess = false;
    String errorInfo = StringUtils.EMPTY;
    try {
        if (null == checkAuthHandler || checkAuthHandler.regResourceManagerCheckAuth(message)) {
            ChannelManager.registerRMChannel(message, ctx.channel());
            Version.putChannelVersion(ctx.channel(), message.getVersion());
            isSuccess = true;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("checkAuth for client:{},vgroup:{},applicationId:{} is OK", ipAndPort, message.getTransactionServiceGroup(), message.getApplicationId());
            }
        }
    } catch (Exception exx) {
        isSuccess = false;
        errorInfo = exx.getMessage();
        LOGGER.error("RM register fail, error message:{}", errorInfo);
    }
    RegisterRMResponse response = new RegisterRMResponse(isSuccess);
    if (StringUtils.isNotEmpty(errorInfo)) {
        response.setMsg(errorInfo);
    }
    remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), response);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("RM register success,message:{},channel:{},client version:{}", message, ctx.channel(), message.getVersion());
    }
}
Also used : RegisterRMResponse(io.seata.core.protocol.RegisterRMResponse) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest)

Example 2 with RegisterRMResponse

use of io.seata.core.protocol.RegisterRMResponse in project seata by seata.

the class RmNettyRemotingClient method onRegisterMsgFail.

@Override
public void onRegisterMsgFail(String serverAddress, Channel channel, Object response, AbstractMessage requestMessage) {
    RegisterRMRequest registerRMRequest = (RegisterRMRequest) requestMessage;
    RegisterRMResponse registerRMResponse = (RegisterRMResponse) response;
    String errMsg = String.format("register RM failed. client version: %s,server version: %s, errorMsg: %s, " + "channel: %s", registerRMRequest.getVersion(), registerRMResponse.getVersion(), registerRMResponse.getMsg(), channel);
    throw new FrameworkException(errMsg);
}
Also used : FrameworkException(io.seata.common.exception.FrameworkException) RegisterRMResponse(io.seata.core.protocol.RegisterRMResponse) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest)

Example 3 with RegisterRMResponse

use of io.seata.core.protocol.RegisterRMResponse in project seata by seata.

the class DefaultServerMessageListenerImpl method onRegRmMessage.

@Override
public void onRegRmMessage(RpcMessage request, ChannelHandlerContext ctx, RegisterCheckAuthHandler checkAuthHandler) {
    RegisterRMRequest message = (RegisterRMRequest) request.getBody();
    String ipAndPort = NetUtil.toStringAddress(ctx.channel().remoteAddress());
    boolean isSuccess = false;
    String errorInfo = StringUtils.EMPTY;
    try {
        if (checkAuthHandler == null || checkAuthHandler.regResourceManagerCheckAuth(message)) {
            ChannelManager.registerRMChannel(message, ctx.channel());
            Version.putChannelVersion(ctx.channel(), message.getVersion());
            isSuccess = true;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("checkAuth for client:{},vgroup:{},applicationId:{} is OK", ipAndPort, message.getTransactionServiceGroup(), message.getApplicationId());
            }
        }
    } catch (Exception exx) {
        isSuccess = false;
        errorInfo = exx.getMessage();
        LOGGER.error("RM register fail, error message:{}", errorInfo);
    }
    RegisterRMResponse response = new RegisterRMResponse(isSuccess);
    if (StringUtils.isNotEmpty(errorInfo)) {
        response.setMsg(errorInfo);
    }
    getServerMessageSender().sendAsyncResponse(request, ctx.channel(), response);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("RM register success,message:{},channel:{},client version:{}", message, ctx.channel(), message.getVersion());
    }
}
Also used : RegisterRMResponse(io.seata.core.protocol.RegisterRMResponse) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest)

Example 4 with RegisterRMResponse

use of io.seata.core.protocol.RegisterRMResponse in project seata by seata.

the class RegisterRMResponseConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    RegisterRMResponse registerRMResponse = new RegisterRMResponse();
    registerRMResponse.setResultCode(ResultCode.Failed);
    registerRMResponse.setMsg("msg");
    registerRMResponse.setIdentified(true);
    registerRMResponse.setVersion("11");
    registerRMResponse.setExtraData("extraData");
    RegisterRMResponseConvertor convertor = new RegisterRMResponseConvertor();
    RegisterRMResponseProto proto = convertor.convert2Proto(registerRMResponse);
    RegisterRMResponse real = convertor.convert2Model(proto);
    assertThat((real.getTypeCode())).isEqualTo(registerRMResponse.getTypeCode());
    assertThat((real.getMsg())).isEqualTo(registerRMResponse.getMsg());
    assertThat((real.getResultCode())).isEqualTo(registerRMResponse.getResultCode());
    assertThat((real.isIdentified())).isEqualTo(registerRMResponse.isIdentified());
    assertThat((real.getVersion())).isEqualTo(registerRMResponse.getVersion());
    assertThat((real.getExtraData())).isEqualTo(registerRMResponse.getExtraData());
}
Also used : RegisterRMResponseProto(io.seata.serializer.protobuf.generated.RegisterRMResponseProto) RegisterRMResponse(io.seata.core.protocol.RegisterRMResponse) Test(org.junit.jupiter.api.Test)

Example 5 with RegisterRMResponse

use of io.seata.core.protocol.RegisterRMResponse in project seata by seata.

the class RegisterRMResponseSerializerTest method test_codec.

/**
 * Test codec.
 */
@Test
public void test_codec() {
    RegisterRMResponse registerRMResponse = new RegisterRMResponse();
    registerRMResponse.setExtraData("abc123");
    registerRMResponse.setIdentified(true);
    registerRMResponse.setMsg("123456");
    registerRMResponse.setVersion("12");
    registerRMResponse.setResultCode(ResultCode.Failed);
    byte[] body = seataSerializer.serialize(registerRMResponse);
    RegisterRMResponse registerRMRespons2 = seataSerializer.deserialize(body);
    assertThat(registerRMRespons2.isIdentified()).isEqualTo(registerRMResponse.isIdentified());
    assertThat(registerRMRespons2.getVersion()).isEqualTo(registerRMResponse.getVersion());
// Assert.assertEquals(registerRMRespons2.getExtraData(), registerRMResponse.getExtraData());
// Assert.assertEquals(registerRMRespons2.getMsg(), registerRMResponse.getMsg());
// Assert.assertEquals(registerRMRespons2.getByCode(), registerRMResponse.getByCode());
}
Also used : RegisterRMResponse(io.seata.core.protocol.RegisterRMResponse) Test(org.junit.jupiter.api.Test)

Aggregations

RegisterRMResponse (io.seata.core.protocol.RegisterRMResponse)7 RegisterRMRequest (io.seata.core.protocol.RegisterRMRequest)4 Test (org.junit.jupiter.api.Test)2 FrameworkException (io.seata.common.exception.FrameworkException)1 AbstractIdentifyResponseProto (io.seata.serializer.protobuf.generated.AbstractIdentifyResponseProto)1 RegisterRMResponseProto (io.seata.serializer.protobuf.generated.RegisterRMResponseProto)1