Skip to content

Commit 6d3be0d

Browse files
committed
FELIX-6448 : Simplify result cache for components check
1 parent 6eff0d0 commit 6d3be0d

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

healthcheck/generalchecks/src/main/java/org/apache/felix/hc/generalchecks/DsComponentsCheck.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import org.slf4j.Logger;
4848
import org.slf4j.LoggerFactory;
4949

50-
@Component(configurationPolicy = ConfigurationPolicy.REQUIRE)
50+
@Component(configurationPolicy = ConfigurationPolicy.REQUIRE, immediate = true)
5151
@HealthCheckService(name = DsComponentsCheck.HC_NAME, tags = { DsComponentsCheck.HC_DEFAULT_TAG })
5252
@Designate(ocd = DsComponentsCheck.Config.class, factory = true)
5353
public class DsComponentsCheck implements HealthCheck {
@@ -175,7 +175,9 @@ public Result execute() {
175175
log.info("{} required components are active", countEnabled);
176176
}
177177
result = new Result(log);
178-
this.cache.set(result);
178+
if ( result.isOk() ) {
179+
this.cache.set(result);
180+
}
179181
}
180182
return result;
181183
}
@@ -200,7 +202,7 @@ static final String toStateString(int state) {
200202
}
201203
}
202204

203-
@Reference(updated = "updatedServiceComponentRuntime")
205+
@Reference(name = "scr", updated = "updatedServiceComponentRuntime")
204206
private void setServiceComponentRuntime(final ServiceComponentRuntime c) {
205207
this.scr = c;
206208
}

systemready/src/main/java/org/apache/felix/systemready/SystemReadyCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* Examples: An asynchronous integration with another instance or a third-party service
2626
*
27-
* {@see SystemReadyMonitor}
27+
* @see SystemReadyMonitor
2828
*
2929
* This framework is deprecated.
3030
* @deprecated Use the Apache Felix Healthchecks instead.

systemready/src/main/java/org/apache/felix/systemready/impl/ComponentsCheck.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private List<DSComp> getComponents(final Collection<ComponentDescriptionDTO> des
104104
.collect(Collectors.toList());
105105
} catch (Throwable e) {
106106
// exception might occur on shutdown or startup
107-
log.warn("Exception while getting ds component dtos {}", e.getMessage(), e);
107+
log.info("Exception while getting ds component dtos {}", e.getMessage(), e);
108108
return null;
109109
}
110110
}
@@ -128,18 +128,20 @@ public CheckStatus getStatus() {
128128
watchedComps.stream().forEach(dsComp -> addDetails(dsComp, details));
129129
final CheckStatus.State state = CheckStatus.State.worstOf(watchedComps.stream().map(this::status));
130130
result = new CheckStatus(getName(), type, state, details.toString());
131-
} catch (Throwable e) {
131+
} catch (final Throwable e) {
132132
// exception might occur on shutdown or startup
133-
log.warn("Exception while checking ds component dtos {}", e.getMessage(), e);
133+
log.info("Exception while checking ds component dtos {}", e.getMessage(), e);
134134
result = new CheckStatus(getName(), type, CheckStatus.State.RED, "Exception while checking ds component dtos : " + e.getMessage());
135135
}
136136
}
137-
this.cache.set(result);
137+
if ( result.getState() == CheckStatus.State.GREEN ) {
138+
this.cache.set(result);
139+
}
138140
}
139141
return result;
140142
}
141143

142-
private CheckStatus.State status(DSComp component) {
144+
private CheckStatus.State status(final DSComp component) {
143145
boolean missingConfig = component.config == null && "require".equals(component.desc.configurationPolicy);
144146
boolean unsatisfied = !component.unsatisfied.isEmpty();
145147
return (missingConfig || unsatisfied) ? CheckStatus.State.YELLOW : CheckStatus.State.GREEN;
@@ -150,7 +152,7 @@ private void addDetails(final DSComp component, final StringBuilder details) {
150152
printer.print(component);
151153
}
152154

153-
@Reference(updated = "updatedServiceComponentRuntime")
155+
@Reference(name = "scr", updated = "updatedServiceComponentRuntime")
154156
private void setServiceComponentRuntime(final ServiceComponentRuntime c) {
155157
this.scr = c;
156158
}

0 commit comments

Comments
 (0)