AutoScalingCtrl.java
6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.ui.ctrl;
import com.ui.cloud.CommAutoModifyScalingGroupReq;
import com.ui.cloud.DeployProjectCloud;
import com.ui.cloud.QcloudModifyScalingGroupReq;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.domain.BuildMessage;
import com.ui.model.req.BuildRequest;
import com.ui.model.req.User;
import com.ui.project.ProjectEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
/**
* 亚马逊云 腾讯云 伸缩组操作
* Created by xh on 2017/5/9.
*/
@Controller
@RequestMapping("autoScalingTool")
public class AutoScalingCtrl {
@Autowired
private HttpRestClient httpClient;
/**
* 跳转到页面
* @param model
* @return
*/
@RequestMapping("/toautoscalingpage")
public ModelAndView toAutoScalingPage(Model model) {
return new ModelAndView("manager/autoscaling");
}
/**
* 显示配置信息
* @param cloudType 云类型 1:AWS 2:QCLOUD
* @return
*/
@RequestMapping("/autoscalingconfig")
@ResponseBody
public BaseResponse<?> autoScalingConfig(int cloudType) {
BaseResponse<?> response = httpClient.defaultPost(
HttpUriContants.GET_CLOUD_AUTOSCALING_CONFIG + "?cloudType="+cloudType, null,
BaseResponse.class);
return response;
}
/**
* 显示配置信息
* @param qCloudReq 修改的相关参数,暂时只用了腾讯云的,日后考虑亚马逊的
* @return
*/
@RequestMapping("/modifyScalingGroup")
@ResponseBody
public BaseResponse<?> modifyScalingGroup(QcloudModifyScalingGroupReq qCloudReq, int cloudType) {
CommAutoModifyScalingGroupReq req = new CommAutoModifyScalingGroupReq();
req.setCloudType(cloudType);
req.setQCloudParms(qCloudReq);
BaseResponse<?> response = httpClient.defaultPost(
HttpUriContants.GET_CLOUD_MODIFY_SCALING_GROUP, req, BaseResponse.class);
return response;
}
/**
* 腾讯云:修改伸缩组后的下一个流程是查询伸缩活动
* 亚马逊云:修改伸缩组后的下一个流程待定,因为不清楚
* @param scalingGroupId 待查询的伸缩组Id
* @param startTime 开始时间,如果不填,则默认是当前时间前10秒之后发生的活动
* @return
*/
@RequestMapping("/describeScalingActivity")
@ResponseBody
public BaseResponse<?> describeScalingActivity(String scalingGroupId, String startTime){
String url = String.format(HttpUriContants.GET_CLOUD_DESCRIBE_SCALING_ACTIVITY+"?scalingGroupId=%s&startTime=%s",scalingGroupId,startTime);
BaseResponse<?> response = httpClient.defaultPost(url, null, BaseResponse.class);
return response;
}
/**
* 腾讯云:根据实例id获取内网ip
* 亚马逊云待定:不清楚流程
* @param ids 实例id集合
* @return
*/
@RequestMapping("/getQcloudDescribeInstances")
@ResponseBody
public BaseResponse<?> getQcloudDescribeInstances(String ids){
String url = String.format(HttpUriContants.GET_QCLOUD_DESCRIBE_INSTANCES+"?instanceIds=%s",ids);
BaseResponse<?> response = httpClient.defaultPost(url, null, BaseResponse.class);
return response;
}
/**
* 系统发布
* @param session
* @param projectName 项目名称
* @param ips 所需发布的ip集合 ,分割
* @param branch 分支名称
* @param environment 发布环境 此为qcloud
* @return
*/
@RequestMapping("/deployCloudProject")
@ResponseBody
public BaseResponse<?> deployCloudProject(HttpSession session, String projectName, String ips, String branch, String environment){
BaseResponse response = null;
try{
User user = (User) session.getAttribute("user");
List<BuildMessage> list = new ArrayList<>();
BuildRequest buildRequest = new BuildRequest();
//分支名称
buildRequest.setBranch(branch);
//登陆用户
buildRequest.setUser(user.getName());
//设置需要发布的ip
buildRequest.setHost(ips);
//发布环境
buildRequest.setEnvironment(environment);
//不存在回滚文件
//操作类型
buildRequest.setOperate("Deploy");
//关联工单
buildRequest.setWorkid("release0");
//项目名称
buildRequest.setProject(projectName);
String messageids = "";
BuildMessage buildMessage = httpClient.post(ProjectEnvironment.getUrl(environment) + "build", buildRequest, BuildMessage.class);
if (buildMessage != null) {
list.add(buildMessage);
messageids = messageids + buildMessage.getId() + ",";
}
DeployProjectCloud deploy = new DeployProjectCloud();
deploy.setMessageids(messageids);
deploy.setMessageList(list);
response = new BaseResponse();
response.setData(deploy);
}catch (Exception e){
response.setCode(300);
response.setMessage(e.getMessage());
}
return response;
}
/**
* 项目发布后集成测试
* @param cloudType 云类型 1:AWS 2:QCLOUD
* @param projectName 项目名称
* @param ips 部署在哪台服务器上,内网ip集合, ,分割
* @return
*/
@RequestMapping("/integrationTest")
@ResponseBody
public BaseResponse<?> integrationTest(int cloudType, String projectName, String ips){
String url = String.format(HttpUriContants.GET_CLOUD_INTEGRATION_TEST+"?cloudType=%s&projectName=%s&ips=%s",cloudType, projectName, ips);
BaseResponse<?> response = httpClient.defaultPost(url, null, BaseResponse.class);
return response;
}
}