Authored by qinchao

监控对象的更新

@@ -316,11 +316,126 @@ public class CloudToolServiceImpl implements CloudToolService { @@ -316,11 +316,126 @@ public class CloudToolServiceImpl implements CloudToolService {
316 return updateMobject4Nginx(infoReq); 316 return updateMobject4Nginx(infoReq);
317 }else if ("PCH5-memcache".equalsIgnoreCase(infoReq.getScalingGroupName())||"java-gateway-memcache".equalsIgnoreCase(infoReq.getScalingGroupName())){ 317 }else if ("PCH5-memcache".equalsIgnoreCase(infoReq.getScalingGroupName())||"java-gateway-memcache".equalsIgnoreCase(infoReq.getScalingGroupName())){
318 return updateMemcacheInfoForMobject(infoReq); 318 return updateMemcacheInfoForMobject(infoReq);
  319 + }else if("ELASTICSEARCH".equalsIgnoreCase(infoReq.getScalingGroupName())){
  320 + //暂时不做
  321 + }else if("PCH5-NODE".equalsIgnoreCase(infoReq.getScalingGroupName())||"PCH5-AutoScaling".equalsIgnoreCase(infoReq.getScalingGroupName())){
  322 + //暂时不做
  323 + }else{
  324 + ////// 普通java项目
  325 + return updateMobject4JavaApp(infoReq);
319 } 326 }
320 } 327 }
321 return res; 328 return res;
322 } 329 }
323 330
  331 + /// java app的监控配置,java_nginx 既包括172 ,又包括10,所以更新的时候,如果要删除需要只删除当前云
  332 + private BaseResponse updateMobject4JavaApp(AutoScalingInfoReq infoReq){
  333 + BaseResponse res = new BaseResponse();
  334 + String environment="";
  335 + if(1==infoReq.getCloudType()){
  336 + environment="aws";
  337 + }else if(2==infoReq.getCloudType()){
  338 + environment="qcloud";
  339 + }
  340 + String mobjectPaths=infoReq.getMobjectPaths();
  341 + String[] mobjectPaths_array=mobjectPaths.split(",");
  342 + String typeNames=mobjectPaths_array[mobjectPaths_array.length-1];//////////有可能是多个,比如activity-bigdata
  343 + StringBuilder sb=new StringBuilder();
  344 + for(String typeName:typeNames.split("-")){
  345 + mobjectPaths_array[mobjectPaths_array.length-1]=typeName;
  346 + TypeInfo typeInfo = getTypeByMobjectPathArray(mobjectPaths_array);
  347 + if(typeInfo!=null){
  348 + List<MObjectInfo> objectInfoList = mObjectInfoMapper.getTypeMosInfo(typeInfo.getTypeId());
  349 + List<String> existsHostIps=new ArrayList<String>();
  350 + if(objectInfoList!=null&&objectInfoList.size()>0){
  351 + for(MObjectInfo mob:objectInfoList){
  352 + //处理移除的机器,但是要保留另外一个云的机器信息
  353 + if(infoReq.getNewInstanceIps().indexOf(mob.getMoHostIp())<0){
  354 + if(environment.equals("aws")&&mob.getMoHostIp().startsWith("172.")){
  355 + mObjectInfoMapper.deleteMoInfo(mob.getMoId());
  356 + sb.append("删除"+typeName+"监控对象:"+mob.getMoId()+"\n");
  357 + }
  358 + if(environment.equals("qcloud")&&mob.getMoHostIp().startsWith("10.")){
  359 + mObjectInfoMapper.deleteMoInfo(mob.getMoId());
  360 + sb.append("删除"+typeName+"监控对象:"+mob.getMoId()+"\n");
  361 + }
  362 + }else{
  363 + existsHostIps.add(mob.getMoHostIp());
  364 + }
  365 + }
  366 + }
  367 + //处理新增的机器
  368 + String[] allIps=infoReq.getNewInstanceIps().split(",");
  369 + for(String ip:allIps){
  370 + if(StringUtils.isNotBlank(ip)&&!existsHostIps.contains(ip)){
  371 + MObjectInfo mob=new MObjectInfo();
  372 + mob.setMoName(buildMoName(typeName,environment));
  373 + mob.setMoHostIp(ip);
  374 + mob.setMoTags(getMobjectTagsForJavaApp(typeName));
  375 + mob.setMoTypeId(typeInfo.getTypeId());
  376 + mObjectInfoMapper.insertMoInfo(mob);
  377 + sb.append("添加"+typeName+"监控对象:"+mob.getMoId()+"\n");
  378 + }
  379 + }
  380 + }
  381 +
  382 + }
  383 + res.setData(sb.toString());
  384 + return res;
  385 + }
  386 +
  387 + // 获取java app的标签 :端口号
  388 + private String getMobjectTagsForJavaApp(String typeName){
  389 + String tag="";
  390 + switch (typeName){
  391 + case "gateway":
  392 + tag="8080";
  393 + break;
  394 + case "order":
  395 + tag="8084";
  396 + break;
  397 + case "promotion":
  398 + tag="8085";
  399 + break;
  400 + case "product":
  401 + tag="8083";
  402 + break;
  403 + case "message":
  404 + tag="8086";
  405 + break;
  406 + case "sns":
  407 + tag="8082";
  408 + break;
  409 + case "users":
  410 + tag="8081";
  411 + break;
  412 + case "resources":
  413 + tag="8087";
  414 + break;
  415 + case "activity":
  416 + tag="8090";
  417 + break;
  418 + case "union":
  419 + tag="";
  420 + break;
  421 + case "brower":
  422 + tag="8092";
  423 + break;
  424 + case "social":
  425 + tag="8095";
  426 + break;
  427 + case "uic":
  428 + tag="8096";
  429 + break;
  430 + case "bigdata":
  431 + tag="";
  432 + break;
  433 + case "yoho!now":
  434 + tag="";
  435 + break;
  436 + }
  437 + return tag;
  438 + }
324 /// nginx的监控配置,java_nginx 既包括172 ,又包括10,所以更新的时候,如果要删除需要只删除当前云 439 /// nginx的监控配置,java_nginx 既包括172 ,又包括10,所以更新的时候,如果要删除需要只删除当前云
325 private BaseResponse updateMobject4Nginx(AutoScalingInfoReq infoReq){ 440 private BaseResponse updateMobject4Nginx(AutoScalingInfoReq infoReq){
326 BaseResponse res = new BaseResponse(); 441 BaseResponse res = new BaseResponse();