mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 22:43:18 +02:00
fix: anomaly detector breaking
This commit is contained in:
parent
4b3f12627d
commit
be94f2dd00
@ -3,6 +3,10 @@ package com.anomaly.detector;
|
|||||||
import com.anomaly.model.Transaction;
|
import com.anomaly.model.Transaction;
|
||||||
import com.anomaly.model.TransactionAlert;
|
import com.anomaly.model.TransactionAlert;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
import org.apache.flink.api.common.functions.MapFunction;
|
import org.apache.flink.api.common.functions.MapFunction;
|
||||||
import org.apache.flink.api.common.serialization.SimpleStringSchema;
|
import org.apache.flink.api.common.serialization.SimpleStringSchema;
|
||||||
import org.apache.flink.connector.base.DeliveryGuarantee;
|
import org.apache.flink.connector.base.DeliveryGuarantee;
|
||||||
@ -20,13 +24,35 @@ import org.apache.flink.util.Collector;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class AnomalyDetector {
|
public class AnomalyDetector {
|
||||||
|
|
||||||
private static final String INPUT_TOPIC = "transactions";
|
private static final String INPUT_TOPIC = "transactions";
|
||||||
private static final String OUTPUT_TOPIC = "alerts";
|
private static final String OUTPUT_TOPIC = "alerts";
|
||||||
private static final String BOOTSTRAP_SERVERS = "localhost:9092";
|
private static final String BOOTSTRAP_SERVERS = "localhost:9092";
|
||||||
private static final Gson gson = new Gson();
|
|
||||||
|
// Replace the simple Gson initialization with a configured one
|
||||||
|
private static final Gson gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Instant.class, new InstantTypeAdapter())
|
||||||
|
.create();
|
||||||
|
|
||||||
|
// Add a custom TypeAdapter for Instant
|
||||||
|
private static class InstantTypeAdapter extends TypeAdapter<Instant> {
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, Instant value) throws IOException {
|
||||||
|
if (value == null) {
|
||||||
|
out.nullValue();
|
||||||
|
} else {
|
||||||
|
out.value(value.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Instant read(JsonReader in) throws IOException {
|
||||||
|
return Instant.parse(in.nextString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Set up the execution environment
|
// Set up the execution environment
|
||||||
|
|||||||
@ -34,28 +34,28 @@ echo "Starting all applications..."
|
|||||||
# Start Flink job (Anomaly Detector)
|
# Start Flink job (Anomaly Detector)
|
||||||
echo "Starting Anomaly Detector..."
|
echo "Starting Anomaly Detector..."
|
||||||
cd anomaly-detector
|
cd anomaly-detector
|
||||||
java -jar target/anomaly-detector-1.0-SNAPSHOT.jar &
|
java --add-opens java.base/java.time=ALL-UNNAMED -jar target/anomaly-detector-1.0-SNAPSHOT.jar &
|
||||||
ANOMALY_PID=$!
|
ANOMALY_PID=$!
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
# Start Alert Visualizer
|
# Start Alert Visualizer
|
||||||
echo "Starting Alert Visualizer..."
|
echo "Starting Alert Visualizer..."
|
||||||
cd alarm-visualizer
|
cd alarm-visualizer
|
||||||
java -jar target/alarm-visualizer-1.0-SNAPSHOT.jar &
|
java --add-opens java.base/java.time=ALL-UNNAMED -jar target/alarm-visualizer-1.0-SNAPSHOT.jar &
|
||||||
ALARM_PID=$!
|
ALARM_PID=$!
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
# Start Transaction Consumer/Visualizer
|
# Start Transaction Consumer/Visualizer
|
||||||
echo "Starting Transaction Consumer..."
|
echo "Starting Transaction Consumer..."
|
||||||
cd kafka-consumer-visualizer
|
cd kafka-consumer-visualizer
|
||||||
java -jar target/kafka-consumer-visualizer-1.0-SNAPSHOT.jar &
|
java --add-opens java.base/java.time=ALL-UNNAMED -jar target/kafka-consumer-visualizer-1.0-SNAPSHOT.jar &
|
||||||
CONSUMER_PID=$!
|
CONSUMER_PID=$!
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
# Start Transaction Producer last
|
# Start Transaction Producer last
|
||||||
echo "Starting Transaction Producer..."
|
echo "Starting Transaction Producer..."
|
||||||
cd transaction-simulator
|
cd transaction-simulator
|
||||||
java -jar target/transaction-simulator-1.0-SNAPSHOT.jar &
|
java --add-opens java.base/java.time=ALL-UNNAMED -jar target/transaction-simulator-1.0-SNAPSHOT.jar &
|
||||||
PRODUCER_PID=$!
|
PRODUCER_PID=$!
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user