Search in sources :

Example 1 with NamingMetadataManager

use of com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager 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);
    }
}
Also used : ServiceManager(com.alibaba.nacos.naming.core.ServiceManager) ServiceChangeV2Task(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV2Task) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) NamingMetadataManager(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)

Example 2 with NamingMetadataManager

use of com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager in project nacos by alibaba.

the class InstanceEnableBeatCheckInterceptor method intercept.

@Override
public boolean intercept(InstanceBeatCheckTask object) {
    NamingMetadataManager metadataManager = ApplicationUtils.getBean(NamingMetadataManager.class);
    HealthCheckInstancePublishInfo instance = object.getInstancePublishInfo();
    Optional<InstanceMetadata> metadata = metadataManager.getInstanceMetadata(object.getService(), instance.getMetadataId());
    if (metadata.isPresent() && metadata.get().getExtendData().containsKey(UtilsAndCommons.ENABLE_CLIENT_BEAT)) {
        return ConvertUtils.toBoolean(metadata.get().getExtendData().get(UtilsAndCommons.ENABLE_CLIENT_BEAT).toString());
    }
    if (instance.getExtendDatum().containsKey(UtilsAndCommons.ENABLE_CLIENT_BEAT)) {
        return ConvertUtils.toBoolean(instance.getExtendDatum().get(UtilsAndCommons.ENABLE_CLIENT_BEAT).toString());
    }
    return false;
}
Also used : InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) NamingMetadataManager(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)

Example 3 with NamingMetadataManager

use of com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager in project nacos by alibaba.

the class ServiceEnableBeatCheckInterceptor method intercept.

@Override
public boolean intercept(InstanceBeatCheckTask object) {
    NamingMetadataManager metadataManager = ApplicationUtils.getBean(NamingMetadataManager.class);
    Optional<ServiceMetadata> metadata = metadataManager.getServiceMetadata(object.getService());
    if (metadata.isPresent() && metadata.get().getExtendData().containsKey(UtilsAndCommons.ENABLE_CLIENT_BEAT)) {
        return Boolean.parseBoolean(metadata.get().getExtendData().get(UtilsAndCommons.ENABLE_CLIENT_BEAT));
    }
    return false;
}
Also used : ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) NamingMetadataManager(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)

Example 4 with NamingMetadataManager

use of com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager in project nacos by alibaba.

the class HealthCheckTaskInterceptWrapperTest method setUp.

@Before
public void setUp() throws Exception {
    when(applicationContext.getBean(NamingMetadataManager.class)).thenReturn(namingMetadataManager);
    when(applicationContext.getBean(GlobalConfig.class)).thenReturn(globalConfig);
    when(applicationContext.getBean(SwitchDomain.class)).thenReturn(switchDomain);
    when(applicationContext.getBean(DistroMapper.class)).thenReturn(distroMapper);
    when(applicationContext.getBean(UpgradeJudgement.class)).thenReturn(upgradeJudgement);
    ApplicationUtils.injectContext(applicationContext);
    client = new IpPortBasedClient(CLIENT_ID, true);
    when(switchDomain.isHealthCheckEnabled()).thenReturn(true);
    when(distroMapper.responsible(client.getResponsibleId())).thenReturn(true);
    when(upgradeJudgement.isUseGrpcFeatures()).thenReturn(true);
    ClientBeatCheckTaskV2 beatCheckTask = new ClientBeatCheckTaskV2(client);
    taskWrapper = new HealthCheckTaskInterceptWrapper(beatCheckTask);
}
Also used : ClientBeatCheckTaskV2(com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatCheckTaskV2) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Before(org.junit.Before)

Example 5 with NamingMetadataManager

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

Aggregations

Before (org.junit.Before)5 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)4 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)3 Field (java.lang.reflect.Field)3 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)2 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)1 Serializer (com.alibaba.nacos.consistency.Serializer)1 Response (com.alibaba.nacos.consistency.entity.Response)1 WriteRequest (com.alibaba.nacos.consistency.entity.WriteRequest)1 ServiceManager (com.alibaba.nacos.naming.core.ServiceManager)1 InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)1 HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)1 ServiceChangeV2Task (com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV2Task)1 ClientBeatCheckTaskV2 (com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatCheckTaskV2)1 SwitchDomain (com.alibaba.nacos.naming.misc.SwitchDomain)1 ByteString (com.google.protobuf.ByteString)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1