Browse Source

feat: m_downtilt和e_downtilt为null时默认0,添加超时控制

weijianghai 2 years ago
parent
commit
5da2f37a6d

+ 0 - 3
build-dir/prod/run.sh

@@ -1,3 +0,0 @@
-#!/bin/bash
-
-nohup java -jar /data/site_info/site_info.jar >/dev/null 2>&1 &

+ 0 - 5
build-dir/prod/stop.sh

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

+ 3 - 0
build-dir/run.sh

@@ -0,0 +1,3 @@
+#!/bin/bash
+
+nohup java -jar site_info.jar >/dev/null 2>&1 &

+ 5 - 0
build-dir/stop.sh

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+for i in $(pgrep -f site_info.jar); do
+  kill -9 "$i"
+done

+ 0 - 3
build-dir/test/run.sh

@@ -1,3 +0,0 @@
-#!/bin/bash
-
-nohup java -jar /data1/site_info/site_info.jar >/dev/null 2>&1 &

+ 0 - 5
build-dir/test/stop.sh

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

+ 14 - 5
pom.xml

@@ -3,10 +3,10 @@
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
     <parent>
-        <groupId>com.nokia</groupId>
-        <artifactId>hb_springboot_parent</artifactId>
-        <version>1.0</version>
-        <relativePath/>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.6.14</version>
+        <relativePath/> <!-- lookup parent from repository -->
     </parent>
     <artifactId>siteinfo</artifactId>
     <version>0.0.1-SNAPSHOT</version>
@@ -14,8 +14,10 @@
     <description>siteinfo_update</description>
     <properties>
         <java.version>8</java.version>
+        <maven.compiler.source>${java.version}</maven.compiler.source>
+        <maven.compiler.target>${java.version}</maven.compiler.target>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <project.reporting.outputEncoding>${project.build.sourceEncoding}</project.reporting.outputEncoding>
         <skipTests>true</skipTests>
     </properties>
     <dependencies>
@@ -34,6 +36,11 @@
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>
@@ -44,9 +51,11 @@
             <artifactId>xxl-job-core</artifactId>
             <version>2.3.0</version>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-csv -->
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-csv</artifactId>
+            <version>1.9.0</version>
         </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 42 - 15
src/main/java/com/nokia/siteinfo/task/UpdateTask.java

@@ -4,10 +4,11 @@ import com.nokia.common.gpload.GploadUtil;
 import com.nokia.common.gpload.entity.GploadResult;
 import com.xxl.job.core.context.XxlJobHelper;
 import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.csv.CSVFormat;
 import org.apache.commons.csv.CSVPrinter;
-import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Component;
 
@@ -22,12 +23,19 @@ import java.time.format.DateTimeFormatter;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 
+@ConfigurationProperties("task")
+@Data
 @Component
 @Slf4j
 public class UpdateTask {
-    @Value("${gpload.shell.path}")
     private String gploadShellPath;
+    /**
+     * 超时分钟
+     */
+    private Long timeout;
 
     private final JdbcTemplate inputJdbcTemplate;
     private final JdbcTemplate outputJdbcTemplate;
@@ -37,20 +45,22 @@ public class UpdateTask {
         this.outputJdbcTemplate = outputJdbcTemplate;
     }
 
-//    0 0 1 ? * 2
+    //    0 0 1 ? * 2
     @XxlJob("siteInfoJobHandler")
     public void siteInfoJobHandler() {
         try {
-            Map<Object, Object> siteLevelMap = getSiteLevelMap();
-            Map<String, Map<String, Object>> four = new HashMap<>();
-            Map<String, Map<String, Object>> five = new HashMap<>();
-            update4g(four);
-            update5g(five);
-            writeCsvs(four, five, siteLevelMap);
-            backup("customer_service.cfg_p_netconf_std");
-            gpload("customer_service.cfg_p_netconf_std");
-            backup("customer_service.cfg_cell_info");
-            gpload("customer_service.cfg_cell_info");
+            CompletableFuture.runAsync(() -> {
+                try {
+                    singleTask();
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }).get(timeout, TimeUnit.MINUTES);
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e.getMessage(), e);
+            XxlJobHelper.log("线程中断: {}", e.getMessage(), e);
+            Thread.currentThread().interrupt();
+            throw new RuntimeException(e);
         } catch (Exception e) {
             log.error("发生异常了: {}", e.getMessage(), e);
             XxlJobHelper.log("发生异常了: {}", e.getMessage(), e);
@@ -58,6 +68,19 @@ public class UpdateTask {
         }
     }
 
+    private void singleTask() throws IOException {
+        Map<Object, Object> siteLevelMap = getSiteLevelMap();
+        Map<String, Map<String, Object>> four = new HashMap<>();
+        Map<String, Map<String, Object>> five = new HashMap<>();
+        update4g(four);
+        update5g(five);
+        writeCsvs(four, five, siteLevelMap);
+        backup("customer_service.cfg_p_netconf_std");
+        gpload("customer_service.cfg_p_netconf_std");
+        backup("customer_service.cfg_cell_info");
+        gpload("customer_service.cfg_cell_info");
+    }
+
     private Map<Object, Object> getSiteLevelMap() {
         Map<Object, Object> siteLevelMap = new HashMap<>();
         String sql = "select * from cfm.cfg_0_4g_sitelevel";
@@ -179,7 +202,9 @@ public class UpdateTask {
             m.put("latitude", t.get("lat"));
             m.put("vendor", t.get("vender"));
             m.put("height", t.get("height"));
-            m.put("downtilt", ((BigDecimal) t.get("m_downtilt")).add((BigDecimal) t.get("e_downtilt")));
+            BigDecimal m_downtilt = t.get("m_downtilt") == null ? BigDecimal.ZERO : (BigDecimal) t.get("m_downtilt");
+            BigDecimal e_downtilt = t.get("e_downtilt") == null ? BigDecimal.ZERO : (BigDecimal) t.get("e_downtilt");
+            m.put("downtilt", m_downtilt.add(e_downtilt));
             m.put("azimuth", t.get("direction"));
             m.put("fr", t.get("down_freq"));
             m.put("scramber", "");
@@ -234,7 +259,9 @@ public class UpdateTask {
             m.put("latitude", t.get("lat"));
             m.put("vendor", t.get("vender"));
             m.put("height", t.get("height"));
-            m.put("downtilt", ((BigDecimal) t.get("m_downtilt")).add((BigDecimal) t.get("e_downtilt")));
+            BigDecimal m_downtilt = t.get("m_downtilt") == null ? BigDecimal.ZERO : (BigDecimal) t.get("m_downtilt");
+            BigDecimal e_downtilt = t.get("e_downtilt") == null ? BigDecimal.ZERO : (BigDecimal) t.get("e_downtilt");
+            m.put("downtilt", m_downtilt.add(e_downtilt));
             m.put("azimuth", t.get("direction"));
             m.put("fr", t.get("down_freq"));
             m.put("scramber", "");

+ 4 - 2
src/main/resources/application-prod.properties

@@ -1,5 +1,6 @@
 server.port=12093
 spring.application.name=siteinfo_update
+logging.level.root=info
 spring.datasource.input.jdbc-url=jdbc:postgresql://192.168.10.9:5432/sqmmt
 spring.datasource.input.username=pmparse
 spring.datasource.input.password=Richr00t#
@@ -21,8 +22,9 @@ xxl.job.executor.address=
 xxl.job.executor.ip=
 xxl.job.executor.port=9999
 ### xxl-job executor log-path
-xxl.job.executor.logpath=/data/site_info/xxl/
+xxl.job.executor.logpath=./log/xxl/
 ### xxl-job executor log-retention-days
 xxl.job.executor.logretentiondays=30
 
-gpload.shell.path=/data/site_info/gpload/gpload.sh
+task.gpload-shell-path=/data/site_info/gpload/gpload.sh
+task.timeout=5

+ 4 - 2
src/main/resources/application-test.properties

@@ -1,5 +1,6 @@
 server.port=12093
 spring.application.name=siteinfo_update
+logging.level.com.nokia=debug
 spring.datasource.input.jdbc-url=jdbc:postgresql://192.168.10.9:5432/sqmmt
 spring.datasource.input.username=pmparse
 spring.datasource.input.password=Richr00t#
@@ -21,8 +22,9 @@ xxl.job.executor.address=
 xxl.job.executor.ip=
 xxl.job.executor.port=9999
 ### xxl-job executor log-path
-xxl.job.executor.logpath=/data1/site_info/xxl/
+xxl.job.executor.logpath=./log/xxl/
 ### xxl-job executor log-retention-days
 xxl.job.executor.logretentiondays=30
 
-gpload.shell.path=/data1/site_info/gpload/gpload.sh
+task.gpload-shell-path=/data1/site_info/gpload/gpload.sh
+task.timeout=5

+ 0 - 29
src/main/resources/application.properties

@@ -1,30 +1 @@
 spring.profiles.active=prod
-logging.level.root=info
-server.port=12093
-spring.application.name=siteinfo_update
-spring.datasource.input.jdbc-url=jdbc:postgresql://192.168.10.9:5432/sqmmt
-spring.datasource.input.username=pmparse
-spring.datasource.input.password=Richr00t#
-spring.datasource.input.driverClassName=org.postgresql.Driver
-
-spring.datasource.output.jdbc-url=jdbc:postgresql://192.168.50.5:5432/sqmmt
-spring.datasource.output.username=sqmdb
-spring.datasource.output.password=sqmdb_1QAZ
-spring.datasource.output.driverClassName=org.postgresql.Driver
-### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
-xxl.job.admin.addresses=http://192.168.10.7:8087/xxl-job-admin
-### xxl-job, access token
-xxl.job.accessToken=
-### xxl-job executor appname
-xxl.job.executor.appname=site-info
-### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
-xxl.job.executor.address=
-### xxl-job executor server-info
-xxl.job.executor.ip=
-xxl.job.executor.port=9999
-### xxl-job executor log-path
-xxl.job.executor.logpath=/data/site_info/xxl/
-### xxl-job executor log-retention-days
-xxl.job.executor.logretentiondays=30
-
-gpload.shell.path=/data/site_info/gpload/gpload.sh

+ 2 - 0
src/test/java/com/nokia/siteinfo/SiteinfoUpdateApplicationTests.java

@@ -5,7 +5,9 @@ import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
 
+@ActiveProfiles("test")
 @Slf4j
 @SpringBootTest
 class SiteinfoUpdateApplicationTests {