|
|
package com.monitor.other.worksystem.dock.qq;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.monitor.common.util.HttpClientUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by jimi on 2017/9/14.
|
|
|
*/
|
|
|
@Service
|
|
|
public class QqDockerServiceUtils {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(QqDockerServiceUtils.class);
|
|
|
|
|
|
private final String requestUrl = "https://ccs.api.qcloud.com/v2/index.php";
|
|
|
|
|
|
@Autowired
|
|
|
private CcsApiQcloud ccsApiQcloud;
|
|
|
|
|
|
/**
|
|
|
* 查询服务列表,该接口返回的列表只包含服务的扼要信息,
|
|
|
* 如果需要获取详细的服务信息,需要调用 DescribeClusterServiceInfo 接口
|
|
|
*/
|
|
|
public JSONObject describeClusterService(String clusterId, String namespace) {
|
|
|
JSONObject resultJson=null;
|
|
|
try{
|
|
|
Map<String, String> paraMap = Maps.newHashMap();
|
|
|
paraMap.put("Action", "DescribeClusterService");
|
|
|
paraMap.put("clusterId", clusterId);
|
|
|
if (StringUtils.isNotEmpty(namespace)) {
|
|
|
paraMap.put("namespace", namespace);
|
|
|
} else {
|
|
|
paraMap.put("namespace", "default");
|
|
|
}
|
|
|
String backString = ccsApiQcloud.pushTest(paraMap);
|
|
|
String uri=requestUrl+"?"+backString;
|
|
|
String qqResponseJsonStr =HttpClientUtil.doget(uri,null,null);
|
|
|
if(StringUtils.isNotBlank(qqResponseJsonStr)){
|
|
|
resultJson = JSONObject.parseObject(qqResponseJsonStr);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error("describeClusterService error",e);
|
|
|
}
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用于查询单个服务详情
|
|
|
*/
|
|
|
public JSONObject describeClusterServiceInfo(String clusterId, String namespace, String serviceName) {
|
|
|
JSONObject resultJson=null;
|
|
|
try{
|
|
|
Map<String, String> paraMap = Maps.newHashMap();
|
|
|
paraMap.put("clusterId", clusterId);
|
|
|
paraMap.put("serviceName", serviceName);
|
|
|
paraMap.put("Action", "DescribeClusterServiceInfo");
|
|
|
if (StringUtils.isNotEmpty(namespace)) {
|
|
|
paraMap.put("namespace", namespace);
|
|
|
} else {
|
|
|
paraMap.put("namespace", "default");
|
|
|
}
|
|
|
String backString = ccsApiQcloud.pushTest(paraMap);
|
|
|
String uri=requestUrl+"?"+backString;
|
|
|
String qqResponseJsonStr =HttpClientUtil.doget(uri,null,null);
|
|
|
if(StringUtils.isNotBlank(qqResponseJsonStr)){
|
|
|
resultJson = JSONObject.parseObject(qqResponseJsonStr);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error("describeClusterServiceInfo error",e);
|
|
|
}
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用于更新镜像文件
|
|
|
*/
|
|
|
public JSONObject modifyClusterServiceImage (String clusterId, String namespace, String serviceName
|
|
|
,String containersIndexName,String containersIndexNameValue,String containersIndexImage,String containersIndexImageValue) {
|
|
|
JSONObject resultJson=null;
|
|
|
try{
|
|
|
Map<String, String> paraMap = Maps.newHashMap();
|
|
|
paraMap.put("clusterId", clusterId);
|
|
|
paraMap.put("serviceName", serviceName);
|
|
|
paraMap.put("Action", "ModifyClusterServiceImage");
|
|
|
paraMap.put(containersIndexName,containersIndexNameValue);// 容器name信息
|
|
|
paraMap.put(containersIndexImage,containersIndexImageValue);// 镜像值信息
|
|
|
if (StringUtils.isNotEmpty(namespace)) {
|
|
|
paraMap.put("namespace", namespace);
|
|
|
} else {
|
|
|
paraMap.put("namespace", "default");
|
|
|
}
|
|
|
logger.info("modifyClusterServiceImage paraMap is {}",paraMap);
|
|
|
String backString = ccsApiQcloud.pushTest(paraMap);
|
|
|
String uri=requestUrl+"?"+backString;
|
|
|
String qqResponseJsonStr =HttpClientUtil.doget(uri,null,null);
|
|
|
logger.info("modifyClusterServiceImage backResponse is {}",qqResponseJsonStr);
|
|
|
if(StringUtils.isNotBlank(qqResponseJsonStr)){
|
|
|
resultJson = JSONObject.parseObject(qqResponseJsonStr);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error("modifyClusterServiceImage error",e);
|
|
|
}
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用于将服务实例重新部署,常用场景为镜像仓库中镜像发生改变后,
|
|
|
* 通过重部署触发服务重新拉取镜像
|
|
|
*/
|
|
|
public JSONObject redeployClusterService(String clusterId, String namespace, String serviceName) {
|
|
|
JSONObject resultJson=null;
|
|
|
try{
|
|
|
Map<String, String> paraMap = Maps.newHashMap();
|
|
|
paraMap.put("clusterId", clusterId);
|
|
|
paraMap.put("serviceName", serviceName);
|
|
|
paraMap.put("Action", "RedeployClusterService");
|
|
|
if (StringUtils.isNotEmpty(namespace)) {
|
|
|
paraMap.put("namespace", namespace);
|
|
|
} else {
|
|
|
paraMap.put("namespace", "default");
|
|
|
}
|
|
|
String backString = ccsApiQcloud.pushTest(paraMap);
|
|
|
String uri=requestUrl+"?"+backString;
|
|
|
String qqResponseJsonStr =HttpClientUtil.doget(uri,null,null);
|
|
|
if(StringUtils.isNotBlank(qqResponseJsonStr)){
|
|
|
resultJson = JSONObject.parseObject(qqResponseJsonStr);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
logger.error("redeployClusterService error",e);
|
|
|
}
|
|
|
|
|
|
return resultJson;
|
|
|
}
|
|
|
|
|
|
/* public JSONObject createClusterService(Map<String, String> paraMap) {
|
|
|
paraMap.put("Action", "CreateClusterService");
|
|
|
String backString = ccsApiQcloud.pushTest(paraMap);
|
|
|
String resultjason = httpRestClientService.doPostStringJson(requestUrl, backString);
|
|
|
JSONObject resultJson = JSONObject.parseObject(resultjason);
|
|
|
return resultJson;
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
/* public JSONObject deleteClusterService(String clusterId, String namespace, String serviceName) {
|
|
|
Map<String, String> paraMap = Maps.newHashMap();
|
|
|
paraMap.put("clusterId", clusterId);
|
|
|
paraMap.put("serviceName", serviceName);
|
|
|
paraMap.put("Action", "DeleteClusterService");
|
|
|
if (StringUtils.isNotEmpty(namespace)) {
|
|
|
paraMap.put("namespace", namespace);
|
|
|
} else {
|
|
|
paraMap.put("namespace", "default");
|
|
|
}
|
|
|
String backString = ccsApiQcloud.pushTest(paraMap);
|
|
|
String resultjason = httpRestClientService.doPostStringJson(requestUrl, backString);
|
|
|
JSONObject resultJson = JSONObject.parseObject(resultjason);
|
|
|
return resultJson;
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
/* public JSONObject describeServiceEvent(String clusterId, String namespace, String serviceName) {
|
|
|
Map<String, String> paraMap = Maps.newHashMap();
|
|
|
paraMap.put("clusterId", clusterId);
|
|
|
paraMap.put("serviceName", serviceName);
|
|
|
paraMap.put("Action", "DescribeServiceEvent");
|
|
|
if (StringUtils.isNotEmpty(namespace)) {
|
|
|
paraMap.put("namespace", namespace);
|
|
|
} else {
|
|
|
paraMap.put("namespace", "default");
|
|
|
}
|
|
|
String backString = ccsApiQcloud.pushTest(paraMap);
|
|
|
String resultjason = httpRestClientService.doPostStringJson(requestUrl, backString);
|
|
|
JSONObject resultJson = JSONObject.parseObject(resultjason);
|
|
|
return resultJson;
|
|
|
}*/
|
|
|
/*
|
|
|
private static Map<String, String> portMap = Maps.newHashMap();
|
|
|
|
|
|
@PostConstruct
|
|
|
private void getUser() {
|
|
|
portMap.put("cobar", "8080");
|
|
|
portMap.put("es", "9300");
|
|
|
portMap.put("java", "8080");
|
|
|
portMap.put("mq", "5672");
|
|
|
portMap.put("mq-common", "5672");
|
|
|
portMap.put("mq-cluster", "5672");
|
|
|
portMap.put("mysql", "3306");
|
|
|
portMap.put("mysql-cms", "3306");
|
|
|
portMap.put("mysql-orders", "3306");
|
|
|
portMap.put("mysql-passport", "3306");
|
|
|
portMap.put("mysql-shops", "3306");
|
|
|
portMap.put("mysql-cobar-split1", "3306");
|
|
|
portMap.put("mysql-cobar-split2", "3306");
|
|
|
portMap.put("mysql-cobar-split3", "3306");
|
|
|
portMap.put("mysql-cobar-split4", "3306");
|
|
|
portMap.put("openresty-java", "80");
|
|
|
portMap.put("twemproxy", "63790");
|
|
|
portMap.put("twemproxy-nosync", "63790");
|
|
|
portMap.put("twemproxy-sync", "63790");
|
|
|
portMap.put("twemproxy-brower", "63790");
|
|
|
portMap.put("twemproxy-bigdata", "63790");
|
|
|
portMap.put("zk", "2181");
|
|
|
|
|
|
portMap.put("java-yoho-gateway", "8080,21212,21211");
|
|
|
portMap.put("java-yoho-users", "8081");
|
|
|
portMap.put("java-uic", "8096");
|
|
|
portMap.put("java-yoho-message", "8086");
|
|
|
portMap.put("java-yohobuy-union", "8088");
|
|
|
portMap.put("java-yohobuy-activity", "8090");
|
|
|
portMap.put("java-yohobuy-resources", "8087");
|
|
|
portMap.put("java-yohobuy-order", "8084");
|
|
|
portMap.put("java-yohobuy-wechat", "8094");
|
|
|
portMap.put("java-yohobuy-product", "8083");
|
|
|
portMap.put("java-yohobuy-platform", "8088");
|
|
|
portMap.put("java-yohobuy-bigdata", "8091");
|
|
|
portMap.put("java-yoho-social", "8095");
|
|
|
portMap.put("java-yohobuy-task", "8084");
|
|
|
portMap.put("java-yohobuy-promotion", "8085");
|
|
|
portMap.put("java-yoho-sns", "8082");
|
|
|
portMap.put("java-yohobuy-brower", "8092");
|
|
|
portMap.put("java-yohobuy-crm", "8093");
|
|
|
portMap.put("java-yoho-push", "8089");
|
|
|
portMap.put("java-cms-push", "8086");
|
|
|
portMap.put("java-yoho-search-producer", "8089");
|
|
|
portMap.put("java-yoho-search-consumer", "8088");
|
|
|
portMap.put("java-yoho-search-service", "8080");
|
|
|
portMap.put("java-yoho-search-adaptor", "8085");
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private String getPort(String key) {
|
|
|
if (portMap.containsKey(key)) {
|
|
|
return portMap.get(key);
|
|
|
} else
|
|
|
return portMap.get("java");
|
|
|
}*/
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|