Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 866289 Details for
Bug 994250
rhqctl always returns exit code 0
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Uses wrapper to catch the return value instead of the ExecuteException
fix_rvalue.patch (text/plain), 45.54 KB, created by
Michael Burman
on 2014-02-21 22:34:20 UTC
(
hide
)
Description:
Uses wrapper to catch the return value instead of the ExecuteException
Filename:
MIME Type:
Creator:
Michael Burman
Created:
2014-02-21 22:34:20 UTC
Size:
45.54 KB
patch
obsolete
>From 11bfb6b277d23446f7f22ff16a9df5eb8ce95cd5 Mon Sep 17 00:00:00 2001 >From: Michael Burman <yak@iki.fi> >Date: Wed, 19 Feb 2014 16:03:41 +0200 >Subject: [PATCH] Use assist-class to catch ExecuteException and return correct > shell return code to the caller > >--- > .../server/control/command/AbstractInstall.java | 122 +++++++-------------- > .../org/rhq/server/control/command/Console.java | 15 +-- > .../org/rhq/server/control/command/Install.java | 2 +- > .../org/rhq/server/control/command/Remove.java | 26 ++--- > .../java/org/rhq/server/control/command/Start.java | 36 ++---- > .../org/rhq/server/control/command/Status.java | 65 +---------- > .../java/org/rhq/server/control/command/Stop.java | 53 +++------ > .../org/rhq/server/control/command/Upgrade.java | 32 ++---- > .../rhq/server/control/util/ExecutorAssist.java | 55 ++++++++++ > 9 files changed, 143 insertions(+), 263 deletions(-) > create mode 100644 modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/util/ExecutorAssist.java > >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java >index 121aef5..81189cf 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/AbstractInstall.java >@@ -41,13 +41,7 @@ import java.util.prefs.Preferences; > import org.apache.commons.cli.CommandLine; > import org.apache.commons.cli.CommandLineParser; > import org.apache.commons.cli.PosixParser; >-import org.apache.commons.exec.DefaultExecuteResultHandler; >-import org.apache.commons.exec.DefaultExecutor; >-import org.apache.commons.exec.Executor; >-import org.apache.commons.exec.PumpStreamHandler; >- > import org.jboss.as.controller.client.ModelControllerClient; >- > import org.rhq.common.jbossas.client.controller.DeploymentJBossASClient; > import org.rhq.common.jbossas.client.controller.MCCHelper; > import org.rhq.core.util.PropertiesFileUpdate; >@@ -57,6 +51,7 @@ import org.rhq.core.util.stream.StreamUtil; > import org.rhq.server.control.ControlCommand; > import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; >+import org.rhq.server.control.util.ExecutorAssist; > > /** > * Common code for commands that perform installs. Basically shared code for Install and Upgrade commands. >@@ -82,27 +77,27 @@ public abstract class AbstractInstall extends ControlCommand { > > protected int installWindowsService(File workingDir, String batFile, boolean replaceExistingService, boolean start) > throws Exception { >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(workingDir); >- executor.setStreamHandler(new PumpStreamHandler()); >+// Executor executor = new DefaultExecutor(); >+// executor.setWorkingDirectory(workingDir); >+// executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > > int rValue = RHQControl.EXIT_CODE_OK; > > if (replaceExistingService) { > commandLine = getCommandLine(batFile, "stop"); >- rValue = Math.max(rValue, executor.execute(commandLine)); >+ rValue = Math.max(rValue, ExecutorAssist.execute(workingDir, commandLine)); > > commandLine = getCommandLine(batFile, "remove"); >- rValue = Math.max(rValue, executor.execute(commandLine)); >+ rValue = Math.max(rValue, ExecutorAssist.execute(workingDir, commandLine)); > } > > commandLine = getCommandLine(batFile, "install"); >- rValue = Math.max(rValue, executor.execute(commandLine)); >+ rValue = Math.max(rValue, ExecutorAssist.execute(workingDir, commandLine)); > > if (start) { > commandLine = getCommandLine(batFile, "start"); >- rValue = Math.max(rValue, executor.execute(commandLine)); >+ rValue = Math.max(rValue, ExecutorAssist.execute(workingDir, commandLine)); > } > return rValue; > } >@@ -251,7 +246,7 @@ public abstract class AbstractInstall extends ControlCommand { > return RHQControl.EXIT_CODE_OK; > } > >- int rValue = 0; >+ int rValue = RHQControl.EXIT_CODE_OK; > > try { > File agentBinDir = new File(agentBasedir, "bin"); >@@ -260,16 +255,13 @@ public abstract class AbstractInstall extends ControlCommand { > } > > log.info("Updating RHQ Agent Service..."); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(agentBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > > // Ensure the windows service is up to date. [re-]install the windows service. > > commandLine = getCommandLine("rhq-agent-wrapper", "stop"); > try { >- rValue = executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(agentBinDir, commandLine)); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to stop agent service", e); >@@ -277,15 +269,14 @@ public abstract class AbstractInstall extends ControlCommand { > > commandLine = getCommandLine("rhq-agent-wrapper", "remove"); > try { >- rValue = Math.max(rValue, executor.execute(commandLine)); >+ rValue = Math.max(rValue, ExecutorAssist.execute(agentBinDir, commandLine)); > } catch (Exception e) { > // Ignore, service may not exist, script returns 1 > log.debug("Failed to uninstall agent service", e); > } > > commandLine = getCommandLine("rhq-agent-wrapper", "install"); >- rValue = Math.max(rValue, executor.execute(commandLine)); >- >+ rValue = Math.max(rValue, ExecutorAssist.execute(agentBinDir, commandLine)); > } catch (IOException e) { > log.error("An error occurred while updating the agent service: " + e.getMessage()); > throw e; >@@ -295,7 +286,7 @@ public abstract class AbstractInstall extends ControlCommand { > } > > protected int startAgent(final File agentBasedir) throws Exception { >- int rValue; >+ int rValue = RHQControl.EXIT_CODE_OK; > > try { > File agentBinDir = new File(agentBasedir, "bin"); >@@ -304,14 +295,11 @@ public abstract class AbstractInstall extends ControlCommand { > } > > log.info("Starting RHQ agent..."); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(agentBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > > // For *nix, just start the server in the background, for Win, now that the service is installed, start it > commandLine = getCommandLine("rhq-agent-wrapper", "start"); >- rValue = executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(agentBinDir, commandLine)); > > // if any errors occur after now, we need to stop the agent > addUndoTask(new ControlCommand.UndoTask("Stopping agent") { >@@ -336,18 +324,14 @@ public abstract class AbstractInstall extends ControlCommand { > } > > log.debug("Stopping RHQ agent..."); >- >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(agentBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > >- int rValue = 0; >+ int rValue = RHQControl.EXIT_CODE_OK; > > if (isWindows()) { > try { > commandLine = getCommandLine("rhq-agent-wrapper", "stop"); >- rValue = executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(agentBinDir, commandLine)); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to stop agent service", e); >@@ -357,9 +341,7 @@ public abstract class AbstractInstall extends ControlCommand { > String pid = getAgentPid(); > if (pid != null) { > commandLine = getCommandLine("rhq-agent-wrapper", "kill"); >- rValue = executor.execute(commandLine); >- } else { >- rValue = RHQControl.EXIT_CODE_OK; >+ rValue = Math.max(rValue, ExecutorAssist.execute(agentBinDir, commandLine)); > } > } > return rValue; >@@ -373,29 +355,27 @@ public abstract class AbstractInstall extends ControlCommand { > } > > log.debug("Stopping RHQ server..."); >- >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(serverBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "stop"); > >- int rValue; >+ int rValue = RHQControl.EXIT_CODE_OK; > > if (isWindows()) { > try { >- rValue = executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(serverBinDir, commandLine)); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to stop server service", e); > rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { >- rValue = executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(serverBinDir, commandLine)); > } > return rValue; > } > >- protected void startRHQServerForInstallation() throws IOException { >+ protected int startRHQServerForInstallation() throws IOException { >+ int rValue = RHQControl.EXIT_CODE_OK; >+ > try { > log.info("The RHQ Server must be started to complete its installation. Starting the RHQ server in preparation of running the server installer..."); > >@@ -407,30 +387,27 @@ public abstract class AbstractInstall extends ControlCommand { > "Something is already listening to port 9999 - shut it down before installing the server."); > } > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; >- >+ > if (isWindows()) { > // For windows we will [re-]install the server as a windows service, then start the service. > > commandLine = getCommandLine("rhq-server", "stop"); >- executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(getBinDir(), commandLine)); > > commandLine = getCommandLine("rhq-server", "remove"); >- executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(getBinDir(), commandLine)); > > commandLine = getCommandLine("rhq-server", "install"); >- executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(getBinDir(), commandLine)); > > commandLine = getCommandLine("rhq-server", "start"); >- executor.execute(commandLine); >+ rValue = Math.max(rValue, ExecutorAssist.execute(getBinDir(), commandLine)); > > } else { > // For *nix, just start the server in the background >- commandLine = getCommandLine("rhq-server", "start"); >- executor.execute(commandLine, new DefaultExecuteResultHandler()); >+ commandLine = getCommandLine("rhq-server", "start"); >+ rValue = Math.max(rValue, ExecutorAssist.execute(getBinDir(), commandLine, true)); > } > > addUndoTaskToStopComponent("--server"); // if any errors occur after now, we need to stop the server >@@ -439,10 +416,6 @@ public abstract class AbstractInstall extends ControlCommand { > log.info("Waiting for the RHQ Server to start in preparation of running the server installer..."); > commandLine = getCommandLine("rhq-installer", "--test"); > >- Executor installerExecutor = new DefaultExecutor(); >- installerExecutor.setWorkingDirectory(getBinDir()); >- installerExecutor.setStreamHandler(new PumpStreamHandler()); >- > int exitCode = 0; > int numTries = 0, maxTries = 30; > do { >@@ -457,8 +430,7 @@ public abstract class AbstractInstall extends ControlCommand { > if (numTries > 1) { > log.info("Still waiting to run the server installer..."); > } >- exitCode = installerExecutor.execute(commandLine); >- >+ exitCode = ExecutorAssist.execute(getBinDir(), commandLine); > } while (exitCode != 0); > > log.info("The RHQ Server is ready to be upgraded by the server installer."); >@@ -467,6 +439,8 @@ public abstract class AbstractInstall extends ControlCommand { > log.error("An error occurred while starting the RHQ server: " + e.getMessage()); > throw e; > } >+ >+ return rValue; > } > > protected int runRHQServerInstaller() throws IOException { >@@ -485,20 +459,14 @@ public abstract class AbstractInstall extends ControlCommand { > } > }); > >+ /** >+ * @TODO There's no way this could catch the resultValue.. >+ */ >+ > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-installer"); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); >- >- DefaultExecuteResultHandler executeHandler = new DefaultExecuteResultHandler(); >- >- executor.execute(commandLine, executeHandler); >+ ExecutorAssist.execute(getBinDir(), commandLine, true); > log.info("The server installer is running"); >- if (executeHandler.hasResult()) { >- return executeHandler.getExitValue(); >- } else { >- return RHQControl.EXIT_CODE_OK; // the installer really didn't exit yet, but just indicate we started it OK >- } >+ return RHQControl.EXIT_CODE_OK; // the installer really didn't exit yet, so we don't know the result > } catch (Exception e) { > log.error("An error occurred while starting the server installer: " + e.getMessage()); > return RHQControl.EXIT_CODE_NOT_INSTALLED; >@@ -588,11 +556,7 @@ public abstract class AbstractInstall extends ControlCommand { > }); > > // execute the storage installer now >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); >- >- int exitCode = executor.execute(commandLine); >+ int exitCode = ExecutorAssist.execute(getBinDir(), commandLine); > log.info("The storage node installer has finished with an exit value of " + exitCode); > > // the storage node is installed AND running now so, if we fail later, we need to shut the storage node down >@@ -639,11 +603,7 @@ public abstract class AbstractInstall extends ControlCommand { > .addArgument("--install=" + agentBasedir.getParentFile().getAbsolutePath()) > .addArgument("--log=" + new File(getLogDir(), "rhq-agent-update.log")); > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBaseDir()); >- executor.setStreamHandler(new PumpStreamHandler()); >- >- int exitValue = executor.execute(commandLine); >+ int exitValue = ExecutorAssist.execute(getBaseDir(), commandLine); > log.info("The agent installer finished running with exit value " + exitValue); > return exitValue; > } catch (Exception e) { >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Console.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Console.java >index 6039e9d..06638fb 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Console.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Console.java >@@ -27,13 +27,10 @@ import java.io.InputStreamReader; > > import org.apache.commons.cli.CommandLine; > import org.apache.commons.cli.Options; >-import org.apache.commons.exec.DefaultExecutor; >-import org.apache.commons.exec.Executor; >-import org.apache.commons.exec.PumpStreamHandler; >- > import org.rhq.server.control.ControlCommand; > import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; >+import org.rhq.server.control.util.ExecutorAssist; > > /** > * @author John Sanda >@@ -121,20 +118,14 @@ public class Console extends ControlCommand { > > org.apache.commons.exec.CommandLine commandLine = new org.apache.commons.exec.CommandLine(getCommandLine(false, > "cassandra", "-f")); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(storageBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); >- return executor.execute(commandLine); >+ return ExecutorAssist.execute(storageBinDir, commandLine); > } > > private int startServerInForeground() throws Exception { > log.debug("Starting RHQ server in foreground"); > > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "console"); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); >- return executor.execute(commandLine); >+ return ExecutorAssist.execute(getBinDir(), commandLine); > } > > private int startAgentInForeground() throws Exception { >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java >index f8d37d9..85eec4b 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Install.java >@@ -163,7 +163,7 @@ public class Install extends AbstractInstall { > } > } else { > startedServer = true; >- startRHQServerForInstallation(); >+ rValue = Math.max(rValue, startRHQServerForInstallation()); > int installerStatusCode = runRHQServerInstaller(); > rValue = Math.max(rValue, installerStatusCode); > if (installerStatusCode == RHQControl.EXIT_CODE_OK) { >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Remove.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Remove.java >index 1de4250..5213f9f 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Remove.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Remove.java >@@ -29,13 +29,10 @@ import java.io.File; > > import org.apache.commons.cli.CommandLine; > import org.apache.commons.cli.Options; >-import org.apache.commons.exec.DefaultExecutor; >-import org.apache.commons.exec.Executor; >-import org.apache.commons.exec.PumpStreamHandler; >- > import org.rhq.server.control.ControlCommand; > import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; >+import org.rhq.server.control.util.ExecutorAssist; > > /** > * This command is registered on Windows only. It performs Windows service removal. >@@ -127,9 +124,6 @@ public class Remove extends ControlCommand { > private int removeStorageService() throws Exception { > log.debug("Stopping RHQ storage node"); > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > > int rValue; >@@ -137,7 +131,7 @@ public class Remove extends ControlCommand { > if (isWindows()) { > commandLine = getCommandLine("rhq-storage", "remove"); > try { >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); > } catch (Exception e) { > log.debug("Failed to remove storage service", e); > rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; >@@ -149,7 +143,7 @@ public class Remove extends ControlCommand { > System.out.println("RHQ storage node (pid=" + pid + ") is stopping..."); > > commandLine = new org.apache.commons.exec.CommandLine("kill").addArgument(pid); >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); > > System.out.println("RHQ storage node has stopped"); > } else { >@@ -163,9 +157,6 @@ public class Remove extends ControlCommand { > private int removeServerService() throws Exception { > log.debug("Stopping RHQ server"); > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > > int rValue; >@@ -173,7 +164,7 @@ public class Remove extends ControlCommand { > if (isWindows()) { > try { > commandLine = getCommandLine("rhq-server", "remove"); >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to remove server service", e); >@@ -184,7 +175,7 @@ public class Remove extends ControlCommand { > > if (pid != null) { > commandLine = getCommandLine("rhq-server", "stop"); >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); > } else { > rValue = RHQControl.EXIT_CODE_OK; > } >@@ -196,9 +187,6 @@ public class Remove extends ControlCommand { > log.debug("Stopping RHQ agent"); > > File agentBinDir = new File(getAgentBasedir(), "bin"); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(agentBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > > int rValue; >@@ -206,7 +194,7 @@ public class Remove extends ControlCommand { > if (isWindows()) { > try { > commandLine = getCommandLine("rhq-agent-wrapper", "remove"); >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(agentBinDir, commandLine); > } catch (Exception e) { > // Ignore, service may not exist, script returns 1 > log.debug("Failed to remove agent service", e); >@@ -217,7 +205,7 @@ public class Remove extends ControlCommand { > > if (pid != null) { > commandLine = getCommandLine("rhq-agent-wrapper", "stop"); >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(agentBinDir, commandLine); > } else { > rValue = RHQControl.EXIT_CODE_OK; > } >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java >index e2ef3a8..0e99eb4 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Start.java >@@ -31,13 +31,10 @@ import java.util.Map; > > import org.apache.commons.cli.CommandLine; > import org.apache.commons.cli.Options; >-import org.apache.commons.exec.DefaultExecutor; >-import org.apache.commons.exec.Executor; >-import org.apache.commons.exec.PumpStreamHandler; >- > import org.rhq.server.control.ControlCommand; > import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; >+import org.rhq.server.control.util.ExecutorAssist; > > /** > * @author John Sanda >@@ -134,8 +131,6 @@ public class Start extends ControlCommand { > private int startStorage() throws Exception { > log.debug("Starting RHQ storage node"); > >- Executor executor = new DefaultExecutor(); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > > int rValue; >@@ -150,15 +145,10 @@ public class Start extends ControlCommand { > env.put("JAVA_HOME", javaHome); > > if (isWindows()) { >- executor.setWorkingDirectory(getBinDir()); > commandLine = getCommandLine("rhq-storage", "start"); >- try { >- rValue = executor.execute(commandLine, env); >- >- } catch (Exception e) { >- // Ignore, service may not exist or may already be running, script returns 1 >- log.debug("Failed to start storage service", e); >- rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine, env); >+ if(rValue != RHQControl.EXIT_CODE_OK) { >+ log.debug("Failed to start storage service, return value" + rValue); > } > } else { > File storageBinDir = new File(getStorageBasedir(), "bin"); >@@ -172,9 +162,7 @@ public class Start extends ControlCommand { > rValue = RHQControl.EXIT_CODE_OK; > } else { > commandLine = getCommandLine(false, "cassandra", "-p", pidFile.getAbsolutePath()); >- executor.setWorkingDirectory(storageBinDir); >- >- rValue = executor.execute(commandLine, env); >+ rValue = ExecutorAssist.execute(storageBinDir, commandLine, env); > } > } > return rValue; >@@ -183,23 +171,20 @@ public class Start extends ControlCommand { > private int startRHQServer() throws Exception { > log.debug("Starting RHQ server"); > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "start"); > > int rValue; > > if (isWindows()) { > try { >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to start server service", e); > rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); > } > return rValue; > } >@@ -208,23 +193,20 @@ public class Start extends ControlCommand { > log.debug("Starting RHQ agent"); > > File agentBinDir = new File(getAgentBasedir(), "bin"); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(agentBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "start"); > > int rValue; > > if (isWindows()) { > try { >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(agentBinDir, commandLine); > } catch (Exception e) { > // Ignore, service may not exist or be running, , script returns 1 > log.debug("Failed to start agent service", e); > rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; > } > } else { >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(agentBinDir, commandLine); > } > > return rValue; >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Status.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Status.java >index 052ae9e..d6d8861 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Status.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Status.java >@@ -29,14 +29,10 @@ import java.io.File; > > import org.apache.commons.cli.CommandLine; > import org.apache.commons.cli.Options; >-import org.apache.commons.exec.DefaultExecutor; >-import org.apache.commons.exec.ExecuteException; >-import org.apache.commons.exec.Executor; >-import org.apache.commons.exec.PumpStreamHandler; >- > import org.rhq.server.control.ControlCommand; > import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; >+import org.rhq.server.control.util.ExecutorAssist; > > /** > * @author John Sanda >@@ -125,24 +121,9 @@ public class Status extends ControlCommand { > int rValue = RHQControl.EXIT_CODE_OK; > > if (isWindows()) { >- Executor executor = new DefaultExecutor(); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; >- executor.setWorkingDirectory(getBinDir()); > commandLine = getCommandLine("rhq-storage", "status"); >- try { >- rValue = executor.execute(commandLine); >- } catch (ExecuteException ee) { >- log.debug("Failed to check storage service status", ee); >- rValue = ee.getExitValue(); >- if (rValue == RHQControl.EXIT_CODE_OK) { >- // if somehow we were told it was OK, change it to unknown since it can't be OK >- rValue = RHQControl.EXIT_CODE_STATUS_UNKNOWN; >- } >- } catch (Exception e) { >- log.debug("Failed to check storage service status", e); >- rValue = RHQControl.EXIT_CODE_STATUS_UNKNOWN; >- } >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); > } else { > final String ANSI_RED = "\u001B[31m"; > final String ANSI_GREEN = "\u001B[32m"; >@@ -164,21 +145,7 @@ public class Status extends ControlCommand { > log.debug("Checking RHQ server status"); > > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "status"); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); >- >- int rValue; >- try { >- rValue = executor.execute(commandLine); >- } catch (ExecuteException ee) { >- rValue = ee.getExitValue(); >- if (rValue == RHQControl.EXIT_CODE_OK) { >- // if somehow we were told it was OK, change it to unknown since it can't be OK >- rValue = RHQControl.EXIT_CODE_STATUS_UNKNOWN; >- } >- } >- return rValue; >+ return ExecutorAssist.execute(getBinDir(), commandLine); > } > > private int checkAgentStatus() throws Exception { >@@ -187,30 +154,6 @@ public class Status extends ControlCommand { > File agentBinDir = new File(getAgentBasedir(), "bin"); > > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "status"); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(agentBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); >- >- int rValue; >- try { >- rValue = executor.execute(commandLine); >- } catch (ExecuteException e) { >- // For windows the JSW exit code for a status check is expected to be a mask value and the agent wrapper >- // .bat will return it explicitly. We can ignore it and assume that the logged output is sufficient. >- // See http://wrapper.tanukisoftware.com/doc/english/launch-win.html#standalone-status >- if (!isWindows()) { >- // UNIX script will exit with 1 if its not running, this is expected, so don't throw exception on 1 >- if (e.getExitValue() != 1) { >- throw e; >- } >- } >- rValue = e.getExitValue(); >- if (rValue == RHQControl.EXIT_CODE_OK) { >- // if somehow we were told it was OK, change it to unknown since it can't be OK >- rValue = RHQControl.EXIT_CODE_STATUS_UNKNOWN; >- } >- } >- >- return rValue; >+ return ExecutorAssist.execute(agentBinDir, commandLine); > } > } >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Stop.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Stop.java >index 7ef66b4..b5d7ea3 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Stop.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Stop.java >@@ -29,12 +29,9 @@ import java.io.File; > > import org.apache.commons.cli.CommandLine; > import org.apache.commons.cli.Options; >-import org.apache.commons.exec.DefaultExecutor; >-import org.apache.commons.exec.Executor; >-import org.apache.commons.exec.PumpStreamHandler; >- > import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; >+import org.rhq.server.control.util.ExecutorAssist; > > /** > * @author John Sanda >@@ -125,23 +122,17 @@ public class Stop extends AbstractInstall { > private int stopStorage() throws Exception { > log.debug("Stopping RHQ storage node"); > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine; > > int rValue; > > if (isWindows()) { > commandLine = getCommandLine("rhq-storage", "stop"); >- try { >- rValue = executor.execute(commandLine); >- System.out.println("RHQ storage node has stopped"); >- >- } catch (Exception e) { >- // Ignore, service may not exist or be running, script returns 1 >- log.debug("Failed to stop storage service", e); >- rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); >+ if(rValue != RHQControl.EXIT_CODE_OK) { >+ log.debug("Failed to stop storage service, return code " + rValue); >+ } else { >+ System.out.println("RHQ storage node has stopped"); > } > } else { > if (isStorageRunning()) { >@@ -165,26 +156,20 @@ public class Stop extends AbstractInstall { > private int stopRHQServer() throws Exception { > log.debug("Stopping RHQ server"); > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-server", "stop"); > > int rValue; > > if (isWindows()) { >- try { >- rValue = executor.execute(commandLine); >- } catch (Exception e) { >- // Ignore, service may not exist or be running, , script returns 1 >- log.debug("Failed to stop server service", e); >- rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; >- } >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); >+ if(rValue != RHQControl.EXIT_CODE_OK) { >+ log.debug("Failed to stop server service"); >+ } > } else { > String pid = getServerPid(); > > if (pid != null) { >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); > } else { > rValue = RHQControl.EXIT_CODE_OK; > } >@@ -196,26 +181,20 @@ public class Stop extends AbstractInstall { > log.debug("Stopping RHQ agent"); > > File agentBinDir = new File(getAgentBasedir(), "bin"); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(agentBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-agent-wrapper", "stop"); > > int rValue; > > if (isWindows()) { >- try { >- rValue = executor.execute(commandLine); >- } catch (Exception e) { >- // Ignore, service may not exist or be running, , script returns 1 >- log.debug("Failed to stop agent service", e); >- rValue = RHQControl.EXIT_CODE_OPERATION_FAILED; >- } >+ rValue = ExecutorAssist.execute(agentBinDir, commandLine); >+ if(rValue != RHQControl.EXIT_CODE_OK) { >+ log.debug("Failed to stop agent service, return value" + rValue); >+ } > } else { > String pid = getAgentPid(); > > if (pid != null) { >- rValue = executor.execute(commandLine); >+ rValue = ExecutorAssist.execute(agentBinDir, commandLine); > } else { > rValue = RHQControl.EXIT_CODE_OK; > } >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java >index 8195284..1ff3034 100644 >--- a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/command/Upgrade.java >@@ -37,10 +37,6 @@ import java.util.Properties; > > import org.apache.commons.cli.CommandLine; > import org.apache.commons.cli.Options; >-import org.apache.commons.exec.DefaultExecutor; >-import org.apache.commons.exec.Executor; >-import org.apache.commons.exec.PumpStreamHandler; >- > import org.rhq.core.util.PropertiesFileUpdate; > import org.rhq.core.util.exception.ThrowableUtil; > import org.rhq.core.util.file.FileReverter; >@@ -50,6 +46,7 @@ import org.rhq.core.util.stream.StreamUtil; > import org.rhq.server.control.ControlCommand; > import org.rhq.server.control.RHQControl; > import org.rhq.server.control.RHQControlException; >+import org.rhq.server.control.util.ExecutorAssist; > > /** > * @author Jay Shaughnessy >@@ -174,10 +171,7 @@ public class Upgrade extends AbstractInstall { > org.apache.commons.exec.CommandLine rhqctlStop = isRhq48OrLater(commandLine) ? getCommandLine(false, > "rhqctl", "stop") : getCommandLine("rhq-server", "stop"); > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(fromBinDir); >- executor.setStreamHandler(new PumpStreamHandler()); >- int exitValue = executor.execute(rhqctlStop); >+ int exitValue = ExecutorAssist.execute(fromBinDir, rhqctlStop); > if (exitValue == 0) { > log.info("The old installation components have been stopped"); > } else { >@@ -261,11 +255,7 @@ public class Upgrade extends AbstractInstall { > commandLine.addArgument("--estimate-only"); > } > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(new File(getBaseDir(), "bin")); // data migrator script is not in bin/internal >- executor.setStreamHandler(new PumpStreamHandler()); >- >- int exitValue = executor.execute(commandLine); >+ int exitValue = ExecutorAssist.execute(new File(getBaseDir(), "bin"), commandLine); > log.info("The data migrator finished with exit value " + exitValue); > rValue = exitValue; > } catch (Exception e) { >@@ -301,13 +291,9 @@ public class Upgrade extends AbstractInstall { > > org.apache.commons.exec.CommandLine commandLine = getCommandLine("rhq-storage-installer", "--upgrade", > getFromServerDir(rhqctlCommandLine).getAbsolutePath()); >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBinDir()); >- executor.setStreamHandler(new PumpStreamHandler()); > >- int exitCode = executor.execute(commandLine); >- log.info("The storage node upgrade has finished with an exit value of " + exitCode); >- rValue = exitCode; >+ rValue = ExecutorAssist.execute(getBinDir(), commandLine); >+ log.info("The storage node upgrade has finished with an exit value of " + rValue); > } catch (IOException e) { > log.error("An error occurred while running the storage node upgrade: " + e.getMessage()); > throw e; >@@ -350,7 +336,7 @@ public class Upgrade extends AbstractInstall { > } > > // start the server, the invoke the installer and wait for the server to be completely installed >- startRHQServerForInstallation(); >+ rValue = Math.max(rValue, startRHQServerForInstallation()); > int installerStatusCode = runRHQServerInstaller(); > rValue = Math.max(rValue, installerStatusCode); > if (installerStatusCode == RHQControl.EXIT_CODE_OK) { >@@ -666,11 +652,7 @@ public class Upgrade extends AbstractInstall { > .addArgument("--log=" + new File(getLogDir(), "rhq-agent-update.log")) // > .addArgument("--launch=false"); // we can't launch this copy - we still have to move it to the new location > >- Executor executor = new DefaultExecutor(); >- executor.setWorkingDirectory(getBaseDir()); >- executor.setStreamHandler(new PumpStreamHandler()); >- >- int exitValue = executor.execute(commandLine); >+ int exitValue = ExecutorAssist.execute(getBaseDir(), commandLine); > log.info("The agent installer finished upgrading with exit value " + exitValue); > > // We need to now move the new, updated agent over to the new agent location. >diff --git a/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/util/ExecutorAssist.java b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/util/ExecutorAssist.java >new file mode 100644 >index 0000000..cfca11e >--- /dev/null >+++ b/modules/enterprise/server/server-control/src/main/java/org/rhq/server/control/util/ExecutorAssist.java >@@ -0,0 +1,55 @@ >+package org.rhq.server.control.util; >+ >+import java.io.File; >+import java.io.IOException; >+import java.util.Map; >+ >+import org.apache.commons.exec.CommandLine; >+import org.apache.commons.exec.DefaultExecuteResultHandler; >+import org.apache.commons.exec.DefaultExecutor; >+import org.apache.commons.exec.ExecuteException; >+import org.apache.commons.exec.Executor; >+import org.apache.commons.exec.PumpStreamHandler; >+ >+public class ExecutorAssist { >+ >+ private static Executor executor; >+ >+ static { >+ executor = new DefaultExecutor(); >+ executor.setStreamHandler(new PumpStreamHandler()); >+ } >+ >+ public static int execute(final File workingDir, final CommandLine commandLine, @SuppressWarnings("rawtypes") final Map environment, final boolean fireAndForget) throws IOException { >+ int rValue = 0; >+ try { >+ // Synchronized to prevent two threads from setting different workingDirectory at the same time.. >+ synchronized(executor) { >+ executor.setWorkingDirectory(workingDir); >+ // null environment is fine in both cases, DefaultExecutor will use default environment in that case >+ if(fireAndForget) { >+ // We're not interested in the return value >+ executor.execute(commandLine, environment, new DefaultExecuteResultHandler()); >+ } else { >+ rValue = executor.execute(commandLine, environment); >+ } >+ } >+ } catch(ExecuteException e) { >+ // DefaultExecutor has no detailed exception text, safe to ignore >+ rValue = Math.max(e.getExitValue(), rValue); >+ } >+ return rValue; >+ } >+ >+ public static int execute(final File workingDir, final CommandLine commandLine, final Map environment) throws IOException { >+ return execute(workingDir, commandLine, environment, false); >+ } >+ >+ public static int execute(final File workingDir, final CommandLine commandLine) throws IOException { >+ return execute(workingDir, commandLine, false); >+ } >+ >+ public static int execute(final File workingDir, final CommandLine commandLine, final boolean fireAndForget) throws IOException { >+ return execute(workingDir, commandLine, null, false); >+ } >+} >-- >1.8.3.msysgit.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 994250
:
783521
|
839282
|
842792
|
844599
|
844601
|
845114
| 866289