use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroClientDataProcessor method getVerifyData.
@Override
public List<DistroData> getVerifyData() {
List<DistroData> result = new LinkedList<>();
for (String each : clientManager.allClientId()) {
Client client = clientManager.getClient(each);
if (null == client || !client.isEphemeral()) {
continue;
}
if (clientManager.isResponsibleClient(client)) {
// TODO add revision for client.
DistroClientVerifyInfo verifyData = new DistroClientVerifyInfo(client.getClientId(), 0);
DistroKey distroKey = new DistroKey(client.getClientId(), TYPE);
DistroData data = new DistroData(distroKey, ApplicationUtils.getBean(Serializer.class).serialize(verifyData));
data.setType(DataOperation.VERIFY);
result.add(data);
}
}
return result;
}
use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroConsistencyServiceImpl method onReceiveChecksums.
/**
* Check sum when receive checksums request.
*
* @param checksumMap map of checksum
* @param server source server request checksum
*/
public void onReceiveChecksums(Map<String, String> checksumMap, String server) {
if (syncChecksumTasks.putIfAbsent(server, ON_RECEIVE_CHECKSUMS_PROCESSING_TAG) != null) {
// Already in process of this server:
Loggers.DISTRO.warn("sync checksum task already in process with {}", server);
return;
}
try {
List<String> toUpdateKeys = new ArrayList<>();
List<String> toRemoveKeys = new ArrayList<>();
for (Map.Entry<String, String> entry : checksumMap.entrySet()) {
if (distroMapper.responsible(KeyBuilder.getServiceName(entry.getKey()))) {
// this key should not be sent from remote server:
Loggers.DISTRO.error("receive responsible key timestamp of " + entry.getKey() + " from " + server);
// abort the procedure:
return;
}
if (!dataStore.contains(entry.getKey()) || dataStore.get(entry.getKey()).value == null || !dataStore.get(entry.getKey()).value.getChecksum().equals(entry.getValue())) {
toUpdateKeys.add(entry.getKey());
}
}
for (String key : dataStore.keys()) {
if (!server.equals(distroMapper.mapSrv(KeyBuilder.getServiceName(key)))) {
continue;
}
if (!checksumMap.containsKey(key)) {
toRemoveKeys.add(key);
}
}
Loggers.DISTRO.info("to remove keys: {}, to update keys: {}, source: {}", toRemoveKeys, toUpdateKeys, server);
for (String key : toRemoveKeys) {
onRemove(key);
}
if (toUpdateKeys.isEmpty()) {
return;
}
try {
DistroHttpCombinedKey distroKey = new DistroHttpCombinedKey(KeyBuilder.INSTANCE_LIST_KEY_PREFIX, server);
distroKey.getActualResourceTypes().addAll(toUpdateKeys);
DistroData remoteData = distroProtocol.queryFromRemote(distroKey);
if (null != remoteData) {
processData(remoteData.getContent());
}
} catch (Exception e) {
Loggers.DISTRO.error("get data from " + server + " failed!", e);
}
} finally {
// Remove this 'in process' flag:
syncChecksumTasks.remove(server);
}
}
use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroControllerTest method testGet.
@Test
public void testGet() {
try {
Mockito.when(distroProtocol.onQuery(Mockito.any())).thenReturn(new DistroData(null, "content".getBytes()));
ResponseEntity<byte[]> responseEntity = distroController.get("{\"keys\":[\"12\", \"33\"]}");
Assert.assertArrayEquals("content".getBytes(), responseEntity.getBody());
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroDataResponseTest method test.
@Test
public void test() {
DistroDataResponse distroDataResponse = new DistroDataResponse();
DistroData distroData = mock(DistroData.class);
distroDataResponse.setDistroData(distroData);
assertEquals(distroData, distroDataResponse.getDistroData());
}
use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroHttpAgent method getData.
@Override
public DistroData getData(DistroKey key, String targetServer) {
try {
List<String> toUpdateKeys = null;
if (key instanceof DistroHttpCombinedKey) {
toUpdateKeys = ((DistroHttpCombinedKey) key).getActualResourceTypes();
} else {
toUpdateKeys = new ArrayList<>(1);
toUpdateKeys.add(key.getResourceKey());
}
byte[] queriedData = NamingProxy.getData(toUpdateKeys, key.getTargetServer());
return new DistroData(key, queriedData);
} catch (Exception e) {
throw new DistroException(String.format("Get data from %s failed.", key.getTargetServer()), e);
}
}
Aggregations