use of com.alibaba.nacos.naming.core.InstanceOperatorClientImpl in project nacos by alibaba.
the class DoubleWriteServiceRemovalToV2Task method run.
@Override
public void run() {
try {
InstanceOperatorClientImpl instanceOperator = ApplicationUtils.getBean(InstanceOperatorClientImpl.class);
ClientServiceIndexesManager clientServiceIndexesManager = ApplicationUtils.getBean(ClientServiceIndexesManager.class);
ServiceStorage serviceStorage = ApplicationUtils.getBean(ServiceStorage.class);
ServiceInfo serviceInfo = serviceStorage.getPushData(service);
for (Instance instance : serviceInfo.getHosts()) {
instanceOperator.removeInstance(service.getNamespace(), service.getName(), instance);
}
int count = 0;
while (!clientServiceIndexesManager.getAllClientsRegisteredService(service).isEmpty() && count < MAX_WAIT_TIMES) {
TimeUnit.MILLISECONDS.sleep(100);
count += 1;
}
clientServiceIndexesManager.removePublisherIndexesByEmptyService(service);
ServiceManager.getInstance().removeSingleton(service);
serviceStorage.removeData(service);
NotifyCenter.publishEvent(new MetadataEvent.ServiceMetadataEvent(service, true));
} catch (Exception e) {
if (Loggers.SRV_LOG.isDebugEnabled()) {
Loggers.SRV_LOG.debug("Double write removal of {} from 1 to 2 failed", service, e);
}
ServiceChangeV1Task retryTask = new ServiceChangeV1Task(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral(), DoubleWriteContent.BOTH, DoubleWriteAction.REMOVE);
retryTask.setTaskInterval(INTERVAL);
String taskKey = ServiceChangeV1Task.getKey(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
ApplicationUtils.getBean(DoubleWriteDelayTaskEngine.class).addTask(taskKey, retryTask);
}
}
Aggregations