Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/866#discussion_r37966051
--- Diff:
software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessWinRmDriver.java
---
@@ -129,10 +132,40 @@ protected WinRmToolResponse
executeCommand(ConfigKey<String> regularCommandKey,
throw new IllegalStateException(String.format("%s and %s
cannot both be set", regularCommandKey.getName(),
powershellCommandKey.getName()));
}
+ WinRmToolResponse response;
if (Strings.isNullOrEmpty(regularCommand)) {
- return
getLocation().executePsScript(ImmutableList.of(powershellCommand));
+ response =
getLocation().executePsScript(ImmutableList.of(powershellCommand));
} else {
- return
getLocation().executeScript(ImmutableList.of(regularCommand));
+ response =
getLocation().executeScript(ImmutableList.of(regularCommand));
+ }
+
+ if (Tasks.current()!=null) {
+ if (BrooklynTaskTags.stream(Tasks.current(),
BrooklynTaskTags.STREAM_STDIN)==null) {
+ if (Strings.isNullOrEmpty(regularCommand)) {
+
tagDynamicallyWithSoftStream(BrooklynTaskTags.STREAM_STDIN, powershellCommand);
+ } else {
+
tagDynamicallyWithSoftStream(BrooklynTaskTags.STREAM_STDIN, regularCommand);
+ }
+ }
+ if (BrooklynTaskTags.stream(Tasks.current(),
BrooklynTaskTags.STREAM_STDOUT)==null) {
+
tagDynamicallyWithSoftStream(BrooklynTaskTags.STREAM_STDOUT,
response.getStdOut());
+
tagDynamicallyWithSoftStream(BrooklynTaskTags.STREAM_STDERR,
response.getStdErr());
+ }
+ }
+
+ return response;
+ }
+
+ private void tagDynamicallyWithSoftStream(String brooklynTaskTag,
String std) {
+ try {
+ ByteArrayOutputStream stdStream = new ByteArrayOutputStream();
+ stdStream.write(std.getBytes());
+
+
Tasks.addTagDynamically(BrooklynTaskTags.tagForStreamSoft(brooklynTaskTag,
stdStream));
+
+ if(LOG.isDebugEnabled()) LOG.debug("{} {}", brooklynTaskTag,
std);
--- End diff --
To double-check: is this the only place the stdout / stderr is being
logged? Or will we now have multiple copies of stdout being logged? We only
want one copy in the log.
It's also definitely worth including more context in the log message. If it
just says "stdout ...." then you can't tell which entity it was for or which
machine it was on. Therefore include a prefix. For example, here is a log
statement for ssh stdout (which is written one line at a time):
2015-08-18 12:58:13,400 DEBUG brooklyn.SSH [Thread-50601]:
[amp@<ip>:22:stdout] WARNING: no known/successful package manager to install
iptables-persistent, may fail subsequently
---
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.
---