|
|
package com.monitor.switchs.centerSwitch.ctrl;
|
|
|
|
|
|
import com.monitor.model.domain.CenterSwitchModel;
|
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import com.monitor.switchs.CommodUtil;
|
|
|
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 java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by zhengyouwei on 2016/10/24.
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/centerSwitch")
|
|
|
public class CenterSwitchCtrl {
|
|
|
|
|
|
@RequestMapping("/getSwitchList")
|
|
|
@ResponseBody
|
|
|
public BaseResponse getSwitchList(){
|
|
|
|
|
|
List<CenterSwitchModel> list = new ArrayList<>();
|
|
|
CenterSwitchModel all = new CenterSwitchModel();
|
|
|
all.setName("one_key_switch");
|
|
|
all.setCName("一键切换");
|
|
|
list.add(all);
|
|
|
|
|
|
CenterSwitchModel db_aws_master_readonly = new CenterSwitchModel();
|
|
|
db_aws_master_readonly.setName("db_aws_master_readonly");
|
|
|
db_aws_master_readonly.setCName("数据库只读");
|
|
|
list.add(db_aws_master_readonly);
|
|
|
|
|
|
CenterSwitchModel db_qcloud_remove_readonly = new CenterSwitchModel();
|
|
|
db_qcloud_remove_readonly.setName("db_qcloud_remove_readonly");
|
|
|
db_qcloud_remove_readonly.setCName("数据库可写");
|
|
|
list.add(db_qcloud_remove_readonly);
|
|
|
|
|
|
CenterSwitchModel cobar = new CenterSwitchModel();
|
|
|
cobar.setName("cobar");
|
|
|
cobar.setCName("cobar");
|
|
|
list.add(cobar);
|
|
|
|
|
|
CenterSwitchModel redis = new CenterSwitchModel();
|
|
|
redis.setName("redis_qcloudtomaster");
|
|
|
redis.setCName("redis");
|
|
|
list.add(redis);
|
|
|
|
|
|
CenterSwitchModel internel_dns_aws = new CenterSwitchModel();
|
|
|
internel_dns_aws.setName("internel_dns_aws");
|
|
|
internel_dns_aws.setCName("aws内部DNS");
|
|
|
list.add(internel_dns_aws);
|
|
|
|
|
|
CenterSwitchModel internel_dns_qcloud = new CenterSwitchModel();
|
|
|
internel_dns_qcloud.setName("internel_dns_qcloud");
|
|
|
internel_dns_qcloud.setCName("qcloud内部DNS");
|
|
|
list.add(internel_dns_qcloud);
|
|
|
|
|
|
CenterSwitchModel switch_lua = new CenterSwitchModel();
|
|
|
switch_lua.setName("switch_lua");
|
|
|
switch_lua.setCName("lua 切换");
|
|
|
list.add(switch_lua);
|
|
|
|
|
|
CenterSwitchModel switch_dnspod = new CenterSwitchModel();
|
|
|
switch_dnspod.setName("switch_dnspod");
|
|
|
switch_dnspod.setCName("dnspod 切换");
|
|
|
list.add(switch_dnspod);
|
|
|
|
|
|
return new BaseResponse(list);
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/doExe")
|
|
|
@ResponseBody
|
|
|
public BaseResponse doExe(@RequestBody CenterSwitchModel centerSwitchModel){
|
|
|
|
|
|
StringBuilder commond = new StringBuilder("ssh root@10.66.4.25 sh /root/script/oneKeySwitch/");
|
|
|
if ("aws".equals(centerSwitchModel.getToCloud()) && !"switch_lua".equals(centerSwitchModel.getName()) ){
|
|
|
centerSwitchModel.setName(centerSwitchModel.getName() + "_re");
|
|
|
}
|
|
|
if (!"switch_lua".equals(centerSwitchModel.getName())){
|
|
|
commond.append(centerSwitchModel.getName());
|
|
|
commond.append(".sh ");
|
|
|
commond.append(centerSwitchModel.getToCloud());
|
|
|
}else {
|
|
|
commond.append("switch_lua.sh -e switch -s ");
|
|
|
commond.append(centerSwitchModel.getToCloud());
|
|
|
}
|
|
|
List<String> resultList = CommodUtil.exe(commond.toString());
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
|
|
for (String str : resultList){
|
|
|
result.append(str).append("\r\n");
|
|
|
}
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
baseResponse.setData(result.toString());
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|