Generating snapshots involves copying files and comparing those files against previous versions to detect whether or not they have changed. This work is relegated to the plugin container since it is the same for any resource types that supports drift management. To support drift management resource component's will have to implement a new facet and make changes in the plugin descriptor.
Plugin Descriptor Changes
<drift name="foo">
<basedir>...</basedir>
<interval>300000</interval>
<includes>
<include path="a..." pattern="a..." />
<include path="b..." pattern="b..." />
</includes>
<excludes>
<exclude path="a..." pattern="a..." />
<exclude path="b..." pattern="b..." />
</excludes>
</drift>
Mazz:
Under the covers, we build a Configuration object with those properties, but the plugin author should not be forced to understand the underlying configuration properties. The plugin container should create a domain object that encapsulates these config properties and provide a strongly typed API like: DriftConfigiration.getBaseDirectory() and DriftConfiguration.getIncludes() ...
jsanda: An alternartive, more concise syntax for specifying filters could be as follows,
<drift name="foo">
<basedir>...</basedir>
<interval>300000</interval>
<filters>
<include path="a..." pattern="a..." />
<include path="b..." pattern="b..." />
<exclude path="a..." pattern="a..." />
<exclude path="b..." pattern="b..." />
</filters>
</drift>
In order for a resource type to support drift management it is necessary to specify at least one <drift> element. Note that you are not required to specify any of the child elements. The preceding example illustrates the allowable child elements, though none of them are required.
Each <drift> element must have a unique name. We might for example have something like <drift name="webapps"> and <drift name="EAP server configuration"> where the former specifies drift management only for web apps whereas the latter specifies drift management for files under JBOSS_HOME/bin and JBOSS_HOME/server/default/conf (assuming we are running the default server configuration).
TODO If only one <drift> is declared, should the name attribute still be required? We could generate a default value alleviating the need to add the extra mark up.
basedir
Specifies the base or root directory from which snapshots will be taken.
Specifying the base directory in the plugin descriptor does not make a whole lot of sense the location of a resource is not know until runtime when it is discovered. But it does make sense to say you want the base directory set to the root directory of your Tomcat installation if for example you are managing drift for Tomcat servers. See the next section, Using Lazy Evaluation for more information on how to do this.
includes
Allows you to specify zero or more inclusion filters. If inclusion filters are specified, then only paths matching the filters will be included in the snapshot.
excludes
Allows you to specify zero or more exclusion filters. If exclusion filters are specified, then any paths matching the filters will be excluded in the snapshot.
interval
Allows you to specify in milliseconds how frequently drift monitoring is performed.
Generally a user should be able to enable drift monitoring for a resource without having to having to make additional configuration changes. The plugin should provide a sensible set of defaults. This can be accomplished with the properties described in this section.
Using Lazy Evaluation
You may want to specify defaults for drift configuration properties such as basedir in the plugin descriptor; however, the file system location of a resource is not known until it has been discovered. Let's consider an example to better illustrate this. Suppose we adding support for drift management of EAP 5/6 servers. This means we will add a <drift> element under JBossAS Server resource type in the plugin descriptor of the JBoss Application Server 5.x plugin. A logical default for the basedir property is the root directory of the EAP server. With lazy evaluation, you can effectively specify the root directory of the server as the value of basedir.
<drift name="Default Drift Configurtion">
<basedir>${homeDir}</basedir>
</drift>
The ${...} syntax indicates that the enclosed string is not to be treated as a literal value. It is used as a form of variable substitution. At run time during discovery the plugin container will look for a plugin configuration property of the same name, and substitute the value of that property.
The JBossAS Server type does in fact does have a plugin configuration property named homeDir (with a display name of JBoss Home Directory if you are looking at the plugin configuration in the UI as opposed to the plugin descriptor file). When a JBossAS Server resource is discovered, the discovery component initializes that property (along with several others). Let's say homeDir is initialized to a value of /var/lib/jboss-eap-5.0. That path is then substituted in for the value of the basedir drift configuration property.
SnapshotFacet
public interface SnapshotFacet {
DriftConfiguration getSnapshotConfiguration(Configuration pluginConfig DriftConfiguration driftConfig);
}
SnapshotFacet is implemented by the discovery component. Immediately after the plugin container invokes the discovery component's discoverResources method, it will invoke getSnapshotConfiguration for each discovered resource and for each drift configuration declared in the plugin descriptor. If two drift configurations are declared in the plugin descriptor (i.e., <drift name="foo"/> and <drift name="bar"/>), then getSnapshotConfiguration will be called twice. discoverResources returns a set of DiscoveredResourceDetails. Each DiscoveredResourceDetails object contains a plugin configuration object. That plugin configuration object is passed as the pluginConfig argument to getSnapshotConfiguration. That same plugin configuration will be used across multiple invocations of getSnapshotConfiguration.
The driftConfig argument contains properties that correspond to the child elements of <drift>. If any defaults are specified in the plugin descriptor, the corresponding properties in the driftConfig object will be initialized to those default values.
SnapshotFacet is not Required
Discovery components are not required to implement SnapshotFacet in order to enable drift management; however, you must declare at least one <drift> configuration element in the plugin descriptor to enable drift management. Implementing SnapshotFacet though provides the ultimately flexibility in defining drift configurations.