2 ============LICENSE_START=======================================================
4 ================================================================================
5 Copyright (C) 2017 AT&T Intellectual Property. All rights
7 ================================================================================
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 ============LICENSE_END=========================================================
24 <title>Configuration</title>
28 <p style="margin-left: 30.0px;">
29 CDP Configuration support is provided by a common framework to load
30 and manage configuration properties from multiple sources. The basic
31 concept is to load a set of default properties from a known resource
32 file located on the class path, and then override these defaults
33 with optional settings that can be provided by a user through either
34 additional property files or via the command line (as VM arguments).
35 The loading of defaults from a resource property file (named <strong>com/att/cdp/default.properties</strong>)
36 ensures that values are defined for properties the application needs
39 <p style="margin-left: 30.0px;">
40 One of these default values that can be set is the name of the
41 property file that allows the user to supply settings, as well as
42 the path where the file can be found. In general, the default name
43 of the property file will be "<strong>cdp.properties</strong>",
44 and the path that will be searched is "<strong>${user.home};etc;../etc</strong>".
45 However, these values can be changed through the use of the
46 default.properties resource file. The property that specifies the
47 property file name is named <strong>com.att.cdp.bootstrap.file</strong>,
48 while the property named <strong>com.att.cdp.bootstrap.path</strong>
49 specifies the search path.
51 <p style="margin-left: 30.0px;">
52 After the default.properties are loaded, but prior to searching for
53 the application configuration file, the configuration factory checks
54 for properties <strong>com.att.cdp.bootstrap.path</strong> and <strong>com.att.cdp.bootstrap.file
55 </strong>in the System properties object (meaning they were set by the
56 command line). If these values are defined in the system properties
57 object, they are used. If not, these values are obtained from the
58 default properties just loaded. This allows the specification of
59 either the file name or path, or both, to be overridden during start
60 up by using command-line arguments.
62 <p style="margin-left: 30.0px;">The search path is scanned for the
63 first occurrence of the specified property file. The first
64 occurrence is loaded and scanning is stopped at that point. The
65 configuration factory does not load all occurrences it finds, only
66 the first occurrence it finds.</p>
67 <p style="margin-left: 30.0px;">The configuration properties are
68 loaded and processed according to a defined precedence order, such
69 that properties defined with a higher precedence override the same
70 property at a lower precedence. The precedence order is defined as
72 <h2>Precedence Order</h2>
74 <li>Default properties are initially loaded into the
75 configuration. These default properties are the lowest level
76 precedence, and will be overridden by any properties specified at
77 higher levels. These are loaded from resources that are packaged
78 as part of the various application components. Each component
79 (Server, Coordinator, EPM, or CLI) may have different default
80 properties. The default properties are loaded from a resource
81 named <strong>com/att/cdp/default.properties</strong>. The default
82 properties can specify the name of the application property file
83 to be used to configure the application, as well as the path to
84 search. Additionally, these properties can be supplied via the
85 command line to override the default settings if needed.<br /> <br />
87 <li>The configuration factory allows for the application to
88 supply an initial properties object to initialize the
89 configuration. This properties object could be loaded or created
90 in any way necessary for the application. This is totally up to
91 the application to define, if it is needed. If no
92 application-specific property object is supplied, this step is
93 skipped. If a property object is supplied, it is used to replace
94 or set any properties that may have been defined by the defaults.<br />
97 <li>The configuration factory will then search for a bootstrap
98 file on a bootstrap path. The actual bootstrap file name and path
99 can be specified as properties on the command line, or will
100 default to a file name of <strong>cdp.properties</strong> and a
101 path of <strong>${user.home};etc;../etc</strong>. If desired, the
102 user can specify the exact name of the property file to be loaded
103 as well as the path using <strong>-Dcom.att.cdp.bootstrap.file=<filename></strong>
104 and <strong>-Dcom.att.cdp.bootstrap.path=<path></strong>.
105 These properties are set to default values by the default
106 properties loaded in step #1 above. The first occurrence of a
107 property file is the file loaded and used. Any other occurrences
108 are not processed.<br /> <br />
110 <li>The System properties are then merged into the
111 configuration. This allows the highest level of precedence,
112 command-line VM arguments (-D<strong>name=value</strong>) to be
113 merged into the configuration property object. These settings
114 override all lower level settings of the same name, as well as
115 merge all system properties into the configuration object.
119 <p style="margin-left: 30.0px;">
120 The configuration support allows for variables to be inserted into
121 any property that is defined. Variables are named using the format <strong>${name}</strong>,
122 where the "name" is the name of a property that is defined
123 in the configuration, or a system property (such as <strong>user.home</strong>).
124 Variables can nest, such that a variable can be replaced with
125 another variable, which is then reevaluated to obtain the value.
126 This allows for indirection as well as variable substitution, if
129 <h2>Using the Configuration Support</h2>
130 <p style="margin-left: 30.0px;">
131 The configuration support was designed to be easy to use. The
132 configuration implementation is abstracted away from the application
133 so that it could be changed easily in the future if needed, or if we
134 needed to load different implementations for different reasons. This
135 means that the application always accesses the configuration through
136 an interface, named <strong>Configuration</strong>. The
137 implementation of that configuration interface is obtained by a
138 static method on the <strong>ConfigurationFactory</strong> class.
139 The configuration factory will both create the configuration if not
140 already created on the first access, as well as return the current
141 configuration if already created. Additionally, the
142 ConfigurationFactory provides mechanisms to recreate the
143 configuration after the application is initialized should the need
144 arise to update its configuration.
146 <p style="margin-left: 30.0px;">An example of the code needed to
147 obtain access to the configuration is:</p>
148 <pre style="margin-left: 30.0px;">Configuration config = ConfigurationFactory.getConfiguration();</pre>
149 <p style="margin-left: 30.0px;">Please refer to the javadoc or the
150 source code in cdp-common for other ways that the configuration and
151 configuration factory can be used.</p>
152 <h2>Reloading Properties</h2>
153 <p style="margin-left: 30.0px;">The configuration support allows
154 for properties to be re-loaded and re-evaluated after the
155 application is running. This is designed to allow a configuration to
156 be refreshed should the need arise. This could allow on-demand
157 refresh (via a command, for example), or automatically based on
158 sensing a change in the configuration file.</p>
159 <p style="margin-left: 30.0px;">
160 When the <strong>ConfigurationFactory</strong> method <strong>getConfiguration(Propert</strong><strong>ies)</strong>
161 is called, the current configuration is cleared and rebuilt using
162 the process defined above. The supplied property object is used in
163 step #2 of the process. While the properties are being re-built, no
164 access to the properties are allowed. Any attempt to access
165 properties while the re-build operation is in effect will block the
166 caller until completed. This is accomplished using read and write