Search in sources :

Example 1 with InstanceMetadata

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

the class ServiceStorage method parseInstance.

private Instance parseInstance(Service service, InstancePublishInfo instanceInfo) {
    Instance result = InstanceUtil.parseToApiInstance(service, instanceInfo);
    Optional<InstanceMetadata> metadata = metadataManager.getInstanceMetadata(service, instanceInfo.getMetadataId());
    metadata.ifPresent(instanceMetadata -> InstanceUtil.updateInstanceMetadata(result, instanceMetadata));
    return result;
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)

Example 2 with InstanceMetadata

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

the class InstanceMetadataProcessor method updateInstanceMetadata.

private void updateInstanceMetadata(MetadataOperation<InstanceMetadata> op) {
    Service service = Service.newService(op.getNamespace(), op.getGroup(), op.getServiceName());
    namingMetadataManager.updateInstanceMetadata(service, op.getTag(), op.getMetadata());
    NotifyCenter.publishEvent(new ServiceEvent.ServiceChangedEvent(service, true));
}
Also used : ServiceEvent(com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent) Service(com.alibaba.nacos.naming.core.v2.pojo.Service)

Example 3 with InstanceMetadata

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

the class InstanceMetadataProcessor method deleteInstanceMetadata.

private void deleteInstanceMetadata(MetadataOperation<InstanceMetadata> op) {
    Service service = Service.newService(op.getNamespace(), op.getGroup(), op.getServiceName());
    namingMetadataManager.removeInstanceMetadata(service, op.getTag());
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service)

Example 4 with InstanceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata 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 5 with InstanceMetadata

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

the class InstanceOperatorClientImpl method patchInstance.

@Override
public void patchInstance(String namespaceId, String serviceName, InstancePatchObject patchObject) throws NacosException {
    Service service = getService(namespaceId, serviceName, true);
    Instance instance = getInstance(namespaceId, serviceName, patchObject.getCluster(), patchObject.getIp(), patchObject.getPort());
    String metadataId = InstancePublishInfo.genMetadataId(instance.getIp(), instance.getPort(), instance.getClusterName());
    Optional<InstanceMetadata> instanceMetadata = metadataManager.getInstanceMetadata(service, metadataId);
    InstanceMetadata newMetadata = instanceMetadata.map(this::cloneMetadata).orElseGet(InstanceMetadata::new);
    mergeMetadata(newMetadata, patchObject);
    metadataOperateService.updateInstanceMetadata(service, metadataId, newMetadata);
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) NamingMetadataOperateService(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) UdpPushService(com.alibaba.nacos.naming.push.UdpPushService)

Aggregations

InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)12 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)9 Instance (com.alibaba.nacos.api.naming.pojo.Instance)5 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)4 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)4 UdpPushService (com.alibaba.nacos.naming.push.UdpPushService)4 Test (org.junit.Test)4 HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)2 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)2 LinkedList (java.util.LinkedList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Client (com.alibaba.nacos.naming.core.v2.client.Client)1 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)1 ServiceEvent (com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent)1 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)1 Field (java.lang.reflect.Field)1 HashMap (java.util.HashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Before (org.junit.Before)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1