Search in sources :

Example 21 with DistroData

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);
}
Also used : DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 22 with DistroData

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());
}
Also used : DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 23 with DistroData

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;
}
Also used : DistroTransportAgent(com.alibaba.nacos.core.distributed.distro.component.DistroTransportAgent) DistroDataProcessor(com.alibaba.nacos.core.distributed.distro.component.DistroDataProcessor) Member(com.alibaba.nacos.core.cluster.Member) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData)

Example 24 with DistroData

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());
}
Also used : DistroDataRequest(com.alibaba.nacos.naming.cluster.remote.request.DistroDataRequest) RequestMeta(com.alibaba.nacos.api.remote.request.RequestMeta) DistroDataResponse(com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse) DistroData(com.alibaba.nacos.core.distributed.distro.entity.DistroData) Test(org.junit.Test)

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