Authored by xuhui

腾讯云伸缩

package com.ui.cloud;
import com.ui.model.domain.BuildMessage;
import lombok.Data;
import java.util.List;
/**
* 用于伸缩云项目发布
* Created by xh on 2017/5/15.
*/
@Data
public class DeployProjectCloud {
private String messageids;
private List<BuildMessage> messageList;
}
\ No newline at end of file
... ...
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;
... ... @@ -12,6 +17,10 @@ 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.
... ... @@ -91,4 +100,57 @@ public class AutoScalingCtrl {
BaseResponse<?> response = httpClient.defaultPost(url, null, BaseResponse.class);
return response;
}
/**
* 腾讯云系统发布
* @param session
* @param projectName 项目名称
* @param ips 所需发布的ip集合 ,分割
* @param branch 分支名称
* @param environment 发布环境 此为qcloud
* @return
*/
@RequestMapping("/deployQcloudProject")
@ResponseBody
public BaseResponse<?> deployQcloudProject(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;
}
}
\ No newline at end of file
... ...
... ... @@ -172,7 +172,6 @@ public class ProjectBuildCtrl {
buildRequest.setOperate(operate_name);
//关联工单
buildRequest.setWorkid(workid_name);
String messageids = "";
if ("Deploy".equals(operate_name)) {
String[] array = project_name.split(",");
... ...
... ... @@ -137,12 +137,15 @@ var souProtectedFromCount;
var souDesiredCapacity;
var souMinSize;
var souMaxSize;
//需要发布的版本
var souBranch;
//修改伸缩组
function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapacity, minSize, maxSize){
scalingGroupName = groupName;
souScalingGroupId = scalingGroupId;
souProtectedFromCount = protectedFromCount;
souDesiredCapacity = desiredCapacity;
//souDesiredCapacity = 2;
souMinSize = minSize;
souMaxSize = maxSize;
... ... @@ -161,6 +164,12 @@ function changeServer(scalingGroupId, groupName, protectedFromCount, desiredCapa
}
function changeOk(){
//分支版本
souBranch = $("#branch").val();
if(souBranch == "" || souBranch == undefined){
alert("需要发布的分支版本不能为空");
return;
}
//异常处理
if(souScalingGroupId == "" || souScalingGroupId == undefined
|| souProtectedFromCount == "" || souProtectedFromCount == undefined
... ... @@ -277,38 +286,24 @@ function refCloudMessage(showMessage, serverCount){
clearInterval(intervalIndex);
}else{
var returnJson = data.data[0];
if(showMessage == "缩容"){
if(returnJson.msg != "success"){
if(count == 0){
writeToText(returnJson.desciption);
}else{
writeToText("......");
}
}else{
writeToText("第 1 步:" + showMessage + " 成功!");
$("#closeButton").removeAttr("disabled");
clearInterval(intervalIndex);
if(returnJson.succInsList == undefined || returnJson.succInsList.length != serverCount){
if(count == 0){
writeToText(returnJson.desciption);
}else{
writeToText("......");
}
}else{
writeToText("第 1 步:" + showMessage + " 成功!");
writeToText("...")
clearInterval(intervalIndex);
if(showMessage == "缩容"){
unDeploy();
writeToText("结束..........");
return;
}
}else{
if(returnJson.succInsList == undefined || returnJson.succInsList.length != 2){
if(count == 0){
writeToText(returnJson.desciption);
}else{
writeToText("......");
}
}else{
writeToText("第 1 步:" + showMessage + " 成功!");
writeToText("...")
clearInterval(intervalIndex);
//扩容成功后执行
deploy(returnJson.succInsList);
writeToText("结束..........");
}
}
}
... ... @@ -356,8 +351,6 @@ function deploy(instanceIds){
}
writeToText("正在发布系统,请稍后...");
deployProject(ips);
writeToText("第 3 步:系统部署成功!");
deployLaster();
}
//发布成功和失败都执行
... ... @@ -411,6 +404,64 @@ function getIpByInstanceIds(instanceIds){
//3:根据ip发布项目
function deployProject(ips){
$.ajax({
url: '/autoScalingTool/deployQcloudProject?projectName='+scalingGroupName+'&ips='+ips+'&branch=' + souBranch + '&environment=qcloud',
type: 'POST',
dataType: 'json',
async: false,
success: function (data) {
if (!data || data.code != 200) {
alert(data.message);
}else{
//同步获取消息
deployProjectGetMsg(data.data.setMessageids.split(',')[0]);
}
},
error: function (data) {
writeToText('系统异常!');
deployLaster();
}
});
}
//3.1:发布项目的同时获取发布的消息
function deployProjectGetMsg(msgId){
var intervalIndexMsg = setInterval(function() {
$.ajax({
url: 'project/getbuildmsg?messageid=' + msgId+"&project="+scalingGroupName,
type: 'POST',
dataType: 'json',
success: function (data3) {
var obj2 = eval("(" + data3 + ")");
var messagedata = obj2.data;
if ((messagedata.message != "") && (messagedata.message != null) && (messagedata.message != undefined)) {
writeToText(messagedata.message);
}
//code为2 ,则结束
var code = obj2.code;
if (code == 2) {
writeToText("第 3 步:系统部署成功!");
clearInterval(intervalIndexMsg);
//集成测试
deployLaster();
writeToText("结束..........");
}
},
error: function (e) {
alert('系统异常');
clearInterval(intervalIndexMsg);
deployLaster();
}
});
}, 3000);
}
//4:集成测试
function test(){
}
... ...