use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroSyncDeleteTask method doExecuteWithCallback.
@Override
protected void doExecuteWithCallback(DistroCallback callback) {
String type = getDistroKey().getResourceType();
DistroData distroData = new DistroData();
distroData.setDistroKey(getDistroKey());
distroData.setType(OPERATION);
getDistroComponentHolder().findTransportAgent(type).syncData(distroData, getDistroKey().getTargetServer(), callback);
}
use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroSyncDeleteTask method doExecute.
@Override
protected boolean doExecute() {
String type = getDistroKey().getResourceType();
DistroData distroData = new DistroData();
distroData.setDistroKey(getDistroKey());
distroData.setType(OPERATION);
return getDistroComponentHolder().findTransportAgent(type).syncData(distroData, getDistroKey().getTargetServer());
}
use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroLoadDataTask method loadAllDataSnapshotFromRemote.
private boolean loadAllDataSnapshotFromRemote(String resourceType) {
DistroTransportAgent transportAgent = distroComponentHolder.findTransportAgent(resourceType);
DistroDataProcessor dataProcessor = distroComponentHolder.findDataProcessor(resourceType);
if (null == transportAgent || null == dataProcessor) {
Loggers.DISTRO.warn("[DISTRO-INIT] Can't find component for type {}, transportAgent: {}, dataProcessor: {}", resourceType, transportAgent, dataProcessor);
return false;
}
for (Member each : memberManager.allMembersWithoutSelf()) {
try {
Loggers.DISTRO.info("[DISTRO-INIT] load snapshot {} from {}", resourceType, each.getAddress());
DistroData distroData = transportAgent.getDatumSnapshot(each.getAddress());
boolean result = dataProcessor.processSnapshot(distroData);
Loggers.DISTRO.info("[DISTRO-INIT] load snapshot {} from {} result: {}", resourceType, each.getAddress(), result);
if (result) {
distroComponentHolder.findDataStorage(resourceType).finishInitial();
return true;
}
} catch (Exception e) {
Loggers.DISTRO.error("[DISTRO-INIT] load snapshot {} from {} failed.", resourceType, each.getAddress(), e);
}
}
return false;
}
use of com.alibaba.nacos.core.distributed.distro.entity.DistroData in project nacos by alibaba.
the class DistroDataRequestHandlerTest method testHandle.
@Test
public void testHandle() throws NacosException {
Mockito.when(distroProtocol.onVerify(Mockito.any(), Mockito.anyString())).thenReturn(false);
DistroDataRequest distroDataRequest = new DistroDataRequest();
distroDataRequest.setDataOperation(VERIFY);
RequestMeta requestMeta = new RequestMeta();
DistroDataResponse response = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertEquals(response.getErrorCode(), ResponseCode.FAIL.getCode());
DistroData distroData = new DistroData();
Mockito.when(distroProtocol.onSnapshot(Mockito.any())).thenReturn(distroData);
distroDataRequest.setDataOperation(SNAPSHOT);
DistroDataResponse response1 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertEquals(response1.getDistroData(), distroData);
distroDataRequest.setDataOperation(DELETE);
Mockito.when(distroProtocol.onReceive(Mockito.any())).thenReturn(false);
DistroDataResponse response2 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertEquals(response2.getErrorCode(), ResponseCode.FAIL.getCode());
distroDataRequest.setDataOperation(QUERY);
Mockito.when(distroProtocol.onQuery(Mockito.any())).thenReturn(distroData);
distroDataRequest.setDistroData(new DistroData());
DistroDataResponse response3 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertEquals(response3.getDistroData(), distroData);
distroDataRequest.setDataOperation(ADD);
DistroDataResponse response4 = distroDataRequestHandler.handle(distroDataRequest, requestMeta);
Assert.assertNull(response4.getDistroData());
}
Aggregations