Skip to content

Commit

Permalink
Should always create archive file when failures happen (#493)
Browse files Browse the repository at this point in the history
* Fix bug in which exceptions thrown by DiagnosticChainExec.runDiagnostic were not being logged in archive

* Remove unused methods
  • Loading branch information
brunofarache authored May 10, 2021
1 parent 86d861d commit e48f0d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public File exec(DiagnosticInputs inputs, DiagConfig config) throws DiagnosticEx
DiagnosticContext ctx = new DiagnosticContext();
ctx.diagsConfig = config;
ctx.diagnosticInputs = inputs;
File file;

try(
RestClient esRestClient = RestClient.getClient(
Expand Down Expand Up @@ -79,12 +80,13 @@ public File exec(DiagnosticInputs inputs, DiagConfig config) throws DiagnosticEx
}

checkAuthLevel(ctx.diagnosticInputs.user, ctx.isAuthorized);

return createArchive(ctx.tempDir);
} finally {
closeLogs();
file = createArchive(ctx.tempDir);
SystemUtils.nukeDirectory(ctx.tempDir);
ResourceCache.closeAll();
}

return file;
}
}
34 changes: 1 addition & 33 deletions src/main/java/com/elastic/support/diagnostics/JavaPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.elastic.support.Constants;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.BufferedReader;
import java.io.StringReader;

public class JavaPlatform {

Expand All @@ -16,7 +14,6 @@ public class JavaPlatform {
public String javac = "javac";

public JavaPlatform(String osName){

switch (osName){
case Constants.linuxPlatform:
this.platform = Constants.linuxPlatform;
Expand All @@ -38,41 +35,12 @@ public JavaPlatform(String osName){
}
}

public String extractJdkPath(String processList) throws DiagnosticException {

String line;
try (BufferedReader br = new BufferedReader(new StringReader(processList))) {
while ((line = br.readLine()) != null) {
if (line.contains(javaExecutable) && line.contains("-Des.")) {
String javaHome = extractJavaHome(line);
}
else {
continue;
}
}
} catch (Exception e) {
logger.error( "Error obtaining the path for the JDK", e);
}

// If we got this far we couldn't find a JDK
logger.info(Constants.CONSOLE, "Could not locate the location of the java executable used to launch Elasticsearch");
throw new DiagnosticException("JDK not found.");
}

public String extractJavaHome(String jdkProcessString){

// After the preceding cols are stripped, truncate the output behind the path to the executable.
int jpathIndex = jdkProcessString.indexOf(javaExecutable);
javaHome = jdkProcessString.substring(0, jpathIndex);

return javaHome;
}

public boolean isJdkPresent(String result){
if(result.contains(javac)){
return true;
}
return false;
}

}
}

0 comments on commit e48f0d7

Please sign in to comment.