##### Coverage Report - com.ctrip.framework.apollo.metaservice.controller.ServiceController

Classes in this File | Line Coverage | Branch Coverage | Complexity
ServiceController |
7% | 1/13
N/A | N/A
| 1.0;1
ServiceController$1 |
0% | 0/6
N/A | N/A
| 1.0;1
ServiceController$2 |
0% | 0/6
N/A | N/A
| 1.0;1
ServiceController$3 |
0% | 0/6
N/A | N/A
| 1.0;1

1 |  |
     package com.ctrip.framework.apollo.metaservice.controller;
2 |  |
3 |  |
     import com.ctrip.framework.apollo.core.dto.ServiceDTO;
4 |  |
     import com.ctrip.framework.apollo.metaservice.service.DiscoveryService;
5 |  |
     import com.netflix.appinfo.InstanceInfo;
6 |  |
7 |  |
     import org.springframework.beans.factory.annotation.Autowired;
8 |  |
     import org.springframework.web.bind.annotation.RequestMapping;
9 |  |
     import org.springframework.web.bind.annotation.RequestParam;
10 |  |
     import org.springframework.web.bind.annotation.RestController;
11 |  |
12 |  |
     import java.util.List;
13 |  |
     import java.util.function.Function;
14 |  |
     import java.util.stream.Collectors;
15 |  |
16 |  |
     @RestController
17 |  |
     @RequestMapping("/services")
18 | 1 |
     public class ServiceController {
19 |  |
20 |  |
       @Autowired
21 |  |
       private DiscoveryService discoveryService;
22 |  |
23 |  |
24 |  |
       @RequestMapping("/meta")
25 |  |
       public List<ServiceDTO> getMetaService() {
26 | 0 |
         List<InstanceInfo> instances = discoveryService.getMetaServiceInstances();
27 | 0 |
         List<ServiceDTO> result = instances.stream().map(new Function<InstanceInfo, ServiceDTO>() {
28 |  |
29 |  |
           @Override
30 |  |
           public ServiceDTO apply(InstanceInfo instance) {
31 | 0 |
             ServiceDTO service = new ServiceDTO();
32 | 0 |
             service.setAppName(instance.getAppName());
33 | 0 |
             service.setInstanceId(instance.getInstanceId());
34 | 0 |
             service.setHomepageUrl(instance.getHomePageUrl());
35 | 0 |
             return service;
36 |  |
           }
37 |  |
38 | 0 |
         }).collect(Collectors.toList());
39 | 0 |
         return result;
40 |  |
       }
41 |  |
42 |  |
       @RequestMapping("/config")
43 |  |
       public List<ServiceDTO> getConfigService(
44 |  |
           @RequestParam(value = "appId", defaultValue = "") String appId,
45 |  |
           @RequestParam(value = "ip", required = false) String clientIp) {
46 | 0 |
         List<InstanceInfo> instances = discoveryService.getConfigServiceInstances();
47 | 0 |
         List<ServiceDTO> result = instances.stream().map(new Function<InstanceInfo, ServiceDTO>() {
48 |  |
49 |  |
           @Override
50 |  |
           public ServiceDTO apply(InstanceInfo instance) {
51 | 0 |
             ServiceDTO service = new ServiceDTO();
52 | 0 |
             service.setAppName(instance.getAppName());
53 | 0 |
             service.setInstanceId(instance.getInstanceId());
54 | 0 |
             service.setHomepageUrl(instance.getHomePageUrl());
55 | 0 |
             return service;
56 |  |
           }
57 |  |
58 | 0 |
         }).collect(Collectors.toList());
59 | 0 |
         return result;
60 |  |
       }
61 |  |
62 |  |
       @RequestMapping("/admin")
63 |  |
       public List<ServiceDTO> getAdminService() {
64 | 0 |
         List<InstanceInfo> instances = discoveryService.getAdminServiceInstances();
65 | 0 |
         List<ServiceDTO> result = instances.stream().map(new Function<InstanceInfo, ServiceDTO>() {
66 |  |
67 |  |
           @Override
68 |  |
           public ServiceDTO apply(InstanceInfo instance) {
69 | 0 |
             ServiceDTO service = new ServiceDTO();
70 | 0 |
             service.setAppName(instance.getAppName());
71 | 0 |
             service.setInstanceId(instance.getInstanceId());
72 | 0 |
             service.setHomepageUrl(instance.getHomePageUrl());
73 | 0 |
             return service;
74 |  |
           }
75 |  |
76 | 0 |
         }).collect(Collectors.toList());
77 | 0 |
         return result;
78 |  |
       }
79 |  |
     }