modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
| 64 +++++-----
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/DeploymentUtils.java
| 50 +++----
2 files changed, 62 insertions(+), 52 deletions(-)
New commits:
commit 8d936c05f084df1856d895cb10d60d72ebeddd64
Author: Filip Drabek <fdrabek(a)dhcp-lab-136.englab.brq.redhat.com>
Date: Fri Mar 4 20:50:43 2011 +0100
BZ-669542 - Deploying exploded WAR to JBoss EAP 5 throws NPE operation fails
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
index 1b2d7f0..5733012 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
@@ -30,11 +30,13 @@ import java.util.jar.Manifest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.jboss.deployers.spi.management.KnownDeploymentTypes;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.deploy.DeploymentManager;
import org.jboss.managed.api.ManagedDeployment;
import org.jboss.profileservice.spi.ProfileKey;
+
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.content.PackageDetailsKey;
import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
@@ -60,7 +62,7 @@ public class ManagedComponentDeployer implements Deployer {
private PackageDownloader downloader;
private ProfileServiceConnection profileServiceConnection;
-
+
/**
* @param downloader
*/
@@ -88,7 +90,7 @@ public class ManagedComponentDeployer implements Deployer {
abortIfApplicationAlreadyDeployed(resourceType, archiveFile);
Configuration deployTimeConfig = details.getDeploymentTimeConfiguration();
- @SuppressWarnings( { "ConstantConditions" })
+ @SuppressWarnings({ "ConstantConditions" })
boolean deployExploded =
deployTimeConfig.getSimple("deployExploded").getBooleanValue();
DeploymentManager deploymentManager =
this.profileServiceConnection.getDeploymentManager();
@@ -114,8 +116,9 @@ public class ManagedComponentDeployer implements Deployer {
deploymentManager.loadProfile(FARM_PROFILE_KEY);
}
+ String[] deployedArchives;
try {
- DeploymentUtils.deployArchive(deploymentManager, archiveFile,
deployExploded);
+ deployedArchives = DeploymentUtils.deployArchive(deploymentManager,
archiveFile, deployExploded);
} finally {
// Make sure to switch back to the 'applications' profile if we
switched to the 'farm' profile above.
if (deployFarmed) {
@@ -125,29 +128,38 @@ public class ManagedComponentDeployer implements Deployer {
//if deployed exploded, we need to store the sha of source package for
correct versioning
if (deployExploded) {
- String shaString = new
MessageDigestGenerator(MessageDigestGenerator.SHA_256)
- .getDigestString(archiveFile);
- String deploymentName =
deployTimeConfig.getSimple(DEPLOYMENT_NAME_PROPERTY).getStringValue();
- URI deployePackageURI = URI.create(deploymentName);
- // e.g.: foo.war
- String path = deployePackageURI.getPath();
- File location = new File(path);
- //We've located the deployed
- if ((location != null) && (location.isDirectory())) {
- File manifestFile = new File(location,
"META-INF/MANIFEST.MF");
- Manifest manifest;
- if (manifestFile.exists()) {
- FileInputStream inputStream = new FileInputStream(manifestFile);
- manifest = new Manifest(inputStream);
- inputStream.close();
- } else {
- manifest = new Manifest();
+ for (String archive : deployedArchives) {
+
+ String shaString = new
MessageDigestGenerator(MessageDigestGenerator.SHA_256)
+ .getDigestString(archiveFile);
+
+ URI deployePackageURI = URI.create(archive);
+ // e.g.: foo.war
+ String path = deployePackageURI.getPath();
+ File location = new File(path);
+ //We've located the deployed
+ if ((location != null) && (location.isDirectory())) {
+ File manifestFile = new File(location,
"META-INF/MANIFEST.MF");
+ Manifest manifest;
+ if (manifestFile.exists()) {
+ FileInputStream inputStream = new
FileInputStream(manifestFile);
+ manifest = new Manifest(inputStream);
+ inputStream.close();
+ } else {
+ File metaInf = new File(location, "META-INF");
+ if (!metaInf.exists())
+ if (!metaInf.mkdir())
+ throw new Exception("Could not create directory
" + location + "META-INF.");
+
+ manifestFile = new File(metaInf, "MANIFEST.MF");
+ manifest = new Manifest();
+ }
+ Attributes attribs = manifest.getMainAttributes();
+ attribs.putValue("RHQ-Sha256", shaString);
+ FileOutputStream outputStream = new
FileOutputStream(manifestFile);
+ manifest.write(outputStream);
+ outputStream.close();
}
- Attributes attribs = manifest.getMainAttributes();
- attribs.putValue("RHQ-Sha256", shaString);
- FileOutputStream outputStream = new FileOutputStream(manifestFile);
- manifest.write(outputStream);
- outputStream.close();
}
}
@@ -179,5 +191,5 @@ public class ManagedComponentDeployer implements Deployer {
throw new IllegalArgumentException("An application named '"
+ archiveFileName
+ "' is already deployed.");
}
- }
+ }
}
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/DeploymentUtils.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/DeploymentUtils.java
index 7d720e2..7fb2ee8 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/DeploymentUtils.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/DeploymentUtils.java
@@ -23,18 +23,20 @@
package org.rhq.plugins.jbossas5.util;
import java.io.File;
-import java.net.URL;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.jboss.deployers.spi.management.deploy.DeploymentManager;
import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
import org.jboss.profileservice.spi.DeploymentOption;
+
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.util.exception.ThrowableUtil;
@@ -72,15 +74,14 @@ public class DeploymentUtils {
*
* @throws Exception if the deployment fails for any reason
*/
- public static void deployArchive(DeploymentManager deploymentManager, File
archiveFile, boolean deployExploded)
+ public static String[] deployArchive(DeploymentManager deploymentManager, File
archiveFile, boolean deployExploded)
throws Exception {
String archiveFileName = archiveFile.getName();
LOG.debug("Deploying '" + archiveFileName + "'
(deployExploded=" + deployExploded + ")...");
URL contentURL;
try {
contentURL = archiveFile.toURI().toURL();
- }
- catch (MalformedURLException e) {
+ } catch (MalformedURLException e) {
throw new IllegalArgumentException("Failed to convert archive file path
'" + archiveFile + "' to URL.", e);
}
List<DeploymentOption> deploymentOptions = new
ArrayList<DeploymentOption>();
@@ -91,20 +92,19 @@ public class DeploymentUtils {
DeploymentStatus distributeStatus;
Exception distributeFailure = null;
try {
- progress = deploymentManager.distribute(archiveFileName, contentURL,
deploymentOptions
- .toArray(new DeploymentOption[deploymentOptions.size()]));
+ progress = deploymentManager.distribute(archiveFileName, contentURL,
+ deploymentOptions.toArray(new
DeploymentOption[deploymentOptions.size()]));
distributeStatus = run(progress);
if (distributeStatus.isFailed()) {
- distributeFailure = (distributeStatus.getFailure() != null) ?
distributeStatus.getFailure() :
- new Exception("Distribute failed for unknown
reason.");
+ distributeFailure = (distributeStatus.getFailure() != null) ?
distributeStatus.getFailure()
+ : new Exception("Distribute failed for unknown reason.");
}
- }
- catch (Exception e) {
+ } catch (Exception e) {
distributeFailure = e;
}
if (distributeFailure != null) {
throw new Exception("Failed to distribute '" + contentURL +
"' to '" + archiveFileName + "' - cause: "
- + ThrowableUtil.getAllMessages(distributeFailure));
+ + ThrowableUtil.getAllMessages(distributeFailure));
}
// Now that we've successfully distributed the deployment, we need to start
it.
@@ -115,16 +115,15 @@ public class DeploymentUtils {
progress = deploymentManager.start(deploymentNames);
startStatus = run(progress);
if (startStatus.isFailed()) {
- startFailure = (startStatus.getFailure() != null) ?
startStatus.getFailure() :
- new Exception("Start failed for unknown reason.");
+ startFailure = (startStatus.getFailure() != null) ?
startStatus.getFailure() : new Exception(
+ "Start failed for unknown reason.");
}
- }
- catch (Exception e) {
+ } catch (Exception e) {
startFailure = e;
}
if (startFailure != null) {
- LOG.error("Failed to start deployment " +
Arrays.asList(deploymentNames)
- + " during deployment of '" + archiveFileName +
"'. Backing out the deployment...", startFailure);
+ LOG.error("Failed to start deployment " +
Arrays.asList(deploymentNames) + " during deployment of '"
+ + archiveFileName + "'. Backing out the deployment...",
startFailure);
// If start failed, the app is invalid, so back out the deployment.
DeploymentStatus removeStatus;
Exception removeFailure = null;
@@ -132,23 +131,22 @@ public class DeploymentUtils {
progress = deploymentManager.remove(deploymentNames);
removeStatus = run(progress);
if (removeStatus.isFailed()) {
- removeFailure = (removeStatus.getFailure() != null) ?
removeStatus.getFailure() :
- new Exception("Remove failed for unknown reason.");
+ removeFailure = (removeStatus.getFailure() != null) ?
removeStatus.getFailure() : new Exception(
+ "Remove failed for unknown reason.");
}
- }
- catch (Exception e) {
+ } catch (Exception e) {
removeFailure = e;
}
if (removeFailure != null) {
- LOG.error("Failed to remove deployment " +
Arrays.asList(deploymentNames)
- + " after start failure.", removeFailure);
+ LOG.error("Failed to remove deployment " +
Arrays.asList(deploymentNames) + " after start failure.",
+ removeFailure);
}
throw new Exception("Failed to start deployment " +
Arrays.asList(deploymentNames)
- + " during deployment of '" + archiveFileName + "'
- cause: " +
- ThrowableUtil.getAllMessages(startFailure));
+ + " during deployment of '" + archiveFileName + "'
- cause: "
+ + ThrowableUtil.getAllMessages(startFailure));
}
// If we made it this far, the deployment (distribution+start) was successful.
- return;
+ return deploymentNames;
}
public static DeploymentStatus run(DeploymentProgress progress) {