Package org.apache.hadoop.fs.audit
Class CommonAuditContext
java.lang.Object
org.apache.hadoop.fs.audit.CommonAuditContext
The common audit context is a map of common context information
which can be used with any audit span.
This context is shared across all Filesystems within the
thread.
Audit spans will be created with a reference to the current
context of their thread;
That reference is retained even as they are moved across threads, so
context information (including thread ID Java runtime).
The Global context entries are a set of key-value pairs which span
all threads; the
HttpReferrerAuditHeader picks these
up automatically. It is intended for minimal use of
shared constant values (process ID, entry point).
An attribute set in setGlobalContextEntry(String, String)
will be set across all audit spans in all threads.
The noteEntryPoint(Object) method should be
used in entry points (ToolRunner.run, etc). It extracts
the final element of the classname and attaches that
to the global context with the attribute key
AuditConstants.PARAM_COMMAND, if not already
set.
This helps identify the application being executued.
All other values set are specific to this context, which
is thread local.
The attributes which can be added to ths common context include
evaluator methods which will be evaluated in whichever thread
invokes getEvaluatedEntries() and then evaluates them.
That map of evaluated options may evaluated later, in a different
thread.
For setting and clearing thread-level options, use
currentAuditContext() to get the thread-local
context for the caller, which can then be manipulated.
For further information, especially related to memory consumption,
read the document `auditing_architecture` in the `hadoop-aws` module.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProcess ID; currently built from UUID and timestamp. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(String key) Does the context contain a specific key?static CommonAuditContextGet the current common audit context.static StringA thread ID which is unique for this process and shared across all S3A clients on the same thread, even those using different FS instances.Get a context entry.Get the evaluated operations.Get an iterator over the global entries.static StringGet a global entry.static voidnoteEntryPoint(Object tool) Add the entry point as a context entry with the keyAuditConstants.PARAM_COMMANDif it has not already been recorded.Put a context entry.Put a context entry dynamically evaluated on demand.voidRemove a context entry.static voidRemove a global entry.voidreset()Rest the context; will set the standard options again.static voidsetGlobalContextEntry(String key, String value) Set a global entry.
-
Field Details
-
PROCESS_ID
Process ID; currently built from UUID and timestamp.
-
-
Method Details
-
put
Put a context entry.- Parameters:
key- keyvalue- new value., If null, triggers removal.- Returns:
- old value or null
-
put
Put a context entry dynamically evaluated on demand. Important: as these supplier methods are long-lived, the supplier function MUST NOT be part of/refer to any object instance of significant memory size. Applications SHOULD remove references when they are no longer needed. When logged at TRACE, prints the key and stack trace of the caller, to allow for debugging of any problems.- Parameters:
key- keyvalue- new value- Returns:
- old value or null
-
remove
Remove a context entry.- Parameters:
key- key
-
get
Get a context entry.- Parameters:
key- key- Returns:
- value or null
-
reset
public void reset()Rest the context; will set the standard options again. Primarily for testing. -
containsKey
Does the context contain a specific key?- Parameters:
key- key- Returns:
- true if it is in the context.
-
currentAuditContext
Get the current common audit context. Thread local.- Returns:
- the audit context of this thread.
-
currentThreadID
A thread ID which is unique for this process and shared across all S3A clients on the same thread, even those using different FS instances.- Returns:
- a thread ID for reporting.
-
getEvaluatedEntries
Get the evaluated operations. This is the map unique to this context.- Returns:
- the operations map.
-
setGlobalContextEntry
Set a global entry.- Parameters:
key- keyvalue- value
-
getGlobalContextEntry
Get a global entry.- Parameters:
key- key- Returns:
- value or null
-
removeGlobalContextEntry
Remove a global entry.- Parameters:
key- key to clear.
-
noteEntryPoint
Add the entry point as a context entry with the keyAuditConstants.PARAM_COMMANDif it has not already been recorded. This is called via ToolRunner but may be used at any other entry point.- Parameters:
tool- object loaded/being launched.
-
getGlobalContextEntries
Get an iterator over the global entries. Thread safe.- Returns:
- an iterable to enumerate the values.
-