Package org.yamcs
Class YConfiguration
java.lang.Object
org.yamcs.YConfiguration
A configuration object is a wrapper around a Map<String, Object> which keeps track to a parent and its original
file (if any).
This class loads yamcs configurations. There are a number of "subsystems", each using a corresponding subsystem.yaml
file
Configuration files are looked up in this order:
- in the prefix/file.yaml via the classpath if the prefix is set in the setup method (used in the unittests)
- in the userConfigDirectory .yamcs/etc/file.yaml
- in the file.yaml via the classpath..
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Introduced to be able to detect when a configuration file was not specified (as opposed to when there's a validation error inside).static class
Default config file resolver.static class
Default property provider. -
Field Summary
-
Constructor Summary
ConstructorDescriptionYConfiguration
(String subsystem, InputStream is, String confpath) Constructs a new configuration object parsing the input streamYConfiguration
(YConfiguration parent, String parentKey, Map<String, Object> root) -
Method Summary
Modifier and TypeMethodDescriptionstatic void
boolean
containsKey
(String key) boolean
containsKey
(String key, String key1) static YConfiguration
byte[]
byte[]
static byte[]
boolean
getBoolean
(String key) boolean
getBoolean
(String key, boolean defaultValue) boolean
getBoolean
(String key, String key1) static boolean
getBoolean
(Map<String, Object> m, String key) static boolean
getBoolean
(Map<String, Object> m, String key, boolean defaultValue) Returns m.get(key) if it exists and is of type boolean, if m.get(key) exists and is not boolean, throw an exception. if m.get(key) does not exist, return the default value.If the key is pointing to a map, creates and returns a configuration object out of that mapgetConfigList
(String key) getConfigListIdx
(String key, int idx) If config.get(key) exists and is a list, and the list has the element idx and is a map, then return a configuration wrapper around that map.getConfigOrEmpty
(String key) Same asgetConfig(String)
but return an empty config if the key does not exist.static YConfiguration
getConfiguration
(String subsystem) Loads (if not already loaded) and returns a configuration corresponding to a file <subsystem>.yaml This method does not reload the configuration file if it has changed.static YConfiguration
getConfiguration
(String subsystem, boolean reload) Loads and returns a configuration corresponding to a file <subsystem>.yaml This method reloads the configuration file always.double
double
static double
static double
<T extends Enum<T>>
T<T extends Enum<T>>
Tstatic <T extends Enum<T>>
TReturns a value of an enumeration that matches ignoring case the string obtained from the config with the given key.returns the first entry(key) in the config file.returns the first entry in the config file if it's a map.int
int
int
int
static int
static int
return the m.get(key) as an int if it's present or v if it is not.getKeys()
<T> List<T>
static <T> List<T>
long
long
static long
static long
return the m.get(key) as an long if it's present or v if it is not.<K,
V> Map<K, V> Consider usinggetConfig(java.lang.String)
to get a child config instead of accessing the map directlygetPath()
static YConfigurationResolver
getRoot()
This is the same like the method above but will create a {class: "string"} for strings rather than throwing an exception.static String
Returns m.get(key) if it exists and is of type string, otherwise throws an exceptionstatic String
<T> List<T>
getSubList
(String key, String key1) getSubString
(String key, String subkey) static boolean
boolean
static boolean
static boolean
static void
setPropertyProvider
(YConfigurationPropertyProvider propertyProvider) static void
setResolver
(YConfigurationResolver resolver) static void
Sets up the Yamcs configuration system and loads the UTC-TAI offsets.static void
Sets up the Yamcs configuration system and loads the UTC-TAI offsets.static void
Sets up the Yamcs configuration system and loads the UTC-TAI offsets.toMap()
toString()
static YConfiguration
Create a new configuration wrapping around a map The resulting config will have no parent
-
Field Details
-
configDirectory
-
PROPERTY_PATTERN
-
-
Constructor Details
-
YConfiguration
Constructs a new configuration object parsing the input stream- Parameters:
is
- input stream where the configuration is loaded fromconfpath
- configuration path - it is remembered together with the configuration in case of error to indicate where it is coming from (i.e. which file)
-
YConfiguration
- Parameters:
parent
-parentKey
-root
-
-
-
Method Details
-
setupTool
public static void setupTool()Sets up the Yamcs configuration system and loads the UTC-TAI offsets.This method is intended for client tools and may store or use files from
~/.yamcs
. -
setupTool
Sets up the Yamcs configuration system and loads the UTC-TAI offsets.This method is intended for client tools that wish to customize the default config directory.
- Parameters:
configDirectory
-
-
setupTest
Sets up the Yamcs configuration system and loads the UTC-TAI offsets.This method is intended for use in unit and integration tests. It allows resolving configuration files from a specific subdirectory of the classpath.
- Parameters:
configPrefix
- the name of the subdirectory where to resolve configuration files. This is resolved from the classpath.
-
clearConfigs
public static void clearConfigs() -
getConfiguration
Loads (if not already loaded) and returns a configuration corresponding to a file <subsystem>.yaml This method does not reload the configuration file if it has changed.- Parameters:
subsystem
-- Returns:
- the loaded configuration
- Throws:
ConfigurationException
- if the configuration file could not be found or not loaded (e.g. error in yaml formatting)
-
getConfiguration
public static YConfiguration getConfiguration(String subsystem, boolean reload) throws ConfigurationException Loads and returns a configuration corresponding to a file <subsystem>.yaml This method reloads the configuration file always.- Parameters:
subsystem
-reload
-- Returns:
- the loaded configuration
- Throws:
ConfigurationException
- if the configuration file could not be found or not loaded (e.g. error in yaml formatting)
-
isDefined
- Throws:
ConfigurationException
-
isNull
-
containsKey
-
containsKey
- Throws:
ConfigurationException
-
getFirstMap
returns the first entry in the config file if it's a map. Otherwise throws an error- Throws:
ConfigurationException
-
getFirstEntry
returns the first entry(key) in the config file.- Returns:
- Throws:
ConfigurationException
-
getKeys
-
getRoot
-
getConfig
If the key is pointing to a map, creates and returns a configuration object out of that mapThe returned object will have its parent set to this object
If the key does not exist a ConfigurationException is thrown.
- Parameters:
key
-- Returns:
-
getConfigOrEmpty
Same asgetConfig(String)
but return an empty config if the key does not exist.- Parameters:
key
-- Returns:
-
getMap
public static Map<String,Object> getMap(Map<String, Object> m, String key) throws ConfigurationException- Throws:
ConfigurationException
-
getMap
Consider usinggetConfig(java.lang.String)
to get a child config instead of accessing the map directly- Throws:
ConfigurationException
-
getSubMap
- Throws:
ConfigurationException
-
getString
Returns m.get(key) if it exists and is of type string, otherwise throws an exception- Parameters:
m
-key
-- Returns:
- Throws:
ConfigurationException
-
getString
public static String getString(Map<String, Object> m, String key, String defaultValue) throws ConfigurationException- Throws:
ConfigurationException
-
getString
- Throws:
ConfigurationException
-
getString
- Throws:
ConfigurationException
-
getSubString
- Throws:
ConfigurationException
-
getList
- Throws:
ConfigurationException
-
getConfigList
- Throws:
ConfigurationException
-
getDouble
- Throws:
ConfigurationException
-
getDouble
- Throws:
ConfigurationException
-
getServiceConfigList
This is the same like the method above but will create a {class: "string"} for strings rather than throwing an exception. It is to be used when loading service list which can be specified just by the class name.- Parameters:
key
-- Returns:
- Throws:
ConfigurationException
-
getSubList
- Throws:
ConfigurationException
-
getBoolean
public static boolean getBoolean(Map<String, Object> m, String key, boolean defaultValue) throws ConfigurationExceptionReturns m.get(key) if it exists and is of type boolean, if m.get(key) exists and is not boolean, throw an exception. if m.get(key) does not exist, return the default value.- Parameters:
m
-key
-defaultValue
- - the default value to return if m.get(key) does not exist.- Returns:
- the boolean config value
- Throws:
ConfigurationException
-
getBoolean
- Throws:
ConfigurationException
-
getBoolean
- Throws:
ConfigurationException
-
getBoolean
- Throws:
ConfigurationException
-
getBoolean
-
getInt
- Throws:
ConfigurationException
-
getInt
- Throws:
ConfigurationException
-
getInt
- Throws:
ConfigurationException
-
getInt
- Throws:
ConfigurationException
-
getInt
- Throws:
ConfigurationException
-
getInt
public static int getInt(Map<String, Object> m, String key, int defaultValue) throws ConfigurationExceptionreturn the m.get(key) as an int if it's present or v if it is not. If the key is present but the value is not an integer, a ConfigurationException is thrown.- Parameters:
m
-key
-defaultValue
-- Returns:
- the value from the map or the passed value if the map does not contain the key
- Throws:
ConfigurationException
- if the key is present but it's not an int
-
getLong
-
getLong
-
getLong
- Throws:
ConfigurationException
-
getBinary
-
getBinary
-
getBinary
- Throws:
ConfigurationException
-
getLong
return the m.get(key) as an long if it's present or v if it is not.- Parameters:
m
-key
-v
-- Returns:
- the value from the map or the passed value if the map does not contain the key
- Throws:
ConfigurationException
- if the key is present but it's not an long
-
getDouble
public static double getDouble(Map<String, Object> m, String key, double v) throws ConfigurationException- Throws:
ConfigurationException
-
getDouble
- Throws:
ConfigurationException
-
isList
-
isList
-
setResolver
-
getResolver
-
setPropertyProvider
-
getPropertyProvider
-
getEnum
-
getEnum
-
getEnum
public static <T extends Enum<T>> T getEnum(Map<String, Object> config, String key, Class<T> enumClass) Returns a value of an enumeration that matches ignoring case the string obtained from the config with the given key. Throws an Configurationexception if the key does not exist in config or if it does not map to a valid enumeration value- Parameters:
config
-key
-enumClass
-- Returns:
-
get
- Parameters:
key
-- Returns:
- root.get(key)
-
wrap
Create a new configuration wrapping around a map The resulting config will have no parent- Parameters:
m
-- Returns:
-
emptyConfig
-
toMap
-
getPath
-
getList
- Throws:
ConfigurationException
-
toString
-
getConfigListIdx
If config.get(key) exists and is a list, and the list has the element idx and is a map, then return a configuration wrapper around that map.Otherwise throw a ConfigurationException
- Parameters:
key
-idx
-- Returns:
-