package info.noconfuse.springair.rpc.monitor;

import info.noconfuse.springair.rpc.ServiceGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Controller of MVC.
 *
 * @author Zheng Zhipeng
 */
@Controller
public class MonitorController {

    @Autowired
    private ServiceMonitor serviceMonitor;

    @RequestMapping("/monitor")
    public String monitor(Model model) {
        List<ServiceGroup> services = null;
        try {
            services = serviceMonitor.allServices();
        } catch (Exception e) {
            e.printStackTrace();
        }

        // UserService
        /*
        List<ServiceNode> userServices = new ArrayList<>(2);
        ServiceNode sn1 = new ServiceNode("UserService-1",
                "http://192.168.20.60:8081/UserService",
                "/services_registry/UserService/UserService-1");
        ServiceNode sn2 = new ServiceNode("UserService-2",
                "http://127.0.0.1:8082/UserService",
                "/services_registry/UserService/UserService-2");
        userServices.add(sn1);
        userServices.add(sn2);
        ServiceGroup userService = new ServiceGroup("UserService", userServices);

        // PushService
        List<ServiceNode> pushServices = new ArrayList<>(2);
        ServiceNode sn3 = new ServiceNode("PushService-1",
                "http://192.168.20.80:8088/PushService",
                "/services_registry/PushService/PushService-1");
        ServiceNode sn4 = new ServiceNode("PushService-2",
                "http://127.0.0.1:8089/PushService",
                "/services_registry/PushService/PushService-2");
        pushServices.add(sn3);
        pushServices.add(sn4);
        ServiceGroup pushService = new ServiceGroup("PushService", pushServices);

        // add all
        List<ServiceGroup> services = new ArrayList<>(2);
        services.add(userService);
        services.add(pushService);
        */
        model.addAttribute("services", services);

        return "monitor";
    }
}

@@ -753,1352 +753,8 @@
    %7D
-%0A%0A        // UserService%0A        /*%0A        List%3CServiceNode%3E userServices = new ArrayList%3C%3E(2);%0A        ServiceNode sn1 = new ServiceNode(%22UserService-1%22,%0A                %22http://192.168.20.60:8081/UserService%22,%0A                %22/services_registry/UserService/UserService-1%22);%0A        ServiceNode sn2 = new ServiceNode(%22UserService-2%22,%0A                %22http://127.0.0.1:8082/UserService%22,%0A                %22/services_registry/UserService/UserService-2%22);%0A        userServices.add(sn1);%0A        userServices.add(sn2);%0A        ServiceGroup userService = new ServiceGroup(%22UserService%22, userServices);%0A%0A        // PushService%0A        List%3CServiceNode%3E pushServices = new ArrayList%3C%3E(2);%0A        ServiceNode sn3 = new ServiceNode(%22PushService-1%22,%0A                %22http://192.168.20.80:8088/PushService%22,%0A                %22/services_registry/PushService/PushService-1%22);%0A        ServiceNode sn4 = new ServiceNode(%22PushService-2%22,%0A                %22http://127.0.0.1:8089/PushService%22,%0A                %22/services_registry/PushService/PushService-2%22);%0A        pushServices.add(sn3);%0A        pushServices.add(sn4);%0A        ServiceGroup pushService = new ServiceGroup(%22PushService%22, pushServices);%0A%0A        // add all%0A        List%3CServiceGroup%3E services = new ArrayList%3C%3E(2);%0A        services.add(userService);%0A        services.add(pushService);%0A        */
 %0A   

remove useless codes