Search in sources :

Example 6 with DistroData

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

the class DistroDataStorageImpl method getDatumSnapshot.

@Override
public DistroData getDatumSnapshot() {
    Map<String, Datum> result = dataStore.getDataMap();
    byte[] dataContent = ApplicationUtils.getBean(Serializer.class).serialize(result);
    DistroKey distroKey = new DistroKey(KeyBuilder.RESOURCE_KEY_SNAPSHOT, KeyBuilder.INSTANCE_LIST_KEY_PREFIX);
    return new DistroData(distroKey, dataContent);
}
Also used : Datum(com.alibaba.nacos.naming.consistency.Datum) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) Serializer(com.alibaba.nacos.naming.cluster.transport.Serializer) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 7 with DistroData

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

the class DistroDataStorageImpl method getVerifyData.

@Override
public List<DistroData> getVerifyData() {
    // If upgrade to 2.0.X, do not verify for v1.
    if (ApplicationUtils.getBean(UpgradeJudgement.class).isUseGrpcFeatures()) {
        return Collections.emptyList();
    }
    Map<String, String> keyChecksums = new HashMap<>(64);
    for (String key : dataStore.keys()) {
        if (!distroMapper.responsible(KeyBuilder.getServiceName(key))) {
            continue;
        }
        Datum datum = dataStore.get(key);
        if (datum == null) {
            continue;
        }
        keyChecksums.put(key, datum.value.getChecksum());
    }
    if (keyChecksums.isEmpty()) {
        return Collections.emptyList();
    }
    DistroKey distroKey = new DistroKey(KeyBuilder.RESOURCE_KEY_CHECKSUM, KeyBuilder.INSTANCE_LIST_KEY_PREFIX);
    DistroData data = new DistroData(distroKey, ApplicationUtils.getBean(Serializer.class).serialize(keyChecksums));
    data.setType(DataOperation.VERIFY);
    return Collections.singletonList(data);
}
Also used : Datum(com.alibaba.nacos.naming.consistency.Datum) HashMap(java.util.HashMap) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) UpgradeJudgement(com.alibaba.nacos.naming.core.v2.upgrade.UpgradeJudgement) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 8 with DistroData

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

the class DistroDataStorageImpl method getDistroData.

@Override
public DistroData getDistroData(DistroKey distroKey) {
    Map<String, Datum> result = new HashMap<>(2);
    if (distroKey instanceof DistroHttpCombinedKey) {
        result = dataStore.batchGet(((DistroHttpCombinedKey) distroKey).getActualResourceTypes());
    } else {
        Datum datum = dataStore.get(distroKey.getResourceKey());
        result.put(distroKey.getResourceKey(), datum);
    }
    byte[] dataContent = ApplicationUtils.getBean(Serializer.class).serialize(result);
    return new DistroData(distroKey, dataContent);
}
Also used : Datum(com.alibaba.nacos.naming.consistency.Datum) HashMap(java.util.HashMap) DistroHttpCombinedKey(com.alibaba.nacos.naming.consistency.ephemeral.distro.combined.DistroHttpCombinedKey) Serializer(com.alibaba.nacos.naming.cluster.transport.Serializer) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 9 with DistroData

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

the class DistroClientDataProcessor method getDistroData.

@Override
public DistroData getDistroData(DistroKey distroKey) {
    Client client = clientManager.getClient(distroKey.getResourceKey());
    if (null == client) {
        return null;
    }
    byte[] data = ApplicationUtils.getBean(Serializer.class).serialize(client.generateSyncData());
    return new DistroData(distroKey, data);
}
Also used : Client(com.alibaba.nacos.naming.core.v2.client.Client) Serializer(com.alibaba.nacos.naming.cluster.transport.Serializer) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 10 with DistroData

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

the class DistroClientDataProcessor method getDatumSnapshot.

@Override
public DistroData getDatumSnapshot() {
    List<ClientSyncData> datum = new LinkedList<>();
    for (String each : clientManager.allClientId()) {
        Client client = clientManager.getClient(each);
        if (null == client || !client.isEphemeral()) {
            continue;
        }
        datum.add(client.generateSyncData());
    }
    ClientSyncDatumSnapshot snapshot = new ClientSyncDatumSnapshot();
    snapshot.setClientSyncDataList(datum);
    byte[] data = ApplicationUtils.getBean(Serializer.class).serialize(snapshot);
    return new DistroData(new DistroKey(DataOperation.SNAPSHOT.name(), TYPE), data);
}
Also used : ClientSyncData(com.alibaba.nacos.naming.core.v2.client.ClientSyncData) ClientSyncDatumSnapshot(com.alibaba.nacos.naming.core.v2.client.ClientSyncDatumSnapshot) Client(com.alibaba.nacos.naming.core.v2.client.Client) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) LinkedList(java.util.LinkedList) Serializer(com.alibaba.nacos.naming.cluster.transport.Serializer) 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