JavaRestartCtrl.java 3.5 KB
package com.ui.ctrl;

import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.RestartModel;
import com.ui.model.req.PageRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by zhengyouwei on 2016/10/18.
 */
@RestController
@RequestMapping(value = "/javaRestart")
public class JavaRestartCtrl {

    Logger log = LoggerFactory.getLogger(JavaRestartCtrl.class);
    @Autowired
    private HttpRestClient httpClient;

    @RequestMapping("/toJavaRestart")
    public ModelAndView toJavaRestart() {
        return new ModelAndView("/switch/java_restart");
    }

    @RequestMapping("/toStopOrRestart")
    public ModelAndView toStopOrRestart(String project,String cloud, String exe,String ip,Model model) {
        model.addAttribute("project",project);
        model.addAttribute("cloud",cloud);
        model.addAttribute("exe",exe);
        model.addAttribute("ip",ip);
        return new ModelAndView("/switch/java_restart_process");
    }

    @RequestMapping("/query")
    @ResponseBody
    public BaseResponse query(PageRequest req) {
        BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_RESTART_GET, req, BaseResponse.class);
        return rep;
    }

    @RequestMapping("/getProjectStatus")
    @ResponseBody
    public BaseResponse getProjectStatus(String project) {
        BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_RESTART_STATAUS + "?project=" + project, null, BaseResponse.class);
        return rep;
    }
    @RequestMapping("/stopOrRestart")
    @ResponseBody
    public BaseResponse stopOrRestart( RestartModel restartModel) {
        if(StringUtils.isBlank(restartModel.getExe()) || StringUtils.isBlank(restartModel.getCloud()) || StringUtils.isBlank(restartModel.getProject())){
            return null;
        }

        BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_STOP_RESTART, restartModel, BaseResponse.class);
        return rep;
    }

    @RequestMapping("/getMessage")
    @ResponseBody
    public BaseResponse getMessage(Integer id) {
        BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_GET_MESSAGE+ "?id=" + id, null, BaseResponse.class);
        return rep;
    }

    @RequestMapping("/getMessageStatus")
    @ResponseBody
    public BaseResponse getMessageStatus(String ids) {
        boolean allOk=true;
        StringBuilder sb=new StringBuilder();
        for(String id:ids.split(",")){
            if(StringUtils.isNotBlank(id)){
                BaseResponse rep = httpClient.defaultPost(HttpUriContants.JAVA_GET_MESSAGE_STATUS+ "?id=" + id, null, BaseResponse.class);
                sb.append(id).append(":").append(rep!=null?rep.getData():"").append("<br>");
                if(rep!=null&&rep.getData()!=null&&(rep.getData().equals("0")||rep.getData().equals("2"))){

                }else{
                    allOk=false;
                }
            }
        }
        if(allOk){
            return new BaseResponse("ok");
        }else{
            return new BaseResponse(sb.toString());
        }
    }
}