• 你们看吧,一看一个不吱声


    本来能及时返回,就是无限嵌套

    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+accessKeySecret
                                                            StringBuffer 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, "集群警告短信通知成功");
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
  • 相关阅读:
    气传导蓝牙耳机哪款好?精选五款值得入手的气传导耳机分享
    果园自主跟随碎枝机器人
    全连接网络参数Xavier初始化
    [UE]常见C++类继承关系
    Pi-hole:Linux 硬件级别的广告拦截器 | 开源日报 No.58
    不精确微分/不完全微分(Inexact differential/Imperfect differential)
    C++类内定义友元却无需类外声明的特殊情况
    Linux 基础-文件属性与权限
    蓝桥杯每日一题2023.10.11
    ElementPlus里的类型别名声明及使用
  • 原文地址:https://blog.csdn.net/weixin_40375601/article/details/133908502