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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations