Search in sources :

Example 1 with DistroDataRequest

use of com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest in project nacos by alibaba.

the class DistroClientTransportAgent method getData.

@Override
public DistroData getData(DistroKey key, String targetServer) {
    Member member = memberManager.find(targetServer);
    if (checkTargetServerStatusUnhealthy(member)) {
        throw new DistroException(String.format("[DISTRO] Cancel get snapshot caused by target server %s unhealthy", targetServer));
    }
    DistroDataRequest request = new DistroDataRequest();
    DistroData distroData = new DistroData();
    distroData.setDistroKey(key);
    distroData.setType(DataOperation.QUERY);
    request.setDistroData(distroData);
    request.setDataOperation(DataOperation.QUERY);
    try {
        Response response = clusterRpcClientProxy.sendRequest(member, request);
        if (checkResponse(response)) {
            return ((DistroDataResponse) response).getDistroData();
        } else {
            throw new DistroException(String.format("[DISTRO-FAILED] Get data request to %s failed, code: %d, message: %s", targetServer, response.getErrorCode(), response.getMessage()));
        }
    } catch (NacosException e) {
        throw new DistroException("[DISTRO-FAILED] Get distro data failed! ", e);
    }
}
Also used : DistroException(com.alibaba.nacos.core.distributed.distro.exception.DistroException) Response(com.alibaba.nacos.api.remote.response.Response) DistroDataResponse(com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse) DistroDataRequest(com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest) Member(com.alibaba.nacos.core.cluster.Member) DistroDataResponse(com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse) NacosException(com.alibaba.nacos.api.exception.NacosException) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 2 with DistroDataRequest

use of com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest in project nacos by alibaba.

the class DistroClientTransportAgent method syncVerifyData.

@Override
public void syncVerifyData(DistroData verifyData, String targetServer, DistroCallback callback) {
    if (isNoExistTarget(targetServer)) {
        callback.onSuccess();
        return;
    }
    DistroDataRequest request = new DistroDataRequest(verifyData, DataOperation.VERIFY);
    Member member = memberManager.find(targetServer);
    try {
        DistroVerifyCallbackWrapper wrapper = new DistroVerifyCallbackWrapper(targetServer, verifyData.getDistroKey().getResourceKey(), callback, member);
        clusterRpcClientProxy.asyncRequest(member, request, wrapper);
    } catch (NacosException nacosException) {
        callback.onFailed(nacosException);
    }
}
Also used : DistroDataRequest(com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest) Member(com.alibaba.nacos.core.cluster.Member) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 3 with DistroDataRequest

use of com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest in project nacos by alibaba.

the class DistroClientTransportAgent method syncData.

@Override
public boolean syncData(DistroData data, String targetServer) {
    if (isNoExistTarget(targetServer)) {
        return true;
    }
    DistroDataRequest request = new DistroDataRequest(data, data.getType());
    Member member = memberManager.find(targetServer);
    if (checkTargetServerStatusUnhealthy(member)) {
        Loggers.DISTRO.warn("[DISTRO] Cancel distro sync caused by target server {} unhealthy", targetServer);
        return false;
    }
    try {
        Response response = clusterRpcClientProxy.sendRequest(member, request);
        return checkResponse(response);
    } catch (NacosException e) {
        Loggers.DISTRO.error("[DISTRO-FAILED] Sync distro data failed! ", e);
    }
    return false;
}
Also used : Response(com.alibaba.nacos.api.remote.response.Response) DistroDataResponse(com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse) DistroDataRequest(com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest) Member(com.alibaba.nacos.core.cluster.Member) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 4 with DistroDataRequest

use of com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest in project nacos by alibaba.

the class DistroClientTransportAgent method syncData.

@Override
public void syncData(DistroData data, String targetServer, DistroCallback callback) {
    if (isNoExistTarget(targetServer)) {
        callback.onSuccess();
        return;
    }
    DistroDataRequest request = new DistroDataRequest(data, data.getType());
    Member member = memberManager.find(targetServer);
    try {
        clusterRpcClientProxy.asyncRequest(member, request, new DistroRpcCallbackWrapper(callback, member));
    } catch (NacosException nacosException) {
        callback.onFailed(nacosException);
    }
}
Also used : DistroDataRequest(com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest) Member(com.alibaba.nacos.core.cluster.Member) NacosException(com.alibaba.nacos.api.exception.NacosException)

Example 5 with DistroDataRequest

use of com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest in project nacos by alibaba.

the class DistroClientTransportAgent method getDatumSnapshot.

@Override
public DistroData getDatumSnapshot(String targetServer) {
    Member member = memberManager.find(targetServer);
    if (checkTargetServerStatusUnhealthy(member)) {
        throw new DistroException(String.format("[DISTRO] Cancel get snapshot caused by target server %s unhealthy", targetServer));
    }
    DistroDataRequest request = new DistroDataRequest();
    request.setDataOperation(DataOperation.SNAPSHOT);
    try {
        Response response = clusterRpcClientProxy.sendRequest(member, request);
        if (checkResponse(response)) {
            return ((DistroDataResponse) response).getDistroData();
        } else {
            throw new DistroException(String.format("[DISTRO-FAILED] Get snapshot request to %s failed, code: %d, message: %s", targetServer, response.getErrorCode(), response.getMessage()));
        }
    } catch (NacosException e) {
        throw new DistroException("[DISTRO-FAILED] Get distro snapshot failed! ", e);
    }
}
Also used : DistroException(com.alibaba.nacos.core.distributed.distro.exception.DistroException) Response(com.alibaba.nacos.api.remote.response.Response) DistroDataResponse(com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse) DistroDataRequest(com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest) Member(com.alibaba.nacos.core.cluster.Member) DistroDataResponse(com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse) NacosException(com.alibaba.nacos.api.exception.NacosException)

Aggregations

DistroDataRequest (com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest)7 NacosException (com.alibaba.nacos.api.exception.NacosException)6 Member (com.alibaba.nacos.core.cluster.Member)6 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)5 Response (com.alibaba.nacos.api.remote.response.Response)4 DistroData (com.alibaba.nacos.core.distributed.distro.entity.DistroData)2 DistroException (com.alibaba.nacos.core.distributed.distro.exception.DistroException)2 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)1 Test (org.junit.Test)1