diff options
Diffstat (limited to 'node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcessImpl.java')
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcessImpl.java | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcessImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcessImpl.java index 367688f0bb4..31ccbe90fda 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcessImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/ChildProcessImpl.java @@ -1,9 +1,11 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.node.admin.task.util.process; +import com.yahoo.vespa.hosted.node.admin.component.TaskContext; import com.yahoo.vespa.hosted.node.admin.task.util.file.UnixPath; import java.nio.file.Path; +import java.util.logging.Logger; /** * Represents a forked child process that still exists or has terminated. @@ -11,17 +13,28 @@ import java.nio.file.Path; * @author hakonhall */ public class ChildProcessImpl implements ChildProcess { + private final TaskContext taskContext; private final Process process; private final Path processOutputPath; private final String commandLine; - ChildProcessImpl(Process process, Path processOutputPath, String commandLine) { + ChildProcessImpl(TaskContext taskContext, + Process process, + Path processOutputPath, + String commandLine) { + this.taskContext = taskContext; this.process = process; this.processOutputPath = processOutputPath; this.commandLine = commandLine; } + @Override + public String commandLine() { + return commandLine; + } + public String getUtf8Output() { + waitForTermination(); return new UnixPath(processOutputPath).readUtf8File(); } @@ -39,10 +52,12 @@ public class ChildProcessImpl implements ChildProcess { } public int exitValue() { + waitForTermination(); return process.exitValue(); } public ChildProcess throwIfFailed() { + waitForTermination(); if (process.exitValue() != 0) { throw new CommandException("Execution of program [" + commandLine + "] failed, stdout/stderr was: <" + suffixOfOutputForLog() + ">"); @@ -65,6 +80,11 @@ public class ChildProcessImpl implements ChildProcess { } @Override + public void logAsModifyingSystemAfterAll(Logger logger) { + taskContext.logSystemModification(logger, "Executed command: " + commandLine); + } + + @Override public void close() { if (process.isAlive()) { process.destroyForcibly(); |