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