Search in sources :

Example 1 with DistroKey

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

the class DistroDelayTaskProcessor method process.

@Override
public boolean process(NacosTask task) {
    if (!(task instanceof DistroDelayTask)) {
        return true;
    }
    DistroDelayTask distroDelayTask = (DistroDelayTask) task;
    DistroKey distroKey = distroDelayTask.getDistroKey();
    switch(distroDelayTask.getAction()) {
        case DELETE:
            DistroSyncDeleteTask syncDeleteTask = new DistroSyncDeleteTask(distroKey, distroComponentHolder);
            distroTaskEngineHolder.getExecuteWorkersManager().addTask(distroKey, syncDeleteTask);
            return true;
        case CHANGE:
        case ADD:
            DistroSyncChangeTask syncChangeTask = new DistroSyncChangeTask(distroKey, distroComponentHolder);
            distroTaskEngineHolder.getExecuteWorkersManager().addTask(distroKey, syncChangeTask);
            return true;
        default:
            return false;
    }
}
Also used : DistroSyncChangeTask(com.alibaba.nacos.core.distributed.distro.task.execute.DistroSyncChangeTask) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey) DistroSyncDeleteTask(com.alibaba.nacos.core.distributed.distro.task.execute.DistroSyncDeleteTask)

Example 2 with DistroKey

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

the class DistroProtocol method syncToTarget.

/**
 * Start to sync to target server.
 *
 * @param distroKey    distro key of sync data
 * @param action       the action of data operation
 * @param targetServer target server
 * @param delay        delay time for sync
 */
public void syncToTarget(DistroKey distroKey, DataOperation action, String targetServer, long delay) {
    DistroKey distroKeyWithTarget = new DistroKey(distroKey.getResourceKey(), distroKey.getResourceType(), targetServer);
    DistroDelayTask distroDelayTask = new DistroDelayTask(distroKeyWithTarget, action, delay);
    distroTaskEngineHolder.getDelayTaskExecuteEngine().addTask(distroKeyWithTarget, distroDelayTask);
    if (Loggers.DISTRO.isDebugEnabled()) {
        Loggers.DISTRO.debug("[DISTRO-SCHEDULE] {} to {}", distroKey, targetServer);
    }
}
Also used : DistroDelayTask(com.alibaba.nacos.core.distributed.distro.task.delay.DistroDelayTask) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey)

Example 3 with DistroKey

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

the class DistroHttpCombinedKeyDelayTask method getDistroKey.

@Override
public DistroKey getDistroKey() {
    DistroKey taskKey = super.getDistroKey();
    DistroHttpCombinedKey result = new DistroHttpCombinedKey(KeyBuilder.INSTANCE_LIST_KEY_PREFIX, taskKey.getTargetServer());
    result.setResourceKey(taskKey.getResourceKey());
    result.getActualResourceTypes().addAll(actualResourceKeys);
    return result;
}
Also used : DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey)

Example 4 with DistroKey

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

the class DistroHttpCombinedKeyTaskFailedHandler method retry.

@Override
public void retry(DistroKey distroKey, DataOperation action) {
    DistroHttpCombinedKey combinedKey = (DistroHttpCombinedKey) distroKey;
    for (String each : combinedKey.getActualResourceTypes()) {
        DistroKey newKey = new DistroKey(each, KeyBuilder.INSTANCE_LIST_KEY_PREFIX, distroKey.getTargetServer());
        DistroDelayTask newTask = new DistroDelayTask(newKey, action, DistroConfig.getInstance().getSyncRetryDelayMillis());
        distroTaskEngineHolder.getDelayTaskExecuteEngine().addTask(newKey, newTask);
    }
}
Also used : DistroDelayTask(com.alibaba.nacos.core.distributed.distro.task.delay.DistroDelayTask) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey)

Example 5 with DistroKey

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

the class DistroHttpDelayTaskProcessor method process.

@Override
public boolean process(NacosTask task) {
    DistroDelayTask distroDelayTask = (DistroDelayTask) task;
    DistroKey distroKey = distroDelayTask.getDistroKey();
    DistroHttpCombinedKeyExecuteTask executeTask = new DistroHttpCombinedKeyExecuteTask(globalConfig, distroTaskEngineHolder.getDelayTaskExecuteEngine(), distroKey, distroDelayTask.getAction());
    distroTaskEngineHolder.getExecuteWorkersManager().addTask(distroKey, executeTask);
    return true;
}
Also used : DistroDelayTask(com.alibaba.nacos.core.distributed.distro.task.delay.DistroDelayTask) DistroKey(com.alibaba.nacos.core.distributed.distro.entity.DistroKey)

Aggregations

DistroKey (com.alibaba.nacos.core.distributed.distro.entity.DistroKey)16 DistroData (com.alibaba.nacos.core.distributed.distro.entity.DistroData)5 Datum (com.alibaba.nacos.naming.consistency.Datum)4 Client (com.alibaba.nacos.naming.core.v2.client.Client)4 DistroDelayTask (com.alibaba.nacos.core.distributed.distro.task.delay.DistroDelayTask)3 BaseTest (com.alibaba.nacos.naming.BaseTest)2 Serializer (com.alibaba.nacos.naming.cluster.transport.Serializer)2 UpgradeJudgement (com.alibaba.nacos.naming.core.v2.upgrade.UpgradeJudgement)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 DistroSyncChangeTask (com.alibaba.nacos.core.distributed.distro.task.execute.DistroSyncChangeTask)1 DistroSyncDeleteTask (com.alibaba.nacos.core.distributed.distro.task.execute.DistroSyncDeleteTask)1 DistroDataResponse (com.alibaba.nacos.naming.cluster.remote.response.DistroDataResponse)1 ClientSyncData (com.alibaba.nacos.naming.core.v2.client.ClientSyncData)1 ClientSyncDatumSnapshot (com.alibaba.nacos.naming.core.v2.client.ClientSyncDatumSnapshot)1 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)1 HashMap (java.util.HashMap)1