Search in sources :

Example 26 with Instance

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);
}
Also used : Instance(com.tencent.polaris.api.pojo.Instance) URL(org.apache.dubbo.common.URL)

Example 27 with Instance

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);
}
Also used : Instance(com.tencent.polaris.api.pojo.Instance) ArrayList(java.util.ArrayList) URL(com.alibaba.dubbo.common.URL)

Example 28 with Instance

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;
}
Also used : ServiceInstances(com.tencent.polaris.api.pojo.ServiceInstances) ServiceInstance(org.springframework.cloud.client.ServiceInstance) Instance(com.tencent.polaris.api.pojo.Instance) ArrayList(java.util.ArrayList) ServiceInstance(org.springframework.cloud.client.ServiceInstance)

Example 29 with Instance

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;
}
Also used : ServiceInstances(com.tencent.polaris.api.pojo.ServiceInstances) Server(com.netflix.loadbalancer.Server) Instance(com.tencent.polaris.api.pojo.Instance) ArrayList(java.util.ArrayList)

Example 30 with Instance

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;
}
Also used : Instance(com.tencent.polaris.api.pojo.Instance) InstancesResponse(com.tencent.polaris.api.rpc.InstancesResponse)

Aggregations

Instance (com.tencent.polaris.api.pojo.Instance)53 ArrayList (java.util.ArrayList)15 InstancesResponse (com.tencent.polaris.api.rpc.InstancesResponse)14 ServiceInstances (com.tencent.polaris.api.pojo.ServiceInstances)12 Server (com.netflix.loadbalancer.Server)9 ConsumerAPI (com.tencent.polaris.api.core.ConsumerAPI)9 PolarisServer (com.tencent.cloud.common.pojo.PolarisServer)6 Configuration (com.tencent.polaris.api.config.Configuration)6 GetOneInstanceRequest (com.tencent.polaris.api.rpc.GetOneInstanceRequest)6 HashMap (java.util.HashMap)6 DefaultServiceInstances (com.tencent.polaris.api.pojo.DefaultServiceInstances)5 ServiceKey (com.tencent.polaris.api.pojo.ServiceKey)5 ServiceCallResult (com.tencent.polaris.api.rpc.ServiceCallResult)5 HashSet (java.util.HashSet)5 LinkedList (java.util.LinkedList)5 Map (java.util.Map)5 PolarisException (com.tencent.polaris.api.exception.PolarisException)4 ResultKey (com.tencent.polaris.api.plugin.circuitbreaker.CircuitBreakResult.ResultKey)4 DefaultInstance (com.tencent.polaris.api.pojo.DefaultInstance)4 StatusDimension (com.tencent.polaris.api.pojo.StatusDimension)4