Return-Path: X-Original-To: apmail-geronimo-scm-archive@www.apache.org Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7DBA81207 for ; Tue, 26 Apr 2011 23:21:00 +0000 (UTC) Received: (qmail 48153 invoked by uid 500); 26 Apr 2011 23:21:00 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 48014 invoked by uid 500); 26 Apr 2011 23:21:00 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 48007 invoked by uid 99); 26 Apr 2011 23:21:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Apr 2011 23:21:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Apr 2011 23:20:57 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 902C92388962; Tue, 26 Apr 2011 23:20:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1096957 - in /geronimo/server/trunk: ./ framework/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/ framework/configs/j2ee-security/ framework/configs/plugin/ framework/configs/server-security-config/ framework/features/cli... Date: Tue, 26 Apr 2011 23:20:37 -0000 To: scm@geronimo.apache.org From: djencks@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110426232037.902C92388962@eris.apache.org> Author: djencks Date: Tue Apr 26 23:20:36 2011 New Revision: 1096957 URL: http://svn.apache.org/viewvc?rev=1096957&view=rev Log: Add a ConfigurationInstaller to install plugin xml substituttions and xml overrirdes. LocalAttributeManager stores data using config admin. Server now starts OK Added: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java (with props) Removed: geronimo/server/trunk/framework/features/client-system/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/geronimo-gbean-deployer/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/j2ee-security/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/jmx-security/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/jsr88-cli/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/jsr88-deploymentfactory/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/offline-deployer/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/online-deployer/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/plugin/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/rmi-naming/src/main/history/dependencies.xml geronimo/server/trunk/framework/features/shutdown/src/main/history/dependencies.xml Modified: geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml geronimo/server/trunk/framework/configs/j2ee-security/pom.xml geronimo/server/trunk/framework/configs/plugin/pom.xml geronimo/server/trunk/framework/configs/server-security-config/pom.xml geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationExtender.java geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/PluginAttributeStore.java geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/WrapperAttributeManager.java geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java geronimo/server/trunk/pom.xml Modified: geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml (original) +++ geronimo/server/trunk/framework/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml Tue Apr 26 23:20:36 2011 @@ -45,7 +45,8 @@ org.apache.geronimo.buildsupport:car-maven-plugin:validate-configuration, - org.apache.geronimo.buildsupport:car-maven-plugin:prepare-plan + org.apache.geronimo.buildsupport:car-maven-plugin:prepare-plan, + org.apache.geronimo.buildsupport:car-maven-plugin:prepare-metadata org.apache.geronimo.buildsupport:car-maven-plugin:compile-gbean-plan, Modified: geronimo/server/trunk/framework/configs/j2ee-security/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/j2ee-security/pom.xml?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/configs/j2ee-security/pom.xml (original) +++ geronimo/server/trunk/framework/configs/j2ee-security/pom.xml Tue Apr 26 23:20:36 2011 @@ -115,17 +115,17 @@ Security - - - - rmi - #{ServerHostname} - #{JMXPort + PortOffset} - /jndi/rmi://#{ServerHostname}:#{NamingPort + PortOffset}/JMXConnector - - - 9999 - + + + + + + + + + + + Modified: geronimo/server/trunk/framework/configs/plugin/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/plugin/pom.xml?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/configs/plugin/pom.xml (original) +++ geronimo/server/trunk/framework/configs/plugin/pom.xml Tue Apr 26 23:20:36 2011 @@ -117,17 +117,17 @@ org.apache.geronimo.framework/geronimo-gbean-deployer-bootstrap/${geronimoVersion}/car?j2eeType=Deployer,name=Deployer Geronimo Core - - - - http://geronimo.apache.org/plugins/plugin-repository-list-3.0.txt - - - - - schema/xsd/ - plugin-repositories.properties - + + + + + + + + + + + Modified: geronimo/server/trunk/framework/configs/server-security-config/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/server-security-config/pom.xml?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/configs/server-security-config/pom.xml (original) +++ geronimo/server/trunk/framework/configs/server-security-config/pom.xml Tue Apr 26 23:20:36 2011 @@ -86,9 +86,9 @@ Security - - security/ - + + + Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationExtender.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationExtender.java?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationExtender.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/ConfigurationExtender.java Tue Apr 26 23:20:36 2011 @@ -31,6 +31,7 @@ import org.apache.felix.scr.annotations. import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.felix.scr.annotations.ReferencePolicy; import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.util.IOUtils; import org.osgi.framework.Bundle; @@ -56,7 +57,7 @@ public class ConfigurationExtender { private BundleTracker bt; - @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY) + @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY, policy = ReferencePolicy.DYNAMIC) private ManageableAttributeStore manageableAttributeStore; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @@ -98,6 +99,11 @@ public class ConfigurationExtender { private class ConfigurationBundleTrackerCustomizer implements BundleTrackerCustomizer { @Override public Object addingBundle(Bundle bundle, BundleEvent bundleEvent) { + if (bundleEvent != null) { + if (bundleEvent.getType() == BundleEvent.STOPPED) { + return null; + } + } if (bundle.getState() == Bundle.RESOLVED) { return loadConfiguration(bundle); } else if (bundle.getState() == Bundle.ACTIVE) { @@ -120,44 +126,7 @@ public class ConfigurationExtender { } } - -// protected Configuration loadConfiguration(Bundle bundle) { -// PluginArtifactType pluginArtifact = dependencyManager.getCachedPluginMetadata(bundle); -// if (pluginArtifact == null) { -// if (BundleUtils.isResolved(bundle)) { -// loadedBundleIds.add(bundle.getBundleId()); -// } -// return; -// } -// Set dependentBundleIds = new HashSet(); -// for (DependencyType dependency : pluginArtifact.getDependency()) { -// Long dependentBundleId = dependencyManager.getBundle(dependency.toArtifact()).getBundleId(); -// if (!loadedBundleIds.contains(dependentBundleId)) { -// dependentBundleIds.add(dependentBundleId); -// } -// } -// if (dependentBundleIds.size() > 0) { -// bundleIdListenerMap.put(bundle.getBundleId(), new BundleListener(bundle, dependentBundleIds)); -// return; -// } -// _loadConfiguration(bundle); -// loadedBundleIds.add(bundle.getBundleId()); -// -// boolean bundleStatusChanged; -// do { -// bundleStatusChanged = false; -// for (Iterator> it = bundleIdListenerMap.entrySet().iterator(); it.hasNext();) { -// Map.Entry entry = it.next(); -// if (entry.getValue().bundleChanged(bundle)) { -// bundleStatusChanged = true; -// it.remove(); -// } -// } -// } while (bundleStatusChanged); -// } - private LoadConfiguration loadConfiguration(Bundle bundle) { -// loadedBundleIds.add(bundle.getBundleId()); URL configSerURL = bundle.getEntry("META-INF/config.ser"); if (configSerURL == null) { return null; @@ -166,35 +135,6 @@ public class ConfigurationExtender { executor.execute(loader); configurationMap.put(bundle.getBundleId(), loader); return loader; -// -// InputStream in = null; -// try { -// in = configSerURL.openStream(); -// //TODO there are additional consistency checks in RepositoryConfigurationStore that we should use. -// ConfigurationData data = ConfigurationUtil.readConfigurationData(in); -// data.setBundle(bundle); -// Configuration configuration = new Configuration(data, manageableAttributeStore); -// configurationMap.put(bundle.getBundleId(), configuration); -// ConfigurationUtil.loadConfigurationGBeans(configuration, kernel); -//// for (GBeanData gBeanData: configuration.getGBeans().values()) { -//// kernel.loadGBean(gBeanData, configuration.getBundle()); -//// } -// return configuration; -// -//// configurationManager.loadConfiguration(data); -//// bundleIdArtifactMap.put(bundle.getBundleId(), data.getId()); -// } catch (IOException e) { -// logger.error("Could not read the config.ser file from bundle " + bundle.getLocation(), e); -// } catch (ClassNotFoundException e) { -// logger.error("Could not load required classes from bundle " + bundle.getLocation(), e); -// } catch (InvalidConfigException e) { -// logger.error("Could not load Configuration from bundle " + bundle.getLocation(), e); -//// } catch (GBeanAlreadyExistsException e) { -//// logger.error("Duplicate gbean in bundle " + bundle.getLocation(), e); -// } finally { -// IOUtils.close(in); -// } -// return null; } private StartConfiguration startConfiguration(Bundle bundle) { @@ -216,45 +156,6 @@ public class ConfigurationExtender { executor.execute(stopConfiguration); configurationMap.put(bundle.getBundleId(), stopConfiguration); } -// Artifact id = getArtifact(bundle); -// if (id == null) { -// return; -// } -// ServiceReference kernelReference = null; -// try { -// kernelReference = bundleContext.getServiceReference(Kernel.class.getName()); -// if (kernelReference == null) { -// return; -// } -// Kernel kernel = (Kernel) bundleContext.getService(kernelReference); -// AbstractName name = Configuration.getConfigurationAbstractName(id); -// //TODO investigate how this is called and whether just stopping/unloading the configuration gbean will -// //leave the configuration model in a consistent state. We might need a shutdown flag set elsewhere to avoid -// //overwriting the load attribute in config.xml. This code mimics the shutdown hook in KernelConfigurationManager -// //see https://issues.apache.org/jira/browse/GERONIMO-4909 -// try { -// kernel.stopGBean(name); -// } catch (Exception e) { -// //ignore -// } -// try { -// kernel.unloadGBean(name); -// } catch (Exception e) { -// } -// //TODO this code is more symmetrical with start, but currently sets the load attribute to false in config.xml, -// //which prevents restarting the server. -// //ConfigurationManager manager = ConfigurationUtil.getConfigurationManager(kernel); -// //manager.unloadConfiguration(id); -// } catch (InvalidConfigException e) { -// // -// } finally { -// if (kernelReference != null) { -// try { -// bundleContext.ungetService(kernelReference); -// } catch (Exception e) { -// } -// } -// } } private void unloadConfiguration(Bundle bundle, GetConfiguration configuration) { @@ -296,21 +197,13 @@ public class ConfigurationExtender { data.setBundle(bundle); Configuration configuration = new Configuration(data, manageableAttributeStore); ConfigurationUtil.loadConfigurationGBeans(configuration, kernel); -// for (GBeanData gBeanData: configuration.getGBeans().values()) { -// kernel.loadGBean(gBeanData, configuration.getBundle()); -// } this.configuration = configuration; - -// configurationManager.loadConfiguration(data); -// bundleIdArtifactMap.put(bundle.getBundleId(), data.getId()); } catch (IOException e) { logger.error("Could not read the config.ser file from bundle " + bundle.getLocation(), e); } catch (ClassNotFoundException e) { logger.error("Could not load required classes from bundle " + bundle.getLocation(), e); } catch (InvalidConfigException e) { logger.error("Could not load Configuration from bundle " + bundle.getLocation(), e); -// } catch (GBeanAlreadyExistsException e) { -// logger.error("Duplicate gbean in bundle " + bundle.getLocation(), e); } finally { IOUtils.close(in); } Added: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java?rev=1096957&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java (added) +++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java Tue Apr 26 23:20:36 2011 @@ -0,0 +1,176 @@ +/* + * 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.geronimo.system.configuration; + +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.apache.geronimo.kernel.repository.Artifact; +import org.apache.geronimo.system.plugin.model.ArtifactType; +import org.apache.geronimo.system.plugin.model.ConfigXmlContentType; +import org.apache.geronimo.system.plugin.model.PluginArtifactType; +import org.apache.geronimo.system.plugin.model.PluginType; +import org.apache.geronimo.system.plugin.model.PluginXmlUtil; +import org.apache.geronimo.system.plugin.model.PropertyType; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; +import org.osgi.util.tracker.BundleTracker; +import org.osgi.util.tracker.BundleTrackerCustomizer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @version $Rev:$ $Date:$ + */ +@Component(metatype = true) +public class ConfigurationInstaller { + private static final Logger logger = LoggerFactory.getLogger(ConfigurationInstaller.class); + + private final Executor executor = Executors.newCachedThreadPool(); + + private BundleTracker bt; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + private PluginAttributeStore pluginAttributeStore; + + public void setPluginAttributeStore(PluginAttributeStore pluginAttributeStore) { + this.pluginAttributeStore = pluginAttributeStore; + } + + public void unsetPluginAttributeStore(PluginAttributeStore pluginAttributeStore) { + if (pluginAttributeStore == this.pluginAttributeStore) { + this.pluginAttributeStore = null; + } + } + + @Activate + public void start(BundleContext bundleContext) { + bt = new BundleTracker(bundleContext, Bundle.INSTALLED, new ConfigurationBundleTrackerCustomizer()); + bt.open(); + + } + + @Deactivate + public void stop() { + bt.close(); + bt = null; + } + + private class ConfigurationBundleTrackerCustomizer implements BundleTrackerCustomizer { + + @Override + public Object addingBundle(Bundle bundle, BundleEvent bundleEvent) { + installConfiguration(bundle); + return null; + } + + @Override + public void modifiedBundle(Bundle bundle, BundleEvent bundleEvent, Object o) { + } + + @Override + public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Object o) { + } + } + + private void installConfiguration(Bundle bundle) { + URL configSerURL = bundle.getEntry("META-INF/geronimo-plugin.xml"); + if (configSerURL == null) { + return; + } + Installer loader = new Installer(configSerURL); + loader.run(); +// try { +// executor.execute(loader); +// } catch (RejectedExecutionException e) { +// logger.info("could not execute in thread pool", e); +// loader.run(); +// } + + } + + private class Installer implements Runnable { + + private URL pluginXmlURL; + + public Installer(URL pluginXmlURL) { + this.pluginXmlURL = pluginXmlURL; + + + } + + private boolean equals(String server, String serverName) { + return server == null? serverName == null || serverName.isEmpty(): server.equals(serverName); + } + + private Artifact toArtifact(ArtifactType moduleId) { + String groupId = moduleId.getGroupId(); + String artifactId = moduleId.getArtifactId(); + String version = moduleId.getVersion(); + String type = moduleId.getType(); + return new Artifact(groupId, artifactId, version, type); + } + + + @Override + public void run() { + try { + InputStream in = pluginXmlURL.openStream(); + try { + PluginType pluginType = PluginXmlUtil.loadPluginMetadata(in); + PluginArtifactType pluginArtifactType = pluginType.getPluginArtifact().get(0); + List substitutions = pluginArtifactType.getConfigSubstitution(); + Map subMap = new HashMap(); + for (PropertyType propertyType: substitutions) { + if (equals(propertyType.getServer(), pluginAttributeStore.getServerName())) { + subMap.put(propertyType.getKey(), propertyType.getValue()); + } + } + pluginAttributeStore.addConfigSubstitutions(subMap); + List xmls = pluginArtifactType.getConfigXmlContent(); + for (ConfigXmlContentType xml: xmls) { + if (equals(xml.getServer(), pluginAttributeStore.getServerName())) { + pluginAttributeStore.setModuleGBeans(toArtifact(pluginArtifactType.getModuleId()), xml.getGbean(), xml.isLoad(), xml.getCondition()); + } + } + } finally { + in.close(); + } + } catch (Exception e) { + logger.info("Could not install plugin xml", e); + } + } + } + + +} Propchange: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/ConfigurationInstaller.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/LocalAttributeManager.java Tue Apr 26 23:20:36 2011 @@ -16,13 +16,6 @@ */ package org.apache.geronimo.system.configuration; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; import java.io.IOException; import java.io.Reader; import java.io.StringReader; @@ -30,22 +23,24 @@ import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Dictionary; import java.util.Enumeration; import java.util.HashMap; +import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Properties; -import java.util.Timer; -import java.util.TimerTask; import javax.xml.bind.JAXBException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.stream.XMLStreamException; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Modified; import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.apache.geronimo.gbean.AbstractName; import org.apache.geronimo.gbean.GAttributeInfo; @@ -65,8 +60,9 @@ import org.apache.geronimo.system.config import org.apache.geronimo.system.plugin.model.AttributesType; import org.apache.geronimo.system.plugin.model.GbeanType; import org.apache.geronimo.system.plugin.model.ModuleType; -import org.apache.geronimo.system.serverinfo.ServerInfo; import org.osgi.framework.Bundle; +import org.osgi.framework.Constants; +import org.osgi.service.cm.ConfigurationAdmin; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; @@ -82,84 +78,97 @@ import org.xml.sax.SAXException; public class LocalAttributeManager implements PluginAttributeStore, PersistentConfigurationList { private static final Logger log = LoggerFactory.getLogger(LocalAttributeManager.class); - private static final String CONFIG_FILE_PROPERTY = "org.apache.geronimo.config.file"; - private final static String SUBSTITUTIONS_FILE_PROPERTY = "org.apache.geronimo.config.substitutions.file"; private final static String SUBSTITUTION_PREFIX_PREFIX = "org.apache.geronimo.config.substitution.prefix"; - private static final String BACKUP_EXTENSION = ".bak"; - private static final String TEMP_EXTENSION = ".working"; - private static final int SAVE_BUFFER_MS = 5000; + private final JexlExpressionParser expressionParser = new JexlExpressionParser(Collections.emptyMap()); -// private final ServerInfo serverInfo; -// private final String configFile; - private boolean readOnly; - private JexlExpressionParser expressionParser; - -// private File attributeFile; -// private File backupFile; -// private File tempFile; private ServerOverride serverOverride; -// private Timer timer; -// private TimerTask currentTask; - private boolean kernelFullyStarted; private String prefix; -// private File configSubstitutionsFile; private Map localConfigSubstitutions; -// private String resolvedPropertiesFile; private final GBeanInfoFactory infoFactory = new MultiGBeanInfoFactory(); - private static final byte[] INSTRUCTION = ("# Put variables and their substitution values in this file. \n" - + "# They will be used when processing the corresponding config.xml. \n" - + "# Values in this file can be overridden by environment variables and system properties \n" - + "# by prefixing the property name with 'org.apache.geronimo.config.substitution.' \n" - + "# For example, an entry such as hostName=localhost \n" - + "# can be overridden by an environment variable or system property org.apache.geronimo.config.substitution.hostName=foo \n" - + "# When running multiple instances of Geronimo choose a PortOffset value such that none of the ports conflict. \n" - + "# For example, try PortOffset=10 \n").getBytes(); - private org.osgi.service.cm.Configuration configuration; - - @Property() static final String OVERRIDES_KEY = ".overrides"; + @Property(value = "org.apache.geronimo.config.substitution.") static final String PREFIX_KEY = ".configSubstitutionsPrefix"; + @Property(boolValue = false) static final String READ_ONLY_KEY = "readOnly"; + private boolean readOnly; + @Property(value = "default") + static final String SERVER_NAME_KEY = "serverName"; + private String serverName; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + private ConfigurationAdmin configurationAdmin; + + public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) { + this.configurationAdmin = configurationAdmin; + } + + public void unsetConfigurationAdmin(ConfigurationAdmin configurationAdmin) { + if (configurationAdmin == this.configurationAdmin) { + this.configurationAdmin = null; + } + } + + private org.osgi.service.cm.Configuration configuration; -// public LocalAttributeManager(String configFile, String configSubstitutionsFileName, String configSubstitutionsPrefix, boolean readOnly, ServerInfo serverInfo) { -// this.configFile = System.getProperty(CONFIG_FILE_PROPERTY, configFile); -// resolvedPropertiesFile = System.getProperty(SUBSTITUTIONS_FILE_PROPERTY, configSubstitutionsFileName); -// configSubstitutionsFile = resolvedPropertiesFile == null? null: serverInfo.resolveServer(resolvedPropertiesFile); -// localConfigSubstitutions = loadConfigSubstitutions(configSubstitutionsFile); -// prefix = System.getProperty(SUBSTITUTION_PREFIX_PREFIX, configSubstitutionsPrefix); -// Map configSubstitutions = loadAllConfigSubstitutions(localConfigSubstitutions, prefix); -// expressionParser = new JexlExpressionParser(configSubstitutions); -// this.readOnly = readOnly; -// this.serverInfo = serverInfo; -// serverOverride = new ServerOverride(); -// -// log.debug("setting configSubstitutionsFile to: {}", configSubstitutionsFile); -// -// infoFactory = newGBeanInfoFactory(); -// } @Activate - public void activate(org.osgi.service.cm.Configuration configuration) throws IOException { - this.configuration = configuration; - Dictionary dictionary = configuration.getProperties(); - String overrides = (String) dictionary.remove(OVERRIDES_KEY); - String configSubstitutionsPrefix = (String) dictionary.remove(PREFIX_KEY); - readOnly = (Boolean) dictionary.get(READ_ONLY_KEY); - localConfigSubstitutions = loadConfigSubstitutions(dictionary); + public void activate(Map properties) throws IOException { + readOnly = (Boolean) properties.get(READ_ONLY_KEY); + serverName = (String) properties.get(SERVER_NAME_KEY); + String configSubstitutionsPrefix = (String) properties.remove(PREFIX_KEY); + String servicePid = (String) properties.get(Constants.SERVICE_PID); + this.configuration = configurationAdmin.getConfiguration(servicePid); + + Dictionary d = getConfigurationProperties(); + String overrides = (String) d.get(OVERRIDES_KEY); + localConfigSubstitutions = loadConfigSubstitutions(d); prefix = System.getProperty(SUBSTITUTION_PREFIX_PREFIX, configSubstitutionsPrefix); Map configSubstitutions = loadAllConfigSubstitutions(localConfigSubstitutions, prefix); - expressionParser = new JexlExpressionParser(configSubstitutions); + expressionParser.setVariables(configSubstitutions); load(overrides); } + + /** + * DS modified method. This is called back every time the config admin Configuration is updated, but asynchronously. + * + * @param properties DS properties (which include configuration properties) + * @throws IOException + */ + @Modified + public void modified(Map properties) throws IOException { +// readOnly = (Boolean) properties.get(READ_ONLY_KEY); +// serverName = (String) properties.get(SERVER_NAME_KEY); +// String configSubstitutionsPrefix = (String) properties.remove(PREFIX_KEY); +// String servicePid = (String) properties.get(Constants.SERVICE_PID); +// this.configuration = configurationAdmin.getConfiguration(servicePid); +// +// Dictionary d = getConfigurationProperties(); +// String overrides = (String) d.get(OVERRIDES_KEY); +// localConfigSubstitutions = loadConfigSubstitutions(d); +// prefix = System.getProperty(SUBSTITUTION_PREFIX_PREFIX, configSubstitutionsPrefix); +// Map configSubstitutions = loadAllConfigSubstitutions(localConfigSubstitutions, prefix); +// expressionParser.setVariables(configSubstitutions); +// +// load(overrides); + } + + private Dictionary getConfigurationProperties() { + Dictionary d = configuration.getProperties(); + if (d == null) { + d = new Hashtable(); + } + return d; + } + public boolean isReadOnly() { return readOnly; } @@ -244,7 +253,7 @@ public class LocalAttributeManager imple return gbean.applyOverrides(data, configName, gbeanName, bundle); } - public void setModuleGBeans(Artifact moduleName, List gbeans, boolean load, String condition) throws InvalidGBeanException { + public synchronized void setModuleGBeans(Artifact moduleName, List gbeans, boolean load, String condition) throws InvalidGBeanException { if (readOnly) { return; } @@ -271,11 +280,16 @@ public class LocalAttributeManager imple return expressionParser.parse(in); } - public void addConfigSubstitutions(Map properties) { + @Override + public String getServerName() { + return serverName; + } + + public synchronized void addConfigSubstitutions(Map properties) { localConfigSubstitutions.putAll(properties); - Map configSubstutions = loadAllConfigSubstitutions(localConfigSubstitutions, prefix); - storeConfigSubstitutions(configuration, localConfigSubstitutions); - expressionParser.setVariables(configSubstutions); + Map configSubstitutions = loadAllConfigSubstitutions(localConfigSubstitutions, prefix); + expressionParser.setVariables(configSubstitutions); + attributeChanged(); } public synchronized void setValue(Artifact configurationName, AbstractName gbeanName, GAttributeInfo attribute, Object value, Bundle bundle) { @@ -395,49 +409,24 @@ public class LocalAttributeManager imple if (readOnly) { return; } -// ensureParentDirectory(); -// if (!tempFile.exists() && !tempFile.createNewFile()) { -// throw new IOException("Unable to create manageable attribute working file for save " + tempFile.getAbsolutePath()); -// } -// if (!tempFile.canWrite()) { -// throw new IOException("Unable to write to manageable attribute working file for save " + tempFile.getAbsolutePath()); -// } // write the new configuration to the temp file String overrides = saveXml(serverOverride); if (overrides == null) { throw new IOException("Could not save serverOverride: " + serverOverride); } - Dictionary d = configuration.getProperties(); + Dictionary d = getConfigurationProperties(); + for (Map.Entry entry: localConfigSubstitutions.entrySet()) { + d.put("." + entry.getKey(), entry.getValue()); + } d.put(OVERRIDES_KEY, overrides); configuration.update(d); -// // delete the current backup file -// if (backupFile.exists()) { -// if (!backupFile.delete()) { -// throw new IOException("Unable to delete old backup file in order to back up current manageable attribute working file for save"); -// } -// } -// -// // rename the existing configuration file to the backup file -// if (attributeFile.exists()) { -// if (!attributeFile.renameTo(backupFile)) { -// throw new IOException("Unable to rename " + attributeFile.getAbsolutePath() + " to " + backupFile.getAbsolutePath() + " in order to back up manageable attribute save file"); -// } -// } -// -// // rename the temp file the the configuration file -// if (!tempFile.renameTo(attributeFile)) { -// throw new IOException( -// "EXTREMELY CRITICAL! Unable to move manageable attributes working file to proper file name! Configuration will revert to defaults unless this is manually corrected! (could not rename " + tempFile.getAbsolutePath() + " to " + attributeFile.getAbsolutePath() + ")"); -// } } void write(Writer writer) throws XMLStreamException, JAXBException, IOException { - AttributesType attributes = serverOverride.writeXml(); - AttributesXmlUtil.writeAttributes(attributes, writer); - writer.flush(); + write(serverOverride, writer); } private static String saveXml(ServerOverride serverOverride) { @@ -579,24 +568,6 @@ public class LocalAttributeManager imple } catch (IOException e) { log.error("could not save serverOverrides", e); } -// if (currentTask != null) { -// currentTask.cancel(); -// } -// if (timer != null) { -// currentTask = new TimerTask() { -// -// public void run() { -// try { -// LocalAttributeManager.this.save(); -// } catch (IOException e) { -// log.error("IOException occurred while saving attributes", e); -// } catch (Throwable t) { -// log.error("Error occurred during execution of attributeChanged TimerTask", t); -// } -// } -// }; -// timer.schedule(currentTask, SAVE_BUFFER_MS); -// } } private static Map loadAllConfigSubstitutions(Map configSubstitutions, String prefix) { @@ -607,56 +578,35 @@ public class LocalAttributeManager imple addGeronimoSubstitutions(vars, System.getenv(), prefix); //properties file is least significant if (configSubstitutions != null) { - addGeronimoSubstitutions(vars, configSubstitutions, "."); + addGeronimoSubstitutions(vars, configSubstitutions, ""); } ParserUtils.addDefaultVariables(vars); return vars; } -// private static Properties loadConfigSubstitutions(File configSubstitutionsFile) { -// Properties properties = new Properties(); -// if (configSubstitutionsFile != null) { -// if (!configSubstitutionsFile.exists()) { -// //write out empty file with instructions as a hint to users. -// storeConfigSubstitutions(configSubstitutionsFile, properties); -// } else { -// try { -// FileInputStream in = new FileInputStream(configSubstitutionsFile); -// try { -// properties.load(in); -// } finally { -// in.close(); -// } -// } catch (Exception e) { -// log.error("Caught exception {} trying to read properties file {}", e, configSubstitutionsFile.getAbsolutePath()); -// } -// } -// } -// return properties; -// } - private static Map loadConfigSubstitutions(Dictionary dictionary) { + private static Map loadConfigSubstitutions(Dictionary dictionary) { Map properties = new HashMap(); - for (Enumeration e = dictionary.keys(); e.hasMoreElements(); ) { + for (Enumeration e = dictionary.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); - if (key.startsWith(".")) { - String value = (String) dictionary.get(key); - properties.put(key.substring(1), value); + Object value = dictionary.get(key); + if (key.startsWith(".") && !key.equals(OVERRIDES_KEY) && value instanceof String) { + properties.put(key.substring(1) , (String) value); } } return properties; } - private static void storeConfigSubstitutions(org.osgi.service.cm.Configuration configuration, Map properties) { - Dictionary d = configuration.getProperties(); - for (Map.Entry entry: properties.entrySet()) { - d.put("." + entry.getKey(), entry.getValue()); - } - try { - configuration.update(d); - } catch (IOException e) { - log.error("Caught exception {} trying to update Configuration dictionary", e); - } - } +// private synchronized void storeConfigSubstitutions(Map properties) { +// Dictionary d = getConfigurationProperties(); +// for (Map.Entry entry: properties.entrySet()) { +// d.put("." + entry.getKey(), entry.getValue()); +// } +// try { +// configuration.update(d); +// } catch (IOException e) { +// log.error("Caught exception {} trying to update Configuration dictionary", e); +// } +// } private static void addGeronimoSubstitutions(Map vars, Map props, String prefix) { if (prefix != null) { Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/PluginAttributeStore.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/PluginAttributeStore.java?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/PluginAttributeStore.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/PluginAttributeStore.java Tue Apr 26 23:20:36 2011 @@ -44,4 +44,6 @@ public interface PluginAttributeStore ex boolean isModuleInstalled(Artifact artifact); String substitute(final String in); + + String getServerName(); } Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/WrapperAttributeManager.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/WrapperAttributeManager.java?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/WrapperAttributeManager.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/WrapperAttributeManager.java Tue Apr 26 23:20:36 2011 @@ -74,6 +74,11 @@ public class WrapperAttributeManager ext return get().substitute(in); } + @Override + public String getServerName() { + return get().getServerName(); + } + public void addGBean(Artifact configurationName, GBeanData gbeanData, Bundle bundle) { get().addGBean(configurationName, gbeanData, bundle); } Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java (original) +++ geronimo/server/trunk/framework/modules/geronimo-system/src/test/java/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java Tue Apr 26 23:20:36 2011 @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Dictionary; +import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.LinkedHashSet; @@ -44,15 +45,16 @@ import org.apache.geronimo.kernel.Naming import org.apache.geronimo.kernel.config.InvalidConfigException; import org.apache.geronimo.kernel.osgi.MockBundle; import org.apache.geronimo.kernel.repository.Artifact; -import org.apache.geronimo.system.serverinfo.BasicServerInfo; import org.osgi.framework.Bundle; +import org.osgi.framework.InvalidSyntaxException; import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; /** * @version $Rev$ $Date$ */ public class LocalAttributeManagerTest extends TestCase { - private static final String basedir = System.getProperties().getProperty("basedir", "."); +// private static final String basedir = System.getProperties().getProperty("basedir", "."); private LocalAttributeManager localAttributeManager; private Artifact configurationName; @@ -248,7 +250,10 @@ public class LocalAttributeManagerTest e protected void setUp() throws Exception { super.setUp(); localAttributeManager = new LocalAttributeManager(); - Configuration configuration = new Configuration() { + final Map props = new HashMap(); + props.put(LocalAttributeManager.READ_ONLY_KEY, false); + props.put(LocalAttributeManager.PREFIX_KEY, "org.apache.geronimo.config.substitution."); + final Configuration configuration = new Configuration() { private Hashtable dictionary = new Hashtable(); @@ -260,9 +265,7 @@ public class LocalAttributeManagerTest e @Override public Dictionary getProperties() { Hashtable d = new Hashtable(); - d.putAll(dictionary); - d.put(LocalAttributeManager.READ_ONLY_KEY, false); - d.put(LocalAttributeManager.PREFIX_KEY, "org.apache.geronimo.config.substitution."); + d.putAll(props); return d; } @@ -294,7 +297,35 @@ public class LocalAttributeManagerTest e return null; } }; - localAttributeManager.activate(configuration); + ConfigurationAdmin ca = new ConfigurationAdmin() { + + @Override + public Configuration createFactoryConfiguration(String s) throws IOException { + return null; + } + + @Override + public Configuration createFactoryConfiguration(String s, String s1) throws IOException { + return null; + } + + @Override + public Configuration getConfiguration(String s, String s1) throws IOException { + return null; + } + + @Override + public Configuration getConfiguration(String s) throws IOException { + return configuration; + } + + @Override + public Configuration[] listConfigurations(String s) throws IOException, InvalidSyntaxException { + return new Configuration[0]; + } + }; + localAttributeManager.setConfigurationAdmin(ca); + localAttributeManager.activate(props); configurationName = Artifact.create("configuration/name/1/car"); ObjectName objectName = ObjectName.getInstance(":name=gbean,parent="+configurationName+",foo=bar"); Modified: geronimo/server/trunk/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/pom.xml?rev=1096957&r1=1096956&r2=1096957&view=diff ============================================================================== --- geronimo/server/trunk/pom.xml (original) +++ geronimo/server/trunk/pom.xml Tue Apr 26 23:20:36 2011 @@ -456,12 +456,12 @@ org.apache.geronimo.components geronimo-jaspi - 1.1.1 + 1.1.2-SNAPSHOT org.apache.geronimo.components geronimo-jaspi - 1.1.1 + 1.1.2-SNAPSHOT tests @@ -2198,6 +2198,12 @@ + + org.apache.karaf.tooling + karaf-maven-plugin + ${karaf.version} + true + @@ -2392,6 +2398,10 @@ org.apache.felix maven-bundle-plugin + + org.apache.karaf.tooling + karaf-maven-plugin +