Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
.project
dependency-reduced-pom.xml
target
*.log
*.log
.DS_Store
.idea
.settings
2 changes: 2 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ For HDInsight clusters, just download your logs on your home container located i

Then each of the container logs will be parsed and written to a ".txt" file, along with the original log file.

When -o option is not provided the parsed output will be written to stdout.

[Download and Parse Logs from WASB]
You can also use this tool to directly download Yarn application logs from Azure Storage account associated with an HDInsight cluster.

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/com/shanyu/hadoop/logparser/LogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
Expand Down Expand Up @@ -44,8 +43,7 @@ public static void main( String[] args )
String.format("WASB Account suffix, defaults to '%s'", DEFAULT_WASB_ACCOUNT_SUFFIX)));
options.addOption(new Option("i", "applicationId", true, "Application ID"));
options.addOption(new Option("d", "localDir", true, "Local Directory Path"));
Option output = new Option("o", "outputDir", true, "Output Directory Name");
output.setRequired(true);
Option output = new Option("o", "outputDir", true, "Output Directory Name (\"-\" prints to stdout)");
options.addOption(output);

CommandLine cmd = null;
Expand Down Expand Up @@ -114,7 +112,6 @@ else if (!isStrEmpty(wasbAccount) && !isStrEmpty(wasbKey) && !isStrEmpty(wasbCon

Path path = new Path(srcPathDir);
FileSystem fs = path.getFileSystem(conf);
new File(outputDir).mkdirs();
TFileParser parser = new TFileParser(conf, fs, outputDir);
FileStatus[] files = fs.listStatus(path);
for(FileStatus file : files) {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/com/shanyu/hadoop/logparser/TFileParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
import java.io.OutputStream;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
Expand All @@ -32,14 +33,22 @@ public TFileParser(Configuration conf, FileSystem fs, String destLocalFolder) {

void parseOneFile(Path srcPath)
throws FileNotFoundException, IOException {
String destLocalPath = _destLocalFolder + File.separator + srcPath.getName() + ".txt";
System.out.println("===================================");
System.out.println("converting " + srcPath);
System.out.println("writting to " + destLocalPath);
OutputStream outputStream = null;
if(_destLocalFolder == null || _destLocalFolder.equals("") || _destLocalFolder.equals("-")) {
outputStream = System.out;
System.out.println("writting to stdout");
} else {
new File(_destLocalFolder).mkdirs();
String destLocalPath = _destLocalFolder + File.separator + srcPath.getName() + ".txt";
outputStream = new FileOutputStream(destLocalPath);
System.out.println("writting to " + destLocalPath);
}

try (
final FSDataInputStream fsdis = _fs.open(srcPath);
final OutputStreamWriter outWriter = new OutputStreamWriter(new FileOutputStream(destLocalPath), "utf-8");
final OutputStreamWriter outWriter = new OutputStreamWriter(outputStream, "utf-8");
final TFile.Reader reader =
new TFile.Reader(fsdis, _fs.getFileStatus(srcPath).getLen(), _conf);
final TFile.Reader.Scanner scanner = reader.createScanner()
Expand Down