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 6d3be0d FELIX-6448 : Simplify result cache for components check
6d3be0d is described below
commit 6d3be0ddb0e757d33062128129d819636c6319f5
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Fri Aug 20 15:18:24 2021 +0200
FELIX-6448 : Simplify result cache for components check
---
.../apache/felix/hc/generalchecks/DsComponentsCheck.java | 8 +++++---
.../org/apache/felix/systemready/SystemReadyCheck.java | 2 +-
.../org/apache/felix/systemready/impl/ComponentsCheck.java | 14 ++++++++------
3 files changed, 14 insertions(+), 10 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 a406e39..098c612 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
@@ -47,7 +47,7 @@ import
org.osgi.service.metatype.annotations.ObjectClassDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@Component(configurationPolicy = ConfigurationPolicy.REQUIRE)
+@Component(configurationPolicy = ConfigurationPolicy.REQUIRE, immediate = true)
@HealthCheckService(name = DsComponentsCheck.HC_NAME, tags = {
DsComponentsCheck.HC_DEFAULT_TAG })
@Designate(ocd = DsComponentsCheck.Config.class, factory = true)
public class DsComponentsCheck implements HealthCheck {
@@ -175,7 +175,9 @@ public class DsComponentsCheck implements HealthCheck {
log.info("{} required components are active", countEnabled);
}
result = new Result(log);
- this.cache.set(result);
+ if ( result.isOk() ) {
+ this.cache.set(result);
+ }
}
return result;
}
@@ -200,7 +202,7 @@ public class DsComponentsCheck implements HealthCheck {
}
}
- @Reference(updated = "updatedServiceComponentRuntime")
+ @Reference(name = "scr", updated = "updatedServiceComponentRuntime")
private void setServiceComponentRuntime(final ServiceComponentRuntime c) {
this.scr = c;
}
diff --git
a/systemready/src/main/java/org/apache/felix/systemready/SystemReadyCheck.java
b/systemready/src/main/java/org/apache/felix/systemready/SystemReadyCheck.java
index 291648d..678705a 100644
---
a/systemready/src/main/java/org/apache/felix/systemready/SystemReadyCheck.java
+++
b/systemready/src/main/java/org/apache/felix/systemready/SystemReadyCheck.java
@@ -24,7 +24,7 @@ package org.apache.felix.systemready;
*
* Examples: An asynchronous integration with another instance or a
third-party service
*
- * {@see SystemReadyMonitor}
+ * @see SystemReadyMonitor
*
* This framework is deprecated.
* @deprecated Use the Apache Felix Healthchecks instead.
diff --git
a/systemready/src/main/java/org/apache/felix/systemready/impl/ComponentsCheck.java
b/systemready/src/main/java/org/apache/felix/systemready/impl/ComponentsCheck.java
index 2812d23..ed65ca7 100644
---
a/systemready/src/main/java/org/apache/felix/systemready/impl/ComponentsCheck.java
+++
b/systemready/src/main/java/org/apache/felix/systemready/impl/ComponentsCheck.java
@@ -104,7 +104,7 @@ public class ComponentsCheck implements SystemReadyCheck {
.collect(Collectors.toList());
} catch (Throwable e) {
// exception might occur on shutdown or startup
- log.warn("Exception while getting ds component dtos {}",
e.getMessage(), e);
+ log.info("Exception while getting ds component dtos {}",
e.getMessage(), e);
return null;
}
}
@@ -128,18 +128,20 @@ public class ComponentsCheck implements SystemReadyCheck {
watchedComps.stream().forEach(dsComp -> addDetails(dsComp,
details));
final CheckStatus.State state =
CheckStatus.State.worstOf(watchedComps.stream().map(this::status));
result = new CheckStatus(getName(), type, state,
details.toString());
- } catch (Throwable e) {
+ } catch (final Throwable e) {
// exception might occur on shutdown or startup
- log.warn("Exception while checking ds component dtos {}",
e.getMessage(), e);
+ log.info("Exception while checking ds component dtos {}",
e.getMessage(), e);
result = new CheckStatus(getName(), type,
CheckStatus.State.RED, "Exception while checking ds component dtos : " +
e.getMessage());
}
}
- this.cache.set(result);
+ if ( result.getState() == CheckStatus.State.GREEN ) {
+ this.cache.set(result);
+ }
}
return result;
}
- private CheckStatus.State status(DSComp component) {
+ private CheckStatus.State status(final DSComp component) {
boolean missingConfig = component.config == null &&
"require".equals(component.desc.configurationPolicy);
boolean unsatisfied = !component.unsatisfied.isEmpty();
return (missingConfig || unsatisfied) ? CheckStatus.State.YELLOW :
CheckStatus.State.GREEN;
@@ -150,7 +152,7 @@ public class ComponentsCheck implements SystemReadyCheck {
printer.print(component);
}
- @Reference(updated = "updatedServiceComponentRuntime")
+ @Reference(name = "scr", updated = "updatedServiceComponentRuntime")
private void setServiceComponentRuntime(final ServiceComponentRuntime c) {
this.scr = c;
}