use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.
the class HealthCheckTaskV2 method getClusterMetadata.
private ClusterMetadata getClusterMetadata(Service service, InstancePublishInfo instancePublishInfo) {
Optional<ServiceMetadata> serviceMetadata = metadataManager.getServiceMetadata(service);
if (!serviceMetadata.isPresent()) {
return new ClusterMetadata();
}
String cluster = instancePublishInfo.getCluster();
ClusterMetadata result = serviceMetadata.get().getClusters().get(cluster);
return null == result ? new ClusterMetadata() : result;
}
use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.
the class DefaultServiceMetadataUpgradeHelper method toV2ServiceMetadata.
@Override
public ServiceMetadata toV2ServiceMetadata(Service service, boolean ephemeral) {
ServiceMetadata result = new ServiceMetadata();
result.setEphemeral(ephemeral);
result.setProtectThreshold(service.getProtectThreshold());
result.setSelector(service.getSelector());
result.setExtendData(service.getMetadata());
for (Map.Entry<String, Cluster> entry : service.getClusterMap().entrySet()) {
result.getClusters().put(entry.getKey(), toV2ClusterMetadata(entry.getValue()));
}
return result;
}
use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata 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.ServiceMetadata in project nacos by alibaba.
the class NamingMetadataManager method loadServiceMetadataSnapshot.
/**
* Load service metadata snapshot.
*
* <p>Service metadata need load back the service.
*
* @param snapshot snapshot
*/
public void loadServiceMetadataSnapshot(ConcurrentMap<Service, ServiceMetadata> snapshot) {
for (Service each : snapshot.keySet()) {
ServiceManager.getInstance().getSingleton(each);
}
ConcurrentMap<Service, ServiceMetadata> oldSnapshot = serviceMetadataMap;
serviceMetadataMap = snapshot;
oldSnapshot.clear();
}
use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.
the class ServiceMetadataProcessor method updateServiceMetadata.
private void updateServiceMetadata(MetadataOperation<ServiceMetadata> op) {
Service service = Service.newService(op.getNamespace(), op.getGroup(), op.getServiceName(), op.getMetadata().isEphemeral());
Optional<ServiceMetadata> currentMetadata = namingMetadataManager.getServiceMetadata(service);
if (currentMetadata.isPresent()) {
ServiceMetadata newMetadata = mergeMetadata(currentMetadata.get(), op.getMetadata());
Service singleton = ServiceManager.getInstance().getSingleton(service);
namingMetadataManager.updateServiceMetadata(singleton, newMetadata);
} else {
Service singleton = ServiceManager.getInstance().getSingleton(service);
namingMetadataManager.updateServiceMetadata(singleton, op.getMetadata());
}
doubleWriteMetadata(service, false);
}
Aggregations