Authored by zhengyouwei

NODE 发布

package com.ui.app.req;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/21.
*/
@Data
public class NodeBuild extends AppBaseReq {
private String id;
private String environment;
private String branch;
private String operate;
private String rollbackfile;
}
... ...
package com.ui.app.req;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/21.
*/
@Data
public class NodeMsg extends AppBaseReq {
private String buildNo;
}
... ...
package com.ui.app.req;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/21.
*/
@Data
public class NodeProjectList extends AppBaseReq {
private String environment;
}
... ...
package com.ui.app.req;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/29.
*/
@Data
public class NodeRollbackList extends AppBaseReq{
private String id;
private String environment;
}
... ...
package com.ui.app.resp;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/29.
*/
@Data
public class NodeBuildResp {
private int code;
private String bid;
}
... ...
package com.ui.app.resp;
import lombok.Data;
import java.util.List;
/**
* Created by zhengyouwei on 2016/11/29.
*/
@Data
public class NodeBuildState {
private String build;
private List<NodeHostState> deploy;
}
... ...
package com.ui.app.resp;
import lombok.Data;
/**
* Created by zhengyouwei on 2016/11/29.
*/
@Data
public class NodeHostState {
private String host;
private String state;
}
... ...
... ... @@ -3,6 +3,8 @@ 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.NodeBuildResp;
import com.ui.app.resp.NodeBuildState;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
... ... @@ -61,14 +63,6 @@ public class AppProjectBuildCtrl {
*/
@RequestMapping(value = "app_getrollbacklist", method = RequestMethod.POST)
public BaseResponse rollbackList(@RequestBody RollbackList rollbackListReq) {
//rollbackListReq.setEnvironment("test");
BaseResponse baseResponse = new BaseResponse();
if (StringUtils.isBlank(rollbackListReq.getProject()) || StringUtils.isBlank(rollbackListReq.getEnvironment())) {
... ... @@ -97,14 +91,6 @@ public class AppProjectBuildCtrl {
*/
@RequestMapping(value = "app_build", method = RequestMethod.POST)
public BaseResponse build(@RequestBody ProjectBuild projectBuild) {
// projectBuild.setEnvironment("test");
BaseResponse baseResponse = new BaseResponse();
String project = projectBuild.getProject();
... ... @@ -207,4 +193,116 @@ public class AppProjectBuildCtrl {
return baseResponse;
}
private static final String PHP_URL = "http://node-ci.yohops.com/api/";
/**
* 获取项目列表
*
* @return
*/
@RequestMapping(value = "app_getnodeprojectlist", method = RequestMethod.POST)
public BaseResponse getnodeprojectlist(@RequestBody NodeProjectList nodeProjectList) {
BaseResponse baseResponse = new BaseResponse();
if (StringUtils.isBlank(nodeProjectList.getEnvironment())) {
baseResponse.setCode(ErrorCode.PARAM_ERROR);
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
return baseResponse;
}
String environment = nodeProjectList.getEnvironment();
if ("qcloud_gray".equals(environment)) {
environment = "qcloud";
}
String result = httpClient.get(PHP_URL + "projects?cloud=" + environment, String.class, null);
if (result == null) {
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage("fail to get node/php project list");
return baseResponse;
}
baseResponse.setData(JSONArray.parse(result));
return baseResponse;
}
/**
* 获取回滚列表
*
* @return
*/
@RequestMapping(value = "app_getnoderollbacklist", method = RequestMethod.POST)
public BaseResponse getnoderollbacklist(@RequestBody NodeRollbackList nodeRollbackList) {
BaseResponse baseResponse = new BaseResponse();
if (StringUtils.isBlank(nodeRollbackList.getEnvironment()) || StringUtils.isBlank(nodeRollbackList.getId())) {
baseResponse.setCode(ErrorCode.PARAM_ERROR);
baseResponse.setMessage(ErrorCode.PARAM_ERROR_MESSAGE);
return baseResponse;
}
String env = "production";
String environment = nodeRollbackList.getEnvironment();
if ("qcloud_gray".equals(environment)) {
env = "preview";
}
Map<String, Object> map = new HashMap<>();
map.put("id", nodeRollbackList.getId());
map.put("env", env);
String result = httpClient.get(PHP_URL + "builds", String.class, map);
if (result == null) {
baseResponse.setCode(ErrorCode.SYSTEM_ERROR);
baseResponse.setMessage("fail to get biuld list");
return baseResponse;
}
baseResponse.setData(JSONArray.parse(result));
return baseResponse;
}
/**
* 发布
*
* @return
*/
@RequestMapping(value = "app_nodebuild", method = RequestMethod.POST)
public BaseResponse nodebuild(@RequestBody NodeBuild nodeBuild) {
BaseResponse baseResponse = new BaseResponse();
Map<String, Object> map = new HashMap<>();
if ("Deploy".equals(nodeBuild.getOperate())) {
String env = "production";
String environment = nodeBuild.getEnvironment();
if ("qcloud_gray".equals(environment)) {
env = "preview";
}
map.put("id", nodeBuild.getId());
map.put("env", env);
map.put("branch", nodeBuild.getBranch());
NodeBuildResp result = httpClient.get(PHP_URL + "publish", NodeBuildResp.class, map);
baseResponse.setData(result.getBid());
} else {
map.put("id", nodeBuild.getRollbackfile());
NodeBuildResp result = httpClient.get(PHP_URL + "rollback", NodeBuildResp.class, map);
baseResponse.setData(result.getBid());
}
return baseResponse;
}
/**
* 状态查询
*
* @return
*/
@RequestMapping(value = "app_getnoderesult", method = RequestMethod.POST)
public BaseResponse getnoderesult(@RequestBody NodeMsg nodeMsg) {
BaseResponse baseResponse = new BaseResponse();
Map<String, Object> map = new HashMap<>();
map.put("bid", nodeMsg.getBuildNo());
NodeBuildState result = httpClient.get(PHP_URL + "state", NodeBuildState.class, map);
baseResponse.setData(result);
return baseResponse;
}
}
... ...
... ... @@ -61,8 +61,7 @@
<br/>
<br/>
<span>
tips:测试结果正在获取中,请不要关闭页面。或者您也可以等待邮件,邮件稍后会发送到您的邮箱!
<strong>tips:测试结果正在获取中,请不要关闭页面。或者您也可以等待邮件,邮件稍后会发送到您的邮箱!</strong>
</span>
</div>
... ...