summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerOperationsDelegate.java77
-rw-r--r--modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/itest/ApplicationServerComponentTest.java28
2 files changed, 80 insertions, 25 deletions
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerOperationsDelegate.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerOperationsDelegate.java
index 5ac0413..60fa42d 100644
--- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerOperationsDelegate.java
+++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ApplicationServerOperationsDelegate.java
@@ -54,6 +54,29 @@ import org.rhq.core.system.SystemInfo;
* @author Jay Shaughnessy
*/
public class ApplicationServerOperationsDelegate {
+
+ private static class ExecutionFailedException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ @SuppressWarnings("unused")
+ public ExecutionFailedException() {
+ }
+
+ public ExecutionFailedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ExecutionFailedException(String message) {
+ super(message);
+ }
+
+ @SuppressWarnings("unused")
+ public ExecutionFailedException(Throwable cause) {
+ super(cause);
+ }
+ }
+
/**
* max amount of time to wait for server to show as unavailable after
* executing stop - in milliseconds
@@ -303,28 +326,30 @@ public class ApplicationServerOperationsDelegate {
* @return The result of the shutdown operation - is successful
*/
private OperationResult shutDown() {
- AvailabilityType avail = this.serverComponent.getAvailability();
- if (avail == AvailabilityType.DOWN) {
- OperationResult result = new OperationResult();
- result.setErrorMessage("The server is already shut down.");
- return result;
- }
-
Configuration pluginConfig = serverComponent.getResourceContext().getPluginConfiguration();
ApplicationServerShutdownMethod shutdownMethod = Enum.valueOf(ApplicationServerShutdownMethod.class,
pluginConfig.getSimple(ApplicationServerPluginConfigurationProperties.SHUTDOWN_METHOD_CONFIG_PROP)
.getStringValue());
- String resultMessage = ApplicationServerShutdownMethod.JMX.equals(shutdownMethod) ? shutdownViaJmx()
- : shutdownViaScript();
-
- avail = waitForServerToShutdown();
+ String errorMessage = null;
+ String resultMessage = null;
+ try {
+ resultMessage = ApplicationServerShutdownMethod.JMX.equals(shutdownMethod) ? shutdownViaJmx()
+ : shutdownViaScript();
+ } catch (ExecutionFailedException e) {
+ errorMessage = e.getMessage();
+ }
+
+ AvailabilityType avail = waitForServerToShutdown();
OperationResult result;
if (avail == AvailabilityType.UP) {
result = new OperationResult();
result.setErrorMessage("The server failed to shut down.");
} else {
- return new OperationResult(resultMessage);
+ result = new OperationResult();
+ result.setSimpleResult(resultMessage);
+ result.setErrorMessage(errorMessage);
}
+
return result;
}
@@ -333,7 +358,7 @@ public class ApplicationServerOperationsDelegate {
*
* @return success message if no errors are encountered
*/
- private String shutdownViaScript() {
+ private String shutdownViaScript() throws ExecutionFailedException {
File shutdownScriptFile = getShutdownScriptPath();
validateScriptFile(shutdownScriptFile,
ApplicationServerPluginConfigurationProperties.SHUTDOWN_SCRIPT_CONFIG_PROP);
@@ -378,8 +403,8 @@ public class ApplicationServerOperationsDelegate {
logExecutionResults(results);
if (results.getError() != null) {
- throw new RuntimeException("Error executing shutdown script while stopping AS instance. Exit code ["
- + results.getExitCode() + "]", results.getError());
+ throw new ExecutionFailedException("Error executing shutdown script while stopping AS instance. Exit code ["
+ + results.getExitCode() + "]: " + results.getError().getMessage(), results.getError());
}
return "The server has been shut down.";
@@ -397,7 +422,7 @@ public class ApplicationServerOperationsDelegate {
*
* @return success message if no errors are encountered
*/
- private String shutdownViaJmx() {
+ private String shutdownViaJmx() throws ExecutionFailedException {
Configuration pluginConfig = serverComponent.getResourceContext().getPluginConfiguration();
String mbeanName = pluginConfig.getSimple(
ApplicationServerPluginConfigurationProperties.SHUTDOWN_MBEAN_CONFIG_PROP).getStringValue();
@@ -406,7 +431,7 @@ public class ApplicationServerOperationsDelegate {
EmsConnection connection = this.serverComponent.getEmsConnection();
if (connection == null) {
- throw new RuntimeException("Can not connect to the server");
+ throw new ExecutionFailedException("Can not connect to the server");
}
EmsBean bean = connection.getBean(mbeanName);
EmsOperation operation = bean.getOperation(operationName);
@@ -422,14 +447,18 @@ public class ApplicationServerOperationsDelegate {
* method, we'd need a clever way for the user to specify parameters
* anyway.
*/
- List<EmsParameter> params = operation.getParameters();
- int count = params.size();
- if (count == 0)
- operation.invoke(new Object[0]);
- else { // overloaded operation
- operation.invoke(new Object[] { 0 }); // return code of 0
+ try {
+ List<EmsParameter> params = operation.getParameters();
+ int count = params.size();
+ if (count == 0)
+ operation.invoke(new Object[0]);
+ else { // overloaded operation
+ operation.invoke(new Object[] { 0 }); // return code of 0
+ }
+ } catch (RuntimeException e) {
+ throw new ExecutionFailedException("Shutting down the server using JMX failed: " + e.getMessage(), e);
}
-
+
return "The server has been shut down.";
}
diff --git a/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/itest/ApplicationServerComponentTest.java b/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/itest/ApplicationServerComponentTest.java
index 2bc7f47..6d60b85 100644
--- a/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/itest/ApplicationServerComponentTest.java
+++ b/modules/plugins/jboss-as-5/src/test/java/org/rhq/plugins/jbossas5/itest/ApplicationServerComponentTest.java
@@ -24,6 +24,8 @@ package org.rhq.plugins.jbossas5.itest;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
import java.io.File;
import java.util.Arrays;
@@ -50,6 +52,7 @@ import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pluginapi.configuration.ListPropertySimpleWrapper;
import org.rhq.core.pluginapi.configuration.MapPropertySimpleWrapper;
+import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.core.pluginapi.util.FileUtils;
import org.rhq.core.pluginapi.util.StartScriptConfiguration;
import org.rhq.core.system.ProcessInfo;
@@ -197,9 +200,32 @@ public class ApplicationServerComponentTest extends AbstractJBossAS5PluginTest {
avail = getAvailability(getServerResource());
assertEquals(avail, AvailabilityType.DOWN);
+ //change the plugin config to shutdown via JMX
+ Configuration pluginConfig = getServerResource().getPluginConfiguration();
+ pluginConfig.getSimple("shutdownMethod").setValue("JMX");
+ restartServerResourceComponent();
+
+ //invoke the shutdown operation again and assert that it actually ran and generated some error message.
+ OperationResult operationResult = invokeOperation(getServerResource(), SHUTDOWN_OPERATION_NAME, null);
+ avail = getAvailability(getServerResource());
+ assertEquals(avail, AvailabilityType.DOWN);
+ assertNotNull(operationResult.getErrorMessage());
+
+ //ok, now try the same with the script shutdown method
+ pluginConfig = getServerResource().getPluginConfiguration();
+ pluginConfig.getSimple("shutdownMethod").setValue("SCRIPT");
+ restartServerResourceComponent();
+
+ //invoke the shutdown operation again and assert that it actually ran
+ operationResult = invokeOperation(getServerResource(), SHUTDOWN_OPERATION_NAME, null);
+ avail = getAvailability(getServerResource());
+ assertEquals(avail, AvailabilityType.DOWN);
+ assertNull(operationResult.getErrorMessage());
+ assertEquals(operationResult.getSimpleResult(), "The server has been shut down.");
+
// Before restarting it, add some stuff to the 'startScriptEnv' and 'startScriptArgs' props so we can verify
// they are used correctly by the Start op.
- Configuration pluginConfig = getServerResource().getPluginConfiguration();
+ pluginConfig = getServerResource().getPluginConfiguration();
StartScriptConfiguration startScriptConfig = new StartScriptConfiguration(pluginConfig);
// Add a var to the start script env.