[jboss-cvs] JBossAS SVN: r89729 - in trunk: system/src/main/org/jboss/system/server/profileservice/repository and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 3 09:00:51 EDT 2009
Author: emuckenhuber
Date: 2009-06-03 09:00:50 -0400 (Wed, 03 Jun 2009)
New Revision: 89729
Added:
trunk/system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java
Modified:
trunk/profileservice/src/main/org/jboss/profileservice/management/upload/SerializableDeploymentID.java
trunk/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
trunk/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java
Log:
[JBAS-6693] handle deploymentOptions
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/upload/SerializableDeploymentID.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/upload/SerializableDeploymentID.java 2009-06-03 12:54:32 UTC (rev 89728)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/upload/SerializableDeploymentID.java 2009-06-03 13:00:50 UTC (rev 89729)
@@ -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: trunk/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java 2009-06-03 12:54:32 UTC (rev 89728)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/BasicDeploymentRepository.java 2009-06-03 13:00:50 UTC (rev 89729)
@@ -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: trunk/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)
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/DeploymentUtils.java 2009-06-03 13:00:50 UTC (rev 89729)
@@ -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: trunk/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java 2009-06-03 12:54:32 UTC (rev 89728)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/test/DeploymentManagerUnitTestCase.java 2009-06-03 13:00:50 UTC (rev 89729)
@@ -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 });
}
/**
@@ -182,11 +181,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
@@ -232,11 +259,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);
@@ -246,15 +275,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
{
@@ -275,6 +316,7 @@
{
is.close();
}
+ return output;
}
void deployFailed(boolean isCopyContent) throws Exception
@@ -321,7 +363,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