You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2021/08/08 10:16:18 UTC
[felix-dev] branch master updated: FELIX-6400 : Reduce resource
consumption during component checks
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 5f82178 FELIX-6400 : Reduce resource consumption during component checks
5f82178 is described below
commit 5f8217865be229eb915fd99f2be2a83b4b8868bd
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Aug 8 12:15:54 2021 +0200
FELIX-6400 : Reduce resource consumption during component checks
---
.../felix/hc/generalchecks/DsComponentsCheck.java | 115 ++++++++++++---------
1 file changed, 68 insertions(+), 47 deletions(-)
diff --git a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java
index cc63898..0700a22 100644
--- a/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java
+++ b/healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java
@@ -23,6 +23,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.felix.hc.annotation.HealthCheckService;
import org.apache.felix.hc.api.FormattingResultLog;
@@ -76,13 +77,15 @@ public class DsComponentsCheck implements HealthCheck {
}
private List<String> componentsList;
+
private Result.Status statusForMissing;
@Reference(policyOption = ReferencePolicyOption.GREEDY)
private DsRootCauseAnalyzer analyzer;
- @Reference(policyOption = ReferencePolicyOption.GREEDY)
- ServiceComponentRuntime scr;
+ volatile ServiceComponentRuntime scr;
+
+ private final AtomicReference<Result> cache = new AtomicReference<>();
@Activate
public void activate(final BundleContext ctx, final Config config) throws InterruptedException {
@@ -93,68 +96,73 @@ public class DsComponentsCheck implements HealthCheck {
@Override
public Result execute() {
- FormattingResultLog log = new FormattingResultLog();
-
- Collection<ComponentDescriptionDTO> componentDescriptionDTOs = scr.getComponentDescriptionDTOs();
- List<ComponentDescriptionDTO> watchedComps = new LinkedList<ComponentDescriptionDTO>();
- List<String> missingComponents = new LinkedList<String>(componentsList);
- for (ComponentDescriptionDTO desc : componentDescriptionDTOs) {
- if (componentsList.contains(desc.name)) {
- watchedComps.add(desc);
- missingComponents.remove(desc.name);
+ Result result = this.cache.get();
+ if ( result == null ) {
+ FormattingResultLog log = new FormattingResultLog();
+
+ Collection<ComponentDescriptionDTO> componentDescriptionDTOs = scr.getComponentDescriptionDTOs();
+ List<ComponentDescriptionDTO> watchedComps = new LinkedList<ComponentDescriptionDTO>();
+ List<String> missingComponents = new LinkedList<String>(componentsList);
+ for (ComponentDescriptionDTO desc : componentDescriptionDTOs) {
+ if (componentsList.contains(desc.name)) {
+ watchedComps.add(desc);
+ missingComponents.remove(desc.name);
+ }
+ }
+ for (String missingComp : missingComponents) {
+ log.info("No component with name {} is registered in SCR runtime", missingComp);
}
- }
- for (String missingComp : missingComponents) {
- log.info("No component with name {} is registered in SCR runtime", missingComp);
- }
- int countEnabled = 0;
- int countDisabled = 0;
- for (ComponentDescriptionDTO dsComp : watchedComps) {
+ int countEnabled = 0;
+ int countDisabled = 0;
+ for (ComponentDescriptionDTO dsComp : watchedComps) {
- boolean isActive;
+ boolean isActive;
- boolean componentEnabled = scr.isComponentEnabled(dsComp);
- if (componentEnabled) {
+ boolean componentEnabled = scr.isComponentEnabled(dsComp);
+ if (componentEnabled) {
- Collection<ComponentConfigurationDTO> componentConfigurationDTOs = scr.getComponentConfigurationDTOs(dsComp);
- List<String> idStateTuples = new ArrayList<>();
- boolean foundActiveOrSatisfiedConfig = false;
- for (ComponentConfigurationDTO configDto : componentConfigurationDTOs) {
- idStateTuples.add("id " + configDto.id + ":" + toStateString(configDto.state));
- if (configDto.state == ComponentConfigurationDTO.ACTIVE || configDto.state == ComponentConfigurationDTO.SATISFIED) {
- foundActiveOrSatisfiedConfig = true;
+ Collection<ComponentConfigurationDTO> componentConfigurationDTOs = scr.getComponentConfigurationDTOs(dsComp);
+ List<String> idStateTuples = new ArrayList<>();
+ boolean foundActiveOrSatisfiedConfig = false;
+ for (ComponentConfigurationDTO configDto : componentConfigurationDTOs) {
+ idStateTuples.add("id " + configDto.id + ":" + toStateString(configDto.state));
+ if (configDto.state == ComponentConfigurationDTO.ACTIVE || configDto.state == ComponentConfigurationDTO.SATISFIED) {
+ foundActiveOrSatisfiedConfig = true;
+ }
+ }
+ log.debug(dsComp.name + " (" + String.join(",", idStateTuples) + ")");
+
+ if (componentConfigurationDTOs.isEmpty() || foundActiveOrSatisfiedConfig) {
+ countEnabled++;
+ isActive = true;
+ } else {
+ countDisabled++;
+ isActive = false;
}
- }
- log.debug(dsComp.name + " (" + String.join(",", idStateTuples) + ")");
- if (componentConfigurationDTOs.isEmpty() || foundActiveOrSatisfiedConfig) {
- countEnabled++;
- isActive = true;
} else {
countDisabled++;
isActive = false;
}
- } else {
- countDisabled++;
- isActive = false;
+ if (!isActive) {
+ analyzer.logNotEnabledComponent(log, dsComp);
+ }
}
- if (!isActive) {
- analyzer.logNotEnabledComponent(log, dsComp);
+ if (!missingComponents.isEmpty()) {
+ log.add(new Entry(statusForMissing, missingComponents.size() + " required components are missing in SCR runtime"));
}
- }
+ if (countDisabled > 0) {
+ log.add(new Entry(statusForMissing, countDisabled + " required components are not active"));
+ }
+ log.info("{} required components are active", countEnabled);
- if (!missingComponents.isEmpty()) {
- log.add(new Entry(statusForMissing, missingComponents.size() + " required components are missing in SCR runtime"));
- }
- if (countDisabled > 0) {
- log.add(new Entry(statusForMissing, countDisabled + " required components are not active"));
+ result = new Result(log);
+ this.cache.set(result);
}
- log.info("{} required components are active", countEnabled);
-
- return new Result(log);
+ return result;
}
static final String toStateString(int state) {
@@ -177,4 +185,17 @@ public class DsComponentsCheck implements HealthCheck {
}
}
+ @Reference(policyOption = ReferencePolicyOption.GREEDY, updated = "updatedServiceComponentRuntime")
+ private void setServiceComponentRuntime(final ServiceComponentRuntime c) {
+ this.scr = c;
+ }
+
+ private void unsetServiceComponentRuntime(final ServiceComponentRuntime c) {
+ this.scr = null;
+ }
+
+ private void updatedServiceComponentRuntime(final ServiceComponentRuntime c) {
+ // change in DS - clear cache
+ this.cache.set(null);
+ }
}