modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
| 105 +++++-----
1 file changed, 55 insertions(+), 50 deletions(-)
New commits:
commit 397cb79ad080285aadb93a9257318d4c1ee2c9b6
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Fri Jul 29 12:51:50 2011 -0400
some general cleanup/refactoring + improved error handling
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 6314d3a..4315155 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
@@ -16,7 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
package org.rhq.plugins.jbossas5.deploy;
import java.io.File;
@@ -60,14 +59,10 @@ public class ManagedComponentDeployer implements Deployer {
private static final ProfileKey FARM_PROFILE_KEY = new ProfileKey("farm");
private static final ProfileKey APPLICATIONS_PROFILE_KEY = new
ProfileKey("applications");
- public static final String DEPLOYMENT_NAME_PROPERTY = "deploymentName";
private PackageDownloader downloader;
private ProfileServiceConnection profileServiceConnection;
- /**
- * @param downloader
- */
public ManagedComponentDeployer(ProfileServiceConnection profileServiceConnection,
PackageDownloader downloader) {
this.downloader = downloader;
this.profileServiceConnection = profileServiceConnection;
@@ -120,9 +115,9 @@ public class ManagedComponentDeployer implements Deployer {
deploymentManager.loadProfile(FARM_PROFILE_KEY);
}
- String[] deployedArchives;
+ String[] deploymentNames;
try {
- deployedArchives = DeploymentUtils.deployArchive(deploymentManager,
archiveFile, deployExploded);
+ deploymentNames = 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) {
@@ -130,62 +125,72 @@ public class ManagedComponentDeployer implements Deployer {
}
}
- //if deployed exploded, we need to store the sha of source package for
correct versioning
+ if (deploymentNames == null || deploymentNames.length != 1) {
+ throw new RuntimeException("deploy operation returned invalid
result: " + deploymentNames);
+ }
+
+ // e.g.: vfszip:/C:/opt/jboss-6.0.0.Final/server/default/deploy/foo.war
+ String deploymentName = deploymentNames[0];
+
+ // If deployed exploded, we need to store the SHA of source package in
META-INF/MANIFEST.MF for correct
+ // versioning.
if (deployExploded) {
- 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();
+ MessageDigestGenerator sha256Generator = new
MessageDigestGenerator(MessageDigestGenerator.SHA_256);
+ String shaString = sha256Generator.calcDigestString(archiveFile);
+ URI deploymentURI = URI.create(deploymentName);
+ // e.g.: /C:/opt/jboss-6.0.0.Final/server/default/deploy/foo.war
+ String deploymentPath = deploymentURI.getPath();
+ File deploymentFile = new File(deploymentPath);
+ if (deploymentFile.isDirectory()) {
+ File manifestFile = new File(deploymentFile,
"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(deploymentFile, "META-INF");
+ if (!metaInf.exists())
+ if (!metaInf.mkdir())
+ throw new Exception("Could not create directory
" + deploymentFile + "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();
+ } else {
+ LOG.error("Exploded deployment '" + deploymentFile
+ + "' does not exist or is not a directory - unable
to add RHQ versioning metadata to META-INF/MANIFEST.MF.");
}
}
+ // Reload the management view to pickup the ManagedDeployment for the app we
just deployed.
ManagementView managementView =
this.profileServiceConnection.getManagementView();
managementView.load();
- for (String deployedArchive : deployedArchives) {
- ManagedDeployment managedDeployment;
- try {
- managedDeployment = managementView.getDeployment(deployedArchive);
- } catch (NoSuchDeploymentException e) {
- LOG.error("Failed to find managed deployment '" +
deployedArchive + "' after deploying '"
- + archiveName + "'.");
- continue;
- }
+
+ ManagedDeployment managedDeployment = null;
+ try {
+ managedDeployment = managementView.getDeployment(deploymentName);
+ } catch (NoSuchDeploymentException e) {
+ LOG.error("Failed to find managed deployment '" +
deploymentName + "' after deploying '"
+ + archiveName + "', so cannot start the
application.");
+ createResourceReport.setStatus(CreateResourceStatus.INVALID_ARTIFACT);
+ createResourceReport.setErrorMessage("Unable to start application
'" + deploymentName
+ + "' after deploying it, since lookup of the associated
ManagedDeployment failed.");
+ }
+ if (managedDeployment != null) {
DeploymentState state = managedDeployment.getDeploymentState();
if (state != DeploymentState.STARTED) {
// The app failed to start - do not consider this a FAILURE, since it
was at least deployed
// successfully. However, set the status to INVALID_ARTIFACT and set
an error message, so
// the user is informed of the condition.
createResourceReport.setStatus(CreateResourceStatus.INVALID_ARTIFACT);
- createResourceReport.setErrorMessage("Failed to start
application '" + deployedArchive + "' after deploying it.");
- break;
+ createResourceReport.setErrorMessage("Failed to start
application '" + deploymentName
+ + "' after deploying it.");
}
}
Show replies by date