-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-18258. Merging of S3A Audit Logs #4383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fa8d82d
HADOOP-18258. Merging of S3A Audit Logs
sravanigadey 89adfff
adding tool functionality and refactoring audit log files merging code
sravanigadey 18b9537
modified audit log files merging code
sravanigadey 661e979
added checkstyle and modified mergefiles method
sravanigadey f238177
fixed checkstyle and modified FileReader code
sravanigadey 76f611d
modified test of merging audit logs
sravanigadey 44d10eb
modified mergefiles method
sravanigadey 8a0af6d
modified mergefiles method and fixed checkstyle
sravanigadey 13d5210
changed merging code
sravanigadey a4b1476
changed mergefiles method
sravanigadey d2a0066
made changes in AuditTool and merging code
sravanigadey ef8e439
modified test file of merging audit logs
sravanigadey c622c55
implemented merging, parsing and converting into avro file
sravanigadey d3865c2
modified code to resolve some errors
sravanigadey effb27b
modified merging, parsing and converting into avro methods and tests
sravanigadey 258532e
fixed spotbug regarding AvroDataRecord class
sravanigadey 3ab4e4f
Merge branch 'apache:trunk' into HADOOP-18258
sravanigadey 0864c1a
pushing recent changes made in code
sravani-gadey b21304c
fixed checkstyle
sravani-gadey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
258 changes: 258 additions & 0 deletions
258
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/audit/AuditTool.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,258 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.hadoop.fs.s3a.audit; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
| import java.io.PrintWriter; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.conf.Configured; | ||
| import org.apache.hadoop.fs.FileStatus; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.fs.s3a.audit.mapreduce.S3AAuditLogMergerAndParser; | ||
| import org.apache.hadoop.util.ExitUtil; | ||
| import org.apache.hadoop.util.Tool; | ||
| import org.apache.hadoop.util.ToolRunner; | ||
|
|
||
| import static org.apache.hadoop.service.launcher.LauncherExitCodes.EXIT_COMMAND_ARGUMENT_ERROR; | ||
| import static org.apache.hadoop.service.launcher.LauncherExitCodes.EXIT_FAIL; | ||
| import static org.apache.hadoop.service.launcher.LauncherExitCodes.EXIT_SUCCESS; | ||
|
|
||
| /** | ||
| * AuditTool is a Command Line Interface. | ||
| * Its functionality is to parse the audit log files | ||
| * and generate avro file. | ||
| */ | ||
| public class AuditTool extends Configured implements Tool, Closeable { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(AuditTool.class); | ||
|
|
||
| private final S3AAuditLogMergerAndParser s3AAuditLogMergerAndParser = | ||
| new S3AAuditLogMergerAndParser(); | ||
|
|
||
| /** | ||
| * Name of this tool: {@value}. | ||
| */ | ||
| public static final String AUDITTOOL = | ||
| "org.apache.hadoop.fs.s3a.audit.AuditTool"; | ||
|
|
||
| /** | ||
| * Purpose of this tool: {@value}. | ||
| */ | ||
| public static final String PURPOSE = | ||
| "\n\nUSAGE:\nMerge, parse audit log files and convert into avro file " | ||
| + "for " | ||
| + "better " | ||
| + "visualization"; | ||
|
|
||
| // Exit codes | ||
| private static final int SUCCESS = EXIT_SUCCESS; | ||
| private static final int FAILURE = EXIT_FAIL; | ||
| private static final int INVALID_ARGUMENT = EXIT_COMMAND_ARGUMENT_ERROR; | ||
|
|
||
| private static final String USAGE = | ||
| "bin/hadoop " + "Class" + " DestinationPath" + " SourcePath" + "\n" + | ||
| "bin/hadoop " + AUDITTOOL + " s3a://BUCKET" + " s3a://BUCKET" + "\n"; | ||
|
|
||
| private PrintWriter out; | ||
|
|
||
| public AuditTool() { | ||
| super(); | ||
| } | ||
|
|
||
| /** | ||
| * Tells us the usage of the AuditTool by commands. | ||
| * | ||
| * @return the string USAGE | ||
| */ | ||
| public String getUsage() { | ||
| return USAGE + PURPOSE; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return AUDITTOOL; | ||
| } | ||
|
|
||
| /** | ||
| * This run method in AuditTool takes source and destination path of bucket, | ||
| * and check if there are directories and pass these paths to merge and | ||
| * parse audit log files. | ||
| * | ||
| * @param args argument list | ||
| * @return SUCCESS i.e, '0', which is an exit code | ||
| * @throws Exception on any failure. | ||
| */ | ||
| @Override | ||
| public int run(String[] args) throws Exception { | ||
| List<String> paths = Arrays.asList(args); | ||
| if(paths.size() == 2) { | ||
| // Path of audit log files | ||
| Path logsPath = new Path(paths.get(1)); | ||
| // Path of destination directory | ||
| Path destPath = new Path(paths.get(0)); | ||
|
|
||
| // Setting the file system | ||
| URI fsURI = new URI(logsPath.toString()); | ||
| FileSystem fileSystem = FileSystem.get(fsURI, new Configuration()); | ||
|
|
||
| FileStatus fileStatus = fileSystem.getFileStatus(logsPath); | ||
| if (fileStatus.isFile()) { | ||
| errorln("Expecting a directory, but " + logsPath.getName() + " is a" | ||
| + " file which was passed as an argument"); | ||
| throw invalidArgs( | ||
| "Expecting a directory, but " + logsPath.getName() + " is a" | ||
| + " file which was passed as an argument"); | ||
| } | ||
| FileStatus fileStatus1 = fileSystem.getFileStatus(destPath); | ||
| if (fileStatus1.isFile()) { | ||
| errorln("Expecting a directory, but " + destPath.getName() + " is a" | ||
| + " file which was passed as an argument"); | ||
| throw invalidArgs( | ||
| "Expecting a directory, but " + destPath.getName() + " is a" | ||
| + " file which was passed as an argument"); | ||
| } | ||
|
|
||
| // Calls S3AAuditLogMergerAndParser for implementing merging, passing of | ||
| // audit log files and converting into avro file | ||
| boolean mergeAndParseResult = | ||
| s3AAuditLogMergerAndParser.mergeAndParseAuditLogFiles( | ||
| fileSystem, logsPath, destPath); | ||
| if (!mergeAndParseResult) { | ||
| return FAILURE; | ||
| } | ||
| } else { | ||
| errorln(getUsage()); | ||
| throw invalidArgs("Invalid number of arguments, please specify audit " | ||
| + "log files directory as 1st argument and destination directory " | ||
| + "as 2nd argument"); | ||
| } | ||
| return SUCCESS; | ||
| } | ||
|
|
||
| protected static void errorln(String x) { | ||
| System.err.println(x); | ||
| } | ||
|
|
||
| /** | ||
| * Build the exception to raise on invalid arguments. | ||
| * | ||
| * @param format string format | ||
| * @param args optional arguments for the string | ||
| * @return a new exception to throw | ||
| */ | ||
| protected static ExitUtil.ExitException invalidArgs( | ||
| String format, Object... args) { | ||
| return exitException(INVALID_ARGUMENT, format, args); | ||
| } | ||
|
|
||
| /** | ||
| * Build a exception to throw with a formatted message. | ||
| * | ||
| * @param exitCode exit code to use | ||
| * @param format string format | ||
| * @param args optional arguments for the string | ||
| * @return a new exception to throw | ||
| */ | ||
| protected static ExitUtil.ExitException exitException( | ||
| final int exitCode, | ||
| final String format, | ||
| final Object... args) { | ||
| return new ExitUtil.ExitException(exitCode, | ||
| String.format(format, args)); | ||
| } | ||
|
|
||
| /** | ||
| * Convert a path to a URI, catching any {@code URISyntaxException} | ||
| * and converting to an invalid args exception. | ||
| * | ||
| * @param s3Path path to convert to a URI | ||
| * @return a URI of the path | ||
| * @throws ExitUtil.ExitException INVALID_ARGUMENT if the URI is invalid | ||
| */ | ||
| protected static URI toUri(String s3Path) { | ||
| URI uri; | ||
| try { | ||
| uri = new URI(s3Path); | ||
| } catch (URISyntaxException e) { | ||
| throw invalidArgs("Not a valid fileystem path: %s", s3Path); | ||
| } | ||
| return uri; | ||
| } | ||
|
|
||
sravanigadey marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * Flush all active output channels, including {@Code System.err}, | ||
| * so as to stay in sync with any JRE log messages. | ||
| */ | ||
| private void flush() { | ||
| if (out != null) { | ||
| out.flush(); | ||
| } else { | ||
| System.out.flush(); | ||
| } | ||
| System.err.flush(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| flush(); | ||
| if (out != null) { | ||
| out.close(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Inner entry point, with no logging or system exits. | ||
| * | ||
| * @param conf configuration | ||
| * @param argv argument list | ||
| * @return an exception | ||
| * @throws Exception Exception. | ||
| */ | ||
| public static int exec(Configuration conf, String... argv) throws Exception { | ||
| try (AuditTool auditTool = new AuditTool()) { | ||
| return ToolRunner.run(conf, auditTool, argv); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Main entry point. | ||
| * | ||
| * @param argv args list | ||
| */ | ||
| public static void main(String[] argv) { | ||
| try { | ||
| ExitUtil.terminate(exec(new Configuration(), argv)); | ||
| } catch (ExitUtil.ExitException e) { | ||
| LOG.error(e.toString()); | ||
| System.exit(e.status); | ||
| } catch (Exception e) { | ||
| LOG.error(e.toString(), e); | ||
| ExitUtil.halt(-1, e); | ||
| } | ||
| } | ||
| } | ||
48 changes: 48 additions & 0 deletions
48
...op-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/audit/avro/AvroDataSchema.avsc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| { | ||
| "type" : "record", "name" : "AvroS3LogEntryRecord", | ||
| "namespace" : "org.apache.hadoop.fs.s3a.audit", | ||
| "fields" : [ | ||
| { "name" : "turnaroundtime" , "type" : ["long", "null"] }, | ||
| { "name" : "remoteip", "type" : "string" }, | ||
| { "name" : "auth", "type" : "string" }, | ||
| { "name" : "useragent", "type" : "string" }, | ||
| { "name" : "hostid", "type" : "string" }, | ||
| { "name" : "requesturi", "type" : "string" }, | ||
| { "name" : "endpoint", "type" : "string" }, | ||
| { "name" : "bytessent", "type" : ["long", "null"] }, | ||
| { "name" : "cypher", "type" : "string" }, | ||
| { "name" : "key", "type" : "string" }, | ||
| { "name" : "timestamp", "type" : "string" }, | ||
| { "name" : "awserrorcode", "type" : "string" }, | ||
| { "name" : "owner", "type" : "string" }, | ||
| { "name" : "requester", "type" : "string" }, | ||
| { "name" : "objectsize", "type" : ["long", "null"] }, | ||
| { "name" : "tail", "type" : "string" }, | ||
| { "name" : "verb", "type" : "string" }, | ||
| { "name" : "version", "type" : "string" }, | ||
| { "name" : "bucket", "type" : "string" }, | ||
| { "name" : "sigv", "type" : "string" }, | ||
| { "name" : "referrer", "type" : "string" }, | ||
| { "name" : "totaltime", "type" : ["long", "null"] }, | ||
| { "name" : "requestid", "type" : "string" }, | ||
| { "name" : "http", "type" : "string" }, | ||
| { "name" : "tls", "type" : "string" }, | ||
| { "name" : "referrerMap", "type" : {"type": "map", "values": "string"} } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.