modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java
| 14 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
| 20 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
| 4
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
| 5
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/ChangeSetManagerImplTest.java
| 4
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
| 105 ----------
6 files changed, 26 insertions(+), 126 deletions(-)
New commits:
commit 79e94f05ae84b852f1dd2c1b8d2df77d34f34a28
Author: John Sanda <jsanda(a)redhat.com>
Date: Tue Jun 28 10:26:05 2011 -0400
Changing DriftAgentService.requestDriftFile to take a Headers arg
The headers from the change set meta data file is what is really needed
to locate the drift files. Like the drift config, it contains the drift
config name and basedir, but it will also contain a version number that
may be needed. That version number is not stored in the drift config.
Refactoring ChangeSetManager APIs to only require what is needed for
arguments.
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 154d2cd..06af0ae 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
@@ -5,6 +5,7 @@ import java.io.IOException;
import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.ChangeSetWriter;
+import org.rhq.common.drift.Headers;
import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftConfiguration;
@@ -14,11 +15,12 @@ public interface ChangeSetManager {
* Locates the latest change set for the specified resource id and drift
configuration.
*
* @param resourceId The id of the resource to which the change set belongs
- * @param driftConfiguration The drift configuration for which the change set was
generated
+ * @param driftConfigurationName The name of the drift configuration for which the
+ * change set was generated
* @return The change set file or null if it is not found
* @throws IOException
*/
- File findChangeSet(int resourceId, DriftConfiguration driftConfiguration) throws
IOException;
+ File findChangeSet(int resourceId, String driftConfigurationName) throws
IOException;
/**
* Locates the latest change set for the given resource and drift configuration and
@@ -27,15 +29,15 @@ public interface ChangeSetManager {
* are required to uniquely identify a particular change set.
*
* @param resourceId The id of the resource to which the change set belongs
- * @param driftConfiguration The drift configuration for which the change set was
generated
+ * @param driftConfigurationName The name of the drift configuration for which the
+ * change set was generated
* @return A ChangeSetReader that is open on the change set identified by resourceId
* and driftConfiguration. Returns null if no change set has previously been
generated.
* @see ChangeSetReader
*/
- ChangeSetReader getChangeSetReader(int resourceId, DriftConfiguration
driftConfiguration) throws IOException;
+ ChangeSetReader getChangeSetReader(int resourceId, String driftConfigurationName)
throws IOException;
- ChangeSetWriter getChangeSetWriter(int resourceId, DriftConfiguration
driftConfiguration,
- DriftChangeSetCategory type) throws IOException;
+ ChangeSetWriter getChangeSetWriter(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 33be5bb..aae887d 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
@@ -9,6 +9,7 @@ import org.rhq.common.drift.ChangeSetReader;
import org.rhq.common.drift.ChangeSetReaderImpl;
import org.rhq.common.drift.ChangeSetWriter;
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;
@@ -23,8 +24,8 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
@Override
- public File findChangeSet(int resourceId, DriftConfiguration driftConfiguration)
throws IOException {
- File changeSetDir = findChangeSetDir(resourceId, driftConfiguration);
+ public File findChangeSet(int resourceId, String driftConfigurationName) throws
IOException {
+ File changeSetDir = findChangeSetDir(resourceId, driftConfigurationName);
File changeSetFile = new File(changeSetDir, "changeset.txt");
if (changeSetFile.exists()) {
@@ -35,9 +36,9 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
@Override
- public ChangeSetReader getChangeSetReader(int resourceId, DriftConfiguration
driftConfiguration)
+ public ChangeSetReader getChangeSetReader(int resourceId, String
driftConfigurationName)
throws IOException {
- File changeSetFile = findChangeSet(resourceId, driftConfiguration);
+ File changeSetFile = findChangeSet(resourceId, driftConfigurationName);
if (changeSetFile == null) {
return null;
@@ -47,29 +48,28 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
@Override
- public ChangeSetWriter getChangeSetWriter(int resourceId, DriftConfiguration
driftConfiguration,
- DriftChangeSetCategory type) throws IOException {
+ public ChangeSetWriter getChangeSetWriter(int resourceId, Headers headers) throws
IOException {
File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
- File changeSetDir = new File(resourceDir, driftConfiguration.getName());
+ File changeSetDir = new File(resourceDir, headers.getDriftConfigurationName());
if (!changeSetDir.exists()) {
changeSetDir.mkdirs();
}
- return new ChangeSetWriterImpl(new File(changeSetDir, "changeset.txt"),
driftConfiguration, type);
+ return new ChangeSetWriterImpl(new File(changeSetDir, "changeset.txt"),
headers);
}
@Override
public void addFileToChangeSet(int resourceId, DriftConfiguration driftConfiguration,
File file) {
}
- private File findChangeSetDir(int resourceId, DriftConfiguration driftConfiguration)
{
+ private File findChangeSetDir(int resourceId, String driftConfigurationName) {
File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
if (!resourceDir.exists()) {
return null;
}
- return new File(resourceDir, driftConfiguration.getName());
+ return new File(resourceDir, driftConfigurationName);
}
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 244ea54..40524ed 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
@@ -13,6 +13,7 @@ import org.apache.commons.logging.LogFactory;
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;
@@ -56,7 +57,8 @@ public class DriftDetector implements Runnable {
// if there is no previous changeset then we need to generate the initial
// coverage changeset
ChangeSetWriter writer =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
- schedule.getDriftConfiguration(), COVERAGE);
+ new Headers(schedule.getDriftConfiguration().getName(),
schedule.getDriftConfiguration().getBasedir(),
+ COVERAGE));
DirectoryScanner scanner = new
DirectoryScanner(schedule.getDriftConfiguration(), writer);
scanner.scan();
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 cfe9137..2560147 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
@@ -13,6 +13,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
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.DriftConfiguration;
@@ -72,7 +73,7 @@ public class DriftManager extends AgentService implements
DriftAgentService, Con
public void sendChangeSetToServer(int resourceId, DriftConfiguration
driftConfiguration) {
try {
- File changeSetFile = changeSetMgr.findChangeSet(resourceId,
driftConfiguration);
+ File changeSetFile = changeSetMgr.findChangeSet(resourceId,
driftConfiguration.getName());
if (changeSetFile == null) {
log
.warn("changeset[resourceId: " + resourceId + ",
driftConfiguration: "
@@ -142,7 +143,7 @@ public class DriftManager extends AgentService implements
DriftAgentService, Con
}
@Override
- public boolean requestDriftFiles(int resourceId, String driftConfigurationName,
List<DriftFile> driftFiles) {
+ public boolean requestDriftFiles(int resourceId, Headers headers,
List<DriftFile> driftFiles) {
return false;
}
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 f839eb2..c7e14ed 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
@@ -37,7 +37,7 @@ public class ChangeSetManagerImplTest {
public void returnNullReaderWhenNoChangeSetExists() throws Exception {
int resourceId = -1;
ChangeSetManager changeSetMgr = new ChangeSetManagerImpl(changeSetsDir);
- ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId,
driftConfiguration("test", "server"));
+ ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId,
"test");
assertNull(reader, "Expect null for the reader when no change set exists for
the drift configuration.");
}
@@ -59,7 +59,7 @@ public class ChangeSetManagerImplTest {
writeLines(new File(changeSetDir, "changeset.txt"), changeSet);
ChangeSetManager changeSetMgr = new ChangeSetManagerImpl(changeSetsDir);
- ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId,
drfitConfig);
+ ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId,
"test-1");
assertNotNull(reader, "Expected to get a change set reader when change set
exists");
assertReaderOpenedOnChangeSet(reader, asList("server/conf",
"1"));
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
deleted file mode 100644
index e96c1e9..0000000
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package org.rhq.core.pc.drift;
-
-import java.io.File;
-
-import org.jmock.Expectations;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import org.rhq.common.drift.ChangeSetWriterImpl;
-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 org.rhq.test.JMockTest;
-
-import static org.apache.commons.io.FileUtils.touch;
-import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
-import static org.testng.Assert.*;
-import static org.apache.commons.io.FileUtils.deleteDirectory;
-
-public class DriftDetectorTest extends JMockTest {
-
- File resourcesDir;
-
- File changeSetsDir;
-
- ScheduleQueue queue;
-
- ChangeSetManager changeSetMgr;
-
- @BeforeClass
- public void resetDataDir() throws Exception {
- File basedir = new File("target", getClass().getSimpleName());
- deleteDirectory(basedir);
-
- resourcesDir = new File(basedir, "resources");
- changeSetsDir = new File(basedir, "changesets");
-
- assertTrue(resourcesDir.mkdirs(), "Failed to create " +
resourcesDir.getAbsolutePath());
- assertTrue(changeSetsDir.mkdirs(), "Failed to create " +
changeSetsDir.getAbsolutePath());
- }
-
- @BeforeMethod
- public void initTest() {
- queue = context.mock(ScheduleQueue.class);
- changeSetMgr = context.mock(ChangeSetManager.class);
- }
-
- @Test(enabled = false)
- public void generateInitialChangeSet() throws Exception {
- File server = new File(resourcesDir, "server");
- File lib = new File(server, "lib");
- lib.mkdirs();
-
- touch(new File(lib, "mylib1.jar"));
- touch(new File(lib, "mylib2.jar"));
-
- File nativeLib = new File(lib, "native");
- nativeLib.mkdir();
- touch(new File(nativeLib, "my-native-lib-1.so"));
- touch(new File(nativeLib, "my-native-lib-2.so"));
-
- final DriftConfiguration driftConfig = driftConfiguration("test",
server.getPath());
-
- final File changeSetDir = new File(changeSetsDir, "1-test");
- changeSetDir.mkdir();
-
- // Note that absence of meta data is not sufficient for determining that
- // no change sets have previously been generated. The user could have just
- // deleted the data directory. We need to track what the current change set
- // is. That probably needs to hang off of the resource so it is obtained
- // during inventory sync when the agent starts up.
-
- final DriftDetectionSchedule schedule = new DriftDetectionSchedule(1,
driftConfig);
-
- context.checking(new Expectations() {{
- allowing(queue).dequeue(); will(returnValue(schedule));
-
- allowing(queue).enqueue(with(any(DriftDetectionSchedule.class)));
-
- allowing(changeSetMgr).getChangeSetReader(schedule.getResourceId(),
schedule.getDriftConfiguration());
- will(returnValue(new DriftDetectionSchedule(1, driftConfig)));
-
- allowing(changeSetMgr).getChangeSetWriter(1,
schedule.getDriftConfiguration(), COVERAGE);
- will(returnValue(new ChangeSetWriterImpl(new File(changeSetDir,
"test"),
- schedule.getDriftConfiguration(), COVERAGE)));
- }});
-
- DriftDetector driftDetector = new DriftDetector();
- driftDetector.setScheduleQueue(queue);
- driftDetector.setChangeSetManager(changeSetMgr);
-
- driftDetector.run();
- }
-
- DriftConfiguration driftConfiguration(String name, String basedir) {
- Configuration config = new Configuration();
- config.put(new PropertySimple("name", name));
- config.put(new PropertySimple("basedir", basedir));
-
- return new DriftConfiguration(config);
- }
-
-}