Search in sources :

Example 21 with ServiceDTO

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;
}
Also used : ServiceInstance(org.springframework.cloud.client.ServiceInstance) ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO)

Example 22 with ServiceDTO

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;
}
Also used : ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO)

Example 23 with ServiceDTO

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));
}
Also used : ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) Test(org.junit.Test)

Example 24 with ServiceDTO

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());
}
Also used : ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) Test(org.junit.Test)

Example 25 with ServiceDTO

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());
}
Also used : ServiceInstance(org.springframework.cloud.client.ServiceInstance) ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) Test(org.junit.Test)

Aggregations

ServiceDTO (com.ctrip.framework.apollo.core.dto.ServiceDTO)27 Test (org.junit.Test)7 Transaction (com.ctrip.framework.apollo.tracer.spi.Transaction)5 InstanceInfo (com.netflix.appinfo.InstanceInfo)4 ServiceException (com.ctrip.framework.apollo.common.exception.ServiceException)3 HttpRequest (com.ctrip.framework.apollo.util.http.HttpRequest)3 List (java.util.List)3 Function (java.util.function.Function)3 ServiceInstance (org.springframework.cloud.client.ServiceInstance)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ApolloConfigException (com.ctrip.framework.apollo.exceptions.ApolloConfigException)2 Before (org.junit.Before)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)1 ApolloConfigStatusCodeException (com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException)1 EnvironmentInfo (com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo)1 Env (com.ctrip.framework.apollo.portal.environment.Env)1 OrderedProperties (com.ctrip.framework.apollo.util.OrderedProperties)1 HttpResponse (com.ctrip.framework.apollo.util.http.HttpResponse)1