[jboss-cvs] JBossAS SVN: r89748 - in branches/JBPAPP_5_0: profileservice/src/main/org/jboss/profileservice/management/upload and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 3 11:44:31 EDT 2009
Author: emuckenhuber
Date: 2009-06-03 11:44:31 -0400 (Wed, 03 Jun 2009)
New Revision: 89748
Added:
branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java
Modified:
branches/JBPAPP_5_0/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java
branches/JBPAPP_5_0/profileservice/src/main/org/jboss/profileservice/management/upload/SerializableDeploymentID.java
branches/JBPAPP_5_0/server/src/etc/conf/all/bootstrap/profile.xml
branches/JBPAPP_5_0/server/src/etc/conf/default/bootstrap/profile.xml
branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java
branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java
Log:
sync latest changes with 5_x branch
Modified: branches/JBPAPP_5_0/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java
===================================================================
--- branches/JBPAPP_5_0/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java 2009-06-03 15:40:09 UTC (rev 89747)
+++ branches/JBPAPP_5_0/profileservice/src/main/org/jboss/profileservice/management/AbstractTemplateCreator.java 2009-06-03 15:44:31 UTC (rev 89748)
@@ -39,6 +39,10 @@
public class AbstractTemplateCreator
{
+ /** Some filtered characters. */
+ private static final char[] filtered = new char[] { '/', '\\', ':', '*', '?', '"', '<', '>', '|' };
+ private static final char replace = '_';
+
/** The deployment manager. */
private DeploymentManager deploymentMgr;
@@ -87,7 +91,7 @@
try
{
// Apply the template
- String deploymentName = template.getDeploymentName(deploymentBaseName);
+ String deploymentName = template.getDeploymentName(fixDeploymentName(deploymentBaseName));
if(deploymentName == null)
throw new IllegalStateException("getDeploymentName returned a null value.");
// Wrap info to exclude all removed properties
@@ -155,6 +159,14 @@
return repositoryNames[0];
}
+ protected String fixDeploymentName(String name)
+ {
+ String fixed = name;
+ for(char c : filtered)
+ fixed = fixed.replace(c, replace);
+ return fixed;
+ }
+
protected String[] distribute(String name, URL url) throws Exception
{
DeploymentProgress progress = this.deploymentMgr.distribute(name, url, true);
Modified: branches/JBPAPP_5_0/profileservice/src/main/org/jboss/profileservice/management/upload/SerializableDeploymentID.java
===================================================================
--- branches/JBPAPP_5_0/profileservice/src/main/org/jboss/profileservice/management/upload/SerializableDeploymentID.java 2009-06-03 15:40:09 UTC (rev 89747)
+++ branches/JBPAPP_5_0/profileservice/src/main/org/jboss/profileservice/management/upload/SerializableDeploymentID.java 2009-06-03 15:44:31 UTC (rev 89748)
@@ -33,6 +33,8 @@
import org.jboss.profileservice.spi.ProfileKey;
/**
+ * A serializable DeploymentID implementation.
+ *
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
@@ -52,7 +54,7 @@
public SerializableDeploymentID(DeploymentID deployment)
{
- this(deployment.getNames(), deployment.getProfile(), deployment.getDescription());
+ this(deployment.getNames(), deployment.getProfile(), deployment.getDescription(), deployment.getDeploymentOptions());
}
public SerializableDeploymentID(String name, ProfileKey profileKey, String description)
@@ -62,11 +64,21 @@
public SerializableDeploymentID(String[] names, ProfileKey profileKey, String description)
{
+ this(names, profileKey, description, new DeploymentOption[0]);
+ }
+
+ public SerializableDeploymentID(String[] names, ProfileKey profileKey, String description, DeploymentOption... options)
+ {
this.deploymentNames = names;
this.profileKey = profileKey;
this.description = description;
this.copyContent = true; // by default we copy content
this.options = new HashSet<DeploymentOption>();
+ if(options != null && options.length > 0)
+ {
+ for(DeploymentOption option : options)
+ addDeploymentOption(option);
+ }
}
public String[] getNames()
@@ -170,6 +182,8 @@
buffer.append(", copyContent=").append(copyContent);
if(description != null)
buffer.append(", description=").append(description);
+ if(options != null && options.isEmpty() == false)
+ buffer.append(", options=").append(options);
return buffer.toString();
}
Modified: branches/JBPAPP_5_0/server/src/etc/conf/all/bootstrap/profile.xml
===================================================================
--- branches/JBPAPP_5_0/server/src/etc/conf/all/bootstrap/profile.xml 2009-06-03 15:40:09 UTC (rev 89747)
+++ branches/JBPAPP_5_0/server/src/etc/conf/all/bootstrap/profile.xml 2009-06-03 15:44:31 UTC (rev 89748)
@@ -175,7 +175,7 @@
<!-- The attachment store -->
<bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore">
- <constructor><parameter><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
+ <constructor><parameter class="java.io.File"><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
<property name="mainDeployer"><inject bean="MainDeployer" /></property>
<property name="serializer"><inject bean="AttachmentsSerializer" /></property>
<property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
Modified: branches/JBPAPP_5_0/server/src/etc/conf/default/bootstrap/profile.xml
===================================================================
--- branches/JBPAPP_5_0/server/src/etc/conf/default/bootstrap/profile.xml 2009-06-03 15:40:09 UTC (rev 89747)
+++ branches/JBPAPP_5_0/server/src/etc/conf/default/bootstrap/profile.xml 2009-06-03 15:44:31 UTC (rev 89748)
@@ -144,7 +144,7 @@
<!-- The attachment store -->
<bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore">
- <constructor><parameter><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
+ <constructor><parameter class="java.io.File"><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
<property name="mainDeployer"><inject bean="MainDeployer" /></property>
<property name="serializer"><inject bean="AttachmentsSerializer" /></property>
<property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
Modified: branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java
===================================================================
--- branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java 2009-06-03 15:40:09 UTC (rev 89747)
+++ branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/hotdeploy/HDScanner.java 2009-06-03 15:44:31 UTC (rev 89748)
@@ -30,6 +30,7 @@
import java.util.concurrent.TimeUnit;
import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
import org.jboss.logging.Logger;
import org.jboss.profileservice.spi.ModificationInfo;
import org.jboss.profileservice.spi.MutableProfile;
@@ -337,17 +338,25 @@
for (ModificationInfo info : modifiedDeployments)
{
ProfileDeployment ctx = info.getDeployment();
- switch (info.getStatus())
+ try
{
- case ADDED:
- case MODIFIED:
- deployer.addDeployment(ctx);
- modifiedDeploymentNames.add(ctx.getName());
- break;
- case REMOVED:
- deployer.removeDeployment(ctx.getName());
- break;
+ switch (info.getStatus())
+ {
+ case ADDED:
+ case MODIFIED:
+ deployer.addDeployment(ctx);
+ modifiedDeploymentNames.add(ctx.getName());
+ break;
+ case REMOVED:
+ deployer.removeDeployment(ctx.getName());
+ modified = true;
+ break;
+ }
}
+ catch(DeploymentException e)
+ {
+ log.warn("Failed to add deployment " + ctx.getName());
+ }
}
if (modifiedDeployments.size() > 0)
Modified: branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
===================================================================
--- branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java 2009-06-03 15:40:09 UTC (rev 89747)
+++ branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java 2009-06-03 15:44:31 UTC (rev 89748)
@@ -32,6 +32,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.zip.ZipInputStream;
@@ -148,7 +149,7 @@
public String addDeploymentContent(String vfsPath, InputStream contentIS, DeploymentOption... options)
throws IOException
- {
+ {
boolean trace = log.isTraceEnabled();
// Suspend hot deployment checking
if( trace )
@@ -168,49 +169,63 @@
// Check if it already exists
boolean exists = contentFile.exists();
- if(exists && isFailIfAlreadyExists())
+ // Get the content options
+ List<DeploymentOption> deploymentOptions = Arrays.asList(options);
+ boolean failIfAlreadyExsists = isFailIfAlreadyExists()
+ || deploymentOptions.contains(DeploymentOption.FailIfExists);
+ if(exists && failIfAlreadyExsists)
throw new SyncFailedException("Deployment content already exists: "+ contentFile.getAbsolutePath());
- // Copy streams
- FileOutputStream fos = new FileOutputStream(contentFile);
- try
+ // Check if we need unpack this deployment
+ if(deploymentOptions.contains(DeploymentOption.Explode))
{
- byte[] tmp = new byte[4096];
- int read;
- while((read = contentIS.read(tmp)) > 0)
- {
- if (trace)
- log.trace("write, " + read);
- fos.write(tmp, 0, read);
- }
- fos.flush();
- // Get the vfs uri and add the VFS uri to the cached VFS uris
- VirtualFile contentVF = VFS.getRoot(contentFile.toURI());
- try
- {
- // Add the new virtual file to the cache
- repositoryName = addVirtualFileCache(contentVF);
-
- // Cleanup
- if(exists)
- cleanUpRoot(contentVF);
- }
- catch(URISyntaxException e)
- {
- throw new RuntimeException(e); // This should not happen anyway
- }
+ // Unjar
+ DeploymentUtils.unjar(contentIS, contentFile);
}
- finally
+ else
{
+ // Copy stream
+ FileOutputStream fos = new FileOutputStream(contentFile);
try
{
- fos.close();
+ byte[] tmp = new byte[4096];
+ int read;
+ while((read = contentIS.read(tmp)) > 0)
+ {
+ if (trace)
+ log.trace("write, " + read);
+ fos.write(tmp, 0, read);
+ }
+ fos.flush();
}
- catch (IOException ignored)
+ finally
{
- }
+ try
+ {
+ fos.close();
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
}
+ // Get the vfs uri and add the VFS uri to the cached VFS uris
+ VirtualFile contentVF = VFS.getRoot(contentFile.toURI());
+ try
+ {
+ // Add the new virtual file to the cache
+ repositoryName = addVirtualFileCache(contentVF);
+
+ // Cleanup
+ if(exists)
+ cleanUpRoot(contentVF);
+ }
+ catch(URISyntaxException e)
+ {
+ throw new RuntimeException(e); // This should not happen anyway
+ }
+
// Lock the content
setDeploymentContentFlags(repositoryName, DeploymentContentFlags.LOCKED);
}
Copied: branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java (from rev 89727, branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java)
===================================================================
--- branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java (rev 0)
+++ branches/JBPAPP_5_0/system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java 2009-06-03 15:44:31 UTC (rev 89748)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.repository;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+/**
+ * Deployment utils.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DeploymentUtils
+{
+
+ /**
+ * Try to unpack a IS. a fork of JarUtils.unjar} which does not close the IS.
+ *
+ * @param in
+ * @param dest
+ * @throws IOException
+ */
+ public static void unjar(InputStream in, File dest) throws IOException
+ {
+ if (!dest.exists())
+ {
+ dest.mkdirs();
+ }
+ if (!dest.isDirectory())
+ {
+ throw new IOException("Destination must be a directory.");
+ }
+ JarInputStream jin = new JarInputStream(in);
+ byte[] buffer = new byte[1024];
+
+ ZipEntry entry = jin.getNextEntry();
+ while (entry != null)
+ {
+ String fileName = entry.getName();
+ if (fileName.charAt(fileName.length() - 1) == '/')
+ {
+ fileName = fileName.substring(0, fileName.length() - 1);
+ }
+ if (fileName.charAt(0) == '/')
+ {
+ fileName = fileName.substring(1);
+ }
+ if (File.separatorChar != '/')
+ {
+ fileName = fileName.replace('/', File.separatorChar);
+ }
+ File file = new File(dest, fileName);
+ if (entry.isDirectory())
+ {
+ // make sure the directory exists
+ file.mkdirs();
+ jin.closeEntry();
+ }
+ else
+ {
+ // make sure the directory exists
+ File parent = file.getParentFile();
+ if (parent != null && !parent.exists())
+ {
+ parent.mkdirs();
+ }
+
+ // dump the file
+ OutputStream out = new FileOutputStream(file);
+ int len = 0;
+ while ((len = jin.read(buffer, 0, buffer.length)) != -1)
+ {
+ out.write(buffer, 0, len);
+ }
+ out.flush();
+ out.close();
+ jin.closeEntry();
+ file.setLastModified(entry.getTime());
+ }
+ entry = jin.getNextEntry();
+ }
+ /* Explicity write out the META-INF/MANIFEST.MF so that any headers such
+ as the Class-Path are see for the unpackaged jar
+ */
+ Manifest mf = jin.getManifest();
+ if (mf != null)
+ {
+ File file = new File(dest, "META-INF/MANIFEST.MF");
+ File parent = file.getParentFile();
+ if( parent.exists() == false )
+ {
+ parent.mkdirs();
+ }
+ OutputStream out = new FileOutputStream(file);
+ mf.write(out);
+ out.flush();
+ out.close();
+ }
+ }
+
+}
+
Modified: branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java
===================================================================
--- branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java 2009-06-03 15:40:09 UTC (rev 89747)
+++ branches/JBPAPP_5_0/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java 2009-06-03 15:44:31 UTC (rev 89748)
@@ -36,7 +36,9 @@
import org.jboss.managed.api.DeploymentState;
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedProperty;
import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.profileservice.spi.DeploymentOption;
import org.jboss.profileservice.spi.NoSuchDeploymentException;
import org.jboss.profileservice.spi.ProfileKey;
import org.jboss.profileservice.spi.ProfileService;
@@ -105,7 +107,7 @@
start = distributeAndStart(NESTED_DEPLOYMENT, true, false);
assertComplete(start);
- Thread.sleep(50);
+ Thread.sleep(5);
redeployCheckComplete(NESTED_DEPLOYMENT);
}
@@ -115,10 +117,7 @@
log.debug("Failed ", e);
throw e;
}
- finally
- {
- stopAndRemove(new String[] { NESTED_DEPLOYMENT });
- }
+ stopAndRemove(new String[] { NESTED_DEPLOYMENT });
}
/**
@@ -178,11 +177,39 @@
}
/**
+ * Test the deployment options
+ *
+ * @throws Exception
+ */
+ public void testDeploymentOptions() throws Exception
+ {
+ try
+ {
+ // Test exploded
+ distributeAndStart(NESTED_DEPLOYMENT,
+ new DeploymentOption[] { DeploymentOption.Explode});
+
+ // Test fail if exsits
+ DeploymentProgress override = getDeploymentManager().distribute(NESTED_DEPLOYMENT,
+ getDeployURL(NESTED_DEPLOYMENT),
+ new DeploymentOption[] { DeploymentOption.FailIfExists});
+ override.run();
+ assertFailed(override);
+ }
+ catch(Exception e)
+ {
+ log.error("Failed ", e);
+ throw e;
+ }
+// stopAndRemove(new String[] { NESTED_DEPLOYMENT } );
+ }
+
+ /**
* Test copyContent to the deployers target profile.
*
* @throws Exception
*/
- public void testDepoyersDir() throws Exception
+ public void testDeployersDir() throws Exception
{
getDeploymentManager().loadProfile(deployersKey);
try
@@ -224,11 +251,13 @@
ComponentType type = new ComponentType("MCBean", "ServerConfig");
ManagedComponent mc = mgtView.getComponent("jboss.system:type=ServerConfig", type);
assertNotNull(mc);
- String homeDir = (String) ((SimpleValue) mc.getProperty("serverHomeDir").getValue()).getValue();
+ ManagedProperty homeDirProperty = mc.getProperty("serverHomeDir");
+ assertNotNull("serverHomeDir property exists", homeDirProperty);
+ String homeDir = (String) ((SimpleValue) homeDirProperty.getValue()).getValue();
assertNotNull(homeDir);
// Manually copy the deployment
- copyFile(new File(homeDir, "deploy/"), HD_DEPLOYMENT);
+ File output = copyFile(new File(homeDir, "deploy/"), HD_DEPLOYMENT);
// Wait for HDScanner
Thread.sleep(10000);
@@ -238,15 +267,27 @@
assertNotNull("hd-beans not deployed", md);
assertEquals("deployment started", DeploymentState.STARTED, md.getDeploymentState());
- stopAndRemove(new String[] { HD_DEPLOYMENT });
+ output.delete();
+ // Wait for HDScanner
+ Thread.sleep(10000);
+ try
+ {
+ mgtView.getDeployment(HD_DEPLOYMENT);
+ fail(HD_DEPLOYMENT + " not undeployed");
+ }
+ catch(NoSuchDeploymentException e)
+ {
+ // ok
+ }
}
- private void copyFile(File dir, String filename) throws Exception
+ private File copyFile(File dir, String filename) throws Exception
{
+ File output = null;
InputStream is = getDeployURL(filename).openStream();
try
{
- File output = new File(dir, filename);
+ output = new File(dir, filename);
FileOutputStream fos = new FileOutputStream(output);
try
{
@@ -267,6 +308,7 @@
{
is.close();
}
+ return output;
}
void deployFailed(boolean isCopyContent) throws Exception
@@ -313,7 +355,32 @@
// Return the start deployment progress
return start;
}
+
+ DeploymentProgress distributeAndStart(String deploymentName, DeploymentOption... options) throws Exception
+ {
+ // The deployment manager
+ DeploymentManager deployMgr = getDeploymentManager();
+ // Distribute
+ DeploymentProgress distribute = deployMgr.distribute(deploymentName,
+ getDeployURL(deploymentName), options);
+ distribute.run();
+ // Distribute always has to complete
+ assertComplete(distribute);
+ // check if the app is stopped
+ assertDeploymentState(distribute.getDeploymentID(), DeploymentState.STOPPED);
+
+ // Get the repository names
+ String[] uploadedNames = distribute.getDeploymentID().getRepositoryNames();
+ assertNotNull(uploadedNames);
+
+ // Start
+ DeploymentProgress start = deployMgr.start(uploadedNames);
+ start.run();
+ // Return the start deployment progress
+ return start;
+ }
+
void redeployCheckComplete(String name) throws Exception
{
// The deployment manager
More information about the jboss-cvs-commits
mailing list