Skip to content

Commit

Permalink
Merge pull request #146 from killbill/work-for-1911
Browse files Browse the repository at this point in the history
Initial changes for 1911
  • Loading branch information
reshmabidikar authored Nov 28, 2023
2 parents 4fa797e + fe38be6 commit 7477ed4
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 9 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
32 changes: 29 additions & 3 deletions osgi/src/main/java/org/killbill/billing/osgi/BundleRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -99,16 +100,41 @@ private void stopAndUninstallBundle(final Bundle bundle, final String pluginName
registry.remove(pluginName);
}

public void startBundles() {
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) {
final boolean isBundleStarted = fileInstall.startBundle(bundleWithConfig.getBundle());

if (!isBundleStarted) {
registry.remove(getPluginName(bundleWithConfig));
final String pluginName = getPluginName(bundleWithConfig);
if (isBundleStarted) {
pluginsStarted.add(pluginName);
} else {
registry.remove(pluginName);
}

}

if (mandatoryPlugins.iterator().hasNext()) {
checkIfMandatoryPluginsAreStarted(pluginsStarted, mandatoryPlugins);
}
else {
log.info("Mandatory plugins not specified, skipping mandatory plugins check");
}

}

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");
}
}
log.info("All mandatory plugins are started");
}


public void stopBundles() {
for (final BundleWithConfig bundleWithConfig : bundleWithConfigs) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
package org.killbill.billing.osgi;

import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Named;
Expand Down Expand Up @@ -97,9 +99,11 @@ 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
bundleRegistry.startBundles();
bundleRegistry.startBundles(mandatoryPluginsList);
// Tell the plugins all bundles have started
killbillActivator.sendEvent("org/killbill/billing/osgi/lifecycle/STARTED", new HashMap<String, String>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,9 @@ public interface OSGIConfig extends KillbillPlatformConfig {
@Default("")
public String getSystemBundleExportPackagesExtra();

@Config("org.killbill.billing.plugin.mandatory.plugins")
@Description("List of mandatory plugins")
@Default("")
public String getMandatoryPluginsList();

}
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ public String getSystemBundleExportPackagesJava() {
public String getSystemBundleExportPackagesExtra() {
return null;
}
@Override
public String getMandatoryPluginsList() {
return null;
}

};
}

Expand Down
2 changes: 1 addition & 1 deletion platform-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
<artifactId>killbill-platform-api</artifactId>
<packaging>jar</packaging>
<name>killbill-platform-api</name>
<dependencies />
<dependencies/>
</project>
4 changes: 2 additions & 2 deletions platform-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@
<phase>initialize</phase>
<configuration>
<tasks>
<copy file="${basedir}/../osgi-bundles/tests/beatrix/target/killbill-platform-osgi-bundles-test-beatrix-${project.version}.jar" tofile="${basedir}/src/test/resources/killbill-osgi-bundles-test-beatrix-jar-with-dependencies.jar" />
<copy file="${basedir}/../osgi-bundles/tests/payment/target/killbill-platform-osgi-bundles-test-payment-${project.version}.jar" tofile="${basedir}/src/test/resources/killbill-osgi-bundles-test-payment-jar-with-dependencies.jar" />
<copy file="${basedir}/../osgi-bundles/tests/beatrix/target/killbill-platform-osgi-bundles-test-beatrix-${project.version}.jar" tofile="${basedir}/src/test/resources/killbill-osgi-bundles-test-beatrix-jar-with-dependencies.jar"/>
<copy file="${basedir}/../osgi-bundles/tests/payment/target/killbill-platform-osgi-bundles-test-payment-${project.version}.jar" tofile="${basedir}/src/test/resources/killbill-osgi-bundles-test-payment-jar-with-dependencies.jar"/>
</tasks>
</configuration>
</execution>
Expand Down

0 comments on commit 7477ed4

Please sign in to comment.