use of com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV2Task in project nacos by alibaba.
the class DoubleWriteInstanceChangeToV1Task method run.
@Override
public void run() {
try {
ServiceManager serviceManager = ApplicationUtils.getBean(ServiceManager.class);
com.alibaba.nacos.naming.core.Service serviceV1 = serviceManager.getService(service.getNamespace(), service.getGroupedServiceName());
if (null == serviceV1) {
serviceManager.createEmptyService(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
}
Instances newInstances = getNewInstances();
String key = KeyBuilder.buildInstanceListKey(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
ConsistencyService consistencyService = ApplicationUtils.getBean(NAME, ConsistencyService.class);
consistencyService.put(key, newInstances);
} catch (Exception e) {
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("Double write task for {} instance from 2 to 1 failed", service, e);
}
ServiceChangeV2Task retryTask = new ServiceChangeV2Task(service, DoubleWriteContent.INSTANCE);
retryTask.setTaskInterval(INTERVAL);
String taskKey = ServiceChangeV2Task.getKey(service);
ApplicationUtils.getBean(DoubleWriteDelayTaskEngine.class).addTask(taskKey, retryTask);
}
}
use of com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV2Task in project nacos by alibaba.
the class DoubleWriteMetadataChangeToV1Task method run.
@Override
public void run() {
try {
NamingMetadataManager metadataManager = ApplicationUtils.getBean(NamingMetadataManager.class);
Optional<ServiceMetadata> serviceMetadata = metadataManager.getServiceMetadata(service);
if (!serviceMetadata.isPresent()) {
return;
}
ServiceManager serviceManager = ApplicationUtils.getBean(ServiceManager.class);
com.alibaba.nacos.naming.core.Service serviceV1 = newServiceForV1(serviceManager, serviceMetadata.get());
serviceManager.addOrReplaceService(serviceV1);
} catch (Exception e) {
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("Double write task for {} metadata from 2 to 1 failed", service, e);
}
ServiceChangeV2Task retryTask = new ServiceChangeV2Task(service, DoubleWriteContent.METADATA);
retryTask.setTaskInterval(INTERVAL);
String taskKey = ServiceChangeV2Task.getKey(service);
ApplicationUtils.getBean(DoubleWriteDelayTaskEngine.class).addTask(taskKey, retryTask);
}
}
use of com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV2Task in project nacos by alibaba.
the class DoubleWriteServiceRemovalToV1Task method run.
@Override
public void run() {
try {
ServiceManager serviceManager = ApplicationUtils.getBean(ServiceManager.class);
com.alibaba.nacos.naming.core.Service serviceV1 = serviceManager.getService(service.getNamespace(), service.getGroupedServiceName());
if (serviceV1 == null) {
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("Double write task is removing a non-exist service: {}", service);
}
return;
}
ConsistencyService consistencyService = ApplicationUtils.getBean("consistencyDelegate", ConsistencyService.class);
// remove instances
String instanceListKey = KeyBuilder.buildInstanceListKey(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
consistencyService.remove(instanceListKey);
// remove metadata
serviceManager.easyRemoveService(service.getNamespace(), service.getGroupedServiceName());
} catch (Exception e) {
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("Double write task for removal of {} from 2 to 1 failed", service, e);
}
ServiceChangeV2Task retryTask = new ServiceChangeV2Task(service, DoubleWriteContent.BOTH, DoubleWriteAction.REMOVE);
retryTask.setTaskInterval(INTERVAL);
String taskKey = ServiceChangeV2Task.getKey(service);
ApplicationUtils.getBean(DoubleWriteDelayTaskEngine.class).addTask(taskKey, retryTask);
}
}
Aggregations