From b102cb0184db1c77129ab7300cdde0711fb3aafd Mon Sep 17 00:00:00 2001 From: ipatini Date: Wed, 29 May 2024 18:16:14 +0300 Subject: [PATCH] Bugfix in EmsBootInitializer and two minor changes Change-Id: I6cbf4a0a69e6d842493923ced8e8cc0014f40b26 --- .../nebulous/ems/service/EmsBootInitializer.java | 15 ++++++++++++++- .../service/ExternalBrokerPublisherService.java | 2 +- .../ems/translate/analyze/ConstraintsHelper.java | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/service/EmsBootInitializer.java b/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/service/EmsBootInitializer.java index e76a5a2..f02055a 100644 --- a/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/service/EmsBootInitializer.java +++ b/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/service/EmsBootInitializer.java @@ -45,6 +45,7 @@ public class EmsBootInitializer extends AbstractExternalBrokerService implements private final NebulousEmsTranslatorProperties translatorProperties; private final String applicationId; private final AtomicBoolean processingResponse = new AtomicBoolean(false); + private final AtomicBoolean alreadyInitialized = new AtomicBoolean(false); private ScheduledFuture bootFuture; private Consumer consumer; private Publisher publisher; @@ -96,7 +97,7 @@ public class EmsBootInitializer extends AbstractExternalBrokerService implements processEmsBootResponseMessage(body); } }; - consumer = new Consumer(properties.getEmsBootResponseTopic(), properties.getEmsBootResponseTopic(), messageHandler, null, true, true); + consumer = new Consumer(properties.getEmsBootResponseTopic(), properties.getEmsBootResponseTopic(), messageHandler, applicationId, true, true); publisher = new Publisher(properties.getEmsBootTopic(), properties.getEmsBootTopic(), true, true); connectToBroker(List.of(publisher), List.of(consumer)); } @@ -118,6 +119,10 @@ public class EmsBootInitializer extends AbstractExternalBrokerService implements } protected void processEmsBootResponseMessage(Map body) { + if (alreadyInitialized.get()) { + log.warn("EmsBootInitializer: Received EMS Boot response but EMS is already initialized. Ignoring it."); + return; + } if (! processingResponse.compareAndSet(false, true)) { log.warn("EmsBootInitializer: A previous EMS Boot response is still being processed. Ignoring this one."); return; @@ -137,6 +142,11 @@ public class EmsBootInitializer extends AbstractExternalBrokerService implements Model: {} """, appId, bindingsMap, metricsList, modelStr); + if (! StringUtils.equals(applicationId, appId)) { + log.warn("EmsBootInitializer: Ignoring EMS Boot response. Response App-Id does not match the configured App Id: {} != {}", appId, applicationId); + return; + } + try { // Process metric model and bindings processMetricModel(appId, modelStr); @@ -153,6 +163,9 @@ public class EmsBootInitializer extends AbstractExternalBrokerService implements log.warn("EmsBootInitializer: EXCEPTION while processing EMS Boot Response message: ", e); } + // Mark EMS as initialized + alreadyInitialized.set(true); + processingResponse.set(false); } diff --git a/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/service/ExternalBrokerPublisherService.java b/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/service/ExternalBrokerPublisherService.java index 845802d..e50dad1 100644 --- a/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/service/ExternalBrokerPublisherService.java +++ b/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/service/ExternalBrokerPublisherService.java @@ -152,7 +152,7 @@ public class ExternalBrokerPublisherService extends AbstractExternalBrokerServic // If an SLO, also send an Event Type VI event to combined SLO topics if (sloSet.contains(topic)) { publishMessage(publishersMap.get(COMBINED_SLO_PUBLISHER_KEY), Map.of( - "severity", 0.5, + "severity", 1.0, "predictionTime", Instant.now().toEpochMilli(), "probability", 1.0 )); diff --git a/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/translate/analyze/ConstraintsHelper.java b/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/translate/analyze/ConstraintsHelper.java index db020ad..38ad193 100644 --- a/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/translate/analyze/ConstraintsHelper.java +++ b/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/translate/analyze/ConstraintsHelper.java @@ -230,7 +230,7 @@ class ConstraintsHelper extends AbstractHelper { private Constraint decomposeComposingConstraintSpec(TranslationContext _TC, Map spec, NamesKey parentNamesKey, Constraint parentConstraint) { // Construct SLO namesKey - String name = "random-"+System.currentTimeMillis(); + String name = "random_"+System.currentTimeMillis(); NamesKey namesKey = createNamesKey(getContainerName(spec), name); // Decompose composing constraint