Search in sources :

Example 6 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class ClientBeatCheckTaskV2 method doHealthCheck.

@Override
public void doHealthCheck() {
    try {
        Collection<Service> services = client.getAllPublishedService();
        for (Service each : services) {
            HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) client.getInstancePublishInfo(each);
            interceptorChain.doInterceptor(new InstanceBeatCheckTask(client, each, instance));
        }
    } catch (Exception e) {
        Loggers.SRV_LOG.warn("Exception while processing client beat time out.", e);
    }
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Example 7 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class ClientBeatProcessorV2 method run.

@Override
public void run() {
    if (Loggers.EVT_LOG.isDebugEnabled()) {
        Loggers.EVT_LOG.debug("[CLIENT-BEAT] processing beat: {}", rsInfo.toString());
    }
    String ip = rsInfo.getIp();
    int port = rsInfo.getPort();
    String serviceName = NamingUtils.getServiceName(rsInfo.getServiceName());
    String groupName = NamingUtils.getGroupName(rsInfo.getServiceName());
    Service service = Service.newService(namespace, groupName, serviceName, rsInfo.isEphemeral());
    HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) client.getInstancePublishInfo(service);
    if (instance.getIp().equals(ip) && instance.getPort() == port) {
        if (Loggers.EVT_LOG.isDebugEnabled()) {
            Loggers.EVT_LOG.debug("[CLIENT-BEAT] refresh beat: {}", rsInfo);
        }
        instance.setLastHeartBeatTime(System.currentTimeMillis());
        if (!instance.isHealthy()) {
            instance.setHealthy(true);
            Loggers.EVT_LOG.info("service: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: client beat ok", rsInfo.getServiceName(), ip, port, rsInfo.getCluster(), UtilsAndCommons.LOCALHOST_SITE);
            NotifyCenter.publishEvent(new ServiceEvent.ServiceChangedEvent(service));
            NotifyCenter.publishEvent(new ClientEvent.ClientChangedEvent(client));
        }
    }
}
Also used : ServiceEvent(com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) ClientEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)

Example 8 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service 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 9 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class DoubleWriteInstanceChangeToV1Task method run.

@Override
public void run() {
    try {
        ServiceManager serviceManager = ApplicationUtils.getBean(ServiceManager.class);
        com.alibaba.nacos.naming.core.Service serviceV1 = serviceManager.getService(service.getNamespace(), service.getGroupedServiceName());
        if (null == serviceV1) {
            serviceManager.createEmptyService(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
        }
        Instances newInstances = getNewInstances();
        String key = KeyBuilder.buildInstanceListKey(service.getNamespace(), service.getGroupedServiceName(), service.isEphemeral());
        ConsistencyService consistencyService = ApplicationUtils.getBean(NAME, ConsistencyService.class);
        consistencyService.put(key, newInstances);
    } catch (Exception e) {
        if (Loggers.SRV_LOG.isDebugEnabled()) {
            Loggers.SRV_LOG.debug("Double write task for {} instance from 2 to 1 failed", service, e);
        }
        ServiceChangeV2Task retryTask = new ServiceChangeV2Task(service, DoubleWriteContent.INSTANCE);
        retryTask.setTaskInterval(INTERVAL);
        String taskKey = ServiceChangeV2Task.getKey(service);
        ApplicationUtils.getBean(DoubleWriteDelayTaskEngine.class).addTask(taskKey, retryTask);
    }
}
Also used : Instances(com.alibaba.nacos.naming.core.Instances) ServiceManager(com.alibaba.nacos.naming.core.ServiceManager) ServiceChangeV2Task(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV2Task) ConsistencyService(com.alibaba.nacos.naming.consistency.ConsistencyService)

Example 10 with Service

use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.

the class DoubleWriteInstanceChangeToV1Task method getNewInstances.

private Instances getNewInstances() {
    Instances result = new Instances();
    ServiceStorage serviceStorage = ApplicationUtils.getBean(ServiceStorage.class);
    InstanceUpgradeHelper instanceUpgradeHelper = ApplicationUtils.getBean(InstanceUpgradeHelper.class);
    long currentTimeStamp = System.currentTimeMillis();
    for (Instance each : serviceStorage.getData(service).getHosts()) {
        com.alibaba.nacos.naming.core.Instance instance = instanceUpgradeHelper.toV1(each);
        instance.setLastBeat(currentTimeStamp);
        result.getInstanceList().add(instance);
    }
    return result;
}
Also used : Instances(com.alibaba.nacos.naming.core.Instances) ServiceStorage(com.alibaba.nacos.naming.core.v2.index.ServiceStorage) Instance(com.alibaba.nacos.api.naming.pojo.Instance)

Aggregations

Service (com.alibaba.nacos.naming.core.v2.pojo.Service)75 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)20 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)19 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)17 Test (org.junit.Test)16 Instance (com.alibaba.nacos.api.naming.pojo.Instance)13 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)13 UdpPushService (com.alibaba.nacos.naming.push.UdpPushService)13 NacosException (com.alibaba.nacos.api.exception.NacosException)11 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)11 HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)11 HashSet (java.util.HashSet)11 Secured (com.alibaba.nacos.auth.annotation.Secured)10 Before (org.junit.Before)10 Client (com.alibaba.nacos.naming.core.v2.client.Client)9 ClientOperationEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientOperationEvent)8 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)8 InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)8 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)7 Set (java.util.Set)7