Search in sources :

Example 1 with DistroData

use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.

the class DistroSyncChangeTask method doExecute.

@Override
protected boolean doExecute() {
    String type = getDistroKey().getResourceType();
    DistroData distroData = getDistroData(type);
    if (null == distroData) {
        Loggers.DISTRO.warn("[DISTRO] {} with null data to sync, skip", toString());
        return true;
    }
    return getDistroComponentHolder().findTransportAgent(type).syncData(distroData, getDistroKey().getTargetServer());
}
Also used : DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 2 with DistroData

use of com.alibaba.nacos.core.distributed.distro.entity.DistroData 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 3 with DistroData

use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.

the class DistroProtocol method onQuery.

/**
 * Query data of input distro key.
 *
 * @param distroKey key of data
 * @return data
 */
public DistroData onQuery(DistroKey distroKey) {
    String resourceType = distroKey.getResourceType();
    DistroDataStorage distroDataStorage = distroComponentHolder.findDataStorage(resourceType);
    if (null == distroDataStorage) {
        Loggers.DISTRO.warn("[DISTRO] Can't find data storage for received key {}", resourceType);
        return new DistroData(distroKey, new byte[0]);
    }
    return distroDataStorage.getDistroData(distroKey);
}
Also used : DistroDataStorage(com.alibaba.nacos.core.distributed.distro.component.DistroDataStorage) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 4 with DistroData

use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.

the class DistroController method get.

/**
 * Get datum.
 *
 * @param body keys of data
 * @return datum
 * @throws Exception if failed
 */
@GetMapping("/datum")
public ResponseEntity get(@RequestBody String body) throws Exception {
    JsonNode bodyNode = JacksonUtils.toObj(body);
    String keys = bodyNode.get("keys").asText();
    String keySplitter = ",";
    DistroHttpCombinedKey distroKey = new DistroHttpCombinedKey(KeyBuilder.INSTANCE_LIST_KEY_PREFIX, "");
    for (String key : keys.split(keySplitter)) {
        distroKey.getActualResourceTypes().add(key);
    }
    DistroData distroData = distroProtocol.onQuery(distroKey);
    return ResponseEntity.ok(distroData.getContent());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) DistroHttpCombinedKey(com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpCombinedKey) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with DistroData

use of com.alibaba.nacos.core.distributed.distro.entity.DistroData 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)

Aggregations

DistroData (com.alibaba.nacos.core.distributed.distro.entity.DistroData)24 DistroKey (com.alibaba.nacos.core.distributed.distro.entity.DistroKey)5 Test (org.junit.Test)5 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)4 Serializer (com.alibaba.nacos.naming.cluster.transport.Serializer)4 DistroHttpCombinedKey (com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpCombinedKey)4 NacosException (com.alibaba.nacos.api.exception.NacosException)3 Member (com.alibaba.nacos.core.cluster.Member)3 Datum (com.alibaba.nacos.naming.consistency.Datum)3 Client (com.alibaba.nacos.naming.core.v2.client.Client)3 DistroDataStorage (com.alibaba.nacos.core.distributed.distro.component.DistroDataStorage)2 DistroTransportAgent (com.alibaba.nacos.core.distributed.distro.component.DistroTransportAgent)2 DistroException (com.alibaba.nacos.core.distributed.distro.exception.DistroException)2 DistroDataRequest (com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)1 Response (com.alibaba.nacos.api.remote.response.Response)1 DataOperation (com.alibaba.nacos.consistency.DataOperation)1 DistroDataProcessor (com.alibaba.nacos.core.distributed.distro.component.DistroDataProcessor)1