Github user knusbaum commented on a diff in the pull request:
https://github.com/apache/storm/pull/1053#discussion_r52079318
--- Diff: storm-core/src/jvm/org/apache/storm/utils/Utils.java ---
@@ -1367,12 +1367,67 @@ public static int toPositive(int number) {
return number & Integer.MAX_VALUE;
}
- public static RuntimeException wrapInRuntime(Exception e){
- if (e instanceof RuntimeException){
- return (RuntimeException)e;
- }else {
+ public static RuntimeException wrapInRuntime(Exception e) {
+ if (e instanceof RuntimeException) {
+ return (RuntimeException) e;
+ } else {
return new RuntimeException(e);
}
}
+
+ public static void ensure_process_killed(Integer pid) {
+ // in this function, just kill the process 5 times
+ // make sure the process be killed definitely
+ for (int i = 0; i < 5; i++) {
+ try {
+ exec_command("kill -9 " + pid);
+ LOG.info("kill -9 process " + pid);
+ sleepMs(100);
+ } catch (ExecuteException e) {
+ LOG.info("Error when trying to kill " + pid + ". Process
has been killed");
+ return;
+ } catch (Exception e) {
+ LOG.info("Error when trying to kill " + pid + ".Exception
", e);
+ }
+ }
+ }
+
+ public static void process_killed(Integer pid) {
+ try {
+ exec_command("kill " + pid);
+ LOG.info("kill process " + pid);
+ } catch (ExecuteException e) {
+ LOG.info("Error when trying to kill " + pid + ". Process has
been killed. ");
+ } catch (Exception e) {
+ LOG.info("Error when trying to kill " + pid + ".Exception ",
e);
+ }
+ }
+
+ public static void kill(Integer pid) {
+ process_killed(pid);
+
+ sleepMs(1000);
+
+ ensure_process_killed(pid);
+ }
+
+ public static void exec_command(String command) throws
ExecuteException, IOException {
+ String[] cmdlist = command.split(" ");
+ CommandLine cmd = new CommandLine(cmdlist[0]);
+ for (int i = 1; i < cmdlist.length; i++) {
+ cmd.addArgument(cmdlist[i]);
+ }
+
+ DefaultExecutor exec = new DefaultExecutor();
+ exec.execute(cmd);
+ }
+
+ public static void sleepMs(long ms) {
--- End diff --
And sleep stuff in `Util` or `Time` or something.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---