Search in sources :

Example 51 with Instance

use of com.tencent.polaris.api.pojo.Instance in project polaris-java by polarismesh.

the class RuleBasedRouter method getInstancesOfEnv.

private List<Instance> getInstancesOfEnv(ServiceInstances serviceInstances, String env) {
    List<Instance> instances = serviceInstances.getInstances();
    List<Instance> retInstances = new ArrayList<>();
    for (Instance ins : instances) {
        if (env.equals(ins.getMetadata().get("env"))) {
            retInstances.add(ins);
        }
    }
    return retInstances;
}
Also used : Instance(com.tencent.polaris.api.pojo.Instance) ArrayList(java.util.ArrayList)

Example 52 with Instance

use of com.tencent.polaris.api.pojo.Instance in project sofa-rpc by sofastack.

the class PolarisWatcher method currentProviders.

public List<ProviderInfo> currentProviders() {
    List<ProviderInfo> providerInfos = new ArrayList<>();
    Instance[] instances = currentData.getInstances();
    for (Instance instance : instances) {
        ProviderInfo providerInfo = ProviderHelper.toProviderInfo(convertInstanceToUrl(instance.getHost(), instance.getPort(), currentData.getMetadata()));
        providerInfos.add(providerInfo);
    }
    return providerInfos;
}
Also used : ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) Instance(com.tencent.polaris.api.pojo.Instance) ArrayList(java.util.ArrayList)

Example 53 with Instance

use of com.tencent.polaris.api.pojo.Instance in project polaris-java-agent by polarismesh.

the class PolarisLoadBalance method doSelect.

@SuppressWarnings("unchecked")
@Override
protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation invocation) {
    if (null == invokers || invokers.size() == 0) {
        return null;
    }
    String service = url.getServiceInterface();
    LOGGER.info("[POLARIS] select instance for service {} by PolarisLoadBalance", service);
    String key = invokers.get(0).getUrl().getServiceKey() + "." + invocation.getMethodName();
    List<Instance> instances = (List<Instance>) ((List<?>) invokers);
    Instance instance = PolarisSingleton.getPolarisOperator().loadBalance(service, key, instances);
    return (InstanceInvoker<T>) instance;
}
Also used : Instance(com.tencent.polaris.api.pojo.Instance) List(java.util.List) InstanceInvoker(cn.polarismesh.agent.plugin.dubbox.entity.InstanceInvoker)

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