Author: taylor Date: Mon Nov 13 20:57:35 2006 New Revision: 474655 URL: http://svn.apache.org/viewvc?view=rev&rev=474655 Log: The FusionUpdateEventListener will receives deployment events to "update" a deployed war file The main difference with normal deployment events is that we do not want to redeploy the portlet app Only update the registry with a new portlet.xml Class and jar files are overlaid A .update file is distributed with the update, for example:
portlet-app = demo psml-locators = user/admin/media-type/html/page/default.psml portlets = HelloPortlet, HelloPortlet3 There are three properties 1. portlet-app - must be the exact name of the portlet app being updated 2. psml-locators - comma-delimited list of PSML locators 3. portlets - comma-delimted list of exact portlet names as entered in the registry (portlet.xml) Locators are a normalized way to express access paths to PSML pages. In the example above, the locator locates the admin's home page for media type HTML. Note that the path is always constructed of keyword/value pairs. You can read more about locators here: http://portals.apache.org/jetspeed-1/psml.html#PSML_Locator ------------------------------------------------------------------------ - PSML The Updater will attempt to rewrite one or more PSML files as instructed in the .update file. You don't have to put any special entries in the PSML files, just make sure to list the portlets you want to update in the .update file (portlets=). Here is an example of a new PSML entry BEFORE running the updater: <entry parent="HelloPortlet3"> <layout> <property name="column" value="0"/> <property name="row" value="3"/> </layout> </entry> and then AFTER, it will look something like this: <entry id="P-10ee495d4d7-10000" parent="HelloPortlet3"> <layout position="-1" size="-1"> <property name="column" value="0"/> <property name="row" value="3"/> </layout> <parameter name="j2_entity" value="110"/> </entry> Note that the updater will: * generate a new PSML (J1) entry id * generate a new j2_entity parameter and value Please note you can't just create j2_entity ids They must be program generated Added: portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentManager.java portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentObject.java portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateEventListener.java Added: portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentManager.java URL: http://svn.apache.org/viewvc/portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentManager.java?view=auto&rev=474655 ============================================================================== --- portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentManager.java (added) +++ portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentManager.java Mon Nov 13 20:57:35 2006 @@ -0,0 +1,69 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed 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.jetspeed.fusion.tools.pamanager; + +import java.io.File; +import java.io.IOException; +import java.util.Collection; + +import org.apache.jetspeed.deployment.DeploymentEvent; +import org.apache.jetspeed.deployment.DeploymentException; +import org.apache.jetspeed.deployment.DeploymentObject; +import org.apache.jetspeed.deployment.DeploymentStatus; +import org.apache.jetspeed.deployment.impl.DeploymentEventImpl; +import org.apache.jetspeed.deployment.impl.StandardDeploymentManager; +import org.apache.jetspeed.deployment.impl.StandardDeploymentObject; + + +/** + * Fusion Update Deployment Manager + * + * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a> + * @version $$ + */ +public class FusionUpdateDeploymentManager extends StandardDeploymentManager +{ + public FusionUpdateDeploymentManager(String stagingDirectories, long scanningDelay, Collection deploymentListeners) + { + super(stagingDirectories, scanningDelay, deploymentListeners); + } + + public synchronized DeploymentStatus deploy(File aFile) throws DeploymentException + { + DeploymentObject deploymentObject = new FusionUpdateDeploymentObject(aFile); + DeploymentEvent event = null; + try + { + event = new DeploymentEventImpl(deploymentObject); + dispatch(event); + } + finally + { + if ( deploymentObject != null ) + { + try + { + deploymentObject.close(); + } + catch (IOException e) + { + } + } + } + return event; + } + +} Added: portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentObject.java URL: http://svn.apache.org/viewvc/portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentObject.java?view=auto&rev=474655 ============================================================================== --- portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentObject.java (added) +++ portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateDeploymentObject.java Mon Nov 13 20:57:35 2006 @@ -0,0 +1,55 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed 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.jetspeed.fusion.tools.pamanager; + +import java.io.File; +import java.io.IOException; +import java.util.zip.ZipFile; + +import org.apache.jetspeed.deployment.DeploymentObject; +import org.apache.jetspeed.deployment.impl.FileNotDeployableException; +import org.apache.jetspeed.deployment.impl.StandardDeploymentObject; + + +public class FusionUpdateDeploymentObject extends StandardDeploymentObject implements DeploymentObject +{ + protected File deploymentObject; + protected ZipFile zipFile; + + /** + * @throws IOException + */ + public FusionUpdateDeploymentObject(File deploymentObject) throws FileNotDeployableException + { + super(deploymentObject); + } + + protected boolean verifyExtension(File file) + { + String fileName = file.getName(); + int dot = fileName.lastIndexOf('.'); + if (dot != -1) + { + String ext = fileName.substring(dot); + return ext.equals(".war") || ext.equals(".jar") || ext.equals(".zip") || ext.equals(".update"); + } + else + { + return false; + } + } + +} Added: portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateEventListener.java URL: http://svn.apache.org/viewvc/portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateEventListener.java?view=auto&rev=474655 ============================================================================== --- portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateEventListener.java (added) +++ portals/jetspeed-1/trunk/fusion/src/java/org/apache/jetspeed/fusion/tools/pamanager/FusionUpdateEventListener.java Mon Nov 13 20:57:35 2006 @@ -0,0 +1,237 @@ +/* + * Copyright 2004 The Apache Software Foundation. + * + * Licensed 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.jetspeed.fusion.tools.pamanager; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jetspeed.Jetspeed; +import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent; +import org.apache.jetspeed.components.portletregistry.PortletRegistry; +import org.apache.jetspeed.deployment.DeploymentEvent; +import org.apache.jetspeed.deployment.DeploymentEventListener; +import org.apache.jetspeed.deployment.DeploymentException; +import org.apache.jetspeed.deployment.DeploymentStatus; +import org.apache.jetspeed.om.profile.Entry; +import org.apache.jetspeed.om.profile.PSMLDocument; +import org.apache.jetspeed.om.profile.Parameter; +import org.apache.jetspeed.om.profile.Portlets; +import org.apache.jetspeed.om.profile.ProfileLocator; +import org.apache.jetspeed.om.profile.psml.PsmlParameter; +import org.apache.jetspeed.portal.Portlet; +import org.apache.jetspeed.services.PortletFactory; +import org.apache.jetspeed.services.Profiler; +import org.apache.jetspeed.services.PsmlManager; +import org.apache.jetspeed.services.resources.FusionResources; +import org.apache.jetspeed.tools.pamanager.PortletApplicationManagement; +import org.apache.jetspeed.util.DirectoryHelper; +import org.apache.pluto.om.entity.PortletEntity; +import org.apache.pluto.om.portlet.PortletDefinition; + +public class FusionUpdateEventListener implements DeploymentEventListener +{ + protected static final Log log = LogFactory.getLog("deployment"); + private String webAppDir; + private boolean stripLoggers; + private PortletApplicationManagement pam; + private PortletRegistry registry; + private PortletEntityAccessComponent entityAccess; + private static final String J2_ENTITY = FusionResources.getString(FusionResources.J2_ENTITY); + + /** + * @param pam + * @param webAppDir + * @throws FileNotFoundException the <code>webAppDir</code> or <code>localAppDir</code> directory does not + * exist. + */ + public FusionUpdateEventListener(PortletApplicationManagement pam, PortletRegistry registry, PortletEntityAccessComponent entityAccess, String webAppDir) + throws FileNotFoundException + { + this.pam = pam; + this.registry = registry; + this.entityAccess = entityAccess; + + File webAppDirFile = new File(webAppDir); + + if (webAppDirFile.exists()) + { + try + { + this.webAppDir = webAppDirFile.getCanonicalPath(); + } + catch (IOException e) {} + } + else + { + throw new FileNotFoundException("The depoyment directory for portlet applications \"" + + webAppDirFile.getAbsolutePath() + "\" does not exist."); + } + } + + public void invokeDeploy(DeploymentEvent event) throws DeploymentException + { + if (event.getName().endsWith(".update")) + { + try + { + // process update file + FileInputStream fis = new FileInputStream(event.getPath()); + Properties updateFile = new Properties(); + updateFile.load(fis); + fis.close(); + String portletApp = updateFile.getProperty("portlet-app"); + String psmlLocators = updateFile.getProperty("psml-locators"); + String portlets = updateFile.getProperty("portlets"); + + // Re-register application + String fullAppPath = this.webAppDir + "/" + portletApp; + DirectoryHelper paDirHelper = new DirectoryHelper(new File(fullAppPath)); + System.out.println(">>> Updating app " + portletApp); + pam.startPortletApplication(portletApp, paDirHelper, null); + + // create j2 entities and rewrite PSML + createEntities(portletApp, parseNames(psmlLocators), parseNames(portlets)); + + // set status to success, j2 will delete it + event.setStatus(DeploymentStatus.STATUS_OKAY); + } + catch (Exception e) + { + String msg = "Failed to open update file: " + event.getPath(); + log.error(msg); + throw new DeploymentException(msg, e); + } + } + } + + public void initialize() + { + } + + public List parseNames(String strList) + { + List names = new ArrayList(); + if (strList == null || strList.length() == 0) + return names; + StringTokenizer tok = new StringTokenizer(strList, ", "); + while (tok.hasMoreTokens()) + { + String name = tok.nextToken(); + names.add(name); + } + return names; + } + + public int createEntities(String appName, List psmlLocators, List portletNames) + { + int count = 0; + Iterator locators= psmlLocators.iterator(); + while (locators.hasNext()) + { + String locatorString = (String)locators.next(); + ProfileLocator locator = Profiler.createLocator(); + locator.createFromPath(locatorString); + PSMLDocument doc = PsmlManager.getDocument(locator); + if (doc == null) + continue; + System.out.println(">>> processing page " + locatorString); + int innerCount = 0; + Iterator pNames = portletNames.iterator(); + while (pNames.hasNext()) + { + String pName = (String)pNames.next(); + Portlets portlets = doc.getPortlets(); + innerCount = traverse(portlets, innerCount, pName, appName); + } + if (innerCount > 0) + { + count++; + PsmlManager.saveDocument(doc); + } + } + return count; + } + + protected void createEntity(Entry entry, String portletName, String appName) + { + String registryKey = appName + "::" + portletName; + PortletDefinition portletDef = registry.getPortletDefinitionByUniqueName(registryKey); + if (null == portletDef) + { + log.error("Could not find portlet definition in registry for " + registryKey); + return; + } + PortletEntity entity = entityAccess.newPortletEntityInstance(portletDef); + try + { + entityAccess.storePortletEntity(entity); + Parameter param = entry.getParameter(J2_ENTITY); + if (param == null) + { + param = new PsmlParameter(); + param.setName(J2_ENTITY); + param.setValue(entity.getId().toString()); + entry.addParameter(param); + } + else + { + param.setValue(entity.getId().toString()); + } + System.out.println(">>> creating entity " + entity.getId().toString() + " for " + registryKey ); + } + catch (Exception e) + { + log.error("Failed to store portlet entity: " + registryKey, e); + } + } + + private int traverse(Portlets portlets, int count, String portletName, String appName) + { + // First let's add all the Entries in the current level + Iterator eItr = portlets.getEntriesIterator(); + while(eItr.hasNext()) + { + Entry entry = (Entry)eItr.next(); + if (entry.getParent().equals(portletName)) + { + createEntity(entry, portletName, appName); + count++; + } + } + + //Now if there are child levels, drill down recursively + if(portlets.getPortletsCount() > 0) + { + Iterator pItr = portlets.getPortletsIterator(); + while(pItr.hasNext()) + { + Portlets childPortlets = (Portlets)pItr.next(); + count += traverse(childPortlets, count, portletName, appName); + } + } + return count; + } + +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
