TM-89 Moving pod log outside the temp folder (#5696)

* TM-89 creating log outside of temp folder

* TM-89 reverting build.gradle changes now that the practical test worked. logs for each container can be viewed in the artifacts section
This commit is contained in:
Razvan Codreanu 2019-11-12 12:36:56 +00:00 committed by Stefano Franz
parent 7fb404bd85
commit cc0e92e988

View File

@ -238,17 +238,17 @@ public class KubesTest extends DefaultTask {
ByteArrayOutputStream errChannelStream = new ByteArrayOutputStream();
CompletableFuture<Integer> waiter = new CompletableFuture<>();
File podOutput = executeBuild(namespace, numberOfPods, podIdx, podName, printOutput, stdOutOs, stdOutIs, errChannelStream, waiter);
File podLogsDirectory = new File(getProject().getBuildDir(), "pod-logs");
if (!podLogsDirectory.exists()) {
podLogsDirectory.mkdirs();
}
File podOutput = executeBuild(namespace, numberOfPods, podIdx, podName, podLogsDirectory, printOutput, stdOutOs, stdOutIs, errChannelStream, waiter);
int resCode = waiter.join();
getProject().getLogger().lifecycle("build has ended on on pod " + podName + " (" + podIdx + "/" + numberOfPods + ") with result " + resCode + " , gathering results");
Collection<File> binaryResults = downloadTestXmlFromPod(namespace, createdPod);
getLogger().lifecycle("removing pod " + podName + " (" + podIdx + "/" + numberOfPods + ") after completed build");
File podLogsDirectory = new File(getProject().getBuildDir(), "pod-logs");
if (!podLogsDirectory.exists()) {
podLogsDirectory.mkdirs();
}
File logFileToArchive = new File(podLogsDirectory, podName + ".log");
try (FileInputStream logIn = new FileInputStream(podOutput); FileOutputStream logOut = new FileOutputStream(logFileToArchive)) {
IOUtils.copy(logIn, logOut);
@ -269,6 +269,7 @@ public class KubesTest extends DefaultTask {
int numberOfPods,
int podIdx,
String podName,
File podLogsDirectory,
boolean printOutput,
PipedOutputStream stdOutOs,
PipedInputStream stdOutIs,
@ -286,7 +287,7 @@ public class KubesTest extends DefaultTask {
.usingListener(execListener)
.exec(getBuildCommand(numberOfPods, podIdx));
return startLogPumping(stdOutIs, podIdx, printOutput);
return startLogPumping(stdOutIs, podIdx, podLogsDirectory, printOutput);
}
private Pod buildPodRequest(String podName, PersistentVolumeClaim pvc) {
@ -334,10 +335,11 @@ public class KubesTest extends DefaultTask {
.build();
}
private File startLogPumping(InputStream stdOutIs, int podIdx, boolean printOutput) throws IOException {
File outputFile = Files.createTempFile("container", ".log").toFile();
private File startLogPumping(InputStream stdOutIs, int podIdx, File podLogsDirectory, boolean printOutput) throws IOException {
File outputFile = new File(podLogsDirectory, "container-" + podIdx + ".log");
outputFile.createNewFile();
Thread loggingThread = new Thread(() -> {
try (BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));
try (BufferedWriter out = new BufferedWriter(new FileWriter(outputFile, true));
BufferedReader br = new BufferedReader(new InputStreamReader(stdOutIs))) {
String line;
while ((line = br.readLine()) != null) {