Authored by qinchao

dock发布功能

@@ -14,4 +14,10 @@ public class DockerJenkinsReq { @@ -14,4 +14,10 @@ public class DockerJenkinsReq {
14 private String userName; 14 private String userName;
15 private String userMail; 15 private String userMail;
16 private String releaseWorkId; 16 private String releaseWorkId;
  17 + private String projectType;
  18 +
  19 + //docker qlcoud
  20 + private String clusterId;
  21 + private String namespace;
  22 + private String serviceName;
17 } 23 }
@@ -11,7 +11,7 @@ import java.util.List; @@ -11,7 +11,7 @@ import java.util.List;
11 * Created by craig.qin 11 * Created by craig.qin
12 */ 12 */
13 public interface DockerJenkinsRecordMapper { 13 public interface DockerJenkinsRecordMapper {
14 - DockerJenkinsRecord selectById(String id); 14 + DockerJenkinsRecord selectById(@Param("id") String id);
15 int insert(DockerJenkinsRecord dockerJenkinsRecord); 15 int insert(DockerJenkinsRecord dockerJenkinsRecord);
16 int updateJob(@Param("id") String id ,@Param("jobId") String jobId,@Param("jobStatus")String jobStatus); 16 int updateJob(@Param("id") String id ,@Param("jobId") String jobId,@Param("jobStatus")String jobStatus);
17 } 17 }
@@ -14,6 +14,14 @@ @@ -14,6 +14,14 @@
14 id, projectname, jenkins_job_id,jenkins_build_status,release_work_id,create_time 14 id, projectname, jenkins_job_id,jenkins_build_status,release_work_id,create_time
15 </sql> 15 </sql>
16 16
  17 + <select id="selectById" resultMap="BaseResultMap">
  18 + select
  19 + <include refid="Base_Column_List" />
  20 + from docker_jenkins_record
  21 + where id= #{id}
  22 + </select>
  23 +
  24 +
17 <insert id="insert" parameterType="com.model.DockerJenkinsRecord" > 25 <insert id="insert" parameterType="com.model.DockerJenkinsRecord" >
18 insert into docker_jenkins_record (id, projectname, release_work_id) 26 insert into docker_jenkins_record (id, projectname, release_work_id)
19 values (#{id,jdbcType=VARCHAR}, #{projectName,jdbcType=VARCHAR}, #{ReleaseWorkId,jdbcType=VARCHAR}) 27 values (#{id,jdbcType=VARCHAR}, #{projectName,jdbcType=VARCHAR}, #{ReleaseWorkId,jdbcType=VARCHAR})
1 package com.monitor.other.worksystem.ctrl; 1 package com.monitor.other.worksystem.ctrl;
2 2
3 import com.alibaba.fastjson.JSONArray; 3 import com.alibaba.fastjson.JSONArray;
  4 +import com.model.DockerJenkinsRecord;
4 import com.model.DockerProjectModel; 5 import com.model.DockerProjectModel;
5 import com.monitor.model.request.DockerJenkinsReq; 6 import com.monitor.model.request.DockerJenkinsReq;
6 import com.monitor.model.response.BaseResponse; 7 import com.monitor.model.response.BaseResponse;
@@ -48,7 +49,8 @@ public class DockerProjectCtrl { @@ -48,7 +49,8 @@ public class DockerProjectCtrl {
48 idList.add(Integer.parseInt(id.trim())); 49 idList.add(Integer.parseInt(id.trim()));
49 } 50 }
50 } 51 }
51 - return new BaseResponse<>(dockerProjectService.selectByIdList(idList)); 52 + List<DockerProjectModel> models= dockerProjectService.selectByIdList(idList);
  53 + return new BaseResponse<>(models);
52 } 54 }
53 55
54 /** 56 /**
@@ -84,24 +86,33 @@ public class DockerProjectCtrl { @@ -84,24 +86,33 @@ public class DockerProjectCtrl {
84 */ 86 */
85 @RequestMapping("/queryJenkinsStatus") 87 @RequestMapping("/queryJenkinsStatus")
86 @ResponseBody 88 @ResponseBody
87 - public BaseResponse queryJenkinsStatus(String ticketID,String jobID,String status) {  
88 - dockerProjectService.jenkinsStatusUpdate(ticketID,jobID,status); 89 + public BaseResponse queryJenkinsStatus(String id) {
  90 + DockerJenkinsRecord record=dockerProjectService.queryJenkinsById(id);
89 BaseResponse rnt=new BaseResponse(); 91 BaseResponse rnt=new BaseResponse();
  92 + if (record==null){
  93 + rnt.setCode(201);
  94 + rnt.setMessage("找不到Jenkins要更新的记录");
  95 + }else{
  96 + rnt.setMessage("Jenkins更新jobid:"+record.getJenkinsJobId());
  97 + rnt.setData(record.getJenkinsBuildStatus()==null?"":record.getJenkinsBuildStatus());
  98 + }
  99 +
90 return rnt; 100 return rnt;
91 } 101 }
92 102
93 103
  104 +
94 /** 105 /**
95 * 发布docker服务 106 * 发布docker服务
96 */ 107 */
97 @RequestMapping("/deployMirror") 108 @RequestMapping("/deployMirror")
98 @ResponseBody 109 @ResponseBody
99 - public BaseResponse deployMirror() { 110 + public BaseResponse deployMirror(@RequestBody DockerJenkinsReq dockerJenkinsReq) {
100 BaseResponse rtn=new BaseResponse(); 111 BaseResponse rtn=new BaseResponse();
101 112
102 - String clusterId="cls-ro6kl3cp";  
103 - String namespace="";  
104 - String serviceName="node-yohoblk-wap"; 113 + String clusterId=dockerJenkinsReq.getClusterId();
  114 + String namespace=dockerJenkinsReq.getNamespace()==null?"":dockerJenkinsReq.getNamespace();
  115 + String serviceName=dockerJenkinsReq.getServiceName();
105 if(!dockerServerDeployService.checkAppIsExist(clusterId,namespace,serviceName)){ 116 if(!dockerServerDeployService.checkAppIsExist(clusterId,namespace,serviceName)){
106 rtn.setCode(201); 117 rtn.setCode(201);
107 rtn.setMessage("Docker服务不存在,请联系运维人员"); 118 rtn.setMessage("Docker服务不存在,请联系运维人员");
@@ -139,4 +150,19 @@ public class DockerProjectCtrl { @@ -139,4 +150,19 @@ public class DockerProjectCtrl {
139 return rtn; 150 return rtn;
140 } 151 }
141 152
  153 +
  154 + /**
  155 + * 发布docker服务
  156 + */
  157 + @RequestMapping("/queryDockerServerStatus")
  158 + @ResponseBody
  159 + public BaseResponse queryDockerServerStatus(@RequestBody DockerJenkinsReq dockerJenkinsReq) {
  160 + BaseResponse rtn=new BaseResponse();
  161 + String clusterId=dockerJenkinsReq.getClusterId();
  162 + String namespace=dockerJenkinsReq.getNamespace()==null?"":dockerJenkinsReq.getNamespace();
  163 + String serviceName=dockerJenkinsReq.getServiceName();
  164 + String status=dockerServerDeployService.queryAppStatus(clusterId,namespace,serviceName);
  165 + rtn.setData(status);
  166 + return rtn;
  167 + }
142 } 168 }
1 package com.monitor.other.worksystem.dock.qq; 1 package com.monitor.other.worksystem.dock.qq;
2 2
  3 +import com.alibaba.fastjson.JSON;
3 import com.alibaba.fastjson.JSONArray; 4 import com.alibaba.fastjson.JSONArray;
4 import com.alibaba.fastjson.JSONObject; 5 import com.alibaba.fastjson.JSONObject;
5 import org.apache.commons.lang.StringUtils; 6 import org.apache.commons.lang.StringUtils;
@@ -41,6 +42,22 @@ public class DockerServerDeployService { @@ -41,6 +42,22 @@ public class DockerServerDeployService {
41 } 42 }
42 43
43 /** 44 /**
  45 + * 检测服务状态
  46 + */
  47 + public String queryAppStatus(String clusterId, String namespace, String serviceName) {
  48 + String status="";
  49 + JSONObject searchResult = txServer.describeClusterServiceInfo(clusterId, namespace,serviceName );
  50 + if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){
  51 + status=searchResult.getJSONObject("data").getJSONObject("service").getString("status");
  52 + }else{
  53 + if(searchResult!=null){
  54 + status= JSON.toJSONString(searchResult);
  55 + }
  56 + }
  57 + return status;
  58 + }
  59 +
  60 + /**
44 * 检测服务状态是否是Normal 61 * 检测服务状态是否是Normal
45 * 返回标志信息和container信息 62 * 返回标志信息和container信息
46 * 63 *
1 package com.monitor.other.worksystem.service; 1 package com.monitor.other.worksystem.service;
2 2
  3 +import com.model.DockerJenkinsRecord;
3 import com.model.DockerProjectModel; 4 import com.model.DockerProjectModel;
4 import com.model.PendingJob; 5 import com.model.PendingJob;
5 import com.monitor.model.request.DockerJenkinsReq; 6 import com.monitor.model.request.DockerJenkinsReq;
@@ -20,5 +21,5 @@ public interface DockerProjectService { @@ -20,5 +21,5 @@ public interface DockerProjectService {
20 21
21 void jenkinsStatusUpdate(String ticketID,String jobID,String status); 22 void jenkinsStatusUpdate(String ticketID,String jobID,String status);
22 23
23 - String queryJenkinsStatus(String id); 24 + DockerJenkinsRecord queryJenkinsById(String id);
24 } 25 }
@@ -66,7 +66,13 @@ public class DockerProjectServiceImpl implements DockerProjectService { @@ -66,7 +66,13 @@ public class DockerProjectServiceImpl implements DockerProjectService {
66 dockerJenkinsRecordMapper.insert(record); 66 dockerJenkinsRecordMapper.insert(record);
67 67
68 FastJenkinsUtils fastJenkinsUtils=new FastJenkinsUtils(); 68 FastJenkinsUtils fastJenkinsUtils=new FastJenkinsUtils();
69 - fastJenkinsUtils.createJob(FastJenkinsUtils.JENKINS_JOB_NODE,params); 69 + String jobName="";
  70 + if("NODE".equalsIgnoreCase(dockerJenkinsReq.getProjectType())){
  71 + jobName=FastJenkinsUtils.JENKINS_JOB_NODE;
  72 + }else if("JAVA".equalsIgnoreCase(dockerJenkinsReq.getProjectType())){
  73 + jobName=FastJenkinsUtils.JENKINS_JOB_JAVA;
  74 + }
  75 + fastJenkinsUtils.createJob(jobName,params);
70 }catch (Exception e){ 76 }catch (Exception e){
71 logger.error("jenkinsBuild error",e); 77 logger.error("jenkinsBuild error",e);
72 return ""; 78 return "";
@@ -80,8 +86,9 @@ public class DockerProjectServiceImpl implements DockerProjectService { @@ -80,8 +86,9 @@ public class DockerProjectServiceImpl implements DockerProjectService {
80 } 86 }
81 87
82 @Override 88 @Override
83 - public String queryJenkinsStatus(String id){  
84 - dockerJenkinsRecordMapper.s 89 + public DockerJenkinsRecord queryJenkinsById(String id) {
  90 + DockerJenkinsRecord record = dockerJenkinsRecordMapper.selectById(id);
  91 + return record;
85 } 92 }
86 93
87 } 94 }