Просмотр исходного кода

feat: 发生异常时打印响应内容

weijianghai 2 лет назад
Родитель
Сommit
34312b58e7

+ 194 - 1
.gitignore

@@ -1,2 +1,195 @@
 target/
-.vscode/
+.vscode/### Java template
+# Compiled class file
+*.class
+
+# Log file
+*.log
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+### Maven template
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+# https://github.com/takari/maven-wrapper#usage-without-binary-jar
+.mvn/wrapper/maven-wrapper.jar
+
+### VisualStudioCode template
+.vscode/*
+!.vscode/settings.json
+!.vscode/tasks.json
+!.vscode/launch.json
+!.vscode/extensions.json
+*.code-workspace
+
+# Local History for Visual Studio Code
+.history/
+
+### JetBrains template
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn.  Uncomment if using
+# auto-import.
+# .idea/artifacts
+# .idea/compiler.xml
+# .idea/jarRepositories.xml
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+# *.iml
+# *.ipr
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Eclipse template
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.settings/
+.loadpath
+.recommenders
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# PyDev specific (Python IDE for Eclipse)
+*.pydevproject
+
+# CDT-specific (C/C++ Development Tooling)
+.cproject
+
+# CDT- autotools
+.autotools
+
+# Java annotation processor (APT)
+.factorypath
+
+# PDT-specific (PHP Development Tools)
+.buildpath
+
+# sbteclipse plugin
+.target
+
+# Tern plugin
+.tern-project
+
+# TeXlipse plugin
+.texlipse
+
+# STS (Spring Tool Suite)
+.springBeans
+
+# Code Recommenders
+.recommenders/
+
+# Annotation Processing
+.apt_generated/
+.apt_generated_test/
+
+# Scala IDE specific (Scala & Java development for Eclipse)
+.cache-main
+.scala_dependencies
+.worksheet
+
+# Uncomment this line if you wish to ignore the project description file.
+# Typically, this file would be tracked if it contains build/dependency configurations:
+#.project
+
+### Example user template template
+### Example user template
+
+# IntelliJ project files
+.idea
+*.iml
+out
+gen
+
+### Includes
+!lib/*

+ 55 - 0
doc/dw_complain_realtime_alarm_h.sql

@@ -0,0 +1,55 @@
+CREATE TABLE tsfx.dw_complain_realtime_alarm_h
+(
+    sdate              timestamp NULL,
+    uniqueid           varchar(200) NULL,
+    uniqueclearid      varchar(200) NULL,
+    eventtime          varchar(50) NULL,
+    canceltime         varchar(50) NULL,
+    status             numeric NULL,
+    projectstatus      numeric NULL,
+    vendoralarmserial  varchar(200) NULL,
+    alarmtitle         varchar(200) NULL,
+    vendorseverity     varchar(200) NULL,
+    vendoralarmtype    varchar(200) NULL,
+    specificproblem    varchar(1000) NULL,
+    specificproblemid  varchar(200) NULL,
+    equipmentclass     varchar(200) NULL,
+    equipmentname      varchar(1000) NULL,
+    locateneclass      varchar(500) NULL,
+    locatenename       varchar(1000) NULL,
+    province           varchar(200) NULL,
+    region             varchar(200) NULL,
+    city               varchar(200) NULL,
+    grid               varchar(200) NULL,
+    area               varchar(200) NULL,
+    vendor             varchar(200) NULL,
+    specialty          numeric NULL,
+    siteid             varchar(200) NULL,
+    roomid             varchar(1000) NULL,
+    towersiteno        varchar(200) NULL,
+    proequipmentstatus numeric NULL,
+    projectname        varchar(200) NULL,
+    projectno          varchar(200) NULL,
+    projectstarttime   varchar(200) NULL,
+    projectendtime     varchar(200) NULL,
+    worksendstatus     numeric NULL,
+    workstatus         numeric NULL,
+    workno             varchar(200) NULL,
+    workarchivedtime   varchar(200) NULL,
+    workdutydep        varchar(200) NULL,
+    worksendperson     varchar(200) NULL,
+    alarmlogicclass    varchar(200) NULL,
+    alarmlogicsubclass varchar(200) NULL,
+    standardalarmname  varchar(1000) NULL,
+    alarmseverity      numeric NULL,
+    standardalarmid    varchar(500) NULL,
+    effectonequipment  varchar(200) NULL,
+    effectonbusiness   varchar(200) NULL,
+    standardflag       numeric NULL,
+    networktype        numeric NULL,
+    equipmentdn        varchar(500) NULL,
+    locatenedn         varchar(500) NULL,
+    taccode            varchar(500) NULL,
+    tacid              varchar(200) NULL,
+    alarmtext          text NULL
+) DISTRIBUTED BY (uniqueid);

+ 0 - 0
doc/gpload/alarm.sh → doc/prod/gpload/alarm.sh


+ 0 - 0
doc/gpload/alarm.yml → doc/prod/gpload/alarm.yml


+ 1 - 0
doc/prod/run.sh

@@ -0,0 +1 @@
+nohup java -jar /data1/s130/alarm/alarm-1.2-exec.jar >/dev/null 2>&1 &

+ 5 - 0
doc/prod/stop.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+for i in $(ps -ef | grep alarm-1.2-exec.jar | grep -v grep | awk '{print $2}'); do
+  kill -9 "$i"
+done

+ 21 - 0
doc/test/gpload/alarm.sh

@@ -0,0 +1,21 @@
+#!/bin/bash
+
+source /usr/local/greenplum-db-clients/greenplum_loaders_path.sh
+
+new_date=$1
+
+# 修改gpload配置文件
+sed -i 's/\/data1\/s130\/alarm\/csv\/resultMap[0-9]\{14\}.csv/\/data1\/s130\/alarm\/csv\/resultMap'${new_date}'.csv/' /data1/s130/alarm/gpload/alarm.yml
+
+# 由于gpload需要输入密码,这里需要使用expect执行
+password=Richr00t#
+
+expect -c "
+set timeout 300
+spawn gpload -f /data1/s130/alarm/gpload/alarm.yml
+expect {
+\"connecting (yes/no)?\" { send \"yes\n\";exp_continue }
+\"Password:\" { send \"${password}\n\"; exp_continue}
+timeout { puts \"超时\" exit 2}
+}
+"

+ 79 - 0
doc/test/gpload/alarm.yml

@@ -0,0 +1,79 @@
+VERSION: 1.0.0.1
+DATABASE: sqmmt
+USER: sqmdb
+HOST: 192.168.50.5
+PORT: 5432
+GPLOAD:
+  INPUT:
+    - SOURCE:
+        LOCAL_HOSTNAME:
+          - 192.168.50.3
+        PORT: 54321
+        FILE:
+          - /data1/s130/alarm/csv/resultMap20220628132304.csv
+    - FORMAT: csv
+    - DELIMITER: ","
+    - HEADER: false
+    - ENCODING: utf-8
+    - ERROR_LIMIT: 20000000
+    - LOG_ERRORS: true
+  EXTERNAL:
+    - SCHEMA: tsfx
+  OUTPUT:
+    - TABLE: tsfx.dw_complain_realtime_alarm_h
+    - MODE: merge
+    - MATCH_COLUMNS:
+        - uniqueid
+        - sdate
+    - UPDATE_COLUMNS:
+        - sdate
+        - uniqueclearid
+        - eventtime
+        - canceltime
+        - status
+        - projectstatus
+        - vendoralarmserial
+        - alarmtitle
+        - vendorseverity
+        - vendoralarmtype
+        - specificproblem
+        - specificproblemid
+        - equipmentclass
+        - equipmentname
+        - locateneclass
+        - locatenename
+        - province
+        - region
+        - city
+        - grid
+        - area
+        - vendor
+        - specialty
+        - siteid
+        - roomid
+        - towersiteno
+        - proequipmentstatus
+        - projectname
+        - projectno
+        - projectstarttime
+        - projectendtime
+        - worksendstatus
+        - workstatus
+        - workno
+        - workarchivedtime
+        - workdutydep
+        - worksendperson
+        - alarmlogicclass
+        - alarmlogicsubclass
+        - standardalarmname
+        - alarmseverity
+        - standardalarmid
+        - effectonequipment
+        - effectonbusiness
+        - standardflag
+        - networktype
+        - equipmentdn
+        - locatenedn
+        - taccode
+        - tacid
+        - alarmtext

+ 1 - 0
doc/test/run.sh

@@ -0,0 +1 @@
+nohup java -jar /data1/s130/alarm/alarm-1.2-exec.jar >/dev/null 2>&1 &

+ 5 - 0
doc/test/stop.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+for i in $(ps -ef | grep alarm-1.2-exec.jar | grep -v grep | awk '{print $2}'); do
+  kill -9 "$i"
+done

+ 43 - 15
src/main/java/com/nokia/alarm/service/AlarmSaveToFileService.java

@@ -1,12 +1,5 @@
 package com.nokia.alarm.service;
 
-import java.io.IOException;
-import java.util.Date;
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
 import com.alibaba.fastjson.JSON;
 import com.hl.opnc.AbilityResponse;
 import com.hl.opnc.ResponseBody;
@@ -17,8 +10,13 @@ import com.nokia.alarm.entity.ResultInfo;
 import com.nokia.alarm.entity.ResultMap;
 import com.nokia.alarm.util.ExportUtil;
 import com.nokia.alarm.util.SDKUtil;
-
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
 
 @Slf4j
 @Service
@@ -36,11 +34,26 @@ public class AlarmSaveToFileService {
         MessageCfg cfg = SDKUtil.getBody(date);
         AbilityResponse response = manager.post(methodUrl, null, JSON.toJSONString(cfg));
         try {
-            ResponseBody resObj = response.getRespObj();
+            String responseStr = response.getRespStr();
+            ResponseBody resObj;
+            try {
+                resObj = JSON.parseObject(responseStr, ResponseBody.class);
+            } catch (Exception e) {
+                log.error("返回消息json解析错误: {}", responseStr);
+                e.printStackTrace();
+                return;
+            }
             String body = (String) resObj.getUNI_NET_BODY();
-            log.info(body);
+//            log.info(body);
             // body = body.replace("null", "\"\"");
-            ResultInfo info = JSON.parseObject(body, ResultInfo.class);
+            ResultInfo info;
+            try {
+                info = JSON.parseObject(body, ResultInfo.class);
+            } catch (Exception e) {
+                log.error("返回消息json解析错误: {}", responseStr);
+                e.printStackTrace();
+                return;
+            }
             int rows = info.getTotal();
             log.info("新增告警返回数据{}条", rows);
             List<ResultMap> results = info.getResult();
@@ -57,7 +70,7 @@ public class AlarmSaveToFileService {
                 log.error("新增告警gpload失败: {}", e.getMessage());
             }
             log.info("查询新增告警完成=====================================================");
-        } catch (IOException e) {
+        } catch (Exception e) {
             log.info("查询新增告警出错=====================================================");
             e.printStackTrace();
         } finally {
@@ -76,10 +89,25 @@ public class AlarmSaveToFileService {
         MessageCfg cfg = SDKUtil.gethistoryBody(date);
         AbilityResponse response = manager.post(methodUrl, null, JSON.toJSONString(cfg));
         try {
-            ResponseBody resObj = response.getRespObj();
+            String responseStr = response.getRespStr();
+            ResponseBody resObj;
+            try {
+                resObj = JSON.parseObject(responseStr, ResponseBody.class);
+            } catch (Exception e) {
+                log.error("返回消息json解析错误: {}", responseStr);
+                e.printStackTrace();
+                return;
+            }
             String body = (String) resObj.getUNI_NET_BODY();
             // body = body.replace("null", "\"\"");
-            ResultInfo info = JSON.parseObject(body, ResultInfo.class);
+            ResultInfo info;
+            try {
+                info = JSON.parseObject(body, ResultInfo.class);
+            } catch (Exception e) {
+                log.error("返回消息json解析错误: {}", responseStr);
+                e.printStackTrace();
+                return;
+            }
             int rows = info.getTotal();
             log.info("消除告警返回数据{}条", rows);
             List<ResultMap> results = info.getResult();
@@ -96,7 +124,7 @@ public class AlarmSaveToFileService {
                 log.error("消除告警gpload失败: {}", e.getMessage());
             }
             log.info("查询消除告警完成=====================================================");
-        } catch (IOException e) {
+        } catch (Exception e) {
             log.info("查询消除告警出错=====================================================");
             e.printStackTrace();
         }

+ 23 - 0
src/main/resources/application-prod.properties

@@ -0,0 +1,23 @@
+server.port=8081
+
+# # 本地postgresql
+# spring.datasource.driverClassName=org.postgresql.Driver
+# spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
+# spring.datasource.username=postgres
+# spring.datasource.password=fantuan
+
+# 70.109 GreenPlum数据库
+spring.datasource.driverClassName=org.postgresql.Driver
+spring.datasource.url=jdbc:postgresql://192.168.70.109:5432/sqmmt
+spring.datasource.username=sqmdb
+spring.datasource.password=sqmdb_1QAZ
+
+# log配置
+logging.level.com.nokia=info
+# logging.file.name=log/alarm.log
+# logging.charset.file=utf-8
+# logging.charset.console=utf-8
+
+httpurl=http://192.168.70.125:12090/esb/HEB_AlarmCustomQuery/0?authcode=SEVCX1VDSUFQI0BhdXRoQCNTWnFsVk9QeA
+
+# httpurl=http://10.160.84.7:8888/esb/HEB_AlarmCustomQuery/0?authcode=SEVCX1VDSUFQI0BhdXRoQCNTWnFsVk9QeA

+ 23 - 0
src/main/resources/application-test.properties

@@ -0,0 +1,23 @@
+server.port=8081
+
+# # 本地postgresql
+# spring.datasource.driverClassName=org.postgresql.Driver
+# spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
+# spring.datasource.username=postgres
+# spring.datasource.password=fantuan
+
+# 70.109 GreenPlum数据库
+spring.datasource.driverClassName=org.postgresql.Driver
+spring.datasource.url=jdbc:postgresql://192.168.50.5:5432/sqmmt
+spring.datasource.username=sqmdb
+spring.datasource.password=sqmdb_1QAZ
+
+# log配置
+logging.level.com.nokia=info
+# logging.file.name=log/alarm.log
+# logging.charset.file=utf-8
+# logging.charset.console=utf-8
+
+httpurl=http://192.168.70.125:12090/esb/HEB_AlarmCustomQuery/0?authcode=SEVCX1VDSUFQI0BhdXRoQCNTWnFsVk9QeA
+
+# httpurl=http://10.160.84.7:8888/esb/HEB_AlarmCustomQuery/0?authcode=SEVCX1VDSUFQI0BhdXRoQCNTWnFsVk9QeA

+ 2 - 1
src/main/resources/application.properties

@@ -1,4 +1,5 @@
-sever.port=8081
+server.port=8081
+spring.profiles.active=prod
 
 # # 本地postgresql
 # spring.datasource.driverClassName=org.postgresql.Driver

+ 51 - 0
src/main/resources/logback-spring.xml

@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+    <property name="PATH" value="./log"/>
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <Pattern>%d{HH:mm:ss.SSS} %highlight(%-5level) %yellow(%X{traceId}) %cyan(%logger:%line) %msg%n</Pattern>
+        </encoder>
+    </appender>
+    <appender name="TRACE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${PATH}/trace.log</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+            <!-- rollover daily -->
+            <fileNamePattern>${PATH}/trace.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+            <!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
+            <maxFileSize>10MB</maxFileSize>
+            <maxHistory>60</maxHistory>
+            <totalSizeCap>20GB</totalSizeCap>
+        </rollingPolicy>
+        <encoder>
+            <Pattern>%d %highlight(%-5level) %yellow(%X{traceId}) %cyan(%logger:%line) %msg%n</Pattern>
+        </encoder>
+    </appender>
+    <appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <file>${PATH}/error.log</file>
+        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+            <!-- rollover daily -->
+            <fileNamePattern>${PATH}/error.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
+            <!-- each file should be at most 100MB, keep 60 days worth of history, but at most 20GB -->
+            <maxFileSize>10MB</maxFileSize>
+            <maxHistory>60</maxHistory>
+            <totalSizeCap>20GB</totalSizeCap>
+        </rollingPolicy>
+        <encoder>
+            <Pattern>%d %highlight(%-5level) %yellow(%X{traceId}) %cyan(%logger:%line) %msg%n</Pattern>
+        </encoder>
+        <filter class="ch.qos.logback.classic.filter.LevelFilter">
+            <level>ERROR</level>
+            <onMatch>ACCEPT</onMatch>
+            <onMismatch>DENY</onMismatch>
+        </filter>
+    </appender>
+    <root level="INFO">
+        <appender-ref ref="STDOUT"/>
+    </root>
+    <root level="TRACE">
+        <appender-ref ref="TRACE_FILE"/>
+    </root>
+    <root level="ERROR">
+        <appender-ref ref="ERROR_FILE"/>
+    </root>
+</configuration>