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