use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class SpringCloudInnerDiscoveryService method getServiceInstances.
@Override
public List<ServiceDTO> getServiceInstances(String serviceId) {
List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
List<ServiceDTO> serviceDTOList = Lists.newLinkedList();
if (!CollectionUtils.isEmpty(instances)) {
instances.forEach(instance -> {
ServiceDTO serviceDTO = this.toServiceDTO(instance, serviceId);
serviceDTOList.add(serviceDTO);
});
}
return serviceDTOList;
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class SpringCloudInnerDiscoveryService method toServiceDTO.
private ServiceDTO toServiceDTO(ServiceInstance instance, String appName) {
ServiceDTO service = new ServiceDTO();
service.setAppName(appName);
service.setInstanceId(instance.getInstanceId());
String homePageUrl = "http://" + instance.getHost() + ":" + instance.getPort() + "/";
service.setHomepageUrl(homePageUrl);
return service;
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class HomePageControllerTest method testListAllServices.
@Test
public void testListAllServices() {
ServiceDTO someServiceDto = mock(ServiceDTO.class);
ServiceDTO anotherServiceDto = mock(ServiceDTO.class);
when(discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE)).thenReturn(Lists.newArrayList(someServiceDto));
when(discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_ADMINSERVICE)).thenReturn(Lists.newArrayList(anotherServiceDto));
List<ServiceDTO> allServices = homePageController.listAllServices();
assertEquals(2, allServices.size());
assertSame(someServiceDto, allServices.get(0));
assertSame(anotherServiceDto, allServices.get(1));
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class KubernetesDiscoveryServiceTest method testGetConfigServiceInstances.
@Test
public void testGetConfigServiceInstances() {
String someUrl = "http://some-host/some-path";
when(bizConfig.getValue(configServiceConfigName)).thenReturn(someUrl);
List<ServiceDTO> serviceDTOList = kubernetesDiscoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE);
assertEquals(1, serviceDTOList.size());
ServiceDTO serviceDTO = serviceDTOList.get(0);
assertEquals(ServiceNameConsts.APOLLO_CONFIGSERVICE, serviceDTO.getAppName());
assertEquals(String.format("%s:%s", ServiceNameConsts.APOLLO_CONFIGSERVICE, someUrl), serviceDTO.getInstanceId());
assertEquals(someUrl, serviceDTO.getHomepageUrl());
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class ZookeeperDiscoveryServiceTest method testGetServiceInstances.
@Test
public void testGetServiceInstances() {
String someIp = "1.2.3.4";
int somePort = 8080;
String someInstanceId = "someInstanceId";
ServiceInstance someServiceInstance = mockServiceInstance(someInstanceId, someIp, somePort);
when(zookeeperDiscoveryClient.getInstances(someServiceId)).thenReturn(Lists.newArrayList(someServiceInstance));
List<ServiceDTO> serviceDTOList = zookeeperDiscoveryService.getServiceInstances(someServiceId);
ServiceDTO serviceDTO = serviceDTOList.get(0);
assertEquals(1, serviceDTOList.size());
assertEquals(someServiceId, serviceDTO.getAppName());
assertEquals("http://1.2.3.4:8080/", serviceDTO.getHomepageUrl());
}
Aggregations