TopoSwitchCtrl.java 3.31 KB
package com.ui.ctrl;

import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 限流调整
 *
 * @author bblu 2016-10-26
 */
@Controller
@RequestMapping("topoSwitch")
public class TopoSwitchCtrl {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    HttpRestClient httpRestClient;

    @Autowired
    TopoSwitchUtil topoSwitchUtil;

    @RequestMapping(value = "toTopoSwitch")
    public ModelAndView toTopoSwitch() {
        ModelAndView mdv = new ModelAndView("switch/switch_topology");
        return mdv;
    }

    @RequestMapping(value = "toAppTopoSwitch")
    public ModelAndView toAppTopoSwitch() {
        ModelAndView mdv = new ModelAndView("switch/switch_topology_app");
        return mdv;
    }

    /**
     * 展示当前配置
     *
     * @return ModelAndView
     */
    @RequestMapping(value = "getNgixnStatus")
    @ResponseBody
    public BaseResponse getNgixnStatus() {
        Map<String, Object> resultMap = new HashMap<>();

        try{
            //nginx
            BaseResponse<Map<String, List<Map<String, Object>>>> response = httpRestClient.exchangeForget(HttpUriContants.VIEW_NGINX_CONF, new ParameterizedTypeReference<BaseResponse<Map<String, List<Map<String, Object>>>>>() {
            }, null);
            Map<String, List<Map<String, Object>>> map = response.getData();

            List<Map<String, Object>> qcloudList = map.get("qcloudList");
            List<Map<String, Object>> qcloudaz2List = map.get("qcloudaz2List");

            List<String> az1HostIps=(List<String>)(map.get("gatewayServerHosts").get(0).get("az1ServerHosts"));
            List<String> az2HostIps=(List<String>)(map.get("gatewayServerHosts").get(0).get("az2ServerHosts"));
            List<String> grayHostIps=(List<String>)(map.get("gatewayServerHosts").get(0).get("grayServerHosts"));

            List<String> ls=topoSwitchUtil.getNginxLocationType(az1HostIps,az2HostIps,grayHostIps,qcloudList);
            String qqApiNginx = ls.get(0);
            String qqGrayNginx = ls.get(1);

            ls=topoSwitchUtil.getNginxLocationType(az1HostIps,az2HostIps,grayHostIps,qcloudaz2List);
            String az2ApiNginx = ls.get(0);
            String az2GrayNginx = ls.get(1);

            resultMap.put("az2ApiNginx", az2ApiNginx);
            resultMap.put("az2GrayNginx", az2GrayNginx);
            resultMap.put("qqApiNginx", qqApiNginx);
            resultMap.put("qqGrayNginx", qqGrayNginx);
            resultMap.put("defaultDns", httpRestClient.defaultGet(HttpUriContants.CENTERSWITCH_DEFAULT_DNS,String.class));
            resultMap.put("luaType", topoSwitchUtil.getLuaType());
        }catch (Exception e){
            logger.error(" TopoSwitchCtrl - getNgixnStatus - err", e);
        }

        return new BaseResponse(resultMap);
    }
}