本来能及时返回,就是无限嵌套
public Result<JSONObject> schedulerClusterSendNotes() {//执行获取集群ID的逻辑//获取集群Result<List<Map>> result = bigdataCommonFegin.selectClusterList();if (null != result && null != result.getData()) {//JSONArray data = JSONObject.parseArray(result.getData().toString());for (Map dataMap : result.getData()) {Integer clusterId = (Integer) (dataMap.get("clusterId"));SdpsNoteAndNoteConfigReq noteAndConfigReq = new SdpsNoteAndNoteConfigReq();noteAndConfigReq.setClusterId(clusterId);List<SdpsNoteAndConfigDTO> noteAndConfigs = sdpsNoteAndNoteConfigMapper.findNotesAndConfig(noteAndConfigReq);AmbariUtil ambariUtil = new AmbariUtil(clusterId);Result<SysGlobalArgs> args = bigdataCommonFegin.getGlobalParam("ambari", "warningCnt");JSONObject warnResult = ambariUtil.getAmbariApi(args.getData().getArgValue(), args.getData().getArgValueDesc(),getClusterNameParam(ambariUtil));//查询群组Result<SysGlobalArgs> argsGroup = bigdataCommonFegin.getGlobalParam("ambari", "warningGroups");JSONObject warnGroupsResult = ambariUtil.getAmbariApi(argsGroup.getData().getArgValue(), argsGroup.getData().getArgValueDesc(),getClusterNameParam(ambariUtil));try {if (null != warnResult) {JSONArray items = warnResult.getJSONArray("items");if (items.size() > 0) {for (int w = 0; w < items.size(); w++) {JSONObject item = items.getJSONObject(w);JSONObject alertJO = item.getJSONObject("Alert");String state = alertJO.getString("state");String text = alertJO.getString("text");String serviceName = alertJO.getString("service_name");String label = alertJO.getString("label");Integer id = alertJO.getInteger("id");String hostName = alertJO.getString("host_name");String componentName = alertJO.getString("component_name");String clusterName = alertJO.getString("cluster_name");//是否在每个群组包括的组件子服务中有一个对应子服务(即含告警的)JSONArray warnGItem = warnGroupsResult.getJSONArray("items");for (int g = 0; g < warnGItem.size(); g++) {JSONObject alertGroup = warnGItem.getJSONObject(g).getJSONObject("AlertGroup");String name = warnGItem.getJSONObject(g).getString("name");Integer noteId = warnGItem.getJSONObject(g).getInteger("id");if(null==alertGroup)continue;JSONArray definitions = alertGroup.getJSONArray("definitions");if(null==definitions)continue;JSONArray targets = alertGroup.getJSONArray("targets");if(null==targets)continue;for (int d = 0; d < definitions.size(); d++) {/*{"name" : "ams_metrics_monitor_process","label" : "Metrics Monitor Status","description" : "This alert indicates the status of the Metrics Monitor process as determined by the monitor status script.","enabled" : false,"service_name" : "AMBARI_METRICS","component_name" : "METRICS_MONITOR","id" : 1,"source_type" : "SCRIPT"},*/String description = definitions.getJSONObject(d).getString("description");boolean cnEnabled = definitions.getJSONObject(d).getBoolean("enabled");if (!cnEnabled) continue;String gComponentName = definitions.getJSONObject(d).getString("component_name");if (StringUtil.isNotBlank(componentName)&&StringUtil.isNotBlank(gComponentName)&&componentName.equals(gComponentName)) {//警告组件在该群组 下一步 寻找目标/*targets" : [{"enabled" : true,"name" : "ambari_notice","properties" : null,"id" : 3,"description" : "ambari_notice","global" : true,"notification_type" : "EMAIL"}*/for (int t = 0; t < targets.size(); t++) {//邮件方式时群组不可用 不让其影响短信群组是否可用// if (!targets.getJSONObject(t).getBoolean("enabled")) continue;String tname = targets.getJSONObject(t).getString("name");Integer idTarget = targets.getJSONObject(t).getInteger("id");//判断通知方 和严重程度for (SdpsNoteAndConfigDTO noteAndConfig : noteAndConfigs) {if (noteAndConfig.getNote().contains(tname)&& 1 == noteAndConfig.getIsEnable()&& noteAndConfig.getComponentName().contains(componentName)&& noteAndConfig.getStatus().contains(state)) {if(StringUtil.isNotBlank(noteAndConfig.getSignature())&&StringUtil.isNotBlank(noteAndConfig.getTemplate())&&StringUtil.isNotBlank(noteAndConfig.getMobile())&&StringUtil.isNotBlank(noteAndConfig.getAccessKeyId())&&StringUtil.isNotBlank(noteAndConfig.getKeysecret())){//发短信SmsParamsDTO smsParamsDTO = new SmsParamsDTO();smsParamsDTO.setSign(noteAndConfig.getSignature());smsParamsDTO.setTemplateId(noteAndConfig.getTemplate());StringBuffer strParams =new StringBuffer();if(StringUtil.isNotBlank(noteAndConfig.getParams()))strParams.append(noteAndConfig.getParams());strParams.append(componentName).append(",").append(text);smsParamsDTO.setParams(strParams.toString());smsParamsDTO.setMobiles(noteAndConfig.getMobile());smsParamsDTO.setAccessKeyId(noteAndConfig.getAccessKeyId());smsParamsDTO.setSecretKey(noteAndConfig.getKeysecret());smsParamsDTO.setTimestamp(String.valueOf(System.currentTimeMillis()));//参数校验序列//signature+template+timestamp+accessKeyId+accessKeySecretStringBuffer encodeEncryption=new StringBuffer();encodeEncryption.append(smsParamsDTO.getSign()).append(smsParamsDTO.getTemplateId()).append(smsParamsDTO.getTimestamp()).append(smsParamsDTO.getAccessKeyId()).append(smsParamsDTO.getSecretKey());//进行MD5(32位小写)2次加密String digest = DigestUtils.md5DigestAsHex(DigestUtils.md5DigestAsHex((encodeEncryption.toString().getBytes())).getBytes());smsParamsDTO.setEncryption(digest);String jsonString = JSON.toJSONString(smsParamsDTO);//BASE64编String encode = Base64.getEncoder().encodeToString(jsonString.getBytes());try{SmsProperties smspro = SpringUtil.getBean(SmsProperties.class);HttpUtil.post(HttpUtil.ContentType_JSON_UTF8,smspro.getUrl(),encode.getBytes());//发完短信追加历史表记录SdpsNoteSendHistory sendHistory = new SdpsNoteSendHistory();sendHistory.setClusterId(clusterId);sendHistory.setClusterName(clusterName);sendHistory.setComponentName(componentName);//Date day=new Date();//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");sendHistory.setCreateTime(new Date());sendHistory.setNote(noteAndConfig.getNote());sendHistory.setText(text);sendHistory.setHistoryId( (int)System.currentTimeMillis());sendHistory.setIsSend(1);sdpsNoteSendHistoryMapper.insert(sendHistory);}catch (Exception e){SdpsNoteSendHistory sendHistory = new SdpsNoteSendHistory();sendHistory.setClusterId(clusterId);sendHistory.setClusterName(clusterName);sendHistory.setComponentName(componentName);//Date day=new Date();//SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");sendHistory.setCreateTime(new Date());sendHistory.setNote(noteAndConfig.getNote());sendHistory.setText(text);sendHistory.setHistoryId( (int)System.currentTimeMillis());sendHistory.setIsSend(2);sdpsNoteSendHistoryMapper.insert(sendHistory);throw new BusinessException("集群id:"+clusterId+" 短信发送失败:"+smsParamsDTO.getMobiles());}}}}}}}}}//return Result.succeed(null, "集群警告短信通知成功");}}return Result.succeed(null, "集群警告短信通知成功");} catch (Exception e) {log.info("集群警告短信通知失败:", e);return Result.failed("集群警告短信通知失败");}}}return Result.succeed(null, "集群警告短信通知成功");
}