Authored by qinchao

Merge branch 'dev_deploy_uic_ui'

@@ -33,7 +33,11 @@ import java.util.*; @@ -33,7 +33,11 @@ import java.util.*;
33 public class ProjectBuildCtrl { 33 public class ProjectBuildCtrl {
34 Logger log = LoggerFactory.getLogger(ProjectBuildCtrl.class); 34 Logger log = LoggerFactory.getLogger(ProjectBuildCtrl.class);
35 //需要特殊处理的项目 35 //需要特殊处理的项目
36 - private final String PROJECT_NAME_YOHO_SEARCH_SERVICE="yoho-search-service"; 36 + //private final String PROJECT_NAME_YOHO_SEARCH_SERVICE="yoho-search-service";
  37 + private final List<String> lb_proejct_list=new ArrayList<String>() {{
  38 + add("yoho-search-service");
  39 + add("uic");
  40 + }};
37 @Autowired 41 @Autowired
38 private HttpRestClient httpRestClient; 42 private HttpRestClient httpRestClient;
39 43
@@ -196,146 +200,65 @@ public class ProjectBuildCtrl { @@ -196,146 +200,65 @@ public class ProjectBuildCtrl {
196 } 200 }
197 } 201 }
198 202
199 - List<BuildMessage> list = new ArrayList<>();  
200 - BuildRequest buildRequest = new BuildRequest();  
201 - //分支名称  
202 - buildRequest.setBranch(branch_name);  
203 - //登陆用户  
204 - buildRequest.setUser(user.getName());  
205 - //发布环境  
206 - buildRequest.setEnvironment(environment_name);  
207 - //回滚文件名称  
208 - buildRequest.setRollbackfile(rollbackfile_name);  
209 - //操作类型  
210 - buildRequest.setOperate(operate_name);  
211 - //关联工单  
212 - buildRequest.setWorkid(workid_name);  
213 - String messageids = "";  
214 - boolean containsSpecialProject=false;  
215 List<String> projectList=Arrays.asList(project_name.split(",")); 203 List<String> projectList=Arrays.asList(project_name.split(","));
216 - if(projectList.contains(PROJECT_NAME_YOHO_SEARCH_SERVICE)  
217 - &&("aws".equals(environment_name)||"qcloud".equals(environment_name))){  
218 - containsSpecialProject=true; 204 + //把要发布的项目重新组合,其中特殊情况的项目,先拿出来传递到前台,其余的普通项目直接发布
  205 + List<String> specialProjectLb=new ArrayList<>();
  206 + if(("aws".equals(environment_name)||"qcloud".equals(environment_name))){
219 project_name=""; 207 project_name="";
220 for(String str:projectList){ 208 for(String str:projectList){
221 - if(str.equals(PROJECT_NAME_YOHO_SEARCH_SERVICE)){  
222 - continue;  
223 - }  
224 - if(project_name.length()>0){  
225 - project_name += ","; 209 + if(StringUtils.isNotBlank(str)){
  210 + if(lb_proejct_list.contains(str)){
  211 + specialProjectLb.add(str);
  212 + continue;
  213 + }
  214 + if(project_name.length()>0){
  215 + project_name += ",";
  216 + }
  217 + project_name += str ;
226 } 218 }
227 - project_name += str ;  
228 } 219 }
229 } 220 }
230 - if ("Deploy".equals(operate_name)) {  
231 - if(containsSpecialProject){  
232 - //包含特殊的项目,再检查是否含其他类型的项目  
233 - //特殊项目的操作  
234 - LbResult lbResult=buildYohoSearchService(environment_name);  
235 - lbResult.setEnvironmentName(environment_name);  
236 - lbResult.setBranch(branch_name);  
237 - lbResult.setWorkIdName(workid_name);  
238 - lbResult.setOperateName(operate_name);  
239 - lbResult.setRollbackfileName(rollbackfile_name);  
240 -  
241 - if(lbResult.errorFlag){  
242 - model.addAttribute("existSpecialYohoSearchService","error");  
243 - }else{  
244 - if(lbResult.getDeployOrDeregister().equals("1")){  
245 - model.addAttribute("existSpecialYohoSearchService","old");  
246 -  
247 - //负载均衡只有一台机器,则走原来的发布  
248 - if(project_name.length()>0){  
249 - project_name += (","+PROJECT_NAME_YOHO_SEARCH_SERVICE);  
250 - }else{  
251 - project_name = PROJECT_NAME_YOHO_SEARCH_SERVICE;  
252 - }  
253 - messageids=deploy(project_name,environment_name,buildRequest,list,messageids);  
254 - }else{  
255 -  
256 - //从负载均衡卸载  
257 - BaseResponse deregisterResponse=deregisterHostYohoSearchService(environment_name,lbResult.getChangeIds());  
258 - if(deregisterResponse==null||deregisterResponse.getCode()!=200){  
259 - model.addAttribute("existSpecialYohoSearchService","error");  
260 - lbResult.setMsg("负载均衡卸载机器出现错误!本项目发布终止");  
261 - }else{  
262 - //负载均衡有多个机器,保留一台,卸载其余的,然后发布其余的,然后挂载其余的,然后卸载第一台,发布第一台,挂载第一台。  
263 - model.addAttribute("existSpecialYohoSearchService","deregister");  
264 - }  
265 - //其他项目的操作  
266 - if(project_name.length()>0){  
267 - messageids=deploy(project_name,environment_name,buildRequest,list,messageids);  
268 - }  
269 - }  
270 - }  
271 - model.addAttribute("specialYohoSearchServiceResult", JSON.toJSONString(lbResult));  
272 - }else{ 221 + model.addAttribute("specialProjectLbList", JSONArray.parseArray(JSON.toJSONString(specialProjectLb)));
  222 +
  223 + String messageids = "";
  224 + List<BuildMessage> list = new ArrayList<>();
  225 + if(StringUtils.isNotBlank(project_name)){
  226 + BuildRequest buildRequest = new BuildRequest();
  227 + //分支名称
  228 + buildRequest.setBranch(branch_name);
  229 + //登陆用户
  230 + buildRequest.setUser(user.getName());
  231 + //发布环境
  232 + buildRequest.setEnvironment(environment_name);
  233 + //回滚文件名称
  234 + buildRequest.setRollbackfile(rollbackfile_name);
  235 + //操作类型
  236 + buildRequest.setOperate(operate_name);
  237 + //关联工单
  238 + buildRequest.setWorkid(workid_name);
  239 +
  240 + if ("Deploy".equals(operate_name)) {
273 //不包含特殊项目,直接走原来的发布 241 //不包含特殊项目,直接走原来的发布
274 messageids=deploy(project_name,environment_name,buildRequest,list,messageids); 242 messageids=deploy(project_name,environment_name,buildRequest,list,messageids);
275 - }  
276 - } else {  
277 - if(containsSpecialProject){  
278 - //包含特殊的项目,再检查是否含其他类型的项目  
279 - //特殊项目的操作  
280 - LbResult lbResult=buildYohoSearchService(environment_name);  
281 - lbResult.setEnvironmentName(environment_name);  
282 - lbResult.setBranch(branch_name);  
283 - lbResult.setWorkIdName(workid_name);  
284 - lbResult.setOperateName(operate_name);  
285 - lbResult.setRollbackfileName(rollbackfile_name);  
286 -  
287 - if(lbResult.errorFlag){  
288 - model.addAttribute("existSpecialYohoSearchService","error");  
289 - }else{  
290 - if(lbResult.getDeployOrDeregister().equals("1")){  
291 - model.addAttribute("existSpecialYohoSearchService","old");  
292 -  
293 - //负载均衡只有一台机器,则走原来的发布  
294 - if(project_name.length()>0){  
295 - project_name += (","+PROJECT_NAME_YOHO_SEARCH_SERVICE);  
296 - }else{  
297 - project_name = PROJECT_NAME_YOHO_SEARCH_SERVICE;  
298 - }  
299 - buildRequest.setProject(project_name);  
300 - messageids=rollback(environment_name,buildRequest,list,messageids);  
301 - }else{  
302 - //从负载均衡卸载  
303 - BaseResponse deregisterResponse=deregisterHostYohoSearchService(environment_name,lbResult.getChangeIds());  
304 - if(deregisterResponse==null||deregisterResponse.getCode()!=200){  
305 - model.addAttribute("existSpecialYohoSearchService","error");  
306 - lbResult.setMsg("负载均衡卸载机器出现错误!本项目发布终止");  
307 - }else{  
308 - //负载均衡有多个机器,保留一台,卸载其余的,然后发布其余的,然后挂载其余的,然后卸载第一台,发布第一台,挂载第一台。  
309 - model.addAttribute("existSpecialYohoSearchService","deregister");  
310 - }  
311 - //其他项目的操作  
312 - if(project_name.length()>0){  
313 - buildRequest.setProject(project_name);  
314 - messageids=rollback(environment_name,buildRequest,list,messageids);  
315 - }  
316 - }  
317 - }  
318 - model.addAttribute("specialYohoSearchServiceResult", JSON.toJSONString(lbResult));  
319 - }else{ 243 + } else {
320 buildRequest.setProject(project_name); 244 buildRequest.setProject(project_name);
321 messageids=rollback(environment_name, buildRequest, list, messageids); 245 messageids=rollback(environment_name, buildRequest, list, messageids);
322 } 246 }
323 -  
324 -  
325 } 247 }
  248 +
326 model.addAttribute("environment_name", environment_name); 249 model.addAttribute("environment_name", environment_name);
327 model.addAttribute("operate_name", operate_name); 250 model.addAttribute("operate_name", operate_name);
328 model.addAttribute("branch_name", branch_name); 251 model.addAttribute("branch_name", branch_name);
329 model.addAttribute("rollbackfile_name", rollbackfile_name); 252 model.addAttribute("rollbackfile_name", rollbackfile_name);
330 model.addAttribute("messageids", messageids); 253 model.addAttribute("messageids", messageids);
331 model.addAttribute("messageList", list); 254 model.addAttribute("messageList", list);
  255 + model.addAttribute("workid_name",workid_name);
332 } catch (Exception ex) { 256 } catch (Exception ex) {
333 } 257 }
334 return new ModelAndView("project/project_build"); 258 return new ModelAndView("project/project_build");
335 } 259 }
336 260
337 -  
338 - @RequestMapping("/buildProjectWithIPs") 261 + @RequestMapping(value ="/buildProjectWithIPs", method = RequestMethod.POST)
339 @ResponseBody 262 @ResponseBody
340 public BaseResponse<?> buildProjectWithIPs(HttpSession session, String project_name,String ips, String environment_name, String operate_name, String branch_name, String rollbackfile_name,String workid_name){ 263 public BaseResponse<?> buildProjectWithIPs(HttpSession session, String project_name,String ips, String environment_name, String operate_name, String branch_name, String rollbackfile_name,String workid_name){
341 BaseResponse response = new BaseResponse(); 264 BaseResponse response = new BaseResponse();
@@ -390,44 +313,59 @@ public class ProjectBuildCtrl { @@ -390,44 +313,59 @@ public class ProjectBuildCtrl {
390 313
391 @RequestMapping(value = "/deregisterHostYohoSearchService") 314 @RequestMapping(value = "/deregisterHostYohoSearchService")
392 @ResponseBody 315 @ResponseBody
393 - public BaseResponse deregisterHostYohoSearchService(String environment_name,String instIds){ 316 + public BaseResponse deregisterHostYohoSearchService(String project,String environment_name,String instIds){
394 Map<String, String> map=new HashMap<>(); 317 Map<String, String> map=new HashMap<>();
395 map.put("cloudType",environment_name); 318 map.put("cloudType",environment_name);
396 map.put("instIds",instIds); 319 map.put("instIds",instIds);
  320 + map.put("project",project);
397 return httpRestClient.defaultGet("/lb/deregisterHostFromLb/yohoSearchService",BaseResponse.class,map); 321 return httpRestClient.defaultGet("/lb/deregisterHostFromLb/yohoSearchService",BaseResponse.class,map);
398 } 322 }
399 323
400 @RequestMapping(value = "/registerHostYohoSearchService") 324 @RequestMapping(value = "/registerHostYohoSearchService")
401 @ResponseBody 325 @ResponseBody
402 - public BaseResponse registerHostYohoSearchService(String environment_name,String instIds){ 326 + public BaseResponse registerHostYohoSearchService(String project,String environment_name,String instIds){
403 Map<String, String> map=new HashMap<>(); 327 Map<String, String> map=new HashMap<>();
404 map.put("cloudType",environment_name); 328 map.put("cloudType",environment_name);
405 map.put("instIds",instIds); 329 map.put("instIds",instIds);
  330 + map.put("project",project);
406 return httpRestClient.defaultGet("/lb/registerHostFromLb/yohoSearchService",BaseResponse.class,map); 331 return httpRestClient.defaultGet("/lb/registerHostFromLb/yohoSearchService",BaseResponse.class,map);
407 } 332 }
408 333
409 @RequestMapping(value = "/getLbInfoYohoSearchService") 334 @RequestMapping(value = "/getLbInfoYohoSearchService")
410 @ResponseBody 335 @ResponseBody
411 - public BaseResponse getLbInfoYohoSearchService(String environment_name){ 336 + public BaseResponse getLbInfoYohoSearchService(String project,String environment_name){
412 Map<String, String> map=new HashMap<>(); 337 Map<String, String> map=new HashMap<>();
413 map.put("cloudType",environment_name); 338 map.put("cloudType",environment_name);
  339 + map.put("project",project);
414 return httpRestClient.defaultGet("/lb/getLb/yohoSearchService",BaseResponse.class,map); 340 return httpRestClient.defaultGet("/lb/getLb/yohoSearchService",BaseResponse.class,map);
415 } 341 }
416 342
417 - //特殊项目的处理yoho-search-service  
418 - //1.卸载 挂载  
419 - private LbResult buildYohoSearchService(String environment_name){ 343 + /**
  344 + * 特殊项目发布之前检查lb的情况
  345 + * @param project
  346 + * @param environment_name
  347 + * @return
  348 + */
  349 + @RequestMapping(value = "/checkSpecialProjectLbInfoBeforeBuild")
  350 + @ResponseBody
  351 + public BaseResponse checkSpecialProjectLbInfoBeforeBuild(String project,String environment_name,String branch_name,String workid_name,String operate_name,String rollbackfile_name){
420 LbResult lbResult=new LbResult(); 352 LbResult lbResult=new LbResult();
421 - lbResult.setCurrentProject(PROJECT_NAME_YOHO_SEARCH_SERVICE);  
422 - BaseResponse response = httpRestClient.defaultGet("/lb/getLb/yohoSearchService?cloudType="+environment_name, BaseResponse.class); 353 + lbResult.setCurrentProject(project);
  354 + lbResult.setEnvironmentName(environment_name);
  355 + lbResult.setBranch(branch_name);
  356 + lbResult.setWorkIdName(workid_name);
  357 + lbResult.setOperateName(operate_name);
  358 + lbResult.setRollbackfileName(rollbackfile_name);
  359 +
  360 + BaseResponse response = this.getLbInfoYohoSearchService(project,environment_name);
423 if(response!=null&&response.getCode()==200){ 361 if(response!=null&&response.getCode()==200){
424 Map<String,String> hostIdAndIpMap=(Map<String,String>)response.getData(); 362 Map<String,String> hostIdAndIpMap=(Map<String,String>)response.getData();
425 //负载均衡只有一台机器的情况,就不拿掉了 ,直接发布吧 363 //负载均衡只有一台机器的情况,就不拿掉了 ,直接发布吧
426 if(hostIdAndIpMap.size()<=1){ 364 if(hostIdAndIpMap.size()<=1){
427 - lbResult.setDeployOrDeregister("1");  
428 - lbResult.setMsg("负载均衡只有一台机器,直接发布!"); 365 + lbResult.setOnlyOneHost("1");
  366 + lbResult.setMsg("负载均衡最多只有一台机器,直接发布!");
429 }else{ 367 }else{
430 - lbResult.setDeployOrDeregister("2"); 368 + lbResult.setOnlyOneHost("2");
431 //保留的机器和需要卸载(挂载)的机器 369 //保留的机器和需要卸载(挂载)的机器
432 lbResult.setMsg("负载均衡有多个机器,走特殊发布流程!"); 370 lbResult.setMsg("负载均衡有多个机器,走特殊发布流程!");
433 int index=0; 371 int index=0;
@@ -452,11 +390,10 @@ public class ProjectBuildCtrl { @@ -452,11 +390,10 @@ public class ProjectBuildCtrl {
452 lbResult.setHostNum(index); 390 lbResult.setHostNum(index);
453 lbResult.setChangeNum(index-1); 391 lbResult.setChangeNum(index-1);
454 } 392 }
455 - }else{  
456 - lbResult.setErrorFlag(true);  
457 - lbResult.setMsg("查询负载均衡信息出错,该项目的发布终止,请检查再重新发布!"); 393 +
  394 + response.setData(lbResult);
458 } 395 }
459 - return lbResult; 396 + return response;
460 } 397 }
461 398
462 399
@@ -471,7 +408,7 @@ public class ProjectBuildCtrl { @@ -471,7 +408,7 @@ public class ProjectBuildCtrl {
471 String rollbackfileName=""; 408 String rollbackfileName="";
472 409
473 boolean errorFlag=false; 410 boolean errorFlag=false;
474 - String deployOrDeregister=""; 411 + String onlyOneHost="";
475 String msg=""; 412 String msg="";
476 413
477 //保留的机器和需要卸载(挂载)的机器 414 //保留的机器和需要卸载(挂载)的机器
@@ -102,6 +102,7 @@ @@ -102,6 +102,7 @@
102 <span class="input-group-addon">回滚:</span> 102 <span class="input-group-addon">回滚:</span>
103 <input type="text" id="rollbackfile_name" name="rollbackfile_name" class="form-control" 103 <input type="text" id="rollbackfile_name" name="rollbackfile_name" class="form-control"
104 readonly="readonly" value="${rollbackfile_name}"/> 104 readonly="readonly" value="${rollbackfile_name}"/>
  105 + <input type="hidden" id="workid_name" name="workid_name" readonly="readonly" value="${workid_name}"/>
105 </div> 106 </div>
106 </div> 107 </div>
107 </div> 108 </div>
@@ -136,19 +137,19 @@ @@ -136,19 +137,19 @@
136 </div> 137 </div>
137 </c:forEach> 138 </c:forEach>
138 139
139 - <c:if test="${existSpecialYohoSearchService=='error' or existSpecialYohoSearchService=='deregister'}"> 140 + <c:forEach items="${specialProjectLbList }" var="specialProject">
140 <div style="float: left;height: 600px;"> 141 <div style="float: left;height: 600px;">
141 <hr> 142 <hr>
142 143
143 - <div>当前项目:<input type="text" value="yoho-search-service" readonly="readonly"> 144 + <div>当前项目:<input type="text" value="${specialProject}" readonly="readonly">
144 145
145 </div> 146 </div>
146 - <div style="height: 50px" class="alert alert-warning" id="task-info-div_yoho-search-service"> 147 + <div style="height: 50px" class="alert alert-warning" id="task-info-div_${specialProject}">
147 </div> 148 </div>
148 - <textarea id="resultArea_yoho-search-service" rows="25" cols="100" 149 + <textarea id="resultArea_${specialProject}" rows="25" cols="100"
149 style="background-color: black; color: white" readonly="readonly"></textarea> 150 style="background-color: black; color: white" readonly="readonly"></textarea>
150 </div> 151 </div>
151 - </c:if> 152 + </c:forEach>
152 153
153 </div> 154 </div>
154 </div> 155 </div>
@@ -166,6 +167,8 @@ @@ -166,6 +167,8 @@
166 167
167 var myArray; 168 var myArray;
168 var removeArray = new Array(); 169 var removeArray = new Array();
  170 + var specialProjectLbList=${specialProjectLbList};
  171 +
169 $(function () { 172 $(function () {
170 var messageListHidden = $("#messageListHidden").val(); 173 var messageListHidden = $("#messageListHidden").val();
171 myArray = messageListHidden.split(","); 174 myArray = messageListHidden.split(",");
@@ -217,32 +220,92 @@ @@ -217,32 +220,92 @@
217 }); 220 });
218 }, 3000); 221 }, 3000);
219 222
220 - specialBuildYohoSearchService(); 223 + //特殊项目的发布
  224 + specialLbProject();
221 }); 225 });
222 226
223 - //特殊项目的发布  
224 - var yoho_search_service_resultAreaId="resultArea_yoho-search-service";  
225 - function specialBuildYohoSearchService(){  
226 - var existSpecialYohoSearchService="${existSpecialYohoSearchService}";  
227 - if("error"!=existSpecialYohoSearchService  
228 - &&"deregister"!=existSpecialYohoSearchService){  
229 - return; 227 +
  228 + function specialLbProject(){
  229 + for(var i=0; i<specialProjectLbList.length; i++){
  230 + var projectName=specialProjectLbList[i];
  231 + var resultAreaId="resultArea_"+projectName;
  232 +
  233 + $.ajax({
  234 + url: contextPath + 'project/checkSpecialProjectLbInfoBeforeBuild',
  235 + type: 'POST',
  236 + data:{
  237 + project:projectName,
  238 + operate_name:$("#operate_name").val(),
  239 + environment_name:$("#environment_name").val(),
  240 + branch_name:$("#branch_name").val(),
  241 + workid_name:$("#workid_name").val(),
  242 + rollbackfile_name:$("#rollbackfile_name").val()
  243 + },
  244 + dataType: 'json',
  245 + success: function (reps) {
  246 + if(reps!=null&&reps.code==200){
  247 + var jsonLbResult = reps.data;
  248 + console.log(jsonLbResult);
  249 + if(jsonLbResult.onlyOneHost=="2"){
  250 + textAreaAppend(resultAreaId,"lb存在多台主机,特殊流程发布!");
  251 +
  252 + singleSpecialLbProjectBuild(resultAreaId,jsonLbResult);
  253 + }else{
  254 + var dialog = $("<div>").appendTo($("body"));
  255 + dialog.dialog({
  256 + title: "提示",
  257 + backdrop: "static",
  258 + content: "负载均衡查询到一台或者没有机器实例,通过原流程发布",
  259 + buttons: [{
  260 + text: "否",
  261 + className: "btn-info",
  262 + onclick: function () {
  263 + textAreaAppend(resultAreaId,"发布取消!!");
  264 + document.getElementById("task-info-div_"+projectName).innerHTML = "<strong>发布取消</strong>";
  265 + dialog.dialog("hide");
  266 + }
  267 + }, {
  268 + text: "是",
  269 + className: "btn-danger",
  270 + onclick: function () {
  271 + dialog.dialog("hide");
  272 + textAreaAppend(resultAreaId,"lb最多只有一台主机,原流程直接发布!");
  273 +
  274 + jsonLbResult.deployIps="";//要发布ip为空,则根据配置文件查找全部机器
  275 + var d=deployYohoSearchService(resultAreaId,jsonLbResult);
  276 + d.then(function () {
  277 + textAreaAppend(resultAreaId,"发布成功,完成!!");
  278 + document.getElementById("task-info-div_"+projectName).innerHTML = "<strong>发布成功</strong>";
  279 + return ;
  280 + });
  281 + }
  282 + }]
  283 + });
  284 + }
  285 + }else{
  286 + if(reps!=null){
  287 + textAreaAppend(resultAreaId,"lb检查出错,"+projectName+"项目发布终止!"+reps.message);
  288 + }else{
  289 + textAreaAppend(resultAreaId,"lb检查出错,"+projectName+"项目发布终止!");
  290 + }
  291 + }
  292 + },
  293 + error: function (e) {
  294 + textAreaAppend(resultAreaId,"lb检查出错,"+projectName+"项目发布终止!");
  295 + }
  296 + });
  297 +
  298 +
  299 +
230 } 300 }
231 301
  302 + }
232 303
233 - var jsonLbResult = JSON.parse('${specialYohoSearchServiceResult}');  
234 - console.log(jsonLbResult);  
235 - if("error"=="${existSpecialYohoSearchService}"){  
236 - textAreaAppendYohoSearchService(jsonLbResult.msg);  
237 - }else{  
238 - textAreaAppendYohoSearchService(jsonLbResult.msg); 304 + function singleSpecialLbProjectBuild(resultAreaId,jsonLbResult) {
  305 + textAreaAppend(resultAreaId,jsonLbResult.msg);
239 //开始执行 306 //开始执行
240 - textAreaAppendYohoSearchService(">>>>>开始执行>>>>>"); 307 + textAreaAppend(resultAreaId,">>>>>开始执行>>>>>");
241 //1.保留,卸载 308 //1.保留,卸载
242 - textAreaAppendYohoSearchService("保留机器id is "+jsonLbResult.keepId);  
243 - textAreaAppendYohoSearchService("保留机器ip is "+jsonLbResult.keepIp);  
244 - textAreaAppendYohoSearchService("卸载机器id包含 "+jsonLbResult.changeIds);  
245 - textAreaAppendYohoSearchService("卸载机器ip包含 "+jsonLbResult.changeIps);  
246 //2.查询卸载结果,等待卸载完成 309 //2.查询卸载结果,等待卸载完成
247 //3.发布本次卸载的机器 310 //3.发布本次卸载的机器
248 //4.查询发布结果,发布完成之后,再挂载 311 //4.查询发布结果,发布完成之后,再挂载
@@ -251,68 +314,77 @@ @@ -251,68 +314,77 @@
251 //7.发布本次卸载的机器 314 //7.发布本次卸载的机器
252 //8.查询发布结果,发布完成之后,再挂载 315 //8.查询发布结果,发布完成之后,再挂载
253 //流程结束 316 //流程结束
  317 + textAreaAppend(resultAreaId,"保留机器id is "+jsonLbResult.keepId);
  318 + textAreaAppend(resultAreaId,"保留机器ip is "+jsonLbResult.keepIp);
  319 + textAreaAppend(resultAreaId,"卸载机器id包含 "+jsonLbResult.changeIds);
  320 + textAreaAppend(resultAreaId,"卸载机器ip包含 "+jsonLbResult.changeIps);
254 321
  322 + jsonLbResult.next_moveIds=jsonLbResult.changeIds;
  323 + var d=deregisterFromLb(resultAreaId,jsonLbResult);
255 324
256 - jsonLbResult.deployIps=jsonLbResult.changeIps;  
257 - jsonLbResult.next_registerIds=jsonLbResult.changeIds;  
258 - jsonLbResult.next_moveIds=jsonLbResult.keepId;  
259 - jsonLbResult.lbHostNum=jsonLbResult.keepNum;  
260 -  
261 - var d=checkDeregister(jsonLbResult); 325 + d = d.then(function(){
  326 + jsonLbResult.deployIps=jsonLbResult.changeIps;
  327 + jsonLbResult.next_registerIds=jsonLbResult.changeIds;
  328 + jsonLbResult.next_moveIds=jsonLbResult.keepId;
  329 + jsonLbResult.lbHostNum=jsonLbResult.keepNum;
  330 + return checkDeregister(resultAreaId,jsonLbResult);
  331 + });
262 332
263 d = d.then(function(){ 333 d = d.then(function(){
264 - return deployYohoSearchService(jsonLbResult); 334 + return deployYohoSearchService(resultAreaId,jsonLbResult);
265 }); 335 });
266 336
267 d= d.then(function(){ 337 d= d.then(function(){
268 //开始挂载到负载均衡 338 //开始挂载到负载均衡
269 - registerToLb(jsonLbResult.environmentName,jsonLbResult.next_registerIds); 339 + registerToLb(resultAreaId,jsonLbResult,jsonLbResult.next_registerIds);
270 //挂载完成之后,负载均衡机器恢复卸载之前的状态,检查 340 //挂载完成之后,负载均衡机器恢复卸载之前的状态,检查
271 jsonLbResult.lbHostNum=jsonLbResult.hostNum; 341 jsonLbResult.lbHostNum=jsonLbResult.hostNum;
272 - return checkDeregister(jsonLbResult); 342 + return checkDeregister(resultAreaId,jsonLbResult);
273 }); 343 });
274 344
275 d= d.then(function(){ 345 d= d.then(function(){
276 - deregisterFromLb(jsonLbResult); 346 + deregisterFromLb(resultAreaId,jsonLbResult);
277 //卸载完成之后,再检查 347 //卸载完成之后,再检查
278 jsonLbResult.deployIps=jsonLbResult.keepIp; 348 jsonLbResult.deployIps=jsonLbResult.keepIp;
279 jsonLbResult.next_registerIds=jsonLbResult.next_moveIds; 349 jsonLbResult.next_registerIds=jsonLbResult.next_moveIds;
280 jsonLbResult.next_moveIds=""; 350 jsonLbResult.next_moveIds="";
281 jsonLbResult.lbHostNum=jsonLbResult.changeNum; 351 jsonLbResult.lbHostNum=jsonLbResult.changeNum;
282 - return checkDeregister(jsonLbResult); 352 + return checkDeregister(resultAreaId,jsonLbResult);
283 }); 353 });
284 354
285 d=d.then(function () { 355 d=d.then(function () {
286 - return deployYohoSearchService(jsonLbResult); 356 + return deployYohoSearchService(resultAreaId,jsonLbResult);
287 }); 357 });
288 358
289 d=d.then(function(){ 359 d=d.then(function(){
290 //开始挂载到负载均衡 360 //开始挂载到负载均衡
291 - registerToLb(jsonLbResult.environmentName,jsonLbResult.next_registerIds); 361 + registerToLb(resultAreaId,jsonLbResult,jsonLbResult.next_registerIds);
292 //挂载完成之后,负载均衡机器恢复卸载之前的状态,检查 362 //挂载完成之后,负载均衡机器恢复卸载之前的状态,检查
293 jsonLbResult.lbHostNum=jsonLbResult.hostNum; 363 jsonLbResult.lbHostNum=jsonLbResult.hostNum;
294 - return checkDeregister(jsonLbResult); 364 + return checkDeregister(resultAreaId,jsonLbResult);
295 }); 365 });
296 366
297 d.then(function () { 367 d.then(function () {
298 - textAreaAppendYohoSearchService("发布成功,完成!!");  
299 - document.getElementById("task-info-div_yoho-search-service").innerHTML = "<strong>发布成功</strong>"; 368 + textAreaAppend(resultAreaId,"发布成功,完成!!");
  369 + document.getElementById("task-info-div_"+jsonLbResult.currentProject).innerHTML = "<strong>发布成功</strong>";
300 return ; 370 return ;
301 }); 371 });
302 - } 372 +
303 } 373 }
304 374
  375 +
305 //发布 376 //发布
306 - function deployYohoSearchService(paramBackJson){  
307 - textAreaAppendYohoSearchService("*** 已经从负载均衡卸载下来的机器 : "+paramBackJson.deployIps);  
308 - var messageId = deployProject(paramBackJson);  
309 - textAreaAppendYohoSearchService("项目正在部署!messageId is "+messageId);  
310 - return deployProjectGetMsg(messageId,paramBackJson); 377 + function deployYohoSearchService(resultAreaId,paramBackJson){
  378 + textAreaAppend(resultAreaId,"*** 即将发布的机器是 : "+paramBackJson.deployIps);
  379 + var messageId = deployProject(resultAreaId,paramBackJson);
  380 + textAreaAppend(resultAreaId,"项目正在部署!messageId is "+messageId);
  381 + return deployProjectGetMsg(resultAreaId,messageId,paramBackJson);
311 } 382 }
312 383
313 384
314 - function deployProject(paramBackJson){  
315 - textAreaAppendYohoSearchService("开始部署项目"); 385 +
  386 + function deployProject(resultAreaId,paramBackJson){
  387 + textAreaAppend(resultAreaId,"开始部署项目");
316 var returnMessageId = ""; 388 var returnMessageId = "";
317 var url = contextPath + 'project/buildProjectWithIPs'; 389 var url = contextPath + 'project/buildProjectWithIPs';
318 var paramFront={}; 390 var paramFront={};
@@ -331,7 +403,7 @@ @@ -331,7 +403,7 @@
331 async: false, 403 async: false,
332 success: function (data) { 404 success: function (data) {
333 if (!data || data.code != 200) { 405 if (!data || data.code != 200) {
334 - textAreaAppendYohoSearchService("发布失败"); 406 + textAreaAppend(resultAreaId,"发布失败");
335 }else{ 407 }else{
336 //console.log("buildProjectWithIPs data is "+data.data); 408 //console.log("buildProjectWithIPs data is "+data.data);
337 returnMessageId = data.data.split(',')[0]; 409 returnMessageId = data.data.split(',')[0];
@@ -339,16 +411,16 @@ @@ -339,16 +411,16 @@
339 }, 411 },
340 error: function (e) { 412 error: function (e) {
341 console.log(e); 413 console.log(e);
342 - textAreaAppendYohoSearchService("发布失败,error"+e); 414 + textAreaAppend(resultAreaId,"发布失败,error"+e);
343 } 415 }
344 }); 416 });
345 return returnMessageId; 417 return returnMessageId;
346 } 418 }
347 419
348 //3.1:发布项目的同时获取发布的消息 420 //3.1:发布项目的同时获取发布的消息
349 - function deployProjectGetMsg(msgId, paramBackJson){ 421 + function deployProjectGetMsg(resultAreaId,msgId, paramBackJson){
350 var def = $.Deferred(); 422 var def = $.Deferred();
351 - textAreaAppendYohoSearchService("检查项目部署进度"); 423 + textAreaAppend(resultAreaId,"检查项目部署进度");
352 var intervalIndexMsg = setInterval(function() { 424 var intervalIndexMsg = setInterval(function() {
353 $.ajax({ 425 $.ajax({
354 url: contextPath + 'project/getbuildmsg?messageid=' + msgId+"&project="+paramBackJson.currentProject, 426 url: contextPath + 'project/getbuildmsg?messageid=' + msgId+"&project="+paramBackJson.currentProject,
@@ -359,7 +431,7 @@ @@ -359,7 +431,7 @@
359 var obj2 = eval("(" + data3 + ")"); 431 var obj2 = eval("(" + data3 + ")");
360 var messagedata = obj2.data; 432 var messagedata = obj2.data;
361 if ((messagedata.message != "") && (messagedata.message != null) && (messagedata.message != undefined)) { 433 if ((messagedata.message != "") && (messagedata.message != null) && (messagedata.message != undefined)) {
362 - textAreaAppendYohoSearchService(messagedata.message); 434 + textAreaAppend(resultAreaId,messagedata.message);
363 } 435 }
364 436
365 //code为2 ,则结束 437 //code为2 ,则结束
@@ -367,7 +439,7 @@ @@ -367,7 +439,7 @@
367 //只有状态2,3,4才表示系统部署成功与否 439 //只有状态2,3,4才表示系统部署成功与否
368 if (code == 2 || code == 3 || code == 4) { 440 if (code == 2 || code == 3 || code == 4) {
369 clearInterval(intervalIndexMsg); 441 clearInterval(intervalIndexMsg);
370 - textAreaAppendYohoSearchService("项目部署完成,状态 is "+code); 442 + textAreaAppend(resultAreaId,"项目部署完成,状态 is "+code);
371 if(code==2){ 443 if(code==2){
372 //任务执行正常结束,只有这种情况,才能执行下一步操作。 444 //任务执行正常结束,只有这种情况,才能执行下一步操作。
373 def.resolve(); 445 def.resolve();
@@ -382,12 +454,13 @@ @@ -382,12 +454,13 @@
382 } 454 }
383 455
384 //卸载 456 //卸载
385 - function deregisterFromLb(paramBackJson) {  
386 - textAreaAppendYohoSearchService("卸载机器到elb"+paramBackJson.next_moveIds);  
387 - $.ajax({ 457 + function deregisterFromLb(resultAreaId,paramBackJson) {
  458 + textAreaAppend(resultAreaId,"从elb卸载机器 "+paramBackJson.next_moveIds);
  459 + return $.ajax({
388 url: contextPath+"/project/deregisterHostYohoSearchService", 460 url: contextPath+"/project/deregisterHostYohoSearchService",
389 type: "post", 461 type: "post",
390 data:{ 462 data:{
  463 + project:paramBackJson.currentProject,
391 environment_name:paramBackJson.environmentName, 464 environment_name:paramBackJson.environmentName,
392 instIds:paramBackJson.next_moveIds 465 instIds:paramBackJson.next_moveIds
393 }, 466 },
@@ -403,13 +476,14 @@ @@ -403,13 +476,14 @@
403 } 476 }
404 477
405 //挂载到负载均衡 478 //挂载到负载均衡
406 - function registerToLb(environment_name,instIds){  
407 - textAreaAppendYohoSearchService("挂载机器到elb "+instIds); 479 + function registerToLb(resultAreaId,jsonLbResult,instIds){
  480 + textAreaAppend(resultAreaId,"挂载机器到elb "+instIds);
408 $.ajax({ 481 $.ajax({
409 url: contextPath+"/project/registerHostYohoSearchService", 482 url: contextPath+"/project/registerHostYohoSearchService",
410 type: "post", 483 type: "post",
411 data:{ 484 data:{
412 - environment_name:environment_name, 485 + project:jsonLbResult.currentProject,
  486 + environment_name:jsonLbResult.environmentName,
413 instIds:instIds 487 instIds:instIds
414 }, 488 },
415 dataType: "json", 489 dataType: "json",
@@ -426,27 +500,30 @@ @@ -426,27 +500,30 @@
426 500
427 501
428 //卸载检查 502 //卸载检查
429 - function checkDeregister(cbfParam){ 503 + function checkDeregister(resultAreaId,cbfParam){
430 var keepHostNum=cbfParam.lbHostNum; 504 var keepHostNum=cbfParam.lbHostNum;
431 var df = $.Deferred(); 505 var df = $.Deferred();
432 - textAreaAppendYohoSearchService("**** 负载均衡实例数量检查 ***"); 506 + textAreaAppend(resultAreaId,"**** 负载均衡实例数量检查 ***");
433 var count=0; 507 var count=0;
434 var intervalIndex = setInterval(function() { 508 var intervalIndex = setInterval(function() {
435 $.ajax({ 509 $.ajax({
436 - url: contextPath+"/project/getLbInfoYohoSearchService?environment_name="+cbfParam.environmentName, 510 + url: contextPath+"/project/getLbInfoYohoSearchService",
437 type: "post", 511 type: "post",
438 dataType: "json", 512 dataType: "json",
439 //async: false, 513 //async: false,
440 //timeout:120000, //超时时间:120秒 514 //timeout:120000, //超时时间:120秒
441 - data: {}, 515 + data: {
  516 + project:cbfParam.currentProject,
  517 + environment_name:cbfParam.environmentName
  518 + },
442 success: function (checkResponse) { 519 success: function (checkResponse) {
443 count++; 520 count++;
444 if(count > 5){ 521 if(count > 5){
445 - textAreaAppendYohoSearchService("..........检查次数......"+(count-5)); 522 + textAreaAppend(resultAreaId,"..........检查次数......"+(count-5));
446 } 523 }
447 if(count > 105){ 524 if(count > 105){
448 clearInterval(intervalIndex); 525 clearInterval(intervalIndex);
449 - textAreaAppendYohoSearchService("**** 超过规定的次数,任务终止 ****"); 526 + textAreaAppend(resultAreaId,"**** 超过规定的次数,任务终止 ****");
450 }else if(checkResponse!=null&&checkResponse.code==200){ 527 }else if(checkResponse!=null&&checkResponse.code==200){
451 var currentHosts=0; 528 var currentHosts=0;
452 for(var hostid in checkResponse.data){ 529 for(var hostid in checkResponse.data){
@@ -454,7 +531,7 @@ @@ -454,7 +531,7 @@
454 } 531 }
455 if(currentHosts==keepHostNum){ 532 if(currentHosts==keepHostNum){
456 clearInterval(intervalIndex); 533 clearInterval(intervalIndex);
457 - textAreaAppendYohoSearchService("**** 检查通过,负载均衡现有实例数量为: "+keepHostNum); 534 + textAreaAppend(resultAreaId,"**** 检查通过,负载均衡现有实例数量为: "+keepHostNum);
458 df.resolve(); 535 df.resolve();
459 } 536 }
460 } 537 }
@@ -530,10 +607,6 @@ @@ -530,10 +607,6 @@
530 }); 607 });
531 } 608 }
532 609
533 - function textAreaAppendYohoSearchService(content) {  
534 - textAreaAppend(yoho_search_service_resultAreaId,content);  
535 - }  
536 -  
537 function textAreaAppend(textId,content) { 610 function textAreaAppend(textId,content) {
538 var d = $("#"+textId).val(); 611 var d = $("#"+textId).val();
539 if(d!=null&&d.length>0){ 612 if(d!=null&&d.length>0){