Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/866#discussion_r37966433
--- 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);
+ } catch (IOException e) {
+ LOG.warn(Joiner.on('\n').join(e.getStackTrace()));
--- End diff --
I'd log with `LOG.warn("Problem populating "+brooklynTaskTag+" for task of
entity "+getEntity(), e);`
It's better to let the logging framework know it's an exception, and to
give more context for what was being done when the exception was thrown.
---
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.
---