Authored by zhouxiang

no message

... ... @@ -12,6 +12,7 @@ import com.monitor.model.domain.SmsTicket;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.HostInfoMapper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpRequest;
import org.slf4j.Logger;
... ... @@ -90,17 +91,15 @@ public class NginxSwitchCtrl {
String tag = StringUtils.equals("gray", target) ? "灰度" : "gateway";
//aws:1 qcloud:2
int nginxCloudType = StringUtils.equals("aws", cloudName) ? 1 : (StringUtils.equals("qcloud", cloudName) ? 2 : 0);
//int nginxCloudType = StringUtils.equals("aws", cloudName) ? 1 : (StringUtils.equals("qcloud", cloudName) ? 2 : 0);
//需要查询的gateway机子
int gatewayCloudType = StringUtils.equals("aws", target) ? 1 : (StringUtils.equals("qcloud", target) ? 2 : (StringUtils.equals("aws", cloudName) ? 1 : 2));
if (0 == nginxCloudType || 0 == gatewayCloudType) {
return new BaseResponse(500, "没有匹配到要切换的云");
}
//if (0 == nginxCloudType || 0 == gatewayCloudType) {
//获取对应cloud的机器 aws 1 qcloud 2
List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTagAndCloudType("nginx", nginxCloudType);
/*List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTagAndCloudType("nginx", nginxCloudType);
if (CollectionUtils.isEmpty(nginxHosts)) {
return new BaseResponse(500, cloudName + "在cmdb中未找到对应的nginx服务器!");
}
}*/
//获取gateway或graygateway服务器
List<HostInfo> gatewayHosts = hostInfoMapper.selectHostInfosByTagAndCloudType(tag, gatewayCloudType);
if (CollectionUtils.isEmpty(gatewayHosts)) {
... ... @@ -129,7 +128,10 @@ public class NginxSwitchCtrl {
String path = httpRequest.getSession().getServletContext().getRealPath("/") + "java-nginx/" + cloudName + "/nginx.conf";
logger.info("nginx.conf creat path is {}",path);
String result = HandlebarsUtils.replace(map, "template/" + cloudName + "-nginx", path);
return new BaseResponse(200, "success",result);
Map<String,Object> resultMap = new HashMap();
resultMap.put("cloudName",cloudName);
resultMap.put("result",result);
return new BaseResponse(200, "success",resultMap);
}
/**
... ... @@ -140,18 +142,28 @@ public class NginxSwitchCtrl {
*/
@RequestMapping(value = "switchNginxConf")
@ResponseBody
public BaseResponse switchNginxConf(String cloudName, String target, HttpServletRequest httpRequest) {
public BaseResponse switchNginxConf(String cloudName, HttpServletRequest httpRequest) {
int nginxCloudType = StringUtils.equals("aws", cloudName) ? 1 : (StringUtils.equals("qcloud", cloudName) ? 2 : 0);
if (0 == nginxCloudType) {
return new BaseResponse(500, "没有匹配到要切换的云");
}
//获取对应cloud的机器 aws 1 qcloud 2
List<HostInfo> nginxHosts = hostInfoMapper.selectHostInfosByTagAndCloudType("nginx", nginxCloudType);
if (CollectionUtils.isEmpty(nginxHosts)) {
return new BaseResponse(500, cloudName + "在cmdb中未找到对应的nginx服务器!");
}
String path = httpRequest.getSession().getServletContext().getRealPath("/") + "java-nginx/" + cloudName + "/nginx.conf";
return null;
}
/**
* 执行命令
*
* @param cloudName
* @param commod
* @return 2016年5月17日下午3:26:29
*/
/**
* 执行命令
*
* @param cloudName
* @param commod
* @return 2016年5月17日下午3:26:29
*/
public String exe(String cloudName, String commod, String target) {
StringBuilder commond = new StringBuilder();
commond.append(" -s " + cloudName);
... ...