Search in sources :

Example 1 with ServiceMetadata

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;
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Example 2 with ServiceMetadata

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;
}
Also used : Cluster(com.alibaba.nacos.naming.core.Cluster) Map(java.util.Map) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Example 3 with ServiceMetadata

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);
    }
}
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 4 with ServiceMetadata

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();
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service)

Example 5 with ServiceMetadata

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);
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service)

Aggregations

ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)33 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)18 Test (org.junit.Test)13 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)11 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)8 NacosException (com.alibaba.nacos.api.exception.NacosException)7 Secured (com.alibaba.nacos.auth.annotation.Secured)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Instance (com.alibaba.nacos.api.naming.pojo.Instance)5 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 Before (org.junit.Before)4 ServiceDetailInfo (com.alibaba.nacos.naming.pojo.ServiceDetailInfo)3 HashMap (java.util.HashMap)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)3 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)2 Serializer (com.alibaba.nacos.consistency.Serializer)2 Cluster (com.alibaba.nacos.naming.core.Cluster)2 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)2 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)2