Class VariableContext
java.lang.Object
org.apache.hadoop.yarn.server.resourcemanager.placement.VariableContext
This class is a key-value store for the variables and their respective values
during an application placement. The class gives support for immutable
variables, which can be set only once, and has helper methods for replacing
the variables with their respective values in provided strings.
We don't extend the map interface, because we don't need all the features
a map provides, this class tries to be as simple as possible.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(String name) Check if a variable is part of the context.Returns the value of a variable, null values are replaced with "".getExtraDataset(String name) Returns the dataset referenced by the name.getOriginal(String name) booleanisImmutable(String name) Checks if the provided variable is immutable.Adds a variable with value to the context or overrides an already existing one.putConditional(String name, MappingRuleConditionalVariable variable) This method is used to add a conditional variable to the variable context.voidputExtraDataset(String name, Set<String> set) Adds a set to the context, each name can only be added once.voidputOriginal(String name, String value) replacePathVariables(String input) This method will consider the input as a queue path, which is a String separated by dot ('.') characters.replaceVariables(String input) This method replaces all variables in the provided string.setImmutables(String... variableNames) Can be used to provide an array of strings which contains the names of the variables which should be immutable.setImmutables(Set<String> variableNames) Can be used to provide a set which contains the name of the variables which should be immutable.
-
Constructor Details
-
VariableContext
public VariableContext()
-
-
Method Details
-
isImmutable
Checks if the provided variable is immutable.- Parameters:
name- Name of the variable to check- Returns:
- true if the variable is immutable
-
setImmutables
Can be used to provide a set which contains the name of the variables which should be immutable.- Parameters:
variableNames- Set containing the names of the immutable variables- Returns:
- same instance of VariableContext for daisy chaining.
- Throws:
IllegalStateException- if the immutable set is already provided.
-
setImmutables
Can be used to provide an array of strings which contains the names of the variables which should be immutable. An immutable set will be created from the array.- Parameters:
variableNames- Set containing the names of the immutable variables- Returns:
- same instance of VariableContext for daisy chaining.
- Throws:
IllegalStateException- if the immutable set is already provided.
-
put
Adds a variable with value to the context or overrides an already existing one. If the variable is already set and immutable an IllegalStateException is thrown.- Parameters:
name- Name of the variable to be added to the contextvalue- Value of the variable- Returns:
- same instance of VariableContext for daisy chaining.
- Throws:
IllegalStateException- if the variable is immutable and already set
-
putOriginal
-
putConditional
This method is used to add a conditional variable to the variable context.- Parameters:
name- Name of the variablevariable- The conditional variable evaluator- Returns:
- VariableContext for daisy chaining
-
get
Returns the value of a variable, null values are replaced with "".- Parameters:
name- Name of the variable- Returns:
- The value of the variable
-
getOriginal
-
putExtraDataset
Adds a set to the context, each name can only be added once. The extra dataset is different from the regular variables because it cannot be referenced via tokens in the paths or any other input. However matchers and actions can explicitly access these datasets and can make decisions based on them.- Parameters:
name- Name which can be used to reference the collectionset- The dataset to be stored
-
getExtraDataset
Returns the dataset referenced by the name.- Parameters:
name- Name of the set to be returned.- Returns:
- the dataset referenced by the name.
-
containsKey
Check if a variable is part of the context.- Parameters:
name- Name of the variable to be checked- Returns:
- True if the variable is added to the context, false otherwise
-
replaceVariables
This method replaces all variables in the provided string. The variables are reverse ordered by the length of their names in order to avoid partial replaces when a shorter named variable is a substring of a longer named variable. All variables will be replaced in the string. Null values will be considered as empty strings during the replace. If the input is null, null will be returned.- Parameters:
input- The string with variables- Returns:
- A string with all the variables substituted with their respective values.
-
replacePathVariables
This method will consider the input as a queue path, which is a String separated by dot ('.') characters. The input will be split along the dots and all parts will be replaced individually. Replace only occur if a part exactly matches a variable name, no composite names or additional characters are supported. e.g. With variables %user and %default "%user.%default" will be substituted while "%user%default.something" won't. Null values will be considered as empty strings during the replace. If the input is null, null will be returned.- Parameters:
input- The string with variables- Returns:
- A string with all the variable only path parts substituted with their respective values.
-