modules/core/client-api/pom.xml
| 19
modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/DriftMetadataParser.java
| 72
modules/core/client-api/src/main/resources/rhq-drift.xsd
| 79
modules/core/client-api/src/test/groovy/org/rhq/core/clientapi/agent/metadata/PluginMetadataParserTest.groovy
| 565 ------
modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
| 837 ++++++++++
modules/core/dbutils/src/main/scripts/dbsetup/config-data.xml
| 164 +
modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
| 58
modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
| 115 +
modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
| 370 +++-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
| 155 +
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftConfigurationDefinitionTest.java
| 212 ++
modules/enterprise/server/jar/src/test/resources/log4j.xml
| 7
12 files changed, 1897 insertions(+), 756 deletions(-)
New commits:
commit 3c32b55beba3c2f8550c12d7106ad7c5cea1d9a9
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Jun 29 14:31:32 2011 -0400
change drift metadata to specify value-context and value-name
diff --git a/modules/core/client-api/pom.xml b/modules/core/client-api/pom.xml
index 9fed074..9f5f66a 100644
--- a/modules/core/client-api/pom.xml
+++ b/modules/core/client-api/pom.xml
@@ -69,12 +69,6 @@
</dependency>
<dependency>
- <groupId>org.codehaus.groovy</groupId>
- <artifactId>groovy-all</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
<groupId>commons-jxpath</groupId>
<artifactId>commons-jxpath</artifactId>
<version>1.3</version>
@@ -110,19 +104,6 @@
</plugin>
<plugin>
- <groupId>org.codehaus.groovy.maven</groupId>
- <artifactId>gmaven-plugin</artifactId>
- <version>1.0</version>
- <executions>
- <execution>
- <goals>
- <!--<goal>generateTestStubs</goal>-->
- <goal>testCompile</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
diff --git
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/DriftMetadataParser.java
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/DriftMetadataParser.java
index 1a4d261..54892ab 100644
---
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/DriftMetadataParser.java
+++
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/DriftMetadataParser.java
@@ -1,20 +1,37 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, version 2, as
+ * published by the Free Software Foundation, and/or the GNU Lesser
+ * General Public License, version 2.1, also as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License and the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
package org.rhq.core.clientapi.agent.metadata;
import org.rhq.core.clientapi.descriptor.drift.DriftDescriptor;
import org.rhq.core.clientapi.descriptor.drift.DriftFilterDescriptor;
+import org.rhq.core.clientapi.descriptor.drift.DriftDescriptor.Basedir;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
-import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
-import org.rhq.core.domain.configuration.definition.PropertySimpleType;
-
-import static org.rhq.core.domain.configuration.definition.PropertySimpleType.LONG;
-import static org.rhq.core.domain.configuration.definition.PropertySimpleType.STRING;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition;
public class DriftMetadataParser {
@@ -32,43 +49,52 @@ public class DriftMetadataParser {
}
private ConfigurationTemplate createTemplate(String name) {
- ConfigurationTemplate template = new ConfigurationTemplate(name,
- name + " drift configuration default template");
+ ConfigurationTemplate template = new ConfigurationTemplate(name, name + "
drift configuration default template");
template.setConfiguration(new Configuration());
return template;
}
private void initEnabled(ConfigurationTemplate template) {
- template.getConfiguration().put(new PropertySimple("enabled", false));
+ template.getConfiguration().put(new
PropertySimple(DriftConfigurationDefinition.PROP_ENABLED, false));
}
private void initName(DriftDescriptor descriptor, ConfigurationTemplate template) {
- template.getConfiguration().put(new PropertySimple("name",
descriptor.getName()));
+ template.getConfiguration().put(
+ new PropertySimple(DriftConfigurationDefinition.PROP_NAME,
descriptor.getName()));
}
private void initBasedir(DriftDescriptor descriptor, ConfigurationTemplate template)
{
- template.getConfiguration().put(new PropertySimple("basedir",
descriptor.getBasedir()));
+ Basedir basedir = descriptor.getBasedir();
+ String valueContext = basedir.getValueContext();
+ String valueName = basedir.getValueName();
+
+ PropertyMap basedirMap = new
PropertyMap(DriftConfigurationDefinition.PROP_BASEDIR);
+ basedirMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT, valueContext));
+ basedirMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME, valueName));
+
+ template.getConfiguration().put(basedirMap);
}
private void initInterval(DriftDescriptor descriptor, ConfigurationTemplate template)
{
Configuration config = template.getConfiguration();
if (descriptor.getInterval() == null) {
- config.put(new PropertySimple("interval", "1800"));
+ config.put(new PropertySimple(DriftConfigurationDefinition.PROP_INTERVAL,
String
+ .valueOf(DriftConfigurationDefinition.DEFAULT_INTERVAL)));
} else {
- config.put(new PropertySimple("interval",
descriptor.getInterval()));
+ config.put(new PropertySimple(DriftConfigurationDefinition.PROP_INTERVAL,
descriptor.getInterval()));
}
}
private void initIncludes(DriftDescriptor descriptor, ConfigurationTemplate template)
{
if (descriptor.getIncludes() != null &&
descriptor.getIncludes().getInclude().size() > 0) {
Configuration config = template.getConfiguration();
- PropertyList includes = new PropertyList("includes");
+ PropertyList includes = new
PropertyList(DriftConfigurationDefinition.PROP_INCLUDES);
for (DriftFilterDescriptor include : descriptor.getIncludes().getInclude())
{
- PropertyMap includeMap = new PropertyMap("include");
- includeMap.put(new PropertySimple("path", include.getPath()));
- includeMap.put(new PropertySimple("pattern",
include.getPattern()));
+ PropertyMap includeMap = new
PropertyMap(DriftConfigurationDefinition.PROP_INCLUDES_INCLUDE);
+ includeMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATH,
include.getPath()));
+ includeMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_PATTERN, include.getPattern()));
includes.add(includeMap);
}
@@ -79,12 +105,12 @@ public class DriftMetadataParser {
private void initExcludes(DriftDescriptor descriptor, ConfigurationTemplate template)
{
if (descriptor.getExcludes() != null &&
descriptor.getExcludes().getExclude().size() > 0) {
Configuration config = template.getConfiguration();
- PropertyList excludes = new PropertyList("excludes");
+ PropertyList excludes = new
PropertyList(DriftConfigurationDefinition.PROP_EXCLUDES);
for (DriftFilterDescriptor exclude : descriptor.getExcludes().getExclude())
{
- PropertyMap excludeMap = new PropertyMap("exclude");
- excludeMap.put(new PropertySimple("path", exclude.getPath()));
- excludeMap.put(new PropertySimple("pattern",
exclude.getPattern()));
+ PropertyMap excludeMap = new
PropertyMap(DriftConfigurationDefinition.PROP_EXCLUDES_EXCLUDE);
+ excludeMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATH,
exclude.getPath()));
+ excludeMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_PATTERN, exclude.getPattern()));
excludes.add(excludeMap);
}
diff --git a/modules/core/client-api/src/main/resources/rhq-drift.xsd
b/modules/core/client-api/src/main/resources/rhq-drift.xsd
index 81aa704..2330c64 100644
--- a/modules/core/client-api/src/main/resources/rhq-drift.xsd
+++ b/modules/core/client-api/src/main/resources/rhq-drift.xsd
@@ -29,79 +29,108 @@
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
blockDefault="">
<xs:annotation>
- <xs:documentation>Schema for the definition of drift configuration
data.</xs:documentation>
- <xs:appinfo>
- <jaxb:schemaBindings>
- <jaxb:package
name="org.rhq.core.clientapi.descriptor.drift"/>
- </jaxb:schemaBindings>
- </xs:appinfo>
- </xs:annotation>
+ <xs:documentation>Schema for the definition of drift configuration
data.</xs:documentation>
+ <xs:appinfo>
+ <jaxb:schemaBindings>
+ <jaxb:package name="org.rhq.core.clientapi.descriptor.drift"
/>
+ </jaxb:schemaBindings>
+ </xs:appinfo>
+ </xs:annotation>
<xs:complexType name="Drift">
<xs:annotation>
<xs:appinfo>
- <jaxb:class name="DriftDescriptor"/>
+ <jaxb:class name="DriftDescriptor" />
</xs:appinfo>
</xs:annotation>
<xs:sequence>
- <xs:element name="basedir" type="xs:string"
minOccurs="1" maxOccurs="1">
- <xs:annotation>
- <xs:documentation>The root directory from which snapshots will
be generated during drift
- monitoring.</xs:documentation>
- </xs:annotation>
+ <xs:element name="basedir" minOccurs="1"
maxOccurs="1">
+ <xs:complexType>
+ <xs:annotation>
+ <xs:documentation>
+ The root directory from which snapshots will be generated
during drift monitoring.
+ Each base directory's value is obtained from a particular
context
+ (e.g. in the resource's plugin configuration or its
resource configuration).
+ Within that context, the base directory value is obtained by
looking up the named value in the given context.
+ For example, if the value-name is "install.dir" and
the value-context is "pluginConfiguration",
+ then the destination base directory value is obtained by
getting the "install.dir" property value
+ found in the resource's plugin configuration.
+ </xs:documentation>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="value-context">
+ <xs:simpleType>
+ <xs:restriction base="xs:string">
+ <xs:enumeration
value="pluginConfiguration"></xs:enumeration>
+ <xs:enumeration
value="resourceConfiguration"></xs:enumeration>
+ <xs:enumeration
value="measurementTrait"></xs:enumeration>
+ <xs:enumeration
value="fileSystem"></xs:enumeration>
+ </xs:restriction>
+ </xs:simpleType>
+ </xs:element>
+ <xs:element name="value-name"
type="xs:string"></xs:element>
+ </xs:sequence>
+ </xs:complexType>
</xs:element>
<xs:element name="interval" type="xs:long"
minOccurs="0" maxOccurs="1" default="1800">
<xs:annotation>
- <xs:documentation>The frequency in seconds in which drift
monitoring should run. Defaults to thirty
- minutes.</xs:documentation>
+ <xs:documentation>
+ The frequency in seconds in which drift monitoring should run.
Defaults to thirty minutes.
+ </xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="includes" type="drift:Includes"
minOccurs="0" maxOccurs="1">
<xs:annotation>
- <xs:documentation>A set of patterns that specify files and/or
directories to include.</xs:documentation>
+ <xs:documentation>
+ A set of patterns that specify files and/or directories to
include.
+ </xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="excludes" type="drift:Excludes"
minOccurs="0" maxOccurs="1">
<xs:annotation>
- <xs:documentation>A set of patterns that specify files and/or
directories to exclude.</xs:documentation>
+ <xs:documentation>
+ A set of patterns that specify files and/or directories to
exclude.
+ </xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
- <xs:attribute name="name" type="xs:string"
use="required"/>
+ <xs:attribute name="name" type="xs:string"
use="required" />
</xs:complexType>
<xs:complexType name="Includes">
<xs:annotation>
<xs:appinfo>
- <jaxb:class name="IncludesDescriptor"/>
+ <jaxb:class name="IncludesDescriptor" />
</xs:appinfo>
</xs:annotation>
<xs:sequence>
- <xs:element name="include" type="drift:DriftFilter"
minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="include" type="drift:DriftFilter"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Excludes">
<xs:annotation>
<xs:appinfo>
- <jaxb:class name="ExcludesDescriptor"/>
+ <jaxb:class name="ExcludesDescriptor" />
</xs:appinfo>
</xs:annotation>
<xs:sequence>
- <xs:element name="exclude" type="drift:DriftFilter"
minOccurs="0" maxOccurs="unbounded"/>
+ <xs:element name="exclude" type="drift:DriftFilter"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="DriftFilter">
<xs:annotation>
<xs:appinfo>
- <jaxb:class name="DriftFilterDescriptor"/>
+ <jaxb:class name="DriftFilterDescriptor" />
</xs:appinfo>
</xs:annotation>
<xs:attribute name="path" type="xs:string"
use="required">
<xs:annotation>
- <xs:documentation>A file system path that can be a directory or a
file. The path is assumed to be
- relative to the base directory of the drift
configuration.</xs:documentation>
+ <xs:documentation>
+ A file system path that can be a directory or a file. The path is
assumed to be
+ relative to the base directory of the drift configuration.
+ </xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="pattern" type="xs:string"
use="optional">
diff --git
a/modules/core/client-api/src/test/groovy/org/rhq/core/clientapi/agent/metadata/PluginMetadataParserTest.groovy
b/modules/core/client-api/src/test/groovy/org/rhq/core/clientapi/agent/metadata/PluginMetadataParserTest.groovy
deleted file mode 100644
index ef41e90..0000000
---
a/modules/core/client-api/src/test/groovy/org/rhq/core/clientapi/agent/metadata/PluginMetadataParserTest.groovy
+++ /dev/null
@@ -1,565 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2005-2008 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.core.clientapi.agent.metadata
-
-import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor
-import org.rhq.core.domain.configuration.definition.ConfigurationFormat
-import org.testng.annotations.Test
-import static org.rhq.core.clientapi.shared.PluginDescriptorUtil.toPluginDescriptor
-import static org.testng.Assert.assertEquals
-import static org.testng.Assert.assertNotNull
-import static org.testng.Assert.assertFalse
-
-class PluginMetadataParserTest {
-
- @Test
- void allTypesShouldHaveOneElementForDescriptorWithOnlyOneResourceType() {
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin">
- <server name="testServer"
- class="org.rhq.plugins.test.TestServer"
-
discovery="org.rhq.plugins.test.TestServerDiscoveryComponent"/>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- assertEquals(parser.allTypes.size(), 1, "The allTypes property should have 1
element for descriptor with a single resource type.")
- assertEquals(parser.allTypes[0].name, "testServer", "Expected to find
resource type named 'testServer' in allTypes.")
- }
-
- @Test
- void allTypesShouldHaveTwoElementsForDescriptorWithOneServerAndOneService() {
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin">
- <server name="testServer"
- class="TestServer"
- discovery="TestServerDiscoveryComponent">
- <service name="testService"
- class="TestService"
- discovery="TestServiceDiscoveryComponent"/>
- </server>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- assertEquals(parser.allTypes.size(), 2, "The allTypes property should have 2
elements for a descriptor with a server and a child service.")
-
- assertNotNull(parser.allTypes.find { it.name == "testServer" },
"Expected to find 'testServer' resource type.")
- assertNotNull(parser.allTypes.find { it.name == "testService" },
"Expected to find 'testService' resource type.")
- }
-
- @Test
- void rootResourceTypesShouldHaveOneElementForDescriptorWithOnlyOneResourceType() {
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin">
- <server name="testServer"
- class="org.rhq.plugins.test.TestServer"
-
discovery="org.rhq.plugins.test.TestServerDiscoveryComponent"/>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- assertEquals(parser.rootResourceTypes.size(), 1, "rootResourceTypes property
should have 1 element for descriptor with a single resource type.")
- assertNotNull(parser.rootResourceTypes.find { it.name == 'testServer' },
"Expected to find resource type named 'testServer' in
rootResouceTypes.")
- }
-
- @Test
- void
getComponentClassShouldReturnValueOfClassAttributeWhenPackageNameIncludedInAttribute() {
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin">
- <server name="testServer"
- class="org.rhq.plugins.test.TestServer"
-
discovery="org.rhq.plugins.test.TestServerDiscoveryComponent"/>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- def resourceType = parser.allTypes.find { it.name == "testServer" }
-
- def componentClass = parser.getComponentClass(resourceType)
-
- assertEquals(
- componentClass,
- "org.rhq.plugins.test.TestServer",
- "Expected the package and class name from the 'class' attribute when
it includes the package name.")
- }
-
- @Test
- void
getComponentClassShouldIncludePluginPackageWhenClassAttributeDoesNotSpecifyPackageName()
{
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin">
- <server name="testServer"
- class="TestServer"
- discovery="TestServerDiscoveryComponent"/>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- def resourceType = parser.allTypes.find { it.name == "testServer" }
-
- def componentClass = parser.getComponentClass(resourceType)
-
- assertEquals(
- componentClass,
- "org.rhq.plugins.test.TestServer",
- "Expected the package name from the 'package' attribute of the
<plugin> element to be included when the " +
- "package is not included in the 'class' attribute."
- )
- }
-
- @Test
- void
getDiscoveryComponentClassShouldReturnValueOfDiscoveryComponentAttributeWhenPackageNameIncludedInAttribute()
{
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin">
- <server name="testServer"
- class="org.rhq.plugins.test.TestServer"
-
discovery="org.rhq.plugins.test.TestServerDiscoveryComponent"/>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- def resourceType = parser.allTypes.find { it.name == "testServer" }
-
- def discoveryComponent = parser.getDiscoveryComponentClass(resourceType)
-
- assertEquals(
- discoveryComponent,
- "org.rhq.plugins.test.TestServerDiscoveryComponent",
- "Expected the package and class name from 'discovery' attribute when
it includes the package name."
- )
- }
-
- @Test
- void
getDiscoveryComponentClassShouldIncludePluginPackageWhenDiscoveryAttributeDoesNotSpecifyPackageName()
{
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin">
- <server name="testServer"
- class="TestServer"
- discovery="TestServerDiscoveryComponent"/>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- def resourceType = parser.allTypes.find { it.name == "testServer" }
-
- def discoveryComponent = parser.getDiscoveryComponentClass(resourceType)
-
- assertEquals(
- discoveryComponent,
- "org.rhq.plugins.test.TestServerDiscoveryComponent",
- "Expected the package name from the 'package' attribute of the
<plugin> element to be included when the " +
- "pacage is not included in the 'discovery' attribute."
- )
- }
-
- @Test
- void childServiceResourceTypeShouldBeAddedToParentServerResourceType() {
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin">
- <server name="testServer"
- class="TestServer"
- discovery="TestServerDiscoveryComponent">
- <service name="testService"
- class="TestService"
- discovery="TestServiceDiscoveryComponent"/>
- </server>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- def serverResourceType = parser.allTypes.find { it.name == "testServer" }
-
- assertNotNull(
- serverResourceType.childResourceTypes.find { it.name == "testService"
},
- "Expected resource type 'testService' to be added to its parent
resource type 'testServer'"
- )
- }
-
- @Test
- void
resourceTypeHavingResourceConfigurationDefinitionShouldBeBuiltForServerWithResourceConfiguration()
{
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:c="urn:xmlns:rhq-configuration">
- <server name="testServer"
- class="TestServer"
- discovery="TestServerDiscoveryComponent">
- <resource-configuration>
- <c:simple-property name="foo" defaultValue="bar"/>
- </resource-configuration>
- </server>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- def serverResourceType = parser.allTypes.find { it.name == "testServer" }
-
- assertNotNull(serverResourceType.resourceConfigurationDefinition, "Expected
resource type to have a resource configuration definition.")
- assertNotNull(
-
serverResourceType.resourceConfigurationDefinition.getPropertyDefinitionSimple("foo"),
- "Expected resource configuration to contain a simple property named
'foo'."
- )
- }
-
- @Test
- void configurationDefinitionShouldHaveConfigurationFormatSetWhenSpecifiedInDescriptor()
{
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:c="urn:xmlns:rhq-configuration">
- <server name="testServer"
- class="TestServer"
- discovery="TestServerDiscoveryComponent">
- <resource-configuration configurationFormat="structured">
- <c:simple-property name="foo" defaultValue="bar"/>
- </resource-configuration>
- </server>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- def serverResourceType = parser.allTypes.find { it.name == "testServer" }
- def resourceConfigurationDefinition =
serverResourceType.resourceConfigurationDefinition
-
- assertEquals(
- resourceConfigurationDefinition.configurationFormat,
- ConfigurationFormat.STRUCTURED,
- "Expected configurationFormat property to be set on resource configuration
definition."
- )
- }
-
- @Test
- void configurationFormatShouldDefaultToStructuredWhenNotDeclaredInDescriptor() {
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:c="urn:xmlns:rhq-configuration">
- <server name="testServer"
- class="TestServer"
- discovery="TestServerDiscoveryComponent">
- <resource-configuration>
- <c:simple-property name="foo" defaultValue="bar"/>
- </resource-configuration>
- </server>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- def serverResourceType = parser.allTypes.find { it.name == "testServer" }
- def resourceConfigurationDefinition =
serverResourceType.resourceConfigurationDefinition
-
- assertEquals(
- resourceConfigurationDefinition.configurationFormat,
- ConfigurationFormat.STRUCTURED,
- "The configurationFormat property of the configuration definition should
default to stuctured when it is not declared in the plugin descriptor."
- )
- }
-
- @Test
- void rawResourceConfigurationShouldNotHaveToSpecifyAnyStructuredConfig() {
- def pluginDescriptor = toPluginDescriptor(
- """
- <plugin name="TestServer" displayName="Test Server"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:c="urn:xmlns:rhq-configuration">
- <server name="testServer"
- class="TestServer"
- discovery="TestServerDiscoveryComponent">
- <resource-configuration configurationFormat="raw"/>
- </server>
- </plugin>
- """
- )
-
- def parsersByPlugin = [:]
-
- def parser = new PluginMetadataParser(pluginDescriptor, parsersByPlugin)
-
- }
-
- @Test
- void createDriftConfigurationBasedirDefaultWithSpecifiedValue() {
- def descriptor = toPluginDescriptor(
- """
- <plugin name="drift-test-plugin" displayName="Drift Test"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:d="urn:xmlns:rhq-drift">
- <server name="TestServer">
- <drift-configuration name="test1">
- <d:basedir>/var/lib/test1</d:basedir>
- </drift-configuration>
- </server>
- </plugin>
- """
- )
-
- verifyDriftConfiguration(descriptor, 'TestServer', 'test1') {
driftTemplate ->
- assertEquals(driftTemplate.configuration.getSimpleValue("basedir",
null),
- "/var/lib/test1", "Expected to find default property set for
basedir")
- }
- }
-
- @Test
- void createDriftConfigurationIntervalDefault() {
- def descriptor = toPluginDescriptor(
- """
- <plugin name="drift-test-plugin" displayName="Drift Test"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:d="urn:xmlns:rhq-drift">
- <server name="TestServer">
- <drift-configuration name="test1">
- <d:basedir>/var/lib/test1</d:basedir>
- </drift-configuration>
- </server>
- </plugin>
- """
- )
-
- verifyDriftConfiguration(descriptor, 'TestServer', 'test1') {
driftTemplate ->
- assertEquals(driftTemplate.configuration.getSimpleValue("interval",
null), "1800",
- "Expected to find default property set for interval")
- }
- }
-
- @Test
- void createDriftConfigurationIntervalDefaultWithSpecifiedValue() {
- def descriptor = toPluginDescriptor(
- """
- <plugin name="drift-test-plugin" displayName="Drift Test"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:d="urn:xmlns:rhq-drift">
- <server name="TestServer">
- <drift-configuration name="test1">
- <d:basedir>/var/lib/test1</d:basedir>
- <d:interval>3600</d:interval>
- </drift-configuration>
- </server>
- </plugin>
- """
- )
-
- verifyDriftConfiguration(descriptor, 'TestServer', 'test1') {
driftTemplate ->
- assertEquals(driftTemplate.configuration.getSimpleValue("interval",
null), "3600",
- "Expected to find default property set for <interval>")
- }
- }
-
- @Test
- void createDriftConfigurationIncludesDefaultWithSpecifiedValue() {
- def descriptor = toPluginDescriptor(
- """
- <plugin name="drift-test-plugin" displayName="Drift Test"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:d="urn:xmlns:rhq-drift">
- <server name="TestServer">
- <drift-configuration name="test1">
- <d:basedir>/var/lib/test1</d:basedir>
- <d:includes>
- <d:include path="lib" pattern="*.jar"/>
- <d:include path="conf" pattern="*.xml"/>
- </d:includes>
- </drift-configuration>
- </server>
- </plugin>
- """
- )
-
- verifyDriftConfiguration(descriptor, 'TestServer', 'test1') {
driftTemplate ->
- def config = driftTemplate.configuration
- def includes = config.getList('includes')
-
- assertNotNull(includes, "Expected to find default property set for
<includes>")
- assertEquals(includes.list.size(), 2, "Expected <includes> property list
to have two property elements.")
-
- def include1 = includes.list[0]
- def path1 = include1.getSimple('path')
- def pattern1 = include1.getSimple('pattern')
-
- assertNotNull(path1, "Expected to find a simple property for the path of the
first <include>")
- assertEquals(path1.stringValue, "lib", "The value is wrong for the
path of the first <include>")
-
- assertNotNull(pattern1, "Expected to find a simple property for the pattern of
the first <include>")
- assertEquals(pattern1.stringValue, '*.jar', 'The value is wrong for the
pattern of the first <include>')
-
- def include2 = includes.list[1]
- def path2 = include2.getSimple('path')
- def pattern2 = include2.getSimple('pattern')
-
- assertNotNull(path1, "Expected to find a simple property for the path of the
second <include>")
- assertEquals(path1.stringValue, "lib", "The value is wrong for the
path of the second <include>")
-
- assertNotNull(pattern1, "Expected to find a simple property for the pattern of
the second <include>")
- assertEquals(pattern1.stringValue, '*.jar', 'The value is wrong for the
pattern of the second <include>')
- }
- }
-
- @Test
- void createDriftConfigurationExcludesDefaultWithSpecifiedValue() {
- def descriptor = toPluginDescriptor(
- """
- <plugin name="drift-test-plugin" displayName="Drift Test"
package="org.rhq.plugins.test"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="urn:xmlns:rhq-plugin"
- xmlns:d="urn:xmlns:rhq-drift">
- <server name="TestServer">
- <drift-configuration name="test1">
- <d:basedir>/var/lib/test1</d:basedir>
- <d:interval>3600</d:interval>
- <d:excludes>
- <d:exclude path="lib" pattern="*.jar"/>
- <d:exclude path="conf" pattern="*.xml"/>
- </d:excludes>
- </drift-configuration>
- </server>
- </plugin>
- """
- )
-
- verifyDriftConfiguration(descriptor, 'TestServer', 'test1') {
driftTemplate ->
- def config = driftTemplate.configuration
- def excludes = config.getList('excludes')
-
- assertNotNull(excludes, "Expected to find default property set for
<excludes>")
- assertEquals(excludes.list.size(), 2, "Expected <excludes> property list
to have two property elements.")
-
- def exclude1 = excludes.list[0]
- def path1 = exclude1.getSimple('path')
- def pattern1 = exclude1.getSimple('pattern')
-
- assertNotNull(path1, "Expected to find a simple property for the path of the
first <exclude>")
- assertEquals(path1.stringValue, "lib", "The value is wrong for the
path of the first <exclude>")
-
- assertNotNull(pattern1, "Expected to find a simple property for the pattern of
the first <exclude>")
- assertEquals(pattern1.stringValue, '*.jar', 'The value is wrong for the
pattern of the first <exclude>')
-
- def exclude2 = excludes.list[1]
- def path2 = exclude2.getSimple('path')
- def pattern2 = exclude2.getSimple('pattern')
-
- assertNotNull(path1, "Expected to find a simple property for the path of the
second <exclude>")
- assertEquals(path1.stringValue, "lib", "The value is wrong for the
path of the second <exclude>")
-
- assertNotNull(pattern1, "Expected to find a simple property for the pattern of
the second <exclude>")
- assertEquals(pattern1.stringValue, '*.jar', 'The value is wrong for the
pattern of the second <exclude>')
- }
- }
-
- def verifyDriftConfiguration(PluginDescriptor descriptor, String resourceTypeName,
String driftConfigName,
- Closure test) {
- def parser = new PluginMetadataParser(descriptor, [:])
- def resourceType = parser.allTypes.find { it.name == resourceTypeName }
- def driftTemplate = resourceType.driftConfigurationTemplates.find { it.name ==
driftConfigName }
-
- assertNotNull(
- resourceType.driftConfigurationTemplates.find { it.name == driftConfigName},
- "Failed to find drift configuration template <$driftConfigName>. The
name attribute may not have been parsed correctly."
- )
-
- def name = driftTemplate.configuration.getSimple('name')
- def enabled = driftTemplate.configuration.getSimple('enabled')
-
- assertNotNull(name, "Expected to find a simple property <name> for the
drift configuration name")
- assertEquals(name.stringValue, driftConfigName,
- "The value is wrong for the <name> property that represents the drift
configuration name")
-
- assertNotNull(enabled, "Expected to find simple property <enabled> for the
drift configuration")
- assertFalse(enabled.booleanValue, "The <enabled> property should be set to
a default value of false")
-
- test(driftTemplate)
- }
-}
diff --git
a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
new file mode 100644
index 0000000..f44d2cb
--- /dev/null
+++
b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
@@ -0,0 +1,837 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.core.clientapi.agent.metadata.test;
+
+import static org.rhq.core.clientapi.shared.PluginDescriptorUtil.toPluginDescriptor;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.testng.annotations.Test;
+
+import org.rhq.core.clientapi.agent.metadata.PluginMetadataParser;
+import org.rhq.core.clientapi.descriptor.plugin.PluginDescriptor;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.ConfigurationFormat;
+import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
+import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition;
+import org.rhq.core.domain.drift.DriftConfiguration.BaseDirectory;
+import org.rhq.core.domain.drift.DriftConfiguration.Filter;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
+import org.rhq.core.domain.resource.ResourceType;
+
+@Test
+public class PluginMetadataParserTest {
+
+ @Test
+ void allTypesShouldHaveOneElementForDescriptorWithOnlyOneResourceType() throws
Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'>" + //
+ " <server name='testServer'" + //
+ " class='org.rhq.plugins.test.TestServer'" + //
+ "
discovery='org.rhq.plugins.test.TestServerDiscoveryComponent'/>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ assertEquals(parser.getAllTypes().size(), 1,
+ "The allTypes property should have 1 element for descriptor with a
single resource type.");
+ assertEquals(parser.getAllTypes().get(0).getName(), "testServer",
+ "Expected to find resource type named 'testServer' in
allTypes.");
+ }
+
+ @Test
+ void allTypesShouldHaveTwoElementsForDescriptorWithOneServerAndOneService() throws
Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'>" + //
+ " <server name='testServer'" + //
+ " class='TestServer'" + //
+ " discovery='TestServerDiscoveryComponent'>" +
//
+ " <service name='testService'" + //
+ " class='TestService'" + //
+ "
discovery='TestServiceDiscoveryComponent'/>" + //
+ " </server>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ assertEquals(parser.getAllTypes().size(), 2,
+ "The allTypes property should have 2 elements for a descriptor with a
server and a child service.");
+
+ assertNotNull(findResourceType(parser, "testServer"));
+ assertNotNull(findResourceType(parser, "testService"));
+ }
+
+ private ResourceType findResourceType(PluginMetadataParser parser, String
resourceTypeName) {
+ List<ResourceType> allTypes = parser.getAllTypes();
+ for (ResourceType resourceType : allTypes) {
+ if (resourceType.getName().equals(resourceTypeName)) {
+ return resourceType;
+ }
+ }
+ assert false : "expected to find resource type [" + resourceTypeName +
"] in: " + allTypes;
+ return null; // no-op since the above assert should always throw exception
+ }
+
+ @Test
+ void rootResourceTypesShouldHaveOneElementForDescriptorWithOnlyOneResourceType()
throws Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'>" + //
+ " <server name='testServer'" + //
+ " class='org.rhq.plugins.test.TestServer'" + //
+ "
discovery='org.rhq.plugins.test.TestServerDiscoveryComponent'/>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ assertEquals(parser.getRootResourceTypes().size(), 1,
+ "rootResourceTypes property should have 1 element for descriptor with a
single resource type.");
+ Set<ResourceType> rootResourceTypes = parser.getRootResourceTypes();
+ ResourceType root = null;
+ for (ResourceType resourceType : rootResourceTypes) {
+ if (resourceType.getName().equals("testServer")) {
+ root = resourceType;
+ break;
+ }
+ }
+ assertNotNull(root, "Expected to find resource type named
'testServer' in rootResouceTypes.");
+ }
+
+ @Test
+ void
getComponentClassShouldReturnValueOfClassAttributeWhenPackageNameIncludedInAttribute()
throws Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'>" + //
+ " <server name='testServer'" + //
+ " class='org.rhq.plugins.test.TestServer'" + //
+ "
discovery='org.rhq.plugins.test.TestServerDiscoveryComponent'/>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ ResourceType resourceType = findResourceType(parser, "testServer");
+
+ String componentClass = parser.getComponentClass(resourceType);
+
+ assertEquals(componentClass, "org.rhq.plugins.test.TestServer",
+ "Expected the package and class name from the 'class' attribute
when it includes the package name.");
+ }
+
+ @Test
+ void
getComponentClassShouldIncludePluginPackageWhenClassAttributeDoesNotSpecifyPackageName()
throws Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'>" + //
+ " <server name='testServer'" + //
+ " class='TestServer'" + //
+ " discovery='TestServerDiscoveryComponent'/>" +
//
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ ResourceType resourceType = findResourceType(parser, "testServer");
+
+ String componentClass = parser.getComponentClass(resourceType);
+
+ assertEquals(componentClass, "org.rhq.plugins.test.TestServer",
+ "Expected the package name from the 'package' attribute of the
<plugin> element to be included when the "
+ + "package is not included in the 'class'
attribute.");
+ }
+
+ @Test
+ void
getDiscoveryComponentClassShouldReturnValueOfDiscoveryComponentAttributeWhenPackageNameIncludedInAttribute()
+ throws Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'>" + //
+ " <server name='testServer'" + //
+ " class='org.rhq.plugins.test.TestServer'" + //
+ "
discovery='org.rhq.plugins.test.TestServerDiscoveryComponent'/>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ ResourceType resourceType = findResourceType(parser, "testServer");
+
+ String discoveryComponent = parser.getDiscoveryComponentClass(resourceType);
+
+ assertEquals(discoveryComponent,
"org.rhq.plugins.test.TestServerDiscoveryComponent",
+ "Expected the package and class name from 'discovery' attribute
when it includes the package name.");
+ }
+
+ @Test
+ void
getDiscoveryComponentClassShouldIncludePluginPackageWhenDiscoveryAttributeDoesNotSpecifyPackageName()
+ throws Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'>" + //
+ " <server name='testServer'" + //
+ " class='TestServer'" + //
+ " discovery='TestServerDiscoveryComponent'/>" +
//
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ ResourceType resourceType = findResourceType(parser, "testServer");
+
+ String discoveryComponent = parser.getDiscoveryComponentClass(resourceType);
+
+ assertEquals(discoveryComponent,
"org.rhq.plugins.test.TestServerDiscoveryComponent",
+ "Expected the package name from the 'package' attribute of the
<plugin> element to be included when the "
+ + "pacage is not included in the 'discovery'
attribute.");
+ }
+
+ @Test
+ void childServiceResourceTypeShouldBeAddedToParentServerResourceType() throws
Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'>" + //
+ " <server name='testServer'" + //
+ " class='TestServer'" + //
+ " discovery='TestServerDiscoveryComponent'>" +
//
+ " <service name='testService'" + //
+ " class='TestService'" + //
+ "
discovery='TestServiceDiscoveryComponent'/>" + //
+ " </server>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ ResourceType serverResourceType = findResourceType(parser,
"testServer");
+ Set<ResourceType> childResourceTypes =
serverResourceType.getChildResourceTypes();
+ ResourceType child = null;
+ for (ResourceType resourceType : childResourceTypes) {
+ if (resourceType.getName().equals("testService")) {
+ child = resourceType;
+ break;
+ }
+ }
+
+ assertNotNull(child,
+ "Expected resource type 'testService' to be added to its parent
resource type 'testServer'");
+ }
+
+ @Test
+ void
resourceTypeHavingResourceConfigurationDefinitionShouldBeBuiltForServerWithResourceConfiguration()
+ throws Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:c='urn:xmlns:rhq-configuration'>" + //
+ " <server name='testServer'" + //
+ " class='TestServer'" + //
+ " discovery='TestServerDiscoveryComponent'>" +
//
+ " <resource-configuration>" + //
+ " <c:simple-property name='foo'
defaultValue='bar'/>" + //
+ " </resource-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ ResourceType serverResourceType = findResourceType(parser,
"testServer");
+
+ assertNotNull(serverResourceType.getResourceConfigurationDefinition(),
+ "Expected resource type to have a resource configuration
definition.");
+
assertNotNull(serverResourceType.getResourceConfigurationDefinition().getPropertyDefinitionSimple("foo"),
+ "Expected resource configuration to contain a simple property named
'foo'.");
+ }
+
+ @Test
+ void
configurationDefinitionShouldHaveConfigurationFormatSetWhenSpecifiedInDescriptor() throws
Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:c='urn:xmlns:rhq-configuration'>" + //
+ " <server name='testServer'" + //
+ " class='TestServer'" + //
+ " discovery='TestServerDiscoveryComponent'>" +
//
+ " <resource-configuration
configurationFormat='structured'>" + //
+ " <c:simple-property name='foo'
defaultValue='bar'/>" + //
+ " </resource-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ ResourceType serverResourceType = findResourceType(parser,
"testServer");
+ ConfigurationDefinition resourceConfigurationDefinition = serverResourceType
+ .getResourceConfigurationDefinition();
+
+ assertEquals(resourceConfigurationDefinition.getConfigurationFormat(),
ConfigurationFormat.STRUCTURED,
+ "Expected configurationFormat property to be set on resource
configuration definition.");
+ }
+
+ @Test
+ void configurationFormatShouldDefaultToStructuredWhenNotDeclaredInDescriptor() throws
Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:c='urn:xmlns:rhq-configuration'>" + //
+ " <server name='testServer'" + //
+ " class='TestServer'" + //
+ " discovery='TestServerDiscoveryComponent'>" +
//
+ " <resource-configuration>" + //
+ " <c:simple-property name='foo'
defaultValue='bar'/>" + //
+ " </resource-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+
+ ResourceType serverResourceType = findResourceType(parser,
"testServer");
+ ConfigurationDefinition resourceConfigurationDefinition = serverResourceType
+ .getResourceConfigurationDefinition();
+
+ assertEquals(
+ resourceConfigurationDefinition.getConfigurationFormat(),
+ ConfigurationFormat.STRUCTURED,
+ "The configurationFormat property of the configuration definition should
default to stuctured when it is not declared in the plugin descriptor.");
+ }
+
+ @Test
+ void rawResourceConfigurationShouldNotHaveToSpecifyAnyStructuredConfig() throws
Exception {
+ PluginDescriptor pluginDescriptor = toPluginDescriptor("" + //
+ "<plugin name='TestServer' displayName='Test Server'
package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:c='urn:xmlns:rhq-configuration'>" + //
+ " <server name='testServer'" + //
+ " class='TestServer'" + //
+ " discovery='TestServerDiscoveryComponent'>" +
//
+ " <resource-configuration
configurationFormat='raw'/>" + //
+ " </server>" + //
+ "</plugin>");
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(pluginDescriptor,
parsersByPlugin);
+ assert parser.getAllTypes().size() > 0;
+ }
+
+ @Test
+ void createDriftConfigurationBasedir() throws Exception {
+ PluginDescriptor descriptor = toPluginDescriptor("" + //
+ "<plugin name='drift-test-plugin' displayName='Drift
Test' package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:d='urn:xmlns:rhq-drift'>" + //
+ " <server name='TestServer'>" + //
+ " <drift-configuration name='test1'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>pluginConfiguration</d:value-context>" + //
+ " <d:value-name>var.lib.test1</d:value-name>"
+ //
+ " </d:basedir>" + //
+ " </drift-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test1",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ DriftConfiguration dc = new
DriftConfiguration(driftTemplate.getConfiguration());
+ BaseDirectory basedir = dc.getBasedir();
+ assertEquals(basedir.getValueContext(),
BaseDirValueContext.pluginConfiguration, "Bad value context");
+ assertEquals(basedir.getValueName(), "var.lib.test1", "Bad
value name");
+ }
+ });
+ }
+
+ @Test
+ void createDriftConfigurationInvalidBasedir() throws Exception {
+ try {
+ toPluginDescriptor("" + //
+ "<plugin name='drift-test-plugin' displayName='Drift
Test' package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" + //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:d='urn:xmlns:rhq-drift'>" + //
+ " <server name='TestServer'>" + //
+ " <drift-configuration name='test1'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>saywhat</d:value-context>" + // this is an invalid
context
+ "
<d:value-name>var.lib.test1</d:value-name>" + //
+ " </d:basedir>" + //
+ " </drift-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+ assert false : "should not have reached here, the XML itself was invalid
and should not have parsed";
+ } catch (Exception ignore) {
+ // this is OK and expected - the XML should not have parsed due to the
invalid context
+ }
+ }
+
+ @Test
+ void createDriftConfigurationIntervalDefault() throws Exception {
+ PluginDescriptor descriptor = toPluginDescriptor("" + //
+ "<plugin name='drift-test-plugin' displayName='Drift
Test' package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:d='urn:xmlns:rhq-drift'>" + //
+ " <server name='TestServer'>" + //
+ " <drift-configuration name='test1'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>pluginConfiguration</d:value-context>" + //
+ " <d:value-name>var.lib.test1</d:value-name>"
+ //
+ " </d:basedir>" + //
+ " </drift-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test1",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ assertEquals(driftTemplate.getConfiguration().getSimpleValue(
+ DriftConfigurationDefinition.PROP_INTERVAL, null), String
+ .valueOf(DriftConfigurationDefinition.DEFAULT_INTERVAL),
+ "Expected to find default property set for interval");
+ }
+ });
+ }
+
+ @Test
+ void createDriftConfigurationIntervalDefaultWithSpecifiedValue() throws Exception {
+ PluginDescriptor descriptor = toPluginDescriptor("" + //
+ "<plugin name='drift-test-plugin' displayName='Drift
Test' package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:d='urn:xmlns:rhq-drift'>" + //
+ " <server name='TestServer'>" + //
+ " <drift-configuration name='test1'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>pluginConfiguration</d:value-context>" + //
+ " <d:value-name>var.lib.test1</d:value-name>"
+ //
+ " </d:basedir>" + //
+ " <d:interval>3600</d:interval>" + //
+ " </drift-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test1",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ assertEquals(driftTemplate.getConfiguration().getSimpleValue(
+ DriftConfigurationDefinition.PROP_INTERVAL, null), "3600",
+ "Expected to find default property set for
<interval>");
+ }
+ });
+
+ }
+
+ @Test
+ void createDriftConfigurationIncludesDefaultWithSpecifiedValue() throws Exception {
+ PluginDescriptor descriptor = toPluginDescriptor("" + //
+ "<plugin name='drift-test-plugin' displayName='Drift
Test' package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:d='urn:xmlns:rhq-drift'>" + //
+ " <server name='TestServer'>" + //
+ " <drift-configuration name='test1'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>pluginConfiguration</d:value-context>" + //
+ " <d:value-name>var.lib.test1</d:value-name>"
+ //
+ " </d:basedir>" + //
+ " <d:includes>" + //
+ " <d:include path='lib'
pattern='*.jar'/>" + //
+ " <d:include path='conf'
pattern='*.xml'/>" + //
+ " </d:includes>" + //
+ " </drift-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test1",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ Configuration config = driftTemplate.getConfiguration();
+ PropertyList includes =
config.getList(DriftConfigurationDefinition.PROP_INCLUDES);
+
+ assertNotNull(includes, "Expected to find default property set for
<includes>");
+ assertEquals(includes.getList().size(), 2,
+ "Expected <includes> property list to have two property
elements.");
+
+ PropertyMap include1 = (PropertyMap) includes.getList().get(0);
+ PropertySimple path1 =
include1.getSimple(DriftConfigurationDefinition.PROP_PATH);
+ PropertySimple pattern1 =
include1.getSimple(DriftConfigurationDefinition.PROP_PATTERN);
+
+ assertNotNull(path1, "Expected to find a simple property for the
path of the first <include>");
+ assertEquals(path1.getStringValue(), "lib", "The value is
wrong for the path of the first <include>");
+
+ assertNotNull(pattern1, "Expected to find a simple property for the
pattern of the first <include>");
+ assertEquals(pattern1.getStringValue(), "*.jar",
+ "The value is wrong for the pattern of the first
<include>");
+
+ PropertyMap include2 = (PropertyMap) includes.getList().get(1);
+ PropertySimple path2 =
include2.getSimple(DriftConfigurationDefinition.PROP_PATH);
+ PropertySimple pattern2 =
include2.getSimple(DriftConfigurationDefinition.PROP_PATTERN);
+
+ assertNotNull(path2, "Expected to find a simple property for the
path of the second <include>");
+ assertEquals(path2.getStringValue(), "conf", "The value is
wrong for the path of the second <include>");
+
+ assertNotNull(pattern2, "Expected to find a simple property for the
pattern of the second <include>");
+ assertEquals(pattern2.getStringValue(), "*.xml",
+ "The value is wrong for the pattern of the second
<include>");
+ }
+ });
+ }
+
+ @Test
+ void createDriftConfigurationExcludesDefaultWithSpecifiedValue() throws Exception {
+ PluginDescriptor descriptor = toPluginDescriptor("" + //
+ "<plugin name='drift-test-plugin' displayName='Drift
Test' package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:d='urn:xmlns:rhq-drift'>" + //
+ " <server name='TestServer'>" + //
+ " <drift-configuration name='test1'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>pluginConfiguration</d:value-context>" + //
+ " <d:value-name>var.lib.test1</d:value-name>"
+ //
+ " </d:basedir>" + //
+ " <d:interval>3600</d:interval>" + //
+ " <d:excludes>" + //
+ " <d:exclude path='lib'
pattern='*.jar'/>" + //
+ " <d:exclude path='conf'
pattern='*.xml'/>" + //
+ " </d:excludes>" + //
+ " </drift-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test1",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ Configuration config = driftTemplate.getConfiguration();
+ PropertyList excludes =
config.getList(DriftConfigurationDefinition.PROP_EXCLUDES);
+
+ assertNotNull(excludes, "Expected to find default property set for
<excludes>");
+ assertEquals(excludes.getList().size(), 2,
+ "Expected <excludes> property list to have two property
elements.");
+
+ PropertyMap exclude1 = (PropertyMap) excludes.getList().get(0);
+ PropertySimple path1 =
exclude1.getSimple(DriftConfigurationDefinition.PROP_PATH);
+ PropertySimple pattern1 =
exclude1.getSimple(DriftConfigurationDefinition.PROP_PATTERN);
+
+ assertNotNull(path1, "Expected to find a simple property for the
path of the first <exclude>");
+ assertEquals(path1.getStringValue(), "lib", "The value is
wrong for the path of the first <exclude>");
+
+ assertNotNull(pattern1, "Expected to find a simple property for the
pattern of the first <exclude>");
+ assertEquals(pattern1.getStringValue(), "*.jar",
+ "The value is wrong for the pattern of the first
<exclude>");
+
+ PropertyMap exclude2 = (PropertyMap) excludes.getList().get(1);
+ PropertySimple path2 =
exclude2.getSimple(DriftConfigurationDefinition.PROP_PATH);
+ PropertySimple pattern2 =
exclude2.getSimple(DriftConfigurationDefinition.PROP_PATTERN);
+
+ assertNotNull(path2, "Expected to find a simple property for the
path of the second <exclude>");
+ assertEquals(path2.getStringValue(), "conf", "The value is
wrong for the path of the second <exclude>");
+
+ assertNotNull(pattern2, "Expected to find a simple property for the
pattern of the second <exclude>");
+ assertEquals(pattern2.getStringValue(), "*.xml",
+ "The value is wrong for the pattern of the second
<exclude>");
+ }
+ });
+ }
+
+ /**
+ * This also tests DriftConfiguration POJO.
+ *
+ * @throws Exception
+ */
+ @Test
+ void createDriftConfigurationMultipleAndTestDriftConfiguration() throws Exception {
+ PluginDescriptor descriptor = toPluginDescriptor("" + //
+ "<plugin name='drift-test-plugin' displayName='Drift
Test' package='org.rhq.plugins.test'" + //
+ "
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
+ //
+ " xmlns='urn:xmlns:rhq-plugin'" + //
+ " xmlns:d='urn:xmlns:rhq-drift'>" + //
+ " <server name='TestServer'>" + //
+ " <drift-configuration name='test1'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>pluginConfiguration</d:value-context>" + //
+ " <d:value-name>var.lib.test1</d:value-name>"
+ //
+ " </d:basedir>" + //
+ " <d:interval>11111</d:interval>" + //
+ " <d:includes>" + //
+ " <d:include path='ilib'
pattern='*.ijar'/>" + //
+ " <d:include path='iconf'
pattern='*.ixml'/>" + //
+ " </d:includes>" + //
+ " </drift-configuration>" + //
+ " <drift-configuration name='test2'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>resourceConfiguration</d:value-context>" + //
+ " <d:value-name>var.lib.test2</d:value-name>"
+ //
+ " </d:basedir>" + //
+ " <d:interval>22222</d:interval>" + //
+ " <d:excludes>" + //
+ " <d:exclude path='elib'
pattern='*.ejar'/>" + //
+ " <d:exclude path='econf'
pattern='*.exml'/>" + //
+ " </d:excludes>" + //
+ " </drift-configuration>" + //
+ " <drift-configuration name='test3'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>measurementTrait</d:value-context>" + //
+ " <d:value-name>var.lib.test3</d:value-name>"
+ //
+ " </d:basedir>" + //
+ " <d:interval>33333</d:interval>" + //
+ " <d:includes>" + //
+ " <d:include path='ilib'
pattern='*.ijar'/>" + //
+ " <d:include path='iconf'
pattern='*.ixml'/>" + //
+ " </d:includes>" + //
+ " <d:excludes>" + //
+ " <d:exclude path='elib'
pattern='*.ejar'/>" + //
+ " <d:exclude path='econf'
pattern='*.exml'/>" + //
+ " </d:excludes>" + //
+ " </drift-configuration>" + //
+ " <drift-configuration name='test4'>" + //
+ " <d:basedir>" + //
+ "
<d:value-context>fileSystem</d:value-context>" + //
+ " <d:value-name>/wot/gorilla</d:value-name>" +
//
+ " </d:basedir>" + //
+ " <d:interval>44444</d:interval>" + //
+ " </drift-configuration>" + //
+ " </server>" + //
+ "</plugin>");
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test1",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ Configuration config = driftTemplate.getConfiguration();
+ DriftConfiguration dconfig = new DriftConfiguration(config);
+
+ assertEquals(dconfig.getInterval().longValue(), 11111L);
+ assertEquals(dconfig.getBasedir().getValueContext(),
BaseDirValueContext.pluginConfiguration);
+ assertEquals(dconfig.getBasedir().getValueName(),
"var.lib.test1");
+
+ assertNotNull(dconfig.getExcludes(), "though we have no excludes,
still expect non-null empty list");
+ assertEquals(dconfig.getExcludes().size(), 0);
+
+ List<Filter> includes = dconfig.getIncludes();
+
+ assertNotNull(includes, "Expected to find default property set for
<includes>");
+ assertEquals(includes.size(), 2, "Expected <includes> property
list to have two property elements.");
+
+ DriftConfiguration.Filter include1 = includes.get(0);
+ String path1 = include1.getPath();
+ String pattern1 = include1.getPattern();
+
+ assertNotNull(path1, "Expected to find a simple property for the
path of the first <include>");
+ assertEquals(path1, "ilib", "The value is wrong for the
path of the first <include>");
+
+ assertNotNull(pattern1, "Expected to find a simple property for the
pattern of the first <include>");
+ assertEquals(pattern1, "*.ijar", "The value is wrong for
the pattern of the first <include>");
+
+ DriftConfiguration.Filter include2 = includes.get(1);
+ String path2 = include2.getPath();
+ String pattern2 = include2.getPattern();
+
+ assertNotNull(path2, "Expected to find a simple property for the
path of the second <include>");
+ assertEquals(path2, "iconf", "The value is wrong for the
path of the second <include>");
+
+ assertNotNull(pattern2, "Expected to find a simple property for the
pattern of the second <include>");
+ assertEquals(pattern2, "*.ixml", "The value is wrong for
the pattern of the second <include>");
+ }
+ });
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test2",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ Configuration config = driftTemplate.getConfiguration();
+ DriftConfiguration dconfig = new DriftConfiguration(config);
+
+ assertEquals(dconfig.getInterval().longValue(), 22222L);
+ assertEquals(dconfig.getBasedir().getValueContext(),
BaseDirValueContext.resourceConfiguration);
+ assertEquals(dconfig.getBasedir().getValueName(),
"var.lib.test2");
+
+ assertNotNull(dconfig.getIncludes(), "though we have no includes,
still expect non-null empty list");
+ assertEquals(dconfig.getIncludes().size(), 0);
+
+ List<Filter> excludes = dconfig.getExcludes();
+
+ assertNotNull(excludes, "Expected to find default property set for
<excludes>");
+ assertEquals(excludes.size(), 2, "Expected <excludes> property
list to have two property elements.");
+
+ DriftConfiguration.Filter exclude1 = excludes.get(0);
+ String path1 = exclude1.getPath();
+ String pattern1 = exclude1.getPattern();
+
+ assertNotNull(path1, "Expected to find a simple property for the
path of the first <exclude>");
+ assertEquals(path1, "elib", "The value is wrong for the
path of the first <exclude>");
+
+ assertNotNull(pattern1, "Expected to find a simple property for the
pattern of the first <exclude>");
+ assertEquals(pattern1, "*.ejar", "The value is wrong for
the pattern of the first <exclude>");
+
+ DriftConfiguration.Filter exclude2 = excludes.get(1);
+ String path2 = exclude2.getPath();
+ String pattern2 = exclude2.getPattern();
+
+ assertNotNull(path2, "Expected to find a simple property for the
path of the second <exclude>");
+ assertEquals(path2, "econf", "The value is wrong for the
path of the second <exclude>");
+
+ assertNotNull(pattern2, "Expected to find a simple property for the
pattern of the second <exclude>");
+ assertEquals(pattern2, "*.exml", "The value is wrong for
the pattern of the second <exclude>");
+ }
+ });
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test3",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ Configuration config = driftTemplate.getConfiguration();
+ DriftConfiguration dconfig = new DriftConfiguration(config);
+
+ assertEquals(dconfig.getInterval().longValue(), 33333L);
+ assertEquals(dconfig.getBasedir().getValueContext(),
BaseDirValueContext.measurementTrait);
+ assertEquals(dconfig.getBasedir().getValueName(),
"var.lib.test3");
+
+ List<Filter> includes = dconfig.getIncludes();
+
+ assertNotNull(includes, "Expected to find default property set for
<includes>");
+ assertEquals(includes.size(), 2, "Expected <includes> property
list to have two property elements.");
+
+ DriftConfiguration.Filter include1 = includes.get(0);
+ String path1 = include1.getPath();
+ String pattern1 = include1.getPattern();
+
+ assertNotNull(path1, "Expected to find a simple property for the
path of the first <include>");
+ assertEquals(path1, "ilib", "The value is wrong for the
path of the first <include>");
+
+ assertNotNull(pattern1, "Expected to find a simple property for the
pattern of the first <include>");
+ assertEquals(pattern1, "*.ijar", "The value is wrong for
the pattern of the first <include>");
+
+ DriftConfiguration.Filter include2 = includes.get(1);
+ String path2 = include2.getPath();
+ String pattern2 = include2.getPattern();
+
+ assertNotNull(path2, "Expected to find a simple property for the
path of the second <include>");
+ assertEquals(path2, "iconf", "The value is wrong for the
path of the second <include>");
+
+ assertNotNull(pattern2, "Expected to find a simple property for the
pattern of the second <include>");
+ assertEquals(pattern2, "*.ixml", "The value is wrong for
the pattern of the second <include>");
+
+ List<Filter> excludes = dconfig.getExcludes();
+
+ assertNotNull(excludes, "Expected to find default property set for
<excludes>");
+ assertEquals(excludes.size(), 2, "Expected <excludes> property
list to have two property elements.");
+
+ DriftConfiguration.Filter exclude1 = excludes.get(0);
+ path1 = exclude1.getPath();
+ pattern1 = exclude1.getPattern();
+
+ assertNotNull(path1, "Expected to find a simple property for the
path of the first <exclude>");
+ assertEquals(path1, "elib", "The value is wrong for the
path of the first <exclude>");
+
+ assertNotNull(pattern1, "Expected to find a simple property for the
pattern of the first <exclude>");
+ assertEquals(pattern1, "*.ejar", "The value is wrong for
the pattern of the first <exclude>");
+
+ DriftConfiguration.Filter exclude2 = excludes.get(1);
+ path2 = exclude2.getPath();
+ pattern2 = exclude2.getPattern();
+
+ assertNotNull(path2, "Expected to find a simple property for the
path of the second <exclude>");
+ assertEquals(path2, "econf", "The value is wrong for the
path of the second <exclude>");
+
+ assertNotNull(pattern2, "Expected to find a simple property for the
pattern of the second <exclude>");
+ assertEquals(pattern2, "*.exml", "The value is wrong for
the pattern of the second <exclude>");
+ }
+ });
+
+ verifyDriftConfiguration(descriptor, "TestServer", "test4",
new AssertDriftTemplateRunnable() {
+ @Override
+ public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
+ Configuration config = driftTemplate.getConfiguration();
+ DriftConfiguration dconfig = new DriftConfiguration(config);
+
+ assertEquals(dconfig.getInterval().longValue(), 44444L);
+ assertEquals(dconfig.getBasedir().getValueContext(),
BaseDirValueContext.fileSystem);
+ assertEquals(dconfig.getBasedir().getValueName(),
"/wot/gorilla");
+
+ assertNotNull(dconfig.getIncludes(), "though we have no includes,
still expect non-null empty list");
+ assertEquals(dconfig.getIncludes().size(), 0);
+
+ assertNotNull(dconfig.getExcludes(), "though we have no excludes,
still expect non-null empty list");
+ assertEquals(dconfig.getExcludes().size(), 0);
+ }
+ });
+ }
+
+ private interface AssertDriftTemplateRunnable {
+ void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws Exception;
+ }
+
+ private void verifyDriftConfiguration(PluginDescriptor descriptor, String
resourceTypeName, String driftConfigName,
+ AssertDriftTemplateRunnable test) throws Exception {
+
+ Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
+ PluginMetadataParser parser = new PluginMetadataParser(descriptor,
parsersByPlugin);
+ ResourceType resourceType = findResourceType(parser, resourceTypeName);
+ Set<ConfigurationTemplate> driftTemplates =
resourceType.getDriftConfigurationTemplates();
+ ConfigurationTemplate driftTemplate = null;
+ for (ConfigurationTemplate template : driftTemplates) {
+ if (template.getName().equals(driftConfigName)) {
+ driftTemplate = template;
+ break;
+ }
+ }
+ assertNotNull(driftTemplate, "Failed to find drift configuration template
[" + driftConfigName
+ + "]. The name attribute may not have been parsed correctly.");
+
+ PropertySimple name =
driftTemplate.getConfiguration().getSimple(DriftConfigurationDefinition.PROP_NAME);
+ PropertySimple enabled =
driftTemplate.getConfiguration().getSimple(DriftConfigurationDefinition.PROP_ENABLED);
+
+ assertNotNull(name, "Expected to find a simple property <name> for the
drift configuration name");
+ assertEquals(name.getStringValue(), driftConfigName,
+ "The value is wrong for the <name> property that represents the
drift configuration name");
+
+ assertNotNull(enabled, "Expected to find simple property <enabled> for
the drift configuration");
+ assertFalse(enabled.getBooleanValue(), "The <enabled> property should
be set to a default value of false");
+
+ test.assertDriftTemplate(driftTemplate);
+ }
+}
diff --git a/modules/core/dbutils/src/main/scripts/dbsetup/config-data.xml
b/modules/core/dbutils/src/main/scripts/dbsetup/config-data.xml
index 03768a2..089cd64 100644
--- a/modules/core/dbutils/src/main/scripts/dbsetup/config-data.xml
+++ b/modules/core/dbutils/src/main/scripts/dbsetup/config-data.xml
@@ -2,37 +2,149 @@
<dbsetup name="config-data.xml">
<table name="RHQ_CONFIG_DEF">
- <data id="1" name="GLOBAL_DRIFT_CONFIG_DEF"
description="The drift configuration definition"/>
+ <data id="1" name="GLOBAL_DRIFT_CONFIG_DEF"
description="The drift configuration definition"
+ config_format="STRUCTURED" />
</table>
<table name="RHQ_CONFIG_PROP_DEF">
- <data id="1" name="name" display_name="Drift
Configuration Name" description="The drift configuration name"
- required="true" simple_type="string"
order_index="0" dtype="property" config_def_id="1"/>
- <data id="2" name="enabled"
display_name="Enabled" description="Enables or disables the drift
configuration"
- required="true" default_value="false"
simple_type="boolean" order_index="1" dtype="property"
config_def_id="1"/>
- <data id="3" name="basedir" display_name="Base
Directory" dtype="property"
+ <data id="1" name="name" display_name="Drift
Configuration Name" config_def_id="1"
+ description="The drift configuration name"
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="0"
+ dtype="property"
+ simple_type="STRING"
+ allow_custom_enum_value="false" />
+
+ <data id="2" name="enabled"
display_name="Enabled" config_def_id="1"
+ description="Enables or disables the drift configuration"
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="1"
+ dtype="property"
+ simple_type="BOOLEAN"
+ allow_custom_enum_value="false"
+ default_value="false" />
+
+ <data id="3" name="basedir" display_name="Base
Directory" config_def_id="1"
description="The root directory from which snapshots will be generated
during drift monitoring."
- required="true" simple_type="string"
order_index="2" config_def_id="1"/>
- <data id="4" name="interval"
display_name="Interval" dtype="property"
- description="The frequency in seconds in which drift monitoring should
run. Defaults to thirty minutes."
- default_value="1800" simple_type="long"
order_index="3" config_def_id="1"/>
- <data id="5" name="includes"
display_name="Includes" dtype="list"
- description="A set of patterns that specify files and/or directories
to include." order_index="4"
- config_def_id="1"/>
- <data id="6" name="include"
display_name="Include" dtype="map"
parent_list_definition_id="4"/>
- <data id="7" name="path" display_name="Path"
dtype="property"
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="2"
+ dtype="map" />
+
+ <data id="4" name="valueContext" display_name="Value
Context" parent_map_definition_id="3"
+ description="Identifies where the named value can be found."
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="0"
+ dtype="property"
+ simple_type="STRING"
+ allow_custom_enum_value="false" />
+
+ <data id="5" name="valueName" display_name="Value
Name" parent_map_definition_id="3"
+ description="The name of the value as found in the context"
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="1"
+ dtype="property"
+ simple_type="STRING"
+ allow_custom_enum_value="false" />
+
+ <data id="6" name="interval"
display_name="Interval" config_def_id="1"
+ description="The frequency in seconds in which drift monitoring should
run. Defaults to 1800 seconds (i.e. 30 minutes)"
+ required="false"
+ readonly="false"
+ summary="true"
+ order_index="3"
+ dtype="property"
+ simple_type="LONG"
+ allow_custom_enum_value="false"
+ default_value="1800" />
+
+ <data id="7" name="includes"
display_name="Includes" config_def_id="1"
+ description="A set of patterns that specify files and/or directories
to include."
+ required="false"
+ readonly="false"
+ summary="true"
+ order_index="4"
+ dtype="list" />
+
+ <data id="8" name="include"
display_name="Include" parent_list_definition_id="7"
+ description="A pattern that specifies a file or directory to
include."
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="0"
+ dtype="map" />
+
+ <data id="9" name="path" display_name="Path"
parent_map_definition_id="8"
description="A file system path that can be a directory or a file. The
path is assumed to be relative to the base directory of the drift configuration."
- simple_type="string" order_index="0"
parent_map_definition_id="5"/>
- <data id="8" name="pattern"
display_name="Pattern" dtype="property" description="TBD"
simple_type="string"
- order_index="1" parent_map_definition_id="5"/>
- <data id="9" name="excludes"
display_name="Excludes" dtype="list"
- description="A set of patterns that specify files and/or directories
to exclude." order_index="5"
- config_def_id="1"/>
- <data id="10" name="exclude"
display_name="Exclude" dtype="map"
parent_list_definition_id="8"/>
- <data id="11" name="path" display_name="Path"
dtype="property"
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="0"
+ dtype="property"
+ simple_type="STRING"
+ allow_custom_enum_value="false" />
+
+ <data id="10" name="pattern"
display_name="Pattern" parent_map_definition_id="8"
+ description="Pathname pattern that must match for the items in the
directory path to be included."
+ required="false"
+ readonly="false"
+ summary="true"
+ order_index="1"
+ dtype="property"
+ simple_type="STRING"
+ allow_custom_enum_value="false" />
+
+ <data id="11" name="excludes"
display_name="Excludes" config_def_id="1"
+ description="A set of patterns that specify files and/or directories
to exclude."
+ required="false"
+ readonly="false"
+ summary="true"
+ order_index="5"
+ dtype="list" />
+
+ <data id="12" name="exclude"
display_name="Exclude" parent_list_definition_id="11"
+ description="A pattern that specifies a files or directory to
exclude."
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="0"
+ dtype="map" />
+
+ <data id="13" name="path" display_name="Path"
parent_map_definition_id="12"
description="A file system path that can be a directory or a file. The
path is assumed to be relative to the base directory of the drift configuration."
- simple_type="string" order_index="0"
parent_map_definition_id="9"/>
- <data id="12" name="pattern"
display_name="Pattern" dtype="property" description="TBD"
simple_type="string"
- order_index="1" parent_map_definition_id="9"/>
+ required="true"
+ readonly="false"
+ summary="true"
+ order_index="0"
+ dtype="property"
+ simple_type="STRING"
+ allow_custom_enum_value="false" />
+
+ <data id="14" name="pattern"
display_name="Pattern" parent_map_definition_id="12"
+ description="Pathname pattern that must match for the items in the
directory path to be excluded."
+ required="false"
+ readonly="false"
+ summary="true"
+ order_index="1"
+ dtype="property"
+ simple_type="STRING"
+ allow_custom_enum_value="false" />
+ </table>
+
+ <table name="RHQ_CONF_PROP_DEF_ENUM">
+ <data id="1" name="pluginConfiguration"
string_value="pluginConfiguration" order_index="0"
property_def_id="4" />
+ <data id="2" name="resourceConfiguration"
string_value="resourceConfiguration" order_index="1"
property_def_id="4" />
+ <data id="3" name="measurementTrait"
string_value="measurementTrait" order_index="2"
property_def_id="4" />
+ <data id="4" name="fileSystem"
string_value="fileSystem" order_index="3"
property_def_id="4" />
</table>
+
</dbsetup>
\ No newline at end of file
diff --git a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
index 8f0a9c7..d34a247 100644
--- a/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
+++ b/modules/core/dbutils/src/main/scripts/dbupgrade/db-upgrade.xml
@@ -3451,70 +3451,52 @@
VALUES (1, 'GLOBAL_DRIFT_CONFIG_DEF', 'The drift
configuration definition')
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name,
description, required, simple_type,
- order_index, dtype, config_def_id)
- VALUES (1, 'name', 'Drift Configuration Name',
'The drift configuration name', true, 'string',
- 0, 'property', 1)
+ INSERT INTO rhq_config_prop_def (id, name, display_name,
description, required, simple_type, order_index, dtype, config_def_id)
+ VALUES (1, 'name', 'Drift Configuration Name',
'The drift configuration name', true, 'STRING', 0, 'property', 1)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name,
description, required, simple_type,
- default_value, order_index, dtype, config_def_id)
- VALUES (2, 'enabled', 'Enabled', 'Enables or
disables drift detection for this configuration', true, 'boolean',
- 'false', 1, 'property', 1)
+ INSERT INTO rhq_config_prop_def (id, name, display_name,
description, required, simple_type, default_value, order_index, dtype, config_def_id)
+ VALUES (2, 'enabled', 'Enabled', 'Enables or
disables drift detection for this configuration', true, 'BOOLEAN',
'false', 1, 'property', 1)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name,
description, required, simple_type,
- order_index, dtype, config_def_id)
- VALUES (3, 'basedir', 'Base Directory', 'The
base directory from which files will be monitored for drift.',
- true, 'string', 2, 'property', 1)
+ INSERT INTO rhq_config_prop_def (id, name, display_name,
description, required, simple_type, order_index, dtype, config_def_id)
+ VALUES (3, 'basedir', 'Base Directory', 'The
base directory from which files will be monitored for drift.', true, 'STRING',
2, 'property', 1)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name,
description, required, simple_type,
- order_index, dtype, default_value, config_def_id)
- VALUES (4, 'interval', 'Interval', 'The
interval, in seconds, between drift detection scans for this configuration. Default is
thirty minutes.',
- false, 'long', 3, 'property', '1800',
1)
+ INSERT INTO rhq_config_prop_def (id, name, display_name,
description, required, simple_type, order_index, dtype, default_value, config_def_id)
+ VALUES (4, 'interval', 'Interval', 'The
interval, in seconds, between drift detection scans for this configuration. Default is
thirty minutes.', false, 'LONG', 3, 'property', '1800', 1)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name, dtype,
description, order_index,
- config_def_id)
- VALUES (5, 'includes', 'Includes',
'list', 'A set of patterns that specify files and/or directories to
include.',
- 4, 1)
+ INSERT INTO rhq_config_prop_def (id, name, display_name, dtype,
description, order_index, config_def_id)
+ VALUES (5, 'includes', 'Includes',
'list', 'A set of patterns that specify files and/or directories to
include.', 4, 1)
</statement>
<statement>
INSERT INTO rhq_config_prop_def (id, name, display_name, dtype,
parent_list_definition_id)
VALUES (6, 'include', 'Include', 'map',
4)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name,
description, simple_type,
- order_index, dtype, parent_map_definition_id)
- VALUES (7, 'path', 'Path', 'A file system
path that can be a directory or a file. The path is assumed to be relative to the base
directory of the drift configuration.',
- 'string', 0, 'property', 5)
+ INSERT INTO rhq_config_prop_def (id, name, display_name,
description, simple_type, order_index, dtype, parent_map_definition_id)
+ VALUES (7, 'path', 'Path', 'A file system
path that can be a directory or a file. The path is assumed to be relative to the base
directory of the drift configuration.', 'STRING', 0, 'property', 5)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name,
description, simple_type,
- order_index, dtype, parent_map_definition_id)
- VALUES (8, 'pattern', 'Pattern', 'TBD',
'string', 1, 'property', 5)
+ INSERT INTO rhq_config_prop_def (id, name, display_name,
description, simple_type, order_index, dtype, parent_map_definition_id)
+ VALUES (8, 'pattern', 'Pattern', 'Pathname
pattern that must match for the items in the directory path to be included.',
'STRING', 1, 'property', 5)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name, dtype,
description, order_index,
- config_def_id)
- VALUES (9, 'excludes', 'Excludes',
'list', 'A set of patterns that specify files and/or directories to
exclude.',
- 5, 1)
+ INSERT INTO rhq_config_prop_def (id, name, display_name, dtype,
description, order_index, config_def_id)
+ VALUES (9, 'excludes', 'Excludes',
'list', 'A set of patterns that specify files and/or directories to
exclude.', 5, 1)
</statement>
<statement>
INSERT INTO rhq_config_prop_def (id, name, display_name, dtype,
parent_list_definition_id)
VALUES (10, 'exclude', 'Exclude', 'map',
8)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name,
description, simple_type,
- order_index, dtype, parent_map_definition_id)
- VALUES (11, 'path', 'Path', 'A file system
path that can be a directory or a file. The path is assumed to be relative to the base
directory of the drift configuration.',
- 'string', 0, 'property', 9)
+ INSERT INTO rhq_config_prop_def (id, name, display_name,
description, simple_type, order_index, dtype, parent_map_definition_id)
+ VALUES (11, 'path', 'Path', 'A file system
path that can be a directory or a file. The path is assumed to be relative to the base
directory of the drift configuration.', 'STRING', 0, 'property', 9)
</statement>
<statement>
- INSERT INTO rhq_config_prop_def (id, name, display_name,
description, simple_type,
- order_index, dtype, parent_map_definition_id)
- VALUES (12, 'pattern', 'Pattern', 'TBD',
'string', 1, 'property', 9)
+ INSERT INTO rhq_config_prop_def (id, name, display_name,
description, simple_type, order_index, dtype, parent_map_definition_id)
+ VALUES (12, 'pattern', 'Pattern', 'Pathname
pattern that must match for the items in the directory path to be excluded.',
'STRING', 1, 'property', 9)
</statement>
</schema-directSQL>
</schemaSpec>
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
index c09b473..00f9ab9 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
@@ -32,15 +32,47 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.Property;
import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
import org.rhq.core.domain.resource.Resource;
/**
+ * This is a convienence wrapper around a Configuration object whose schema is that
+ * of {@link DriftConfigurationDefinition}.
+ *
+ * Note that this is not an actual Configuration object - it's got a HAS-A
relationship
+ * with Configuration.
+ *
+ * This object also has an optional relationship with a Resource.
+ *
+ * TODO: this is missing setters for includes/excludes filters. We should add those.
+ *
* @author John Sanda
+ * @author John Mazzitelli
*/
public class DriftConfiguration implements Serializable {
private static final long serialVersionUID = 1L;
+ public class BaseDirectory implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private final BaseDirValueContext context;
+ private final String name;
+
+ public BaseDirectory(BaseDirValueContext context, String name) {
+ this.context = context;
+ this.name = name;
+ }
+
+ public BaseDirValueContext getValueContext() {
+ return context;
+ }
+
+ public String getValueName() {
+ return name;
+ }
+ }
+
public static class Filter implements Serializable {
private static final long serialVersionUID = 1L;
@@ -126,28 +158,94 @@ public class DriftConfiguration implements Serializable {
return configuration.getId();
}
+ public void setId(int id) {
+ configuration.setId(id);
+ }
+
public String getName() {
- return configuration.getSimpleValue("name", "");
+ return configuration.getSimpleValue(DriftConfigurationDefinition.PROP_NAME,
"");
+ }
+
+ public void setName(String name) {
+ if (name == null) {
+ throw new NullPointerException("name is null");
+ }
+ configuration.put(new PropertySimple(DriftConfigurationDefinition.PROP_NAME,
name));
+ }
+
+ public BaseDirectory getBasedir() {
+ PropertyMap map =
configuration.getMap(DriftConfigurationDefinition.PROP_BASEDIR);
+ String valueContext =
map.getSimpleValue(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT, null);
+ String valueName =
map.getSimpleValue(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME, null);
+
+ BaseDirValueContext valueContextEnum;
+
+ if (valueContext == null) {
+ throw new NullPointerException("valueContext is null");
+ } else {
+ try {
+ valueContextEnum = BaseDirValueContext.valueOf(valueContext);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Invalid valueContext: " +
valueContext);
+ }
+ }
+
+ if (valueName == null) {
+ throw new NullPointerException("valueName is null");
+ }
+
+ return new BaseDirectory(valueContextEnum, valueName);
}
- public String getBasedir() {
- return configuration.getSimpleValue("basedir", "");
+ public void setBasedir(BaseDirectory basedir) {
+ if (basedir == null) {
+ throw new NullPointerException("basedir is null");
+ }
+ if (basedir.getValueContext() == null) {
+ throw new NullPointerException("valueContext is null");
+ }
+ if (basedir.getValueName() == null) {
+ throw new NullPointerException("valueName is null");
+ }
+
+ String valueContext = basedir.getValueContext().name();
+ String valueName = basedir.getValueName();
+
+ PropertyMap basedirMap = new
PropertyMap(DriftConfigurationDefinition.PROP_BASEDIR);
+ basedirMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT, valueContext));
+ basedirMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME, valueName));
+
+ configuration.put(basedirMap);
}
public Long getInterval() {
- return Long.parseLong(configuration.getSimpleValue("interval",
"0"));
+ return
Long.parseLong(configuration.getSimpleValue(DriftConfigurationDefinition.PROP_INTERVAL,
String
+ .valueOf(DriftConfigurationDefinition.DEFAULT_INTERVAL)));
+ }
+
+ public void setInterval(Long interval) {
+ if (interval == null) {
+ configuration.remove(DriftConfigurationDefinition.PROP_INTERVAL);
+ } else {
+ configuration.put(new
PropertySimple(DriftConfigurationDefinition.PROP_INTERVAL, interval.toString()));
+ }
}
public boolean getEnabled() {
- return configuration.getSimpleValue("enabled",
"false").equals("true");
+ return configuration.getSimpleValue(DriftConfigurationDefinition.PROP_ENABLED,
+
String.valueOf(DriftConfigurationDefinition.DEFAULT_ENABLED)).equals("true");
+ }
+
+ public void setEnabled(boolean enabled) {
+ configuration.put(new PropertySimple(DriftConfigurationDefinition.PROP_ENABLED,
String.valueOf(enabled)));
}
public List<Filter> getIncludes() {
- return getFilters("includes");
+ return getFilters(DriftConfigurationDefinition.PROP_INCLUDES);
}
public List<Filter> getExcludes() {
- return getFilters("excludes");
+ return getFilters(DriftConfigurationDefinition.PROP_EXCLUDES);
}
private List<Filter> getFilters(String type) {
@@ -159,7 +257,8 @@ public class DriftConfiguration implements Serializable {
List<Filter> filters = new ArrayList<Filter>();
for (Property property : filtersListProperty.getList()) {
PropertyMap filter = (PropertyMap) property;
- filters.add(new Filter(filter.getSimpleValue("path", ""),
filter.getSimpleValue("pattern", "")));
+ filters.add(new
Filter(filter.getSimpleValue(DriftConfigurationDefinition.PROP_PATH, ""),
filter
+ .getSimpleValue(DriftConfigurationDefinition.PROP_PATTERN,
"")));
}
return filters;
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
index 4279049..3090601 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationDefinition.java
@@ -18,68 +18,340 @@
*/
package org.rhq.core.domain.drift;
-import java.util.HashMap;
-import java.util.Map;
+import java.io.Serializable;
+import java.util.ArrayList;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.ConfigurationFormat;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionEnumeration;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
/**
+ * The drift subsystem has a fixed configuration definition. That is, its property
definitions
+ * are the same always. There is no metadata that needs to be read in from a descriptor -
this definition
+ * is fixed and the code requires all the property definitions to follow what is encoded
in this POJO.
+ *
+ * Note that this class must mimic the definition data as found in the database. The
installer
+ * will prepopulate the configuration definition tables that match the definitions
encoded in this POJO.
+ *
* @author Jay Shaughnessy
+ * @author John Mazzitelli
*/
-public class DriftConfigurationDefinition {
+public class DriftConfigurationDefinition implements Serializable {
+ private static final long serialVersionUID = 1L;
- static private final ConfigurationDefinition INSTANCE = new
ConfigurationDefinition("GLOBAL_DRIFT_CONFIG_DEF",
+ public static final String PROP_NAME = "name";
+ public static final String PROP_ENABLED = "enabled";
+ public static final String PROP_BASEDIR = "basedir";
+ public static final String PROP_BASEDIR_VALUECONTEXT = "valueContext";
+ public static final String PROP_BASEDIR_VALUENAME = "valueName";
+ public static final String PROP_INTERVAL = "interval";
+ public static final String PROP_INCLUDES = "includes";
+ public static final String PROP_INCLUDES_INCLUDE = "include";
+ public static final String PROP_EXCLUDES = "excludes";
+ public static final String PROP_EXCLUDES_EXCLUDE = "exclude";
+ public static final String PROP_PATH = "path"; // for both include and
exclude
+ public static final String PROP_PATTERN = "pattern"; // for both include
and exclude
+
+ public static final boolean DEFAULT_ENABLED = false;
+ public static final long DEFAULT_INTERVAL = 1800L;
+
+ /**
+ * The basedir property is specified in two parts - a "context" and a
"name". Taken together
+ * the value of the basedir can be determined. The value name is just a simple name
that
+ * is used to look up the basedir value within the appropriate context. A context can
be
+ * one of four places - either the value is a named property in a resource's
plugin configuration,
+ * a named property in a resource's resource configuration, a named trait that is
emitted by a
+ * resource or an absolute path found on a file system.
+ */
+ public enum BaseDirValueContext {
+ pluginConfiguration, resourceConfiguration, measurementTrait, fileSystem
+ }
+
+ private static final ConfigurationDefinition INSTANCE = new
ConfigurationDefinition("GLOBAL_DRIFT_CONFIG_DEF",
"The drift configuration definition");
+ public static ConfigurationDefinition getInstance() {
+ return INSTANCE;
+ }
+
static {
INSTANCE.setId(1);
- Map<String, PropertyDefinition> propDefs = new HashMap<String,
PropertyDefinition>();
- PropertyDefinitionSimple propDef;
-
- propDef = new PropertyDefinitionSimple("name", "The drift
configuration name", true, PropertySimpleType.STRING);
- propDefs.put("name", propDef);
-
- propDef = new PropertyDefinitionSimple("name", "The drift
configuration name", true, PropertySimpleType.STRING);
- propDef.setId(1);
- propDef.setDisplayName("Drift Configuration Name");
- propDef.setOrder(0);
- propDef.setConfigurationDefinition(INSTANCE);
- propDefs.put("name", propDef);
-
- propDef = new PropertyDefinitionSimple("enabled", "Enabled",
true, PropertySimpleType.BOOLEAN);
- propDef.setId(2);
- propDef.setDisplayName("Enables or disables drift detection for this
configuration");
- propDef.setOrder(1);
- propDef.setDefaultValue("false");
- propDef.setConfigurationDefinition(INSTANCE);
- propDefs.put("enabled", propDef);
-
- propDef = new PropertyDefinitionSimple("basedir", "Base
Directory", true, PropertySimpleType.STRING);
- propDef.setId(3);
- propDef.setDisplayName("The base directory from which files will be
monitored for drift.");
- propDef.setOrder(2);
- propDef.setConfigurationDefinition(INSTANCE);
- propDefs.put("basedir", propDef);
-
- propDef = new PropertyDefinitionSimple("interval",
"Interval", false, PropertySimpleType.LONG);
- propDef.setId(4);
- propDef
- .setDisplayName("The interval, in seconds, between drift detection scans
for this configuration. Default is 30 minutes.");
- propDef.setOrder(3);
- propDef.setDefaultValue("1800");
- propDef.setConfigurationDefinition(INSTANCE);
- propDefs.put("interval", propDef);
-
- //TODO, add the include/exclude list of maps
-
- INSTANCE.setPropertyDefinitions(propDefs);
- }
-
- static public ConfigurationDefinition getInstance() {
- return INSTANCE;
+ INSTANCE.setConfigurationFormat(ConfigurationFormat.STRUCTURED);
+
+ INSTANCE.put(createName());
+ INSTANCE.put(createEnabled());
+ INSTANCE.put(createBasedir());
+ INSTANCE.put(createInterval());
+ INSTANCE.put(createIncludes());
+ INSTANCE.put(createExcludes());
+
+ }
+
+ private static PropertyDefinitionSimple createName() {
+ String name = PROP_NAME;
+ String description = "The drift configuration name";
+ boolean required = true;
+ PropertySimpleType type = PropertySimpleType.STRING;
+
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(1);
+ pd.setDisplayName("Drift Configuration Name");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(0);
+ pd.setAllowCustomEnumeratedValue(false);
+ pd.setConfigurationDefinition(INSTANCE);
+ return pd;
+ }
+
+ private static PropertyDefinitionSimple createEnabled() {
+ String name = PROP_ENABLED;
+ String description = "Enables or disables the drift configuration";
+ boolean required = true;
+ PropertySimpleType type = PropertySimpleType.BOOLEAN;
+
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(2);
+ pd.setDisplayName("Enabled");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(1);
+ pd.setAllowCustomEnumeratedValue(false);
+ pd.setConfigurationDefinition(INSTANCE);
+ pd.setDefaultValue(String.valueOf(DEFAULT_ENABLED));
+ return pd;
+ }
+
+ private static PropertyDefinitionMap createBasedir() {
+ String name = PROP_BASEDIR;
+ String description = "The root directory from which snapshots will be
generated during drift monitoring.";
+ boolean required = true;
+
+ PropertyDefinitionSimple valueContext = createBasedirValueContext();
+ PropertyDefinitionSimple valueName = createBasedirValueName();
+
+ PropertyDefinitionMap pd = new PropertyDefinitionMap(name, description, required,
valueContext, valueName);
+ pd.setId(3);
+ pd.setDisplayName("Base Directory");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(2);
+ pd.setConfigurationDefinition(INSTANCE);
+
+ return pd;
+ }
+
+ private static PropertyDefinitionSimple createBasedirValueContext() {
+ String name = PROP_BASEDIR_VALUECONTEXT;
+ String description = "Identifies where the named value can be found.";
+ boolean required = true;
+ PropertySimpleType type = PropertySimpleType.STRING;
+
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(4);
+ pd.setDisplayName("Value Context");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(0);
+
+ PropertyDefinitionEnumeration pcEnum = new PropertyDefinitionEnumeration(
+ BaseDirValueContext.pluginConfiguration.name(),
BaseDirValueContext.pluginConfiguration.name());
+ pcEnum.setId(1);
+ pcEnum.setOrderIndex(0);
+
+ PropertyDefinitionEnumeration rcEnum = new PropertyDefinitionEnumeration(
+ BaseDirValueContext.resourceConfiguration.name(),
BaseDirValueContext.resourceConfiguration.name());
+ rcEnum.setId(2);
+ rcEnum.setOrderIndex(1);
+
+ PropertyDefinitionEnumeration mtEnum = new
PropertyDefinitionEnumeration(BaseDirValueContext.measurementTrait
+ .name(), BaseDirValueContext.measurementTrait.name());
+ mtEnum.setId(3);
+ mtEnum.setOrderIndex(2);
+
+ PropertyDefinitionEnumeration fsEnum = new
PropertyDefinitionEnumeration(BaseDirValueContext.fileSystem.name(),
+ BaseDirValueContext.fileSystem.name());
+ fsEnum.setId(4);
+ fsEnum.setOrderIndex(3);
+
+ ArrayList<PropertyDefinitionEnumeration> pdEnums = new
ArrayList<PropertyDefinitionEnumeration>(4);
+ pdEnums.add(pcEnum);
+ pdEnums.add(rcEnum);
+ pdEnums.add(mtEnum);
+ pdEnums.add(fsEnum);
+ pd.setEnumeratedValues(pdEnums, false);
+
+ return pd;
+ }
+
+ private static PropertyDefinitionSimple createBasedirValueName() {
+ String name = PROP_BASEDIR_VALUENAME;
+ String description = "The name of the value as found in the context";
+ boolean required = true;
+ PropertySimpleType type = PropertySimpleType.STRING;
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(5);
+ pd.setDisplayName("Value Name");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(1);
+ pd.setAllowCustomEnumeratedValue(false);
+ return pd;
}
+
+ private static PropertyDefinitionSimple createInterval() {
+ String name = PROP_INTERVAL;
+ String description = "The frequency in seconds in which drift monitoring
should run. Defaults to 1800 seconds (i.e. 30 minutes)";
+ boolean required = false;
+ PropertySimpleType type = PropertySimpleType.LONG;
+
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(6);
+ pd.setDisplayName("Interval");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(3);
+ pd.setAllowCustomEnumeratedValue(false);
+ pd.setConfigurationDefinition(INSTANCE);
+ pd.setDefaultValue(String.valueOf(DEFAULT_INTERVAL));
+ return pd;
+ }
+
+ private static PropertyDefinitionList createIncludes() {
+ String name = PROP_INCLUDES;
+ String description = "A set of patterns that specify files and/or
directories to include.";
+ boolean required = false;
+
+ PropertyDefinitionMap map = createInclude();
+
+ PropertyDefinitionList pd = new PropertyDefinitionList(name, description,
required, map);
+ pd.setId(7);
+ pd.setDisplayName("Includes");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(4);
+ pd.setConfigurationDefinition(INSTANCE);
+ return pd;
+ }
+
+ private static PropertyDefinitionMap createInclude() {
+ String name = PROP_INCLUDES_INCLUDE;
+ String description = "A set of patterns that specify files and/or
directories to include.";
+ boolean required = true;
+
+ PropertyDefinitionSimple path = createIncludePath();
+ PropertyDefinitionSimple pattern = createIncludePattern();
+
+ PropertyDefinitionMap pd = new PropertyDefinitionMap(name, description, required,
path, pattern);
+ pd.setId(8);
+ pd.setDisplayName("Include");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(0);
+ return pd;
+ }
+
+ private static PropertyDefinitionSimple createIncludePath() {
+ String name = PROP_PATH;
+ String description = "A file system path that can be a directory or a file.
The path is assumed to be relative to the base directory of the drift
configuration.";
+ boolean required = true;
+ PropertySimpleType type = PropertySimpleType.STRING;
+
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(9);
+ pd.setDisplayName("Path");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(0);
+ pd.setAllowCustomEnumeratedValue(false);
+ return pd;
+ }
+
+ private static PropertyDefinitionSimple createIncludePattern() {
+ String name = PROP_PATTERN;
+ String description = "Pathname pattern that must match for the items in the
directory path to be included.";
+ boolean required = false;
+ PropertySimpleType type = PropertySimpleType.STRING;
+
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(10);
+ pd.setDisplayName("Pattern");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(1);
+ pd.setAllowCustomEnumeratedValue(false);
+ return pd;
+ }
+
+ private static PropertyDefinitionList createExcludes() {
+ String name = PROP_EXCLUDES;
+ String description = "A set of patterns that specify files and/or
directories to exclude.";
+ boolean required = false;
+
+ PropertyDefinitionMap map = createExclude();
+
+ PropertyDefinitionList pd = new PropertyDefinitionList(name, description,
required, map);
+ pd.setId(11);
+ pd.setDisplayName("Excludes");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(5);
+ pd.setConfigurationDefinition(INSTANCE);
+ return pd;
+ }
+
+ private static PropertyDefinitionMap createExclude() {
+ String name = PROP_EXCLUDES_EXCLUDE;
+ String description = "A set of patterns that specify files and/or
directories to exclude.";
+ boolean required = true;
+
+ PropertyDefinitionSimple path = createExcludePath();
+ PropertyDefinitionSimple pattern = createExcludePattern();
+
+ PropertyDefinitionMap pd = new PropertyDefinitionMap(name, description, required,
path, pattern);
+ pd.setId(12);
+ pd.setDisplayName("Exclude");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(0);
+ return pd;
+ }
+
+ private static PropertyDefinitionSimple createExcludePath() {
+ String name = PROP_PATH;
+ String description = "A file system path that can be a directory or a file.
The path is assumed to be relative to the base directory of the drift
configuration.";
+ boolean required = true;
+ PropertySimpleType type = PropertySimpleType.STRING;
+
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(13);
+ pd.setDisplayName("Path");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(0);
+ pd.setAllowCustomEnumeratedValue(false);
+ return pd;
+ }
+
+ private static PropertyDefinitionSimple createExcludePattern() {
+ String name = PROP_PATTERN;
+ String description = "Pathname pattern that must match for the items in the
directory path to be excluded.";
+ boolean required = false;
+ PropertySimpleType type = PropertySimpleType.STRING;
+
+ PropertyDefinitionSimple pd = new PropertyDefinitionSimple(name, description,
required, type);
+ pd.setId(14);
+ pd.setDisplayName("Pattern");
+ pd.setReadOnly(false);
+ pd.setSummary(true);
+ pd.setOrder(1);
+ pd.setAllowCustomEnumeratedValue(false);
+ return pd;
+ }
+
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
index ef97e00..cffea1c 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
@@ -6,7 +6,9 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@@ -18,9 +20,18 @@ import org.rhq.core.clientapi.agent.drift.DriftAgentService;
import org.rhq.core.clientapi.server.drift.DriftServerService;
import org.rhq.core.domain.drift.DriftConfiguration;
import org.rhq.core.domain.drift.DriftFile;
+import org.rhq.core.domain.measurement.DataType;
+import org.rhq.core.domain.measurement.MeasurementData;
+import org.rhq.core.domain.measurement.MeasurementDataRequest;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.domain.resource.Resource;
import org.rhq.core.pc.ContainerService;
+import org.rhq.core.pc.PluginContainer;
import org.rhq.core.pc.PluginContainerConfiguration;
import org.rhq.core.pc.agent.AgentService;
+import org.rhq.core.pc.inventory.InventoryManager;
+import org.rhq.core.pc.inventory.ResourceContainer;
+import org.rhq.core.pc.measurement.MeasurementManager;
public class DriftManager extends AgentService implements DriftAgentService, DriftClient,
ContainerService {
@@ -108,8 +119,8 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
driftServer.sendFilesZip(resourceId, zipFile.length(), remoteInputStream(new
BufferedInputStream(
new FileInputStream(zipFile))));
} catch (IOException e) {
- log.error("An error occurred while trying to send content for
changeset[resourceId: " + resourceId +
- ", driftConfiguration: " + driftConfigurationName +
"]", e);
+ log.error("An error occurred while trying to send content for
changeset[resourceId: " + resourceId
+ + ", driftConfiguration: " + driftConfigurationName +
"]", e);
}
}
@@ -165,7 +176,6 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
return true;
}
-
@Override
public void unscheduleDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
}
@@ -174,4 +184,143 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
public void updateDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
}
+ /**
+ * Given a drift configuration, this examines the config and its associated resource
to determine where exactly
+ * the base directory is that should be monitoried.
+ *
+ * @param driftConfiguration describes what is to be monitored for drift
+ *
+ * @return absolute directory location where the drift configuration base directory
is referring
+ */
+ public File getAbsoluteBaseDirectory(DriftConfiguration driftConfiguration) {
+
+ // get the resource entity stored in our local inventory
+ InventoryManager im = getInventoryManager();
+ Resource resource = driftConfiguration.getResource();
+ ResourceContainer container = im.getResourceContainer(resource);
+ resource = container.getResource();
+
+ // find out the type of base location that is specified by the drift config
+ DriftConfiguration.BaseDirectory baseDir = driftConfiguration.getBasedir();
+ if (baseDir == null) {
+ throw new IllegalArgumentException("Missing basedir in drift
config");
+ }
+
+ // based on the type of base location, determine the root base directory
+ String baseDirValueName = baseDir.getValueName(); // the name we look up in the
given context
+ String baseLocation;
+ switch (baseDir.getValueContext()) {
+ case fileSystem: {
+ baseLocation = baseDirValueName; // the value name IS the absolute directory
name
+ if (baseLocation == null || baseLocation.trim().length() == 0) {
+ baseLocation = File.separator; // paranoia, if not specified, assume the
top root directory
+ }
+ break;
+ }
+ case pluginConfiguration: {
+ baseLocation =
resource.getPluginConfiguration().getSimpleValue(baseDirValueName, null);
+ if (baseLocation == null) {
+ throw new IllegalArgumentException("Cannot determine the bundle base
deployment location - "
+ + "there is no plugin configuration setting for [" +
baseDirValueName + "]");
+ }
+ break;
+ }
+ case resourceConfiguration: {
+ baseLocation =
resource.getResourceConfiguration().getSimpleValue(baseDirValueName, null);
+ if (baseLocation == null) {
+ throw new IllegalArgumentException("Cannot determine the bundle base
deployment location - "
+ + "there is no resource configuration setting for [" +
baseDirValueName + "]");
+ }
+ break;
+ }
+ case measurementTrait: {
+ baseLocation = getTraitValue(container, baseDirValueName);
+ if (baseLocation == null) {
+ throw new IllegalArgumentException("Cannot obtain trait [" +
baseDirValueName + "] for resource ["
+ + resource.getName() + "]");
+ }
+ break;
+ }
+ default: {
+ throw new IllegalArgumentException("Unknown location context: " +
baseDir.getValueContext());
+ }
+ }
+
+ File destDir = new File(baseLocation);
+
+ if (!destDir.isAbsolute()) {
+ throw new IllegalArgumentException("The base location path specified by
[" + baseDirValueName
+ + "] in the context [" + baseDir.getValueContext() + "]
did not resolve to an absolute path ["
+ + destDir.getPath() + "] so there is no way to know what directory
to monitor for drift");
+ }
+
+ return destDir;
+ }
+
+ /**
+ * Given the name of a trait, this will find the value of that trait for the given
resource.
+ *
+ * @param resource the resource whose trait value is to be obtained
+ * @param traitName the name of the trait whose value is to be obtained
+ *
+ * @return the value of the trait, or <code>null</code> if unknown
+ *
+ * TODO: this is taken directly from BundleManager. We should refactor this and the
one
+ * in BundleManager to a single place, perhaps MeasurementManager.
+ */
+ private String getTraitValue(ResourceContainer container, String traitName) {
+ Integer traitScheduleId = null;
+ Set<MeasurementScheduleRequest> schedules =
container.getMeasurementSchedule();
+ for (MeasurementScheduleRequest schedule : schedules) {
+ if (schedule.getName().equals(traitName)) {
+ if (schedule.getDataType() != DataType.TRAIT) {
+ throw new IllegalArgumentException("Measurement named [" +
traitName + "] for resource ["
+ + container.getResource().getName() + "] is not a trait, it
is of type ["
+ + schedule.getDataType() + "]");
+ }
+ traitScheduleId = Integer.valueOf(schedule.getScheduleId());
+ }
+ }
+ if (traitScheduleId == null) {
+ throw new IllegalArgumentException("There is no trait [" +
traitName + "] for resource ["
+ + container.getResource().getName() + "]");
+ }
+
+ MeasurementManager mm = getMeasurementManager();
+ String traitValue = mm.getCachedTraitValue(traitScheduleId.intValue());
+ if (traitValue == null) {
+ // the trait hasn't been collected yet, so it isn't cached. We need
to get its live value
+ List<MeasurementDataRequest> requests = new
ArrayList<MeasurementDataRequest>();
+ requests.add(new MeasurementDataRequest(traitName, DataType.TRAIT));
+ Set<MeasurementData> dataset =
mm.getRealTimeMeasurementValue(container.getResource().getId(), requests);
+ if (dataset != null && dataset.size() == 1) {
+ Object value = dataset.iterator().next().getValue();
+ if (value != null) {
+ traitValue = value.toString();
+ }
+ }
+ }
+
+ return traitValue;
+ }
+
+ /**
+ * Returns the manager that can provide data on the inventory. This is a separate
protected method
+ * so we can extend our manger class to have a mock manager for testing.
+ *
+ * @return the inventory manager
+ */
+ protected InventoryManager getInventoryManager() {
+ return PluginContainer.getInstance().getInventoryManager();
+ }
+
+ /**
+ * Returns the manager that can provide data on the measurements/metrics. This is a
separate protected method
+ * so we can extend our manger class to have a mock manager for testing.
+ *
+ * @return the inventory manager
+ */
+ protected MeasurementManager getMeasurementManager() {
+ return PluginContainer.getInstance().getMeasurementManager();
+ }
}
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftConfigurationDefinitionTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftConfigurationDefinitionTest.java
new file mode 100644
index 0000000..525a46c
--- /dev/null
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftConfigurationDefinitionTest.java
@@ -0,0 +1,212 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.server.drift;
+
+import java.util.List;
+
+import org.testng.annotations.Test;
+
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionEnumeration;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition;
+import org.rhq.enterprise.server.test.AbstractEJB3Test;
+
+/**
+ * Tests that our hard-coded singleton DriftConfigurationDefinition is persisted properly
in the DB.
+ */
+@Test
+public class DriftConfigurationDefinitionTest extends AbstractEJB3Test {
+
+ public void testDriftConfigurationDefinition() throws Throwable {
+ getTransactionManager().begin();
+ try {
+ ConfigurationDefinition def = DriftConfigurationDefinition.getInstance();
+ ConfigurationDefinition defDATABASE =
getEntityManager().find(ConfigurationDefinition.class, def.getId());
+
+ assert defDATABASE.getId() == def.getId();
+ assert defDATABASE.getPropertyDefinitions().size() ==
def.getPropertyDefinitions().size();
+
+ PropertyDefinitionSimple simpleDATABASE;
+ PropertyDefinitionSimple simple;
+ PropertyDefinitionMap mapDATABASE;
+ PropertyDefinitionMap map;
+ PropertyDefinitionList listDATABASE;
+ PropertyDefinitionList list;
+
+ // NAME
+ simpleDATABASE =
defDATABASE.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_NAME);
+ simple =
def.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_NAME);
+ assertSimpleProperty(simpleDATABASE, simple);
+
+ // ENABLED
+ simpleDATABASE =
defDATABASE.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_ENABLED);
+ simple =
def.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_ENABLED);
+ assertSimpleProperty(simpleDATABASE, simple);
+
+ // INTERVAL
+ simpleDATABASE =
defDATABASE.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_INTERVAL);
+ simple =
def.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_INTERVAL);
+ assertSimpleProperty(simpleDATABASE, simple);
+
+ // BASEDIR
+ mapDATABASE =
defDATABASE.getPropertyDefinitionMap(DriftConfigurationDefinition.PROP_BASEDIR);
+ map =
def.getPropertyDefinitionMap(DriftConfigurationDefinition.PROP_BASEDIR);
+ assertMapProperty(mapDATABASE, map);
+
+ // BASEDIR VALUECONTEXT (implicitly also tests the enums)
+ simpleDATABASE = mapDATABASE
+
.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT);
+ simple =
map.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT);
+ assertSimpleProperty(simpleDATABASE, simple);
+
+ // BASEDIR VALUENAME
+ simpleDATABASE = mapDATABASE
+
.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME);
+ simple =
map.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME);
+ assertSimpleProperty(simpleDATABASE, simple);
+
+ // INCLUDES
+ listDATABASE =
defDATABASE.getPropertyDefinitionList(DriftConfigurationDefinition.PROP_INCLUDES);
+ list =
def.getPropertyDefinitionList(DriftConfigurationDefinition.PROP_INCLUDES);
+ assertListProperty(listDATABASE, list);
+
+ // INCLUDES INCLUDE
+ /*
+ PropertyDefinitionMap deleteme =
getEntityManager().find(PropertyDefinitionMap.class, 8);
+
+ mapDATABASE = (PropertyDefinitionMap) listDATABASE.getMemberDefinition();
+ map = (PropertyDefinitionMap) list.getMemberDefinition();
+ assertMapProperty(mapDATABASE, map);
+
+ // INCLUDES INCLUDE PATH
+ simpleDATABASE =
mapDATABASE.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_PATH);
+ simple =
map.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_PATH);
+ assertSimpleProperty(simpleDATABASE, simple);
+
+ // INCLUDES INCLUDE PATTERN
+ simpleDATABASE =
mapDATABASE.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_PATTERN);
+ simple =
map.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_PATTERN);
+ assertSimpleProperty(simpleDATABASE, simple);
+ */
+
+ // EXCLUDES
+ listDATABASE =
defDATABASE.getPropertyDefinitionList(DriftConfigurationDefinition.PROP_EXCLUDES);
+ list =
def.getPropertyDefinitionList(DriftConfigurationDefinition.PROP_EXCLUDES);
+ assertListProperty(listDATABASE, list);
+
+ /*
+ // EXCLUDES EXCLUDE
+ mapDATABASE = (PropertyDefinitionMap) listDATABASE.getMemberDefinition();
+ map = (PropertyDefinitionMap) list.getMemberDefinition();
+ assertMapProperty(mapDATABASE, map);
+
+ // EXCLUDES EXCLUDE PATH
+ simpleDATABASE =
mapDATABASE.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_PATH);
+ simple =
map.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_PATH);
+ assertSimpleProperty(simpleDATABASE, simple);
+
+ // EXCLUDES EXCLUDE PATTERN
+ simpleDATABASE =
mapDATABASE.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_PATTERN);
+ simple =
map.getPropertyDefinitionSimple(DriftConfigurationDefinition.PROP_PATTERN);
+ assertSimpleProperty(simpleDATABASE, simple);
+ */
+ } finally {
+ getTransactionManager().rollback();
+ }
+ }
+
+ private void assertListProperty(PropertyDefinitionList listDb, PropertyDefinitionList
list) throws Throwable {
+
+ try {
+ assert listDb.getId() == list.getId();
+ assert listDb.getActivationPolicy() == list.getActivationPolicy();
+ assert listDb.getDescription().equals(list.getDescription());
+ assert listDb.getDisplayName().equals(list.getDisplayName());
+ assert listDb.getName().equals(list.getName());
+ assert listDb.getOrder() == list.getOrder();
+ } catch (Throwable t) {
+ System.out.println("Lists failed test:\nlistDb=[" + listDb +
"]\nlist=[" + list + "]");
+ throw t;
+ }
+ }
+
+ private void assertMapProperty(PropertyDefinitionMap mapDb, PropertyDefinitionMap
map) throws Throwable {
+
+ try {
+ assert mapDb.getId() == map.getId();
+ assert mapDb.getActivationPolicy() == map.getActivationPolicy();
+ assert mapDb.getDescription().equals(map.getDescription());
+ assert mapDb.getDisplayName().equals(map.getDisplayName());
+ assert mapDb.getName().equals(map.getName());
+ assert mapDb.getOrder() == map.getOrder();
+ } catch (Throwable t) {
+ System.out.println("Maps failed test:\nmapDb=[" + mapDb +
"]\nmap=[" + map + "]");
+ throw t;
+ }
+ }
+
+ private void assertSimpleProperty(PropertyDefinitionSimple simpleDb,
PropertyDefinitionSimple simple)
+ throws Throwable {
+
+ try {
+ assert simpleDb.getId() == simple.getId();
+ assert simpleDb.getAllowCustomEnumeratedValue() ==
simple.getAllowCustomEnumeratedValue();
+ assert simpleDb.getActivationPolicy() == simple.getActivationPolicy();
+ assert simpleDb.getDescription().equals(simple.getDescription());
+ assert simpleDb.getDisplayName().equals(simple.getDisplayName());
+ assert simpleDb.getName().equals(simple.getName());
+ assert simpleDb.getOrder() == simple.getOrder();
+ assert simpleDb.getType() == simple.getType();
+ if (simpleDb.getDefaultValue() == null) {
+ assert simpleDb.getDefaultValue() == null &&
simple.getDefaultValue() == null;
+ } else {
+ assert simpleDb.getDefaultValue().equals(simple.getDefaultValue());
+ }
+ assertEnumeratedValues(simpleDb.getEnumeratedValues(),
simple.getEnumeratedValues());
+
+ } catch (Throwable t) {
+ System.out.println("Simples failed test:\nsimpleDb=[" + simpleDb +
"]\nsimple=[" + simple + "]");
+ throw t;
+ }
+ }
+
+ private void assertEnumeratedValues(List<PropertyDefinitionEnumeration>
enumsDb,
+ List<PropertyDefinitionEnumeration> enums) throws Throwable {
+
+ assert enumsDb.size() == enums.size() : "enum sizes do not match: " +
enumsDb.size() + ":" + enums.size();
+
+ for (int i = 0; i < enumsDb.size(); i++) {
+ PropertyDefinitionEnumeration eenumDb = enumsDb.get(i);
+ PropertyDefinitionEnumeration eenum = enums.get(i);
+
+ try {
+ assert eenumDb.getId() == eenum.getId();
+ assert eenumDb.getName().equals(eenum.getName());
+ assert eenumDb.getOrderIndex() == eenum.getOrderIndex();
+ assert eenumDb.getValue().equals(eenum.getValue());
+ } catch (Throwable t) {
+ System.out.println("Enum failed test:\neenumDb=[" + eenumDb +
"]\neenums=[" + eenum + "]");
+ throw t;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/test/resources/log4j.xml
b/modules/enterprise/server/jar/src/test/resources/log4j.xml
index d721bff..681f2af 100644
--- a/modules/enterprise/server/jar/src/test/resources/log4j.xml
+++ b/modules/enterprise/server/jar/src/test/resources/log4j.xml
@@ -49,6 +49,13 @@
<priority value="ERROR"/>
</category>
+ <!-- Hibernate SQL logs -->
+ <!--
+ <category name="org.hibernate.SQL">
+ <priority value="DEBUG"/>
+ </category>
+ -->
+
<root>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>