Search in sources :

Example 1 with ServiceInstance

use of org.apache.dubbo.registry.client.ServiceInstance in project incubator-dubbo-ops by apache.

the class InstanceRegistryQueryHelper method urlsToProviderList.

private List<Provider> urlsToProviderList(List<InstanceAddressURL> urls) {
    List<Provider> providers = Lists.newArrayList();
    urls.stream().distinct().forEach(url -> {
        ServiceInstance instance = url.getInstance();
        MetadataInfo metadataInfo = url.getMetadataInfo();
        metadataInfo.getServices().forEach((serviceKey, serviceInfo) -> {
            Provider p = new Provider();
            String service = serviceInfo.getServiceKey();
            p.setService(service);
            p.setAddress(url.getAddress());
            p.setApplication(instance.getServiceName());
            p.setUrl(url.toParameterString());
            p.setDynamic(url.getParameter("dynamic", true));
            p.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
            p.setWeight(url.getParameter(Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT));
            p.setUsername(url.getParameter("owner"));
            p.setRegistrySource(RegistrySource.INSTANCE);
            providers.add(p);
        });
    });
    return providers;
}
Also used : MetadataInfo(org.apache.dubbo.metadata.MetadataInfo) ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) Provider(org.apache.dubbo.admin.model.domain.Provider)

Example 2 with ServiceInstance

use of org.apache.dubbo.registry.client.ServiceInstance in project incubator-dubbo-ops by apache.

the class AdminMappingListener method onEvent.

@Override
public void onEvent(MappingChangedEvent event) {
    Set<String> apps = event.getApps();
    if (CollectionUtils.isEmpty(apps)) {
        return;
    }
    for (String serviceName : apps) {
        ServiceInstancesChangedListener serviceInstancesChangedListener = serviceListeners.get(serviceName);
        if (serviceInstancesChangedListener == null) {
            synchronized (this) {
                serviceInstancesChangedListener = serviceListeners.get(serviceName);
                if (serviceInstancesChangedListener == null) {
                    AddressChangeListener addressChangeListener = new DefaultAddressChangeListener(serviceName, instanceRegistryCache);
                    serviceInstancesChangedListener = new AdminServiceInstancesChangedListener(Sets.newHashSet(serviceName), serviceDiscovery, addressChangeListener);
                    serviceInstancesChangedListener.setUrl(CONSUMER_URL);
                    List<ServiceInstance> serviceInstances = serviceDiscovery.getInstances(serviceName);
                    if (CollectionUtils.isNotEmpty(serviceInstances)) {
                        serviceInstancesChangedListener.onEvent(new ServiceInstancesChangedEvent(serviceName, serviceInstances));
                    }
                    serviceListeners.put(serviceName, serviceInstancesChangedListener);
                    serviceInstancesChangedListener.setUrl(CONSUMER_URL);
                    serviceDiscovery.addServiceInstancesChangedListener(serviceInstancesChangedListener);
                }
            }
        }
    }
}
Also used : ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) ServiceInstancesChangedEvent(org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent) ServiceInstancesChangedListener(org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener)

Example 3 with ServiceInstance

use of org.apache.dubbo.registry.client.ServiceInstance in project dubbo by alibaba.

the class EtcdServiceDiscovery method getInstances.

@Override
public List<ServiceInstance> getInstances(String serviceName) {
    List<String> children = etcdClient.getChildren(toParentPath(serviceName));
    if (CollectionUtils.isEmpty(children)) {
        return Collections.EMPTY_LIST;
    }
    List<ServiceInstance> list = new ArrayList<>(children.size());
    for (String child : children) {
        ServiceInstance serviceInstance = new Gson().fromJson(etcdClient.getKVValue(child), DefaultServiceInstance.class);
        list.add(serviceInstance);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) Gson(com.google.gson.Gson)

Example 4 with ServiceInstance

use of org.apache.dubbo.registry.client.ServiceInstance in project dubbo by alibaba.

the class EtcdServiceDiscoveryTest method testRegistry.

@Test
public void testRegistry() throws Exception {
    ServiceInstance serviceInstance = new DefaultServiceInstance(valueOf(System.nanoTime()), "EtcdTestService", "127.0.0.1", 8080);
    Assertions.assertNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
    etcdServiceDiscovery.register(serviceInstance);
    Assertions.assertNotNull(etcdServiceDiscovery.etcdClient.getKVValue(etcdServiceDiscovery.toPath(serviceInstance)));
}
Also used : DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) Test(org.junit.jupiter.api.Test)

Example 5 with ServiceInstance

use of org.apache.dubbo.registry.client.ServiceInstance in project dubbo by alibaba.

the class EurekaServiceDiscovery method getInstances.

@Override
public List<ServiceInstance> getInstances(String serviceName) throws NullPointerException {
    Application application = this.eurekaClient.getApplication(serviceName);
    if (application == null) {
        return emptyList();
    }
    List<InstanceInfo> infos = application.getInstances();
    List<ServiceInstance> instances = new ArrayList<>();
    for (InstanceInfo info : infos) {
        instances.add(buildServiceInstance(info));
    }
    return instances;
}
Also used : ArrayList(java.util.ArrayList) ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

ServiceInstance (org.apache.dubbo.registry.client.ServiceInstance)16 DefaultServiceInstance (org.apache.dubbo.registry.client.DefaultServiceInstance)11 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)4 ServiceInstancesChangedEvent (org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent)4 Instance (com.alibaba.nacos.api.naming.pojo.Instance)3 LinkedList (java.util.LinkedList)3 ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener)3 HashMap (java.util.HashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 URL (org.apache.dubbo.common.URL)2 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)2 NacosNamingServiceUtils.toInstance (org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.toInstance)2 Gson (com.google.gson.Gson)1 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 Application (com.netflix.discovery.shared.Application)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1