public DefaultPluginConfig(final String pluginName, final String version, final Properties props, final File pluginVersionRoot) { this.pluginName = pluginName; this.version = version; this.pluginVersionRoot = pluginVersionRoot; this.pluginType = PluginType.valueOf(props.getProperty(PROP_PLUGIN_TYPE_NAME, PluginType.__UNKNOWN__.toString())); }
@Override public int compare(final PluginConfig o1, final PluginConfig o2) { return -(o1.getVersion().compareTo(o2.getVersion())); } });
@Override public int hashCode() { int result = pluginName != null ? pluginName.hashCode() : 0; result = 31 * result + (pluginType != null ? pluginType.hashCode() : 0); result = 31 * result + (version != null ? version.hashCode() : 0); result = 31 * result + (pluginVersionRoot != null ? pluginVersionRoot.hashCode() : 0); return result; }
@Test(groups = "fast") public void testMultipleJavaVersions() throws IOException, InterruptedException, PluginConfigException { final File plugin = createNewJavaPlugin("FOO", new String[]{"1.2", "0.5", "1.0", "2.1", "0.8"}, null); final List<PluginJavaConfig> javaConfigs = pluginFinder.getLatestJavaPlugins(); assertEquals(javaConfigs.size(), 1); final PluginJavaConfig javaConfig = javaConfigs.get(0); assertEquals(javaConfig.getPluginName(), "FOO"); assertEquals(javaConfig.getVersion(), "2.1"); assertEquals(javaConfig.getBundleJarPath(), plugin.getAbsolutePath() + "/2.1" + "/FOO.jar"); }
if (shouldStopPlugin) { try { logSafely(LogService.LOG_INFO, String.format("Stopping plugin='%s' ", pluginConfig.getPluginName())); stopAllButRestartMechanism(context); } catch (final IllegalStateException e) { logSafely(LogService.LOG_DEBUG, String.format("Error stopping plugin='%s'", pluginConfig.getPluginName()), e); } catch (final Exception e) { logSafely(LogService.LOG_WARNING, String.format("Error stopping plugin='%s'", pluginConfig.getPluginName()), e); logSafely(LogService.LOG_INFO, String.format("Restarting plugin='%s'", pluginConfig.getPluginName())); } catch (final IllegalStateException e) { logSafely(LogService.LOG_DEBUG, String.format("Error stopping plugin='%s'", pluginConfig.getPluginName()), e); } catch (final Exception e) { logSafely(LogService.LOG_WARNING, String.format("Error stopping plugin='%s'", pluginConfig.getPluginName()), e); start(context); } catch (final Exception e) { logSafely(LogService.LOG_WARNING, String.format("Error starting plugin='%s'", pluginConfig.getPluginName()), e);
private <T extends PluginConfig> void loadPluginsForLanguage(final PluginLanguage pluginLanguage) throws PluginConfigException { final String rootDirPath = osgiConfig.getRootInstallationDir() + "/plugins/" + pluginLanguage.toString().toLowerCase(); final File rootDir = new File(rootDirPath); if (!rootDir.exists() || !rootDir.isDirectory()) { List<T> curPluginVersionlist = (List<T>) allPlugins.get(plugin.getPluginName()); if (curPluginVersionlist == null) { curPluginVersionlist = new LinkedList<T>(); allPlugins.put(plugin.getPluginName(), curPluginVersionlist); logger.info("Adding plugin {} ", plugin.getPluginVersionnedName());
private void installAllJavaPluginBundles(final BundleContext context, final List<Bundle> installedBundles) throws PluginConfigException, BundleException { final List<PluginJavaConfig> pluginJavaConfigs = pluginFinder.getLatestJavaPlugins(); for (final PluginJavaConfig cur : pluginJavaConfigs) { logger.info("Installing Java bundle for plugin {} from {}", cur.getPluginName(), cur.getBundleJarPath()); final Bundle bundle = context.installBundle("file:" + cur.getBundleJarPath()); ((DefaultPluginConfigServiceApi) pluginConfigServiceApi).registerBundle(bundle.getBundleId(), cur); installedBundles.add(bundle); } }
private File setupTmpDir(final PluginConfig pluginConfig) { final File tmpDirPath = new File(pluginConfig.getPluginVersionRoot().getAbsolutePath() + "/" + TMP_DIR_NAME); if (!tmpDirPath.exists()) { if (!tmpDirPath.mkdir()) { logService.log(LogService.LOG_WARNING, "Unable to create directory " + tmpDirPath + ", the restart mechanism is disabled"); return null; } } if (!tmpDirPath.isDirectory()) { logService.log(LogService.LOG_WARNING, tmpDirPath + " is not a directory, the restart mechanism is disabled"); return null; } return tmpDirPath; } }
protected PluginConfig retrievePluginConfig(final BundleContext context) { final PluginConfigServiceApi pluginConfigServiceApi = killbillAPI.getPluginConfigServiceApi(); return pluginConfigServiceApi.getPluginJavaConfig(context.getBundle().getBundleId()); }
private <T extends PluginConfig> List<T> getLatestPluginForLanguage(final PluginLanguage pluginLanguage) throws PluginConfigException { loadPluginsIfRequired(); final List<T> result = new LinkedList<T>(); for (final String pluginName : allPlugins.keySet()) { final T plugin = (T) allPlugins.get(pluginName).get(0); if (pluginLanguage != plugin.getPluginLanguage()) { continue; } result.add(plugin); } return result; }
private void installAllJRubyPluginBundles(final BundleContext context, final List<Bundle> installedBundles, @Nullable final String jrubyBundlePath) throws PluginConfigException, BundleException { if (jrubyBundlePath == null) { return; } final List<PluginRubyConfig> pluginRubyConfigs = pluginFinder.getLatestRubyPlugins(); int i = 0; for (final PluginRubyConfig cur : pluginRubyConfigs) { final String uniqueJrubyBundlePath = "jruby-" + cur.getPluginName(); InputStream tweakedInputStream = null; try { logger.info("Installing JRuby bundle for plugin {} ", uniqueJrubyBundlePath); tweakedInputStream = tweakRubyManifestToBeUnique(jrubyBundlePath, ++i); final Bundle bundle = context.installBundle(uniqueJrubyBundlePath, tweakedInputStream); ((DefaultPluginConfigServiceApi) pluginConfigServiceApi).registerBundle(bundle.getBundleId(), cur); installedBundles.add(bundle); } catch (IOException e) { logger.warn("Failed to open file {}", jrubyBundlePath); } finally { if (tweakedInputStream != null) { try { tweakedInputStream.close(); } catch (IOException ignore) { } } } } }
@Test(groups = "fast") public void testMultipleJavaVersionsWithDefault() throws IOException, InterruptedException, PluginConfigException { final File plugin = createNewJavaPlugin("BAR", new String[]{"1.2", "0.5", "1.0", "2.1", "0.8"}, "0.5"); final List<PluginJavaConfig> javaConfigs = pluginFinder.getLatestJavaPlugins(); assertEquals(javaConfigs.size(), 1); final PluginJavaConfig javaConfig = javaConfigs.get(0); assertEquals(javaConfig.getPluginName(), "BAR"); assertEquals(javaConfig.getVersion(), "0.5"); assertEquals(javaConfig.getBundleJarPath(), plugin.getAbsolutePath() + "/0.5" + "/BAR.jar"); }
if (shouldStopPlugin) { try { logSafely(LogService.LOG_INFO, String.format("Stopping plugin='%s' ", pluginConfig.getPluginName())); stopAllButRestartMechanism(context); } catch (final IllegalStateException e) { logSafely(LogService.LOG_DEBUG, String.format("Error stopping plugin='%s'", pluginConfig.getPluginName()), e); } catch (final Exception e) { logSafely(LogService.LOG_WARNING, String.format("Error stopping plugin='%s'", pluginConfig.getPluginName()), e); logSafely(LogService.LOG_INFO, String.format("Restarting plugin='%s'", pluginConfig.getPluginName())); } catch (final IllegalStateException e) { logSafely(LogService.LOG_DEBUG, String.format("Error stopping plugin='%s'", pluginConfig.getPluginName()), e); } catch (final Exception e) { logSafely(LogService.LOG_WARNING, String.format("Error stopping plugin='%s'", pluginConfig.getPluginName()), e); start(context); } catch (final Exception e) { logSafely(LogService.LOG_WARNING, String.format("Error starting plugin='%s'", pluginConfig.getPluginName()), e);
private File setupTmpDir(final PluginConfig pluginConfig) { final File tmpDirPath = new File(pluginConfig.getPluginVersionRoot().getAbsolutePath() + "/" + TMP_DIR_NAME); if (!tmpDirPath.exists()) { if (!tmpDirPath.mkdir()) { logService.log(LogService.LOG_WARNING, "Unable to create directory " + tmpDirPath + ", the restart mechanism is disabled"); return null; } } if (!tmpDirPath.isDirectory()) { logService.log(LogService.LOG_WARNING, tmpDirPath + " is not a directory, the restart mechanism is disabled"); return null; } return tmpDirPath; } }
protected PluginConfig retrievePluginConfig(final BundleContext context) { final PluginConfigServiceApi pluginConfigServiceApi = killbillAPI.getPluginConfigServiceApi(); return pluginConfigServiceApi.getPluginJavaConfig(context.getBundle().getBundleId()); }
@Test(groups = "fast") public void testJavaPluginWithDisabledHighest() throws IOException, InterruptedException, PluginConfigException { final File plugin = createNewJavaPlugin("ZOO", new String[]{"1.2", "0.5", "1.0", "2.1", "0.8"}, null); // In that case the code will default to the second highest known version addDisabledFile(plugin, "2.1"); final List<PluginJavaConfig> javaConfigs = pluginFinder.getLatestJavaPlugins(); assertEquals(javaConfigs.size(), 1); final PluginJavaConfig javaConfig = javaConfigs.get(0); assertEquals(javaConfig.getPluginName(), "ZOO"); assertEquals(javaConfig.getVersion(), "1.2"); assertEquals(javaConfig.getBundleJarPath(), plugin.getAbsolutePath() + "/1.2" + "/ZOO.jar"); }
public void addPlugin(final PluginConfig newPlugin) { final Map<String, LinkedList<PluginConfig>> allPluginField = getAllPluginField(); allPluginField.clear(); if (allPluginField.get(newPlugin.getPluginName()) == null) { allPluginField.put(newPlugin.getPluginName(), new LinkedList<PluginConfig>()); } allPluginField.get(newPlugin.getPluginName()).add(newPlugin); }
@Test(groups = "fast") public void testJavaPluginWithDisabledDefault() throws IOException, InterruptedException, PluginConfigException { final File plugin = createNewJavaPlugin("YEAH", new String[]{"1.2", "0.5", "1.0", "2.1", "0.8"}, "1.0"); // In that case the code will default to the highest known version addDisabledFile(plugin, "1.0"); final List<PluginJavaConfig> javaConfigs = pluginFinder.getLatestJavaPlugins(); assertEquals(javaConfigs.size(), 1); final PluginJavaConfig javaConfig = javaConfigs.get(0); assertEquals(javaConfig.getPluginName(), "YEAH"); assertEquals(javaConfig.getVersion(), "2.1"); assertEquals(javaConfig.getBundleJarPath(), plugin.getAbsolutePath() + "/2.1" + "/YEAH.jar"); }