package org.apache.mesos.elasticsearch.scheduler.controllers;

import org.apache.mesos.elasticsearch.scheduler.ElasticsearchScheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 *
 */
@RestController
@RequestMapping("/cluster")
public class ClusterController {

    @Autowired
    ElasticsearchScheduler scheduler;

    @RequestMapping(method = RequestMethod.GET)
    public ClusterInfoResponse clusterInfo() {
        ClusterInfoResponse response = new ClusterInfoResponse();
        response.name = "TODO";
        response.configuration = Collections.emptyMap();
        return response;
    }

    /**
     * HTTP response entity class
     */
    public static class ClusterInfoResponse {
        public String name;
        public Map<String, String> configuration;
    }

    @RequestMapping(value = "/scheduler", method = RequestMethod.GET)
    public ClusterSchedulerInfoResponse schedulerInfo() {
        final ClusterSchedulerInfoResponse response = new ClusterSchedulerInfoResponse();
        response.docker = dockerMap("image", "tag", "id");
        return response;
    }

    /**
     * HTTP response entity class
     */
    public static class ClusterSchedulerInfoResponse {
        public Map<String, String> docker = new HashMap<>();
    }

    @RequestMapping(value = "/executors", method = RequestMethod.GET)
    public ClusterExecutorsInfoResponse executorsInfo() {
        final ClusterExecutorsInfoResponse response = new ClusterExecutorsInfoResponse();
        response.docker = dockerMap("image", "tag", "id");
        return response;
    }

    /**
     * HTTP response entity class
     */
    public static class ClusterExecutorsInfoResponse {
        public Map<String, String> docker;
    }

    private Map<String, String> dockerMap(String image, String tag, String id) {
        final HashMap<String, String> map = new HashMap<>();
        map.put("image", image);
        map.put("tag", tag);
        map.put("id", id);
        return map;
    }
}

@@ -56,16 +56,143 @@
 llers;%0A%0A
+import org.apache.log4j.Logger;%0Aimport org.apache.mesos.Protos;%0Aimport org.apache.mesos.elasticsearch.scheduler.Configuration;%0A
 import o
@@ -523,23 +523,51 @@
 ava.
-util.Collection
+lang.reflect.Method;%0Aimport java.util.Array
 s;%0Ai
@@ -612,16 +612,52 @@
 til.Map;
+%0Aimport java.util.stream.Collectors;
 %0A%0A/**%0A *
@@ -737,16 +737,99 @@
 roller %7B
+%0A    public static final Logger LOGGER = Logger.getLogger(ClusterController.class);
 %0A%0A    @A
@@ -876,16 +876,65 @@
 duler;%0A%0A
+    @Autowired%0A    Configuration configuration;%0A%0A
     @Req
@@ -1114,14 +1114,35 @@
 e = 
-%22TODO%22
+configuration.getTaskName()
 ;%0A  
@@ -1176,56 +1176,1071 @@
 n = 
-Collections.emptyMap();%0A        return response;
+toMap(configuration);%0A        return response;%0A    %7D%0A%0A    private Map%3CString, Object%3E toMap(Configuration configuration) %7B%0A        return Arrays.stream(configuration.getClass().getDeclaredMethods()).filter(this::isGetter).collect(Collectors.toMap(method -%3E method.getName().substring(3), this::invokeConfigurationGetter));%0A    %7D%0A%0A    private boolean isGetter(Method method) %7B%0A        return method.getName().startsWith(%22get%22) %7C%7C method.getName().startsWith(%22is%22);%0A    %7D%0A%0A    private Object invokeConfigurationGetter(Method method) %7B%0A        try %7B%0A            final Object result = method.invoke(configuration);%0A            if (result instanceof Number %7C%7C result instanceof Boolean %7C%7C result instanceof String) %7B%0A                return result;%0A            %7D%0A            else if (result instanceof Protos.FrameworkID) %7B%0A                return ((Protos.FrameworkID) result).getValue();%0A            %7D%0A            return result.toString();%0A        %7D catch (Exception e) %7B%0A            LOGGER.warn(%22Failed to invoce method%22, e);%0A            return %22--ERROR--%22;%0A        %7D
 %0A   
@@ -2394,22 +2394,22 @@
 String, 
-String
+Object
 %3E config

Add all getters from configuration