Skip to content

Commit

Permalink
Changes as per review comments - Round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
reshmabidikar committed Nov 27, 2023
1 parent 88861bc commit fe38be6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
6 changes: 6 additions & 0 deletions lifecycle/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@
<Method name="initialize" />
<Bug pattern="EI_EXPOSE_REP2" />
</Match>

<Match>
<Class name="org.killbill.billing.lifecycle.DefaultLifecycle" />
<Method name="doFireStage" />
<Bug pattern="DM_EXIT" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.slf4j.LoggerFactory;

import com.google.inject.ConfigurationException;

import com.google.inject.Injector;
import com.google.inject.ProvisionException;

Expand All @@ -53,10 +52,14 @@ public class DefaultLifecycle implements Lifecycle {
// See https://github.com/killbill/killbill-commons/issues/143
private final Map<LifecycleLevel, SortedSet<LifecycleHandler<? extends KillbillService>>> handlersByLevel;

private static final String EXIT_ON_LIFECYCLE_ERROR_PROPERTY = "org.killbill.server.exit.on.lifecycle.error";
private boolean exitOnError;

@Inject
public DefaultLifecycle(final Injector injector) {
this();
final ServiceFinder<KillbillService> serviceFinder = new ServiceFinder<>(DefaultLifecycle.class.getClassLoader(), KillbillService.class.getName());
exitOnError = System.getProperty(EXIT_ON_LIFECYCLE_ERROR_PROPERTY) != null && Boolean.parseBoolean(System.getProperty(EXIT_ON_LIFECYCLE_ERROR_PROPERTY));
init(serviceFinder, injector);
}

Expand Down Expand Up @@ -155,6 +158,10 @@ private void doFireStage(final LifecycleHandlerType.LifecycleLevel level) {
method.invoke(target);
} catch (final Exception e) {
logWarn("Killbill lifecycle failed to invoke lifecycle handler", e);
if (exitOnError) {
log.info("{} is set, so exiting..", EXIT_ON_LIFECYCLE_ERROR_PROPERTY);
System.exit(1);
}
}
}

Expand Down
21 changes: 8 additions & 13 deletions osgi/src/main/java/org/killbill/billing/osgi/BundleRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void stopAndUninstallBundle(final Bundle bundle, final String pluginName
registry.remove(pluginName);
}

public void startBundles(final Iterable<String> mandatoryPlugins) {
public void startBundles(final Iterable<String> mandatoryPlugins) throws Exception {
log.info("List of mandatory plugins: {}", mandatoryPlugins);
final List<String> pluginsStarted = new LinkedList<>();
for (final BundleWithConfig bundleWithConfig : bundleWithConfigs) {
Expand All @@ -109,8 +109,7 @@ public void startBundles(final Iterable<String> mandatoryPlugins) {
final String pluginName = getPluginName(bundleWithConfig);
if (isBundleStarted) {
pluginsStarted.add(pluginName);
}
else {
} else {
registry.remove(pluginName);
}

Expand All @@ -125,18 +124,14 @@ public void startBundles(final Iterable<String> mandatoryPlugins) {

}

private void checkIfMandatoryPluginsAreStarted(final List<String> pluginsStarted, final Iterable<String> mandatoryPlugins){
boolean allMandatoryPluginsStarted = true;
for (String pluginName: mandatoryPlugins) {
if(!pluginsStarted.contains(pluginName)) {
log.error("Mandatory plugin {} not started", pluginName); //TODO_1911 - Exit here?
allMandatoryPluginsStarted = false;
private void checkIfMandatoryPluginsAreStarted(final List<String> pluginsStarted, final Iterable<String> mandatoryPlugins) throws Exception {
for (final String pluginName : mandatoryPlugins) {
if (!pluginsStarted.contains(pluginName)) {
log.warn("Mandatory plugin {} not started", pluginName);
throw new Exception("Mandatory plugin " + pluginName + " not started");
}
}
if (allMandatoryPluginsStarted) {
log.info("All mandatory plugins are started");
}

log.info("All mandatory plugins are started");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void initialize() {
}

@LifecycleHandlerType(LifecycleHandlerType.LifecycleLevel.START_PLUGIN)
public void start() {
public void start() throws Exception {
final String mandatoryPlugins = osgiConfig.getMandatoryPluginsList();
final Set<String> mandatoryPluginsList = mandatoryPlugins != null && !mandatoryPlugins.isEmpty() ? Set.of(mandatoryPlugins.split("\\s*,\\s*")) : Collections.emptySet();
// This will call the start() method for the bundles
Expand Down

0 comments on commit fe38be6

Please sign in to comment.