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

    https://github.com/apache/incubator-brooklyn/pull/866#discussion_r38178746
  
    --- 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 --
    
    But the way you've followed that is different. In 
https://github.com/apache/incubator-brooklyn/blob/master/software/base/src/main/java/org/apache/brooklyn/entity/software/base/AbstractSoftwareProcessSshDriver.java#L262
 it has the `if` guard for the call to `Tasks.addTagDynamically`. You have done 
that a few lines above.
    
    My point here is that once you've called `Tasks.addTagDyamically` a few 
lines above, you don't want to then do the `if` guard again for when you call 
`writeToStream` - I'd expect that second if to return false because you 
previously added the steam tag for this task.


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