Authored by qinchao

docker发布

@@ -454,14 +454,26 @@ public class DockerProjectCtrl { @@ -454,14 +454,26 @@ public class DockerProjectCtrl {
454 return rtn; 454 return rtn;
455 } 455 }
456 456
457 - Map<String,Object> statusMap=dockerServerDeployService.checkAppStatusIsNormal(clusterId,namespace,serviceName); 457 + //Map<String,Object> statusMap=dockerServerDeployService.checkAppStatusIsNormal(clusterId,namespace,serviceName);
  458 +
  459 + /*
458 boolean normalStatusFlag=(boolean)statusMap.get("result"); 460 boolean normalStatusFlag=(boolean)statusMap.get("result");
459 if(!normalStatusFlag){ 461 if(!normalStatusFlag){
460 rtn.setCode(201); 462 rtn.setCode(201);
461 rtn.setMessage("Docker服务非Normal状态,发布中止!"); 463 rtn.setMessage("Docker服务非Normal状态,发布中止!");
462 return rtn; 464 return rtn;
463 } 465 }
  466 + */
  467 +
  468 + Map<String,Object> statusMap=dockerServerDeployService.queryAppServiceInfo(clusterId,namespace,serviceName);
  469 +
464 JSONArray containerJa=(JSONArray)statusMap.get("containerJa"); 470 JSONArray containerJa=(JSONArray)statusMap.get("containerJa");
  471 + if(containerJa==null){
  472 + rtn.setCode(201);
  473 + rtn.setMessage("Docker服务修改镜像服务发生异常,获取容器描述为空");
  474 + return rtn;
  475 + }
  476 +
465 boolean currentImageLatestFlag=dockerServerDeployService.checkImageLatestWithModifyFlag(clusterId, namespace, serviceName,imageStore, containerJa,false); 477 boolean currentImageLatestFlag=dockerServerDeployService.checkImageLatestWithModifyFlag(clusterId, namespace, serviceName,imageStore, containerJa,false);
466 if(currentImageLatestFlag){ 478 if(currentImageLatestFlag){
467 //开始重新发布 479 //开始重新发布
@@ -540,7 +552,7 @@ public class DockerProjectCtrl { @@ -540,7 +552,7 @@ public class DockerProjectCtrl {
540 rtn.setMessage("Docker服务不存在,请联系运维人员"); 552 rtn.setMessage("Docker服务不存在,请联系运维人员");
541 return rtn; 553 return rtn;
542 } 554 }
543 - 555 + /*
544 Map<String,Object> statusMap=dockerServerDeployService.checkAppStatusIsNormal(clusterId,namespace,serviceName); 556 Map<String,Object> statusMap=dockerServerDeployService.checkAppStatusIsNormal(clusterId,namespace,serviceName);
545 boolean normalStatusFlag=(boolean)statusMap.get("result"); 557 boolean normalStatusFlag=(boolean)statusMap.get("result");
546 if(!normalStatusFlag){ 558 if(!normalStatusFlag){
@@ -548,8 +560,15 @@ public class DockerProjectCtrl { @@ -548,8 +560,15 @@ public class DockerProjectCtrl {
548 rtn.setMessage("Docker服务非Normal状态,发布中止!"); 560 rtn.setMessage("Docker服务非Normal状态,发布中止!");
549 return rtn; 561 return rtn;
550 } 562 }
551 - JSONArray containerJa=(JSONArray)statusMap.get("containerJa"); 563 + */
  564 + Map<String,Object> statusMap=dockerServerDeployService.queryAppServiceInfo(clusterId,namespace,serviceName);
552 565
  566 + JSONArray containerJa=(JSONArray)statusMap.get("containerJa");
  567 + if(containerJa==null){
  568 + rtn.setCode(201);
  569 + rtn.setMessage("Docker服务修改镜像服务发生异常,获取容器描述为空");
  570 + return rtn;
  571 + }
553 //更改路径,更改之后自动重新部署 572 //更改路径,更改之后自动重新部署
554 boolean currentImageLatestFlag=dockerServerDeployService.rollbackImageStore(clusterId, namespace, serviceName, containerJa,rollbackImageStore); 573 boolean currentImageLatestFlag=dockerServerDeployService.rollbackImageStore(clusterId, namespace, serviceName, containerJa,rollbackImageStore);
555 if(!currentImageLatestFlag){ 574 if(!currentImageLatestFlag){
@@ -577,8 +596,8 @@ public class DockerProjectCtrl { @@ -577,8 +596,8 @@ public class DockerProjectCtrl {
577 if(StringUtils.isBlank(clusterId)){ 596 if(StringUtils.isBlank(clusterId)){
578 continue; 597 continue;
579 } 598 }
580 - List<String> statusAndCreateAt=dockerServerDeployService.queryAppStatus(clusterId,namespace,serviceName);  
581 - statusMap.put(clusterId,statusAndCreateAt.get(0)); 599 + Map<String,Object> appStatusMap=dockerServerDeployService.queryAppServiceInfo(clusterId,namespace,serviceName);
  600 + statusMap.put(clusterId,String.valueOf(appStatusMap.get("queryDesc")));
582 } 601 }
583 602
584 boolean allNormal=false; 603 boolean allNormal=false;
@@ -140,27 +140,6 @@ public class DockerServerDeployService { @@ -140,27 +140,6 @@ public class DockerServerDeployService {
140 return sb.toString(); 140 return sb.toString();
141 } 141 }
142 142
143 - /**  
144 - * 检测服务状态  
145 - */  
146 - public List<String> queryAppStatus(String clusterId, String namespace, String serviceName) {  
147 - String status="";//状态  
148 - String createdAt="";//创建时间  
149 - JSONObject searchResult = txServer.describeClusterServiceInfo(clusterId, namespace,serviceName );  
150 - if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){  
151 - JSONObject jo=searchResult.getJSONObject("data").getJSONObject("service");  
152 - status=jo.getString("status");  
153 - createdAt=jo.getString("createdAt");  
154 - }else{  
155 - if(searchResult!=null){  
156 - status= JSON.toJSONString(searchResult);  
157 - }  
158 - }  
159 - List<String> ls=new ArrayList<>();  
160 - ls.add(status);  
161 - ls.add(createdAt);  
162 - return ls;  
163 - }  
164 143
165 /** 144 /**
166 * 检测服务实例状态 145 * 检测服务实例状态
@@ -191,12 +170,53 @@ public class DockerServerDeployService { @@ -191,12 +170,53 @@ public class DockerServerDeployService {
191 } 170 }
192 171
193 /** 172 /**
  173 + * 检测服务状态
  174 + */
  175 + public Map<String,Object> queryAppServiceInfo(String clusterId, String namespace, String serviceName) {
  176 + Map<String,Object> map=new HashMap<>();
  177 + //多次循环调用,防止网络异常
  178 + for(int i=0;i<3;i++){
  179 + boolean successQuery=false;
  180 + String queryDesc="";
  181 + JSONArray containerJa=null;
  182 + JSONObject searchResult = txServer.describeClusterServiceInfo(clusterId, namespace,serviceName );
  183 + if(searchResult!=null&&searchResult.getInteger("code")!=null&& searchResult.getInteger("code").equals(NumberUtils.INTEGER_ZERO)){
  184 + successQuery=true;
  185 + JSONObject jo=searchResult.getJSONObject("data").getJSONObject("service");
  186 + queryDesc=" status is "+jo.getString("status");
  187 + containerJa=searchResult.getJSONObject("data").getJSONObject("service").getJSONArray("containers");
  188 +
  189 + }else{
  190 + if(searchResult!=null){
  191 + queryDesc= JSON.toJSONString(searchResult);
  192 + }
  193 + }
  194 + map.put("successQuery",successQuery);
  195 + map.put("queryDesc",queryDesc);
  196 + map.put("containerJa",containerJa);
  197 +
  198 + if(successQuery){
  199 + break;
  200 + }else{
  201 + //等待1s
  202 + try {
  203 + Thread.sleep(1000);
  204 + } catch (InterruptedException e) {
  205 + e.printStackTrace();
  206 + }
  207 + }
  208 + }
  209 +
  210 + return map;
  211 + }
  212 +
  213 + /**
194 * 检测服务状态是否是Normal 214 * 检测服务状态是否是Normal
195 * 返回标志信息和container信息 215 * 返回标志信息和container信息
196 * 216 *
197 * serviceName.replace("_","-") 217 * serviceName.replace("_","-")
198 */ 218 */
199 - public Map<String,Object> checkAppStatusIsNormal(String clusterId, String namespace, String serviceName) { 219 + private Map<String,Object> checkAppStatusIsNormal(String clusterId, String namespace, String serviceName) {
200 int requestTime=3; 220 int requestTime=3;
201 return checkAppStatusIsNormal(clusterId,namespace,serviceName,requestTime); 221 return checkAppStatusIsNormal(clusterId,namespace,serviceName,requestTime);
202 } 222 }