From 4ec762fd6046e5b22742a4ebf10a5ebe88a89ad8 Mon Sep 17 00:00:00 2001 From: Andreas Tsagkaropoulos Date: Thu, 23 Nov 2023 14:02:52 +0200 Subject: [PATCH] Improvement of README file, and miscellaneous code improvements Removal of unnecessary code to improve legibility Introduction of new class for the Director subcomponent to allow defining functionality specific to it Improvement of code organization Additions to README file to enable better code understading and provide a high-level overview of the operational phases of SLOViD Change-Id: Ie52de0a2446f376f7612473a69e9a0eae10e5c80 --- slo-violation-detector/README.md | 37 ++++++++++++++++++- .../main/java/configuration/Constants.java | 3 +- .../AttributeSubscription.java | 4 +- .../java/runtime/DetectorRequestMappings.java | 6 +-- .../java/runtime/DirectorRequestMappings.java | 2 +- .../src/main/java/runtime/Main.java | 12 ++++-- .../main/java/slo_rule_modelling/SLORule.java | 2 +- .../java/slo_rule_modelling/SLOSubRule.java | 2 +- .../DirectorSubcomponent.java | 19 ---------- .../{ => detector}/DetectorSubcomponent.java | 9 +++-- .../DetectorSubcomponentState.java | 2 +- .../DetectorSubcomponentUtilities.java | 12 ++---- .../director/DirectorSubcomponent.java | 37 +++++++++++++++++++ .../generic}/Runnables.java | 34 ++++------------- .../SLOViolationDetectorStateUtils.java | 8 +--- .../SLOViolationDetectorSubcomponent.java | 2 +- .../java/utilities/DebugDataSubscription.java | 11 ++---- .../MonitoringAttributeUtilities.java | 3 +- .../java/utilities/OperationalModeUtils.java | 14 +++++++ .../utility_beans/CharacterizedThread.java | 6 +-- .../PredictedMonitoringAttribute.java | 3 +- .../RealtimeMonitoringAttribute.java | 2 +- .../java/DerivedMonitoringAttributeTests.java | 4 +- .../src/test/java/SeverityTests.java | 2 +- .../UnboundedMonitoringAttributeTests.java | 4 +- 25 files changed, 136 insertions(+), 104 deletions(-) delete mode 100644 slo-violation-detector/src/main/java/slo_violation_detector_engine/DirectorSubcomponent.java rename slo-violation-detector/src/main/java/slo_violation_detector_engine/{ => detector}/DetectorSubcomponent.java (94%) rename slo-violation-detector/src/main/java/slo_violation_detector_engine/{ => detector}/DetectorSubcomponentState.java (98%) rename slo-violation-detector/src/main/java/slo_violation_detector_engine/{ => detector}/DetectorSubcomponentUtilities.java (98%) create mode 100644 slo-violation-detector/src/main/java/slo_violation_detector_engine/director/DirectorSubcomponent.java rename slo-violation-detector/src/main/java/{processing_logic => slo_violation_detector_engine/generic}/Runnables.java (87%) rename slo-violation-detector/src/main/java/slo_violation_detector_engine/{ => generic}/SLOViolationDetectorStateUtils.java (86%) rename slo-violation-detector/src/main/java/slo_violation_detector_engine/{ => generic}/SLOViolationDetectorSubcomponent.java (78%) diff --git a/slo-violation-detector/README.md b/slo-violation-detector/README.md index 625cf42..a10d55c 100644 --- a/slo-violation-detector/README.md +++ b/slo-violation-detector/README.md @@ -4,7 +4,22 @@ The SLO Severity-based Violation Detector is a component which receives predicted and actual monitoring metric values, and produces AMQP messages which denote i) the calculated severity ii) the probability that a reconfiguration will be required and iii) the timestamp which we refer to. -The component can run either using a compiled jar file, or be packaged to a Docker container and run in containerized form. +The component can run either using a compiled jar file, or be packaged to a Docker container and run in containerized form. At a high level, the component runs through the following operational phases: + +Operational phases +----------------------- + +1. Initialization of generic execution parameters +2. Choice of operational mode (Detector or Director-Detector) +3. If the operational mode is Director-Detector then the following steps are carried out: + - Initialization of the subscription to the topics the Director-Detector is responsible for +4. If the operational mode is Detector then the following steps are carried out: + - Initialization of the internal structures representing the SLO rules and the monitoring metrics + - Subscription to metric_list topic and initialization of new subscribers based on initial message + - Subscription to topic_for_lost_device_announcement + - Continuous calculation of Severity based on incoming realtime and predicted metrics, and creation of severity output messages when relevant input has been received + - Continuous monitoring of reconfiguration statistics and adaptation of the behaviour of the component as appropriate + ## Configuration @@ -142,8 +157,28 @@ To illustrate, in the case that an SLO message identical to the simple SLO examp ### Development +#### General Remarks + Starting new threads in the SLO Violation Detection component should only be done using the CharacterizedThread class, as opposed to using plain Threads - to reassure that Threads are being defined in a way which permits their appropriate management (registration/removal). +#### Internal structure + +Execution in the SLO Violation Detector component begins at the Main class, part of the `runtime` package inside the src/main/java folder. Immediately, following some basic initializations the character of the program is determined - either Director-Detector or simple Detector - and then the relevant subcomponents are initialized. If the component is initialized as a Director-Detector, it will also have some active Spring Boot endpoints using which, it will be able to listen to incoming requests and provide information. The way this information is provided, is detailed in the Director and the Detector RequestMapping classes inside the `runtime` package. + +Generic constants which should be available throughout the program, are included in the `Constants` class inside the `configuration` package. + +The `metric_retrieval` package includes the AttributeSubscription class which manages the subscription to all metrics (or attributes) which are included in a particular SLO rule. + +The `slo_rule_modelling` package includes classes which are important to setup the methods in which Severity calculations are described for different kinds of rules. Inside it are the important SLORule and SLOSubRule classes. +The heart of the SLO Violation Detector is inside the `slo_violation_detector_engine` package, which contains the specific subcomponent classes which describe the behaviour of the two subcomponents of the SLOViD: the Director and the Detector. Also, the `Runnables` class inside it, contains the all runnables and runnable-like classes which do not tightly belong to their surrounding code. Classes are organized in three sub-packages: the `director`, `detector`, and `generic` sub-packages, which include classes specific to the director subcomponent, the detector subcomponent and all subcomponents, respectively. + +The `utilities` subpackage contains miscellaneous utility classes which undertake miscellaneous tasks, including the SLOViolationCalculator class which performs the actual severity calculations. Similarly, the `utility_beans` package contains classes designed to model individual aspects of the behaviour of the component. + + +The `src/main/resources` folder contains files which are either used at runtime to fetch resources necessary for the proper execution of the program, or files which help with the testing of the component. Most notable are the property files under the config folder which directly impact the behaviour of the program, and the application.properties file which include parameters which regulate the execution of the Spring Boot part of the component (if a director component is spawned). + +The `src/test` folder contains miscellaneous tests which are useful to verify the correct behaviour of the component. + ### Docker container build diff --git a/slo-violation-detector/src/main/java/configuration/Constants.java b/slo-violation-detector/src/main/java/configuration/Constants.java index 3e06d61..457a14a 100644 --- a/slo-violation-detector/src/main/java/configuration/Constants.java +++ b/slo-violation-detector/src/main/java/configuration/Constants.java @@ -9,8 +9,8 @@ package configuration; import java.net.URI; +import java.util.ArrayList; import java.util.logging.Level; - public class Constants { //String constants @@ -31,6 +31,7 @@ public class Constants { public static String topic_for_lost_device_announcement = "eu.nebulouscloud.device_lost"; public static String slo_rules_topic = "eu.nebulouscloud.monitoring.slo.new"; public static String metric_list_topic = "eu.nebulouscloud.monitoring.metric_list"; + public static ArrayList director_subscription_topics; public static double slo_violation_probability_threshold = 0.5; //The threshold over which the probability of a predicted slo violation should be to have a violation detection public static int kept_values_per_metric = 5; //Default to be overriden from the configuration file. This indicates how many metric values are kept to calculate the "previous" metric value during the rate of change calculation public static String roc_calculation_mode = "prototype"; diff --git a/slo-violation-detector/src/main/java/metric_retrieval/AttributeSubscription.java b/slo-violation-detector/src/main/java/metric_retrieval/AttributeSubscription.java index c6f4e87..a2e694a 100644 --- a/slo-violation-detector/src/main/java/metric_retrieval/AttributeSubscription.java +++ b/slo-violation-detector/src/main/java/metric_retrieval/AttributeSubscription.java @@ -11,7 +11,7 @@ package metric_retrieval; //import eu.melodic.event.brokerclient.BrokerSubscriber; //import eu.melodic.event.brokerclient.templates.EventFields; //import eu.melodic.event.brokerclient.templates.TopicNames; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utility_beans.BrokerSubscriber; import utility_beans.BrokerSubscriber.EventFields; import utility_beans.BrokerSubscriber.TopicNames; @@ -31,8 +31,6 @@ import java.util.function.BiFunction; import java.util.logging.Logger; import static configuration.Constants.*; -import static slo_violation_detector_engine.SLOViolationDetectorStateUtils.*; -import static utility_beans.CharacterizedThread.CharacterizedThreadType.slo_bound_running_thread; import static utility_beans.PredictedMonitoringAttribute.getPredicted_monitoring_attributes; import static utility_beans.RealtimeMonitoringAttribute.update_monitoring_attribute_value; diff --git a/slo-violation-detector/src/main/java/runtime/DetectorRequestMappings.java b/slo-violation-detector/src/main/java/runtime/DetectorRequestMappings.java index 367bded..e0f2f59 100644 --- a/slo-violation-detector/src/main/java/runtime/DetectorRequestMappings.java +++ b/slo-violation-detector/src/main/java/runtime/DetectorRequestMappings.java @@ -1,13 +1,11 @@ package runtime; import org.springframework.web.bind.annotation.*; -import slo_violation_detector_engine.DetectorSubcomponent; - -import java.io.IOException; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import static configuration.Constants.default_handled_application_name; import static runtime.Main.detectors; -import static slo_violation_detector_engine.DetectorSubcomponent.detector_integer_id; +import static slo_violation_detector_engine.detector.DetectorSubcomponent.detector_integer_id; import static utilities.DebugDataSubscription.debug_data_generation; import static utility_beans.CharacterizedThread.CharacterizedThreadRunMode.detached; @RestController diff --git a/slo-violation-detector/src/main/java/runtime/DirectorRequestMappings.java b/slo-violation-detector/src/main/java/runtime/DirectorRequestMappings.java index d23a23f..b23dde8 100644 --- a/slo-violation-detector/src/main/java/runtime/DirectorRequestMappings.java +++ b/slo-violation-detector/src/main/java/runtime/DirectorRequestMappings.java @@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utility_beans.CharacterizedThread; import utility_beans.RealtimeMonitoringAttribute; diff --git a/slo-violation-detector/src/main/java/runtime/Main.java b/slo-violation-detector/src/main/java/runtime/Main.java index 665e3ef..6262958 100644 --- a/slo-violation-detector/src/main/java/runtime/Main.java +++ b/slo-violation-detector/src/main/java/runtime/Main.java @@ -12,7 +12,8 @@ package runtime; //import eu.melodic.event.brokerclient.BrokerSubscriber; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; +import slo_violation_detector_engine.director.DirectorSubcomponent; import utility_beans.*; import java.io.IOException; @@ -24,7 +25,8 @@ import static configuration.Constants.*; import static java.util.logging.Level.INFO; import static utilities.OperationalModeUtils.getSLOViolationDetectionOperationalMode; -import static slo_violation_detector_engine.SLOViolationDetectorStateUtils.*; +import static slo_violation_detector_engine.generic.SLOViolationDetectorStateUtils.*; +import static utilities.OperationalModeUtils.get_director_subscription_topics; import static utility_beans.CharacterizedThread.CharacterizedThreadRunMode.detached; @@ -70,17 +72,19 @@ public class Main { slo_violation_probability_threshold = Double.parseDouble(prop.getProperty("slo_violation_probability_threshold")); slo_violation_determination_method = prop.getProperty("slo_violation_determination_method"); maximum_acceptable_forward_predictions = Integer.parseInt(prop.getProperty("maximum_acceptable_forward_predictions")); + director_subscription_topics = get_director_subscription_topics(); DetectorSubcomponent detector = new DetectorSubcomponent(default_handled_application_name,detached); detectors.add(detector); ArrayList unbounded_metric_strings = new ArrayList<>(Arrays.asList(prop.getProperty("metrics_bounds").split(","))); for (String metric_string : unbounded_metric_strings) { - detector.getSubcomponent_state().getMonitoring_attributes_bounds_representation().put(metric_string.split(";")[0], metric_string.split(";", 2)[1]); + detector.getSubcomponent_state().getMonitoring_attributes_bounds_representation().put(metric_string.split(";")[0], metric_string.split(";", 2)[1]); //TODO delete once this information is successfully received from the AMQP broker } } //initialization if (operational_mode.equals(OperationalMode.DETECTOR)) { - Logger.getAnonymousLogger().log(INFO,"Starting new Detector instance"); + Logger.getAnonymousLogger().log(INFO,"Starting new Detector instance"); //This detector instance has been already started in the initialization block above as it will be commonly needed both for the plain Detector and the Director-Detector }else if (operational_mode.equals(OperationalMode.DIRECTOR)){ Logger.getAnonymousLogger().log(INFO,"Starting new Director and new Detector instance"); + DirectorSubcomponent director = new DirectorSubcomponent(); SpringApplication.run(Main.class, args); Logger.getAnonymousLogger().log(INFO,"Execution completed"); } diff --git a/slo-violation-detector/src/main/java/slo_rule_modelling/SLORule.java b/slo-violation-detector/src/main/java/slo_rule_modelling/SLORule.java index 1e531cc..b344835 100644 --- a/slo-violation-detector/src/main/java/slo_rule_modelling/SLORule.java +++ b/slo-violation-detector/src/main/java/slo_rule_modelling/SLORule.java @@ -12,7 +12,7 @@ import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utilities.MathUtils; import utilities.SLOViolationCalculator; import utility_beans.RealtimeMonitoringAttribute; diff --git a/slo-violation-detector/src/main/java/slo_rule_modelling/SLOSubRule.java b/slo-violation-detector/src/main/java/slo_rule_modelling/SLOSubRule.java index f27d578..502ad60 100644 --- a/slo-violation-detector/src/main/java/slo_rule_modelling/SLOSubRule.java +++ b/slo-violation-detector/src/main/java/slo_rule_modelling/SLOSubRule.java @@ -8,7 +8,7 @@ package slo_rule_modelling; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utility_beans.PredictedMonitoringAttribute; import java.util.ArrayList; diff --git a/slo-violation-detector/src/main/java/slo_violation_detector_engine/DirectorSubcomponent.java b/slo-violation-detector/src/main/java/slo_violation_detector_engine/DirectorSubcomponent.java deleted file mode 100644 index 984fe2c..0000000 --- a/slo-violation-detector/src/main/java/slo_violation_detector_engine/DirectorSubcomponent.java +++ /dev/null @@ -1,19 +0,0 @@ -package slo_violation_detector_engine; - -import utility_beans.CharacterizedThread; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.concurrent.atomic.AtomicBoolean; - -public class DirectorSubcomponent extends SLOViolationDetectorSubcomponent{ - public HashMap persistent_running_director_threads = new HashMap<>(); - Integer id = 1; - public static HashMap director_subcomponents = new HashMap<>(); - public DirectorSubcomponent(){ - super.thread_type = CharacterizedThread.CharacterizedThreadType.persistent_running_director_thread; - director_subcomponents.put(String.valueOf(id),this); - id++; - } - -} diff --git a/slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponent.java b/slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponent.java similarity index 94% rename from slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponent.java rename to slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponent.java index 711a48b..e3644c5 100644 --- a/slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponent.java +++ b/slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponent.java @@ -1,7 +1,8 @@ -package slo_violation_detector_engine; +package slo_violation_detector_engine.detector; import org.json.simple.JSONObject; -import processing_logic.Runnables; +import slo_violation_detector_engine.generic.Runnables; +import slo_violation_detector_engine.generic.SLOViolationDetectorSubcomponent; import utility_beans.*; @@ -12,11 +13,11 @@ import java.util.function.BiFunction; import java.util.logging.Logger; import static configuration.Constants.*; -import static slo_violation_detector_engine.SLOViolationDetectorStateUtils.*; +import static slo_violation_detector_engine.generic.SLOViolationDetectorStateUtils.*; import static utility_beans.CharacterizedThread.CharacterizedThreadRunMode.attached; -public class DetectorSubcomponent extends SLOViolationDetectorSubcomponent{ +public class DetectorSubcomponent extends SLOViolationDetectorSubcomponent { public static final SynchronizedInteger detector_integer_id = new SynchronizedInteger(); public static HashMap detector_subcomponents = new HashMap<>(); //A HashMap containing all detector subcomponents private DetectorSubcomponentState subcomponent_state; diff --git a/slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponentState.java b/slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponentState.java similarity index 98% rename from slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponentState.java rename to slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponentState.java index 5da40ab..754e06b 100644 --- a/slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponentState.java +++ b/slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponentState.java @@ -1,4 +1,4 @@ -package slo_violation_detector_engine; +package slo_violation_detector_engine.detector; import org.apache.commons.collections4.queue.CircularFifoQueue; import slo_rule_modelling.SLORule; diff --git a/slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponentUtilities.java b/slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponentUtilities.java similarity index 98% rename from slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponentUtilities.java rename to slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponentUtilities.java index 9c3b965..cdb9267 100644 --- a/slo-violation-detector/src/main/java/slo_violation_detector_engine/DetectorSubcomponentUtilities.java +++ b/slo-violation-detector/src/main/java/slo_violation_detector_engine/detector/DetectorSubcomponentUtilities.java @@ -1,7 +1,6 @@ -package slo_violation_detector_engine; +package slo_violation_detector_engine.detector; import metric_retrieval.AttributeSubscription; -import org.apache.commons.collections4.queue.CircularFifoQueue; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -25,10 +24,10 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import static configuration.Constants.*; -import static processing_logic.Runnables.device_lost_topic_subscriber_runnable; -import static processing_logic.Runnables.get_severity_calculation_runnable; +import static slo_violation_detector_engine.generic.Runnables.device_lost_topic_subscriber_runnable; +import static slo_violation_detector_engine.generic.Runnables.get_severity_calculation_runnable; import static runtime.Main.*; -import static slo_violation_detector_engine.SLOViolationDetectorStateUtils.*; +import static slo_violation_detector_engine.generic.SLOViolationDetectorStateUtils.*; import static utility_beans.PredictedMonitoringAttribute.getPredicted_monitoring_attributes; public class DetectorSubcomponentUtilities { @@ -282,9 +281,6 @@ public class DetectorSubcomponentUtilities { //Implementation of 'Lost edge device' thread - - - CharacterizedThread.create_new_thread(device_lost_topic_subscriber_runnable,"device_lost_topic_subscriber_thread",true,associated_detector_subcomponent); diff --git a/slo-violation-detector/src/main/java/slo_violation_detector_engine/director/DirectorSubcomponent.java b/slo-violation-detector/src/main/java/slo_violation_detector_engine/director/DirectorSubcomponent.java new file mode 100644 index 0000000..abe6e91 --- /dev/null +++ b/slo-violation-detector/src/main/java/slo_violation_detector_engine/director/DirectorSubcomponent.java @@ -0,0 +1,37 @@ +package slo_violation_detector_engine.director; + +import slo_violation_detector_engine.generic.SLOViolationDetectorSubcomponent; +import utility_beans.CharacterizedThread; + +import java.util.HashMap; + +import static utilities.OperationalModeUtils.get_director_subscription_topics; + +public class DirectorSubcomponent extends SLOViolationDetectorSubcomponent { + public HashMap persistent_running_director_threads = new HashMap<>(); + Integer id = 1; + public static HashMap director_subcomponents = new HashMap<>(); + private static DirectorSubcomponent master_director; + + public static DirectorSubcomponent getMaster_director() { + return master_director; + } + + public static void setMaster_director(DirectorSubcomponent master_director) { + DirectorSubcomponent.master_director = master_director; + } + + public DirectorSubcomponent(){ + super.thread_type = CharacterizedThread.CharacterizedThreadType.persistent_running_director_thread; + create_director_topic_subscribers(); + director_subcomponents.put(String.valueOf(id),this); + id++; + master_director = this; + } + + private void create_director_topic_subscribers(){ + for (String subscription_topic : get_director_subscription_topics()){ + //TODO subscribe to each topic, creating a Characterized thread for each of them + } + } +} diff --git a/slo-violation-detector/src/main/java/processing_logic/Runnables.java b/slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/Runnables.java similarity index 87% rename from slo-violation-detector/src/main/java/processing_logic/Runnables.java rename to slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/Runnables.java index 1cb0e8f..7cbf0bd 100644 --- a/slo-violation-detector/src/main/java/processing_logic/Runnables.java +++ b/slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/Runnables.java @@ -1,15 +1,13 @@ -package processing_logic; +package slo_violation_detector_engine.generic; //import eu.melodic.event.brokerclient.BrokerPublisher; -import slo_violation_detector_engine.DetectorSubcomponent; -import slo_violation_detector_engine.DetectorSubcomponentUtilities; -import slo_violation_detector_engine.SLOViolationDetectorStateUtils; +import slo_violation_detector_engine.detector.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponentUtilities; import utility_beans.BrokerPublisher; import org.json.simple.JSONObject; import slo_rule_modelling.SLORule; import utility_beans.CharacterizedThread; -import java.io.IOException; import java.sql.Timestamp; import java.time.Clock; import java.util.Date; @@ -20,9 +18,9 @@ import java.util.logging.Logger; import static configuration.Constants.*; import static java.lang.Thread.sleep; import static slo_rule_modelling.SLORule.process_rule_value; -import static slo_violation_detector_engine.DetectorSubcomponent.*; -import static slo_violation_detector_engine.SLOViolationDetectorStateUtils.*; -import static slo_violation_detector_engine.DetectorSubcomponentUtilities.*; +import static slo_violation_detector_engine.detector.DetectorSubcomponent.*; +import static slo_violation_detector_engine.generic.SLOViolationDetectorStateUtils.*; +import static slo_violation_detector_engine.detector.DetectorSubcomponentUtilities.*; import static utilities.DebugDataSubscription.*; public class Runnables { @@ -57,7 +55,7 @@ public class Runnables { public static Runnable device_lost_topic_subscriber_runnable = () -> { while (true) { device_lost_subscriber.subscribe(device_lost_subscriber_function, new AtomicBoolean(false)); //This subscriber should be immune to stop signals - Logger.getAnonymousLogger().log(info_logging_level,"Broker unavailable, will try to reconnect after 10 seconds"); + Logger.getAnonymousLogger().log(info_logging_level,"A device used by the platform was lost, will therefore trigger a reconfiguration"); try { Thread.sleep(10000); }catch (InterruptedException i){ @@ -84,11 +82,6 @@ public class Runnables { BrokerPublisher persistent_publisher = new BrokerPublisher(topic_for_severity_announcement, prop.getProperty("broker_ip_url"), prop.getProperty("broker_username"), prop.getProperty("broker_password"), amq_library_configuration_location); while (!detector.stop_signal.get()) { - /*try { - Thread.sleep(time_horizon_seconds*1000); - } catch (InterruptedException e) { - e.printStackTrace(); - }*/ synchronized (detector.PREDICTION_EXISTS) { while (!detector.PREDICTION_EXISTS.getValue()) { try { @@ -132,19 +125,6 @@ public class Runnables { Logger.getAnonymousLogger().log(info_logging_level, "Targeted_prediction_time " + targeted_prediction_time); Runnable internal_severity_calculation_runnable = () -> { try { - /* - synchronized (ADAPTATION_TIMES_MODIFY) { - while (!ADAPTATION_TIMES_MODIFY.getValue()) { - ADAPTATION_TIMES_MODIFY.wait(); - } - ADAPTATION_TIMES_MODIFY.setValue(false); - adaptation_times.remove(targeted_prediction_time);//remove from the list of timepoints which should be processed. Later this timepoint will be added to the adaptation_times_to_remove HashSet to remove any data associated with it - ADAPTATION_TIMES_MODIFY.setValue(true); - ADAPTATION_TIMES_MODIFY.notifyAll(); - } - //adaptation_times_pending_processing.add(targeted_prediction_time); - - */ synchronized (detector.PREDICTION_EXISTS) { detector.PREDICTION_EXISTS.setValue(detector.getSubcomponent_state().adaptation_times.size() > 0); } diff --git a/slo-violation-detector/src/main/java/slo_violation_detector_engine/SLOViolationDetectorStateUtils.java b/slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/SLOViolationDetectorStateUtils.java similarity index 86% rename from slo-violation-detector/src/main/java/slo_violation_detector_engine/SLOViolationDetectorStateUtils.java rename to slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/SLOViolationDetectorStateUtils.java index 7c73c20..580b8b3 100644 --- a/slo-violation-detector/src/main/java/slo_violation_detector_engine/SLOViolationDetectorStateUtils.java +++ b/slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/SLOViolationDetectorStateUtils.java @@ -1,7 +1,5 @@ -package slo_violation_detector_engine; +package slo_violation_detector_engine.generic; -import org.apache.commons.collections4.queue.CircularFifoQueue; -import slo_rule_modelling.SLORule; import utility_beans.*; import java.io.File; @@ -9,11 +7,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Logger; import static configuration.Constants.*; diff --git a/slo-violation-detector/src/main/java/slo_violation_detector_engine/SLOViolationDetectorSubcomponent.java b/slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/SLOViolationDetectorSubcomponent.java similarity index 78% rename from slo-violation-detector/src/main/java/slo_violation_detector_engine/SLOViolationDetectorSubcomponent.java rename to slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/SLOViolationDetectorSubcomponent.java index ea7b6b9..d5e48ec 100644 --- a/slo-violation-detector/src/main/java/slo_violation_detector_engine/SLOViolationDetectorSubcomponent.java +++ b/slo-violation-detector/src/main/java/slo_violation_detector_engine/generic/SLOViolationDetectorSubcomponent.java @@ -1,4 +1,4 @@ -package slo_violation_detector_engine; +package slo_violation_detector_engine.generic; import utility_beans.CharacterizedThread; diff --git a/slo-violation-detector/src/main/java/utilities/DebugDataSubscription.java b/slo-violation-detector/src/main/java/utilities/DebugDataSubscription.java index 1016251..de315b7 100644 --- a/slo-violation-detector/src/main/java/utilities/DebugDataSubscription.java +++ b/slo-violation-detector/src/main/java/utilities/DebugDataSubscription.java @@ -2,9 +2,8 @@ package utilities; //import eu.melodic.event.brokerclient.BrokerPublisher; //import eu.melodic.event.brokerclient.BrokerSubscriber; -import processing_logic.Runnables; -import slo_violation_detector_engine.DetectorSubcomponent; -import slo_violation_detector_engine.DetectorSubcomponentUtilities; +import slo_violation_detector_engine.generic.Runnables; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utility_beans.BrokerSubscriber; import org.apache.commons.collections4.queue.CircularFifoQueue; import slo_rule_modelling.SLOSubRule; @@ -19,10 +18,8 @@ import java.util.logging.Logger; import static configuration.Constants.amq_library_configuration_location; import static configuration.Constants.info_logging_level; -import static slo_violation_detector_engine.DetectorSubcomponent.detector_subcomponents; -import static slo_violation_detector_engine.DirectorSubcomponent.director_subcomponents; -import static slo_violation_detector_engine.SLOViolationDetectorStateUtils.*; -import static utility_beans.CharacterizedThread.CharacterizedThreadType.slo_bound_running_thread; +import static slo_violation_detector_engine.detector.DetectorSubcomponent.detector_subcomponents; +import static slo_violation_detector_engine.director.DirectorSubcomponent.director_subcomponents; import static utility_beans.RealtimeMonitoringAttribute.get_metric_value; /** diff --git a/slo-violation-detector/src/main/java/utilities/MonitoringAttributeUtilities.java b/slo-violation-detector/src/main/java/utilities/MonitoringAttributeUtilities.java index ea480e2..c634cb7 100644 --- a/slo-violation-detector/src/main/java/utilities/MonitoringAttributeUtilities.java +++ b/slo-violation-detector/src/main/java/utilities/MonitoringAttributeUtilities.java @@ -9,7 +9,7 @@ package utilities; import slo_rule_modelling.SLOSubRule; -import slo_violation_detector_engine.DetectorSubcomponentState; +import slo_violation_detector_engine.detector.DetectorSubcomponentState; import utility_beans.MonitoringAttributeStatistics; import utility_beans.RealtimeMonitoringAttribute; @@ -18,7 +18,6 @@ import java.util.ArrayList; import static configuration.Constants.epsilon; import static configuration.Constants.roc_limit; import static utility_beans.PredictedMonitoringAttribute.*; -import slo_violation_detector_engine.DetectorSubcomponentState.*; public class MonitoringAttributeUtilities { diff --git a/slo-violation-detector/src/main/java/utilities/OperationalModeUtils.java b/slo-violation-detector/src/main/java/utilities/OperationalModeUtils.java index 11ebfc2..5f20d8d 100644 --- a/slo-violation-detector/src/main/java/utilities/OperationalModeUtils.java +++ b/slo-violation-detector/src/main/java/utilities/OperationalModeUtils.java @@ -2,10 +2,24 @@ package utilities; import utility_beans.OperationalMode; +import java.util.ArrayList; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import static configuration.Constants.*; + public class OperationalModeUtils{ + + public static ArrayList get_director_subscription_topics(){ + return new ArrayList<> + (List.of( + topic_for_severity_announcement, + topic_for_lost_device_announcement, + slo_rules_topic, + metric_list_topic + )); + } public static OperationalMode getSLOViolationDetectionOperationalMode(String operational_mode) { if (operational_mode.equalsIgnoreCase("DIRECTOR")){ return OperationalMode.DIRECTOR; diff --git a/slo-violation-detector/src/main/java/utility_beans/CharacterizedThread.java b/slo-violation-detector/src/main/java/utility_beans/CharacterizedThread.java index 31c66bc..77c37f8 100644 --- a/slo-violation-detector/src/main/java/utility_beans/CharacterizedThread.java +++ b/slo-violation-detector/src/main/java/utility_beans/CharacterizedThread.java @@ -1,8 +1,8 @@ package utility_beans; -import slo_violation_detector_engine.DetectorSubcomponent; -import slo_violation_detector_engine.DirectorSubcomponent; -import slo_violation_detector_engine.SLOViolationDetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; +import slo_violation_detector_engine.director.DirectorSubcomponent; +import slo_violation_detector_engine.generic.SLOViolationDetectorSubcomponent; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/slo-violation-detector/src/main/java/utility_beans/PredictedMonitoringAttribute.java b/slo-violation-detector/src/main/java/utility_beans/PredictedMonitoringAttribute.java index 1af39c4..7077582 100644 --- a/slo-violation-detector/src/main/java/utility_beans/PredictedMonitoringAttribute.java +++ b/slo-violation-detector/src/main/java/utility_beans/PredictedMonitoringAttribute.java @@ -8,7 +8,7 @@ package utility_beans; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import java.util.*; import java.util.logging.Level; @@ -16,7 +16,6 @@ import java.util.logging.Logger; import static configuration.Constants.*; import static utilities.MonitoringAttributeUtilities.isZero; -import static utility_beans.RealtimeMonitoringAttribute.*; public class PredictedMonitoringAttribute { diff --git a/slo-violation-detector/src/main/java/utility_beans/RealtimeMonitoringAttribute.java b/slo-violation-detector/src/main/java/utility_beans/RealtimeMonitoringAttribute.java index 09ef628..bb55c42 100644 --- a/slo-violation-detector/src/main/java/utility_beans/RealtimeMonitoringAttribute.java +++ b/slo-violation-detector/src/main/java/utility_beans/RealtimeMonitoringAttribute.java @@ -9,7 +9,7 @@ package utility_beans; import org.apache.commons.collections4.queue.CircularFifoQueue; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utilities.MathUtils; import java.util.Collection; diff --git a/slo-violation-detector/src/test/java/DerivedMonitoringAttributeTests.java b/slo-violation-detector/src/test/java/DerivedMonitoringAttributeTests.java index daa0e73..b2b878d 100644 --- a/slo-violation-detector/src/test/java/DerivedMonitoringAttributeTests.java +++ b/slo-violation-detector/src/test/java/DerivedMonitoringAttributeTests.java @@ -7,13 +7,11 @@ */ import org.junit.Test; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utility_beans.CharacterizedThread; import utility_beans.MonitoringAttributeStatistics; -import utility_beans.RealtimeMonitoringAttribute; import utility_beans.PredictedMonitoringAttribute; -import java.util.Arrays; import java.util.List; import static configuration.Constants.default_handled_application_name; diff --git a/slo-violation-detector/src/test/java/SeverityTests.java b/slo-violation-detector/src/test/java/SeverityTests.java index 8eb8eb1..4733deb 100644 --- a/slo-violation-detector/src/test/java/SeverityTests.java +++ b/slo-violation-detector/src/test/java/SeverityTests.java @@ -8,7 +8,7 @@ import org.junit.Test; import slo_rule_modelling.SLOSubRule; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utilities.SLOViolationCalculator; import utility_beans.CharacterizedThread; import utility_beans.MonitoringAttributeStatistics; diff --git a/slo-violation-detector/src/test/java/UnboundedMonitoringAttributeTests.java b/slo-violation-detector/src/test/java/UnboundedMonitoringAttributeTests.java index 22deea8..99a6ad7 100644 --- a/slo-violation-detector/src/test/java/UnboundedMonitoringAttributeTests.java +++ b/slo-violation-detector/src/test/java/UnboundedMonitoringAttributeTests.java @@ -11,7 +11,7 @@ //import eu.melodic.event.brokerclient.templates.EventFields; //import eu.melodic.event.brokerclient.templates.TopicNames; -import slo_violation_detector_engine.DetectorSubcomponent; +import slo_violation_detector_engine.detector.DetectorSubcomponent; import utility_beans.*; import utility_beans.BrokerSubscriber.*; import org.json.simple.JSONArray; @@ -41,7 +41,7 @@ import java.util.logging.Logger; import static configuration.Constants.*; import static slo_rule_modelling.SLORule.process_rule_value; -import static slo_violation_detector_engine.DetectorSubcomponentUtilities.initialize_subrule_and_attribute_associations; +import static slo_violation_detector_engine.detector.DetectorSubcomponentUtilities.initialize_subrule_and_attribute_associations; import static utility_beans.CharacterizedThread.CharacterizedThreadRunMode.detached; import static utility_beans.PredictedMonitoringAttribute.getPredicted_monitoring_attributes; import static utility_beans.RealtimeMonitoringAttribute.update_monitoring_attribute_value;