Authored by qinchao

docker发布

... ... @@ -454,14 +454,26 @@ public class DockerProjectCtrl {
return rtn;
}
Map<String,Object> statusMap=dockerServerDeployService.checkAppStatusIsNormal(clusterId,namespace,serviceName);
//Map<String,Object> statusMap=dockerServerDeployService.checkAppStatusIsNormal(clusterId,namespace,serviceName);
/*
boolean normalStatusFlag=(boolean)statusMap.get("result");
if(!normalStatusFlag){
rtn.setCode(201);
rtn.setMessage("Docker服务非Normal状态,发布中止!");
return rtn;
}
*/
Map<String,Object> statusMap=dockerServerDeployService.queryAppServiceInfo(clusterId,namespace,serviceName);
JSONArray containerJa=(JSONArray)statusMap.get("containerJa");
if(containerJa==null){
rtn.setCode(201);
rtn.setMessage("Docker服务修改镜像服务发生异常,获取容器描述为空");
return rtn;
}
boolean currentImageLatestFlag=dockerServerDeployService.checkImageLatestWithModifyFlag(clusterId, namespace, serviceName,imageStore, containerJa,false);
if(currentImageLatestFlag){
//开始重新发布
... ... @@ -540,7 +552,7 @@ public class DockerProjectCtrl {
rtn.setMessage("Docker服务不存在,请联系运维人员");
return rtn;
}
/*
Map<String,Object> statusMap=dockerServerDeployService.checkAppStatusIsNormal(clusterId,namespace,serviceName);
boolean normalStatusFlag=(boolean)statusMap.get("result");
if(!normalStatusFlag){
... ... @@ -548,8 +560,15 @@ public class DockerProjectCtrl {
rtn.setMessage("Docker服务非Normal状态,发布中止!");
return rtn;
}
JSONArray containerJa=(JSONArray)statusMap.get("containerJa");
*/
Map<String,Object> statusMap=dockerServerDeployService.queryAppServiceInfo(clusterId,namespace,serviceName);
JSONArray containerJa=(JSONArray)statusMap.get("containerJa");
if(containerJa==null){
rtn.setCode(201);
rtn.setMessage("Docker服务修改镜像服务发生异常,获取容器描述为空");
return rtn;
}
//更改路径,更改之后自动重新部署
boolean currentImageLatestFlag=dockerServerDeployService.rollbackImageStore(clusterId, namespace, serviceName, containerJa,rollbackImageStore);
if(!currentImageLatestFlag){
... ... @@ -577,8 +596,8 @@ public class DockerProjectCtrl {
if(StringUtils.isBlank(clusterId)){
continue;
}
List<String> statusAndCreateAt=dockerServerDeployService.queryAppStatus(clusterId,namespace,serviceName);
statusMap.put(clusterId,statusAndCreateAt.get(0));
Map<String,Object> appStatusMap=dockerServerDeployService.queryAppServiceInfo(clusterId,namespace,serviceName);
statusMap.put(clusterId,String.valueOf(appStatusMap.get("queryDesc")));
}
boolean allNormal=false;
... ...
... ... @@ -140,27 +140,6 @@ public class DockerServerDeployService {
return sb.toString();
}
/**
* 检测服务状态
*/
public List<String> queryAppStatus(String clusterId, String namespace, String serviceName) {
String status="";//状态
String createdAt="";//创建时间
JSONObject searchResult = txServer.describeClusterServiceInfo(clusterId, namespace,serviceName );
if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){
JSONObject jo=searchResult.getJSONObject("data").getJSONObject("service");
status=jo.getString("status");
createdAt=jo.getString("createdAt");
}else{
if(searchResult!=null){
status= JSON.toJSONString(searchResult);
}
}
List<String> ls=new ArrayList<>();
ls.add(status);
ls.add(createdAt);
return ls;
}
/**
* 检测服务实例状态
... ... @@ -191,12 +170,53 @@ public class DockerServerDeployService {
}
/**
* 检测服务状态
*/
public Map<String,Object> queryAppServiceInfo(String clusterId, String namespace, String serviceName) {
Map<String,Object> map=new HashMap<>();
//多次循环调用,防止网络异常
for(int i=0;i<3;i++){
boolean successQuery=false;
String queryDesc="";
JSONArray containerJa=null;
JSONObject searchResult = txServer.describeClusterServiceInfo(clusterId, namespace,serviceName );
if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){
successQuery=true;
JSONObject jo=searchResult.getJSONObject("data").getJSONObject("service");
queryDesc=" status is "+jo.getString("status");
containerJa=searchResult.getJSONObject("data").getJSONObject("service").getJSONArray("containers");
}else{
if(searchResult!=null){
queryDesc= JSON.toJSONString(searchResult);
}
}
map.put("successQuery",successQuery);
map.put("queryDesc",queryDesc);
map.put("containerJa",containerJa);
if(successQuery){
break;
}else{
//等待1s
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
return map;
}
/**
* 检测服务状态是否是Normal
* 返回标志信息和container信息
*
* serviceName.replace("_","-")
*/
public Map<String,Object> checkAppStatusIsNormal(String clusterId, String namespace, String serviceName) {
private Map<String,Object> checkAppStatusIsNormal(String clusterId, String namespace, String serviceName) {
int requestTime=3;
return checkAppStatusIsNormal(clusterId,namespace,serviceName,requestTime);
}
... ...