[rhq] Branch 'mod_cluster_plugin' - 5 commits - modules/plugins modules/test-utils
by snegrea
modules/plugins/mod-cluster/pom.xml | 78 +++++++++
modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml | 15 -
modules/plugins/pom.xml | 3
modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java | 22 ++
modules/test-utils/src/main/java/org/rhq/test/CollectionMatchesChecker.java | 82 ++++++++++
5 files changed, 191 insertions(+), 9 deletions(-)
New commits:
commit 93ac1b5c3ba6032e3c726f32e01d73e16d73e076
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Wed Jul 6 15:28:48 2011 -0500
A couple more tweaks to make the user interface for mod_cluster display correct and proper text.
diff --git a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
index cdfa7fb..b2179c3 100644
--- a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
@@ -24,7 +24,7 @@
<plugin-configuration>
<c:simple-property name="objectName" readOnly="true" default="Catalina:type=ModClusterListener,*"/>
- <c:simple-property name="nameTemplate" default="{application}"/>
+ <c:simple-property name="nameTemplate" default="mod_cluster"/>
</plugin-configuration>
<operation name="reset" displayName="Reset the node" description="Move the node out of an error state" />
@@ -50,22 +50,22 @@
<c:simple-property name="advertise" type="boolean" description="Enable autodiscovery of httpd servers."/>
</resource-configuration>
- <service name="mod_cluster_context"
+ <service name="mod_cluster Webapp Context"
discovery="ContextDiscoveryComponent"
class="ContextComponent"
description="A mod_cluster context">
- <operation name="enableContext" displayName="Enable webapp" description="Enable a single webapp">
+ <operation name="enableContext" displayName="Enable webapp" description="Enable the webapp">
<results>
<c:simple-property name="result" type="boolean" description="The result of the operation" />
</results>
</operation>
- <operation name="disableContext" displayName="Disable webpapp" description="Disable a single webapp">
+ <operation name="disableContext" displayName="Disable webpapp" description="Disable the webapp">
<results>
<c:simple-property name="result" type="boolean" description="The result of the operation" />
</results>
</operation>
- <operation name="stopContext" displayName="Stop webpapp" description="Gracefully stops a single webapp">
+ <operation name="stopContext" displayName="Stop webpapp" description="Gracefully stops the webapp">
<results>
<c:simple-property name="result" type="boolean" description="The result of the operation" />
</results>
commit bed08a054ca397b313d97022c29ad61f1b7e6a81
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Wed Jul 6 13:19:07 2011 -0500
Fine tuning the plugin configuration based other plugin configuration and test deployment issues.
diff --git a/modules/plugins/mod-cluster/pom.xml b/modules/plugins/mod-cluster/pom.xml
index 74defeb..4536125 100644
--- a/modules/plugins/mod-cluster/pom.xml
+++ b/modules/plugins/mod-cluster/pom.xml
@@ -12,7 +12,7 @@
<artifactId>modcluster-plugin</artifactId>
<packaging>jar</packaging>
- <name>mod_cluster RHQ Plugin</name>
+ <name>RHQ mod_cluster Plugin</name>
<description>mod_cluster RHQ Agent plugin</description>
<dependencies>
diff --git a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
index be4b25b..cdfa7fb 100644
--- a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
@@ -14,11 +14,12 @@
discovery="org.rhq.plugins.jmx.MBeanResourceDiscoveryComponent"
class="ModclusterServerComponent"
supportsManualAdd="true"
- description="mod_cluster plugin">
+ description="mod_cluster plugin"
+ singleton="true">
<runs-inside>
<parent-resource-type name="JBossAS Server" plugin="JBossAS"/>
- <parent-resource-type name="JBossAS Server" plugin="JBossAS5"/>
+ <parent-resource-type name="JBossAS5 Server" plugin="JBossAS5"/>
</runs-inside>
<plugin-configuration>
diff --git a/modules/plugins/pom.xml b/modules/plugins/pom.xml
index 02f6584..f32159e 100644
--- a/modules/plugins/pom.xml
+++ b/modules/plugins/pom.xml
@@ -125,10 +125,11 @@
<module>augeas</module>
<module>apache</module>
<module>tomcat</module>
- <module>jboss-as</module>
<module>hibernate</module>
+ <module>mod-cluster</module>
<module>rhq-server</module>
<module>jboss-cache</module>
+ <module>jboss-as</module>
<module>jboss-as-5</module>
<module>jboss-as-7</module>
<module>jboss-cache-v3</module>
commit af18d25dc8b66f9d95477e90356f6aecccf6077c
Merge: 7f4c0a9 67e6127
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Wed Jul 6 10:01:46 2011 -0500
Merge branch 'master' into mod_cluster_plugin
commit 7f4c0a99bb2121fd3496d3bc1af3079f4e922c3a
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Wed Jul 6 10:00:21 2011 -0500
Added dev profile for plugin deployment in the local plugin repo.
diff --git a/modules/plugins/mod-cluster/pom.xml b/modules/plugins/mod-cluster/pom.xml
index a19dfc0..74defeb 100644
--- a/modules/plugins/mod-cluster/pom.xml
+++ b/modules/plugins/mod-cluster/pom.xml
@@ -190,6 +190,82 @@
</plugins>
</build>
</profile>
+
+
+ <profile>
+ <id>dev</id>
+
+ <properties>
+ <rhq.rootDir>../../..</rhq.rootDir>
+ <rhq.containerDir>${rhq.rootDir}/${rhq.defaultDevContainerPath}</rhq.containerDir>
+ <rhq.deploymentDir>${rhq.containerDir}/jbossas/server/default/deploy/${rhq.earName}/rhq-downloads/rhq-plugins</rhq.deploymentDir>
+ </properties>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+
+ <execution>
+ <id>deploy</id>
+ <phase>compile</phase>
+ <configuration>
+ <tasks>
+ <mkdir dir="${rhq.deploymentDir}" />
+ <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar" />
+ <echo>*** Updating ${deployment.file}...</echo>
+ <jar destfile="${deployment.file}" basedir="${project.build.outputDirectory}" />
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ <execution>
+ <id>deploy-jar-meta-inf</id>
+ <phase>package</phase>
+ <configuration>
+ <tasks>
+ <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar" />
+ <echo>*** Updating META-INF dir in ${deployment.file}...</echo>
+ <unjar src="${project.build.directory}/${project.build.finalName}.jar" dest="${project.build.outputDirectory}">
+ <patternset><include name="META-INF/**" /></patternset>
+ </unjar>
+ <jar destfile="${deployment.file}" manifest="${project.build.outputDirectory}/META-INF/MANIFEST.MF" update="true">
+ </jar>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ <execution>
+ <id>undeploy</id>
+ <phase>clean</phase>
+ <configuration>
+ <tasks>
+ <property name="deployment.file" location="${rhq.deploymentDir}/${project.build.finalName}.jar" />
+ <echo>*** Deleting ${deployment.file}...</echo>
+ <delete file="${deployment.file}" />
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+ </profile>
+
</profiles>
</project>
commit 67e6127f6ec3fb8a2186f1a583bda88d76ef2696
Author: John Sanda <jsanda(a)redhat.com>
Date: Fri Jul 1 21:07:04 2011 -0400
Initial commit for CollectionMatchersChecker
Adding a new assert in AssertUtils that verifies whether two collections
match. assertCollectionMatchesNoOrder compares the elements of two
collections, doing a property-wise comparison similar to how
assertPropertiesMatch does.
diff --git a/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java b/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java
index c86114e..fc41623 100644
--- a/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java
+++ b/modules/test-utils/src/main/java/org/rhq/test/AssertUtils.java
@@ -101,4 +101,26 @@ public class AssertUtils {
assertTrue(result.isEqual(), msg + " -- " + result.getDetails());
}
+ /**
+ * Verifies that the two collections contain the same number of matching elements as is
+ * done in {@link #assertPropertiesMatch(String, Object, Object, String...)}. If the
+ * collections differ in size, an assertion error will be thrown; otherwise, elements
+ * are compared, ignoring order. Note that all element properties are are compared in
+ * this method.
+ *
+ * @param expected The expected collection to compare against
+ * @param actual The actual collection under test
+ * @param msg An error message
+ * @param <T> The type of the elements in the collections
+ */
+ public static <T> void assertCollectionMatchesNoOrder(Collection<T> expected, Collection<T> actual, String msg) {
+ CollectionMatchesChecker<T> checker = new CollectionMatchesChecker<T>();
+ checker.setExpected(expected);
+ checker.setActual(actual);
+
+ MatchResult result = checker.execute();
+
+ assertTrue(result.isMatch(), msg + " -- " + result.getDetails());
+ }
+
}
diff --git a/modules/test-utils/src/main/java/org/rhq/test/CollectionMatchesChecker.java b/modules/test-utils/src/main/java/org/rhq/test/CollectionMatchesChecker.java
new file mode 100644
index 0000000..b4b5fcc
--- /dev/null
+++ b/modules/test-utils/src/main/java/org/rhq/test/CollectionMatchesChecker.java
@@ -0,0 +1,82 @@
+package org.rhq.test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+public class CollectionMatchesChecker<T> {
+
+ private Collection<T> expected;
+
+ private Collection<T> actual;
+
+ public void setExpected(Collection<T> expected) {
+ this.expected = expected;
+ }
+
+ public void setActual(Collection<T> actual) {
+ this.actual = actual;
+ }
+
+ public MatchResult execute() {
+ boolean isMatch = true;
+ StringBuilder details = new StringBuilder();
+
+ if (expected.size() != actual.size()) {
+ isMatch = false;
+ details.append("Expected " + expected.size() + " elements but found " + actual.size() + " elements\n");
+ }
+
+ List<T> elementsThatShouldBePresent = findMissingElements(expected, actual);
+ if (!elementsThatShouldBePresent.isEmpty()) {
+ isMatch = false;
+ details.append("Expected to find the following elements:\n\t" +
+ toString(elementsThatShouldBePresent) + "\n\n");
+ }
+
+ List<T> elementsThatShouldNotBePresent = findMissingElements(actual, expected);
+ if (!elementsThatShouldNotBePresent.isEmpty()) {
+ isMatch = false;
+ details.append("Did not expect to find the following elements:\n\t" +
+ toString(elementsThatShouldNotBePresent) + "\n\n");
+ }
+
+ return new MatchResult(isMatch, details.toString());
+ }
+
+ private List<T> findMissingElements(Collection<T> elementsToSearchFor, Collection<T> elementsToSearch) {
+ List<T> missingElements = new ArrayList<T>();
+ for (T element : elementsToSearchFor) {
+ if (!containsMatch(elementsToSearch, element)) {
+ missingElements.add(element);
+ }
+ }
+ return missingElements;
+ }
+
+ private boolean containsMatch(Collection<T> elementsToSearch, T elementToSearchFor) {
+ for (T actual : elementsToSearch) {
+ PropertyMatcher<T> matcher = new PropertyMatcher<T>();
+ matcher.setExpected(elementToSearchFor);
+ matcher.setActual(actual);
+ MatchResult result = matcher.execute();
+
+ if (result.isMatch()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private String toString(List<T> list) {
+ StringBuilder buffer = new StringBuilder("[");
+ for (T element : list) {
+ buffer.append(element.toString() + ", ");
+ }
+ buffer.delete(buffer.length() - 2, buffer.length());
+ buffer.append("]");
+
+ return buffer.toString();
+ }
+
+}
12 years, 11 months
[rhq] Branch 'drift' - 4 commits - modules/common modules/core
by John Sanda
modules/common/drift/src/main/java/org/rhq/common/drift/DirectoryEntry.java | 16 +
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java | 4
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java | 78 +++++---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java | 15 +
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftClient.java | 3
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetectionSchedule.java | 4
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java | 96 +++++++---
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java | 6
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java | 15 -
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java | 41 +++-
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftClientTestStub.java | 5
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java | 69 ++++++-
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java | 4
13 files changed, 281 insertions(+), 75 deletions(-)
New commits:
commit f39dd9c2a10e959842f51b8d51c495157bfb07d8
Author: John Sanda <jsanda(a)redhat.com>
Date: Wed Jul 6 15:49:48 2011 -0400
Removing more unused imports
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java
index 8f4dfa3..5f20699 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java
@@ -55,8 +55,6 @@ public class DirectoryAnalyzer {
Map<String, FileEntry> fileEntries = createFileEntriesMap();
List<String> processed = new ArrayList<String>();
- Set<String> dirEntryFileNames = dirEntryFileNames();
-
for (String file : files) {
if (!fileEntries.containsKey(file)) {
filesAdded.add(addedFileEntry(file, sha256(new File(dir, file))));
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java
index 5a347ac..e4ab114 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java
@@ -1,26 +1,21 @@
package org.rhq.core.pc.drift;
import java.io.File;
-import java.util.Arrays;
import java.util.List;
-import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.DirectoryEntry;
-import org.rhq.common.drift.FileEntry;
import org.rhq.common.drift.Headers;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.drift.DriftChangeSetCategory;
-import org.rhq.core.domain.drift.DriftConfiguration;
import static java.util.Arrays.asList;
-import static org.apache.commons.io.FileUtils.writeLines;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.DRIFT;
-import static org.testng.Assert.*;
-import static org.apache.commons.io.FileUtils.deleteDirectory;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
public class ChangeSetManagerImplTest extends DriftTest {
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
index 1666646..4f27974 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
@@ -16,17 +16,13 @@ import org.rhq.common.drift.ChangeSetReaderImpl;
import org.rhq.common.drift.DirectoryEntry;
import org.rhq.common.drift.FileEntry;
import org.rhq.common.drift.Headers;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.test.AssertUtils;
import static org.apache.commons.io.FileUtils.touch;
import static org.rhq.common.drift.FileEntry.addedFileEntry;
import static org.rhq.common.drift.FileEntry.removedFileEntry;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.DRIFT;
-import static org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext.fileSystem;
import static org.rhq.test.AssertUtils.assertCollectionMatchesNoOrder;
import static org.rhq.test.AssertUtils.assertPropertiesMatch;
import static org.testng.Assert.assertNotNull;
commit 4430a503e84b8c360786c2b0b1ce17aed6b48058
Author: John Sanda <jsanda(a)redhat.com>
Date: Wed Jul 6 15:46:05 2011 -0400
Removing unused, unwanted imports
IntelliJ's code completion is a bit over agressive at times.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
index 2f330ba..dbb1cfb 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
@@ -7,9 +7,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.IOUtils;
-
import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.ChangeSetReaderImpl;
import org.rhq.common.drift.ChangeSetWriter;
@@ -19,9 +16,6 @@ import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
import org.rhq.core.util.stream.StreamUtil;
-import net.sourceforge.cobertura.coveragedata.CoverageData;
-
-import static java.io.File.separator;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
public class ChangeSetManagerImpl implements ChangeSetManager {
commit dba97250148f2c809afb3fcab81cc5470bc2d658
Author: John Sanda <jsanda(a)redhat.com>
Date: Wed Jul 6 15:36:13 2011 -0400
Generate updated coverage change set when generating drift change set
diff --git a/modules/common/drift/src/main/java/org/rhq/common/drift/DirectoryEntry.java b/modules/common/drift/src/main/java/org/rhq/common/drift/DirectoryEntry.java
index 960f687..c5c5e7a 100644
--- a/modules/common/drift/src/main/java/org/rhq/common/drift/DirectoryEntry.java
+++ b/modules/common/drift/src/main/java/org/rhq/common/drift/DirectoryEntry.java
@@ -26,6 +26,22 @@ public class DirectoryEntry implements Iterable<FileEntry>, Serializable {
return this;
}
+ public DirectoryEntry remove(FileEntry entry) {
+ FileEntry entryToRemove = null;
+ int i = 0;
+ for (FileEntry fileEntry : files) {
+ if (entry.getFile().equals(fileEntry.getFile())) {
+ entryToRemove = fileEntry;
+ break;
+ }
+ ++i;
+ }
+ if (entryToRemove != null) {
+ files.remove(i);
+ }
+ return this;
+ }
+
public int getNumberOfFiles() {
return files.size();
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java
index 3f946f5..4ef7821 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java
@@ -44,6 +44,10 @@ public interface ChangeSetManager {
ChangeSetWriter getChangeSetWriter(int resourceId, Headers headers) throws IOException;
+ ChangeSetWriter getChangeSetWriterForUpdate(int resourceId, Headers headers) throws IOException;
+
+ void updateChangeSet(int resourceId, Headers headers) throws IOException;
+
void addFileToChangeSet(int resourceId, DriftConfiguration driftConfiguration, File file);
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
index c412bcb..2f330ba 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
@@ -1,9 +1,14 @@
package org.rhq.core.pc.drift;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.ChangeSetReaderImpl;
@@ -12,6 +17,7 @@ import org.rhq.common.drift.ChangeSetWriterImpl;
import org.rhq.common.drift.Headers;
import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.util.stream.StreamUtil;
import net.sourceforge.cobertura.coveragedata.CoverageData;
@@ -96,6 +102,31 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
@Override
+ public ChangeSetWriter getChangeSetWriterForUpdate(int resourceId, Headers headers) throws IOException {
+ File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
+ File changeSetDir = new File(resourceDir, headers.getDriftConfigurationName());
+
+ return new ChangeSetWriterImpl(new File(changeSetDir, "changeset.working"), headers);
+ }
+
+ @Override
+ public void updateChangeSet(int resourceId, Headers headers) throws IOException {
+ File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
+ File changeSetDir = new File(resourceDir, headers.getDriftConfigurationName());
+ File newChangeSet = new File(changeSetDir, "changeset.working");
+ File changeSet = new File(changeSetDir, "changeset.txt");
+
+ if (!newChangeSet.exists()) {
+ return;
+ }
+
+ changeSet.delete();
+
+ StreamUtil.copy(new BufferedInputStream(new FileInputStream(newChangeSet)),
+ new BufferedOutputStream(new FileOutputStream(changeSet)));
+ }
+
+ @Override
public void addFileToChangeSet(int resourceId, DriftConfiguration driftConfiguration, File file) {
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
index e57d763..f2883b9 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
@@ -60,12 +60,13 @@ public class DriftDetector implements Runnable {
DriftConfiguration driftConfig = schedule.getDriftConfiguration();
int resourceId = schedule.getResourceId();
DriftChangeSetCategory changeSetType = null;
+ int changes = 0;
try {
if (changeSetMgr.changeSetExists(schedule.getResourceId(), new Headers(driftConfig.getName(),
basedir(resourceId, driftConfig), COVERAGE))) {
changeSetType = DRIFT;
- generateDriftChangeSet(schedule);
+ changes = generateDriftChangeSet(schedule);
} else {
changeSetType = COVERAGE;
generateCoverageChangeSet(schedule);
@@ -77,34 +78,72 @@ public class DriftDetector implements Runnable {
schedule.updateShedule();
scheduleQueue.enqueue(schedule);
- driftClient.sendChangeSetToServer(schedule.getResourceId(), driftConfig, changeSetType);
+
+ if (changeSetType == COVERAGE || changes > 0) {
+ driftClient.sendChangeSetToServer(schedule.getResourceId(), driftConfig, changeSetType);
+ }
}
- private void generateDriftChangeSet(DriftDetectionSchedule schedule) throws IOException {
+ private int generateDriftChangeSet(DriftDetectionSchedule schedule) throws IOException {
File basedir = new File(basedir(schedule.getResourceId(), schedule.getDriftConfiguration()));
- ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
+ ChangeSetWriter driftWriter = changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
new Headers(schedule.getDriftConfiguration().getName(), basedir.getAbsolutePath(), DRIFT));
+ ChangeSetWriter coverageWriter = changeSetMgr.getChangeSetWriterForUpdate(schedule.getResourceId(),
+ new Headers(schedule.getDriftConfiguration().getName(), basedir.getAbsolutePath(), COVERAGE));
ChangeSetReader reader = changeSetMgr.getChangeSetReader(schedule.getResourceId(),
schedule.getDriftConfiguration().getName());
+ int changes = 0;
+
for (DirectoryEntry dirEntry : reader) {
DirectoryAnalyzer analyzer = new DirectoryAnalyzer(basedir, dirEntry);
analyzer.run();
- DirectoryEntry newDirEntry = new DirectoryEntry(dirEntry.getDirectory());
- for (FileEntry entry : analyzer.getFilesAdded()) {
- newDirEntry.add(entry);
- }
- for (FileEntry entry : analyzer.getFilesRemoved()) {
- newDirEntry.add(entry);
- }
- for (FileEntry entry : analyzer.getFilesChanged()) {
- newDirEntry.add(entry);
+ if (analyzer.getFilesAdded().size() > 0 || analyzer.getFilesRemoved().size() > 0 ||
+ analyzer.getFilesChanged().size() > 0) {
+ DirectoryEntry driftDirEntry = new DirectoryEntry(dirEntry.getDirectory());
+ DirectoryEntry coverageDirEntry = new DirectoryEntry(dirEntry.getDirectory());
+
+ // add new files to the directory entry
+ for (FileEntry entry : analyzer.getFilesAdded()) {
+ driftDirEntry.add(entry);
+ ++changes;
+ coverageDirEntry.add(entry);
+ }
+
+ // add removed files to the directory entry
+ for (FileEntry entry : analyzer.getFilesRemoved()) {
+ driftDirEntry.add(entry);
+ ++changes;
+ dirEntry.remove(entry);
+ }
+
+ // add changed files to the directory entry
+ for (FileEntry entry : analyzer.getFilesChanged()) {
+ driftDirEntry.add(entry);
+ ++changes;
+ dirEntry.remove(entry);
+ coverageDirEntry.add(entry);
+ }
+
+ // add the remaining unchanged files to the coverage entry
+ for (FileEntry entry : dirEntry) {
+ coverageDirEntry.add(entry);
+ }
+
+ driftWriter.writeDirectoryEntry(driftDirEntry);
+ coverageWriter.writeDirectoryEntry(coverageDirEntry);
+ } else {
+ coverageWriter.writeDirectoryEntry(dirEntry);
}
- writer.writeDirectoryEntry(newDirEntry);
}
- writer.close();
+ driftWriter.close();
+ coverageWriter.close();
+ changeSetMgr.updateChangeSet(schedule.getResourceId(), new Headers(schedule.getDriftConfiguration().getName(),
+ basedir.getAbsolutePath(), COVERAGE));
+
+ return changes;
}
private void generateCoverageChangeSet(DriftDetectionSchedule schedule) throws IOException {
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
index 9b66324..1666646 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
@@ -197,11 +197,21 @@ public class DriftDetectorTest extends DriftTest {
scheduleQueue.enqueue(new DriftDetectionSchedule(resourceId(), config));
detector.run();
- File changeSet = changeSet(config.getName(), DRIFT);
+ File driftChangeSet = changeSet(config.getName(), DRIFT);
- assertTrue(changeSet.exists(), "Expected to find drift change set " + changeSet.getPath());
- assertHeaderEquals(changeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), DRIFT));
- assertChangeSetContainsDirEntry(changeSet, new DirectoryEntry("conf")
+ assertTrue(driftChangeSet.exists(), "Expected to find drift change set " + driftChangeSet.getPath());
+
+ // verify that the drift change set was generated
+ assertHeaderEquals(driftChangeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), DRIFT));
+ assertChangeSetContainsDirEntry(driftChangeSet, new DirectoryEntry("conf")
+ .add(addedFileEntry("server-2.conf", sha256(server2Conf))));
+
+ File coverageChangeSet = changeSet(config.getName(), COVERAGE);
+
+ // verify that the coverage change set was updated
+ assertHeaderEquals(coverageChangeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), COVERAGE));
+ assertChangeSetContainsDirEntry(coverageChangeSet, new DirectoryEntry("conf")
+ .add(addedFileEntry("server-1.conf", sha256(server1Conf)))
.add(addedFileEntry("server-2.conf", sha256(server2Conf))));
}
@@ -236,16 +246,21 @@ public class DriftDetectorTest extends DriftTest {
scheduleQueue.enqueue(new DriftDetectionSchedule(resourceId(), config));
detector.run();
- File changeSet = changeSet(config.getName(), DRIFT);
+ File driftChangeSet = changeSet(config.getName(), DRIFT);
- assertTrue(changeSet.exists(), "Expected to find drift change set " + changeSet.getPath());
- assertHeaderEquals(changeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), DRIFT));
- assertChangeSetContainsDirEntry(changeSet, new DirectoryEntry("conf")
+ // verify that the drift change set was generated
+ assertTrue(driftChangeSet.exists(), "Expected to find drift change set " + driftChangeSet.getPath());
+ assertHeaderEquals(driftChangeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), DRIFT));
+ assertChangeSetContainsDirEntry(driftChangeSet, new DirectoryEntry("conf")
.add(removedFileEntry("server-2.conf", server2ConfHash)));
- }
- //@SuppressWarnings("unchecked")
+ // verify that the coverage change set was updated
+ File coverageChangeSet = changeSet(config.getName(), COVERAGE);
+ assertHeaderEquals(coverageChangeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), COVERAGE));
+ assertChangeSetContainsDirEntry(coverageChangeSet, new DirectoryEntry("conf")
+ .add(addedFileEntry("server-1.conf", sha256(server1Conf))));
+ }
void assertHeaderEquals(File changeSet, Headers expected) throws Exception {
ChangeSetReader reader = new ChangeSetReaderImpl(new BufferedReader(new FileReader(changeSet)));
commit 75983c3b3b86b3b798b209bc001be6399c115311
Author: John Sanda <jsanda(a)redhat.com>
Date: Wed Jul 6 14:16:15 2011 -0400
First, rough cut at generating drift change sets
Some of the code is particularly rough because it is going to be
refactored soon as a new change set file format is introduced. The file
format will be more similar to that used by bundles where files are not
grouped by directories. I am trying not to do any more than I have to in
order to get things working so that I can start the refactoring.
This commit also adds logic in DriftDetector to check whether the
schedule pulled off the queue is ready to be processed. If not, it is
put back on the queue, and DriftDetector simply returns.
This commit does not include logic for updating the coverage change set
when drift is detected.
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
index 9fba34e..c412bcb 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
@@ -28,8 +28,11 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
@Override
public boolean changeSetExists(int resourceId, Headers headers) throws IOException {
- File file = findChangeSet(resourceId, headers.getDriftConfigurationName());
- return file != null && file.exists();
+ File changeSetDir = findChangeSetDir(resourceId, headers.getDriftConfigurationName());
+ if (changeSetDir == null || !changeSetDir.exists()) {
+ return false;
+ }
+ return new File(changeSetDir, "changeset.txt").exists();
}
@Override
@@ -46,7 +49,12 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
@Override
public File findChangeSet(int resourceId, String name, DriftChangeSetCategory type) {
- File changeSetDir = findChangeSetDir(resourceId, name);
+ File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
+ File changeSetDir = new File(resourceDir, name);
+ if (!changeSetDir.exists()) {
+ changeSetDir.mkdirs();
+ }
+
switch (type) {
case COVERAGE:
return new File(changeSetDir, "changeset.txt");
@@ -71,15 +79,19 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
@Override
public ChangeSetWriter getChangeSetWriter(int resourceId, Headers headers) throws IOException {
-// File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
-// File changeSetDir = new File(resourceDir, headers.getDriftConfigurationName());
-//
-// if (!changeSetDir.exists()) {
-// changeSetDir.mkdirs();
-// }
-//
-// return new ChangeSetWriterImpl(new File(changeSetDir, "changeset.txt"), headers);
- File changeSet = findChangeSet(resourceId, headers.getDriftConfigurationName(), headers.getType());
+ File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
+ File changeSetDir = new File(resourceDir, headers.getDriftConfigurationName());
+
+ if (!changeSetDir.exists()) {
+ changeSetDir.mkdirs();
+ }
+
+ File changeSet;
+ if (headers.getType() == COVERAGE) {
+ changeSet = new File(changeSetDir, "changeset.txt");
+ } else {
+ changeSet = new File(changeSetDir, "drift-changeset.txt");
+ }
return new ChangeSetWriterImpl(changeSet, headers);
}
@@ -97,11 +109,4 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
- private String relativePath(File basedir, File file) {
- if (basedir.equals(file)) {
- return basedir.getPath();
- }
- return FilenameUtils.getName(basedir.getAbsolutePath()) + separator +
- file.getAbsolutePath().substring(basedir.getAbsolutePath().length() + 1);
- }
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java
index 140e777..8f4dfa3 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java
@@ -14,6 +14,7 @@ import org.rhq.common.drift.FileEntry;
import org.rhq.core.util.MessageDigestGenerator;
import static org.rhq.common.drift.FileEntry.addedFileEntry;
+import static org.rhq.common.drift.FileEntry.changedFileEntry;
import static org.rhq.common.drift.FileEntry.removedFileEntry;
public class DirectoryAnalyzer {
@@ -49,22 +50,34 @@ public class DirectoryAnalyzer {
public void run() throws IOException {
File dir = new File(basedir, dirEntry.getDirectory());
+ // TODO handle directories
Set<String> files = fileNames(dir.listFiles());
Map<String, FileEntry> fileEntries = createFileEntriesMap();
+ List<String> processed = new ArrayList<String>();
Set<String> dirEntryFileNames = dirEntryFileNames();
for (String file : files) {
if (!fileEntries.containsKey(file)) {
filesAdded.add(addedFileEntry(file, sha256(new File(dir, file))));
+ processed.add(file);
}
}
+ files.removeAll(processed);
for (String file : fileEntries.keySet()) {
if (!files.contains(file)) {
filesRemoved.add(removedFileEntry(file, fileEntries.get(file).getNewSHA()));
}
}
+
+ for (String file : files) {
+ FileEntry entry = fileEntries.get(file);
+ String currentHash = sha256(new File(dir, file));
+ if (!currentHash.equals(entry.getNewSHA())) {
+ filesChanged.add(changedFileEntry(file, entry.getNewSHA(), currentHash));
+ }
+ }
}
private Set<String> fileNames(File... files) {
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftClient.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftClient.java
index aca1a2f..0f4f7cf 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftClient.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftClient.java
@@ -2,6 +2,7 @@ package org.rhq.core.pc.drift;
import java.io.File;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
/**
@@ -10,7 +11,7 @@ import org.rhq.core.domain.drift.DriftConfiguration;
*/
public interface DriftClient {
- void sendChangeSetToServer(int resourceId, DriftConfiguration driftConfiguration);
+ void sendChangeSetToServer(int resourceId, DriftConfiguration driftConfiguration, DriftChangeSetCategory type);
void sendChangeSetContentToServer(int resourceId, String driftConfigurationName, File contentDir);
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetectionSchedule.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetectionSchedule.java
index e7d9534..0184782 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetectionSchedule.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetectionSchedule.java
@@ -24,6 +24,10 @@ public class DriftDetectionSchedule implements Comparable<DriftDetectionSchedule
return driftConfig;
}
+ public long getNextScan() {
+ return nextScan;
+ }
+
public void updateShedule() {
nextScan = System.currentTimeMillis() + (driftConfig.getInterval() * 60 * 1000);
}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
index 653bf6f..e57d763 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
@@ -3,8 +3,6 @@ package org.rhq.core.pc.drift;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
import java.util.Stack;
import org.apache.commons.io.DirectoryWalker;
@@ -16,6 +14,7 @@ import org.rhq.common.drift.ChangeSetWriter;
import org.rhq.common.drift.DirectoryEntry;
import org.rhq.common.drift.FileEntry;
import org.rhq.common.drift.Headers;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
import org.rhq.core.util.MessageDigestGenerator;
@@ -53,17 +52,22 @@ public class DriftDetector implements Runnable {
return;
}
+ if (schedule.getNextScan() > (System.currentTimeMillis() + 100L)) {
+ scheduleQueue.enqueue(schedule);
+ return;
+ }
+
DriftConfiguration driftConfig = schedule.getDriftConfiguration();
int resourceId = schedule.getResourceId();
+ DriftChangeSetCategory changeSetType = null;
try {
- // TODO add logic to determine if there is an existing changeset
- // if there is no previous changeset then we need to generate the initial
- // coverage changeset
if (changeSetMgr.changeSetExists(schedule.getResourceId(), new Headers(driftConfig.getName(),
basedir(resourceId, driftConfig), COVERAGE))) {
+ changeSetType = DRIFT;
generateDriftChangeSet(schedule);
} else {
+ changeSetType = COVERAGE;
generateCoverageChangeSet(schedule);
}
} catch (IOException e) {
@@ -73,23 +77,34 @@ public class DriftDetector implements Runnable {
schedule.updateShedule();
scheduleQueue.enqueue(schedule);
- driftClient.sendChangeSetToServer(schedule.getResourceId(), driftConfig);
+ driftClient.sendChangeSetToServer(schedule.getResourceId(), driftConfig, changeSetType);
}
private void generateDriftChangeSet(DriftDetectionSchedule schedule) throws IOException {
-// File basedir = new File(basedir(schedule.getResourceId(), schedule.getDriftConfiguration()));
-//
-// ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
-// new Headers(schedule.getDriftConfiguration().getName(), basedir.getAbsolutePath(), DRIFT));
-// ChangeSetReader reader = changeSetMgr.getChangeSetReader(schedule.getResourceId(),
-// schedule.getDriftConfiguration().getName());
-//
-// for (DirectoryEntry dirEntry : reader) {
-// File dir = new File(basedir, dirEntry.getDirectory());
-// if (dir.list().length > dirEntry.getNumberOfFiles()) {
-//
-// }
-// }
+ File basedir = new File(basedir(schedule.getResourceId(), schedule.getDriftConfiguration()));
+
+ ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
+ new Headers(schedule.getDriftConfiguration().getName(), basedir.getAbsolutePath(), DRIFT));
+ ChangeSetReader reader = changeSetMgr.getChangeSetReader(schedule.getResourceId(),
+ schedule.getDriftConfiguration().getName());
+
+ for (DirectoryEntry dirEntry : reader) {
+ DirectoryAnalyzer analyzer = new DirectoryAnalyzer(basedir, dirEntry);
+ analyzer.run();
+
+ DirectoryEntry newDirEntry = new DirectoryEntry(dirEntry.getDirectory());
+ for (FileEntry entry : analyzer.getFilesAdded()) {
+ newDirEntry.add(entry);
+ }
+ for (FileEntry entry : analyzer.getFilesRemoved()) {
+ newDirEntry.add(entry);
+ }
+ for (FileEntry entry : analyzer.getFilesChanged()) {
+ newDirEntry.add(entry);
+ }
+ writer.writeDirectoryEntry(newDirEntry);
+ }
+ writer.close();
}
private void generateCoverageChangeSet(DriftDetectionSchedule schedule) throws IOException {
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 be93ed5..8bd9da1 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
@@ -20,6 +20,7 @@ import org.apache.commons.logging.LogFactory;
import org.rhq.common.drift.Headers;
import org.rhq.core.clientapi.agent.drift.DriftAgentService;
import org.rhq.core.clientapi.server.drift.DriftServerService;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.domain.resource.Resource;
@@ -83,9 +84,10 @@ public class DriftManager extends AgentService implements DriftAgentService, Dri
}
@Override
- public void sendChangeSetToServer(int resourceId, DriftConfiguration driftConfiguration) {
+ public void sendChangeSetToServer(int resourceId, DriftConfiguration driftConfiguration,
+ DriftChangeSetCategory type) {
try {
- File changeSetFile = changeSetMgr.findChangeSet(resourceId, driftConfiguration.getName());
+ File changeSetFile = changeSetMgr.findChangeSet(resourceId, driftConfiguration.getName(), type);
if (changeSetFile == null) {
log
.warn("changeset[resourceId: " + resourceId + ", driftConfiguration: "
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java
index df05a15..8f9588f 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java
@@ -1,22 +1,17 @@
package org.rhq.core.pc.drift;
import java.io.File;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Set;
-import java.util.TreeSet;
import org.testng.annotations.Test;
import org.rhq.common.drift.DirectoryEntry;
-import org.rhq.common.drift.FileEntry;
import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.test.AssertUtils;
import static java.util.Arrays.asList;
-import static java.util.Collections.addAll;
import static org.apache.commons.io.FileUtils.touch;
+import static org.apache.commons.io.FileUtils.writeLines;
import static org.rhq.common.drift.FileEntry.addedFileEntry;
+import static org.rhq.common.drift.FileEntry.changedFileEntry;
import static org.rhq.common.drift.FileEntry.removedFileEntry;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
import static org.rhq.test.AssertUtils.assertCollectionMatchesNoOrder;
@@ -91,4 +86,36 @@ public class DirectoryAnalyzerTest extends DriftTest {
assertCollectionMatchesNoOrder(asList(removedFileEntry("server-2.conf", server2ConfHash)),
analyzer.getFilesRemoved(), "Failed to detect removed file.");
}
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void detectChangedFile() throws Exception {
+ DriftConfiguration config = driftConfiguration("changed-files-test", resourceDir.getAbsolutePath());
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = new File(confDir, "server-1.conf");
+ touch(server1Conf);
+
+ String server1ConfHash = sha256(server1Conf);
+ File changeSetDir = changeSetDir(config.getName());
+
+ // generate the initial, coverage changes set
+ writeChangeSet(changeSetDir,
+ config.getName(),
+ resourceDir.getAbsolutePath(),
+ COVERAGE.code(),
+ "conf 1",
+ sha256(server1Conf) + " 0 server-1.conf A",
+ ""
+ );
+
+ // create some drift
+ writeLines(server1Conf, asList("This is a test", "Testing a changed file"));
+
+ DirectoryAnalyzer analyzer = new DirectoryAnalyzer(resourceDir, new DirectoryEntry("conf")
+ .add(addedFileEntry("server-1.conf", server1ConfHash)));
+ analyzer.run();
+
+ assertCollectionMatchesNoOrder(asList(changedFileEntry("server-1.conf", server1ConfHash, sha256(server1Conf))),
+ analyzer.getFilesChanged(), "Failed to detect changed files.");
+ }
}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftClientTestStub.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftClientTestStub.java
index 013aaef..758fda8 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftClientTestStub.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftClientTestStub.java
@@ -2,6 +2,7 @@ package org.rhq.core.pc.drift;
import java.io.File;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
class DriftClientTestStub implements DriftClient {
@@ -9,7 +10,9 @@ class DriftClientTestStub implements DriftClient {
private File basedir;
@Override
- public void sendChangeSetToServer(int resourceId, DriftConfiguration driftConfiguration) {
+ public void sendChangeSetToServer(int resourceId, DriftConfiguration driftConfiguration,
+ DriftChangeSetCategory type) {
+
}
@Override
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
index dca3dc6..9b66324 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
@@ -17,11 +17,13 @@ import org.rhq.common.drift.DirectoryEntry;
import org.rhq.common.drift.FileEntry;
import org.rhq.common.drift.Headers;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
import org.rhq.test.AssertUtils;
import static org.apache.commons.io.FileUtils.touch;
import static org.rhq.common.drift.FileEntry.addedFileEntry;
+import static org.rhq.common.drift.FileEntry.removedFileEntry;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.DRIFT;
import static org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext.fileSystem;
@@ -196,9 +198,55 @@ public class DriftDetectorTest extends DriftTest {
detector.run();
File changeSet = changeSet(config.getName(), DRIFT);
+
assertTrue(changeSet.exists(), "Expected to find drift change set " + changeSet.getPath());
+ assertHeaderEquals(changeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), DRIFT));
+ assertChangeSetContainsDirEntry(changeSet, new DirectoryEntry("conf")
+ .add(addedFileEntry("server-2.conf", sha256(server2Conf))));
}
+ @SuppressWarnings("unchecked")
+ @Test
+ public void includeRemovedFileInDriftChangeSet() throws Exception {
+ DriftConfiguration config = driftConfiguration("file-removed-drift-test", resourceDir.getAbsolutePath());
+
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = new File(confDir, "server-1.conf");
+ touch(server1Conf);
+ File server2Conf = new File(confDir, "server-2.conf");
+ touch(server2Conf);
+
+ String server2ConfHash = sha256(server2Conf);
+ File changeSetDir = changeSetDir(config.getName());
+
+ // generate the initial, coverage change set
+ writeChangeSet(changeSetDir,
+ config.getName(),
+ resourceDir.getAbsolutePath(),
+ COVERAGE.code(),
+ "conf 2",
+ sha256(server1Conf) + " 0 server-1.conf A",
+ server2ConfHash + " 0 server-2.conf A",
+ ""
+ );
+
+ // create some drift
+ server2Conf.delete();
+
+ scheduleQueue.enqueue(new DriftDetectionSchedule(resourceId(), config));
+ detector.run();
+
+ File changeSet = changeSet(config.getName(), DRIFT);
+
+ assertTrue(changeSet.exists(), "Expected to find drift change set " + changeSet.getPath());
+ assertHeaderEquals(changeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), DRIFT));
+ assertChangeSetContainsDirEntry(changeSet, new DirectoryEntry("conf")
+ .add(removedFileEntry("server-2.conf", server2ConfHash)));
+ }
+
+ //@SuppressWarnings("unchecked")
+
+
void assertHeaderEquals(File changeSet, Headers expected) throws Exception {
ChangeSetReader reader = new ChangeSetReaderImpl(new BufferedReader(new FileReader(changeSet)));
Headers actual = reader.getHeaders();
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java
index b555fef..97bfa45 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java
@@ -171,8 +171,8 @@ public class DriftTest {
}
protected void writeChangeSet(File changeSetDir, String... changeSet) throws Exception {
- BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(changeSetDir,
- "changeset.txt")));
+ File changeSetFile = new File(changeSetDir, "changeset.txt");
+ BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(changeSetFile));
writeLines(asList(changeSet), "\n", stream);
stream.close();
}
12 years, 11 months
[rhq] Branch 'drift' - modules/enterprise
by mazz
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ContentMetadataManagerBean.java | 12 +
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java | 61 ++++++++++
modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/remove_bundle_drift_config_v1.xml | 20 +++
modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/remove_bundle_drift_config_v2.xml | 7 +
4 files changed, 95 insertions(+), 5 deletions(-)
New commits:
commit 184ac150b3357c133783e09204fdcfcc72cb591e
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Wed Jul 6 15:35:15 2011 -0400
more unit tests to confirm when a type is removed or cleaned that both bundle and drift configs are removed
this fixes a bug the tests found with bundle config removal
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ContentMetadataManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ContentMetadataManagerBean.java
index 1831a3e..6fc58d6 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ContentMetadataManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ContentMetadataManagerBean.java
@@ -75,9 +75,8 @@ public class ContentMetadataManagerBean implements ContentMetadataManagerLocal {
// set the bundle configuration if the new type is a potential bundle deployment target
ResourceTypeBundleConfiguration newBundleConfiguration = newType.getResourceTypeBundleConfiguration();
+ ResourceTypeBundleConfiguration existingBundleConfiguration = existingType.getResourceTypeBundleConfiguration();
if (newBundleConfiguration != null) {
- ResourceTypeBundleConfiguration existingBundleConfiguration = existingType
- .getResourceTypeBundleConfiguration();
if (existingBundleConfiguration == null) {
// the new type has now become a bundle target where the old type was not
existingType.setResourceTypeBundleConfiguration(newBundleConfiguration);
@@ -90,10 +89,13 @@ public class ContentMetadataManagerBean implements ContentMetadataManagerLocal {
}
}
} else {
- if (log.isDebugEnabled()) {
- log.debug("Removing bundle configuration");
+ if (existingBundleConfiguration != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Removing bundle configuration");
+ }
+ entityMgr.remove(existingBundleConfiguration.getBundleConfiguration());
+ existingType.setResourceTypeBundleConfiguration(null);
}
- existingType.setResourceTypeBundleConfiguration(null);
}
// Easy case: If there are no package definitions in the new type, null out any in the existing and return
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
index e2fdd96..c4268df 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
@@ -5,6 +5,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
+import javax.persistence.Query;
+
import org.apache.commons.beanutils.MethodUtils;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.WordUtils;
@@ -19,6 +21,7 @@ import org.rhq.core.domain.bundle.BundleType;
import org.rhq.core.domain.bundle.ResourceTypeBundleConfiguration;
import org.rhq.core.domain.bundle.ResourceTypeBundleConfiguration.BundleDestinationBaseDirectory;
import org.rhq.core.domain.bundle.ResourceTypeBundleConfiguration.BundleDestinationBaseDirectory.Context;
+import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
import org.rhq.core.domain.content.PackageType;
import org.rhq.core.domain.content.Package;
@@ -38,6 +41,7 @@ import org.rhq.core.domain.shared.ResourceBuilder;
import org.rhq.enterprise.server.alert.AlertTemplateManagerLocal;
import org.rhq.enterprise.server.auth.SubjectManagerLocal;
import org.rhq.enterprise.server.bundle.BundleManagerLocal;
+import org.rhq.enterprise.server.configuration.ConfigurationManagerLocal;
import org.rhq.enterprise.server.content.ContentManagerLocal;
import org.rhq.enterprise.server.operation.OperationManagerLocal;
import org.rhq.enterprise.server.resource.ResourceManagerLocal;
@@ -49,6 +53,63 @@ import static java.util.Arrays.asList;
public class ResourceMetadataManagerBeanTest extends MetadataBeanTest {
+ @Test(groups = { "plugin.metadata", "NewPlugin" })
+ public void testRemovalOfObsoleteBundleAndDriftConfig() throws Exception {
+ // create the initial type that has bundle and drift configs
+ createPlugin("test-plugin.jar", "1.0", "remove_bundle_drift_config_v1.xml");
+
+ // make sure the drift config was persisted, and remember the type
+ ResourceType type1 = assertResourceTypeAssociationEquals(
+ "ServerWithBundleAndDriftConfig",
+ "TestPlugin",
+ "driftConfigurationTemplates",
+ asList("drift1"));
+
+ // sanity check, make sure our queries work and that we did persist these things
+ Query qTemplate;
+ Query qConfig;
+ String qTemplateString = "select ct from ConfigurationTemplate ct where ct.id = :id";
+ String qConfigString = "select c from Configuration c where c.id = :id";
+ ConfigurationTemplate driftTemplate = type1.getDriftConfigurationTemplates().iterator().next();
+ Configuration bundleConfig = type1.getResourceTypeBundleConfiguration().getBundleConfiguration();
+ Configuration driftConfig = driftTemplate.getConfiguration();
+
+ getTransactionManager().begin();
+ try {
+ qTemplate = getEntityManager().createQuery(qTemplateString).setParameter("id", driftTemplate.getId());
+ qConfig = getEntityManager().createQuery(qConfigString).setParameter("id", driftConfig.getId());
+ assertEquals("drift template didn't get persisted", 1, qTemplate.getResultList().size());
+ assertEquals("drift template config didn't get persisted", 1, qConfig.getResultList().size());
+
+ qConfig.setParameter("id", bundleConfig.getId());
+ assertEquals("bundle config didn't get persisted", 1, qConfig.getResultList().size());
+ } finally {
+ getTransactionManager().commit();
+ }
+
+ // make sure the bundle config was also persisted
+ // NOTE: WHY DOES THIS WORK? I DIDN'T ASK TO FETCH IT AND IT IS MARKED AS LAZY LOAD
+ assertNotNull(type1.getResourceTypeBundleConfiguration());
+ assertEquals("destdir1",
+ type1.getResourceTypeBundleConfiguration().getBundleDestinationBaseDirectories().iterator().next().getName());
+
+ // upgrade the type which removes the bundle config and drift config
+ createPlugin("test-plugin.jar", "2.0", "remove_bundle_drift_config_v2.xml");
+
+ getTransactionManager().begin();
+ try {
+ qTemplate = getEntityManager().createQuery(qTemplateString).setParameter("id", driftTemplate.getId());
+ qConfig = getEntityManager().createQuery(qConfigString).setParameter("id", driftConfig.getId());
+ assertEquals("drift template didn't get purged", 0, qTemplate.getResultList().size());
+ assertEquals("drift template config didn't get purged", 0, qConfig.getResultList().size());
+
+ qConfig.setParameter("id", bundleConfig.getId());
+ assertEquals("bundle config didn't get purged", 0, qConfig.getResultList().size());
+ } finally {
+ getTransactionManager().commit();
+ }
+ }
+
@Test(groups = {"plugin.metadata", "NewPlugin"})
public void registerPluginWithDuplicateDriftConfigurations() {
try {
diff --git a/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/remove_bundle_drift_config_v1.xml b/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/remove_bundle_drift_config_v1.xml
new file mode 100644
index 0000000..7ed29dd
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/remove_bundle_drift_config_v1.xml
@@ -0,0 +1,20 @@
+<plugin name="TestPlugin" displayName="Test Plugin" 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="ServerWithBundleAndDriftConfig">
+ <drift-configuration name="drift1">
+ <basedir>
+ <value-context>fileSystem</value-context>
+ <value-name>/dirA</value-name>
+ </basedir>
+ </drift-configuration>
+
+ <bundle-target>
+ <destination-base-dir name="destdir1">
+ <value-context>fileSystem</value-context>
+ <value-name>/dirB</value-name>
+ </destination-base-dir>
+ </bundle-target>
+ </server>
+</plugin>
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/remove_bundle_drift_config_v2.xml b/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/remove_bundle_drift_config_v2.xml
new file mode 100644
index 0000000..c92919d
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/remove_bundle_drift_config_v2.xml
@@ -0,0 +1,7 @@
+<plugin name="TestPlugin" displayName="Test Plugin" 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="ServerWithBundleAndDriftConfig">
+ </server>
+</plugin>
\ No newline at end of file
12 years, 11 months
[rhq] modules/enterprise
by ips
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java | 156 ++++++----
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties | 18 -
2 files changed, 113 insertions(+), 61 deletions(-)
New commits:
commit 2ffae275d74d321668ad36009bdad223cea78cb5
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Wed Jul 6 13:20:56 2011 -0400
[BZ 718335] add Select All and Deselect All buttons to autodiscovery view (https://bugzilla.redhat.com/show_bug.cgi?id=718335); right-align inventory status filter in footer, along with Select All, Deselect All, and Refresh buttons
diff --git a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
index da3768c..e504f2a 100644
--- a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
+++ b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/discovery/ResourceAutodiscoveryView.java
@@ -1,6 +1,6 @@
/*
* RHQ Management Platform
- * Copyright (C) 2005-2010 Red Hat, Inc.
+ * Copyright (C) 2005-2011 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
@@ -51,6 +51,7 @@ import com.smartgwt.client.widgets.tree.TreeNode;
import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.RefreshableView;
import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.gwt.ResourceGWTServiceAsync;
@@ -64,7 +65,7 @@ import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
/**
* @author Greg Hinkle
*/
-public class ResourceAutodiscoveryView extends LocatableVLayout {
+public class ResourceAutodiscoveryView extends LocatableVLayout implements RefreshableView {
private static final String TITLE = MSG.view_autoDiscoveryQ_title();
private static final String HEADER_ICON = "global/AutoDiscovery_24.png";
@@ -73,6 +74,8 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
private TreeGrid treeGrid;
private ToolStrip footer;
private DataSource dataSource;
+ // This allows the selection handler to ignore selection changes initiated by us, as opposed to by the user.
+ private boolean selectionChangedHandlerDisabled;
private ResourceGWTServiceAsync resourceService = GWTServiceLookup.getResourceService(1000000);
@@ -167,6 +170,10 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
disableButtons(importButton, ignoreButton, unignoreButton);
+ footer.addMember(new LayoutSpacer());
+
+ // The remaining footer items (status filter, (de)select all buttons, and refresh button) will be right-aligned.
+
DynamicForm form = new LocatableDynamicForm(this.extendLocatorId("Status"));
final SelectItem statusSelectItem = new SelectItem("status", MSG.view_autoDiscoveryQ_showStatus());
statusSelectItem.setValueMap(AutodiscoveryQueueDataSource.NEW, AutodiscoveryQueueDataSource.IGNORED,
@@ -182,7 +189,13 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
});
footer.addMember(form);
- footer.addMember(new LayoutSpacer());
+ final IButton selectAllButton = new LocatableIButton(this.extendLocatorId("SelectAll"),
+ MSG.view_autoDiscoveryQ_selectAll());
+ footer.addMember(selectAllButton);
+ final IButton deselectAllButton = new LocatableIButton(this.extendLocatorId("DeselectAll"),
+ MSG.view_autoDiscoveryQ_deselectAll());
+ deselectAllButton.setDisabled(true);
+ footer.addMember(deselectAllButton);
IButton refreshButton = new LocatableIButton(extendLocatorId("Refresh"), MSG.common_button_refresh());
refreshButton.addClickHandler(new ClickHandler() {
@@ -193,9 +206,6 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
footer.addMember(refreshButton);
treeGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
- // use this to ignore selection changes we initiate from within this handler
- private boolean selectionChangedHandlerDisabled = false;
-
public void onSelectionChanged(SelectionEvent selectionEvent) {
if (selectionChangedHandlerDisabled || selectionEvent.isRightButtonDown()) {
return;
@@ -218,7 +228,8 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
}
}
}
- updateButtonEnablement(importButton, ignoreButton, unignoreButton);
+ updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
+ unignoreButton);
selectionChangedHandlerDisabled = false;
}
});
@@ -228,10 +239,11 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
treeGrid.deselectRecord(child);
}
}
- // the immediate redraw below should not be necessary but without it the deselected
+ // the immediate redraw below should not be necessary, but without it the deselected
// platform checkbox remained checked.
treeGrid.redraw();
- updateButtonEnablement(importButton, ignoreButton, unignoreButton);
+ updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
+ unignoreButton);
selectionChangedHandlerDisabled = false;
}
} else {
@@ -240,52 +252,51 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
treeGrid.selectRecord(parentNode);
}
}
- updateButtonEnablement(importButton, ignoreButton, unignoreButton);
+ updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
+ unignoreButton);
selectionChangedHandlerDisabled = false;
}
}
- private void updateButtonEnablement(IButton importButton, IButton ignoreButton, IButton unignoreButton) {
- if (treeGrid.getSelection().length == 0) {
- importButton.setDisabled(true);
- ignoreButton.setDisabled(true);
- unignoreButton.setDisabled(true);
- return;
- }
-
- boolean importOk = false;
- boolean ignoreOk = false;
- boolean unignoreOk = false;
-
- for (ListGridRecord listGridRecord : treeGrid.getSelection()) {
- TreeNode node = (TreeNode) listGridRecord;
- String status = node.getAttributeAsString("status");
- TreeNode parentNode = treeGrid.getTree().getParent(node);
- boolean isPlatform = treeGrid.getTree().isRoot(parentNode);
-
- importOk |= InventoryStatus.NEW.name().equals(status);
- unignoreOk |= InventoryStatus.IGNORED.name().equals(status);
+ });
- if (!isPlatform) {
- String parentStatus = parentNode.getAttributeAsString("status");
- if (InventoryStatus.COMMITTED.name().equals(parentStatus)) {
- ignoreOk |= InventoryStatus.NEW.name().equals(status);
+ selectAllButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ SC.ask(MSG.view_autoDiscoveryQ_confirmSelectAll(), new BooleanCallback() {
+ public void execute(Boolean selectChildServers) {
+ selectionChangedHandlerDisabled = true;
+ if (selectChildServers) {
+ treeGrid.selectAllRecords();
+ } else {
+ // Select only the platforms.
+ TreeNode rootNode = treeGrid.getTree().getRoot();
+ TreeNode[] platformNodes = treeGrid.getTree().getChildren(rootNode);
+ for (TreeNode platformNode : platformNodes) {
+ treeGrid.selectRecord(platformNode);
+ }
}
+ selectionChangedHandlerDisabled = false;
+ updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton,
+ unignoreButton);
}
- }
+ });
+ }
+ });
- importButton.setDisabled(!importOk || unignoreOk);
- ignoreButton.setDisabled(!ignoreOk || unignoreOk);
- unignoreButton.setDisabled(!unignoreOk || importOk || ignoreOk);
- markForRedraw();
+ deselectAllButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ selectionChangedHandlerDisabled = true;
+ treeGrid.deselectAllRecords();
+ selectionChangedHandlerDisabled = false;
+ updateButtonEnablement(selectAllButton, deselectAllButton, importButton, ignoreButton, unignoreButton);
}
});
importButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
- disableButtons(importButton, ignoreButton, unignoreButton);
+ disableButtons(selectAllButton, deselectAllButton, importButton, ignoreButton, unignoreButton);
CoreGUI.getMessageCenter().notify(
- new Message("Importing the selected Resources...", Message.Severity.Info, EnumSet
+ new Message(MSG.view_autoDiscoveryQ_importInProgress(), Message.Severity.Info, EnumSet
.of(Message.Option.Transient)));
resourceService.importResources(getSelectedIds(), new AsyncCallback<Void>() {
@@ -304,9 +315,9 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
ignoreButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
- disableButtons(importButton, ignoreButton, unignoreButton);
+ disableButtons(selectAllButton, deselectAllButton, importButton, ignoreButton, unignoreButton);
CoreGUI.getMessageCenter().notify(
- new Message("Ignoring the selected Resources...", Message.Severity.Info, EnumSet
+ new Message(MSG.view_autoDiscoveryQ_ignoreInProgress(), Message.Severity.Info, EnumSet
.of(Message.Option.Transient)));
resourceService.ignoreResources(getSelectedIds(), new AsyncCallback<Void>() {
@@ -325,9 +336,9 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
unignoreButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent clickEvent) {
- disableButtons(importButton, ignoreButton, unignoreButton);
+ disableButtons(selectAllButton, deselectAllButton, importButton, ignoreButton, unignoreButton);
CoreGUI.getMessageCenter().notify(
- new Message("Unignoring the selected Resources...", Message.Severity.Info, EnumSet
+ new Message(MSG.view_autoDiscoveryQ_unignoreInProgress(), Message.Severity.Info, EnumSet
.of(Message.Option.Transient)));
resourceService.unignoreResources(getSelectedIds(), new AsyncCallback<Void>() {
@@ -346,6 +357,48 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
}
+ private void updateButtonEnablement(IButton selectAllButton, IButton deselectAllButton,
+ IButton importButton, IButton ignoreButton, IButton unignoreButton) {
+ if (treeGrid.getSelection().length == 0) {
+ selectAllButton.setDisabled(false);
+ deselectAllButton.setDisabled(true);
+ importButton.setDisabled(true);
+ ignoreButton.setDisabled(true);
+ unignoreButton.setDisabled(true);
+ return;
+ }
+
+ boolean allSelected = (treeGrid.getSelection().length == treeGrid.getRecords().length);
+ selectAllButton.setDisabled(allSelected);
+ deselectAllButton.setDisabled(false);
+
+ boolean importOk = false;
+ boolean ignoreOk = false;
+ boolean unignoreOk = false;
+
+ for (ListGridRecord listGridRecord : treeGrid.getSelection()) {
+ TreeNode node = (TreeNode) listGridRecord;
+ String status = node.getAttributeAsString("status");
+ TreeNode parentNode = treeGrid.getTree().getParent(node);
+ boolean isPlatform = treeGrid.getTree().isRoot(parentNode);
+
+ importOk |= InventoryStatus.NEW.name().equals(status);
+ unignoreOk |= InventoryStatus.IGNORED.name().equals(status);
+
+ if (!isPlatform) {
+ String parentStatus = parentNode.getAttributeAsString("status");
+ if (InventoryStatus.COMMITTED.name().equals(parentStatus)) {
+ ignoreOk |= InventoryStatus.NEW.name().equals(status);
+ }
+ }
+ }
+
+ importButton.setDisabled(!importOk || unignoreOk);
+ ignoreButton.setDisabled(!ignoreOk || unignoreOk);
+ unignoreButton.setDisabled(!unignoreOk || importOk || ignoreOk);
+ markForRedraw();
+ }
+
private void disableButtons(IButton... buttons) {
for (IButton button : buttons) {
button.setDisabled(true);
@@ -363,17 +416,10 @@ public class ResourceAutodiscoveryView extends LocatableVLayout {
return TableUtility.getIds(selected);
}
- /** Custom refresh operation as we cannot directly extend Table because it
- * contains a TreeGrid, not a ListGrid.
+ /**
+ * Custom refresh operation, as we cannot extend Table because we use a TreeGrid, not a ListGrid.
*/
- @Override
- public void redraw() {
- super.redraw();
- // Now reload the table data.
- refresh();
- }
-
- private void refresh() {
+ public void refresh() {
this.treeGrid.invalidateCache();
this.treeGrid.markForRedraw();
}
diff --git a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
index ddd0d3e..f7f6f75 100644
--- a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
+++ b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
@@ -831,29 +831,35 @@ view_alerts_table_title_group = Group Alert History
view_alerts_table_title_resource = Resource Alert History
view_autoDiscoveryQ_committed = Committed
view_autoDiscoveryQ_confirmSelect = Also select the platform children?
+view_autoDiscoveryQ_confirmSelectAll = Also select the children of each platform?
view_autoDiscoveryQ_deleted = Deleted
+view_autoDiscoveryQ_deselectAll = Deselect All
view_autoDiscoveryQ_field_discoveryTime = Discovery Time
view_autoDiscoveryQ_field_inventoryStatus = Inventory Status
view_autoDiscoveryQ_field_key = Resource Key
view_autoDiscoveryQ_field_name = Resource Name
view_autoDiscoveryQ_field_parentId = Parent ID
view_autoDiscoveryQ_ignore = Ignore
-view_autoDiscoveryQ_ignoreFailure = Failed to ignore resources
-view_autoDiscoveryQ_ignoreSuccessful = You have successfully ignored the selected resources.
+view_autoDiscoveryQ_ignoreFailure = Failed to ignore Resources
+view_autoDiscoveryQ_ignoreInProgress = Ignoring the selected Resources...
+view_autoDiscoveryQ_ignoreSuccessful = You have successfully ignored the selected Resources.
view_autoDiscoveryQ_ignored = Ignored
view_autoDiscoveryQ_import = Import
-view_autoDiscoveryQ_importFailure = Failed to import resources
-view_autoDiscoveryQ_importSuccessful = You have successfully imported the selected resources.
+view_autoDiscoveryQ_importFailure = Failed to import Resources
+view_autoDiscoveryQ_importInProgress = Importing the selected Resources...
+view_autoDiscoveryQ_importSuccessful = You have successfully imported the selected Resources.
view_autoDiscoveryQ_loadFailure = Failed to load the inventory discovery queue
view_autoDiscoveryQ_new = New
view_autoDiscoveryQ_newAndIgnored = New and Ignored
view_autoDiscoveryQ_noItems = No items to show
view_autoDiscoveryQ_noperm = (You are not authorized to view the auto-discovery queue)
+view_autoDiscoveryQ_selectAll = Select All
view_autoDiscoveryQ_showStatus = Show
view_autoDiscoveryQ_title = Autodiscovery Queue
view_autoDiscoveryQ_unignore = Unignore
-view_autoDiscoveryQ_unignoreFailure = Failed to unignore resources
-view_autoDiscoveryQ_unignoreSuccessful = You have successfully unignored the selected resources.
+view_autoDiscoveryQ_unignoreFailure = Failed to unignore Resources
+view_autoDiscoveryQ_unignoreInProgress = Unignoring the selected Resources...
+view_autoDiscoveryQ_unignoreSuccessful = You have successfully unignored the selected Resources.
view_autoDiscoveryQ_uninventoried = Uninventoried
view_bundleVersion_loadFailure = Failed to load bundle version data
view_bundle_bundle = Bundle
12 years, 11 months
[rhq] Branch 'as7plugin' - 2 commits - modules/plugins
by Heiko W. Rupp
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java | 39 +-
modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java | 66 +++
modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml | 51 ++
modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/DatasourceDeployTest.java | 180 ++++++----
4 files changed, 238 insertions(+), 98 deletions(-)
New commits:
commit 2e4e8dadb30d546fa2b57c61e77a1923721af084
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Jul 6 18:08:22 2011 +0200
Allow to deploy xa-data-sources.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java
index ad6914f..e969644 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java
@@ -1,11 +1,14 @@
package org.rhq.modules.plugins.jbossas7;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.modules.plugins.jbossas7.json.Operation;
@@ -47,25 +50,44 @@ public class DatasourceComponent extends BaseComponent implements OperationFacet
}
}
else if (operationName.equals("addDatasource")) {
- String driver = parameters.getSimpleValue("driver", NOTSET);
- String jndiName = parameters.getSimpleValue("jndi-name", NOTSET);
- String poolName = parameters.getSimpleValue("pool-name", NOTSET);
- String connectionUrl = parameters.getSimpleValue("connection-url",NOTSET);
- String userName = parameters.getSimpleValue("user-name","");
- String password = parameters.getSimpleValue("password","");
String name = parameters.getSimpleValue("name",NOTSET);
List<PROPERTY_VALUE> address = pathToAddress(getPath());
address.add(new PROPERTY_VALUE("data-source",name));
Operation op = new Operation("add",address);
- op.addAdditionalProperty("driver-name",driver);
- op.addAdditionalProperty("jndi-name",jndiName);
- op.addAdditionalProperty("pool-name",poolName);
- op.addAdditionalProperty("connection-url",connectionUrl);
- if (userName!=null && !userName.isEmpty())
- op.addAdditionalProperty("user-name",userName);
- if (password!=null && !password.isEmpty())
- op.addAdditionalProperty("password",password);
+ addRequiredToOp(op,parameters,"driver-name");
+ addRequiredToOp(op,parameters,"jndi-name");
+ addRequiredToOp(op, parameters, "pool-name");
+ addRequiredToOp(op, parameters, "connection-url");
+ addOptionalToOp(op, parameters, "user-name");
+ addOptionalToOp(op,parameters,"password");
+
+ Result res = connection.execute(op);
+ if (res.isSuccess()) {
+ result.setSimpleResult("Success");
+ }
+ else {
+ result.setErrorMessage(res.getFailureDescription().toString());
+ }
+
+ }
+ else if (operationName.equals("addXADatasource")) {
+ String name = parameters.getSimpleValue("name",NOTSET);
+
+ List<PROPERTY_VALUE> address = pathToAddress(getPath());
+ address.add(new PROPERTY_VALUE("xa-data-source",name));
+ Operation op = new Operation("add",address);
+ addRequiredToOp(op,parameters,"driver-name");
+ addRequiredToOp(op,parameters,"jndi-name");
+ addRequiredToOp(op,parameters,"pool-name");
+ addRequiredToOp(op,parameters,"connection-url");
+ addOptionalToOp(op,parameters,"user-name");
+ addOptionalToOp(op,parameters,"password");
+ addRequiredToOp(op,parameters,"xa-data-source-class");
+
+ Map<String,Object> props = new HashMap<String, Object>(); // TODO
+ props.put("_foo","_bar"); // TODO AS7-1209
+ op.addAdditionalProperty("xa-data-source-properties",props);
Result res = connection.execute(op);
if (res.isSuccess()) {
@@ -83,7 +105,25 @@ public class DatasourceComponent extends BaseComponent implements OperationFacet
return result;
}
- void addAdditionalToOp(Operation op, Configuration parameters, String property, boolean optional) {
+ void addAdditionalToOp(Operation op, Configuration parameters, String property, boolean optional) {
+
+ PropertySimple ps = parameters.getSimple(property);
+ if (ps==null) {
+ if (!optional)
+ throw new IllegalArgumentException("Property " + property + " not found for required parameter");
+ }
+ else {
+ String tmp = ps.getStringValue();
+ op.addAdditionalProperty(property,tmp);
+ }
+ }
+
+
+ void addRequiredToOp(Operation op, Configuration parameters, String property) {
+ addAdditionalToOp(op,parameters,property,false);
+ }
+ void addOptionalToOp(Operation op, Configuration parameters, String property) {
+ addAdditionalToOp(op,parameters,property,true);
}
}
diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
index 248367a..9aac735 100644
--- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
@@ -738,22 +738,38 @@
<operation name="addDatasource" description="Add a datasource to the system. Needs a jdbc-driver that was already added to the domain and promoted to the respective server-group(s) (if in domain mode).">
<parameters>
<c:simple-property name="name" required="true" description="Name of the datasource"/>
- <c:simple-property name="driver" required="true">
+ <c:simple-property name="driver-name" required="true">
<c:option-source target="resource" expression="type=DomainDeployment"/>
</c:simple-property>
-<!--
- <c:simple-property name="server-group" required="true" >
- <c:property-options>
- <c:option value="_all" name="All"/>
- </c:property-options>
- <c:option-source target="resource" expression="type=ServerGroup"/>
- </c:simple-property>
--->
<c:simple-property name="jndi-name" description="JNDI-Name of the Datasource" required="true"/>
+ <c:simple-property name="connection-url" description="URL for the connection to the database" required="true"/>
<c:simple-property name="pool-name" description="Name of the pool" required="true"/>
+ <c:simple-property name="user-name" description="User name for DB-connections" required="false" />
+ <c:simple-property name="password" description="Password" type="password" required="false"/>
+ </parameters>
+ <results>
+ <c:simple-property name="operationResult"/>
+ </results>
+ </operation>
+
+ <operation name="addXADatasource" description="Add a XA datasource to the system. Needs a jdbc-driver that was already added to the domain and promoted to the respective server-group(s) (if in domain mode).">
+ <parameters>
+ <c:simple-property name="name" required="true" description="Name of the datasource"/>
+ <c:simple-property name="driver-name" required="true">
+ <c:option-source target="resource" expression="type=DomainDeployment"/>
+ </c:simple-property>
+ <c:simple-property name="xa-data-source-class" required="true" description="xa-data-source-class"/>
+ <c:simple-property name="jndi-name" description="JNDI-Name of the Datasource" required="true"/>
<c:simple-property name="connection-url" description="URL for the connection to the database" required="true"/>
+ <c:simple-property name="pool-name" description="Name of the pool" required="true"/>
<c:simple-property name="user-name" description="User name for DB-connections" required="false" />
<c:simple-property name="password" description="Password" type="password" required="false"/>
+ <c:list-property name="xa-properties" displayName="XA Properties" description="Additional XA Properties" required="false">
+ <c:map-property name="xa-properties">
+ <c:simple-property name="key" displayName="Key" description="Key of the property"/>
+ <c:simple-property name="value" displayName="Value" description="Value of the property"/>
+ </c:map-property>
+ </c:list-property>
</parameters>
<results>
<c:simple-property name="operationResult"/>
diff --git a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/DatasourceDeployTest.java b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/DatasourceDeployTest.java
index 8930fe9..6ce5619 100644
--- a/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/DatasourceDeployTest.java
+++ b/modules/plugins/jboss-as-7/src/test/java/org/rhq/modules/plugins/jbossas7/DatasourceDeployTest.java
@@ -19,6 +19,7 @@
package org.rhq.modules.plugins.jbossas7;
import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -73,10 +74,7 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
List<String> result = (List<String>) res.getResult();
assert result.contains(DRIVER): "Driver not found in deployments";
- op = new Operation("remove","deployment",DRIVER);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Removal of driver from /deployment failed";
+ cleanupDomainDeployment(conn);
}
/*
@@ -121,7 +119,7 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
uploadDriverToDomain(conn);
Result res;
- Address sgAddress = addDriverToServerGroup(conn);
+ Address sgAddress = addDriverToMainServerGroup(conn);
Operation op;
// Now try to see if this ended up in server-one
@@ -149,18 +147,8 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
// Now clean up
- op = new Remove(sgAddress);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove driver from server group";
-
-
- Address deployment = new Address("deployment",DRIVER);
- op = new Remove(deployment);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove driver from /deployment";
-
+ cleanupSGDeployment(conn,sgAddress);
+ cleanupDomainDeployment(conn);
}
public void createDatasource() throws Exception {
@@ -168,12 +156,12 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
ASConnection conn = getASConnection();
uploadDriverToDomain(conn);
Result res;
- Address sgAddress = addDriverToServerGroup(conn);
+ Address sgAddress = addDriverToMainServerGroup(conn);
Operation op;
// Now create the data source in the profile, that main-server-group is using.
- Address dsAddress = createDatasource(conn);
+ Address dsAddress = createDatasource(conn, false);
System.out.println("Deployed new datasource at " + dsAddress.toString());
@@ -181,24 +169,33 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
// clean up
- op = new Remove(dsAddress);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove datasource from profile";
+ cleanupDatasource(conn,dsAddress);
+ cleanupSGDeployment(conn,sgAddress);
+ cleanupDomainDeployment(conn);
+ }
- op = new Remove(sgAddress);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove driver from server group";
+ public void createXADatasource() throws Exception {
+ ASConnection conn = getASConnection();
+ uploadDriverToDomain(conn);
+ Result res;
+ Address sgAddress = addDriverToMainServerGroup(conn);
+ Operation op;
- Address deployment = new Address("deployment",DRIVER);
- op = new Remove(deployment);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove driver from /deployment";
+ // Now create the data source in the profile, that main-server-group is using.
+
+ Address dsAddress = createDatasource(conn, true);
+
+ System.out.println("Deployed new xa-datasource at " + dsAddress.toString());
+ Thread.sleep(1000L); // give some time to settle
+
+ // clean up
+
+ cleanupDatasource(conn,dsAddress);
+ cleanupSGDeployment(conn,sgAddress);
+ cleanupDomainDeployment(conn);
}
@@ -206,12 +203,12 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
ASConnection conn = getASConnection();
uploadDriverToDomain(conn);
Result res;
- Address sgAddress = addDriverToServerGroup(conn);
+ Address sgAddress = addDriverToMainServerGroup(conn);
Operation op;
// Now create the data source in the profile, that main-server-group is using.
- Address dsAddress = createDatasource(conn);
+ Address dsAddress = createDatasource(conn, false);
System.out.println("Deployed new datasource at " + dsAddress.toString());
@@ -222,25 +219,9 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
assert res != null;
assert res.isSuccess(): "Updating the max-pool-size did not work: " + res.getFailureDescription();
-
- op = new Remove(dsAddress);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove datasource from profile";
-
-
- op = new Remove(sgAddress);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove driver from server group";
-
-
- Address deployment = new Address("deployment",DRIVER);
- op = new Remove(deployment);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove driver from /deployment";
-
+ cleanupDatasource(conn,dsAddress);
+ cleanupSGDeployment(conn,sgAddress);
+ cleanupDomainDeployment(conn);
}
@@ -248,7 +229,7 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
ASConnection conn = getASConnection();
uploadDriverToDomain(conn);
Result res;
- Address sgAddress = addDriverToServerGroup(conn);
+ Address sgAddress = addDriverToMainServerGroup(conn);
Operation op;
// Now create the data source in the profile, that main-server-group is using.
@@ -261,7 +242,7 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
Configuration parameters = new Configuration();
parameters.put(new PropertySimple("name",name));
- parameters.put(new PropertySimple("driver",DRIVER));
+ parameters.put(new PropertySimple("driver-name",DRIVER));
parameters.put(new PropertySimple("pool-name","pgPool"));
parameters.put(new PropertySimple("connection-url","jdbc:postgresql:foo@localhost:5432"));
parameters.put(new PropertySimple("jndi-name","postgresDS"));
@@ -280,41 +261,102 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
Thread.sleep(1000L); // give some time to settle
+ cleanupDatasource(conn, dsAddress);
+ cleanupSGDeployment(conn, sgAddress);
+ cleanupDomainDeployment(conn);
- op = new Remove(dsAddress);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove datasource from profile";
+ }
+ public void deployXADatasourceViaOperation() throws Exception {
+ ASConnection conn = getASConnection();
+ uploadDriverToDomain(conn);
+ Result res;
+ Address sgAddress = addDriverToMainServerGroup(conn);
+ Operation op;
- op = new Remove(sgAddress);
- res = conn.execute(op);
- assert res != null;
- assert res.isSuccess() : "Could not remove driver from server group";
+ // Now create the data source in the profile, that main-server-group is using.
+
+ String name = "myTestDS";
+ DatasourceComponent dc = new DatasourceComponent();
+ dc.path="profile=default,subsystem=datasources";
+ dc.connection = conn;
- Address deployment = new Address("deployment",DRIVER);
+ Configuration parameters = new Configuration();
+ parameters.put(new PropertySimple("name",name));
+ parameters.put(new PropertySimple("driver-name",DRIVER));
+ parameters.put(new PropertySimple("pool-name","pgPool"));
+ parameters.put(new PropertySimple("connection-url","jdbc:postgresql:foo@localhost:5432"));
+ parameters.put(new PropertySimple("jndi-name","postgresDS"));
+ parameters.put(new PropertySimple("xa-data-source-class","org.postgres.XA.driver"));
+ OperationResult operationResult = dc.invokeOperation("addXADatasource",parameters);
+ assert operationResult != null;
+ assert operationResult.getSimpleResult()!=null ;
+ assert operationResult.getErrorMessage()==null;
+
+ Address dsAddress = new Address();
+ dsAddress.add("profile","default");
+ dsAddress.add("subsystem","datasources");
+ dsAddress.add("xa-data-source",name);
+
+
+ System.out.println("Deployed new xa-datasource at " + dsAddress.toString());
+
+ Thread.sleep(1000L); // give some time to settle
+
+ cleanupDatasource(conn, dsAddress);
+ cleanupSGDeployment(conn, sgAddress);
+ cleanupDomainDeployment(conn);
+
+
+ }
+
+ private void cleanupDomainDeployment(ASConnection conn) {
+ Operation op;Result res;Address deployment = new Address("deployment",DRIVER);
op = new Remove(deployment);
res = conn.execute(op);
assert res != null;
assert res.isSuccess() : "Could not remove driver from /deployment";
-
-
}
+ private void cleanupSGDeployment(ASConnection conn, Address sgAddress) {
+ Operation op;Result res;
+ op = new Remove(sgAddress);
+ res = conn.execute(op);
+ assert res != null;
+ assert res.isSuccess() : "Could not remove driver from server group @ " + sgAddress;
+ }
- private Address createDatasource(ASConnection conn) {
+ private void cleanupDatasource(ASConnection conn, Address dsAddress) {
Operation op;Result res;
+ op = new Remove(dsAddress);
+ res = conn.execute(op);
+ assert res != null;
+ assert res.isSuccess() : "Could not remove datasource from profile @ " + dsAddress;
+ }
+
+ private Address createDatasource(ASConnection conn, boolean isXa) {
+ Operation op;
+ Result res;
Address dsAddress = new Address("profile","default");
dsAddress.add("subsystem","datasources");
- dsAddress.add("data-source", POSTGRES);
+ if (isXa)
+ dsAddress.add("xa-data-source", POSTGRES);
+ else
+ dsAddress.add("data-source", POSTGRES);
op = new Operation("add",dsAddress);
op.addAdditionalProperty("driver-name",DRIVER);
op.addAdditionalProperty("jndi-name","postgresDS");
op.addAdditionalProperty("pool-name","pgPool");
op.addAdditionalProperty("connection-url","jdbc:postgresql://127.0.0.1:5432/rhqdev");
+ if (isXa) {
+ op.addAdditionalProperty("xa-data-source-class","org.postgresql.xa.PGXADataSource");
+ Map<String,String> map = new HashMap<String, String>(1); // TODO AS7-1209
+ map.put("key","value");
+ op.addAdditionalProperty("xa-data-source-properties",map);
+ }
res = conn.execute(op);
assert res != null;
@@ -322,7 +364,7 @@ public class DatasourceDeployTest extends AbstractIntegrationTest {
return dsAddress;
}
- private Address addDriverToServerGroup(ASConnection conn) {
+ private Address addDriverToMainServerGroup(ASConnection conn) {
Result res;// then add the driver to the server-group we want to have the DS on
Address sgAddress = new Address();
sgAddress.add("server-group", "main-server-group");
commit 37f2759320d13dfd2e68e93563ffcc4098f58059
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Wed Jul 6 13:28:14 2011 +0200
Allow to add username/password when creating the DS.
Allow to promote a deployment to all server groups.
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
index 401bfb6..5feaf3a 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/BaseComponent.java
@@ -21,6 +21,7 @@ package org.rhq.modules.plugins.jbossas7;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.jackson.JsonNode;
+import org.hibernate.cfg.CollectionSecondPass;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
@@ -53,11 +54,14 @@ import org.rhq.modules.plugins.jbossas7.json.CompositeOperation;
import org.rhq.modules.plugins.jbossas7.json.Operation;
import org.rhq.modules.plugins.jbossas7.json.PROPERTY_VALUE;
import org.rhq.modules.plugins.jbossas7.json.ReadAttribute;
+import org.rhq.modules.plugins.jbossas7.json.ReadChildrenNames;
import org.rhq.modules.plugins.jbossas7.json.ReadResource;
import org.rhq.modules.plugins.jbossas7.json.Result;
import java.io.OutputStream;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@@ -478,16 +482,32 @@ public class BaseComponent implements ResourceComponent, MeasurementFacet, Confi
} else if (what.equals("domain-deployment")) {
if (op.equals("promote")) {
String serverGroup = parameters.getSimpleValue("server-group","-not set-");
+ List<String> serverGroups = new ArrayList<String>();
+ if (serverGroup.equals("__all")) {
+ serverGroups.addAll(getServerGroups());
+ }
+ else {
+ serverGroups.add(serverGroup);
+ }
+ String resourceKey = context.getResourceKey();
+ resourceKey = resourceKey.substring(resourceKey.indexOf("=")+1);
+
+ log.info("Promoting [" + resourceKey + "] to server group(s) [" + Arrays.asList(serverGroups) + "]");
+
PropertySimple simple = parameters.getSimple("enabled");
Boolean enabled = false;
if (simple!=null && simple.getBooleanValue()!=null)
enabled= simple.getBooleanValue();
- address.add(new PROPERTY_VALUE("server-group",serverGroup));
- String resourceKey = context.getResourceKey();
- resourceKey = resourceKey.substring(resourceKey.indexOf("=")+1);
- address.add(new PROPERTY_VALUE("deployment", resourceKey));
- operation = new Operation("add",address,"enabled",enabled);
+ operation = new CompositeOperation();
+ for (String theGroup : serverGroups) {
+ address = new ArrayList<PROPERTY_VALUE>();
+ address.add(new PROPERTY_VALUE("server-group",theGroup));
+
+ address.add(new PROPERTY_VALUE("deployment", resourceKey));
+ Operation step = new Operation("add",address,"enabled",enabled);
+ ((CompositeOperation)operation).addStep(step);
+ }
}
}
@@ -505,10 +525,17 @@ public class BaseComponent implements ResourceComponent, MeasurementFacet, Confi
else {
operationResult.setErrorMessage("No valid operation was given for input [" + name + "]");
}
- // TODO throw an exception if the operation failed?
return operationResult;
}
+ @SuppressWarnings("unchecked")
+ private Collection<String> getServerGroups() {
+ Operation op = new ReadChildrenNames(Collections.<PROPERTY_VALUE>emptyList(),"server-group");
+ Result res = connection.execute(op);
+
+ return (Collection<String>) res.getResult();
+ }
+
Object getObjectForProperty(PropertySimple prop, PropertyDefinitionSimple propDef) {
PropertySimpleType type = propDef.getType();
diff --git a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java
index 4be263f..ad6914f 100644
--- a/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java
+++ b/modules/plugins/jboss-as-7/src/main/java/org/rhq/modules/plugins/jbossas7/DatasourceComponent.java
@@ -51,6 +51,8 @@ public class DatasourceComponent extends BaseComponent implements OperationFacet
String jndiName = parameters.getSimpleValue("jndi-name", NOTSET);
String poolName = parameters.getSimpleValue("pool-name", NOTSET);
String connectionUrl = parameters.getSimpleValue("connection-url",NOTSET);
+ String userName = parameters.getSimpleValue("user-name","");
+ String password = parameters.getSimpleValue("password","");
String name = parameters.getSimpleValue("name",NOTSET);
List<PROPERTY_VALUE> address = pathToAddress(getPath());
@@ -60,6 +62,10 @@ public class DatasourceComponent extends BaseComponent implements OperationFacet
op.addAdditionalProperty("jndi-name",jndiName);
op.addAdditionalProperty("pool-name",poolName);
op.addAdditionalProperty("connection-url",connectionUrl);
+ if (userName!=null && !userName.isEmpty())
+ op.addAdditionalProperty("user-name",userName);
+ if (password!=null && !password.isEmpty())
+ op.addAdditionalProperty("password",password);
Result res = connection.execute(op);
if (res.isSuccess()) {
@@ -76,4 +82,8 @@ public class DatasourceComponent extends BaseComponent implements OperationFacet
return result;
}
+
+ void addAdditionalToOp(Operation op, Configuration parameters, String property, boolean optional) {
+
+ }
}
diff --git a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
index 0cb4eef..248367a 100644
--- a/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/jboss-as-7/src/main/resources/META-INF/rhq-plugin.xml
@@ -126,7 +126,7 @@
<c:simple-property name="auto-start" displayName="Autostart" default="false" type="boolean" />
</parameters>
<results>
- <c:simple-property name="result" description="Outcome of the create server operation"/>
+ <c:simple-property name="operationResult" description="Outcome of the create server operation"/>
</results>
</operation>
<operation name="managed-server:remove" displayName="Remove managed server" description="Remove a managed server">
@@ -137,7 +137,7 @@
</c:simple-property>
</parameters>
<results>
- <c:simple-property name="result" description="Outcome of the remove server operation"/>
+ <c:simple-property name="operationResult" description="Outcome of the remove server operation"/>
</results>
</operation>
@@ -218,7 +218,7 @@
<c:simple-property name="auto-start" displayName="Autostart" description="Should this server start at boot?" type="boolean" default="false" required="true"/>
</parameters>
<results>
- <c:simple-property name="result" description="Outcome of the create server operation"/>
+ <c:simple-property name="operationResult" description="Outcome of the create server operation"/>
</results>
</operation>
<operation name="server:remove" displayName="Delete server" description="Deletes a server on this host.">
@@ -226,7 +226,7 @@
<c:simple-property name="name" description="Name of this new server" required="true"/>
</parameters>
<results>
- <c:simple-property name="result" description="Outcome of the delete server operation"/>
+ <c:simple-property name="operationResult" description="Outcome of the delete server operation"/>
</results>
</operation>
</server>
@@ -243,12 +243,15 @@
<operation name="domain-deployment:promote" displayName="Deploy to Server-Group" description="Deploy this deployment to a server group">
<parameters>
<c:simple-property name="server-group" required="true" description="Server group to deploy to" type="string">
+ <c:property-options>
+ <c:option value="__all" name="All"/>
+ </c:property-options>
<c:option-source target="resource" expression="type=ServerGroup" />
</c:simple-property>
<c:simple-property name="enabled" required="true" default="true" description="Should the deployment be enabled on the server group?" type="boolean"/>
</parameters>
<results>
- <c:simple-property name="result" description="Outcome of the deploy to server group operation"/>
+ <c:simple-property name="operationResult" description="Outcome of the deploy to server group operation"/>
</results>
</operation>
@@ -749,6 +752,8 @@
<c:simple-property name="jndi-name" description="JNDI-Name of the Datasource" required="true"/>
<c:simple-property name="pool-name" description="Name of the pool" required="true"/>
<c:simple-property name="connection-url" description="URL for the connection to the database" required="true"/>
+ <c:simple-property name="user-name" description="User name for DB-connections" required="false" />
+ <c:simple-property name="password" description="Password" type="password" required="false"/>
</parameters>
<results>
<c:simple-property name="operationResult"/>
@@ -806,7 +811,7 @@
description="A class that implements org.jboss.jca.adapters.jdbc.URLSelectorStrategy" required="false"/>
<c:simple-property name="use-java-context" type="boolean" readOnly="true"
description="Setting this to false will bind the DataSource into global JNDI;"/>
- <c:simple-property name="enabled" type="string" readOnly="true" description="Specifies if the datasource should be enabled"/>
+ <c:simple-property name="enabled" type="boolean" readOnly="true" required="false" description="Specifies if the datasource should be enabled"/>
<c:simple-property name="max-pool-size" type="integer" readOnly="false" required="false"
description="The max-pool-size element indicates the maximum number of connections for a pool. No more connections will be created in each sub-pool."/>
<c:simple-property name="min-pool-size" type="integer" readOnly="false" required="false"
12 years, 11 months
[rhq] Branch 'drift' - modules/core
by John Sanda
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java | 7
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java | 40 +++-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java | 98 ++++++++++
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java | 41 +++-
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java | 66 +++---
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java | 94 +++++++++
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java | 77 ++++++-
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftFilesSenderTest.java | 15 -
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java | 42 +++-
9 files changed, 407 insertions(+), 73 deletions(-)
New commits:
commit 5b7729c64a50c1688fb119da12b93e7fd91a68da
Author: John Sanda <jsanda(a)redhat.com>
Date: Wed Jul 6 09:07:26 2011 -0400
Initial commit for DirectoryAnalyzer and DirectoryAnalyzerTest
DirectoryAnalyzer compares a file system directory against a
DirectoryEntry reporting any drift.
Adding some additional methods in ChangeSetManager for retrieving drift
change set files. Up until now, ChangeSetManager only works with
coverage change sets. It is distinguishes between the two by file name.
A coverage change set is named changeset.txt, and a drift change set is
named drift-changeset.txt.
Pushing some more helper methods into DriftTest. Adding initial logic in
DriftDetector for determining whether or not a coverage change set needs
to be generated (versus a drift change set).
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java
index 06af0ae..3f946f5 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java
@@ -11,8 +11,11 @@ import org.rhq.core.domain.drift.DriftConfiguration;
public interface ChangeSetManager {
+ boolean changeSetExists(int resourceId, Headers headers) throws IOException;
+
/**
- * Locates the latest change set for the specified resource id and drift configuration.
+ * Locates the latest coverage change set for the specified resource id and drift
+ * configuration.
*
* @param resourceId The id of the resource to which the change set belongs
* @param driftConfigurationName The name of the drift configuration for which the
@@ -22,6 +25,8 @@ public interface ChangeSetManager {
*/
File findChangeSet(int resourceId, String driftConfigurationName) throws IOException;
+ File findChangeSet(int resourceId, String name, DriftChangeSetCategory type);
+
/**
* Locates the latest change set for the given resource and drift configuration and
* returns a ChangeSetReader for that change set. Note that a resource can have
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
index aae887d..9fba34e 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
@@ -13,7 +13,10 @@ import org.rhq.common.drift.Headers;
import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
+import net.sourceforge.cobertura.coveragedata.CoverageData;
+
import static java.io.File.separator;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
public class ChangeSetManagerImpl implements ChangeSetManager {
@@ -24,6 +27,12 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
@Override
+ public boolean changeSetExists(int resourceId, Headers headers) throws IOException {
+ File file = findChangeSet(resourceId, headers.getDriftConfigurationName());
+ return file != null && file.exists();
+ }
+
+ @Override
public File findChangeSet(int resourceId, String driftConfigurationName) throws IOException {
File changeSetDir = findChangeSetDir(resourceId, driftConfigurationName);
File changeSetFile = new File(changeSetDir, "changeset.txt");
@@ -36,6 +45,19 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
@Override
+ public File findChangeSet(int resourceId, String name, DriftChangeSetCategory type) {
+ File changeSetDir = findChangeSetDir(resourceId, name);
+ switch (type) {
+ case COVERAGE:
+ return new File(changeSetDir, "changeset.txt");
+ case DRIFT:
+ return new File(changeSetDir, "drift-changeset.txt");
+ default:
+ throw new IllegalArgumentException(type + " is not a recognized, supported change set type.");
+ }
+ }
+
+ @Override
public ChangeSetReader getChangeSetReader(int resourceId, String driftConfigurationName)
throws IOException {
File changeSetFile = findChangeSet(resourceId, driftConfigurationName);
@@ -49,14 +71,16 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
@Override
public ChangeSetWriter getChangeSetWriter(int resourceId, Headers headers) throws IOException {
- File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
- File changeSetDir = new File(resourceDir, headers.getDriftConfigurationName());
-
- if (!changeSetDir.exists()) {
- changeSetDir.mkdirs();
- }
-
- return new ChangeSetWriterImpl(new File(changeSetDir, "changeset.txt"), headers);
+// File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
+// File changeSetDir = new File(resourceDir, headers.getDriftConfigurationName());
+//
+// if (!changeSetDir.exists()) {
+// changeSetDir.mkdirs();
+// }
+//
+// return new ChangeSetWriterImpl(new File(changeSetDir, "changeset.txt"), headers);
+ File changeSet = findChangeSet(resourceId, headers.getDriftConfigurationName(), headers.getType());
+ return new ChangeSetWriterImpl(changeSet, headers);
}
@Override
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java
new file mode 100644
index 0000000..140e777
--- /dev/null
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DirectoryAnalyzer.java
@@ -0,0 +1,98 @@
+package org.rhq.core.pc.drift;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.rhq.common.drift.DirectoryEntry;
+import org.rhq.common.drift.FileEntry;
+import org.rhq.core.util.MessageDigestGenerator;
+
+import static org.rhq.common.drift.FileEntry.addedFileEntry;
+import static org.rhq.common.drift.FileEntry.removedFileEntry;
+
+public class DirectoryAnalyzer {
+
+ private File basedir;
+
+ private DirectoryEntry dirEntry;
+
+ private List<FileEntry> filesAdded = new ArrayList<FileEntry>();
+
+ private List<FileEntry> filesRemoved = new ArrayList<FileEntry>();
+
+ private List<FileEntry> filesChanged = new ArrayList<FileEntry>();
+
+ private MessageDigestGenerator digestGenerator = new MessageDigestGenerator(MessageDigestGenerator.SHA_256);
+
+ public DirectoryAnalyzer(File basedir, DirectoryEntry directoryEntry) {
+ this.basedir = basedir;
+ dirEntry = directoryEntry;
+ }
+
+ public List<FileEntry> getFilesAdded() {
+ return filesAdded;
+ }
+
+ public List<FileEntry> getFilesRemoved() {
+ return filesRemoved;
+ }
+
+ public List<FileEntry> getFilesChanged() {
+ return filesChanged;
+ }
+
+ public void run() throws IOException {
+ File dir = new File(basedir, dirEntry.getDirectory());
+ Set<String> files = fileNames(dir.listFiles());
+ Map<String, FileEntry> fileEntries = createFileEntriesMap();
+
+ Set<String> dirEntryFileNames = dirEntryFileNames();
+
+ for (String file : files) {
+ if (!fileEntries.containsKey(file)) {
+ filesAdded.add(addedFileEntry(file, sha256(new File(dir, file))));
+ }
+ }
+
+ for (String file : fileEntries.keySet()) {
+ if (!files.contains(file)) {
+ filesRemoved.add(removedFileEntry(file, fileEntries.get(file).getNewSHA()));
+ }
+ }
+ }
+
+ private Set<String> fileNames(File... files) {
+ Set<String> set = new TreeSet<String>();
+ for (File file : files) {
+ set.add(file.getName());
+ }
+ return set;
+ }
+
+ private Map<String, FileEntry> createFileEntriesMap() {
+ Map<String, FileEntry> map = new TreeMap<String, FileEntry>();
+ for (FileEntry entry : dirEntry) {
+ map.put(entry.getFile(), entry);
+ }
+ return map;
+ }
+
+ private Set<String> dirEntryFileNames() {
+ Set<String> set = new TreeSet<String>();
+ for (FileEntry entry : dirEntry) {
+ set.add(entry.getFile());
+ }
+ return set;
+ }
+
+ private String sha256(File file) throws IOException {
+ return digestGenerator.calcDigestString(file);
+ }
+
+}
diff --git a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
index 5d1ae5d..653bf6f 100644
--- a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
+++ b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
@@ -3,12 +3,15 @@ package org.rhq.core.pc.drift;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import java.util.Stack;
import org.apache.commons.io.DirectoryWalker;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.ChangeSetWriter;
import org.rhq.common.drift.DirectoryEntry;
import org.rhq.common.drift.FileEntry;
@@ -18,6 +21,7 @@ import org.rhq.core.util.MessageDigestGenerator;
import static java.util.Collections.EMPTY_LIST;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.DRIFT;
public class DriftDetector implements Runnable {
private Log log = LogFactory.getLog(DriftDetector.class);
@@ -56,11 +60,12 @@ public class DriftDetector implements Runnable {
// TODO add logic to determine if there is an existing changeset
// if there is no previous changeset then we need to generate the initial
// coverage changeset
- ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
- new Headers(driftConfig.getName(), basedir(resourceId, driftConfig), COVERAGE));
-
- DirectoryScanner scanner = new DirectoryScanner(resourceId, driftConfig, writer);
- scanner.scan();
+ if (changeSetMgr.changeSetExists(schedule.getResourceId(), new Headers(driftConfig.getName(),
+ basedir(resourceId, driftConfig), COVERAGE))) {
+ generateDriftChangeSet(schedule);
+ } else {
+ generateCoverageChangeSet(schedule);
+ }
} catch (IOException e) {
// TODO Call ChangeSetManager here to rollback any thing that was written to disk.
log.error("An error occurred while scanning for drift", e);
@@ -71,6 +76,32 @@ public class DriftDetector implements Runnable {
driftClient.sendChangeSetToServer(schedule.getResourceId(), driftConfig);
}
+ private void generateDriftChangeSet(DriftDetectionSchedule schedule) throws IOException {
+// File basedir = new File(basedir(schedule.getResourceId(), schedule.getDriftConfiguration()));
+//
+// ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
+// new Headers(schedule.getDriftConfiguration().getName(), basedir.getAbsolutePath(), DRIFT));
+// ChangeSetReader reader = changeSetMgr.getChangeSetReader(schedule.getResourceId(),
+// schedule.getDriftConfiguration().getName());
+//
+// for (DirectoryEntry dirEntry : reader) {
+// File dir = new File(basedir, dirEntry.getDirectory());
+// if (dir.list().length > dirEntry.getNumberOfFiles()) {
+//
+// }
+// }
+ }
+
+ private void generateCoverageChangeSet(DriftDetectionSchedule schedule) throws IOException {
+ ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
+ new Headers(schedule.getDriftConfiguration().getName(),
+ basedir(schedule.getResourceId(), schedule.getDriftConfiguration()), COVERAGE));
+
+ DirectoryScanner scanner = new DirectoryScanner(schedule.getResourceId(), schedule.getDriftConfiguration(),
+ writer);
+ scanner.scan();
+ }
+
private String relativePath(File basedir, File file) {
if (basedir.equals(file)) {
return ".";
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java
index 2cb74a2..5a347ac 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java
@@ -10,63 +10,69 @@ import org.testng.annotations.Test;
import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.DirectoryEntry;
import org.rhq.common.drift.FileEntry;
+import org.rhq.common.drift.Headers;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
import static java.util.Arrays.asList;
import static org.apache.commons.io.FileUtils.writeLines;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.DRIFT;
import static org.testng.Assert.*;
import static org.apache.commons.io.FileUtils.deleteDirectory;
-public class ChangeSetManagerImplTest {
-
- File changeSetsDir;
-
- @BeforeClass
- public void resetChangeSetsDir() throws Exception {
- File dataDir = new File("target", getClass().getSimpleName());
- deleteDirectory(dataDir);
-
- changeSetsDir = new File(dataDir, "changesets");
- assertTrue(changeSetsDir.mkdirs(), "Failed to create " + changeSetsDir.getAbsolutePath());
- changeSetsDir = new File(dataDir, "changesets");
- }
+public class ChangeSetManagerImplTest extends DriftTest {
@Test
public void returnNullReaderWhenNoChangeSetExists() throws Exception {
- int resourceId = -1;
- ChangeSetManager changeSetMgr = new ChangeSetManagerImpl(changeSetsDir);
- ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId, "test");
-
+ ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId(), "test");
assertNull(reader, "Expect null for the reader when no change set exists for the drift configuration.");
}
@Test
public void returnReaderForRequestedChangeSet() throws Exception {
- int resourceId = 1;
+ String config = "return-reader-for-existing-changeset-test";
+ File changeSetDir = changeSetDir(config);
- File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
- File changeSetDir = new File(resourceDir, "test-1");
-
- assertTrue(changeSetDir.mkdirs(), "Failed to create change set directory: " + changeSetDir.getAbsolutePath());
-
- List<String> changeSet = asList(
- "test-1",
+ writeChangeSet(changeSetDir,
+ config,
"server",
"D",
"server/conf 1",
"8f26ac3d 0 myconf.conf A"
);
- writeLines(new File(changeSetDir, "changeset.txt"), changeSet);
- ChangeSetManager changeSetMgr = new ChangeSetManagerImpl(changeSetsDir);
- ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId, "test-1");
+ ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId(), config);
assertNotNull(reader, "Expected to get a change set reader when change set exists");
assertReaderOpenedOnChangeSet(reader, asList("server/conf", "1"));
}
+ @Test
+ public void verifyChangeSetExists() throws Exception {
+ String config = "changeset-exists-test";
+ File changeSetDir = changeSetDir(config);
+
+ writeChangeSet(changeSetDir,
+ config,
+ "server",
+ "D",
+ "server/conf 1",
+ "8f26ac3d 0 myconf.conf A"
+ );
+
+ assertTrue(changeSetMgr.changeSetExists(resourceId(), new Headers(config, resourceDir.getAbsolutePath(),
+ DRIFT)), "Expected to find change set file.");
+ }
+
+ @Test
+ public void verifyChangeSetDoesNotExist() throws Exception {
+ String config = "changeset-does-not-exist";
+ assertFalse(changeSetMgr.changeSetExists(resourceId(), new Headers(config, resourceDir.getAbsolutePath(),
+ DRIFT)), "Did not expect to find change set file.");
+ }
+
/**
* Verifies that a {@link ChangeSetReader} has been opened on the expected change set.
* This method first verifies that the reader is not null. It then reads the first
@@ -74,8 +80,8 @@ public class ChangeSetManagerImplTest {
* numberOfFiles properties match the expected values specified in dirEntry.
* <p/>
* This method does not rigorously check the entire contents of the change set file
- * because that {@link ChangeSetReader} tests; rather, it aims to inspect just enough
- * info to verify that the reader is opened on the correct change set.
+ * because that is handled by {@link ChangeSetReader} tests; rather, it aims to inspect
+ * just enough info to verify that the reader is opened on the correct change set.
*
* @param reader The ChangeSetReader returned from the ChangeSetManager under test
* @param dirEntry A list of strings representing the first line of a directory entry.
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java
new file mode 100644
index 0000000..df05a15
--- /dev/null
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DirectoryAnalyzerTest.java
@@ -0,0 +1,94 @@
+package org.rhq.core.pc.drift;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.testng.annotations.Test;
+
+import org.rhq.common.drift.DirectoryEntry;
+import org.rhq.common.drift.FileEntry;
+import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.test.AssertUtils;
+
+import static java.util.Arrays.asList;
+import static java.util.Collections.addAll;
+import static org.apache.commons.io.FileUtils.touch;
+import static org.rhq.common.drift.FileEntry.addedFileEntry;
+import static org.rhq.common.drift.FileEntry.removedFileEntry;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
+import static org.rhq.test.AssertUtils.assertCollectionMatchesNoOrder;
+
+public class DirectoryAnalyzerTest extends DriftTest {
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void detectAddedFile() throws Exception {
+ DriftConfiguration config = driftConfiguration("added-files-test", resourceDir.getAbsolutePath());
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = new File(confDir, "server-1.conf");
+ touch(server1Conf);
+
+ File changeSetDir = changeSetDir(config.getName());
+
+ // Generate the initial, coverage change set
+ writeChangeSet(changeSetDir,
+ config.getName(),
+ resourceDir.getAbsolutePath(),
+ COVERAGE.code(),
+ "conf 1",
+ sha256(server1Conf) + " 0 server-1.conf A",
+ ""
+ );
+
+ // Create some drift
+ File server2Conf = new File(confDir, "server-2.conf");
+ touch(server2Conf);
+
+ DirectoryAnalyzer analyzer = new DirectoryAnalyzer(resourceDir, new DirectoryEntry("conf")
+ .add(addedFileEntry(server1Conf.getName(), sha256(server1Conf))));
+ analyzer.run();
+
+ assertCollectionMatchesNoOrder(asList(addedFileEntry("server-2.conf", sha256(server2Conf))),
+ analyzer.getFilesAdded(), "Failed to detect added file.");
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void detectRemovedFile() throws Exception {
+ DriftConfiguration config = driftConfiguration("added-files-test", resourceDir.getAbsolutePath());
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = new File(confDir, "server-1.conf");
+ touch(server1Conf);
+ File server2Conf = new File(confDir, "server-2.conf");
+ touch(server2Conf);
+
+ String server2ConfHash = sha256(server2Conf);
+
+ File changeSetDir = changeSetDir(config.getName());
+
+ // Generate the initial, coverage change set
+ writeChangeSet(changeSetDir,
+ config.getName(),
+ resourceDir.getAbsolutePath(),
+ COVERAGE.code(),
+ "conf 1",
+ sha256(server1Conf) + " 0 server-1.conf A",
+ server2ConfHash + " 0 server-2.conf A",
+ ""
+ );
+
+ // create some drift
+ server2Conf.delete();
+
+ DirectoryAnalyzer analyzer = new DirectoryAnalyzer(resourceDir, new DirectoryEntry("conf")
+ .add(addedFileEntry("server-1.conf", sha256(server1Conf)))
+ .add(addedFileEntry("server-2.conf", server2ConfHash)));
+ analyzer.run();
+
+ assertCollectionMatchesNoOrder(asList(removedFileEntry("server-2.conf", server2ConfHash)),
+ analyzer.getFilesRemoved(), "Failed to detect removed file.");
+ }
+}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
index ff1af08..dca3dc6 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
@@ -23,9 +23,12 @@ import org.rhq.test.AssertUtils;
import static org.apache.commons.io.FileUtils.touch;
import static org.rhq.common.drift.FileEntry.addedFileEntry;
import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.DRIFT;
import static org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext.fileSystem;
+import static org.rhq.test.AssertUtils.assertCollectionMatchesNoOrder;
import static org.rhq.test.AssertUtils.assertPropertiesMatch;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
public class DriftDetectorTest extends DriftTest {
@@ -59,7 +62,7 @@ public class DriftDetectorTest extends DriftTest {
scheduleQueue.enqueue(new DriftDetectionSchedule(resourceId(), driftConfig));
detector.run();
- File changeSet = changeSet(driftConfig.getName());
+ File changeSet = changeSet(driftConfig.getName(), COVERAGE);
assertHeaderEquals(changeSet, new Headers(driftConfig.getName(), resourceDir.getAbsolutePath(), COVERAGE));
assertThatChangeSetDoesNotContainEmptyDirs(changeSet);
@@ -83,7 +86,7 @@ public class DriftDetectorTest extends DriftTest {
scheduleQueue.enqueue(schedule);
detector.run();
- assertChangeSetContainsDirEntry(changeSet(driftConfig.getName()),
+ assertChangeSetContainsDirEntry(changeSet(driftConfig.getName(), COVERAGE),
new DirectoryEntry(".")
.add(addedFileEntry("data-1.txt", sha256(data1)))
.add(addedFileEntry("data-2.txt", sha256(data2))));
@@ -91,6 +94,29 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
+ public void includeMultipleFilesInDirInCoverageChangeSet() throws Exception {
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = new File(confDir, "server-1.conf");
+ touch(server1Conf);
+ File server2Conf = new File(confDir, "server-2.conf");
+ touch(server2Conf);
+
+ DriftConfiguration config = driftConfiguration("multiple-files-test", resourceDir.getAbsolutePath());
+
+ scheduleQueue.enqueue(new DriftDetectionSchedule(resourceId(), config));
+ detector.run();
+
+ File changeSet = changeSet(config.getName(), COVERAGE);
+
+ assertHeaderEquals(changeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), COVERAGE));
+ assertChangeSetContainsDirEntry(changeSet,
+ new DirectoryEntry("conf")
+ .add(addedFileEntry("server-1.conf", sha256(server1Conf)))
+ .add(addedFileEntry("server-2.conf", sha256(server2Conf))));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
public void includedSiblingDirsInCoverageChangeSet() throws Exception {
File confDir = mkdir(resourceDir, "conf");
File serverConf = new File(confDir, "server.conf");
@@ -105,7 +131,7 @@ public class DriftDetectorTest extends DriftTest {
scheduleQueue.enqueue(new DriftDetectionSchedule(resourceId(), config));
detector.run();
- File changeSet = changeSet(config.getName());
+ File changeSet = changeSet(config.getName(), COVERAGE);
assertHeaderEquals(changeSet, new Headers(config.getName(), resourceDir.getAbsolutePath(), COVERAGE));
@@ -131,7 +157,7 @@ public class DriftDetectorTest extends DriftTest {
scheduleQueue.enqueue(new DriftDetectionSchedule(resourceId(), config));
detector.run();
- File changeSet = changeSet(config.getName());
+ File changeSet = changeSet(config.getName(), COVERAGE);
assertHeaderEquals(changeSet, new Headers("nested-dirs-test", resourceDir.getAbsolutePath(), COVERAGE));
@@ -141,6 +167,38 @@ public class DriftDetectorTest extends DriftTest {
new DirectoryEntry("conf/subconf").add(addedFileEntry("server-2.conf", sha256(server2Conf))));
}
+ @SuppressWarnings("unchecked")
+ @Test
+ public void includeAddedFileInDriftChangeSet() throws Exception {
+ DriftConfiguration config = driftConfiguration("file-added-drift-test", resourceDir.getAbsolutePath());
+
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = new File(confDir, "server-1.conf");
+ touch(server1Conf);
+
+ File changeSetDir = changeSetDir(config.getName());
+
+ // Generate the initial, coverage change set
+ writeChangeSet(changeSetDir,
+ config.getName(),
+ resourceDir.getAbsolutePath(),
+ COVERAGE.code(),
+ "conf 1",
+ sha256(server1Conf) + " 0 server-1.conf A",
+ ""
+ );
+
+ // Create some drift
+ File server2Conf = new File(confDir, "server-2.conf");
+ touch(server2Conf);
+
+ scheduleQueue.enqueue(new DriftDetectionSchedule(resourceId(), config));
+ detector.run();
+
+ File changeSet = changeSet(config.getName(), DRIFT);
+ assertTrue(changeSet.exists(), "Expected to find drift change set " + changeSet.getPath());
+ }
+
void assertHeaderEquals(File changeSet, Headers expected) throws Exception {
ChangeSetReader reader = new ChangeSetReaderImpl(new BufferedReader(new FileReader(changeSet)));
Headers actual = reader.getHeaders();
@@ -171,10 +229,8 @@ public class DriftDetectorTest extends DriftTest {
}
assertNotNull(actual, "Failed to find " + expected + " in " + changeSet.getPath());
- AssertUtils.assertCollectionMatchesNoOrder(fileEntries(expected), fileEntries(actual), "File entries for " +
+ assertCollectionMatchesNoOrder(fileEntries(expected), fileEntries(actual), "File entries for " +
expected + " in change set " + changeSet.getPath() + " do not match");
-// AssertUtils.assertCollectionEqualsNoOrder(fileEntries(expected), fileEntries(actual), "File entries for " +
-// expected);
}
Collection<FileEntry> fileEntries(DirectoryEntry dirEntry) {
@@ -185,11 +241,4 @@ public class DriftDetectorTest extends DriftTest {
return list;
}
- DriftConfiguration driftConfiguration(String name, String basedir) {
- DriftConfiguration config = new DriftConfiguration(new Configuration());
- config.setName(name);
- config.setBasedir(new DriftConfiguration.BaseDirectory(fileSystem, basedir));
-
- return config;
- }
}
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftFilesSenderTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftFilesSenderTest.java
index f4d42e5..20637d3 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftFilesSenderTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftFilesSenderTest.java
@@ -47,7 +47,7 @@ public class DriftFilesSenderTest extends DriftTest {
// Each item in changeSet is listed by the line it will appear in the actual file
// in an attemp to make it more self-documenting.
- writeChangeSet(changeSetDir, asList(
+ writeChangeSet(changeSetDir,
driftConfigName,
resourceDir.getAbsolutePath(),
COVERAGE.code(),
@@ -55,7 +55,7 @@ public class DriftFilesSenderTest extends DriftTest {
"2e345df 0 server-1.conf A",
"a5d8c3e 0 server-2.conf A",
""
- ));
+ );
sender.setDriftFiles(driftFiles("2e345df", "a5d8c3e"));
sender.setHeaders(new Headers(driftConfigName, resourceDir.getAbsolutePath(), COVERAGE));
@@ -83,7 +83,7 @@ public class DriftFilesSenderTest extends DriftTest {
// Each item in changeSet is listed by the line it will appear in the actual file
// in an attemp to make it more self-documenting.
- writeChangeSet(changeSetDir, asList(
+ writeChangeSet(changeSetDir,
driftConfigName,
resourceDir.getAbsolutePath(),
COVERAGE.code(),
@@ -95,7 +95,7 @@ public class DriftFilesSenderTest extends DriftTest {
"91d4abb 0 server-1.jar A",
"92c4abb 0 server-2.jar A",
""
- ));
+ );
// Note that the order of the drift files is random. When the server sends a request
// for files we cannot assume that the files will be in any particular order.
@@ -127,13 +127,6 @@ public class DriftFilesSenderTest extends DriftTest {
contentDir.getPath() + ". The SHA-256 hash should be used as the file name.");
}
- void writeChangeSet(File changeSetDir, List<String> changeSet) throws Exception {
- BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(changeSetDir,
- "changeset.txt")));
- writeLines(changeSet, "\n", stream);
- stream.close();
- }
-
List<DriftFile> driftFiles(String... hashes) {
List<DriftFile> files = new ArrayList<DriftFile>();
for (String hash : hashes) {
diff --git a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java
index caf2019..b555fef 100644
--- a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java
+++ b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java
@@ -1,15 +1,23 @@
package org.rhq.core.pc.drift;
+import java.io.BufferedOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
+import org.rhq.core.domain.drift.DriftConfiguration;
import org.rhq.core.util.MessageDigestGenerator;
+import static java.util.Arrays.asList;
import static org.apache.commons.io.FileUtils.deleteDirectory;
+import static org.apache.commons.io.IOUtils.writeLines;
+import static org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext.fileSystem;
/**
* A base test class that provides a framework for drift related tests. DriftTest sets up
@@ -133,14 +141,17 @@ public class DriftTest {
}
/**
- * Returns the change set file for the specified drift configuration.
+ * Returns the change set file for the specified drift configuration for the resource
+ * with the id that can be obtained from {@link #resourceId}. The type argument
+ * determines whether a coverage or drift change set file is returned.
*
* @param config The drift configuration name
- * @return The change set file or null if not found
+ * @param type Determines whether a coverage or drift change set file is to be returned
+ * @return The change set file
* @throws IOException
*/
- protected File changeSet(String config) throws IOException {
- return changeSetMgr.findChangeSet(resourceId(), config);
+ protected File changeSet(String config, DriftChangeSetCategory type) throws IOException {
+ return changeSetMgr.findChangeSet(resourceId(), config, type);
}
protected File changeSetDir(String driftConfigName) throws Exception {
@@ -158,4 +169,27 @@ public class DriftTest {
protected String sha256(File file) throws IOException {
return digestGenerator.calcDigestString(file);
}
+
+ protected void writeChangeSet(File changeSetDir, String... changeSet) throws Exception {
+ BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(changeSetDir,
+ "changeset.txt")));
+ writeLines(asList(changeSet), "\n", stream);
+ stream.close();
+ }
+
+ /**
+ * Creates a {@link DriftConfiguration} with the specified basedir. The file system is
+ * used as the context for the basedir which means the path specified is used as is.
+ *
+ * @param name The configuration name
+ * @param basedir An absolute path of the base directory
+ * @return The drift configuration object
+ */
+ protected DriftConfiguration driftConfiguration(String name, String basedir) {
+ DriftConfiguration config = new DriftConfiguration(new Configuration());
+ config.setName(name);
+ config.setBasedir(new DriftConfiguration.BaseDirectory(fileSystem, basedir));
+
+ return config;
+ }
}
12 years, 11 months
[rhq] Branch 'mod_cluster_plugin' - modules/plugins
by snegrea
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java | 61 ++--------
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java | 8 -
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java | 33 ++++-
modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml | 2
modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java | 19 ++-
5 files changed, 64 insertions(+), 59 deletions(-)
New commits:
commit 060cf8983b9230adf3f26c936d0fe6c8d1966bd1
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Tue Jul 5 23:31:24 2011 -0500
All the context dependent operations are now passed for execution to the parent MBean. The operation arguments are parsed from the proxyInfo MBean property.
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java
index f73a151..922197a 100644
--- a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java
+++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java
@@ -1,24 +1,20 @@
/*
- * Jopr Management Platform
+ * 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, 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.
+ * 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 and the GNU Lesser General Public License
- * for more details.
+ * GNU 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.
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.rhq.plugins.modcluster;
@@ -29,10 +25,9 @@ import org.rhq.core.pluginapi.operation.OperationResult;
import org.rhq.plugins.jmx.MBeanResourceComponent;
/**
- * Manages a Hibernate Entity.
+ * Manages a mod_cluster context entity.
*
- * @author Greg Hinkle
- * @author John Mazzitelli
+ * @author Stefan Negrea
*/
public class ContextComponent extends MBeanResourceComponent<MBeanResourceComponent> {
@Override
@@ -42,46 +37,24 @@ public class ContextComponent extends MBeanResourceComponent<MBeanResourceCompon
@Override
public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
- if ("enableContext".equals(name)) {
- //String[] queryStrings = (String[]) getEmsBean().getAttribute("Queries").refresh();
- OperationResult result = new OperationResult();
- result.setSimpleResult("This works!");
- /*PropertyList queries = new PropertyList("queries");
- result.getComplexResults().put(queries);*/
+ if ("enableContext".equals(name) || "disableContext".equals(name) || "stopContext".equals(name)) {
+
+ ProxyInfo.Context context = ProxyInfo.Context.fromString(resourceContext.getResourceKey());
+ System.out.println(context.toString());
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
- /*Thread.currentThread().setContextClassLoader(getEmsBean().getClass().getClassLoader());
- for (String queryString : queryStrings) {
- Object queryStatistics = getEmsBean().getOperation("getQueryStatistics").invoke(
- new Object[] { queryString });
-
- Long executionCount = (Long) queryStatistics.getClass().getMethod("getExecutionCount")
- .invoke(queryStatistics);
- Long executionRowCount = (Long) queryStatistics.getClass().getMethod("getExecutionRowCount")
- .invoke(queryStatistics);
- Long executionMinTime = (Long) queryStatistics.getClass().getMethod("getExecutionMinTime")
- .invoke(queryStatistics);
- Long executionMaxTime = (Long) queryStatistics.getClass().getMethod("getExecutionMaxTime")
- .invoke(queryStatistics);
- Long executionAvgTime = (Long) queryStatistics.getClass().getMethod("getExecutionAvgTime")
- .invoke(queryStatistics);
-
- PropertyMap query = new PropertyMap("query", new PropertySimple("query", queryString),
- new PropertySimple("executionCount", executionCount), new PropertySimple("executionRowCount",
- executionRowCount), new PropertySimple("executionMinTime", executionMinTime),
- new PropertySimple("executionMaxTime", executionMaxTime), new PropertySimple(
- "executionAvgTime", executionAvgTime));
+ Thread.currentThread().setContextClassLoader(getEmsBean().getClass().getClassLoader());
- queries.add(query);
- }*/
+ Object resultObject = getEmsBean().getOperation(name).invoke(
+ new Object[] { context.host, context.path });
- return result;
+ return new OperationResult(String.valueOf(resultObject));
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
- return super.invokeOperation(name, parameters);
+ throw new Exception("Operation " + name + " not available mod_cluster_context service");
}
}
\ No newline at end of file
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java
index 90e5c6b..4b3adcd 100644
--- a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java
+++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java
@@ -33,11 +33,15 @@ import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
import org.rhq.plugins.jmx.MBeanResourceComponent;
/**
- * Discovers hibernate entities from a hibernate stats mbean
+ * Discovers mod_cluster contexts from the proxyInfo mbean property.
*
- * @author Greg Hinkle
+ * @author Stefan Negrea
*/
public class ContextDiscoveryComponent implements ResourceDiscoveryComponent<MBeanResourceComponent> {
+
+ /* (non-Javadoc)
+ * @see org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent#discoverResources(org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext)
+ */
public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<MBeanResourceComponent> context) {
Set<DiscoveredResourceDetails> entities = new HashSet<DiscoveredResourceDetails>();
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java
index 15a9a68..9cb6b86 100644
--- a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java
+++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java
@@ -16,7 +16,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
package org.rhq.plugins.modcluster;
import java.util.ArrayList;
@@ -25,16 +24,17 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+/**
+ * Simple parser for the raw proxy information provided by mod_cluster.
+ *
+ * @author Stefan Negrea
+ */
public class ProxyInfo {
private List<Context> availableContexts = new ArrayList<ProxyInfo.Context>();
public ProxyInfo(String rawProxyInfo) {
- System.out.println("--------------------------------------");
- System.out.println(rawProxyInfo);
- System.out.println("--------------------------------------");
-
Pattern test = Pattern.compile("Context.*\n");
Matcher m = test.matcher(rawProxyInfo);
while (m.find()) {
@@ -42,7 +42,7 @@ public class ProxyInfo {
String[] contextPieces = rawContext.split(",");
String actualContext = contextPieces[1].substring(contextPieces[1].indexOf("/")).trim();
- availableContexts.add(new Context(actualContext, "localHost"));
+ availableContexts.add(new Context(actualContext, "localhost"));
}
}
@@ -50,12 +50,11 @@ public class ProxyInfo {
return Collections.unmodifiableList(availableContexts);
}
- public class Context {
+ public static class Context {
String path;
String host;
public Context(String path, String host) {
- super();
this.path = path;
this.host = host;
}
@@ -80,5 +79,23 @@ public class ProxyInfo {
public String toString() {
return "Context [path=" + path + ", host=" + host + "]";
}
+
+ public static Context fromString(String stringRepresentation) {
+ stringRepresentation = stringRepresentation.substring(stringRepresentation.indexOf('[') + 1);
+ stringRepresentation = stringRepresentation.substring(0, stringRepresentation.indexOf(']'));
+ stringRepresentation = stringRepresentation.trim();
+
+ String host = null;
+ String path = null;
+ for (String part : stringRepresentation.split(",")) {
+ part = part.trim();
+ if (part.startsWith("path=")) {
+ path = part.substring(5).trim();
+ } else if (part.startsWith("host=")) {
+ host = part.substring(5).trim();
+ }
+ }
+ return new Context(path, host);
+ }
}
}
\ No newline at end of file
diff --git a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
index 084165e..be4b25b 100644
--- a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
@@ -45,6 +45,8 @@
<resource-configuration>
<c:simple-property name="stickySessions" type="boolean" description="Enables sticky sessions."/>
+ <c:simple-property name="stickySessionRemove" type="boolean" description="Remove session when the request cannot be routed to the right node."/>
+ <c:simple-property name="advertise" type="boolean" description="Enable autodiscovery of httpd servers."/>
</resource-configuration>
<service name="mod_cluster_context"
diff --git a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java
index deceb70..0d16e92 100644
--- a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java
+++ b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java
@@ -140,8 +140,14 @@ public class ModclusterPluginTest {
assert (resources.size() != 0) : "No mod_cluster or related instances found.";
if (resources.size() != 0) {
- testResourceMeasurement((Resource) resources.toArray()[0]);
- testContextOperations((Resource) resources.toArray()[1]);
+ for (Object objectResource : resources.toArray()) {
+ Resource resource = (Resource) objectResource;
+ if (resource.getResourceType().getName().equals("mod_cluster")) {
+ testResourceMeasurement(resource);
+ } else {
+ testContextOperations(resource);
+ }
+ }
}
}
@@ -175,9 +181,12 @@ public class ModclusterPluginTest {
.getResourceComponent(resource);
if (resourceComponent instanceof OperationFacet) {
- OperationResult result = ((OperationFacet) resourceComponent).invokeOperation("enableContext", null);
- log.info("Result of operation " + "enableContext" + " was: " + result.getSimpleResult());
-
+ try {
+ OperationResult result = ((OperationFacet) resourceComponent).invokeOperation("enableContext", null);
+ log.info("Result of operation " + "enableContext" + " was: " + result.getSimpleResult());
+ } catch (Exception e) {
+ log.info("Operation failed");
+ }
/*result = ((OperationFacet) resourceComponent).invokeOperation("disable", null);
log.info("Result of operation test was: " + result.getSimpleResult());*/
}
12 years, 11 months
[rhq] Branch 'mod_cluster_plugin' - modules/plugins
by snegrea
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java | 87 ++++++++++
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java | 57 ++++++
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ModclusterServerComponent.java | 15 -
modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java | 84 +++++++++
modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml | 24 ++
modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java | 59 ++++++
6 files changed, 307 insertions(+), 19 deletions(-)
New commits:
commit a23fc57dda98b70cb7c1b23af91b9e3e3597969a
Author: Stefan Negrea <snegrea(a)redhat.com>
Date: Tue Jul 5 18:43:06 2011 -0500
Added individual contexts as sub services to mod_cluster service.
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java
new file mode 100644
index 0000000..f73a151
--- /dev/null
+++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextComponent.java
@@ -0,0 +1,87 @@
+/*
+ * Jopr 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, 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.plugins.modcluster;
+
+import org.mc4j.ems.connection.bean.EmsBean;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.pluginapi.operation.OperationResult;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+
+/**
+ * Manages a Hibernate Entity.
+ *
+ * @author Greg Hinkle
+ * @author John Mazzitelli
+ */
+public class ContextComponent extends MBeanResourceComponent<MBeanResourceComponent> {
+ @Override
+ protected EmsBean loadBean() {
+ return getResourceContext().getParentResourceComponent().getEmsBean();
+ }
+
+ @Override
+ public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
+ if ("enableContext".equals(name)) {
+ //String[] queryStrings = (String[]) getEmsBean().getAttribute("Queries").refresh();
+ OperationResult result = new OperationResult();
+ result.setSimpleResult("This works!");
+ /*PropertyList queries = new PropertyList("queries");
+ result.getComplexResults().put(queries);*/
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ try {
+ /*Thread.currentThread().setContextClassLoader(getEmsBean().getClass().getClassLoader());
+ for (String queryString : queryStrings) {
+ Object queryStatistics = getEmsBean().getOperation("getQueryStatistics").invoke(
+ new Object[] { queryString });
+
+ Long executionCount = (Long) queryStatistics.getClass().getMethod("getExecutionCount")
+ .invoke(queryStatistics);
+ Long executionRowCount = (Long) queryStatistics.getClass().getMethod("getExecutionRowCount")
+ .invoke(queryStatistics);
+ Long executionMinTime = (Long) queryStatistics.getClass().getMethod("getExecutionMinTime")
+ .invoke(queryStatistics);
+ Long executionMaxTime = (Long) queryStatistics.getClass().getMethod("getExecutionMaxTime")
+ .invoke(queryStatistics);
+ Long executionAvgTime = (Long) queryStatistics.getClass().getMethod("getExecutionAvgTime")
+ .invoke(queryStatistics);
+
+ PropertyMap query = new PropertyMap("query", new PropertySimple("query", queryString),
+ new PropertySimple("executionCount", executionCount), new PropertySimple("executionRowCount",
+ executionRowCount), new PropertySimple("executionMinTime", executionMinTime),
+ new PropertySimple("executionMaxTime", executionMaxTime), new PropertySimple(
+ "executionAvgTime", executionAvgTime));
+
+ queries.add(query);
+ }*/
+
+ return result;
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+ }
+
+ return super.invokeOperation(name, parameters);
+ }
+}
\ No newline at end of file
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java
new file mode 100644
index 0000000..90e5c6b
--- /dev/null
+++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ContextDiscoveryComponent.java
@@ -0,0 +1,57 @@
+/*
+ * Jopr 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, 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.plugins.modcluster;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.mc4j.ems.connection.bean.EmsBean;
+
+import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+import org.rhq.plugins.jmx.MBeanResourceComponent;
+
+/**
+ * Discovers hibernate entities from a hibernate stats mbean
+ *
+ * @author Greg Hinkle
+ */
+public class ContextDiscoveryComponent implements ResourceDiscoveryComponent<MBeanResourceComponent> {
+ public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<MBeanResourceComponent> context) {
+ Set<DiscoveredResourceDetails> entities = new HashSet<DiscoveredResourceDetails>();
+
+ EmsBean statsBean = context.getParentResourceComponent().getEmsBean();
+
+ String rawProxyInfo = (String) statsBean.getAttribute("proxyInfo").refresh().toString();
+ ProxyInfo proxyInfo = new ProxyInfo(rawProxyInfo);
+
+ for (ProxyInfo.Context availableContext : proxyInfo.getAvailableContexts()) {
+ DiscoveredResourceDetails detail = new DiscoveredResourceDetails(context.getResourceType(),
+ availableContext.toString(), availableContext.toString(), null, "mod_cluster Context", null, null);
+ entities.add(detail);
+ }
+
+ return entities;
+ }
+}
\ No newline at end of file
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ModclusterServerComponent.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ModclusterServerComponent.java
index a98792e..783f579 100644
--- a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ModclusterServerComponent.java
+++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ModclusterServerComponent.java
@@ -18,9 +18,6 @@
*/
package org.rhq.plugins.modcluster;
-import org.rhq.core.domain.operation.OperationDefinition;
-import org.rhq.core.pluginapi.inventory.ResourceComponent;
-import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.rhq.plugins.jmx.MBeanResourceComponent;
/**
@@ -28,16 +25,4 @@ import org.rhq.plugins.jmx.MBeanResourceComponent;
*
*/
public class ModclusterServerComponent extends MBeanResourceComponent {
-
- /**
- * Stores the context and loads the MBean.
- * @see ResourceComponent#start(ResourceContext)
- */
- @Override
- public void start(ResourceContext context) {
- super.start(context);
-
- OperationDefinition test = new OperationDefinition(context.getResourceType(), "Text");
- context.getResourceType().addOperationDefinition(test);
- }
}
diff --git a/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java
new file mode 100644
index 0000000..15a9a68
--- /dev/null
+++ b/modules/plugins/mod-cluster/src/main/java/org/rhq/plugins/modcluster/ProxyInfo.java
@@ -0,0 +1,84 @@
+/*
+ * 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.plugins.modcluster;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ProxyInfo {
+
+ private List<Context> availableContexts = new ArrayList<ProxyInfo.Context>();
+
+ public ProxyInfo(String rawProxyInfo) {
+
+ System.out.println("--------------------------------------");
+ System.out.println(rawProxyInfo);
+ System.out.println("--------------------------------------");
+
+ Pattern test = Pattern.compile("Context.*\n");
+ Matcher m = test.matcher(rawProxyInfo);
+ while (m.find()) {
+ String rawContext = m.group();
+ String[] contextPieces = rawContext.split(",");
+ String actualContext = contextPieces[1].substring(contextPieces[1].indexOf("/")).trim();
+
+ availableContexts.add(new Context(actualContext, "localHost"));
+ }
+ }
+
+ public List<Context> getAvailableContexts() {
+ return Collections.unmodifiableList(availableContexts);
+ }
+
+ public class Context {
+ String path;
+ String host;
+
+ public Context(String path, String host) {
+ super();
+ this.path = path;
+ this.host = host;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ @Override
+ public String toString() {
+ return "Context [path=" + path + ", host=" + host + "]";
+ }
+ }
+}
\ No newline at end of file
diff --git a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
index b8d7249..084165e 100644
--- a/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
+++ b/modules/plugins/mod-cluster/src/main/resources/META-INF/rhq-plugin.xml
@@ -47,5 +47,29 @@
<c:simple-property name="stickySessions" type="boolean" description="Enables sticky sessions."/>
</resource-configuration>
+ <service name="mod_cluster_context"
+ discovery="ContextDiscoveryComponent"
+ class="ContextComponent"
+ description="A mod_cluster context">
+
+ <operation name="enableContext" displayName="Enable webapp" description="Enable a single webapp">
+ <results>
+ <c:simple-property name="result" type="boolean" description="The result of the operation" />
+ </results>
+ </operation>
+ <operation name="disableContext" displayName="Disable webpapp" description="Disable a single webapp">
+ <results>
+ <c:simple-property name="result" type="boolean" description="The result of the operation" />
+ </results>
+ </operation>
+ <operation name="stopContext" displayName="Stop webpapp" description="Gracefully stops a single webapp">
+ <results>
+ <c:simple-property name="result" type="boolean" description="The result of the operation" />
+ </results>
+ </operation>
+
+ </service>
+
+
</service>
</plugin>
diff --git a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java
index da0303e..deceb70 100644
--- a/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java
+++ b/modules/plugins/mod-cluster/src/test/java/org/rhq/plugins/modcluster/test/ModclusterPluginTest.java
@@ -19,8 +19,10 @@
package org.rhq.plugins.modcluster.test;
import java.io.File;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
+import java.util.List;
import java.util.Queue;
import java.util.Set;
@@ -45,6 +47,7 @@ import org.rhq.core.pluginapi.inventory.ResourceComponent;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
import org.rhq.core.pluginapi.operation.OperationFacet;
import org.rhq.core.pluginapi.operation.OperationResult;
+import org.rhq.plugins.modcluster.ProxyInfo;
/**
* @author Fady Matar
@@ -80,6 +83,31 @@ public class ModclusterPluginTest {
}
@Test
+ public void testProxyInfo() {
+ String test = "{mobile-work/192.168.1.40:6666=Node: [1],Name: 4e6189af-0502-3305-8ff3-fad7fee8b516,Balancer: mycluster,LBGroup: ,Host: 127.0.0.1,Port: 8009,Type: ajp,Flushpackets: Off,Flushwait: 10,Ping: 10,Smax: 26,Ttl: 60,Elected: 3233,Read: 7355619,Transfered: 0,Connected: 0,Load: 100\n"
+ + "Node: [2],Name: node2,Balancer: mycluster,LBGroup: ,Host: 127.0.0.1,Port: 8009,Type: ajp,Flushpackets: Off,Flushwait: 10,Ping: 10,Smax: 26,Ttl: 60,Elected: 0,Read: 0,Transfered: 0,Connected: 0,Load: 99\n"
+ + "Vhost: [1:1:1], Alias: localhost\n"
+ + "Vhost: [2:1:2], Alias: localhost\n"
+ + "Context: [1:1:1], Context: /invoker, Status: DISABLED\n"
+ + "Context: [1:1:2], Context: /loaddemo, Status: DISABLED\n"
+ + "Context: [1:1:3], Context: /jbossws, Status: DISABLED\n"
+ + "Context: [1:1:4], Context: /juddi, Status: DISABLED\n"
+ + "Context: [1:1:5], Context: /jbossmq-httpil, Status: DISABLED\n"
+ + "Context: [1:1:6], Context: /web-console, Status: DISABLED\n"
+ + "Context: [1:1:7], Context: /jmx-console, Status: DISABLED\n"
+ + "Context: [1:1:8], Context: /, Status: DISABLED\n"
+ + "Context: [2:1:9], Context: /loaddemo, Status: ENABLED\n" + "}";
+
+ ProxyInfo proxyInfo = new ProxyInfo(test);
+
+ for (ProxyInfo.Context context : proxyInfo.getAvailableContexts()) {
+ log.info(context.toString());
+ }
+
+ assert (proxyInfo.getAvailableContexts().size() != 0) : "Raw proxy info parsing failed!";
+ }
+
+ @Test
public void testPluginLoad() {
PluginManager pluginManager = PluginContainer.getInstance().getPluginManager();
PluginEnvironment pluginEnvironment = pluginManager.getPlugin(PLUGIN_NAME);
@@ -98,12 +126,22 @@ public class ModclusterPluginTest {
assert report != null;
System.out.println("Discovery took: " + (report.getEndTime() - report.getStartTime()) + "ms");
+ List<String> typeNames = new ArrayList<String>() {
+ {
+ add(PLUGIN_NAME);
+ add(PLUGIN_NAME + "_context");
+ }
+ };
+
Set<Resource> resources = findResource(PluginContainer.getInstance().getInventoryManager().getPlatform(),
- PLUGIN_NAME);
- log.info("Found " + resources.size() + " mod_cluster instance(s).");
+ typeNames);
+ log.info("Found " + resources.size() + " mod_cluster and mod_cluster_context instance(s).");
+
+ assert (resources.size() != 0) : "No mod_cluster or related instances found.";
if (resources.size() != 0) {
testResourceMeasurement((Resource) resources.toArray()[0]);
+ testContextOperations((Resource) resources.toArray()[1]);
}
}
@@ -132,7 +170,20 @@ public class ModclusterPluginTest {
}
}
- private Set<Resource> findResource(Resource parent, String typeName) {
+ private void testContextOperations(Resource resource) throws Exception {
+ ResourceComponent resourceComponent = PluginContainer.getInstance().getInventoryManager()
+ .getResourceComponent(resource);
+
+ if (resourceComponent instanceof OperationFacet) {
+ OperationResult result = ((OperationFacet) resourceComponent).invokeOperation("enableContext", null);
+ log.info("Result of operation " + "enableContext" + " was: " + result.getSimpleResult());
+
+ /*result = ((OperationFacet) resourceComponent).invokeOperation("disable", null);
+ log.info("Result of operation test was: " + result.getSimpleResult());*/
+ }
+ }
+
+ private Set<Resource> findResource(Resource parent, List<String> typeNames) {
Set<Resource> found = new HashSet<Resource>();
Queue<Resource> discoveryQueue = new LinkedList<Resource>();
@@ -142,7 +193,7 @@ public class ModclusterPluginTest {
Resource currentResource = discoveryQueue.poll();
log.info("Discovered resource of type: " + currentResource.getResourceType().getName());
- if (currentResource.getResourceType().getName().equals(typeName)) {
+ if (typeNames.contains(currentResource.getResourceType().getName())) {
found.add(currentResource);
}
12 years, 11 months
[rhq] Branch 'drift' - modules/enterprise
by mazz
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java | 12 +++++-
modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/dup_drift.xml | 19 ++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
New commits:
commit c307eb219e654b02b027c325f1a37c7d188e5008
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Jul 5 17:36:54 2011 -0400
unit test to make sure we do not deploy plugins that have duplicate drift config names
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
index 27bcdc7..e2fdd96 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
@@ -50,10 +50,20 @@ import static java.util.Arrays.asList;
public class ResourceMetadataManagerBeanTest extends MetadataBeanTest {
@Test(groups = {"plugin.metadata", "NewPlugin"})
+ public void registerPluginWithDuplicateDriftConfigurations() {
+ try {
+ createPlugin("test-plugin.jar", "1.0", "dup_drift.xml");
+ fail("should not have succeeded - the drift config had duplicate names");
+ } catch (Exception e) {
+ // OK, the plugin should have failed to be deployed since it has duplicate drift configs
+ }
+ }
+
+ @Test(groups = {"plugin.metadata", "NewPlugin"})
public void registerPlugin() throws Exception {
createPlugin("test-plugin.jar", "1.0", "plugin_v1.xml");
}
-
+
@Test(dependsOnMethods = {"registerPlugin"}, groups = {"plugin.metadata", "NewPlugin"})
public void persistNewTypes() {
List<String> newTypes = asList("ServerA", "ServerB");
diff --git a/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/dup_drift.xml b/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/dup_drift.xml
new file mode 100644
index 0000000..d2dd71f
--- /dev/null
+++ b/modules/enterprise/server/jar/src/test/resources/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest/dup_drift.xml
@@ -0,0 +1,19 @@
+<plugin name="TestPlugin" displayName="Test Plugin" 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="ServerWithDupDrift" description="has duplicate drift config names and thus is invalid">
+ <drift-configuration name="drift-one">
+ <basedir>
+ <value-context>fileSystem</value-context>
+ <value-name>/a</value-name>
+ </basedir>
+ </drift-configuration>
+ <drift-configuration name="drift-one">
+ <basedir>
+ <value-context>fileSystem</value-context>
+ <value-name>/b</value-name>
+ </basedir>
+ </drift-configuration>
+ </server>
+</plugin>
\ No newline at end of file
12 years, 11 months
[rhq] Branch 'drift' - modules/core modules/enterprise
by mazz
modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java | 8 +
modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java | 1
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java | 77 ++++++++++
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerLocal.java | 3
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java | 2
5 files changed, 90 insertions(+), 1 deletion(-)
New commits:
commit a35e6479cdd1c4b6df3f5f59ced3114cdceecbc0
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Tue Jul 5 17:04:31 2011 -0400
fix the test that was broken. we now support drift configuration metadata updates. test passes.
we also abort plugin update for a plugin that defines multiple drift configs but whose drift config names have duplicates
(since all drift config names must be unique)
diff --git a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java
index f3aa13e..e856e2b 100644
--- a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java
+++ b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java
@@ -25,6 +25,7 @@ package org.rhq.core.clientapi.agent.metadata;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -490,10 +491,17 @@ public class PluginMetadataParser {
.getName(), resourceDescriptor.getResourceConfiguration()));
}
+ Set<String> driftConfigNames = new HashSet<String>();
DriftMetadataParser driftMetadataParser = new DriftMetadataParser();
for (DriftDescriptor descriptor : resourceDescriptor.getDriftConfiguration()) {
+ if (driftConfigNames.contains(descriptor.getName())) {
+ throw new InvalidPluginDescriptorException("Duplicate drift configuration name detected ["
+ + descriptor.getName() + "]");
+ }
+ driftConfigNames.add(descriptor.getName());
resourceType.addDriftConfigurationTemplate(driftMetadataParser.parseDriftMetadata(descriptor));
}
+ driftConfigNames = null; // don't need this anymore
int displayPosition = 1;
for (MetricDescriptor metricDescriptor : resourceDescriptor.getMetric()) {
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
index ff4904d..36ee734 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
@@ -827,6 +827,7 @@ public class ResourceType implements Serializable, Comparable<ResourceType> {
this.bundleType = bundleType;
}
+ // this must return the actual set, not a copy - see the metadata manager SLSB for when we update plugin metadata
public Set<ConfigurationTemplate> getDriftConfigurationTemplates() {
return driftConfigurationTemplates;
}
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
index 14a5343..7e9bc1a 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
@@ -44,6 +44,8 @@ import org.rhq.core.clientapi.agent.metadata.PluginMetadataManager;
import org.rhq.core.clientapi.agent.metadata.SubCategoriesMetadataParser;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.authz.Permission;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
import org.rhq.core.domain.criteria.ResourceCriteria;
import org.rhq.core.domain.resource.ProcessScan;
import org.rhq.core.domain.resource.Resource;
@@ -400,6 +402,8 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
contentMetadataMgr.updateMetadata(existingType, resourceType);
operationMetadataMgr.updateMetadata(existingType, resourceType);
+ resourceMetadataManager.updateDriftMetadata(existingType, resourceType);
+
updateProcessScans(resourceType, existingType);
eventMetadataMgr.updateMetadata(existingType, resourceType);
@@ -442,6 +446,79 @@ public class ResourceMetadataManagerBean implements ResourceMetadataManagerLocal
entityManager.flush();
}
+ @Override
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public void updateDriftMetadata(ResourceType existingType, ResourceType resourceType) {
+ boolean isSame = true;
+
+ existingType = entityManager.find(ResourceType.class, existingType.getId());
+
+ //
+ // First, we need to see if the drift configs have changed. If the existing and new drift configs
+ // are the same, then we can skip the update and do nothing. Only if one or more drift configs
+ // are different do we have to do anything to the persisted metadata.
+ //
+
+ Set<ConfigurationTemplate> existingDriftTemplates = existingType.getDriftConfigurationTemplates();
+ Set<ConfigurationTemplate> newDriftTemplates = resourceType.getDriftConfigurationTemplates();
+ if (existingDriftTemplates.size() != newDriftTemplates.size()) {
+ isSame = false;
+ } else {
+ // note: the size of the sets are typically really small (usually between 0 and 3),
+ // so iterating through them is fast.
+
+ // look at all the configs to ensure we detect any changes to individual settings on the templates
+ Set<String> existingNames = new HashSet<String>(existingDriftTemplates.size());
+ Set<String> newNames = new HashSet<String>(newDriftTemplates.size());
+ for (ConfigurationTemplate existingCT : existingDriftTemplates) {
+ String existingName = existingCT.getName();
+ Configuration existingConfig = existingCT.getConfiguration();
+
+ existingNames.add(existingName); // for later
+
+ for (ConfigurationTemplate newCT : newDriftTemplates) {
+ String newName = newCT.getName();
+ newNames.add(newName); // for later, do this here, not in the if-stmt below, so we can catch if new has names not in existing
+ if (newName.equals(existingName)) {
+ Configuration newConfig = newCT.getConfiguration();
+ if (!existingConfig.equals(newConfig)) {
+ isSame = false;
+ }
+ break;
+ }
+ }
+
+ if (!isSame) {
+ break;
+ }
+ }
+
+ if (isSame) {
+ // make sure they all have the same names and no duplicate names existed
+ isSame = existingNames.equals(newNames) && existingNames.size() == existingDriftTemplates.size();
+ }
+ }
+
+ //
+ // If one or more drift configs are different between new and existing,
+ // then we need to remove the old drift config and persist the new drift config.
+ //
+
+ if (!isSame) {
+ for (ConfigurationTemplate doomed : existingDriftTemplates) {
+ entityManager.remove(doomed);
+ }
+ existingType.getDriftConfigurationTemplates().clear();
+
+ for (ConfigurationTemplate toPersist : newDriftTemplates) {
+ entityManager.persist(toPersist);
+ existingType.addDriftConfigurationTemplate(toPersist);
+ }
+ }
+
+ return;
+ }
+
private void persistNewType(ResourceType resourceType) {
log.info("Persisting new ResourceType [" + toConciseString(resourceType) + "]...");
// If the type didn't exist then we'll persist here which will cascade through
diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerLocal.java b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerLocal.java
index 4592bc7..ae96d22 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerLocal.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerLocal.java
@@ -45,4 +45,7 @@ public interface ResourceMetadataManagerLocal {
void completeRemoveResourceType(Subject subject, ResourceType existingType);
void updateTypes(Set<ResourceType> resourceTypes) throws Exception;
+
+ /** TODO: do we want to create a driftMetadataManager SLSB and put this in there */
+ void updateDriftMetadata(ResourceType existingType, ResourceType resourceType);
}
\ No newline at end of file
diff --git a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
index 0481d9d..27bcdc7 100644
--- a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
+++ b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
@@ -269,7 +269,7 @@ public class ResourceMetadataManagerBeanTest extends MetadataBeanTest {
);
}
- @Test(enabled = false, dependsOnMethods = {"upgradePlugin"}, groups = {"plugin.metadata", "UpgradePlugin"})
+ @Test(dependsOnMethods = {"upgradePlugin"}, groups = {"plugin.metadata", "UpgradePlugin"})
public void upgradeDriftConfigurationTemplates() throws Exception {
ResourceType type = assertResourceTypeAssociationEquals(
"ServerA",
12 years, 11 months