|
|
package com.ui.ctrl.app;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.ui.app.common.ErrorCode;
|
|
|
import com.ui.app.req.*;
|
|
|
import com.ui.app.resp.NodeBuildState;
|
|
|
import com.ui.http.HttpRestClient;
|
|
|
import com.ui.model.BaseResponse;
|
|
|
import com.ui.model.domain.BuildMessage;
|
|
|
import com.ui.model.domain.PythonProject;
|
|
|
import com.ui.model.req.BuildRequest;
|
|
|
import com.ui.project.Project;
|
|
|
import com.ui.project.ProjectEnvironment;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Created by zhengyouwei on 2016/11/14.
|
|
|
* app 服务端,重写一个
|
|
|
*/
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/app_nodeBuild")
|
|
|
public class AppNodeBuildCtrl {
|
|
|
|
|
|
@Autowired
|
|
|
private HttpRestClient httpClient;
|
|
|
|
|
|
private String NODE_URL = "http://172.31.16.167:8883/node/";
|
|
|
|
|
|
/**
|
|
|
* 获取项目列表
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "app_getnodeprojectlist", method = RequestMethod.POST)
|
|
|
public BaseResponse getnodeprojectlist(@RequestBody AppBaseReq appBaseReq) {
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
String result = httpClient.get(NODE_URL + "getProjects", String.class, null);
|
|
|
List<Project> projectList = JSONArray.parseArray(result,Project.class);
|
|
|
List<String> stringList = projectList.stream().map(Project::getName).collect(Collectors.toList());
|
|
|
baseResponse.setData(stringList);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取项目信息
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "app_getnodeprojectinfo", method = RequestMethod.POST)
|
|
|
public BaseResponse getnodeprojectinfo(@RequestBody ProjectInfo projectInfo) {
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
if (StringUtils.isBlank(projectInfo.getProject())) {
|
|
|
baseResponse.setCode(ErrorCode.PARAM_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
PythonProject pythonProject = httpClient.get(NODE_URL + "getProject?name="+projectInfo.getProject() , PythonProject.class, null);
|
|
|
baseResponse.setData(pythonProject);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取回滚列表
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "app_getnoderollbacklist", method = RequestMethod.POST)
|
|
|
public BaseResponse getnoderollbacklist(@RequestBody RollbackList rollbackListReq) {
|
|
|
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
if (StringUtils.isBlank(rollbackListReq.getProject()) || StringUtils.isBlank(rollbackListReq.getEnvironment())) {
|
|
|
baseResponse.setCode(ErrorCode.PARAM_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("project", rollbackListReq.getProject());
|
|
|
map.put("environment", rollbackListReq.getEnvironment());
|
|
|
String result = httpClient.get(NODE_URL + "rollbackList", String.class, map);
|
|
|
if ("failed".equals(result)) {//没有文件
|
|
|
baseResponse.setCode(ErrorCode.ROLLBACK_FILE_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.ROLLBACK_FILE_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
baseResponse.setData(JSONArray.parse(result));
|
|
|
return baseResponse;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取回滚列表
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "app_nodebuild", method = RequestMethod.POST)
|
|
|
public BaseResponse build(@RequestBody ProjectBuild projectBuild) {
|
|
|
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
String project = projectBuild.getProject();
|
|
|
String environment = projectBuild.getEnvironment();
|
|
|
String operate = projectBuild.getOperate();
|
|
|
String branch = projectBuild.getBranch();
|
|
|
String rollbackFile = projectBuild.getRollbackfile();
|
|
|
if (StringUtils.isBlank(project) || StringUtils.isBlank(environment) || StringUtils.isBlank(operate)) {
|
|
|
baseResponse.setCode(ErrorCode.PARAM_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
if ("Deploy".equals(operate)) {
|
|
|
if (StringUtils.isBlank(branch)) {
|
|
|
baseResponse.setCode(ErrorCode.PARAM_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
//check branch
|
|
|
if (!"master".equals(branch)) {
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("projects", project);
|
|
|
map.put("branch", branch);
|
|
|
String result = httpClient.get(ProjectEnvironment.getUrl(environment) + "checkBranch", String.class, map);
|
|
|
if (!"1".equals(result)) {
|
|
|
baseResponse.setCode(ErrorCode.BRANCH_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.BRANCH_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (StringUtils.isBlank(rollbackFile)) {
|
|
|
baseResponse.setCode(ErrorCode.PARAM_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
BuildRequest buildRequest = new BuildRequest();
|
|
|
buildRequest.setBranch(branch);
|
|
|
buildRequest.setUser(projectBuild.getAccountname());
|
|
|
buildRequest.setEnvironment(environment);
|
|
|
buildRequest.setRollbackfile(rollbackFile);
|
|
|
buildRequest.setOperate(operate);
|
|
|
buildRequest.setProject(project);
|
|
|
buildRequest.setHost(projectBuild.getHosts());
|
|
|
BuildMessage buildMessage = httpClient.post(NODE_URL + "build", buildRequest, BuildMessage.class);
|
|
|
baseResponse.setData(buildMessage.getId());
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取执行结果
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "app_getnodebuildmsg", method = RequestMethod.POST)
|
|
|
public BaseResponse getbuildmsg(@RequestBody Buildmsg buildmsg) {
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
if (StringUtils.isBlank(buildmsg.getProject()) || StringUtils.isBlank(buildmsg.getMessageid())) {
|
|
|
baseResponse.setCode(ErrorCode.PARAM_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("messageid", buildmsg.getMessageid());
|
|
|
map.put("project", buildmsg.getProject());
|
|
|
BaseResponse<BuildMessage> result = httpClient.otherOxchangeForget(ProjectEnvironment.getUrl(buildmsg.getMessageid().split("_")[0]) + "getbuildmsg", new ParameterizedTypeReference<BaseResponse<BuildMessage>>() {
|
|
|
}, map);
|
|
|
if (result.getCode() == 1) {
|
|
|
baseResponse.setData(result.getData().getMessage());
|
|
|
} else {
|
|
|
baseResponse.setCode(201);
|
|
|
baseResponse.setMessage(result.getMessage());
|
|
|
baseResponse.setData(result.getData().getMessage());
|
|
|
}
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消执行
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "app_nodecancelbuild", method = RequestMethod.POST)
|
|
|
public BaseResponse cancelbuild(@RequestBody CancleBuild cancleBuild) {
|
|
|
BaseResponse baseResponse = new BaseResponse();
|
|
|
if (StringUtils.isBlank(cancleBuild.getMessageid())) {
|
|
|
baseResponse.setCode(ErrorCode.PARAM_ERROR);
|
|
|
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("id", cancleBuild.getMessageid());
|
|
|
String result = httpClient.get(ProjectEnvironment.getUrl(cancleBuild.getMessageid().split("_")[0]) + "cancelBuild", String.class, map);
|
|
|
baseResponse.setData(result);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|