package com.xti.spring.cloud.heroku.discovery.example;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

@RestController
@RequestMapping(path = "/topology")
public class TopologyController {

    @RequestMapping(method = RequestMethod.GET)
    public String getSpaceTopology(){
        try {
            return new String(Files.readAllBytes(Paths.get("/etc/heroku/space-topology.json")));
        } catch (IOException e) {
            e.printStackTrace();
            return "failed to get space topology";
        }

    }
}

@@ -49,16 +49,203 @@
 ample;%0A%0A
+import org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.cloud.client.ServiceInstance;%0Aimport org.springframework.cloud.client.discovery.DiscoveryClient;%0A
 import o
@@ -299,16 +299,16 @@
 apping;%0A
-
 import o
@@ -508,16 +508,39 @@
 e.Paths;
+%0Aimport java.util.List;
 %0A%0A@RestC
@@ -620,16 +620,77 @@
 ller %7B%0A%0A
+    @Autowired%0A    private DiscoveryClient discoveryClient;%0A%0A
     @Req
@@ -701,16 +701,32 @@
 Mapping(
+path = %22/file%22, 
 method =
@@ -1028,11 +1028,616 @@
 %7D%0A%0A    %7D
+%0A%0A    @RequestMapping(path = %22/springcloud%22, method = RequestMethod.GET)%0A    public String getSpringCloudTopology()%7B%0A        StringBuilder sb = new StringBuilder();%0A        List%3CString%3E services = discoveryClient.getServices();%0A        for (String service : services) %7B%0A            sb.append(service).append(%22%5Cn%22);%0A            List%3CServiceInstance%3E instances = discoveryClient.getInstances(service);%0A            for (ServiceInstance instance : instances) %7B%0A                sb.append(instance.getHost()).append(%22%5Cn%22);%0A            %7D%0A            sb.append(%22%5Cn%22);%0A        %7D%0A        return sb.toString();%0A    %7D
 %0A%7D%0A

add spring cloud discovery topology endpoint