Authored by qinchao

dock发布功能

... ... @@ -14,4 +14,10 @@ public class DockerJenkinsReq {
private String userName;
private String userMail;
private String releaseWorkId;
private String projectType;
//docker qlcoud
private String clusterId;
private String namespace;
private String serviceName;
}
... ...
... ... @@ -11,7 +11,7 @@ import java.util.List;
* Created by craig.qin
*/
public interface DockerJenkinsRecordMapper {
DockerJenkinsRecord selectById(String id);
DockerJenkinsRecord selectById(@Param("id") String id);
int insert(DockerJenkinsRecord dockerJenkinsRecord);
int updateJob(@Param("id") String id ,@Param("jobId") String jobId,@Param("jobStatus")String jobStatus);
}
... ...
... ... @@ -14,6 +14,14 @@
id, projectname, jenkins_job_id,jenkins_build_status,release_work_id,create_time
</sql>
<select id="selectById" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from docker_jenkins_record
where id= #{id}
</select>
<insert id="insert" parameterType="com.model.DockerJenkinsRecord" >
insert into docker_jenkins_record (id, projectname, release_work_id)
values (#{id,jdbcType=VARCHAR}, #{projectName,jdbcType=VARCHAR}, #{ReleaseWorkId,jdbcType=VARCHAR})
... ...
package com.monitor.other.worksystem.ctrl;
import com.alibaba.fastjson.JSONArray;
import com.model.DockerJenkinsRecord;
import com.model.DockerProjectModel;
import com.monitor.model.request.DockerJenkinsReq;
import com.monitor.model.response.BaseResponse;
... ... @@ -48,7 +49,8 @@ public class DockerProjectCtrl {
idList.add(Integer.parseInt(id.trim()));
}
}
return new BaseResponse<>(dockerProjectService.selectByIdList(idList));
List<DockerProjectModel> models= dockerProjectService.selectByIdList(idList);
return new BaseResponse<>(models);
}
/**
... ... @@ -84,24 +86,33 @@ public class DockerProjectCtrl {
*/
@RequestMapping("/queryJenkinsStatus")
@ResponseBody
public BaseResponse queryJenkinsStatus(String ticketID,String jobID,String status) {
dockerProjectService.jenkinsStatusUpdate(ticketID,jobID,status);
public BaseResponse queryJenkinsStatus(String id) {
DockerJenkinsRecord record=dockerProjectService.queryJenkinsById(id);
BaseResponse rnt=new BaseResponse();
if (record==null){
rnt.setCode(201);
rnt.setMessage("找不到Jenkins要更新的记录");
}else{
rnt.setMessage("Jenkins更新jobid:"+record.getJenkinsJobId());
rnt.setData(record.getJenkinsBuildStatus()==null?"":record.getJenkinsBuildStatus());
}
return rnt;
}
/**
* 发布docker服务
*/
@RequestMapping("/deployMirror")
@ResponseBody
public BaseResponse deployMirror() {
public BaseResponse deployMirror(@RequestBody DockerJenkinsReq dockerJenkinsReq) {
BaseResponse rtn=new BaseResponse();
String clusterId="cls-ro6kl3cp";
String namespace="";
String serviceName="node-yohoblk-wap";
String clusterId=dockerJenkinsReq.getClusterId();
String namespace=dockerJenkinsReq.getNamespace()==null?"":dockerJenkinsReq.getNamespace();
String serviceName=dockerJenkinsReq.getServiceName();
if(!dockerServerDeployService.checkAppIsExist(clusterId,namespace,serviceName)){
rtn.setCode(201);
rtn.setMessage("Docker服务不存在,请联系运维人员");
... ... @@ -139,4 +150,19 @@ public class DockerProjectCtrl {
return rtn;
}
/**
* 发布docker服务
*/
@RequestMapping("/queryDockerServerStatus")
@ResponseBody
public BaseResponse queryDockerServerStatus(@RequestBody DockerJenkinsReq dockerJenkinsReq) {
BaseResponse rtn=new BaseResponse();
String clusterId=dockerJenkinsReq.getClusterId();
String namespace=dockerJenkinsReq.getNamespace()==null?"":dockerJenkinsReq.getNamespace();
String serviceName=dockerJenkinsReq.getServiceName();
String status=dockerServerDeployService.queryAppStatus(clusterId,namespace,serviceName);
rtn.setData(status);
return rtn;
}
}
... ...
package com.monitor.other.worksystem.dock.qq;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
... ... @@ -41,6 +42,22 @@ public class DockerServerDeployService {
}
/**
* 检测服务状态
*/
public String queryAppStatus(String clusterId, String namespace, String serviceName) {
String status="";
JSONObject searchResult = txServer.describeClusterServiceInfo(clusterId, namespace,serviceName );
if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){
status=searchResult.getJSONObject("data").getJSONObject("service").getString("status");
}else{
if(searchResult!=null){
status= JSON.toJSONString(searchResult);
}
}
return status;
}
/**
* 检测服务状态是否是Normal
* 返回标志信息和container信息
*
... ...
package com.monitor.other.worksystem.service;
import com.model.DockerJenkinsRecord;
import com.model.DockerProjectModel;
import com.model.PendingJob;
import com.monitor.model.request.DockerJenkinsReq;
... ... @@ -20,5 +21,5 @@ public interface DockerProjectService {
void jenkinsStatusUpdate(String ticketID,String jobID,String status);
String queryJenkinsStatus(String id);
DockerJenkinsRecord queryJenkinsById(String id);
}
... ...
... ... @@ -66,7 +66,13 @@ public class DockerProjectServiceImpl implements DockerProjectService {
dockerJenkinsRecordMapper.insert(record);
FastJenkinsUtils fastJenkinsUtils=new FastJenkinsUtils();
fastJenkinsUtils.createJob(FastJenkinsUtils.JENKINS_JOB_NODE,params);
String jobName="";
if("NODE".equalsIgnoreCase(dockerJenkinsReq.getProjectType())){
jobName=FastJenkinsUtils.JENKINS_JOB_NODE;
}else if("JAVA".equalsIgnoreCase(dockerJenkinsReq.getProjectType())){
jobName=FastJenkinsUtils.JENKINS_JOB_JAVA;
}
fastJenkinsUtils.createJob(jobName,params);
}catch (Exception e){
logger.error("jenkinsBuild error",e);
return "";
... ... @@ -80,8 +86,9 @@ public class DockerProjectServiceImpl implements DockerProjectService {
}
@Override
public String queryJenkinsStatus(String id){
dockerJenkinsRecordMapper.s
public DockerJenkinsRecord queryJenkinsById(String id) {
DockerJenkinsRecord record = dockerJenkinsRecordMapper.selectById(id);
return record;
}
}
... ...