Showing
5 changed files
with
148 additions
and
1 deletions
@@ -10,6 +10,8 @@ import java.util.List; | @@ -10,6 +10,8 @@ import java.util.List; | ||
10 | * Created by craig.qin | 10 | * Created by craig.qin |
11 | */ | 11 | */ |
12 | public interface DockerProjectMapper { | 12 | public interface DockerProjectMapper { |
13 | + DockerProjectModel selectByProjectName(String projectName); | ||
14 | + | ||
13 | int selectCount(); | 15 | int selectCount(); |
14 | 16 | ||
15 | List<DockerProjectModel> selectByPage(PageBean page); | 17 | List<DockerProjectModel> selectByPage(PageBean page); |
@@ -17,6 +17,15 @@ | @@ -17,6 +17,15 @@ | ||
17 | <result column="port" property="port" jdbcType="VARCHAR" /> | 17 | <result column="port" property="port" jdbcType="VARCHAR" /> |
18 | </resultMap> | 18 | </resultMap> |
19 | 19 | ||
20 | + | ||
21 | + <select id="selectByProjectName" resultMap="BaseResultMap"> | ||
22 | + select | ||
23 | + <include refid="Base_Column_List" /> | ||
24 | + from docker_project | ||
25 | + where | ||
26 | + projectname = #{projectName} | ||
27 | + </select> | ||
28 | + | ||
20 | <sql id="Base_Column_List" > | 29 | <sql id="Base_Column_List" > |
21 | id, projectname,projectgitgroup,projectjobtype,dockerprojectname,dockergrayclusterid,dockergraynamespace, | 30 | id, projectname,projectgitgroup,projectjobtype,dockerprojectname,dockergrayclusterid,dockergraynamespace, |
22 | dockergrayimagestore,dockeronlineclusterid,dockeronlinenamespace,dockeronlineimagestore,port | 31 | dockergrayimagestore,dockeronlineclusterid,dockeronlinenamespace,dockeronlineimagestore,port |
@@ -5,8 +5,11 @@ import com.model.DockerJenkinsRecord; | @@ -5,8 +5,11 @@ import com.model.DockerJenkinsRecord; | ||
5 | import com.model.DockerProjectModel; | 5 | import com.model.DockerProjectModel; |
6 | import com.monitor.model.request.DockerJenkinsReq; | 6 | import com.monitor.model.request.DockerJenkinsReq; |
7 | import com.monitor.model.response.BaseResponse; | 7 | import com.monitor.model.response.BaseResponse; |
8 | +import com.monitor.mysql.mapper.DockerProjectMapper; | ||
8 | import com.monitor.other.worksystem.dock.qq.DockerServerDeployService; | 9 | import com.monitor.other.worksystem.dock.qq.DockerServerDeployService; |
10 | +import com.monitor.other.worksystem.model.WebHooksReleaseBO; | ||
9 | import com.monitor.other.worksystem.service.DockerProjectService; | 11 | import com.monitor.other.worksystem.service.DockerProjectService; |
12 | +import com.offbytwo.jenkins.model.JobWithDetails; | ||
10 | import org.apache.commons.lang.StringUtils; | 13 | import org.apache.commons.lang.StringUtils; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 14 | import org.springframework.beans.factory.annotation.Autowired; |
12 | import org.springframework.stereotype.Controller; | 15 | import org.springframework.stereotype.Controller; |
@@ -28,6 +31,9 @@ public class DockerProjectCtrl { | @@ -28,6 +31,9 @@ public class DockerProjectCtrl { | ||
28 | @Autowired | 31 | @Autowired |
29 | private DockerServerDeployService dockerServerDeployService; | 32 | private DockerServerDeployService dockerServerDeployService; |
30 | 33 | ||
34 | + @Autowired | ||
35 | + private DockerProjectMapper dockerProjectMapper; | ||
36 | + | ||
31 | /** | 37 | /** |
32 | * 查询docker项目 | 38 | * 查询docker项目 |
33 | */ | 39 | */ |
@@ -71,6 +77,45 @@ public class DockerProjectCtrl { | @@ -71,6 +77,45 @@ public class DockerProjectCtrl { | ||
71 | } | 77 | } |
72 | 78 | ||
73 | /** | 79 | /** |
80 | + * 发布工单_jenkins:自动发布的项目 | ||
81 | + */ | ||
82 | + @RequestMapping("/gitWebHook") | ||
83 | + @ResponseBody | ||
84 | + public BaseResponse gitWebHook(@RequestBody WebHooksReleaseBO webHooksReleaseBO) { | ||
85 | + BaseResponse rtn=new BaseResponse<>(); | ||
86 | + if (!webHooksReleaseBO.getRef().contains("master")&&StringUtils.isBlank(webHooksReleaseBO.getProjectName())) { | ||
87 | + rtn.setData(""); | ||
88 | + return rtn; | ||
89 | + } | ||
90 | + | ||
91 | + DockerProjectModel model=dockerProjectMapper.selectByProjectName(webHooksReleaseBO.getProjectName()); | ||
92 | + if (isRealChange(webHooksReleaseBO)&&model!=null) { | ||
93 | + //Docker-Deploy-GitHook | ||
94 | + DockerJenkinsReq dockerJenkinsReq=new DockerJenkinsReq(); | ||
95 | + dockerJenkinsReq.setDeployName(model.getProjectName()); | ||
96 | + dockerJenkinsReq.setProjectGitGroup(model.getProjectGitGroup()); | ||
97 | + dockerJenkinsReq.setDeployName(model.getDockerProjectName()); | ||
98 | + dockerJenkinsReq.setBranch("master"); | ||
99 | + dockerJenkinsReq.setUserMail(webHooksReleaseBO.getUser_email()); | ||
100 | + dockerJenkinsReq.setImageSource(model.getDockerOnlineImageStore()); | ||
101 | + dockerJenkinsReq.setNodeEnv("yoho-online"); | ||
102 | + String id=dockerProjectService.jenkinsBuild(dockerJenkinsReq); | ||
103 | + rtn.setData(id); | ||
104 | + } | ||
105 | + | ||
106 | + return rtn; | ||
107 | + } | ||
108 | + | ||
109 | + public Boolean isRealChange(WebHooksReleaseBO webHooksReleaseBO) { | ||
110 | + boolean object_kind_check = webHooksReleaseBO.getObject_kind().equals("push"); | ||
111 | + boolean ref_check = webHooksReleaseBO.getRef().equals("refs/heads/master"); | ||
112 | + boolean total_commits_count_check = webHooksReleaseBO.getTotal_commits_count() > 0; | ||
113 | + return object_kind_check && ref_check && total_commits_count_check; | ||
114 | + } | ||
115 | + | ||
116 | + | ||
117 | + | ||
118 | + /** | ||
74 | * 发布工单_jenkins:更新镜像的状态 | 119 | * 发布工单_jenkins:更新镜像的状态 |
75 | */ | 120 | */ |
76 | @RequestMapping("/updateJenkinsStatus") | 121 | @RequestMapping("/updateJenkinsStatus") |
monitor-service-other/src/main/java/com/monitor/other/worksystem/model/WebHooksReleaseBO.java
0 → 100644
1 | +package com.monitor.other.worksystem.model; | ||
2 | + | ||
3 | + | ||
4 | +import java.util.Set; | ||
5 | + | ||
6 | +/** | ||
7 | + * Created by jimi on 2017/9/18. | ||
8 | + */ | ||
9 | +public class WebHooksReleaseBO { | ||
10 | + | ||
11 | + private String object_kind; | ||
12 | + private String ref; | ||
13 | + private Integer total_commits_count; | ||
14 | + private Set<String> changFileForDockerFile; | ||
15 | + private String projectName ; | ||
16 | + private String projectNameSpace ; | ||
17 | + private String gitUrl; | ||
18 | + private String user_name; | ||
19 | + private String user_email; | ||
20 | + | ||
21 | + public String getUser_email() { | ||
22 | + return user_email; | ||
23 | + } | ||
24 | + | ||
25 | + public void setUser_email(String user_email) { | ||
26 | + this.user_email = user_email; | ||
27 | + } | ||
28 | + | ||
29 | + public String getUser_name() { | ||
30 | + return user_name; | ||
31 | + } | ||
32 | + | ||
33 | + public void setUser_name(String user_name) { | ||
34 | + this.user_name = user_name; | ||
35 | + } | ||
36 | + | ||
37 | + public String getGitUrl() { | ||
38 | + return gitUrl; | ||
39 | + } | ||
40 | + | ||
41 | + public void setGitUrl(String gitUrl) { | ||
42 | + this.gitUrl = gitUrl; | ||
43 | + } | ||
44 | + | ||
45 | + public String getProjectName() { | ||
46 | + return projectName; | ||
47 | + } | ||
48 | + | ||
49 | + public void setProjectName(String projectName) { | ||
50 | + this.projectName = projectName; | ||
51 | + } | ||
52 | + | ||
53 | + public String getProjectNameSpace() { | ||
54 | + return projectNameSpace; | ||
55 | + } | ||
56 | + | ||
57 | + public void setProjectNameSpace(String projectNameSpace) { | ||
58 | + this.projectNameSpace = projectNameSpace; | ||
59 | + } | ||
60 | + | ||
61 | + public String getObject_kind() { | ||
62 | + return object_kind; | ||
63 | + } | ||
64 | + | ||
65 | + public void setObject_kind(String object_kind) { | ||
66 | + this.object_kind = object_kind; | ||
67 | + } | ||
68 | + | ||
69 | + public String getRef() { | ||
70 | + return ref; | ||
71 | + } | ||
72 | + | ||
73 | + public void setRef(String ref) { | ||
74 | + this.ref = ref; | ||
75 | + } | ||
76 | + | ||
77 | + public Integer getTotal_commits_count() { | ||
78 | + return total_commits_count; | ||
79 | + } | ||
80 | + | ||
81 | + public void setTotal_commits_count(Integer total_commits_count) { | ||
82 | + this.total_commits_count = total_commits_count; | ||
83 | + } | ||
84 | + | ||
85 | + public Set<String> getChangFileForDockerFile() { | ||
86 | + return changFileForDockerFile; | ||
87 | + } | ||
88 | + | ||
89 | + public void setChangFileForDockerFile(Set<String> changFileForDockerFile) { | ||
90 | + this.changFileForDockerFile = changFileForDockerFile; | ||
91 | + } | ||
92 | +} |
@@ -56,7 +56,6 @@ public class DockerProjectServiceImpl implements DockerProjectService { | @@ -56,7 +56,6 @@ public class DockerProjectServiceImpl implements DockerProjectService { | ||
56 | params.put("ticketID", uuid); | 56 | params.put("ticketID", uuid); |
57 | params.put("projectName",dockerJenkinsReq.getProjectName()); | 57 | params.put("projectName",dockerJenkinsReq.getProjectName()); |
58 | params.put("projectGitGroup",dockerJenkinsReq.getProjectGitGroup()); | 58 | params.put("projectGitGroup",dockerJenkinsReq.getProjectGitGroup()); |
59 | - params.put("projectGitGroup",dockerJenkinsReq.getProjectGitGroup()); | ||
60 | params.put("deployName",deployName); | 59 | params.put("deployName",deployName); |
61 | params.put("branch",dockerJenkinsReq.getBranch()); | 60 | params.put("branch",dockerJenkinsReq.getBranch()); |
62 | params.put("nodeEnv",dockerJenkinsReq.getNodeEnv()); | 61 | params.put("nodeEnv",dockerJenkinsReq.getNodeEnv()); |
-
Please register or login to post a comment