use of com.tencent.polaris.api.pojo.Instance in project polaris-java-agent by polarismesh.
the class PolarisRegistry method onInstances.
private void onInstances(URL url, NotifyListener listener, Instance[] instances) {
LOGGER.info("[POLARIS] update instances count: {}, service: {}", null == instances ? 0 : instances.length, url.getServiceInterface());
List<URL> urls = new ArrayList<>();
if (null != instances) {
for (Instance instance : instances) {
urls.add(instanceToURL(instance));
}
}
PolarisRegistry.this.notify(url, listener, urls);
}
use of com.tencent.polaris.api.pojo.Instance in project polaris-java-agent by polarismesh.
the class PolarisRegistry method onInstances.
private void onInstances(URL url, NotifyListener listener, Instance[] instances) {
LOGGER.info("[POLARIS] update instances count: {}, service: {}", null == instances ? 0 : instances.length, url.getServiceInterface());
List<URL> urls = new ArrayList<>();
if (null != instances) {
for (Instance instance : instances) {
urls.add(instanceToURL(instance));
}
}
PolarisRegistry.this.notify(url, listener, urls);
}
use of com.tencent.polaris.api.pojo.Instance in project polaris-java-agent by polarismesh.
the class PolarisServiceDiscovery method getInstances.
/**
* Return all instances for the given service.
*
* @param serviceId id of service
* @return list of instances
* @throws PolarisException polarisException
*/
public List<ServiceInstance> getInstances(String serviceId) throws PolarisException {
LogUtils.logInvoke(this, "getInstances");
List<ServiceInstance> instances = new ArrayList<>();
ServiceInstances serviceInstances = polarisDiscoveryHandler.getFilteredInstances(serviceId);
for (Instance instance : serviceInstances.getInstances()) {
instances.add(new PolarisServiceInstance(instance));
}
return instances;
}
use of com.tencent.polaris.api.pojo.Instance in project polaris-java-agent by polarismesh.
the class PolarisServerList method getServers.
private List<Server> getServers() {
ServiceInstances serviceInstances = polarisDiscoveryHandler.getFilteredInstances(serviceId);
List<Server> polarisServers = new ArrayList<>();
for (Instance instance : serviceInstances.getInstances()) {
polarisServers.add(new PolarisServer(serviceInstances, instance));
}
return polarisServers;
}
use of com.tencent.polaris.api.pojo.Instance in project polaris-java-agent by polarismesh.
the class PolarisServiceRegistry method getStatus.
@Override
public Object getStatus(Registration registration) {
String serviceName = registration.getServiceId();
InstancesResponse instancesResponse = polarisDiscoveryHandler.getInstances(serviceName);
Instance[] instances = instancesResponse.getInstances();
if (null == instances || instances.length == 0) {
return null;
}
for (Instance instance : instances) {
if (instance.getHost().equalsIgnoreCase(registration.getHost()) && instance.getPort() == polarisProperties.getPort()) {
return instance.isHealthy() ? "UP" : "DOWN";
}
}
return null;
}
Aggregations