modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/CreateResourceRunner.java
| 19 ++--
modules/plugins/apache/src/main/java/org/rhq/plugins/www/util/WWWUtils.java
| 41 +++++-----
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
| 35 +++++++-
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/util/DeploymentUtils.java
| 31 +------
4 files changed, 70 insertions(+), 56 deletions(-)
New commits:
commit 38ce0dd10f62d6f5f190c3dc82d8bc03d8d5a998
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)
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/ManagedComponentDeployer.java
b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/deploy/ManagedComponentDeployer.java
index 5733012..6314d3a 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
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 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
@@ -34,7 +34,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;
@@ -72,7 +74,9 @@ public class ManagedComponentDeployer implements Deployer {
}
public void deploy(CreateResourceReport createResourceReport, ResourceType
resourceType) {
+ createResourceReport.setStatus(null);
File archiveFile = null;
+
try {
ResourcePackageDetails details = createResourceReport.getPackageDetails();
PackageDetailsKey key = details.getKey();
@@ -163,11 +167,34 @@ public class ManagedComponentDeployer 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 7fb2ee8..560cb9d 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
@@ -107,7 +107,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;
@@ -122,30 +122,11 @@ 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 deploymentNames;
}
commit 6002385bcf18e960d5ef4312d656e13ebf870239
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Tue Jun 21 14:43:16 2011 -0400
set read timeout on http url connections to prevent calls to down URLs from hanging
when running on certain versions of JRockit
(
https://bugzilla.redhat.com/show_bug.cgi?id=714817)
diff --git a/modules/plugins/apache/src/main/java/org/rhq/plugins/www/util/WWWUtils.java
b/modules/plugins/apache/src/main/java/org/rhq/plugins/www/util/WWWUtils.java
index 5afb34a..a979565 100644
--- a/modules/plugins/apache/src/main/java/org/rhq/plugins/www/util/WWWUtils.java
+++ b/modules/plugins/apache/src/main/java/org/rhq/plugins/www/util/WWWUtils.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2008 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
@@ -21,8 +21,6 @@ package org.rhq.plugins.www.util;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
@@ -32,36 +30,37 @@ import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
-import javax.xml.ws.handler.LogicalHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
- * Helper class that contains methods that send http requests and evaluate results
+ * Helper class that contains methods that send HTTP requests and evaluate results.
+ *
* @author Ian Springer
*/
public abstract class WWWUtils {
- /**
- * Sends a HEAD request to the passed url and returns if the server was
reachable
- * @param httpURL a http or https URL to check
- * @return true if connecting to the URL succeeds, or false otherwise
- */
-
+ /**
+ * Sends a HEAD request for the passed URL and returns true if the URL was
reachable.
+ *
+ * @param httpURL a http or https URL to check
+ * @return true if connecting to the URL succeeds, or false otherwise
+ */
public static boolean isAvailable(URL httpURL) {
String failMsg = "URL [" + httpURL + "] returned
unavailable";
try {
HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection();
connection.setRequestMethod("HEAD");
connection.setConnectTimeout(3000);
+ connection.setReadTimeout(1000);
if (connection instanceof HttpsURLConnection) {
disableCertificateVerification((HttpsURLConnection) connection);
}
connection.connect();
- // get the respone code to actually trigger sending the Request.
+ // get the response code to actually trigger sending the Request.
connection.getResponseCode();
} catch (SSLException e) {
Log log = LogFactory.getLog(WWWUtils.class);
@@ -77,9 +76,10 @@ public abstract class WWWUtils {
}
/**
- * Get the content of the 'Server:' header
+ * Get the content of the 'Server' header.
+ *
* @param httpURL a http or https URL to get the header from
- * @return The contents of the header or null if anything went wrong or the field was
not present.
+ * @return the contents of the header or null if anything went wrong or the field was
not present.
*/
public static String getServerHeader(URL httpURL) {
String ret;
@@ -88,8 +88,10 @@ public abstract class WWWUtils {
HttpURLConnection connection = (HttpURLConnection) httpURL.openConnection();
connection.setRequestMethod("HEAD");
connection.setConnectTimeout(3000);
+ connection.setReadTimeout(1000);
+
connection.connect();
- // get the respone code to actually trigger sending the Request.
+ // get the response code to actually trigger sending the Request.
connection.getResponseCode();
ret = connection.getHeaderField("Server");
}
@@ -108,9 +110,11 @@ public abstract class WWWUtils {
}
public void checkClientTrusted(X509Certificate[] certs, String authType)
{
+ return;
}
public void checkServerTrusted(X509Certificate[] certs, String authType)
{
+ return;
}
}
};
@@ -120,14 +124,11 @@ public abstract class WWWUtils {
connection.setSSLSocketFactory(sslContext.getSocketFactory());
connection.setHostnameVerifier(new HostnameVerifier() {
@Override
- public boolean verify(String s, SSLSession sslSession) {
+ public boolean verify(String hostname, SSLSession sslSession) {
return true;
}
});
- } catch (NoSuchAlgorithmException e) {
- Log log = LogFactory.getLog(WWWUtils.class);
- log.warn("Failed to disable certificate validation.", e);
- } catch (KeyManagementException e) {
+ } catch (Exception e) {
Log log = LogFactory.getLog(WWWUtils.class);
log.warn("Failed to disable certificate validation.", e);
}