Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/866#discussion_r38088184
  
    --- Diff: 
software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessWinRmDriver.java
 ---
    @@ -119,20 +136,53 @@ protected void createDirectory(String directoryName, 
String summaryForLogging) {
         protected WinRmToolResponse executeCommand(ConfigKey<String> 
regularCommandKey, ConfigKey<String> powershellCommandKey, boolean allowNoOp) {
             String regularCommand = getEntity().getConfig(regularCommandKey);
             String powershellCommand = 
getEntity().getConfig(powershellCommandKey);
    -        if (Strings.isNullOrEmpty(regularCommand) && 
Strings.isNullOrEmpty(powershellCommand)) {
    +        if (Strings.isBlank(regularCommand) && 
Strings.isBlank(powershellCommand)) {
                 if (allowNoOp) {
                     return new WinRmToolResponse("", "", 0);
                 } else {
                     throw new IllegalStateException(String.format("Exactly one 
of %s or %s must be set", regularCommandKey.getName(), 
powershellCommandKey.getName()));
                 }
    -        } else if (!Strings.isNullOrEmpty(regularCommand) && 
!Strings.isNullOrEmpty(powershellCommand)) {
    +        } else if (!Strings.isBlank(regularCommand) && 
!Strings.isBlank(powershellCommand)) {
                 throw new IllegalStateException(String.format("%s and %s 
cannot both be set", regularCommandKey.getName(), 
powershellCommandKey.getName()));
             }
     
    -        if (Strings.isNullOrEmpty(regularCommand)) {
    -            return 
getLocation().executePsScript(ImmutableList.of(powershellCommand));
    +        ByteArrayOutputStream stdIn = new ByteArrayOutputStream();
    +        ByteArrayOutputStream stdOut = new ByteArrayOutputStream();
    +        ByteArrayOutputStream stdErr = new ByteArrayOutputStream();
    +
    +        boolean tagWithStd = Tasks.current() != null;
    +        if (tagWithStd) {
    +            writeToStream(stdIn, Strings.isBlank(regularCommand) ? 
powershellCommand : regularCommand);
    +            
Tasks.addTagDynamically(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDIN,
 stdIn));
    +
    +            if (BrooklynTaskTags.stream(Tasks.current(), 
BrooklynTaskTags.STREAM_STDOUT)==null) {
    +                
Tasks.addTagDynamically(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDOUT,
 stdOut));
    +                
Tasks.addTagDynamically(BrooklynTaskTags.tagForStreamSoft(BrooklynTaskTags.STREAM_STDERR,
 stdErr));
    +            }
    +        }
    +
    +        WinRmToolResponse response;
    +        if (Strings.isBlank(regularCommand)) {
    +            response = 
getLocation().executePsScript(ImmutableList.of(powershellCommand));
             } else {
    -            return 
getLocation().executeScript(ImmutableList.of(regularCommand));
    +            response = 
getLocation().executeScript(ImmutableList.of(regularCommand));
    +        }
    +
    +        if (tagWithStd) {
    +            if (BrooklynTaskTags.stream(Tasks.current(), 
BrooklynTaskTags.STREAM_STDOUT)==null) {
    --- End diff --
    
    I don't think you want this additional `if`. I'm surprised it works with 
it. We've added a stream to this task previously, so when you check if the 
current task has a null stdout stream, I'd expect it to return false.
    
    Also, you're just writing to your stdout / stderr streams. If someone else 
has replaced the tag for some reason, then you writing to your streams won't 
affect that.


---
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.
---

Reply via email to