From e48015f470f80f9f235e041eb88a7212d7c9b41c Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Mon, 15 Jul 2024 15:40:12 +0200 Subject: [PATCH 1/2] Added cacheable method to return component name and current status --- .../QanaryComponentRegistrationChangeNotifier.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/QanaryComponentRegistrationChangeNotifier.java b/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/QanaryComponentRegistrationChangeNotifier.java index 1c94cf46..5e5da969 100644 --- a/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/QanaryComponentRegistrationChangeNotifier.java +++ b/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/QanaryComponentRegistrationChangeNotifier.java @@ -5,6 +5,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,6 +16,7 @@ import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent; import de.codecentric.boot.admin.server.notify.AbstractEventNotifier; import eu.wdaqua.qanary.business.QanaryComponent; +import org.springframework.cache.annotation.Cacheable; import reactor.core.publisher.Mono; public class QanaryComponentRegistrationChangeNotifier extends AbstractEventNotifier { @@ -44,6 +46,8 @@ protected Mono doNotify(InstanceEvent event, Instance instance) { logger.warn("registering component \"{}\" has no callable URL ({})", instanceName, instance.getRegistration().getServiceUrl()); } + } else if(status.toUpperCase().compareTo("OFFLINE") == 0) { + availableComponents.remove(instanceName); } else { availableComponents.put(instanceName, null); } @@ -53,7 +57,7 @@ protected Mono doNotify(InstanceEvent event, Instance instance) { }); } - protected void addAvailableComponent(String instanceName, Instance instance) { + protected void addAvailableComponent(String instanceName, Instance instance) { this.getAvailableComponents().put(instanceName, instance); } @@ -61,6 +65,14 @@ public List getAvailableComponentNames() { return new ArrayList<>(availableComponents.keySet()); } + @Cacheable + public Map getComponentsAndAvailability() { + return this.availableComponents.entrySet().stream().collect(Collectors.toMap( + Map.Entry::getKey, + entry -> entry.getValue().getStatusInfo().getStatus() + )); + } + public Map getAvailableComponents() { return this.availableComponents; } From 29883b70c8eeabff486203176547b551f7bf45cd Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Tue, 16 Jul 2024 09:52:25 +0200 Subject: [PATCH 2/2] [Done]: Fix indicator for component availability --- qanary_pipeline-template/pom.xml | 2 +- ...QanaryComponentRegistrationChangeNotifier.java | 15 ++++++--------- .../web/QanaryQuestionAnsweringController.java | 6 +++--- .../resources/templates/lib/reusableforms.html | 10 +++++----- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/qanary_pipeline-template/pom.xml b/qanary_pipeline-template/pom.xml index f7121344..801c6630 100644 --- a/qanary_pipeline-template/pom.xml +++ b/qanary_pipeline-template/pom.xml @@ -5,7 +5,7 @@ 4.0.0 qa.pipeline eu.wdaqua.qanary - 3.9.2 + 3.9.3 org.springframework.boot spring-boot-starter-parent diff --git a/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/QanaryComponentRegistrationChangeNotifier.java b/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/QanaryComponentRegistrationChangeNotifier.java index 5e5da969..7fa558bb 100644 --- a/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/QanaryComponentRegistrationChangeNotifier.java +++ b/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/QanaryComponentRegistrationChangeNotifier.java @@ -46,10 +46,8 @@ protected Mono doNotify(InstanceEvent event, Instance instance) { logger.warn("registering component \"{}\" has no callable URL ({})", instanceName, instance.getRegistration().getServiceUrl()); } - } else if(status.toUpperCase().compareTo("OFFLINE") == 0) { - availableComponents.remove(instanceName); } else { - availableComponents.put(instanceName, null); + availableComponents.put(instanceName, instance); } } else { logger.debug("Instance {} ({}) {}", instanceName, event.getInstance(), event.getType()); @@ -65,12 +63,11 @@ public List getAvailableComponentNames() { return new ArrayList<>(availableComponents.keySet()); } - @Cacheable - public Map getComponentsAndAvailability() { - return this.availableComponents.entrySet().stream().collect(Collectors.toMap( - Map.Entry::getKey, - entry -> entry.getValue().getStatusInfo().getStatus() - )); + @Cacheable(value = "availableComponents") // TODO: Handle changes ? + public Map getComponentsAndAvailability(Map availableComponents) { + Map comps = availableComponents.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e->e.getValue().getStatusInfo().getStatus())); + logger.info("Comps: {}", comps); + return comps; } public Map getAvailableComponents() { diff --git a/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/web/QanaryQuestionAnsweringController.java b/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/web/QanaryQuestionAnsweringController.java index c6313880..2531d7ba 100644 --- a/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/web/QanaryQuestionAnsweringController.java +++ b/qanary_pipeline-template/src/main/java/eu/wdaqua/qanary/web/QanaryQuestionAnsweringController.java @@ -129,9 +129,9 @@ public QanaryQuestionAnsweringController( // * expose the model with the component names */ @ModelAttribute("componentList") - public List componentList() { - logger.info("available components: {}", myComponentNotifier.getAvailableComponentNames()); - return myComponentNotifier.getAvailableComponentNames(); + public Map componentList() { + logger.info("available components: {}", myComponentNotifier.getAvailableComponentNames()); + return myComponentNotifier.getComponentsAndAvailability(myComponentNotifier.getAvailableComponents()); } /** diff --git a/qanary_pipeline-template/src/main/resources/templates/lib/reusableforms.html b/qanary_pipeline-template/src/main/resources/templates/lib/reusableforms.html index 658bcc4d..9d9813fa 100644 --- a/qanary_pipeline-template/src/main/resources/templates/lib/reusableforms.html +++ b/qanary_pipeline-template/src/main/resources/templates/lib/reusableforms.html @@ -58,11 +58,11 @@

Currently available Qanary components

    -
  • - -
  • + +
- + \ No newline at end of file