Showing
5 changed files
with
566 additions
and
15 deletions
monitor-service-other/src/main/java/com/monitor/other/worksystem/dock/DockerServerDeployCtrl.java
0 → 100644
1 | +package com.monitor.other.worksystem.dock; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONArray; | ||
4 | +import com.model.ReleaseWorkJob; | ||
5 | +import com.monitor.model.response.BaseResponse; | ||
6 | +import com.monitor.other.worksystem.dock.qq.DockerServerDeployService; | ||
7 | +import com.monitor.other.worksystem.service.ReleaseService; | ||
8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
9 | +import org.springframework.stereotype.Controller; | ||
10 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
11 | +import org.springframework.web.bind.annotation.ResponseBody; | ||
12 | + | ||
13 | +import java.util.HashMap; | ||
14 | +import java.util.Map; | ||
15 | + | ||
16 | +@Controller | ||
17 | +@RequestMapping("/work/docker") | ||
18 | +public class DockerServerDeployCtrl { | ||
19 | + @Autowired | ||
20 | + private ReleaseService releaseService; | ||
21 | + @Autowired | ||
22 | + private DockerServerDeployService dockerServerDeployService; | ||
23 | + | ||
24 | + | ||
25 | + /** | ||
26 | + * 发布工单_jenkins:发起镜像制作 | ||
27 | + */ | ||
28 | + @RequestMapping("/createMirror") | ||
29 | + @ResponseBody | ||
30 | + public BaseResponse createMirror() { | ||
31 | + ReleaseWorkJob releaseWorkJob=new ReleaseWorkJob(); | ||
32 | + int jobId=releaseService.jenkinsBuild(releaseWorkJob); | ||
33 | + BaseResponse rnt=new BaseResponse(); | ||
34 | + rnt.setData(jobId); | ||
35 | + return rnt; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * 发布docker服务 | ||
40 | + */ | ||
41 | + @RequestMapping("/deployMirror") | ||
42 | + @ResponseBody | ||
43 | + public BaseResponse deployMirror() { | ||
44 | + BaseResponse rtn=new BaseResponse(); | ||
45 | + | ||
46 | + String clusterId="cls-ro6kl3cp"; | ||
47 | + String namespace=""; | ||
48 | + String serviceName="node-yohoblk-wap"; | ||
49 | + if(!dockerServerDeployService.checkAppIsExist(clusterId,namespace,serviceName)){ | ||
50 | + rtn.setCode(201); | ||
51 | + rtn.setMessage("Docker服务不存在,请联系运维人员"); | ||
52 | + return rtn; | ||
53 | + } | ||
54 | + | ||
55 | + Map<String,Object> statusMap=dockerServerDeployService.checkAppStatusIsNormal(clusterId,namespace,serviceName); | ||
56 | + boolean normalStatusFlag=(boolean)statusMap.get("result"); | ||
57 | + if(!normalStatusFlag){ | ||
58 | + rtn.setCode(201); | ||
59 | + rtn.setMessage("Docker服务非Normal状态,发布中止!"); | ||
60 | + return rtn; | ||
61 | + } | ||
62 | + JSONArray containerJa=(JSONArray)statusMap.get("containerJa"); | ||
63 | + boolean currentImageLatestFlag=dockerServerDeployService.checkImageLatestWithModifyFlag(clusterId, namespace, serviceName, containerJa,false); | ||
64 | + if(currentImageLatestFlag){ | ||
65 | + //开始重新发布 | ||
66 | + boolean deploySuccess=dockerServerDeployService.redeployClusterService(clusterId, namespace, serviceName); | ||
67 | + if(!deploySuccess){ | ||
68 | + rtn.setCode(201); | ||
69 | + rtn.setMessage("Docker服务重新发布失败,请联系运维人员"); | ||
70 | + return rtn; | ||
71 | + } | ||
72 | + }else{ | ||
73 | + currentImageLatestFlag=dockerServerDeployService.checkImageLatestWithModifyFlag(clusterId, namespace, serviceName, containerJa,true); | ||
74 | + if(!currentImageLatestFlag){ | ||
75 | + rtn.setCode(201); | ||
76 | + rtn.setMessage("Docker服务修改镜像服务发生异常"); | ||
77 | + return rtn; | ||
78 | + } | ||
79 | + //重新部署 | ||
80 | + | ||
81 | + } | ||
82 | + return rtn; | ||
83 | + } | ||
84 | + | ||
85 | +} |
@@ -14,21 +14,6 @@ public class JenkinsCtrl { | @@ -14,21 +14,6 @@ public class JenkinsCtrl { | ||
14 | @Autowired | 14 | @Autowired |
15 | private ReleaseService releaseService; | 15 | private ReleaseService releaseService; |
16 | 16 | ||
17 | - | ||
18 | - /** | ||
19 | - * 发布工单_jenkins:发起镜像制作 | ||
20 | - */ | ||
21 | - @RequestMapping("/createMirror") | ||
22 | - @ResponseBody | ||
23 | - public BaseResponse createMirror() { | ||
24 | - ReleaseWorkJob releaseWorkJob=new ReleaseWorkJob(); | ||
25 | - int jobId=releaseService.jenkinsBuild(releaseWorkJob); | ||
26 | - BaseResponse rnt=new BaseResponse(); | ||
27 | - rnt.setData(jobId); | ||
28 | - System.out.println("jobId is "+jobId); | ||
29 | - return rnt; | ||
30 | - } | ||
31 | - | ||
32 | /** | 17 | /** |
33 | * 发布工单_jenkins:更新镜像的状态 | 18 | * 发布工单_jenkins:更新镜像的状态 |
34 | */ | 19 | */ |
monitor-service-other/src/main/java/com/monitor/other/worksystem/dock/qq/CcsApiQcloud.java
0 → 100644
1 | +package com.monitor.other.worksystem.dock.qq; | ||
2 | + | ||
3 | +import org.apache.commons.codec.binary.Base64; | ||
4 | +import org.springframework.stereotype.Component; | ||
5 | + | ||
6 | +import javax.crypto.Mac; | ||
7 | +import javax.crypto.spec.SecretKeySpec; | ||
8 | +import java.net.URLEncoder; | ||
9 | +import java.util.*; | ||
10 | + | ||
11 | +/** | ||
12 | + * Created by jimi on 2017/9/14. | ||
13 | + */ | ||
14 | +@Component | ||
15 | +public class CcsApiQcloud { | ||
16 | + | ||
17 | + public String pushTest(Map<String, String> paraMap) { | ||
18 | + String secretId = "AKID6dwpKadiQgbDpXDtyNhppIHPO5qPv5GK"; | ||
19 | + //用于加密签名字符串和服务器端验证签名字符串的密钥 | ||
20 | + String secretKey = "ACJkH9mg0DBA1PYpf0E7f3g534wBsQaW"; | ||
21 | + //当前时间戳 | ||
22 | + long timestamp = System.currentTimeMillis() / 1000; | ||
23 | + //随机的正整数 | ||
24 | + int nonce = (new Random()).nextInt(100000); | ||
25 | + //实例所在区域 | ||
26 | + String region = "bj"; | ||
27 | + //签名方式 | ||
28 | + String signatureMethod = "HmacSHA256"; | ||
29 | + paraMap.put("Nonce", String.valueOf(nonce)); | ||
30 | + paraMap.put("Region", region); | ||
31 | + paraMap.put("SecretId", secretId); | ||
32 | + paraMap.put("SignatureMethod", signatureMethod); | ||
33 | + paraMap.put("Timestamp", String.valueOf(timestamp)); | ||
34 | + | ||
35 | + List<String> listPara = new ArrayList<String> (); | ||
36 | + StringBuffer buffer = new StringBuffer(); | ||
37 | + | ||
38 | + listPara.addAll(paraMap.keySet()); | ||
39 | + Collections.sort(listPara); | ||
40 | + for (String mykey :listPara) { | ||
41 | + if (buffer.length() > 0) { | ||
42 | + buffer.append("&"); | ||
43 | + buffer.append(mykey + "=" + paraMap.get(mykey)); | ||
44 | + } else { | ||
45 | + buffer.append(mykey + "=" + paraMap.get(mykey)); | ||
46 | + } | ||
47 | + } | ||
48 | + String url = "GETccs.api.qcloud.com/v2/index.php?" + buffer.toString(); | ||
49 | + String signature = getSignature(url); | ||
50 | + System.out.println("https://ccs.api.qcloud.com/v2/index.php?" + buffer.toString() + "&Signature=" + signature); | ||
51 | + return buffer.toString() + "&Signature=" + signature; | ||
52 | + } | ||
53 | + | ||
54 | + | ||
55 | + private String getSignature(String url) { | ||
56 | + String returnValue = ""; | ||
57 | + try { | ||
58 | + String secretKey = "ACJkH9mg0DBA1PYpf0E7f3g534wBsQaW"; | ||
59 | + Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); | ||
60 | + SecretKeySpec secret_key = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256"); | ||
61 | + sha256_HMAC.init(secret_key); | ||
62 | + String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(url.getBytes())); | ||
63 | + returnValue = URLEncoder.encode(hash, "GBK"); | ||
64 | + } catch (Exception e) { | ||
65 | + e.printStackTrace(); | ||
66 | + } | ||
67 | + return returnValue; | ||
68 | + } | ||
69 | + | ||
70 | + | ||
71 | + public static void main(String[] args) { | ||
72 | + String imageName="yoho-core/es"; | ||
73 | + String imageNameShow="es"; | ||
74 | + CcsApiQcloud ccsApiQcloud = new CcsApiQcloud(); | ||
75 | + Map<String, String> paraMap = new HashMap<>(); | ||
76 | + paraMap.put("clusterId", "cls-qz2lezjt"); | ||
77 | + paraMap.put("Action", "CreateClusterService"); | ||
78 | + paraMap.put("serviceName", imageNameShow); | ||
79 | + paraMap.put("serviceDesc", "testyoho-" + imageNameShow); | ||
80 | + paraMap.put("replicas", "1"); | ||
81 | + paraMap.put("accessType", "ClusterIP"); | ||
82 | + paraMap.put("portMappings.0.protocol", "TCP"); | ||
83 | + String port = "9200"; | ||
84 | + paraMap.put("portMappings.0.containerPort", port); | ||
85 | + paraMap.put("portMappings.0.lbPort", port);//防止端口冲突 | ||
86 | + paraMap.put("portMappings.0.nodePort", "0");//防止端口冲突 | ||
87 | + paraMap.put("containers.0.containerName", imageNameShow); | ||
88 | + paraMap.put("namespace", "default"); | ||
89 | + paraMap.put("containers.0.image", "ccr.ccs.tencentyun.com/" + imageName); | ||
90 | + String jsonObject = ccsApiQcloud.pushTest(paraMap); | ||
91 | + System.out.println(jsonObject); | ||
92 | + } | ||
93 | + | ||
94 | +} |
1 | +package com.monitor.other.worksystem.dock.qq; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONArray; | ||
4 | +import com.alibaba.fastjson.JSONObject; | ||
5 | +import org.apache.commons.lang.StringUtils; | ||
6 | +import org.apache.commons.lang.math.NumberUtils; | ||
7 | +import org.slf4j.Logger; | ||
8 | +import org.slf4j.LoggerFactory; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import java.util.HashMap; | ||
13 | +import java.util.Map; | ||
14 | + | ||
15 | +/** | ||
16 | + * Created by jimi on 2017/11/6. | ||
17 | + */ | ||
18 | +@Service | ||
19 | +public class DockerServerDeployService { | ||
20 | + | ||
21 | + @Autowired | ||
22 | + private QqDockerServiceUtils txServer; | ||
23 | + | ||
24 | + private static final Logger logger = LoggerFactory.getLogger(DockerServerDeployService.class); | ||
25 | + | ||
26 | + /** | ||
27 | + * 检查是否存在服务 | ||
28 | + * @param checkedServiceName 需要检查的服务名称 | ||
29 | + */ | ||
30 | + public boolean checkAppIsExist(String clusterId, String namespace,String checkedServiceName){ | ||
31 | + JSONObject searchResult=txServer.describeClusterService(clusterId,namespace); | ||
32 | + if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){ | ||
33 | + JSONArray jaServices=searchResult.getJSONObject("data").getJSONArray("services"); | ||
34 | + for(int i=0;i<jaServices.size();i++){ | ||
35 | + if(checkedServiceName.equals(jaServices.getJSONObject(i).getString("serviceName"))){ | ||
36 | + return true; | ||
37 | + } | ||
38 | + } | ||
39 | + } | ||
40 | + return false; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * 检测服务状态是否是Normal | ||
45 | + * 返回标志信息和container信息 | ||
46 | + * | ||
47 | + * serviceName.replace("_","-") | ||
48 | + */ | ||
49 | + public Map<String,Object> checkAppStatusIsNormal(String clusterId, String namespace, String serviceName) { | ||
50 | + int requestTime=3; | ||
51 | + return checkAppStatusIsNormal(clusterId,namespace,serviceName,requestTime); | ||
52 | + } | ||
53 | + | ||
54 | + private Map<String,Object> checkAppStatusIsNormal(String clusterId, String namespace, String serviceName, int requestTime) { | ||
55 | + //List<String> myString = Splitter.on(",").omitEmptyStrings().splitToList(serviceNames); | ||
56 | + boolean normalFlag=false; | ||
57 | + JSONArray containerJa=null; | ||
58 | + for (int i = 0; i < requestTime; i++) { | ||
59 | + JSONObject searchResult = txServer.describeClusterServiceInfo(clusterId, namespace,serviceName ); | ||
60 | + logger.info("第 {} 次检测服务 {} 是否正常 ,返回结果 {}", i,serviceName,searchResult); | ||
61 | + boolean singleResult = searchResult!=null | ||
62 | + &&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO) | ||
63 | + &&searchResult.getJSONObject("data").getJSONObject("service").getString("status").equals("Normal"); | ||
64 | + boolean result = true; | ||
65 | + result = result && singleResult; | ||
66 | + | ||
67 | + if (result == true) { | ||
68 | + normalFlag=result; | ||
69 | + containerJa=searchResult.getJSONObject("data").getJSONObject("service").getJSONArray("containers"); | ||
70 | + break; | ||
71 | + } | ||
72 | + } | ||
73 | + Map<String,Object> map=new HashMap<>(); | ||
74 | + map.put("result",normalFlag); | ||
75 | + map.put("containerJa",containerJa); | ||
76 | + return map; | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * 检测服务的container的镜像文件是否是latest, | ||
81 | + * 如果不是需要修改镜像的版本为latest | ||
82 | + */ | ||
83 | + public boolean checkImageLatestWithModifyFlag(String clusterId, String namespace, String serviceName,JSONArray containerJa,boolean modifyFlag){ | ||
84 | + if(containerJa==null||containerJa.size()<=0){ | ||
85 | + logger.info("modifyClusterServiceImageFailed: container is empty !"); | ||
86 | + return false; | ||
87 | + } | ||
88 | + boolean correctImageFlag=false; | ||
89 | + for(int i=0;i<containerJa.size();i++){ | ||
90 | + JSONObject jo=containerJa.getJSONObject(i); | ||
91 | + String image=jo.getString("image"); | ||
92 | + | ||
93 | + if(StringUtils.isNotBlank(image)&&image.indexOf("/"+serviceName+":")>0){ | ||
94 | + int index=image.lastIndexOf(":"); | ||
95 | + String imageLeft=image.substring(0,index); | ||
96 | + String imageRight=image.substring(index+1); | ||
97 | + if("latest".equals(imageRight)){ | ||
98 | + correctImageFlag=true; | ||
99 | + break; | ||
100 | + }else{ | ||
101 | + if(modifyFlag){ | ||
102 | + String containersIndexName="containers."+i+".containerName"; | ||
103 | + String containersIndexNameValue=jo.getString("containerName"); | ||
104 | + String containersIndexImage="containers."+i+".image"; | ||
105 | + String containersIndexImageValue=imageLeft+":latest"; | ||
106 | + JSONObject searchResult = txServer.modifyClusterServiceImage(clusterId, namespace,serviceName ,containersIndexName,containersIndexNameValue,containersIndexImage,containersIndexImageValue); | ||
107 | + if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){ | ||
108 | + correctImageFlag=true; | ||
109 | + } | ||
110 | + break; | ||
111 | + } | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + } | ||
116 | + return correctImageFlag; | ||
117 | + } | ||
118 | + | ||
119 | + /** | ||
120 | + * 重新发布 | ||
121 | + */ | ||
122 | + public boolean redeployClusterService(String clusterId, String namespace, String serviceName){ | ||
123 | + JSONObject searchResult =txServer.redeployClusterService(clusterId,namespace,serviceName); | ||
124 | + if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){ | ||
125 | + return true; | ||
126 | + }else{ | ||
127 | + logger.error("redeployClusterServiceFailed ,response is {} ",searchResult); | ||
128 | + return false; | ||
129 | + } | ||
130 | + } | ||
131 | + | ||
132 | + public static void main(String args[]){ | ||
133 | + String image="xxxxxxx/fddfdf:wwwxxx"; | ||
134 | + int index=image.lastIndexOf(":"); | ||
135 | + String imageLeft=image.substring(0,index); | ||
136 | + String imageRight=image.substring(index+1); | ||
137 | + System.out.println(imageLeft); | ||
138 | + System.out.println(imageRight); | ||
139 | + } | ||
140 | +} |
monitor-service-other/src/main/java/com/monitor/other/worksystem/dock/qq/QqDockerServiceUtils.java
0 → 100644
1 | +package com.monitor.other.worksystem.dock.qq; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSONObject; | ||
4 | +import com.google.common.collect.Maps; | ||
5 | +import com.monitor.common.util.HttpClientUtil; | ||
6 | +import org.apache.commons.lang3.StringUtils; | ||
7 | +import org.slf4j.Logger; | ||
8 | +import org.slf4j.LoggerFactory; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import java.util.Map; | ||
13 | + | ||
14 | +/** | ||
15 | + * Created by jimi on 2017/9/14. | ||
16 | + */ | ||
17 | +@Service | ||
18 | +public class QqDockerServiceUtils { | ||
19 | + private static final Logger logger = LoggerFactory.getLogger(QqDockerServiceUtils.class); | ||
20 | + | ||
21 | + private final String requestUrl = "https://ccs.api.qcloud.com/v2/index.php"; | ||
22 | + | ||
23 | + @Autowired | ||
24 | + private CcsApiQcloud ccsApiQcloud; | ||
25 | + | ||
26 | + /** | ||
27 | + * 查询服务列表,该接口返回的列表只包含服务的扼要信息, | ||
28 | + * 如果需要获取详细的服务信息,需要调用 DescribeClusterServiceInfo 接口 | ||
29 | + */ | ||
30 | + public JSONObject describeClusterService(String clusterId, String namespace) { | ||
31 | + JSONObject resultJson=null; | ||
32 | + try{ | ||
33 | + Map<String, String> paraMap = Maps.newHashMap(); | ||
34 | + paraMap.put("Action", "DescribeClusterService"); | ||
35 | + paraMap.put("clusterId", clusterId); | ||
36 | + if (StringUtils.isNotEmpty(namespace)) { | ||
37 | + paraMap.put("namespace", namespace); | ||
38 | + } else { | ||
39 | + paraMap.put("namespace", "default"); | ||
40 | + } | ||
41 | + String backString = ccsApiQcloud.pushTest(paraMap); | ||
42 | + String uri=requestUrl+"?"+backString; | ||
43 | + String qqResponseJsonStr =HttpClientUtil.doget(uri,null,null); | ||
44 | + if(StringUtils.isNotBlank(qqResponseJsonStr)){ | ||
45 | + resultJson = JSONObject.parseObject(qqResponseJsonStr); | ||
46 | + } | ||
47 | + }catch (Exception e){ | ||
48 | + logger.error("describeClusterService error",e); | ||
49 | + } | ||
50 | + return resultJson; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * 用于查询单个服务详情 | ||
55 | + */ | ||
56 | + public JSONObject describeClusterServiceInfo(String clusterId, String namespace, String serviceName) { | ||
57 | + JSONObject resultJson=null; | ||
58 | + try{ | ||
59 | + Map<String, String> paraMap = Maps.newHashMap(); | ||
60 | + paraMap.put("clusterId", clusterId); | ||
61 | + paraMap.put("serviceName", serviceName); | ||
62 | + paraMap.put("Action", "DescribeClusterServiceInfo"); | ||
63 | + if (StringUtils.isNotEmpty(namespace)) { | ||
64 | + paraMap.put("namespace", namespace); | ||
65 | + } else { | ||
66 | + paraMap.put("namespace", "default"); | ||
67 | + } | ||
68 | + String backString = ccsApiQcloud.pushTest(paraMap); | ||
69 | + String uri=requestUrl+"?"+backString; | ||
70 | + String qqResponseJsonStr =HttpClientUtil.doget(uri,null,null); | ||
71 | + if(StringUtils.isNotBlank(qqResponseJsonStr)){ | ||
72 | + resultJson = JSONObject.parseObject(qqResponseJsonStr); | ||
73 | + } | ||
74 | + }catch (Exception e){ | ||
75 | + logger.error("describeClusterServiceInfo error",e); | ||
76 | + } | ||
77 | + return resultJson; | ||
78 | + } | ||
79 | + | ||
80 | + /** | ||
81 | + * 用于更新镜像文件 | ||
82 | + */ | ||
83 | + public JSONObject modifyClusterServiceImage (String clusterId, String namespace, String serviceName | ||
84 | + ,String containersIndexName,String containersIndexNameValue,String containersIndexImage,String containersIndexImageValue) { | ||
85 | + JSONObject resultJson=null; | ||
86 | + try{ | ||
87 | + Map<String, String> paraMap = Maps.newHashMap(); | ||
88 | + paraMap.put("clusterId", clusterId); | ||
89 | + paraMap.put("serviceName", serviceName); | ||
90 | + paraMap.put("Action", "ModifyClusterServiceImage"); | ||
91 | + paraMap.put(containersIndexName,containersIndexNameValue);// 容器name信息 | ||
92 | + paraMap.put(containersIndexImage,containersIndexImageValue);// 镜像值信息 | ||
93 | + if (StringUtils.isNotEmpty(namespace)) { | ||
94 | + paraMap.put("namespace", namespace); | ||
95 | + } else { | ||
96 | + paraMap.put("namespace", "default"); | ||
97 | + } | ||
98 | + logger.info("modifyClusterServiceImage paraMap is {}",paraMap); | ||
99 | + String backString = ccsApiQcloud.pushTest(paraMap); | ||
100 | + String uri=requestUrl+"?"+backString; | ||
101 | + String qqResponseJsonStr =HttpClientUtil.doget(uri,null,null); | ||
102 | + logger.info("modifyClusterServiceImage backResponse is {}",qqResponseJsonStr); | ||
103 | + if(StringUtils.isNotBlank(qqResponseJsonStr)){ | ||
104 | + resultJson = JSONObject.parseObject(qqResponseJsonStr); | ||
105 | + } | ||
106 | + }catch (Exception e){ | ||
107 | + logger.error("modifyClusterServiceImage error",e); | ||
108 | + } | ||
109 | + return resultJson; | ||
110 | + } | ||
111 | + | ||
112 | + /** | ||
113 | + * 用于将服务实例重新部署,常用场景为镜像仓库中镜像发生改变后, | ||
114 | + * 通过重部署触发服务重新拉取镜像 | ||
115 | + */ | ||
116 | + public JSONObject redeployClusterService(String clusterId, String namespace, String serviceName) { | ||
117 | + JSONObject resultJson=null; | ||
118 | + try{ | ||
119 | + Map<String, String> paraMap = Maps.newHashMap(); | ||
120 | + paraMap.put("clusterId", clusterId); | ||
121 | + paraMap.put("serviceName", serviceName); | ||
122 | + paraMap.put("Action", "RedeployClusterService"); | ||
123 | + if (StringUtils.isNotEmpty(namespace)) { | ||
124 | + paraMap.put("namespace", namespace); | ||
125 | + } else { | ||
126 | + paraMap.put("namespace", "default"); | ||
127 | + } | ||
128 | + String backString = ccsApiQcloud.pushTest(paraMap); | ||
129 | + String uri=requestUrl+"?"+backString; | ||
130 | + String qqResponseJsonStr =HttpClientUtil.doget(uri,null,null); | ||
131 | + if(StringUtils.isNotBlank(qqResponseJsonStr)){ | ||
132 | + resultJson = JSONObject.parseObject(qqResponseJsonStr); | ||
133 | + } | ||
134 | + }catch (Exception e){ | ||
135 | + logger.error("redeployClusterService error",e); | ||
136 | + } | ||
137 | + | ||
138 | + return resultJson; | ||
139 | + } | ||
140 | + | ||
141 | + /* public JSONObject createClusterService(Map<String, String> paraMap) { | ||
142 | + paraMap.put("Action", "CreateClusterService"); | ||
143 | + String backString = ccsApiQcloud.pushTest(paraMap); | ||
144 | + String resultjason = httpRestClientService.doPostStringJson(requestUrl, backString); | ||
145 | + JSONObject resultJson = JSONObject.parseObject(resultjason); | ||
146 | + return resultJson; | ||
147 | + }*/ | ||
148 | + | ||
149 | + | ||
150 | + | ||
151 | + /* public JSONObject deleteClusterService(String clusterId, String namespace, String serviceName) { | ||
152 | + Map<String, String> paraMap = Maps.newHashMap(); | ||
153 | + paraMap.put("clusterId", clusterId); | ||
154 | + paraMap.put("serviceName", serviceName); | ||
155 | + paraMap.put("Action", "DeleteClusterService"); | ||
156 | + if (StringUtils.isNotEmpty(namespace)) { | ||
157 | + paraMap.put("namespace", namespace); | ||
158 | + } else { | ||
159 | + paraMap.put("namespace", "default"); | ||
160 | + } | ||
161 | + String backString = ccsApiQcloud.pushTest(paraMap); | ||
162 | + String resultjason = httpRestClientService.doPostStringJson(requestUrl, backString); | ||
163 | + JSONObject resultJson = JSONObject.parseObject(resultjason); | ||
164 | + return resultJson; | ||
165 | + }*/ | ||
166 | + | ||
167 | + | ||
168 | + | ||
169 | + /* public JSONObject describeServiceEvent(String clusterId, String namespace, String serviceName) { | ||
170 | + Map<String, String> paraMap = Maps.newHashMap(); | ||
171 | + paraMap.put("clusterId", clusterId); | ||
172 | + paraMap.put("serviceName", serviceName); | ||
173 | + paraMap.put("Action", "DescribeServiceEvent"); | ||
174 | + if (StringUtils.isNotEmpty(namespace)) { | ||
175 | + paraMap.put("namespace", namespace); | ||
176 | + } else { | ||
177 | + paraMap.put("namespace", "default"); | ||
178 | + } | ||
179 | + String backString = ccsApiQcloud.pushTest(paraMap); | ||
180 | + String resultjason = httpRestClientService.doPostStringJson(requestUrl, backString); | ||
181 | + JSONObject resultJson = JSONObject.parseObject(resultjason); | ||
182 | + return resultJson; | ||
183 | + }*/ | ||
184 | +/* | ||
185 | + private static Map<String, String> portMap = Maps.newHashMap(); | ||
186 | + | ||
187 | + @PostConstruct | ||
188 | + private void getUser() { | ||
189 | + portMap.put("cobar", "8080"); | ||
190 | + portMap.put("es", "9300"); | ||
191 | + portMap.put("java", "8080"); | ||
192 | + portMap.put("mq", "5672"); | ||
193 | + portMap.put("mq-common", "5672"); | ||
194 | + portMap.put("mq-cluster", "5672"); | ||
195 | + portMap.put("mysql", "3306"); | ||
196 | + portMap.put("mysql-cms", "3306"); | ||
197 | + portMap.put("mysql-orders", "3306"); | ||
198 | + portMap.put("mysql-passport", "3306"); | ||
199 | + portMap.put("mysql-shops", "3306"); | ||
200 | + portMap.put("mysql-cobar-split1", "3306"); | ||
201 | + portMap.put("mysql-cobar-split2", "3306"); | ||
202 | + portMap.put("mysql-cobar-split3", "3306"); | ||
203 | + portMap.put("mysql-cobar-split4", "3306"); | ||
204 | + portMap.put("openresty-java", "80"); | ||
205 | + portMap.put("twemproxy", "63790"); | ||
206 | + portMap.put("twemproxy-nosync", "63790"); | ||
207 | + portMap.put("twemproxy-sync", "63790"); | ||
208 | + portMap.put("twemproxy-brower", "63790"); | ||
209 | + portMap.put("twemproxy-bigdata", "63790"); | ||
210 | + portMap.put("zk", "2181"); | ||
211 | + | ||
212 | + portMap.put("java-yoho-gateway", "8080,21212,21211"); | ||
213 | + portMap.put("java-yoho-users", "8081"); | ||
214 | + portMap.put("java-uic", "8096"); | ||
215 | + portMap.put("java-yoho-message", "8086"); | ||
216 | + portMap.put("java-yohobuy-union", "8088"); | ||
217 | + portMap.put("java-yohobuy-activity", "8090"); | ||
218 | + portMap.put("java-yohobuy-resources", "8087"); | ||
219 | + portMap.put("java-yohobuy-order", "8084"); | ||
220 | + portMap.put("java-yohobuy-wechat", "8094"); | ||
221 | + portMap.put("java-yohobuy-product", "8083"); | ||
222 | + portMap.put("java-yohobuy-platform", "8088"); | ||
223 | + portMap.put("java-yohobuy-bigdata", "8091"); | ||
224 | + portMap.put("java-yoho-social", "8095"); | ||
225 | + portMap.put("java-yohobuy-task", "8084"); | ||
226 | + portMap.put("java-yohobuy-promotion", "8085"); | ||
227 | + portMap.put("java-yoho-sns", "8082"); | ||
228 | + portMap.put("java-yohobuy-brower", "8092"); | ||
229 | + portMap.put("java-yohobuy-crm", "8093"); | ||
230 | + portMap.put("java-yoho-push", "8089"); | ||
231 | + portMap.put("java-cms-push", "8086"); | ||
232 | + portMap.put("java-yoho-search-producer", "8089"); | ||
233 | + portMap.put("java-yoho-search-consumer", "8088"); | ||
234 | + portMap.put("java-yoho-search-service", "8080"); | ||
235 | + portMap.put("java-yoho-search-adaptor", "8085"); | ||
236 | + | ||
237 | + | ||
238 | + } | ||
239 | + | ||
240 | + private String getPort(String key) { | ||
241 | + if (portMap.containsKey(key)) { | ||
242 | + return portMap.get(key); | ||
243 | + } else | ||
244 | + return portMap.get("java"); | ||
245 | + }*/ | ||
246 | + | ||
247 | +} |
-
Please register or login to post a comment