Search in sources :

Example 1 with InstanceOperatorClientImpl

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);
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ServiceStorage(com.alibaba.nacos.naming.core.v2.index.ServiceStorage) Instance(com.alibaba.nacos.api.naming.pojo.Instance) MetadataEvent(com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent) ClientServiceIndexesManager(com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager) ServiceChangeV1Task(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task) InstanceOperatorClientImpl(com.alibaba.nacos.naming.core.InstanceOperatorClientImpl)

Aggregations

Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)1 InstanceOperatorClientImpl (com.alibaba.nacos.naming.core.InstanceOperatorClientImpl)1 MetadataEvent (com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent)1 ClientServiceIndexesManager (com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager)1 ServiceStorage (com.alibaba.nacos.naming.core.v2.index.ServiceStorage)1 ServiceChangeV1Task (com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task)1