Search in sources :

Example 1 with ClientServiceIndexesManager

use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.

the class ServiceStorageTest method setUp.

@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
    serviceStorage = new ServiceStorage(clientServiceIndexesManager, clientManagerDelegate, switchDomain, namingMetadataManager);
    Field serviceClusterIndex = ServiceStorage.class.getDeclaredField("serviceClusterIndex");
    serviceClusterIndex.setAccessible(true);
    ConcurrentMap<Service, Set<String>> serviceSetConcurrentMap = (ConcurrentMap<Service, Set<String>>) serviceClusterIndex.get(serviceStorage);
    serviceSetConcurrentMap.put(SERVICE, new HashSet<>(Collections.singletonList(NACOS)));
    Field serviceDataIndexes = ServiceStorage.class.getDeclaredField("serviceDataIndexes");
    serviceDataIndexes.setAccessible(true);
    ConcurrentMap<Service, ServiceInfo> infoConcurrentMap = (ConcurrentMap<Service, ServiceInfo>) serviceDataIndexes.get(serviceStorage);
    infoConcurrentMap.put(SERVICE, serviceInfo);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Field(java.lang.reflect.Field) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentMap(java.util.concurrent.ConcurrentMap) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Before(org.junit.Before)

Example 2 with ClientServiceIndexesManager

use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.

the class ClientServiceIndexesManagerTest method setUp.

@Before
public void setUp() throws NoSuchFieldException, IllegalAccessException {
    clientServiceIndexesManager = new ClientServiceIndexesManager();
    Class<ClientServiceIndexesManager> clientServiceIndexesManagerClass = ClientServiceIndexesManager.class;
    Field publisherIndexesField = clientServiceIndexesManagerClass.getDeclaredField("publisherIndexes");
    publisherIndexesField.setAccessible(true);
    ConcurrentMap<Service, Set<String>> publisherIndexes = (ConcurrentMap<Service, Set<String>>) publisherIndexesField.get(clientServiceIndexesManager);
    publisherIndexes.put(service, new HashSet<>(Collections.singletonList(NACOS)));
    Field subscriberIndexesField = clientServiceIndexesManagerClass.getDeclaredField("subscriberIndexes");
    subscriberIndexesField.setAccessible(true);
    ConcurrentMap<Service, Set<String>> subscriberIndexes = (ConcurrentMap<Service, Set<String>>) subscriberIndexesField.get(clientServiceIndexesManager);
    subscriberIndexes.put(service, new HashSet<>(Collections.singletonList(NACOS)));
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentMap(java.util.concurrent.ConcurrentMap) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Before(org.junit.Before)

Example 3 with ClientServiceIndexesManager

use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.

the class EmptyServiceAutoCleanerV2Test method setUp.

@Before
public void setUp() {
    EnvUtil.setEnvironment(new MockEnvironment());
    emptyServiceAutoCleanerV2 = new EmptyServiceAutoCleanerV2(clientServiceIndexesManager, serviceStorage);
    Mockito.when(service.getNamespace()).thenReturn("public");
    ServiceManager serviceManager = ServiceManager.getInstance();
    serviceManager.getSingleton(service);
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) ServiceManager(com.alibaba.nacos.naming.core.v2.ServiceManager) Before(org.junit.Before)

Example 4 with ClientServiceIndexesManager

use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager 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)

Example 5 with ClientServiceIndexesManager

use of com.alibaba.nacos.naming.core.v2.index.ClientServiceIndexesManager in project nacos by alibaba.

the class ClientServiceIndexesManagerTest method testRemovePublisherIndexesByEmptyService.

@Test
public void testRemovePublisherIndexesByEmptyService() throws NoSuchFieldException, IllegalAccessException {
    clientServiceIndexesManager.removePublisherIndexesByEmptyService(service);
    Class<ClientServiceIndexesManager> clientServiceIndexesManagerClass = ClientServiceIndexesManager.class;
    Field publisherIndexesField = clientServiceIndexesManagerClass.getDeclaredField("publisherIndexes");
    publisherIndexesField.setAccessible(true);
    ConcurrentMap<Service, Set<String>> publisherIndexes = (ConcurrentMap<Service, Set<String>>) publisherIndexesField.get(clientServiceIndexesManager);
    Assert.assertEquals(publisherIndexes.size(), 1);
}
Also used : Field(java.lang.reflect.Field) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentMap(java.util.concurrent.ConcurrentMap) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) Test(org.junit.Test)

Aggregations

Service (com.alibaba.nacos.naming.core.v2.pojo.Service)3 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 Before (org.junit.Before)3 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)2 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 InstanceOperatorClientImpl (com.alibaba.nacos.naming.core.InstanceOperatorClientImpl)1 ServiceManager (com.alibaba.nacos.naming.core.v2.ServiceManager)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 Test (org.junit.Test)1 MockEnvironment (org.springframework.mock.env.MockEnvironment)1