Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 43093 invoked from network); 17 Feb 2011 08:21:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Feb 2011 08:21:30 -0000 Received: (qmail 96283 invoked by uid 500); 17 Feb 2011 08:21:29 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 96145 invoked by uid 500); 17 Feb 2011 08:21:26 -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 96138 invoked by uid 99); 17 Feb 2011 08:21:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Feb 2011 08:21:25 +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; Thu, 17 Feb 2011 08:21:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B415D23889F7; Thu, 17 Feb 2011 08:20:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1071540 - in /geronimo/server/branches/3.0-M2: framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/ framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ plugins/aries/gero... Date: Thu, 17 Feb 2011 08:20:59 -0000 To: scm@geronimo.apache.org From: genspring@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110217082059.B415D23889F7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: genspring Date: Thu Feb 17 08:20:59 2011 New Revision: 1071540 URL: http://svn.apache.org/viewvc?rev=1071540&view=rev Log: svn merge -c r1071532 https://svn.apache.org/repos/asf/geronimo/server/trunk . GERONIMO-5769 use OSGi API to operate WAB in portlet, suggestion from Jarek. Added: geronimo/server/branches/3.0-M2/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/BundleUtil.java - copied unchanged from r1071532, geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/BundleUtil.java Modified: geronimo/server/branches/3.0-M2/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java geronimo/server/branches/3.0-M2/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationInstaller.java geronimo/server/branches/3.0-M2/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java geronimo/server/branches/3.0-M2/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java (contents, props changed) Modified: geronimo/server/branches/3.0-M2/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java?rev=1071540&r1=1071539&r2=1071540&view=diff ============================================================================== --- geronimo/server/branches/3.0-M2/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java (original) +++ geronimo/server/branches/3.0-M2/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java Thu Feb 17 08:20:59 2011 @@ -37,6 +37,7 @@ import javax.xml.parsers.SAXParserFactor import org.apache.geronimo.common.DeploymentException; import org.apache.geronimo.kernel.repository.Artifact; import org.apache.geronimo.kernel.repository.Version; +import org.apache.geronimo.kernel.util.BundleUtil; import org.apache.geronimo.kernel.util.JarUtils; import org.apache.geronimo.kernel.util.XmlUtil; import org.slf4j.Logger; @@ -268,18 +269,10 @@ public class ConfigIDExtractor { org.osgi.framework.Version version=new org.osgi.framework.Version(artifactVersion.trim()); - return new Artifact("application", artifactID.trim(), getVersion(version), "eba").toString(); + return new Artifact("application", artifactID.trim(), BundleUtil.getVersion(version), "eba").toString(); } - //copied from org.apache.geronimo.aries.builder.ApplicationInstaller.getVersion(Version) - private static String getVersion(org.osgi.framework.Version version) { - String str = version.getMajor() + "." + version.getMinor() + "." + version.getMicro(); - String qualifier = version.getQualifier(); - if (qualifier != null && qualifier.trim().length() > 0) { - str += "-" + version.getQualifier().trim(); - } - return str; - } + private static String extractModuleIdFromPlan(Reader plan) throws IOException { SAXParserFactory factory = XmlUtil.newSAXParserFactory(); Modified: geronimo/server/branches/3.0-M2/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationInstaller.java URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationInstaller.java?rev=1071540&r1=1071539&r2=1071540&view=diff ============================================================================== --- geronimo/server/branches/3.0-M2/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationInstaller.java (original) +++ geronimo/server/branches/3.0-M2/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationInstaller.java Thu Feb 17 08:20:59 2011 @@ -42,6 +42,7 @@ import org.apache.geronimo.kernel.config import org.apache.geronimo.kernel.config.ConfigurationUtil; import org.apache.geronimo.kernel.repository.Artifact; import org.apache.geronimo.kernel.repository.Environment; +import org.apache.geronimo.kernel.util.BundleUtil; import org.apache.geronimo.kernel.util.FileUtils; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; @@ -173,20 +174,8 @@ public class ApplicationInstaller implem } public static Artifact getConfigId(ApplicationMetadata metadata) { - return createArtifact("application", metadata.getApplicationSymbolicName(), metadata.getApplicationVersion()); + return BundleUtil.createArtifact("application", metadata.getApplicationSymbolicName(), metadata.getApplicationVersion()); } - private static Artifact createArtifact(String group, String symbolicName, Version version) { - return new Artifact(group, symbolicName, getVersion(version), "eba"); - } - - private static String getVersion(Version version) { - String str = version.getMajor() + "." + version.getMinor() + "." + version.getMicro(); - String qualifier = version.getQualifier(); - if (qualifier != null && qualifier.trim().length() > 0) { - str += "-" + version.getQualifier().trim(); - } - return str; - } } Modified: geronimo/server/branches/3.0-M2/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java?rev=1071540&r1=1071539&r2=1071540&view=diff ============================================================================== --- geronimo/server/branches/3.0-M2/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java (original) +++ geronimo/server/branches/3.0-M2/plugins/console/console-base-portlets/src/main/java/org/apache/geronimo/console/configmanager/ConfigManagerPortlet.java Thu Feb 17 08:20:59 2011 @@ -31,6 +31,7 @@ import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletConfig; import javax.portlet.PortletException; +import javax.portlet.PortletRequest; import javax.portlet.PortletRequestDispatcher; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; @@ -57,7 +58,10 @@ import org.apache.geronimo.kernel.config import org.apache.geronimo.kernel.management.State; import org.apache.geronimo.kernel.repository.Artifact; import org.apache.geronimo.kernel.repository.MissingDependencyException; +import org.apache.geronimo.kernel.util.BundleUtil; import org.apache.geronimo.management.geronimo.WebModule; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,7 +80,7 @@ public class ConfigManagerPortlet extend private static final String CONFIG_INIT_PARAM = "config-type"; private static final String SHOW_DEPENDENCIES_COOKIE = "org.apache.geronimo.configmanager.showDependencies"; - + private Kernel kernel; private PortletRequestDispatcher normalView; @@ -144,34 +148,77 @@ public class ConfigManagerPortlet extend public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException { String action = actionRequest.getParameter("action"); actionResponse.setRenderParameter("message", ""); // set to blank first + try { ConfigurationManager configurationManager = ConfigurationUtil.getConfigurationManager(kernel); String config = getConfigID(actionRequest); Artifact configId = Artifact.create(config); + + boolean isWAB = configId.getType().equalsIgnoreCase(ConfigurationModuleType.WAB.getName()); + + Bundle wabBundle=null; + + if (isWAB){ + + wabBundle= this.getWABbundle(actionRequest,configId); + } if (START_ACTION.equals(action)) { - if(!configurationManager.isLoaded(configId)) { - configurationManager.loadConfiguration(configId); - } - if(!configurationManager.isRunning(configId)) { - org.apache.geronimo.kernel.config.LifecycleResults lcresult = configurationManager.startConfiguration(configId); - addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg01") + printResults(lcresult.getStarted())); + + if (isWAB && wabBundle!=null) { + wabBundle.start(); + } else { + + if (!configurationManager.isLoaded(configId)) { + configurationManager.loadConfiguration(configId); + } + if (!configurationManager.isRunning(configId)) { + org.apache.geronimo.kernel.config.LifecycleResults lcresult = configurationManager + .startConfiguration(configId); + addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg01") + + printResults(lcresult.getStarted())); + } } + } else if (STOP_ACTION.equals(action)) { - if(configurationManager.isLoaded(configId)) { - LifecycleResults lcresult = configurationManager.unloadConfiguration(configId); - addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg02") + printResults(lcresult.getStopped())); + + if (isWAB && wabBundle!=null) { + wabBundle.stop(); + addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg02")); + } else { + + if(configurationManager.isLoaded(configId)) { + LifecycleResults lcresult = configurationManager.unloadConfiguration(configId); + addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg02") + printResults(lcresult.getStopped())); + } } + } else if (UNINSTALL_ACTION.equals(action)) { - configurationManager.uninstallConfiguration(configId); + + if (isWAB && wabBundle!=null) { + wabBundle.uninstall(); + } else { + configurationManager.uninstallConfiguration(configId); + } + addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg04") + "
" + configId); + } else if (RESTART_ACTION.equals(action)) { - LifecycleResults lcresult = configurationManager.restartConfiguration(configId); - addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg03") + printResults(lcresult.getStarted())); + + if (isWAB && wabBundle!=null) { + wabBundle.stop(); + wabBundle.start(); + addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg03")); + } else { + LifecycleResults lcresult = configurationManager.restartConfiguration(configId); + addInfoMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.infoMsg03") + printResults(lcresult.getStarted())); + } + } else { addWarningMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.warnMsg01") + action + "
"); throw new PortletException("Invalid value for changeState: " + action); } + } catch (NoSuchConfigException e) { // ignore this for now addErrorMessage(actionRequest, getLocalizedString(actionRequest, "consolebase.errorMsg01")); @@ -185,6 +232,36 @@ public class ConfigManagerPortlet extend logger.error("Exception", e); } } + + + private BundleContext getBundleContext(PortletRequest request) { + return (BundleContext) request.getPortletSession().getPortletContext().getAttribute("osgi-bundlecontext"); + } + + private Bundle getWABbundle(PortletRequest request, Artifact configId) { + + Bundle[] bundles = getBundleContext(request).getBundles(); + + String symboleName = configId.getArtifactId(); + + String version = configId.getVersion().toString(); + + for (Bundle bundle : bundles) { + String contextPath = (String) bundle.getHeaders().get(BundleUtil.WEB_CONTEXT_PATH_HEADER); + // a WAB MUST have the Web-ContextPath header + if (contextPath != null && bundle.getSymbolicName().equals(symboleName) + && BundleUtil.getVersion(bundle.getVersion()).equals(version)) { + + return bundle; + } + + } + + return null; + + } + + /** * Check if a configuration should be listed here. This method depends on the "config-type" portlet parameter @@ -314,40 +391,22 @@ public class ConfigManagerPortlet extend // hack to display WAB because WAB can't be get from configManager.listConfigurations(); if (ConfigurationModuleType.WAB.getName().equalsIgnoreCase(moduleType)) { - - Artifact wabQuery = Artifact.createPartial("///" + ConfigurationModuleType.WAB.getName().toLowerCase()); - - Artifact[] runningWABs = configManager.getRunning(wabQuery); - - if (runningWABs != null && runningWABs.length > 0) { - - for (Artifact wab : runningWABs) { - ModuleDetails details = new ModuleDetails(wab, ConfigurationModuleType.WAB, State.RUNNING); - try { - AbstractName configObjName = Configuration.getConfigurationAbstractName(wab); - boolean loaded = loadModule(configManager, configObjName); - - WebModule webModule = (WebModule) PortletManager.getModule(renderRequest, wab); - if (webModule != null) { - details.getContextPaths().add(webModule.getContextPath()); - details.setDisplayName(webModule.getDisplayName()); - } + Bundle[] bundles = getBundleContext(renderRequest).getBundles(); - if (showDependencies) { - addDependencies(details, configObjName); - } - if (loaded) { - unloadModule(configManager, configObjName); - } - } catch (InvalidConfigException ice) { - // Should not occur - ice.printStackTrace(); - } + for (Bundle bundle : bundles) { + String contextPath = (String) bundle.getHeaders().get(BundleUtil.WEB_CONTEXT_PATH_HEADER); + // a WAB MUST have the Web-ContextPath header + if (contextPath != null) { + Artifact wabArtifact=new Artifact("",bundle.getSymbolicName(),BundleUtil.getVersion(bundle.getVersion()),ConfigurationModuleType.WAB.getName().toLowerCase()); + ModuleDetails details = new ModuleDetails(wabArtifact, ConfigurationModuleType.WAB, getWABStateFromBundleState(bundle)); + details.getContextPaths().add(contextPath); + details.setDisplayName(bundle.getSymbolicName()); moduleDetails.add(details); } - + } + } @@ -389,6 +448,27 @@ public class ConfigManagerPortlet extend } return configurationState; } + + private State getWABStateFromBundleState(Bundle bundle) { + + int state = bundle.getState(); + + switch (state) { + + case Bundle.ACTIVE: + return State.RUNNING; + + case Bundle.STARTING: + return State.STARTING; + + case Bundle.STOPPING: + return State.STOPPING; + + default: + return State.STOPPED; + } + + } private WebModule getWebModule(Configuration config, Configuration child) { try { @@ -487,7 +567,7 @@ public class ConfigManagerPortlet extend * Convenience data holder for portlet that displays deployed modules. * Includes context path information for web modules. */ - public static class ModuleDetails implements Comparable, Serializable { + public static class ModuleDetails implements Comparable, Serializable { private static final long serialVersionUID = -7022687152297202079L; private final Artifact configId; private final ConfigurationModuleType type; @@ -505,14 +585,14 @@ public class ConfigManagerPortlet extend this.configId = configId; this.type = type; this.state = state; - if (configId.toString().indexOf("org.apache.geronimo.configs/") == 0) { + if (configId.toString().indexOf("org.apache.geronimo.configs/") == 0 || configId.toString().indexOf("org.apache.geronimo.plugins/") == 0) { this.expertConfig = true; } } - public int compareTo(Object o) { - if (o != null && o instanceof ModuleDetails){ - return configId.compareTo(((ModuleDetails)o).configId); + public int compareTo(ModuleDetails o) { + if (o != null ){ + return configId.compareTo(o.configId); } else { return -1; } Modified: geronimo/server/branches/3.0-M2/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0-M2/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java?rev=1071540&r1=1071539&r2=1071540&view=diff ============================================================================== --- geronimo/server/branches/3.0-M2/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java (original) +++ geronimo/server/branches/3.0-M2/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java Thu Feb 17 08:20:59 2011 @@ -43,6 +43,7 @@ import org.apache.geronimo.kernel.config import org.apache.geronimo.kernel.config.ConfigurationUtil; import org.apache.geronimo.kernel.repository.Environment; import org.apache.geronimo.kernel.repository.Repository; +import org.apache.geronimo.kernel.util.BundleUtil; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; @@ -60,8 +61,7 @@ import org.slf4j.LoggerFactory; */ @GBean public class WebContainerExtender implements GBeanLifecycle { - // the header that identifies a bundle as being a WAB - public final static String WEB_CONTEXT_PATH_HEADER = "Web-ContextPath"; + private static final Logger LOGGER = LoggerFactory.getLogger(WebContainerExtender.class); @@ -243,7 +243,7 @@ public class WebContainerExtender implem */ private WebApplication deploy(Bundle bundle) { LOGGER.debug("Scanning bundle {} for WAB application", bundle.getSymbolicName()); - String contextPath = (String) bundle.getHeaders().get(WEB_CONTEXT_PATH_HEADER); + String contextPath = (String) bundle.getHeaders().get(BundleUtil.WEB_CONTEXT_PATH_HEADER); // a WAB MUST have the Web-ContextPath header or it must be ignored by the extender. if (contextPath == null) { LOGGER.debug("No web container application found in bundle {}", bundle.getSymbolicName()); Propchange: geronimo/server/branches/3.0-M2/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Feb 17 08:20:59 2011 @@ -1,4 +1,4 @@ /geronimo/server/branches/2.2/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/WebContainerExtender.java:832538,885058 /geronimo/server/branches/3.0-M1/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java:948864,951792 /geronimo/server/trunk/plugins/j2ee/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/WebContainerExtender.java:887507 -/geronimo/server/trunk/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java:1056676,1057959-1057962,1064377,1064432-1064433,1071183 +/geronimo/server/trunk/plugins/wab/geronimo-web-extender/src/main/java/org/apache/geronimo/osgi/web/extender/WebContainerExtender.java:1056676,1057959-1057962,1064377,1064432-1064433,1071183,1071532