Search in sources :

Example 6 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class DistroVerifyTimedTask method verifyForDataStorage.

private void verifyForDataStorage(String type, List<Member> targetServer) {
    DistroDataStorage dataStorage = distroComponentHolder.findDataStorage(type);
    if (!dataStorage.isFinishInitial()) {
        Loggers.DISTRO.warn("data storage {} has not finished initial step, do not send verify data", dataStorage.getClass().getSimpleName());
        return;
    }
    List<DistroData> verifyData = dataStorage.getVerifyData();
    if (null == verifyData || verifyData.isEmpty()) {
        return;
    }
    for (Member member : targetServer) {
        DistroTransportAgent agent = distroComponentHolder.findTransportAgent(type);
        if (null == agent) {
            continue;
        }
        executeTaskExecuteEngine.addTask(member.getAddress() + type, new DistroVerifyExecuteTask(agent, verifyData, member.getAddress(), type));
    }
}
Also used : DistroTransportAgent(com.alibaba.nacos.core.distributed.distro.component.DistroTransportAgent) DistroDataStorage(com.alibaba.nacos.core.distributed.distro.component.DistroDataStorage) Member(com.alibaba.nacos.core.cluster.Member) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 7 with Member

use of com.alibaba.nacos.core.cluster.Member 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 8 with Member

use of com.alibaba.nacos.core.cluster.Member 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 9 with Member

use of com.alibaba.nacos.core.cluster.Member 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 10 with Member

use of com.alibaba.nacos.core.cluster.Member in project nacos by alibaba.

the class RaftListener method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEvent event) {
    final Lock lock = readLock;
    lock.lock();
    try {
        if (event instanceof BaseRaftEvent && !stopUpdate) {
            BaseRaftEvent raftEvent = (BaseRaftEvent) event;
            RaftPeer local = raftEvent.getLocal();
            String json = JacksonUtils.toJson(local);
            Map map = JacksonUtils.toObj(json, HashMap.class);
            Member self = memberManager.getSelf();
            self.setExtendVal(Constants.OLD_NAMING_RAFT_GROUP, map);
            memberManager.update(self);
        }
        if (stopUpdate) {
            removeOldRaftMetadata();
        }
    } finally {
        lock.unlock();
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) Member(com.alibaba.nacos.core.cluster.Member) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

Member (com.alibaba.nacos.core.cluster.Member)53 Test (org.junit.Test)17 NacosException (com.alibaba.nacos.api.exception.NacosException)11 HashMap (java.util.HashMap)11 Response (com.alibaba.nacos.api.remote.response.Response)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 DistroDataRequest (com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest)6 Map (java.util.Map)5 ServerLoaderInfoResponse (com.alibaba.nacos.api.remote.response.ServerLoaderInfoResponse)4 NacosAsyncRestTemplate (com.alibaba.nacos.common.http.client.NacosAsyncRestTemplate)4 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Before (org.junit.Before)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 ServerAbilities (com.alibaba.nacos.api.ability.ServerAbilities)3 RequestCallBack (com.alibaba.nacos.api.remote.RequestCallBack)3 ServerRemoteAbility (com.alibaba.nacos.api.remote.ability.ServerRemoteAbility)3 RestResult (com.alibaba.nacos.common.model.RestResult)3 GenericType (com.alibaba.nacos.core.utils.GenericType)3