@InterfaceAudience.Public @InterfaceStability.Unstable public final class CommonAuditContext extends Object
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.Modifier and Type | Field and Description |
---|---|
static String |
PROCESS_ID
Process ID; currently built from UUID and timestamp.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(String key)
Does the context contain a specific key?
|
static CommonAuditContext |
currentAuditContext()
Get the current common audit context.
|
static String |
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.
|
String |
get(String key)
Get a context entry.
|
Map<String,Supplier<String>> |
getEvaluatedEntries()
Get the evaluated operations.
|
static Iterable<Map.Entry<String,String>> |
getGlobalContextEntries()
Get an iterator over the global entries.
|
static String |
getGlobalContextEntry(String key)
Get a global entry.
|
static void |
noteEntryPoint(Object tool)
Add the entry point as a context entry with the key
AuditConstants.PARAM_COMMAND
if it has not already been recorded. |
Supplier<String> |
put(String key,
String value)
Put a context entry.
|
Supplier<String> |
put(String key,
Supplier<String> value)
Put a context entry dynamically evaluated on demand.
|
void |
remove(String key)
Remove a context entry.
|
static void |
removeGlobalContextEntry(String key)
Remove a global entry.
|
void |
reset()
Rest the context; will set the standard options again.
|
static void |
setGlobalContextEntry(String key,
String value)
Set a global entry.
|
public static final String PROCESS_ID
public Supplier<String> put(String key, String value)
key
- keyvalue
- new value., If null, triggers removal.public Supplier<String> put(String key, Supplier<String> value)
key
- keyvalue
- new valuepublic void remove(String key)
key
- keypublic void reset()
public boolean containsKey(String key)
key
- keypublic static CommonAuditContext currentAuditContext()
public static String currentThreadID()
public Map<String,Supplier<String>> getEvaluatedEntries()
public static void setGlobalContextEntry(String key, String value)
key
- keyvalue
- valuepublic static String getGlobalContextEntry(String key)
key
- keypublic static void removeGlobalContextEntry(String key)
key
- key to clear.public static void noteEntryPoint(Object tool)
AuditConstants.PARAM_COMMAND
if it has not already been recorded.
This is called via ToolRunner but may be used at any
other entry point.tool
- object loaded/being launched.Copyright © 2024 Apache Software Foundation. All rights reserved.