TAMAYA-274 Added Tamaya Configuration Service and reduced exposed artifacts.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/commit/2b878fa1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/tree/2b878fa1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/diff/2b878fa1 Branch: refs/heads/master Commit: 2b878fa18225ed965e63ed5ceeb19309c6beb420 Parents: 7d463e3 Author: Anatole Tresch <[email protected]> Authored: Thu Oct 12 12:27:13 2017 +0200 Committer: Anatole Tresch <[email protected]> Committed: Thu Oct 12 12:27:13 2017 +0200 ---------------------------------------------------------------------- osgi/common/bnd.bnd | 2 +- .../java/org/apache/tamaya/osgi/Activator.java | 7 +- .../java/org/apache/tamaya/osgi/Backups.java | 4 +- .../org/apache/tamaya/osgi/ConfigHistory.java | 41 ++-- .../apache/tamaya/osgi/TamayaConfigPlugin.java | 98 ++++++++- .../tamaya/osgi/commands/BackupCommands.java | 36 ++-- .../tamaya/osgi/commands/ConfigCommands.java | 31 ++- .../tamaya/osgi/commands/HistoryCommands.java | 25 ++- .../osgi/commands/TamayaConfigService.java | 206 +++++++++++++++++++ .../apache/tamaya/osgi/AbstractOSGITest.java | 3 +- .../org/apache/tamaya/osgi/ActivatorTest.java | 3 +- .../apache/tamaya/osgi/ConfigHistoryTest.java | 40 ++-- .../tamaya/osgi/TamayaConfigPluginTest.java | 28 +-- .../osgi/commands/BackupCommandsTest.java | 34 ++- .../osgi/commands/ConfigCommandsTest.java | 15 +- .../osgi/commands/HistoryCommandsTest.java | 43 ++-- .../tamaya/gogo/shell/BackupCommands.java | 16 +- .../tamaya/gogo/shell/ConfigCommands.java | 4 +- .../tamaya/gogo/shell/HistoryCommands.java | 36 ++-- .../tamaya/gogo/shell/SettingsCommands.java | 16 +- .../tamaya/gogo/shell/AbstractOSGITest.java | 7 +- .../OSGIConfigAdminPropertySource.java | 19 +- .../injection/OSGIConfigurationInjector.java | 18 ++ .../tamaya/karaf/shell/BackupCreateCommand.java | 7 +- .../tamaya/karaf/shell/BackupDeleteCommand.java | 7 +- .../tamaya/karaf/shell/BackupListCommand.java | 7 +- .../karaf/shell/BackupRestoreCommand.java | 4 +- .../karaf/shell/DefaultEnableCommand.java | 4 +- .../karaf/shell/DefaultEnabledCommand.java | 4 +- .../tamaya/karaf/shell/GetPolicyCommand.java | 4 +- .../karaf/shell/HistoryDeleteAllCommand.java | 9 +- .../karaf/shell/HistoryDeleteCommand.java | 9 +- .../tamaya/karaf/shell/HistoryGetCommand.java | 8 +- .../karaf/shell/HistoryMaxsizeCommand.java | 10 +- .../karaf/shell/HistoryMaxsizeSetCommand.java | 10 +- .../apache/tamaya/karaf/shell/InfoCommand.java | 7 +- .../tamaya/karaf/shell/OSGIConfigCommand.java | 4 +- .../tamaya/karaf/shell/PolicyGetCommand.java | 4 +- .../tamaya/karaf/shell/PolicySetCommand.java | 4 +- .../karaf/shell/PropagateUpdatesCommand.java | 6 +- .../karaf/shell/PropagateUpdatesSetCommand.java | 4 +- .../tamaya/karaf/shell/PropertyGetCommand.java | 4 - .../karaf/shell/PropertySourceCommand.java | 4 - .../tamaya/karaf/shell/TamayaConfigCommand.java | 5 +- .../apache/tamaya/osgi/updater/Activator.java | 6 +- .../tamaya/osgi/updater/EventListener.java | 6 +- 46 files changed, 613 insertions(+), 256 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/bnd.bnd ---------------------------------------------------------------------- diff --git a/osgi/common/bnd.bnd b/osgi/common/bnd.bnd index 4731c08..e937379 100644 --- a/osgi/common/bnd.bnd +++ b/osgi/common/bnd.bnd @@ -30,4 +30,4 @@ Import-Package: \ org.apache.tamaya.spi,\ org.apache.tamaya.functions,\ org.apache.tamaya.spisupport -Export-Service: org.apache.tamaya.osgi.TamayaConfigPlugin +Export-Service: org.apache.tamaya.osgi.commands.TamayaConfigService http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java index d3a138f..aef323d 100644 --- a/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/Activator.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.osgi; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.framework.*; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; @@ -44,7 +45,7 @@ public class Activator implements BundleActivator { private static final Logger LOG = Logger.getLogger(Activator.class.getName()); - private ServiceRegistration<TamayaConfigPlugin> registration; + private ServiceRegistration<TamayaConfigService> registration; private TamayaConfigPlugin plugin; @@ -57,9 +58,9 @@ public class Activator implements BundleActivator { this.plugin = new TamayaConfigPlugin(context); Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_RANKING, DEFAULT_RANKING); - LOG.info("Registering Tamaya OSGI Config plugin as service..."); + LOG.info("Registering Tamaya OSGI Config Service..."); registration = context.registerService( - TamayaConfigPlugin.class, + TamayaConfigService.class, this.plugin, props); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java index 6205895..0ae1048 100644 --- a/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/Backups.java @@ -32,7 +32,7 @@ import java.util.logging.Logger; * Config with Tamaya settings. This allows to restore the configuration in * case of issues. */ -public final class Backups { +final class Backups { private static final Logger LOG = Logger.getLogger(Backups.class.getName()); public static final String TAMAYA_BACKUP = "tamaya.backup"; @@ -151,7 +151,7 @@ public final class Backups { ois.close(); } } catch (Exception e) { - LOG.log(Level.WARNING, "Failed to store getConfig change history.", e); + LOG.log(Level.WARNING, "Failed to store getConfig change getHistory.", e); } } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java index cdb915c..dc41787 100644 --- a/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/ConfigHistory.java @@ -118,7 +118,7 @@ public final class ConfigHistory implements Serializable{ * Sets the maximum history size. * @param maxHistory the size */ - public static void setMaxHistory(int maxHistory){ + static void setMaxHistory(int maxHistory){ ConfigHistory.maxHistory = maxHistory; } @@ -126,7 +126,7 @@ public final class ConfigHistory implements Serializable{ * Get the max history size. * @return the max size */ - public static int getMaxHistory(){ + static int getMaxHistory(){ return maxHistory; } @@ -134,14 +134,14 @@ public final class ConfigHistory implements Serializable{ * Access the current history. * @return the current history, never null. */ - public static List<ConfigHistory> history(){ - return history(null); + static List<ConfigHistory> getHistory(){ + return getHistory(null); } /** * Clears the history. */ - public static void clearHistory(){ + static void clearHistory(){ clearHistory(null); } @@ -149,12 +149,12 @@ public final class ConfigHistory implements Serializable{ * Clears the history for a PID. * @param pid the pid, null clears the full history. */ - public static void clearHistory(String pid){ + static void clearHistory(String pid){ synchronized (history){ if("*".equals(pid)) { history.clear(); }else{ - history.removeAll(history(pid)); + history.removeAll(getHistory(pid)); } } } @@ -164,7 +164,7 @@ public final class ConfigHistory implements Serializable{ * @param pid the pid, null returns the full history. * @return */ - public static List<ConfigHistory> history(String pid) { + public static List<ConfigHistory> getHistory(String pid) { if(pid==null || pid.isEmpty()){ return new ArrayList<>(history); } @@ -214,12 +214,23 @@ public final class ConfigHistory implements Serializable{ return this; } + @Override + public String toString() { + return "ConfigHistory{" + + "timestamp=" + timestamp + + ", previousValue=" + previousValue + + ", value=" + value + + ", key='" + key + '\'' + + '}'; + } + + /** * This methd saves the (serialized) history in the plugin's OSGI configuration using * the HISTORY_KEY key. * @param osgiConfig the plugin config, not null. */ - public static void save(Dictionary<String,Object> osgiConfig){ + static void save(Dictionary<String,Object> osgiConfig){ try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); @@ -235,7 +246,7 @@ public final class ConfigHistory implements Serializable{ * Restores the history from the plugin's OSGI configuration. * @param osgiConfig */ - public static void restore(Dictionary<String,Object> osgiConfig){ + static void restore(Dictionary<String,Object> osgiConfig){ try{ String serialized = (String)osgiConfig.get(HISTORY_KEY); if(serialized!=null) { @@ -249,16 +260,6 @@ public final class ConfigHistory implements Serializable{ } } - @Override - public String toString() { - return "ConfigHistory{" + - "timestamp=" + timestamp + - ", previousValue=" + previousValue + - ", value=" + value + - ", key='" + key + '\'' + - '}'; - } - private static void checkHistorySize(){ while(history.size() > maxHistory){ history.remove(0); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java index 50c3860..e095b14 100644 --- a/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/TamayaConfigPlugin.java @@ -18,15 +18,13 @@ */ package org.apache.tamaya.osgi; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.framework.*; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; import java.io.IOException; -import java.util.Dictionary; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.Objects; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -34,7 +32,7 @@ import java.util.logging.Logger; * Tamaya plugin that updates/extends the component configurations managed * by {@link ConfigurationAdmin}, based on the configured {@link Policy}. */ -public class TamayaConfigPlugin implements BundleListener, ServiceListener{ +public class TamayaConfigPlugin implements TamayaConfigService,BundleListener, ServiceListener{ static final String COMPONENTID = "TamayaConfigPlugin"; /** the logger. */ private static final Logger LOG = Logger.getLogger(TamayaConfigPlugin.class.getName()); @@ -83,25 +81,30 @@ public class TamayaConfigPlugin implements BundleListener, ServiceListener{ initConfigs(); } + @Override public void setAutoUpdateEnabled(boolean enabled){ this.autoUpdateEnabled = enabled; setConfigValue(TAMAYA_AUTO_UPDATE_ENABLED_PROP, enabled); } + @Override public void setTamayaEnabledByDefault(boolean enabledByDefault){ this.enabledByDefault = enabledByDefault; setConfigValue(TAMAYA_ENABLED_PROP, enabledByDefault); } + @Override public boolean isTamayaEnabledByDefault(){ return enabledByDefault; } - public Policy getDefaultOperationMode(){ + @Override + public Policy getDefaultPolicy(){ return defaultPolicy; } - public void setDefaultOperationMode(Policy mode){ + @Override + public void setDefaultPolicy(Policy mode){ this.defaultPolicy = Objects.requireNonNull(mode); setConfigValue(Policy.class.getSimpleName(), defaultPolicy.toString()); } @@ -145,14 +148,17 @@ public class TamayaConfigPlugin implements BundleListener, ServiceListener{ setPluginConfig(props); } + @Override public Dictionary<String,Object> updateConfig(String pid) { return updateConfig(pid, defaultPolicy, false, false); } + @Override public Dictionary<String,Object> updateConfig(String pid, boolean dryRun) { return updateConfig(pid, defaultPolicy, false, dryRun); } + @Override public Dictionary<String,Object> updateConfig(String pid, Policy opMode, boolean explicitMode, boolean dryRun) { if(dryRun){ return configChanger.configure(pid, null, opMode, explicitMode, true); @@ -187,6 +193,7 @@ public class TamayaConfigPlugin implements BundleListener, ServiceListener{ setPluginConfig(props); } + @Override public boolean isBundleEnabled(Bundle bundle){ // Optional MANIFEST entries String bundleEnabledVal = bundle.getHeaders().get(TAMAYA_ENABLED_MANIFEST); @@ -319,19 +326,85 @@ public class TamayaConfigPlugin implements BundleListener, ServiceListener{ return configChanger.getTamayaConfiguration(root); } + @Override public boolean isAutoUpdateEnabled() { return this.autoUpdateEnabled; } - public boolean restoreBackup(String pid)throws IOException{ + @Override + public Dictionary<String, ?> getBackup(String pid) { + return Backups.get(pid); + } + + @Override + public Set<String> getBackupPids() { + return Backups.getPids(); + } + + @Override + public boolean restoreBackup(String pid){ Dictionary<String,Object> config = (Dictionary<String,Object>) Backups.get(pid); if(config==null){ return false; } - this.configChanger.restoreBackup(pid, config); - return true; + try { + this.configChanger.restoreBackup(pid, config); + return true; + } catch (IOException e) { + LOG.log(Level.WARNING, "Error restoring backup for PID: " + pid, e); + return false; + } + } + + @Override + public boolean createBackup(String pid) { + if(!Backups.contains(pid)) { + Backups.set(pid, getOSGIConfiguration(pid, null)); + return true; + } + return false; } + @Override + public boolean deleteBackup(String pid) { + if(Backups.contains(pid)) { + Backups.remove(pid); + return true; + } + return false; + } + + @Override + public void setMaxHistorySize(int maxHistory) { + ConfigHistory.setMaxHistory(maxHistory); + } + + @Override + public int getMaxHistorySize() { + return ConfigHistory.getMaxHistory(); + } + + @Override + public List<ConfigHistory> getHistory() { + return ConfigHistory.getHistory(); + } + + @Override + public void clearHistory() { + ConfigHistory.clearHistory(); + } + + @Override + public void clearHistory(String pid) { + ConfigHistory.clearHistory(pid); + } + + @Override + public List<ConfigHistory> getHistory(String pid) { + return ConfigHistory.getHistory(pid); + } + + @Override public Dictionary<String, Object> getOSGIConfiguration(String pid, String section) { try { Configuration config = configChanger.getConfigurationAdmin().getConfiguration(pid); @@ -351,6 +424,11 @@ public class TamayaConfigPlugin implements BundleListener, ServiceListener{ } } + @Override + public boolean containsBackup(String pid) { + return Backups.contains(pid); + } + private Dictionary<String, Object> filter(Dictionary<String, Object> props, String section) { Hashtable<String, Object> result = new Hashtable<>(); Enumeration<String> keys = props.keys(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java index 13c811b..d8734f7 100644 --- a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/BackupCommands.java @@ -18,8 +18,6 @@ */ package org.apache.tamaya.osgi.commands; -import org.apache.tamaya.osgi.Backups; -import org.apache.tamaya.osgi.TamayaConfigPlugin; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; @@ -28,7 +26,6 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.util.Dictionary; import java.util.Enumeration; -import java.util.Map; /** @@ -39,15 +36,16 @@ public final class BackupCommands { /** Singleton constructor. */ private BackupCommands(){} - public static String createBackup(ConfigurationAdmin cm, String pid, boolean force) throws IOException { + public static String createBackup(TamayaConfigService service, ConfigurationAdmin cm, String pid, boolean force) throws IOException { Configuration cfg = cm.getConfiguration(pid); if(cfg!=null){ Dictionary<String,?> props = cfg.getProperties(); if(props!=null){ - if(force || !Backups.contains(pid)){ - Backups.set(pid, props); - return "Backup created, PID = " + pid + '\n' + - printProps(props); + if(force && service.getBackup(pid)!=null) { + service.deleteBackup(pid); + } + if(service.createBackup(pid)){ + return "Backup created, PID = " + pid + '\n' + printProps(props); }else{ return "Creating backup failed. Backup already existing, PID = " + pid; } @@ -56,21 +54,23 @@ public final class BackupCommands { return "Creating backup failed. No Config found, PID = " + pid; } - public static String deleteBackup(String pid) throws IOException { + public static String deleteBackup(TamayaConfigService service, String pid) throws IOException { if("*".equals(pid)){ - Backups.removeAll(); + for(String current: service.getBackupPids()){ + service.deleteBackup(current); + } return "All Backups deleted."; }else { - Backups.remove(pid); + service.deleteBackup(pid); return "Backup deleted: " + pid; } } - public static String restoreBackup(TamayaConfigPlugin plugin, String pid) throws IOException { + public static String restoreBackup(TamayaConfigService plugin, String pid) throws IOException { StringBuilder b = new StringBuilder("Restored Configurations:\n") .append("------------------------\n"); if("*".equals(pid)){ - for(String current: Backups.getPids()){ + for(String current: plugin.getBackupPids()){ try{ if(plugin.restoreBackup(current)){ b.append(current).append(" -> restored.\n"); @@ -95,9 +95,9 @@ public final class BackupCommands { } } - public static String listBackup(String pid) throws IOException { + public static String listBackup(TamayaConfigService plugin, String pid) throws IOException { if(pid!=null){ - Dictionary<String, ?> props = Backups.get(pid); + Dictionary<String, ?> props = plugin.getBackup(pid); if(props==null){ return "No backup found: " + pid; }else{ @@ -107,9 +107,9 @@ public final class BackupCommands { }else { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); - for(Map.Entry<String, Dictionary<String,?>> en: Backups.get().entrySet()){ - pw.println("PID: " + en.getKey()); - pw.println(printProps(en.getValue())); + for(String current: plugin.getBackupPids()){ + pw.println("PID: " + current); + pw.println(printProps(plugin.getBackup(current))); } return sw.toString(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java index 50e8666..061b066 100644 --- a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java @@ -22,7 +22,6 @@ import org.apache.tamaya.Configuration; import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.functions.ConfigurationFunctions; import org.apache.tamaya.osgi.Policy; -import org.apache.tamaya.osgi.TamayaConfigPlugin; import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; @@ -39,10 +38,10 @@ public final class ConfigCommands { /** Singleton constructor. */ private ConfigCommands(){} - public static String getInfo(TamayaConfigPlugin configPlugin) throws IOException { + public static String getInfo(TamayaConfigService configPlugin) throws IOException { Configuration config = ConfigurationProvider.getConfiguration(); return config.toString() + "\n\n" - + StringUtil.format("Default Policy:", 30) + configPlugin.getDefaultOperationMode() + '\n' + + StringUtil.format("Default Policy:", 30) + configPlugin.getDefaultPolicy() + '\n' + StringUtil.format("Default Enabled: ", 30) + configPlugin.isTamayaEnabledByDefault(); } @@ -66,7 +65,7 @@ public final class ConfigCommands { return readTamayaConfig("["+pid+"]", filter); } - public static String applyTamayaConfiguration(TamayaConfigPlugin configPlugin, String pid, String operationMode, boolean dryRun){ + public static String applyTamayaConfiguration(TamayaConfigService configPlugin, String pid, String operationMode, boolean dryRun){ Dictionary<String,Object> config = null; if(operationMode!=null){ config = configPlugin.updateConfig(pid, Policy.valueOf(operationMode), true, dryRun); @@ -81,13 +80,13 @@ public final class ConfigCommands { return "Full configuration\n" + "------------------\n" + "PID : " + pid + "\n" + - "Policy : "+ configPlugin.getDefaultOperationMode() + "\n" + + "Policy : "+ configPlugin.getDefaultPolicy() + "\n" + "Applied : " + !dryRun + "\n" + printOSGIConfig(pid, config); } } - public static String readOSGIConfiguration(TamayaConfigPlugin configPlugin, String pid, String section) { + public static String readOSGIConfiguration(TamayaConfigService configPlugin, String pid, String section) { Dictionary<String,Object> config = configPlugin.getOSGIConfiguration(pid, section); return printOSGIConfig(pid, config); } @@ -113,13 +112,13 @@ public final class ConfigCommands { return b.toString(); } - public static String getDefaultOpPolicy(TamayaConfigPlugin configPlugin) throws IOException { - return String.valueOf(configPlugin.getDefaultOperationMode()); + public static String getDefaultOpPolicy(TamayaConfigService configPlugin) throws IOException { + return String.valueOf(configPlugin.getDefaultPolicy()); } - public static String setDefaultOpPolicy(TamayaConfigPlugin configPlugin, String policy) throws IOException { + public static String setDefaultOpPolicy(TamayaConfigService configPlugin, String policy) throws IOException { Policy opMode = Policy.valueOf(policy); - configPlugin.setDefaultOperationMode(opMode); + configPlugin.setDefaultPolicy(opMode); return "Policy="+opMode.toString(); } @@ -225,21 +224,21 @@ public final class ConfigCommands { return sw.toString(); } - public static String setDefaultEnabled(TamayaConfigPlugin configPlugin, boolean enabled) throws IOException { + public static String setDefaultEnabled(TamayaConfigService configPlugin, boolean enabled) throws IOException { configPlugin.setTamayaEnabledByDefault(enabled); - return TamayaConfigPlugin.TAMAYA_ENABLED_PROP+"="+enabled; + return TamayaConfigService.TAMAYA_ENABLED_PROP+"="+enabled; } - public static String getDefaultEnabled(TamayaConfigPlugin configPlugin) { + public static String getDefaultEnabled(TamayaConfigService configPlugin) { return String.valueOf(configPlugin.isTamayaEnabledByDefault()); } - public static String setAutoUpdateEnabled(TamayaConfigPlugin configPlugin, boolean enabled) { + public static String setAutoUpdateEnabled(TamayaConfigService configPlugin, boolean enabled) { configPlugin.setAutoUpdateEnabled(enabled); - return TamayaConfigPlugin.TAMAYA_AUTO_UPDATE_ENABLED_PROP+"="+enabled; + return TamayaConfigService.TAMAYA_AUTO_UPDATE_ENABLED_PROP+"="+enabled; } - public static String getAutoUpdateEnabled(TamayaConfigPlugin configPlugin) { + public static String getAutoUpdateEnabled(TamayaConfigService configPlugin) { return String.valueOf(configPlugin.isAutoUpdateEnabled()); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java index 03fc304..f58516d 100644 --- a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/HistoryCommands.java @@ -19,7 +19,6 @@ package org.apache.tamaya.osgi.commands; import org.apache.tamaya.osgi.ConfigHistory; -import org.apache.tamaya.osgi.TamayaConfigPlugin; import java.io.IOException; import java.io.PrintWriter; @@ -31,23 +30,23 @@ import java.util.Set; /** - * Utility class implementing the available change history related commands. + * Utility class implementing the available change getHistory related commands. */ public final class HistoryCommands{ /** Singleton constructor. */ private HistoryCommands(){} - public static String clearHistory(String pid) throws IOException { - int size = ConfigHistory.history(pid).size(); - ConfigHistory.clearHistory(pid); - return "Deleted history for PID: " + pid; + public static String clearHistory(TamayaConfigService service, String pid) throws IOException { + int size = service.getHistory(pid).size(); + service.clearHistory(pid); + return "Deleted getHistory for PID: " + pid; } - public static String getHistory(String pid, String... events) throws IOException { + public static String getHistory(TamayaConfigService service, String pid, String... events) throws IOException { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); - List<ConfigHistory> history = ConfigHistory.history(pid); + List<ConfigHistory> history = service.getHistory(pid); history = filterTypes(history, events); pw.print(StringUtil.format("Type", 10)); pw.print(StringUtil.format("PID", 30)); @@ -66,13 +65,13 @@ public final class HistoryCommands{ return sw.toString(); } - public static String getMaxHistorySize(){ - return String.valueOf(ConfigHistory.getMaxHistory()); + public static String getMaxHistorySize(TamayaConfigService service){ + return String.valueOf(service.getMaxHistorySize()); } - public static String setMaxHistorySize(int maxSize){ - ConfigHistory.setMaxHistory(maxSize); - return "tamaya-max-history-size="+maxSize; + public static String setMaxHistorySize(TamayaConfigService service, int maxSize){ + service.setMaxHistorySize(maxSize); + return "tamaya-max-getHistory-size="+maxSize; } private static List<ConfigHistory> filterTypes(List<ConfigHistory> history, String... eventTypes) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/TamayaConfigService.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/TamayaConfigService.java b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/TamayaConfigService.java new file mode 100644 index 0000000..99cd5fb --- /dev/null +++ b/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/TamayaConfigService.java @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.osgi.commands; + +import org.apache.tamaya.osgi.ConfigHistory; +import org.apache.tamaya.osgi.Policy; +import org.osgi.framework.Bundle; + +import java.util.Dictionary; +import java.util.List; +import java.util.Set; + +/** + * Service exposing the Tamaya OSGI configuration logic. + */ +public interface TamayaConfigService{ + /** The system/config property to set Tamaya's {@link Policy}. */ + String TAMAYA_POLICY_PROP = "tamaya-policy"; + /** The MANIFEST property to set Tamaya's {@link Policy}. */ + String TAMAYA_POLICY_MANIFEST = "Tamaya-Policy"; + /** The system/config property to define a customized Tamaya's configuration root, replacing the {@code [PID]} default + * prefix used. */ + String TAMAYA_CUSTOM_ROOT_PROP = "tamaya-config-root"; + /** The MANIFEST property to define a customized Tamaya's configuration root, replacing the {@code [PID]} default + * prefix used. */ + String TAMAYA_CUSTOM_ROOT_MANIFEST = "Tamaya-Config-Root"; + /** The system/config property to enable Tamaya. */ + String TAMAYA_ENABLED_PROP = "tamaya-enabled"; + /** The MANIFEST property to enable Tamaya. */ + String TAMAYA_ENABLED_MANIFEST = "Tamaya-Enabled"; + /** The system/config property to enable Tamaya automatic updates (requires Tamaya's Updater plugin to be loaded as well). */ + String TAMAYA_AUTO_UPDATE_ENABLED_PROP = "tamaya-update-enabled"; + /** The MANIFEST property to enable Tamaya automatic updates (requires Tamaya's Updater plugin to be loaded as well). */ + String TAMAYA_AUTO_UPDATE_ENABLED_MANIFEST = "Tamaya-Update-Enabled"; + + /** + * Enables/disables automatic updates (requires Tamaya's Updater plugin to be loaded as well). + * @param enabled set to true to enable updates. + */ + void setAutoUpdateEnabled(boolean enabled); + + /** + * Enables/disables Tamaya config by default. + * @param enabled set to true to enable Tamaya for all bundles by default. + */ + void setTamayaEnabledByDefault(boolean enabled); + + /** + * Get the flag, if Tamaya is enabled by default for all bundles. + * @return true if Tamaya is enabled. + */ + boolean isTamayaEnabledByDefault(); + + /** + * Get the default policy Tamaya is using for adapting OSGI configuration. + * @return the default policy, never null. + */ + Policy getDefaultPolicy(); + + /** + * Set the default policy Tamaya is using for adapting OSGI configuration. + * @param policy the policy, not null. + */ + void setDefaultPolicy(Policy policy); + + /** + * Updates the given OSGI configuration with Tamaya configuration. + * @param pid the target PID, not null. + * @return the new configuration. + */ + Dictionary<String,Object> updateConfig(String pid); + + /** + * Updates the given OSGI configuration with Tamaya configuration. + * @param pid the target PID, not null. + * @param dryRun if true, the changes will not be applied to the OSGI configuration. + * @return the configuration that would be applied, has been applied. + */ + Dictionary<String,Object> updateConfig(String pid, boolean dryRun); + + /** + * Updates the given OSGI configuration with Tamaya configuration. + * @param pid the target PID, not null. + * @param policy the updating policy to be used, by default. + * @param forcePolicy if set to true, the given policy will be used, even if an alternate policy is configured + * for the given PID. + * @param dryRun if true, the changes will not be applied to the OSGI configuration. + * @return the configuration that would be applied, has been applied. + */ + Dictionary<String,Object> updateConfig(String pid, Policy policy, boolean forcePolicy, boolean dryRun); + + /** + * Checks if a bundle is enabled for Tamaya configuration. + * @param bundle the bundle, not null. + * @return true, if the bundle is enabled. + */ + boolean isBundleEnabled(Bundle bundle); + + /** + * Get the flag if automatic updates for config changes are enabled. + * @return true, if automatic updates for config changes are enabled. + */ + boolean isAutoUpdateEnabled(); + + /** + * Get the backup written for a PID. + * @param pid the pid, not null. + * @return the backup, or null, if no backup is present. + */ + Dictionary<String,?> getBackup(String pid); + + /** + * Get all current known PIDs for which backups are registered. + * @return all known PIDs for which backups are registered. + */ + Set<String> getBackupPids(); + + /** + * Restores a backup, replacing the current OSGI configuration with the backup and + * disabling Tamaya for this PID. + * @param pid the PID, not null. + * @return true, if a backup has been restored successfully. + */ + boolean restoreBackup(String pid); + + /** + * Stores the current OSGI configuration as a backup (only if no backup is existing). + * @param pid the target PID, not null. + * @return true, if a backup has been stored successfully. + */ + boolean createBackup(String pid); + + /** + * Deletes a backup, if existing. + * @param pid the target PID, not null. + * @return true, if a backup has been restored successfully. + */ + boolean deleteBackup(String pid); + + /** + * Sets the maximum getHistory size. + * @param maxHistory the max getHistory size. {@code 0} disables the getHistory function. + */ + void setMaxHistorySize(int maxHistory); + + /** + * Get the max getHistory size. + * @return the max getHistory size. {@code 0} means the getHistory function is disabled. + */ + int getMaxHistorySize(); + + /** + * Access the current (full) change getHistory. + * @return the current getHistory, never null. + */ + List<ConfigHistory> getHistory(); + + /** + * Clears the getHistory. + */ + void clearHistory(); + + /** + * Clears the getHistory for a PID. + * @param pid the target PID, not null. + */ + void clearHistory(String pid); + + /** + * Get the getHistory for a PID. + * @param pid the target PID, not null. + * @return the PID's getHistory, never null. + */ + List<ConfigHistory> getHistory(String pid); + + /** + * Access the current OSGI configuration for a PID. + * @param pid the target PID, not null. + * @param section a subsection to be filter (using startsWith). + * @return the (optionally filtered) OSGI configuration. + */ + Dictionary<String,Object> getOSGIConfiguration(String pid, String section); + + /** + * Checks if a backup exists. + * @param pid the target PID, not null. + * @return true, if a backup exists. + */ + boolean containsBackup(String pid); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java index 3794afa..20f6fea 100644 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java +++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/AbstractOSGITest.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.osgi; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.junit.Before; import org.mockito.Mock; import org.mockito.stubbing.Answer; @@ -53,7 +54,7 @@ public abstract class AbstractOSGITest { @Mock private ServiceReference<TamayaConfigPlugin> tamayaRef; - protected TamayaConfigPlugin tamayaConfigPlugin; + protected TamayaConfigService tamayaConfigPlugin; protected Dictionary<String,Object> getProperties(String pid){ return this.properties.get(pid); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java index 35a402b..c1510f8 100644 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java +++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/ActivatorTest.java @@ -18,6 +18,7 @@ */ package org.apache.tamaya.osgi; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; @@ -36,7 +37,7 @@ public class ActivatorTest extends AbstractOSGITest{ public void startStop() throws Exception { Activator activator = new Activator(); activator.start(super.bundleContext); - verify(bundleContext).registerService(eq(TamayaConfigPlugin.class), anyObject(), anyObject()); + verify(bundleContext).registerService(eq(TamayaConfigService.class), anyObject(), anyObject()); activator.stop(super.bundleContext); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java index 7e58176..a829f7b 100644 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java +++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/ConfigHistoryTest.java @@ -69,9 +69,9 @@ public class ConfigHistoryTest { @Test public void history() throws Exception { for(int i=0;i<100;i++){ - ConfigHistory.propertySet("history", "history"+i, "prev"+i, "new"+i); + ConfigHistory.propertySet("getHistory", "getHistory"+i, "prev"+i, "new"+i); } - List<ConfigHistory> hist = ConfigHistory.history(); + List<ConfigHistory> hist = ConfigHistory.getHistory(); assertNotNull(hist); assertTrue(hist.size()>=100); } @@ -80,19 +80,19 @@ public class ConfigHistoryTest { public void history_pid() throws Exception { ConfigHistory.configuring("history1", "history_pid"); for(int i=0;i<100;i++){ - ConfigHistory.propertySet("history1", "history"+i, "prev"+i, "new"+i); + ConfigHistory.propertySet("history1", "getHistory"+i, "prev"+i, "new"+i); } ConfigHistory.configured("history1", "history_pid"); for(int i=0;i<100;i++){ - ConfigHistory.propertySet("history2", "history"+i, "prev"+i, "new"+i); + ConfigHistory.propertySet("history2", "getHistory"+i, "prev"+i, "new"+i); } - List<ConfigHistory> hist = ConfigHistory.history("history1"); + List<ConfigHistory> hist = ConfigHistory.getHistory("history1"); assertNotNull(hist); assertTrue(hist.size()==102); - hist = ConfigHistory.history("history2"); + hist = ConfigHistory.getHistory("history2"); assertNotNull(hist); assertTrue(hist.size()==100); - hist = ConfigHistory.history(null); + hist = ConfigHistory.getHistory(null); assertNotNull(hist); assertTrue(hist.size()>=202); } @@ -100,21 +100,21 @@ public class ConfigHistoryTest { @Test public void clearHistory() throws Exception { for(int i=0;i<100;i++){ - ConfigHistory.propertySet("history3", "history"+i, "prev"+i, "new"+i); + ConfigHistory.propertySet("history3", "getHistory"+i, "prev"+i, "new"+i); } for(int i=0;i<100;i++){ - ConfigHistory.propertySet("history4", "history"+i, "prev"+i, "new"+i); + ConfigHistory.propertySet("history4", "getHistory"+i, "prev"+i, "new"+i); } - List<ConfigHistory> hist = ConfigHistory.history("history3"); + List<ConfigHistory> hist = ConfigHistory.getHistory("history3"); assertNotNull(hist); assertTrue(hist.size()==100); - assertEquals(ConfigHistory.history("history4").size(), 100); + assertEquals(ConfigHistory.getHistory("history4").size(), 100); ConfigHistory.clearHistory("history3"); - assertEquals(ConfigHistory.history("history3").size(), 0); - assertEquals(ConfigHistory.history("history4").size(), 100); + assertEquals(ConfigHistory.getHistory("history3").size(), 0); + assertEquals(ConfigHistory.getHistory("history4").size(), 100); ConfigHistory.clearHistory(null); - assertEquals(ConfigHistory.history().size(), 0); - assertEquals(ConfigHistory.history("history4").size(), 0); + assertEquals(ConfigHistory.getHistory().size(), 0); + assertEquals(ConfigHistory.getHistory("history4").size(), 0); } @@ -133,16 +133,16 @@ public class ConfigHistoryTest { @Test public void saveRestore() throws Exception { for(int i=0;i<10;i++){ - ConfigHistory.propertySet("save", "history"+i, "prev"+i, "new"+i); + ConfigHistory.propertySet("save", "getHistory"+i, "prev"+i, "new"+i); } - assertEquals(ConfigHistory.history("save").size(), 10); + assertEquals(ConfigHistory.getHistory("save").size(), 10); Dictionary<String,Object> config = new Hashtable<>(); ConfigHistory.save(config); - assertEquals(ConfigHistory.history("save").size(), 10); + assertEquals(ConfigHistory.getHistory("save").size(), 10); ConfigHistory.clearHistory(); - assertEquals(ConfigHistory.history("save").size(), 0); + assertEquals(ConfigHistory.getHistory("save").size(), 0); ConfigHistory.restore(config); - assertEquals(ConfigHistory.history("save").size(), 10); + assertEquals(ConfigHistory.getHistory("save").size(), 10); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java index 9758c08..d597557 100644 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java +++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java @@ -40,10 +40,10 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ @Test public void testOperationMode() throws Exception { - Policy om = tamayaConfigPlugin.getDefaultOperationMode(); - tamayaConfigPlugin.setDefaultOperationMode(Policy.EXTEND); - assertEquals(Policy.EXTEND, tamayaConfigPlugin.getDefaultOperationMode()); - tamayaConfigPlugin.setDefaultOperationMode(Policy.OVERRIDE); + Policy om = tamayaConfigPlugin.getDefaultPolicy(); + tamayaConfigPlugin.setDefaultPolicy(Policy.EXTEND); + assertEquals(Policy.EXTEND, tamayaConfigPlugin.getDefaultPolicy()); + tamayaConfigPlugin.setDefaultPolicy(Policy.OVERRIDE); } @Test @@ -67,21 +67,21 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ @Test public void testSetPluginConfig() throws Exception { Dictionary<String,Object> config = new Hashtable<>(); - tamayaConfigPlugin.setPluginConfig(config); - assertEquals(tamayaConfigPlugin.getPluginConfig(), config); + ((TamayaConfigPlugin)tamayaConfigPlugin).setPluginConfig(config); + assertEquals(((TamayaConfigPlugin)tamayaConfigPlugin).getPluginConfig(), config); } @Test public void testSetGetConfigValue() throws Exception { Dictionary<String,Object> config = new Hashtable<>(); - String val = (String)tamayaConfigPlugin.getConfigValue("foo"); - tamayaConfigPlugin.setConfigValue("bar", "foo"); - assertEquals(tamayaConfigPlugin.getConfigValue("bar"), "foo"); + String val = (String)((TamayaConfigPlugin)tamayaConfigPlugin).getConfigValue("foo"); + ((TamayaConfigPlugin)tamayaConfigPlugin).setConfigValue("bar", "foo"); + assertEquals(((TamayaConfigPlugin)tamayaConfigPlugin).getConfigValue("bar"), "foo"); } @Test public void getTMUpdateConfig() throws Exception { - org.apache.tamaya.Configuration config = tamayaConfigPlugin.getTamayaConfiguration("java."); + org.apache.tamaya.Configuration config = ((TamayaConfigPlugin)tamayaConfigPlugin).getTamayaConfiguration("java."); assertNotNull(config); assertNull(config.get("jlkjllj")); assertEquals(config.get("home"),System.getProperty("java.home")); @@ -110,24 +110,24 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ @Test public void getPluginConfig() throws Exception { - Dictionary<String, Object> config = tamayaConfigPlugin.getPluginConfig(); + Dictionary<String, Object> config = ((TamayaConfigPlugin)tamayaConfigPlugin).getPluginConfig(); assertNotNull(config); assertEquals(config, super.getProperties(TamayaConfigPlugin.COMPONENTID)); } @Test public void getDefaultOperationMode() throws Exception { - Policy om = tamayaConfigPlugin.getDefaultOperationMode(); + Policy om = tamayaConfigPlugin.getDefaultPolicy(); assertNotNull(om); Dictionary<String,Object> pluginConfig = super.getProperties(TamayaConfigPlugin.COMPONENTID); pluginConfig.put(Policy.class.getSimpleName(), Policy.UPDATE_ONLY.toString()); TamayaConfigPlugin plugin = new TamayaConfigPlugin(bundleContext); - om = plugin.getDefaultOperationMode(); + om = plugin.getDefaultPolicy(); assertNotNull(om); assertEquals(om, Policy.UPDATE_ONLY); pluginConfig.put(Policy.class.getSimpleName(), Policy.OVERRIDE.toString()); plugin = new TamayaConfigPlugin(bundleContext); - om = plugin.getDefaultOperationMode(); + om = plugin.getDefaultPolicy(); assertNotNull(om); assertEquals(om, Policy.OVERRIDE); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java index c7a5f62..20d2a78 100644 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java +++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/BackupCommandsTest.java @@ -19,8 +19,6 @@ package org.apache.tamaya.osgi.commands; import org.apache.tamaya.osgi.AbstractOSGITest; -import org.apache.tamaya.osgi.Backups; -import org.apache.tamaya.osgi.TamayaConfigPlugin; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; @@ -36,47 +34,47 @@ import static org.junit.Assert.*; public class BackupCommandsTest extends AbstractOSGITest { @Test public void createBackup() throws Exception { - String result = BackupCommands.createBackup(cm, "createBackup", false); + String result = BackupCommands.createBackup(tamayaConfigPlugin, cm, "createBackup", false); assertNotNull(result); assertTrue(result.contains("createBackup")); assertTrue(result.contains("Backup created")); - assertTrue(Backups.contains("createBackup")); + assertTrue(tamayaConfigPlugin.containsBackup("createBackup")); // A backup with the given name already exists, so it fails - result = BackupCommands.createBackup(cm, "createBackup", false); + result = BackupCommands.createBackup(tamayaConfigPlugin, cm, "createBackup", false); assertNotNull(result); assertTrue(result.contains("createBackup")); assertTrue(result.contains("Creating backup failed")); assertTrue(result.contains("already existing")); - assertTrue(Backups.contains("createBackup")); + assertTrue(tamayaConfigPlugin.containsBackup("createBackup")); // any existing backups gets overridden - result = BackupCommands.createBackup(cm, "createBackup", true); + result = BackupCommands.createBackup(tamayaConfigPlugin, cm, "createBackup", true); assertNotNull(result); assertTrue(result.contains("createBackup")); assertTrue(result.contains("Backup created")); - assertTrue(Backups.contains("createBackup")); + assertTrue(tamayaConfigPlugin.containsBackup("createBackup")); } @Test public void deleteBackup() throws Exception { - BackupCommands.createBackup(cm, "deleteBackup", false); - assertTrue(Backups.contains("deleteBackup")); - String result = BackupCommands.deleteBackup("deleteBackup"); + BackupCommands.createBackup(tamayaConfigPlugin, cm, "deleteBackup", false); + assertTrue(tamayaConfigPlugin.containsBackup("deleteBackup")); + String result = BackupCommands.deleteBackup(tamayaConfigPlugin, "deleteBackup"); assertNotNull(result); assertTrue(result.contains("deleteBackup")); assertTrue(result.contains("Backup deleted")); - assertFalse(Backups.contains("deleteBackup")); + assertFalse(tamayaConfigPlugin.containsBackup("deleteBackup")); } @Test public void restoreBackup() throws Exception { - BackupCommands.createBackup(cm, "restoreBackup", false); - assertTrue(Backups.contains("restoreBackup")); + BackupCommands.createBackup(tamayaConfigPlugin, cm, "restoreBackup", false); + assertTrue(tamayaConfigPlugin.containsBackup("restoreBackup")); String result = BackupCommands.restoreBackup(tamayaConfigPlugin, "restoreBackup"); assertNotNull(result); assertTrue(result.contains("restoreBackup")); assertTrue(result.contains("Backup restored")); - BackupCommands.deleteBackup("restoreBackup"); - assertFalse(Backups.contains("restoreBackup")); + BackupCommands.deleteBackup(tamayaConfigPlugin, "restoreBackup"); + assertFalse(tamayaConfigPlugin.containsBackup("restoreBackup")); result = BackupCommands.restoreBackup(tamayaConfigPlugin, "restoreBackup"); assertTrue(result.contains("Backup restore failed")); assertTrue(result.contains("no backup found")); @@ -84,8 +82,8 @@ public class BackupCommandsTest extends AbstractOSGITest { @Test public void listBackup() throws Exception { - BackupCommands.createBackup(cm, "listBackup", false); - String result = BackupCommands.listBackup("listBackup"); + BackupCommands.createBackup(tamayaConfigPlugin, cm, "listBackup", false); + String result = BackupCommands.listBackup(tamayaConfigPlugin, "listBackup"); result.concat("listBackup"); result.contains("pid"); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java index 41a43b7..a2c273b 100644 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java +++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java @@ -20,7 +20,6 @@ package org.apache.tamaya.osgi.commands; import org.apache.tamaya.osgi.AbstractOSGITest; import org.apache.tamaya.osgi.Policy; -import org.apache.tamaya.osgi.TamayaConfigPlugin; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; @@ -96,7 +95,7 @@ public class ConfigCommandsTest extends AbstractOSGITest{ @Test public void getDefaultOpPolicy() throws Exception { - Policy mode = tamayaConfigPlugin.getDefaultOperationMode(); + Policy mode = tamayaConfigPlugin.getDefaultPolicy(); String result = ConfigCommands.getDefaultOpPolicy(tamayaConfigPlugin); assertNotNull(result); assertTrue(result.contains(mode.toString())); @@ -107,11 +106,11 @@ public class ConfigCommandsTest extends AbstractOSGITest{ String result = ConfigCommands.setDefaultOpPolicy(tamayaConfigPlugin, Policy.EXTEND.toString()); assertNotNull(result); assertTrue(result.contains("EXTEND")); - assertEquals(tamayaConfigPlugin.getDefaultOperationMode(), Policy.EXTEND); + assertEquals(tamayaConfigPlugin.getDefaultPolicy(), Policy.EXTEND); result = ConfigCommands.setDefaultOpPolicy(tamayaConfigPlugin, Policy.UPDATE_ONLY.toString()); assertNotNull(result); assertTrue(result.contains("UPDATE_ONLY")); - assertEquals(tamayaConfigPlugin.getDefaultOperationMode(), Policy.UPDATE_ONLY); + assertEquals(tamayaConfigPlugin.getDefaultPolicy(), Policy.UPDATE_ONLY); } @Test @@ -156,11 +155,11 @@ public class ConfigCommandsTest extends AbstractOSGITest{ String result = ConfigCommands.setDefaultEnabled(tamayaConfigPlugin, true); assertNotNull(result); System.out.println(result); - assertTrue(result.contains(TamayaConfigPlugin.TAMAYA_ENABLED_PROP+"=true")); + assertTrue(result.contains(TamayaConfigService.TAMAYA_ENABLED_PROP+"=true")); assertTrue(tamayaConfigPlugin.isTamayaEnabledByDefault()); result = ConfigCommands.setDefaultEnabled(tamayaConfigPlugin, false); assertNotNull(result); - assertTrue(result.contains(TamayaConfigPlugin.TAMAYA_ENABLED_PROP+"=false")); + assertTrue(result.contains(TamayaConfigService.TAMAYA_ENABLED_PROP+"=false")); assertFalse(tamayaConfigPlugin.isTamayaEnabledByDefault()); } @@ -181,12 +180,12 @@ public class ConfigCommandsTest extends AbstractOSGITest{ assertNotNull(result); System.out.println(result); assertTrue(result.contains("true")); - assertTrue(result.contains(TamayaConfigPlugin.TAMAYA_AUTO_UPDATE_ENABLED_PROP)); + assertTrue(result.contains(TamayaConfigService.TAMAYA_AUTO_UPDATE_ENABLED_PROP)); assertTrue(tamayaConfigPlugin.isAutoUpdateEnabled()); result = ConfigCommands.setAutoUpdateEnabled(tamayaConfigPlugin, false); assertNotNull(result); assertTrue(result.contains("false")); - assertTrue(result.contains(TamayaConfigPlugin.TAMAYA_AUTO_UPDATE_ENABLED_PROP)); + assertTrue(result.contains(TamayaConfigService.TAMAYA_AUTO_UPDATE_ENABLED_PROP)); assertFalse(tamayaConfigPlugin.isAutoUpdateEnabled()); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java ---------------------------------------------------------------------- diff --git a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java index 44c61ed..ad32857 100644 --- a/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java +++ b/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/HistoryCommandsTest.java @@ -18,35 +18,40 @@ */ package org.apache.tamaya.osgi.commands; +import org.apache.tamaya.osgi.AbstractOSGITest; import org.apache.tamaya.osgi.ConfigHistory; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; import static org.junit.Assert.*; /** * Created by atsti on 30.09.2017. */ -public class HistoryCommandsTest { +@RunWith(MockitoJUnitRunner.class) +public class HistoryCommandsTest extends AbstractOSGITest { + @Test public void clearHistory() throws Exception { ConfigHistory.configured("clearHistory1", "test"); ConfigHistory.configured("clearHistory2", "test"); - assertTrue(ConfigHistory.history("clearHistory1").size()==1); - assertTrue(ConfigHistory.history("clearHistory2").size()==1); - assertTrue(ConfigHistory.history("clearHistory3").size()==0); - String result = HistoryCommands.clearHistory("clearHistory1"); + assertTrue(ConfigHistory.getHistory("clearHistory1").size()==1); + assertTrue(ConfigHistory.getHistory("clearHistory2").size()==1); + assertTrue(ConfigHistory.getHistory("clearHistory3").size()==0); + String result = HistoryCommands.clearHistory(tamayaConfigPlugin, "clearHistory1"); assertTrue(result.contains("PID")); assertTrue(result.contains("clearHistory1")); - assertTrue(ConfigHistory.history("clearHistory1").size()==0); - assertTrue(ConfigHistory.history("clearHistory2").size()==1); - assertTrue(ConfigHistory.history("clearHistory3").size()==0); + assertTrue(ConfigHistory.getHistory("clearHistory1").size()==0); + assertTrue(ConfigHistory.getHistory("clearHistory2").size()==1); + assertTrue(ConfigHistory.getHistory("clearHistory3").size()==0); ConfigHistory.configured("clearHistory1", "test"); - result = HistoryCommands.clearHistory("*"); + result = HistoryCommands.clearHistory(tamayaConfigPlugin, "*"); assertTrue(result.contains("PID")); assertTrue(result.contains("*")); - assertTrue(ConfigHistory.history("clearHistory1").size()==0); - assertTrue(ConfigHistory.history("clearHistory2").size()==0); - assertTrue(ConfigHistory.history("clearHistory3").size()==0); + assertTrue(ConfigHistory.getHistory("clearHistory1").size()==0); + assertTrue(ConfigHistory.getHistory("clearHistory2").size()==0); + assertTrue(ConfigHistory.getHistory("clearHistory3").size()==0); } @@ -56,12 +61,12 @@ public class HistoryCommandsTest { ConfigHistory.configuring("getHistory", "test"); ConfigHistory.propertySet("getHistory", "k1", "v1", null); ConfigHistory.propertySet("getHistory", "k2", null, "v2"); - String result = HistoryCommands.getHistory("getHistory"); + String result = HistoryCommands.getHistory(tamayaConfigPlugin, "getHistory"); assertNotNull(result); assertTrue(result.contains("k1")); assertTrue(result.contains("v1")); assertTrue(result.contains("test")); - result = HistoryCommands.getHistory("getHistory", ConfigHistory.TaskType.BEGIN.toString()); + result = HistoryCommands.getHistory(tamayaConfigPlugin, "getHistory", ConfigHistory.TaskType.BEGIN.toString()); assertNotNull(result); assertTrue(result.contains("getHistory")); assertTrue(result.contains("test")); @@ -71,11 +76,11 @@ public class HistoryCommandsTest { @Test public void getSetMaxHistorySize() throws Exception { - String result = HistoryCommands.getMaxHistorySize(); - assertEquals(result, String.valueOf(ConfigHistory.getMaxHistory())); - result = HistoryCommands.setMaxHistorySize(111); - assertEquals(result, "tamaya-max-history-size=111"); - result = HistoryCommands.getMaxHistorySize(); + String result = HistoryCommands.getMaxHistorySize(tamayaConfigPlugin); + assertEquals(result, String.valueOf(tamayaConfigPlugin.getMaxHistorySize())); + result = HistoryCommands.setMaxHistorySize(tamayaConfigPlugin, 111); + assertEquals(result, "tamaya-max-getHistory-size=111"); + result = HistoryCommands.getMaxHistorySize(tamayaConfigPlugin); assertEquals(result, "111"); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java index 33fd333..67c7b66 100644 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/BackupCommands.java @@ -20,7 +20,7 @@ package org.apache.tamaya.gogo.shell; import org.apache.felix.service.command.Descriptor; import org.apache.felix.service.command.Parameter; -import org.apache.tamaya.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.cm.ConfigurationAdmin; @@ -47,26 +47,32 @@ public class BackupCommands { @Descriptor("The PID (requred)") String pid, @Parameter(absentValue = Parameter.UNSPECIFIED, names={"-f", "--force"}) @Descriptor("If set any existing backup will be overriden, default is false.") Boolean force) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.createBackup(getService(ConfigurationAdmin.class), pid, force)); + System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.createBackup( + getService(TamayaConfigService.class), + getService(ConfigurationAdmin.class), pid, force)); } @Descriptor("Deletes an OSGI ConfigAdmin configuration backup for a PID.") public void tm_backup_delete(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) @Descriptor("The target PID") String pid) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.deleteBackup(pid)); + System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.deleteBackup( + getService(TamayaConfigService.class), + pid)); } @Descriptor("Restores an OSGI ConfigAdmin configuration backup for a PID and disabled Tamaya for the given PID.") public void tm_backup_restore(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) @Descriptor("The target PID") String pid) throws IOException { System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.restoreBackup( - getService(TamayaConfigPlugin.class), pid)); + getService(TamayaConfigService.class), pid)); } @Descriptor("Shows the contents of the OSGI ConfigAdmin configuration backup for a PID.") public void tm_backup_get(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) @Descriptor("The PID (requred)") String pid) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.listBackup(Objects.requireNonNull(pid))); + System.out.println(org.apache.tamaya.osgi.commands.BackupCommands.listBackup( + getService(TamayaConfigService.class), + Objects.requireNonNull(pid))); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java index addd5c5..8926ede 100644 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/ConfigCommands.java @@ -21,7 +21,7 @@ package org.apache.tamaya.gogo.shell; import org.apache.felix.service.command.Descriptor; import org.apache.felix.service.command.Parameter; import org.apache.tamaya.osgi.Policy; -import org.apache.tamaya.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -63,7 +63,7 @@ public class ConfigCommands { @Descriptor("If set to true no OSGI configuration gets changed.") boolean dryRun){ System.out.println(org.apache.tamaya.osgi.commands.ConfigCommands.applyTamayaConfiguration( - getService(TamayaConfigPlugin.class), pid, policy.toString(), dryRun)); + getService(TamayaConfigService.class), pid, policy.toString(), dryRun)); } @Descriptor("Gets the detailed property values.") http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java index 54ca024..906f471 100644 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/HistoryCommands.java @@ -20,6 +20,7 @@ package org.apache.tamaya.gogo.shell; import org.apache.felix.service.command.Descriptor; import org.apache.felix.service.command.Parameter; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -39,39 +40,50 @@ public class HistoryCommands { this.context = Objects.requireNonNull(context); } - @Descriptor("Deletes the history of configuration changes.") + @Descriptor("Deletes the getHistory of configuration changes.") public void tm_history_delete(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--pid"}) @Descriptor("The PID.") String pid) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.clearHistory(pid)); + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.clearHistory( + getService(TamayaConfigService.class), + pid)); } - @Descriptor("Deletes the full history of configuration changes.") + @Descriptor("Deletes the full getHistory of configuration changes.") public void tm_history_delete_all() throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.clearHistory(null)); + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.clearHistory( + getService(TamayaConfigService.class), + null)); } - @Descriptor("Read the history of configuration changes.") + @Descriptor("Read the getHistory of configuration changes.") public void tm_history_get(@Parameter(absentValue = "", names={"-p", "--pid"}) @Descriptor("The PID.")String pid, @Parameter(absentValue = "", names={"-t", "--eventtypes"}) @Descriptor("The comma separated Event types to filter, valid types are " + "PROPERTY,BEGIN,END")String eventTypes) throws IOException { if(eventTypes.isEmpty()){ - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.getHistory(pid, null)); + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.getHistory( + getService(TamayaConfigService.class), + pid, null)); }else { - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.getHistory(pid, eventTypes.split(","))); + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.getHistory( + getService(TamayaConfigService.class), + pid, eventTypes.split(","))); } } - @Descriptor("Get the maximum configuration change history size.") + @Descriptor("Get the maximum configuration change getHistory size.") public void tm_history_maxsize() throws IOException { - System.out.println(String.valueOf(org.apache.tamaya.osgi.commands.HistoryCommands.getMaxHistorySize())); + System.out.println(String.valueOf(org.apache.tamaya.osgi.commands.HistoryCommands.getMaxHistorySize( + getService(TamayaConfigService.class)))); } - @Descriptor("Sets the maximum configuration change history size.") + @Descriptor("Sets the maximum configuration change getHistory size.") public void tm_history_maxsize_set(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-s", "--size"}) - @Descriptor("The maximum size of history entries stored.")int maxSize) throws IOException { - System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.setMaxHistorySize(maxSize)); + @Descriptor("The maximum size of getHistory entries stored.")int maxSize) throws IOException { + System.out.println(org.apache.tamaya.osgi.commands.HistoryCommands.setMaxHistorySize( + getService(TamayaConfigService.class), + maxSize)); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java index 6275242..cf79f0a 100644 --- a/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java +++ b/osgi/gogo-shell/src/main/java/org/apache/tamaya/gogo/shell/SettingsCommands.java @@ -21,8 +21,8 @@ package org.apache.tamaya.gogo.shell; import org.apache.felix.service.command.Descriptor; import org.apache.felix.service.command.Parameter; import org.apache.tamaya.osgi.Policy; -import org.apache.tamaya.osgi.TamayaConfigPlugin; import org.apache.tamaya.osgi.commands.ConfigCommands; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; @@ -45,39 +45,39 @@ public class SettingsCommands { @Descriptor("Allows to disable/enable Tamaya configuration by default.") public void tm_enable(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-e", "--enable"}) @Descriptor("if true Tamaya is enabled by default (default=false)") boolean enabled) throws IOException { - System.out.println(ConfigCommands.setDefaultEnabled(getService(TamayaConfigPlugin.class), enabled)); + System.out.println(ConfigCommands.setDefaultEnabled(getService(TamayaConfigService.class), enabled)); } @Descriptor("Access if Tamaya is currently enabled by default to change OSGI configuration.") public void tm_enabled(){ - System.out.println(ConfigCommands.getDefaultEnabled(getService(TamayaConfigPlugin.class))); + System.out.println(ConfigCommands.getDefaultEnabled(getService(TamayaConfigService.class))); } @Descriptor("Get the default Tamaya configuration policy.") public void tm_policy() throws IOException { - System.out.println(ConfigCommands.getDefaultOpPolicy(getService(TamayaConfigPlugin.class))); + System.out.println(ConfigCommands.getDefaultOpPolicy(getService(TamayaConfigService.class))); } @Descriptor("Set the default Tamaya configuration policy.") public void tm_policy_set(@Parameter(absentValue = Parameter.UNSPECIFIED, names={"-p", "--policy"}) @Descriptor("The policy to apply (required), one of: EXTEND, OVERRIDE, UPDATE_ONLY") Policy policy) throws IOException { - System.out.println(ConfigCommands.setDefaultOpPolicy(getService(TamayaConfigPlugin.class), policy.toString())); + System.out.println(ConfigCommands.setDefaultOpPolicy(getService(TamayaConfigService.class), policy.toString())); } @Descriptor("Get info about the current Tamaya configuration settings.") public void tm_info() throws IOException { - System.out.println(ConfigCommands.getInfo(getService(TamayaConfigPlugin.class))); + System.out.println(ConfigCommands.getInfo(getService(TamayaConfigService.class))); } @Descriptor("Flag if Tamaya is automatically triggering OSGI config updates, when according " + "Tamaya configuration changes.") public void tm_propagate_updates() throws IOException { - System.out.println(getService(TamayaConfigPlugin.class).isAutoUpdateEnabled()); + System.out.println(getService(TamayaConfigService.class).isAutoUpdateEnabled()); } @Descriptor("Configure if Tamaya is automatically triggering OSGI config updates, when according " + "Tamaya configuration changes.") public void tm_propagate_updates_set(boolean enabled) throws IOException { - System.out.println(ConfigCommands.setAutoUpdateEnabled(getService(TamayaConfigPlugin.class), enabled)); + System.out.println(ConfigCommands.setAutoUpdateEnabled(getService(TamayaConfigService.class), enabled)); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java ---------------------------------------------------------------------- diff --git a/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java b/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java index 511769a..918ff97 100644 --- a/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java +++ b/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/AbstractOSGITest.java @@ -19,6 +19,7 @@ package org.apache.tamaya.gogo.shell; import org.apache.tamaya.osgi.TamayaConfigPlugin; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.junit.Before; import org.mockito.Mock; import org.osgi.framework.Bundle; @@ -51,9 +52,9 @@ public abstract class AbstractOSGITest { @Mock private ServiceReference<ConfigurationAdmin> cmRef; @Mock - private ServiceReference<TamayaConfigPlugin> tamayaRef; + private ServiceReference<TamayaConfigService> tamayaRef; - protected TamayaConfigPlugin tamayaConfigPlugin; + protected TamayaConfigService tamayaConfigPlugin; protected Dictionary<String,Object> getProperties(String pid){ return this.properties.get(pid); @@ -70,7 +71,7 @@ public abstract class AbstractOSGITest { doReturn(new Bundle[0]).when(bundleContext).getBundles(); doReturn(cmRef).when(bundleContext).getServiceReference(ConfigurationAdmin.class); doReturn(cm).when(bundleContext).getService(cmRef); - doReturn(tamayaRef).when(bundleContext).getServiceReference(TamayaConfigPlugin.class); + doReturn(tamayaRef).when(bundleContext).getServiceReference(TamayaConfigService.class); tamayaConfigPlugin = new TamayaConfigPlugin(bundleContext); doReturn(tamayaConfigPlugin).when(bundleContext).getService(tamayaRef); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java b/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java index 6689b31..529468e 100644 --- a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java +++ b/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java @@ -1,6 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.tamaya.osgi.injection; -import org.apache.tamaya.spi.PropertySource; import org.apache.tamaya.spi.PropertyValue; import org.apache.tamaya.spisupport.BasePropertySource; import org.osgi.service.cm.Configuration; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java ---------------------------------------------------------------------- diff --git a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java b/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java index ddec058..656f565 100644 --- a/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java +++ b/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.tamaya.osgi.injection; import org.apache.tamaya.Configuration; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java index 4aa3f8d..dda367a 100644 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupCreateCommand.java @@ -22,8 +22,10 @@ import org.apache.karaf.shell.api.action.Action; import org.apache.karaf.shell.api.action.Argument; import org.apache.karaf.shell.api.action.Command; import org.apache.karaf.shell.api.action.Option; +import org.apache.karaf.shell.api.action.lifecycle.Reference; import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.osgi.commands.BackupCommands; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.service.cm.ConfigurationAdmin; import java.io.IOException; @@ -32,6 +34,9 @@ import java.io.IOException; @Service public class BackupCreateCommand implements Action{ + @Reference + private TamayaConfigService configPlugin; + @Argument(index = 0, name = "pid", description = "The target pid to backup.", required = true, multiValued = false) String pid; @@ -45,7 +50,7 @@ public class BackupCreateCommand implements Action{ @Override public Object execute() throws IOException { - return(BackupCommands.createBackup(cm, pid, replace)); + return(BackupCommands.createBackup(configPlugin, cm, pid, replace)); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java index 6bf6162..f8fe5fe 100644 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupDeleteCommand.java @@ -21,8 +21,10 @@ package org.apache.tamaya.karaf.shell; import org.apache.karaf.shell.api.action.Action; import org.apache.karaf.shell.api.action.Argument; import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.lifecycle.Reference; import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.osgi.commands.BackupCommands; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; @@ -30,13 +32,16 @@ import java.io.IOException; @Service public class BackupDeleteCommand implements Action{ + @Reference + private TamayaConfigService configPlugin; + @Argument(index = 0, name = "pid", description = "Allows to filter on the given PID. '*' removes all backups.", required = true, multiValued = false) String pid; @Override public Object execute() throws IOException { - return(BackupCommands.deleteBackup(pid)); + return(BackupCommands.deleteBackup(configPlugin, pid)); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/2b878fa1/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java ---------------------------------------------------------------------- diff --git a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java index 9a4a2ed..edc5e88 100644 --- a/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java +++ b/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/BackupListCommand.java @@ -21,8 +21,10 @@ package org.apache.tamaya.karaf.shell; import org.apache.karaf.shell.api.action.Action; import org.apache.karaf.shell.api.action.Argument; import org.apache.karaf.shell.api.action.Command; +import org.apache.karaf.shell.api.action.lifecycle.Reference; import org.apache.karaf.shell.api.action.lifecycle.Service; import org.apache.tamaya.osgi.commands.BackupCommands; +import org.apache.tamaya.osgi.commands.TamayaConfigService; import java.io.IOException; @@ -30,13 +32,16 @@ import java.io.IOException; @Service public class BackupListCommand implements Action{ + @Reference + private TamayaConfigService configPlugin; + @Argument(index = 0, name = "pid", description = "Allows to filter on the given PID.", required = false, multiValued = false) String pid; @Override public Object execute() throws IOException { - return(BackupCommands.listBackup(pid)); + return(BackupCommands.listBackup(configPlugin, pid)); } } \ No newline at end of file
