解决修改序列化方式之后产生的null值问题

This commit is contained in:
wangkuan
2024-08-09 18:23:27 +08:00
parent 2d0dcf89e3
commit c08b94fec2
6 changed files with 25 additions and 19 deletions

11
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.zdjizhi</groupId>
<artifactId>flink-dos-detection</artifactId>
<version>24-07-25</version>
<version>24-08-07</version>
<name>flink-dos-detection</name>
<url>http://www.example.com</url>
@@ -80,7 +80,7 @@
</goals>
<configuration>
<finalName>flink-dos-detection-24-07-25</finalName>
<finalName>flink-dos-detection-24-08-07</finalName>
<relocations>
<relocation>
<pattern>org.apache.http</pattern>
@@ -134,7 +134,12 @@
</build>
<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.12</artifactId>
<version>${flink.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>

View File

@@ -244,7 +244,7 @@ public class DosSketchLog implements Serializable {
}
public int getRule_id() {
public int getRule_id() {
return rule_id;
}

View File

@@ -58,7 +58,10 @@ public class DosMetricsRichFunction extends RichFlatMapFunction<DosSketchLog, St
}
private int getPartitionNumByIp(String destinationIp) {
return Math.abs(destinationIp.hashCode()) % configuration.get(DESTINATION_IP_PARTITION_NUM);
if(destinationIp!=null){
return Math.abs(destinationIp.hashCode()) % configuration.get(DESTINATION_IP_PARTITION_NUM);
}
return 0;
}
}

View File

@@ -24,13 +24,20 @@ public class FlatSketchFunction implements FlatMapFunction<String, DosSketchLog>
DosSketchLog dosSketchLog = JSONObject.parseObject(value, DosSketchLog.class);
dosSketchLog.setRecv_time(System.currentTimeMillis()/1000);
dosSketchLog.setStart_timestamp_ms(dosSketchLog.getTimestamp_ms());
if(dosSketchLog.getDuration()<=0){
dosSketchLog.setDuration(60000);
}
dosSketchLog.setEnd_timestamp_ms(dosSketchLog.getTimestamp_ms() + dosSketchLog.getDuration());
HashSet<String> client_ips = new HashSet<>();
HashSet<String> client_countrys = new HashSet<>();
dosSketchLog.setClient_ips(client_ips);
dosSketchLog.setClient_countrys(client_countrys);
if("top_client_and_server_ip".equals(dosSketchLog.getName())){
client_ips.add(dosSketchLog.getClient_ip());
dosSketchLog.setDecoded_as("");
if(dosSketchLog.getClient_ip()!=null) {
client_ips.add(dosSketchLog.getClient_ip());
}
if(dosSketchLog.getClient_country()!=null && !dosSketchLog.getClient_country().isEmpty()) {
client_countrys.add(dosSketchLog.getClient_country());
}
@@ -39,7 +46,9 @@ public class FlatSketchFunction implements FlatMapFunction<String, DosSketchLog>
dosSketchLog.setPkts(0);
dosSketchLog.setBytes(0);
dosSketchLog.setSessions(0);
client_ips.add(dosSketchLog.getClient_ip());
if(dosSketchLog.getClient_ip()!=null) {
client_ips.add(dosSketchLog.getClient_ip());
}
if(dosSketchLog.getClient_country()!=null && !dosSketchLog.getClient_country().isEmpty()) {
client_countrys.add(dosSketchLog.getClient_country());
}

View File

@@ -45,7 +45,7 @@ public class MetricsCalculate extends ProcessWindowFunction<
dosSketchLog.setSession_rate(dosSketchLog.getSessions()/ (duration/1000) );
dosSketchLog.setPacket_rate(dosSketchLog.getPkts()/(duration/1000));
dosSketchLog.setBit_rate(dosSketchLog.getBytes()*8/(duration/1000));
dosSketchLog.setAttack_type(attackTypeMapping.getOrDefault(dosSketchLog.getDecoded_as(),""));
dosSketchLog.setAttack_type(attackTypeMapping.get(dosSketchLog.getDecoded_as()));
}catch (RuntimeException e){
logger.error(e.toString());
}

View File

@@ -1,11 +0,0 @@
package com.zdjizhi.etl;
import org.junit.Test;
public class EtlProcessFunctionTest {
@Test
public void EtlProcessFunctionTest(){
}
}