modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
| 19 +++-
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/AbstractDeployer.java
| 40 ++++++++--
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/DeploymentUtils.java
| 39 ++-------
3 files changed, 56 insertions(+), 42 deletions(-)
New commits:
commit 0a60272e37cc77bde16a420ea2d0bd09acb714b5
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Tue Jun 21 14:46:04 2011 -0400
[BZ 713448] in the EAR/WAR Resource creation code, if the ManagedDeployment fails to
start, do not consider the Resource creation a failure and rollback the deployment
(
https://bugzilla.redhat.com/show_bug.cgi?id=713448)
(cherry picked from commit 38ce0dd10f62d6f5f190c3dc82d8bc03d8d5a998)
Conflicts:
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/AbstractDeployer.java
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/DeploymentUtils.java
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
index e03eaba..2ce32ef 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
@@ -129,14 +129,14 @@ public class CreateResourceRunner implements Callable, Runnable {
}
// Ensure a resource key was returned from the plugin if the plugin reports
the create was successful
- if ((reportedStatus == CreateResourceStatus.SUCCESS) && (resourceKey
== null)) {
- log.warn("Plugin did not indicate the result of the request: "
+ requestId);
+ if ((isSuccessStatus(reportedStatus)) && (resourceKey == null)) {
+ log.warn("Plugin did not indicate the resource key for this request:
" + requestId);
errorMessage = "Plugin did not indicate a resource key for this
request.";
status = CreateResourceStatus.FAILURE;
}
// RHQ-666 - The plugin should provide a resource name if the create was
successful
- if ((reportedStatus == CreateResourceStatus.SUCCESS) && (resourceName
== null)) {
+ if ((isSuccessStatus(reportedStatus)) && (resourceName == null)) {
log.warn("Plugin did not indicate a resource name for the request:
" + requestId);
errorMessage = "Plugin did not indicate a resource name for this
request.";
status = CreateResourceStatus.FAILURE;
@@ -175,16 +175,21 @@ public class CreateResourceRunner implements Callable, Runnable {
// Trigger a service scan on the parent resource to have the newly created
resource discovered if the plugin
// said the create was successful
- if (runRuntimeScan && (status == CreateResourceStatus.SUCCESS)) {
- log.info("Scanning for newly created resource");
+ if (runRuntimeScan && isSuccessStatus(status)) {
+ log.info("Scanning for newly created Resource...");
try {
InventoryManager inventoryManager =
PluginContainer.getInstance().getInventoryManager();
inventoryManager.performServiceScan(parentResourceId);
} catch (Throwable t) {
- log.error("Error received while attempting runtime scan for newly
created resource");
+ log.error("Error received while attempting runtime scan for newly
created Resource...");
}
}
return response;
}
-}
\ No newline at end of file
+
+ private static boolean isSuccessStatus(CreateResourceStatus status) {
+ return (status == CreateResourceStatus.SUCCESS) || (status ==
CreateResourceStatus.INVALID_CONFIGURATION)
+ || (status == CreateResourceStatus.INVALID_ARTIFACT);
+ }
+ }
\ No newline at end of file
diff --git
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/AbstractDeployer.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/AbstractDeployer.java
index 5dff4ef..72b51cf 100644
---
a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/AbstractDeployer.java
+++
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/AbstractDeployer.java
@@ -1,6 +1,6 @@
/*
- * Jopr Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -37,7 +37,9 @@ 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.DeploymentState;
import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
import org.jboss.profileservice.spi.ProfileKey;
import org.rhq.core.domain.configuration.Configuration;
@@ -71,7 +73,9 @@ public abstract class AbstractDeployer implements Deployer {
}
public void deploy(CreateResourceReport createResourceReport, ResourceType
resourceType) {
+ createResourceReport.setStatus(null);
File archiveFile = null;
+
try {
ResourcePackageDetails details = createResourceReport.getPackageDetails();
PackageDetailsKey key = details.getKey();
@@ -115,8 +119,9 @@ public abstract class AbstractDeployer 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) {
@@ -152,11 +157,34 @@ public abstract class AbstractDeployer implements Deployer {
}
}
- // Deployment was successful!
+ 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;
+ }
+ 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.setResourceName(archiveName);
createResourceReport.setResourceKey(archiveName);
- createResourceReport.setStatus(CreateResourceStatus.SUCCESS);
-
+ if (createResourceReport.getStatus() == null) {
+ // Deployment was 100% successful, including starting the app.
+ createResourceReport.setStatus(CreateResourceStatus.SUCCESS);
+ }
} catch (Throwable t) {
log.error("Error deploying application for request [" +
createResourceReport + "].", t);
createResourceReport.setStatus(CreateResourceStatus.FAILURE);
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..abd0982 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
@@ -1,6 +1,6 @@
/*
* Jopr Management Platform
- * Copyright (C) 2005-2009 Red Hat, Inc.
+ * Copyright (C) 2005-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -64,15 +64,16 @@ public class DeploymentUtils {
/**
* Deploys (i.e. distributes then starts) the specified archive file.
*
+ *
* @param deploymentManager
* @param archiveFile
* @param deployExploded
- *
+ *
* @return
*
* @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 + ")...");
@@ -107,7 +108,7 @@ public class DeploymentUtils {
+ ThrowableUtil.getAllMessages(distributeFailure));
}
- // Now that we've successfully distributed the deployment, we need to start
it.
+ // Now that we've successfully distributed the deployment, try to start it.
String[] deploymentNames = progress.getDeploymentID().getRepositoryNames();
DeploymentStatus startStatus;
Exception startFailure = null;
@@ -123,32 +124,12 @@ public class DeploymentUtils {
startFailure = e;
}
if (startFailure != null) {
- 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;
- try {
- progress = deploymentManager.remove(deploymentNames);
- removeStatus = run(progress);
- if (removeStatus.isFailed()) {
- removeFailure = (removeStatus.getFailure() != null) ?
removeStatus.getFailure() :
- new Exception("Remove failed for unknown reason.");
- }
- }
- catch (Exception e) {
- removeFailure = e;
- }
- if (removeFailure != null) {
- 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));
+ // There are times when the user expects the app to fail to start, so just
log a warning.
+ LOG.warn("Failed to start deployment " +
Arrays.asList(deploymentNames) + " during deployment of '"
+ + archiveFileName + "'.", startFailure);
}
- // If we made it this far, the deployment (distribution+start) was successful.
- return;
+
+ return deploymentNames;
}
public static DeploymentStatus run(DeploymentProgress progress) {