Skip to content

Commit 6d1aed6

Browse files
Merge pull request #196 from wttech/bundle-context-issues-in-hc
Bundle state visible in HC
2 parents 9aa7910 + 0affa8e commit 6d1aed6

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

core/src/main/java/dev/vml/es/acm/core/instance/HealthChecker.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import dev.vml.es.acm.core.code.*;
44
import dev.vml.es.acm.core.code.script.ExtensionScriptSyntax;
5-
import dev.vml.es.acm.core.osgi.*;
5+
import dev.vml.es.acm.core.osgi.InstanceInfo;
6+
import dev.vml.es.acm.core.osgi.InstanceType;
7+
import dev.vml.es.acm.core.osgi.OsgiEvent;
8+
import dev.vml.es.acm.core.osgi.OsgiEventCollector;
9+
import dev.vml.es.acm.core.osgi.OsgiScanner;
10+
import dev.vml.es.acm.core.osgi.OsgiUtils;
611
import dev.vml.es.acm.core.repo.Repo;
712
import dev.vml.es.acm.core.util.ExceptionUtils;
813
import dev.vml.es.acm.core.util.ResolverUtils;
@@ -162,25 +167,44 @@ private void checkRepository(HealthStatus result, ResourceResolver resourceResol
162167
}
163168
}
164169

170+
/**
171+
* @see <https://github.com/apache/felix-dev/blob/master/framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java> 'checkValidity()' method
172+
*/
165173
private void checkBundles(HealthStatus result) {
166174
if (!config.bundleChecking()) {
167175
return;
168176
}
177+
178+
try {
179+
osgiScanner.getBundleContext().getBundle();
180+
} catch (Exception e) {
181+
result.issues.add(new HealthIssue(
182+
HealthIssueSeverity.CRITICAL,
183+
HealthIssueCategory.OSGI,
184+
"Bundle context not valid",
185+
ExceptionUtils.toString(e)));
186+
return;
187+
}
188+
169189
osgiScanner.scanBundles().filter(b -> !isBundleIgnored(b)).forEach(bundle -> {
170190
if (osgiScanner.isFragment(bundle)) {
171191
if (!osgiScanner.isBundleResolved(bundle)) {
172192
result.issues.add(new HealthIssue(
173193
HealthIssueSeverity.CRITICAL,
174194
HealthIssueCategory.OSGI,
175-
String.format("Bundle fragment not resolved: '%s'", bundle.getSymbolicName()),
195+
String.format(
196+
"Bundle fragment not resolved (%s): '%s'",
197+
OsgiUtils.bundleStateName(bundle.getState()), bundle.getSymbolicName()),
176198
null));
177199
}
178200
} else {
179201
if (!osgiScanner.isBundleActive(bundle)) {
180202
result.issues.add(new HealthIssue(
181203
HealthIssueSeverity.CRITICAL,
182204
HealthIssueCategory.OSGI,
183-
String.format("Bundle not active: '%s'", bundle.getSymbolicName()),
205+
String.format(
206+
"Bundle not active (%s): '%s'",
207+
OsgiUtils.bundleStateName(bundle.getState()), bundle.getSymbolicName()),
184208
null));
185209
}
186210
}

core/src/main/java/dev/vml/es/acm/core/osgi/OsgiScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class OsgiScanner {
2424

2525
private static final String BUNDLE_WIRING_PACKAGE = "osgi.wiring.package";
2626

27-
private BundleContext getBundleContext() {
27+
public BundleContext getBundleContext() {
2828
return FrameworkUtil.getBundle(getClass()).getBundleContext();
2929
}
3030

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package dev.vml.es.acm.core.osgi;
2+
3+
import org.osgi.framework.Bundle;
4+
5+
public final class OsgiUtils {
6+
7+
private OsgiUtils() {
8+
// Utility class
9+
}
10+
11+
public static String bundleStateName(int state) {
12+
switch (state) {
13+
case Bundle.UNINSTALLED:
14+
return "uninstalled";
15+
case Bundle.INSTALLED:
16+
return "installed";
17+
case Bundle.RESOLVED:
18+
return "resolved";
19+
case Bundle.STARTING:
20+
return "starting";
21+
case Bundle.STOPPING:
22+
return "stopping";
23+
case Bundle.ACTIVE:
24+
return "active";
25+
default:
26+
return String.format("state '%d'", state);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)