Authored by zhengyouwei

center switch

package com.monitor.model.domain;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/10/24.
*/
@Data
public class CenterSwitchModel {
private String name;
private String cName;
private String exe;
private String toCloud;
}
... ...
... ... @@ -71,42 +71,40 @@ public class CommodUtil {
* @return
*/
public static List<String> exe(String commond) {
// try {
// Thread.sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// List<String> list = new ArrayList<>();
//
// if (commond.indexOf("getIPs") != -1){
// list.add("$SERVER@@master@172.31.28.161@@1@@");
// list.add("$SERVER@@master@172.31.28.162@@1@@");
// }
// return list;
Process process;
List<String> list = new ArrayList<>();
BufferedReader input = null;
try {
process = Runtime.getRuntime().exec(commond);
input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
list.add(line);
}
} catch (Exception e) {
logger.error("process exe failed!", e);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
logger.error("process exe failed!", e);
}
}
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
List<String> list = new ArrayList<>();
list.add(commond);
list.add(commond);
return list;
// Process process;
// List<String> list = new ArrayList<>();
// BufferedReader input = null;
// try {
// process = Runtime.getRuntime().exec(commond);
// input = new BufferedReader(new InputStreamReader(process.getInputStream()));
// String line;
// while ((line = input.readLine()) != null) {
// list.add(line);
// }
// } catch (Exception e) {
// logger.error("process exe failed!", e);
// } finally {
// if (input != null) {
// try {
// input.close();
// } catch (IOException e) {
// logger.error("process exe failed!", e);
// }
// }
// }
// return list;
}
}
... ...
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;
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.switchs.projectRestart.task;
import com.monitor.model.domain.Project;
import com.monitor.switchs.projectRestart.common.ProjectOnline;
import com.monitor.switchs.projectRestart.common.RestartProcessStore;
import com.monitor.switchs.projectRestart.service.RestartService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -18,19 +19,9 @@ public class ProjectStatusTask {
private static Logger logger = LoggerFactory.getLogger(ProjectStatusTask.class);
@Autowired
private RestartService restartService;
@Scheduled(cron = "${cron_task_project_status}")
@Scheduled(cron = "0 0 0 * * ?")
public void check(){
for (Project project : ProjectOnline.getJavaList()){
try {
String name = project.getName();
restartService.cehckStatus("mix",name);
}catch (Exception e){
logger.error("check erreo!",e);
}
}
RestartProcessStore.clear();
}
... ...