Skip to content

Commit

Permalink
Unbuffer stderr stdout (#61)
Browse files Browse the repository at this point in the history
* More logging work
* Resolve inspection warnings
  • Loading branch information
kdebisschop authored Mar 4, 2021
1 parent bd69fd8 commit ae3664b
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/bioraft/rundeck/rancher/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private Constants() {
public static final int INTERVAL_MILLIS = 2000;

@SuppressWarnings("SpellCheckingInspection")
public static final String STDERR_TOKEN = ";v9ZvwThpU1FtyrlIBf4UIC8";
public static final String STDERR_TOKEN = ":v9ZvwThpU1FtyrlIBf4UIC8:";

// These are fields in JSON from Rancher API.
public static final String NODE_ID = "id";
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/bioraft/rundeck/rancher/IResolverUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static int resolveIntProperty(
try {
value = Integer.parseInt(string);
} catch (NumberFormatException e) {
return defaultValue;
}
}
return value;
Expand All @@ -85,6 +86,7 @@ public static long resolveLongProperty(
try {
value = Long.parseLong(string);
} catch (NumberFormatException e) {
return defaultValue;
}
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package com.bioraft.rundeck.rancher;

import com.dtolabs.rundeck.core.Constants;
import com.dtolabs.rundeck.core.common.Framework;
import com.dtolabs.rundeck.core.common.IFramework;
import com.dtolabs.rundeck.core.common.INodeEntry;
import com.dtolabs.rundeck.core.common.IRundeckProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public static void runJob(String url, String accessKey, String secretKey, String
private static String[] remoteCommand(String[] command, String temp) {
String file = temp + ".pid; ";
// Prefix STDERR lines with STDERR_TOKEN to decode in logging step.
String cmd = String.join(" ", command);
String job = "( " + cmd + " ) 2> >(sed 's/^/" + STDERR_TOKEN + "/')";
String cmd = "( " + String.join(" ", command) + " )";
String sed = " 2> >(while IFS= read -r line || [ -n \"$line\" ]; do echo " + STDERR_TOKEN + "$line ; done)";
// Note that bash is required to support adding a prefix token to STDERR.
return new String[]{ "bash", "-c", "printf $$ >>" + file + job + ";printf ' %s' $? >>" + file };
return new String[]{ "bash", "-c", "printf $$ >>" + file + cmd + sed + ";printf ' %s' $? >>" + file };
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bioraft/rundeck/rancher/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String loadStoragePathData(final String passwordStoragePath) throws IOExc
ResourceMeta contents = executionContext.getStorageTree().getResource(passwordStoragePath).getContents();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
contents.writeContent(byteArrayOutputStream);
return new String(byteArrayOutputStream.toByteArray());
return byteArrayOutputStream.toString();
}

}

0 comments on commit ae3664b

Please sign in to comment.