modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetReaderImpl.java
| 4
modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetWriterImpl.java
| 4
modules/common/drift/src/main/java/org/rhq/common/drift/Headers.java
| 28
modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetReaderImplTest.java
| 16
modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetWriterImplTest.java
| 16
modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
| 48
modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/metadata/PluginMetadataParser.java
| 2
modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
| 10
modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
| 16
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftChangeSetCriteria.java
| 4
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftConfigurationCriteria.java
| 87
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftDefinitionCriteria.java
| 85
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/GenericDriftChangeSetCriteria.java
| 10
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/JPADriftChangeSetCriteria.java
| 20
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceCriteria.java
| 6
modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceTypeCriteria.java
| 6
modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftChangeSet.java
| 44
modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftComposite.java
| 2
modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
| 421 ---
modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationComparator.java
| 140 -
modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDefinition.java
| 421 +++
modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDefinitionComparator.java
| 140 +
modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADrift.java
| 6
modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADriftChangeSet.java
| 36
modules/core/domain/src/main/java/org/rhq/core/domain/drift/dto/DriftChangeSetDTO.java
| 4
modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
| 22
modules/core/domain/src/main/java/org/rhq/core/domain/resource/ResourceType.java
| 16
modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftConfigurationTest.java
| 50
modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftSnapshotTest.java
| 4
modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java
| 2
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManager.java
| 20
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ChangeSetManagerImpl.java
| 33
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftClient.java
| 8
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetectionSchedule.java
| 22
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftDetector.java
| 118 -
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java
| 6
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftManager.java
| 255 +-
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueue.java
| 42
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueueImpl.java
| 51
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
| 47
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSynchronizer.java
| 46
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/RuntimeSynchronizer.java
| 64
modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/StartupSynchronizer.java
| 62
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
| 84
modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
| 22
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/DriftClientTestStub.java
| 6
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftDetectorTest.java
| 261 +-
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftFilesSenderTest.java
| 4
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
| 87
modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftTest.java
| 42
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java
| 60
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java
| 10
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
| 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/Carousel.java
| 1135 ++++++++++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/CarouselMember.java
| 35
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/CarouselWidget.java
| 28
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
| 91
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeDataSource.java
| 8
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeView.java
| 34
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftCarouselMemberView.java
| 189 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftCarouselView.java
| 201 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationDataSource.java
| 289 --
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
| 194 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationView.java
| 243 --
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDataSource.java
| 25
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionDataSource.java
| 313 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionEditView.java
| 192 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionsView.java
| 259 ++
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
| 2
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftHistoryView.java
| 7
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeDataSource.java
| 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeView.java
| 20
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftConfigurationView.java
| 40
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftDefinitionsView.java
| 40
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/AbstractDriftAddConfigWizard.java
| 93
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/AbstractDriftAddDefinitionWizard.java
| 93
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizard.java
| 159 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizardConfigStep.java
| 76
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizardInfoStep.java
| 125 -
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizard.java
| 160 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizardConfigStep.java
| 76
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizardInfoStep.java
| 125 +
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
| 42
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
| 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
| 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/type/ResourceTypeRepository.java
| 12
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestDataSourceResponseStatisticsView.java
| 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestRemoteServiceStatisticsView.java
| 6
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
| 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
| 37
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/ResourceGWTServiceImpl.java
| 2
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages.properties
| 11
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
| 11
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
| 11
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
| 11
modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
| 11
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
| 127 -
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
| 36
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
| 32
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
| 65
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerLocal.java
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftChangeSetSummary.java
| 15
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftServerPluginFacet.java
| 10
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
| 4
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBean.java
| 8
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftManagerBeanTest.java
| 176 -
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/inventory/UninventoryTest.java
| 42
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/resource/metadata/ResourceMetadataManagerBeanTest.java
| 20
modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/TestAgentClient.java
| 10
modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/MongoDBDriftServer.java
| 8
modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSet.java
| 4
modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSetEntry.java
| 2
modules/enterprise/server/plugins/drift-mongodb/src/test/java/org/rhq/enterprise/server/plugins/drift/mongodb/dao/ChangeSetDAOTest.java
| 12
modules/enterprise/server/plugins/drift-rhq/src/main/java/org/rhq/enterprise/server/plugins/drift/JPADriftServerPluginComponent.java
| 4
116 files changed, 4832 insertions(+), 3201 deletions(-)
New commits:
commit 4d56f0b1e2f567ac333804fea42803ba757e6696
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Sep 29 23:08:28 2011 -0400
Make sure our renamed resource field does not get wiped when sent to the
gui.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/ResourceGWTServiceImpl.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/ResourceGWTServiceImpl.java
index 694fafd..89e217e 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/ResourceGWTServiceImpl.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/ResourceGWTServiceImpl.java
@@ -107,7 +107,7 @@ public class ResourceGWTServiceImpl extends AbstractGWTServiceImpl
implements Re
// "eventSources \n" +
// "productVersion "}
"tags", //
- "driftConfigurations" };
+ "driftDefinitions" };
public static Set<String> importantFieldsSet = new
HashSet<String>(Arrays.asList(importantFields));
commit 55a79bc86a143d766a8ca7df69a0f2ddc1e04943
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Sep 29 23:07:44 2011 -0400
Fix a variety of merge issues. Hopefully got them all.
diff --git
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
index c121cfa..4a2d134 100644
---
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
+++
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
@@ -52,7 +52,7 @@ public interface DriftAgentService {
* Because the drift detection happens asynchronously, it cannot be guaranteed that
the
* drift detection will actually happen immediately. Drift detection schedules are
* maintained by a priority queue and are ordered by their next scan time. The
schedule
- * corresponding to <code>resourceId</code> and
<code>driftConfiguration</code> has its
+ * corresponding to <code>resourceId</code> and
<code>driftDefinition</code> has its
* next scan time reset in order to move the schedule to the front of the queue.
* <p/>
* Note that when the drift detection occurs is largely dependent on a couple of
@@ -64,72 +64,72 @@ public interface DriftAgentService {
* finish plus the time period between executions of the drift detector task.
*
* @param resourceId The id of the resource for which the request is being made
- * @param driftConfiguration Specifies how the detection should be carried out. This
+ * @param driftDefinition Specifies how the detection should be carried out. This
* includes any filtering rules that should be applied.
*/
- void detectDrift(int resourceId, DriftDefinition driftConfiguration);
+ void detectDrift(int resourceId, DriftDefinition driftDefinition);
/**
* Requests that the agent start performing drift detection for a resource with the
- * specified drift configuration. The interval at which the drift detection occurs
is
- * specified by the drift configuration.
+ * specified drift definition. The interval at which the drift detection occurs is
+ * specified by the drift definition.
* <p/>
* Note that drift detection occurs asynchronously which means that this method
should
- * return very quickly which could be before the drift detection for this
configuration
+ * return very quickly which could be before the drift detection for this definition
* has actually started.
*
* @param resourceId The id of the resource for which the request is being made
- * @param driftConfiguration Specifies how and when the detection should be carried
out
+ * @param driftDefinition Specifies how and when the detection should be carried out
* @see DriftDefinition
*/
- void scheduleDriftDetection(int resourceId, DriftDefinition driftConfiguration);
+ void scheduleDriftDetection(int resourceId, DriftDefinition driftDefinition);
/**
* Requests that the agent stop performing the specified drift detection for the
resource. (In
* effect, a remove operation).
*
* @param resourceId The id of the resource for which the request is being made
- * @param driftConfiguration The doomed drift config
+ * @param driftDefinition The doomed drift config
* @see DriftDefinition
*/
- void unscheduleDriftDetection(int resourceId, DriftDefinition driftConfiguration);
+ void unscheduleDriftDetection(int resourceId, DriftDefinition driftDefinition);
/**
- * Requests that the agent update its processing of the specified driftConfiguration.
The filters
+ * Requests that the agent update its processing of the specified driftDefinition.
The filters
* are unchanged, but something else may have changed (enablement/interval, etc).
*
* @param resourceId The id of the resource for which the request is being made
- * @param driftConfiguration The updated driftConfiguration.
+ * @param driftDefinition The updated driftDefinition.
* @see DriftDefinition
*/
- void updateDriftDetection(int resourceId, DriftDefinition driftConfiguration);
+ void updateDriftDetection(int resourceId, DriftDefinition driftDefinition);
/**
* This method is invoked to inform the agent that the server has successfully
* persisted the last change set sent to the server for the specified drift
- * configuration. The agent will proceed to purge the older, previous snapshot
+ * definition. The agent will proceed to purge the older, previous snapshot
* as well as the the change set zip file.
* <br/><br/>
* <strong>Note:</strong> The agent will not resume drift detection for
this drift
- * configuration until the server has acknowledged the last change set sent.
+ * definition until the server has acknowledged the last change set sent.
*
* @param resourceId The id of the resource to which the acknowledged change set
* belongs.
- * @param driftConfigName The name of the drift configuration to which the change
set
+ * @param driftDefName The name of the drift definition to which the change set
* belongs.
*/
- void ackChangeSet(int resourceId, String driftConfigName);
+ void ackChangeSet(int resourceId, String driftDefName);
/**
* This method is invoked to inform the agent that the server has successfully
* persisted change set content that was previously sent to the server. The agent
* will proceed to purge the referenced content zip file.
*
- * @param resourceId The id of the resource to which the referenced drift
configuration
+ * @param resourceId The id of the resource to which the referenced drift definition
* belongs.
- * @param driftConfigName The name of the drift configuration to which the content
+ * @param driftDefName The name of the drift definition to which the content
* belongs.
* @param token A token that is used to identify the content zip file
*/
- void ackChangeSetContent(int resourceId, String driftConfigName, String token);
+ void ackChangeSetContent(int resourceId, String driftDefName, String token);
}
\ No newline at end of file
diff --git
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
index c7c88ef..f476263 100644
---
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
+++
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
@@ -107,7 +107,7 @@ public interface DriftServerService {
* for the acknowledgement step.
*
* @param resourceId The id of the resource to which the change set content belongs
- * @param driftConfigName The drift configuration name. This is needed for the
+ * @param driftDefName The drift definition name. This is needed for the
* acknowledgement step.
* @param token A token needed for the acknowledgement step that allows the agent to
* uniquely identify the zip file that was sent.
@@ -115,9 +115,9 @@ public interface DriftServerService {
* @param zipStream A RemoteStream
*/
@Asynchronous(guaranteedDelivery = true)
- void sendFilesZip(int resourceId, String driftConfigName, String token, long zipSize,
InputStream zipStream);
+ void sendFilesZip(int resourceId, String driftDefName, String token, long zipSize,
InputStream zipStream);
Map<Integer, List<DriftDefinition>>
getDriftDefinitions(Set<Integer> resourceIds);
- DriftSnapshot getCurrentSnapshot(int driftConfigurationId);
+ DriftSnapshot getCurrentSnapshot(int driftDefinitionId);
}
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 cba943f..8f8c23d 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
@@ -28,6 +28,7 @@ import static org.rhq.core.util.file.FileUtil.copyFile;
import static org.rhq.core.util.file.FileUtil.forEachFile;
import java.io.File;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedList;
@@ -71,7 +72,7 @@ public class DriftDetector implements Runnable {
@Override
public void run() {
- log.debug("Starting drift detection..");
+ log.debug("Starting drift detection...");
long startTime = System.currentTimeMillis();
try {
if (log.isDebugEnabled()) {
@@ -99,25 +100,30 @@ public class DriftDetector implements Runnable {
return;
}
- DriftDefinition driftDef = schedule.getDriftDefinition();
- DriftChangeSetCategory changeSetType = null;
- int changes = 0;
+ if (previousSnapshotExists(schedule)) {
+ log.debug("Skipping " + schedule + " because server has
not yet acked previous change set");
+ return;
+ }
+ DriftDetectionSummary detectionSummary = new DriftDetectionSummary();
+ detectionSummary.setSchedule(schedule);
try {
if (changeSetMgr.changeSetExists(schedule.getResourceId(),
createHeaders(schedule, COVERAGE, 0))) {
- changeSetType = DRIFT;
- changes = generateDriftChangeSet(schedule);
+ detectionSummary.setType(DRIFT);
+ generateDriftChangeSet(detectionSummary);
} else {
- changeSetType = COVERAGE;
- generateSnapshot(schedule);
+ detectionSummary.setType(COVERAGE);
+ generateSnapshot(detectionSummary);
+ }
+ if (detectionSummary.getType() == COVERAGE ||
detectionSummary.getDriftChangeSet() != null) {
+ driftClient.sendChangeSetToServer(detectionSummary);
}
} 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);
- }
-
- if (changeSetType == COVERAGE || changes > 0) {
- driftClient.sendChangeSetToServer(schedule.getResourceId(), driftDef,
changeSetType);
+ log.error("Drift detection failed: " + e.getMessage(), e);
+ revertSnapshot(detectionSummary);
+ } catch (RuntimeException e) {
+ log.error("Drift detection failed: " + e.getMessage(), e);
+ revertSnapshot(detectionSummary);
}
} catch (Throwable t) {
Throwable cause = t.getCause();
@@ -138,12 +144,22 @@ public class DriftDetector implements Runnable {
}
}
- private int generateDriftChangeSet(final DriftDetectionSchedule schedule) throws
IOException {
+ private boolean previousSnapshotExists(DriftDetectionSchedule schedule) {
+ File snapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
schedule.getDriftDefinition().getName(),
+ COVERAGE);
+ File previousSnapshot = new File(snapshot.getParentFile(), snapshot.getName() +
".previous");
+ return previousSnapshot.exists();
+ }
+
+ private void generateDriftChangeSet(DriftDetectionSummary summary) throws IOException
{
+ final DriftDetectionSchedule schedule = summary.getSchedule();
+
log.debug("Generating drift change set for " + schedule);
final File basedir = new File(basedir(schedule.getResourceId(),
schedule.getDriftDefinition()));
- final ChangeSetReader coverageReader =
changeSetMgr.getChangeSetReader(schedule.getResourceId(), schedule
- .getDriftDefinition().getName());
+ File currentSnapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
schedule.getDriftDefinition()
+ .getName(), COVERAGE);
+ final ChangeSetReader coverageReader =
changeSetMgr.getChangeSetReader(currentSnapshot);
final Set<File> processedFiles = new HashSet<File>();
final List<FileEntry> snapshotEntries = new LinkedList<FileEntry>();
final List<FileEntry> deltaEntries = new LinkedList<FileEntry>();
@@ -154,16 +170,22 @@ public class DriftDetector implements Runnable {
File file = new File(basedir, entry.getFile());
if (!file.exists()) {
// The file has been deleted since the last scan
- if (log.isInfoEnabled()) {
- log.info("Detected deleted file for " + schedule + "
--> " + file.getAbsolutePath());
+ if (log.isDebugEnabled()) {
+ log.debug("Detected deleted file for " + schedule + "
--> " + file.getAbsolutePath());
+ }
+ deltaEntries.add(removedFileEntry(entry.getFile(), entry.getNewSHA()));
+ } else if (!file.canRead()) {
+ processedFiles.add(file);
+ if (log.isDebugEnabled()) {
+ log.debug(file.getPath() + " is no longer readable. Treating it
as a deleted file.");
}
deltaEntries.add(removedFileEntry(entry.getFile(), entry.getNewSHA()));
} else {
processedFiles.add(file);
String currentSHA = sha256(file);
if (!currentSHA.equals(entry.getNewSHA())) {
- if (log.isInfoEnabled()) {
- log.info("Detected modified file for " + schedule +
" --> " + file.getAbsolutePath());
+ if (log.isDebugEnabled()) {
+ log.debug("Detected modified file for " + schedule +
" --> " + file.getAbsolutePath());
}
FileEntry modifiedEntry = changedFileEntry(entry.getFile(),
entry.getNewSHA(), currentSHA);
deltaEntries.add(modifiedEntry);
@@ -187,6 +209,13 @@ public class DriftDetector implements Runnable {
return;
}
+ if (!file.canRead()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Skipping " + file.getPath() + "
since it is not readable.");
+ return;
+ }
+ }
+
if (log.isInfoEnabled()) {
log.info("Detected added file for " + schedule +
" --> " + file.getAbsolutePath());
}
@@ -205,39 +234,47 @@ public class DriftDetector implements Runnable {
if (deltaEntries.isEmpty()) {
// If nothing has changed, there is no need to add/update any files
- return 0;
- }
-
- File snapshotFile = changeSetMgr.findChangeSet(schedule.getResourceId(),
schedule.getDriftDefinition()
- .getName(), COVERAGE);
- File backupSnapshotFile = new File(snapshotFile.getParentFile(),
snapshotFile.getName() + ".bak");
- copyFile(snapshotFile, snapshotFile);
-
- Headers deltaHeaders = createHeaders(schedule, DRIFT, newVersion);
- Headers snapshotHeaders = createHeaders(schedule, COVERAGE, newVersion);
-
- ChangeSetWriter deltaWriter =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(), deltaHeaders);
- ChangeSetWriter snapshotWriter =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(), snapshotHeaders);
-
- for (FileEntry entry : deltaEntries) {
- deltaWriter.write(entry);
- }
- deltaWriter.close();
+ summary.setNewSnapshot(currentSnapshot);
+ } else {
+ File oldSnapshot = new File(currentSnapshot.getParentFile(),
currentSnapshot.getName() + ".previous");
+ copyFile(currentSnapshot, oldSnapshot);
+ currentSnapshot.delete();
+
+ Headers deltaHeaders = createHeaders(schedule, DRIFT, newVersion);
+ Headers snapshotHeaders = createHeaders(schedule, COVERAGE, newVersion);
+
+ File driftChangeSet = changeSetMgr.findChangeSet(schedule.getResourceId(),
schedule.getDriftDefinition()
+ .getName(), DRIFT);
+ ChangeSetWriter deltaWriter = changeSetMgr.getChangeSetWriter(driftChangeSet,
deltaHeaders);
+
+ File newSnapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
schedule.getDriftDefinition()
+ .getName(), COVERAGE);
+ ChangeSetWriter newSnapshotWriter =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
+ snapshotHeaders);
+
+ summary.setDriftChangeSet(driftChangeSet);
+ summary.setNewSnapshot(newSnapshot);
+ summary.setOldSnapshot(oldSnapshot);
+
+ for (FileEntry entry : deltaEntries) {
+ deltaWriter.write(entry);
+ }
+ deltaWriter.close();
- for (FileEntry entry : snapshotEntries) {
- snapshotWriter.write(entry);
+ for (FileEntry entry : snapshotEntries) {
+ newSnapshotWriter.write(entry);
+ }
+ newSnapshotWriter.close();
}
- snapshotWriter.close();
- backupSnapshotFile.delete();
-
- return deltaEntries.size();
}
- private void generateSnapshot(final DriftDetectionSchedule schedule) throws
IOException {
+ private void generateSnapshot(DriftDetectionSummary summary) throws IOException {
+ final DriftDetectionSchedule schedule = summary.getSchedule();
log.debug("Generating coverage change set for " + schedule);
- final ChangeSetWriter writer =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(), createHeaders(
- schedule, COVERAGE, 0));
+ File snapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
schedule.getDriftDefinition().getName(),
+ COVERAGE);
+ final ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(snapshot,
createHeaders(schedule, COVERAGE, 0));
final DriftDefinition driftDef = schedule.getDriftDefinition();
final File basedir = new File(basedir(schedule.getResourceId(), driftDef));
if (basedir.isDirectory()) {
@@ -247,10 +284,14 @@ public class DriftDetector implements Runnable {
@Override
public void visit(File file) {
try {
- if (log.isInfoEnabled()) {
- log
- .info("Adding " + file.getAbsolutePath() +
" to coverage change set for "
- + schedule);
+ if (!file.canRead()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Skipping " + file.getPath() +
" since it is not readable.");
+ }
+ return;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Adding " + file.getPath() + "
to coverage change set for " + schedule);
}
writer.write(addedFileEntry(relativePath(basedir, file),
sha256(file)));
} catch (IOException e) {
@@ -263,6 +304,7 @@ public class DriftDetector implements Runnable {
}));
}
writer.close();
+ summary.setNewSnapshot(snapshot);
}
private String relativePath(File basedir, File file) {
@@ -292,4 +334,50 @@ public class DriftDetector implements Runnable {
return headers;
}
+ private void revertSnapshot(DriftDetectionSummary summary) throws IOException {
+ log.info("Reverting snapshot for " + summary.getSchedule());
+
+ DriftDetectionSchedule scheudle = summary.getSchedule();
+ File newSnapshot = changeSetMgr.findChangeSet(scheudle.getResourceId(),
+ scheudle.getDriftDefinition().getName(), COVERAGE);
+
+ // We want to delete the snapshot file regardless of whether the drift detection
+ // was for an initial coverage change set or for a drift change set. We do not
know
+ // the state of the snapshot file so we have to delete it. If we have only
generated
+ // the initial coverage change set, then it will get regenerated.
+ newSnapshot.delete();
+
+ if (summary.getType() == DRIFT) {
+ File oldSnapshotBackup = summary.getOldSnapshot();
+ // If we generated a drift change set, we need to check for a back up of the
+ // previous snapshot. We revert to the back up. If no back up is found, we
log
+ // an error.
+ if (oldSnapshotBackup != null && oldSnapshotBackup.exists()) {
+ copyFile(oldSnapshotBackup, newSnapshot);
+ // We have to delete to the previous version snapshot file; otherwise,
+ // subsequent detection runs will be skipped.
+ oldSnapshotBackup.delete();
+ } else {
+ // TODO Should we throw an exception and/or disable detection?
+ // If we fall into this else block, that means we were not able to
revert
+ // to the previous snapshot version, and we may be in an inconsistent
state.
+ log.error("Cannot revert snapshot to previous version for " +
summary.getSchedule()
+ + ". Snapshot back up file not found.");
+ }
+ }
+ deleteZipFiles(newSnapshot.getParentFile());
+ }
+
+ private void deleteZipFiles(File dir) {
+ File[] files = dir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".zip");
+ }
+ });
+ for (File file : files) {
+ file.delete();
+ }
+ }
+
}
\ No newline at end of file
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 f655dd7..74ed3d4 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
@@ -22,14 +22,16 @@ package org.rhq.core.pc.drift;
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.DriftDefinitionComparator.CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
import static org.rhq.core.util.file.FileUtil.purge;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -46,9 +48,7 @@ import org.rhq.core.clientapi.agent.drift.DriftAgentService;
import org.rhq.core.clientapi.server.drift.DriftServerService;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.drift.Drift;
-import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftDefinition;
-import org.rhq.core.domain.drift.DriftDefinitionComparator;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.resource.Resource;
@@ -94,6 +94,7 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
@Override
public void initialize() {
+ long initStartTime = System.currentTimeMillis();
changeSetsDir.mkdir();
changeSetMgr = new ChangeSetManagerImpl(changeSetsDir);
@@ -106,8 +107,12 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
long startTime = System.currentTimeMillis();
initSchedules(inventoryMgr.getPlatform(), inventoryMgr);
long endTime = System.currentTimeMillis();
- log.info("Finished initializing drift detection schedules in " +
(endTime - startTime) + " ms");
+ if (log.isInfoEnabled()) {
+ log.info("Finished initializing drift detection schedules in " +
(endTime - startTime) + " ms");
+ }
+
+ scanForContentToResend();
purgeDeletedDriftDefDirs();
driftThreadPool = new ScheduledThreadPoolExecutor(5);
@@ -122,6 +127,10 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
initialized = true;
+ long initEndTime = System.currentTimeMillis();
+ if (log.isInfoEnabled()) {
+ log.info("Finished initialization in " + (initEndTime -
initStartTime) + " ms");
+ }
}
private void initSchedules(Resource r, InventoryManager inventoryMgr) {
@@ -152,32 +161,34 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
}
- private void syncWithServer(Resource resource, DriftDefinition driftDef) throws
IOException {
- Headers headers = createHeaders(resource, driftDef);
+ private void syncWithServer(Resource resource, DriftDefinition driftDefinition)
throws IOException {
+ Headers headers = createHeaders(resource, driftDefinition);
if (!changeSetMgr.changeSetExists(resource.getId(), headers)) {
- log.info("No snapshot found for " + toString(resource, driftDef) +
". Downloading snapshot from "
+ log.info("No snapshot found for " + toString(resource,
driftDefinition) + ". Downloading snapshot from "
+ "server");
DriftSnapshot snapshot =
pluginContainerConfiguration.getServerServices().getDriftServerService()
- .getCurrentSnapshot(driftDef.getId());
+ .getCurrentSnapshot(driftDefinition.getId());
if (snapshot.getVersion() == -1) {
// A version of -1 indicates that no change sets have been reported
- // for this def. This can occur when a user creates a
- // drift def while the agent is offline for example. At
+ // for this definition. This can occur when a user creates a
+ // drift definition while the agent is offline for example. At
// this point we just return and allow the agent to generate the
// initial snapshot file.
if (log.isDebugEnabled()) {
- log.debug("The server does not have any change sets for " +
toString(resource, driftDef)
+ log.debug("The server does not have any change sets for " +
toString(resource, driftDefinition)
+ ". An initial snapshot needs to be generated.");
}
return;
}
+ headers.setVersion(snapshot.getVersion());
+
log.info("Preparing to write snapshot at version " +
snapshot.getVersion() + " to disk for "
- + toString(resource, driftDef));
+ + toString(resource, driftDefinition));
ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resource.getId(),
headers);
- for (Drift drift : snapshot.getEntries()) {
+ for (Drift<?, ?> drift : snapshot.getEntries()) {
switch (drift.getCategory()) {
case FILE_ADDED:
writer.write(addedFileEntry(drift.getPath(),
drift.getNewDriftFile().getHashId()));
@@ -196,15 +207,13 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
private void purgeDeletedDriftDefDirs() {
log.info("Checking for deleted drift definitions");
- DriftDefinitionComparator comparator = new DriftDefinitionComparator(
- BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
for (File resourceDir : changeSetsDir.listFiles()) {
int resourceId = Integer.parseInt(resourceDir.getName());
for (File defDir : resourceDir.listFiles()) {
- DriftDefinition def = new DriftDefinition(new Configuration());
- def.setName(defDir.getName());
- if (!schedulesQueue.contains(resourceId, def)) {
- log.info("Detected deleted drift definition,
DriftDefinition[name: " + def.getName()
+ DriftDefinition driftDef = new DriftDefinition(new Configuration());
+ driftDef.setName(defDir.getName());
+ if (!schedulesQueue.contains(resourceId, driftDef)) {
+ log.info("Detected deleted drift definition,
DriftDefinition[name: " + driftDef.getName()
+ ", resourceId: " + resourceId + "]");
log.info("Deleting drift definition directory " +
defDir.getPath());
purge(defDir, true);
@@ -213,17 +222,40 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
}
+ /**
+ * Scans the changesets directory for any change set content zip files. This method
+ * assumes that any content zip files found have not been received or persisted by
the
+ * server. Each content zip file is resent to the server.
+ */
+ public void scanForContentToResend() {
+ log.info("Scanning for change set content to resend...");
+ for (File resourceDir : changeSetsDir.listFiles()) {
+ for (File defDir : resourceDir.listFiles()) {
+ for (File contentZipFile : defDir.listFiles(new
ZipFileNameFilter("content_"))) {
+ if (log.isDebugEnabled()) {
+ log.debug("Resending " + contentZipFile.getPath());
+ }
+ sendContentZipFile(Integer.parseInt(resourceDir.getName()),
defDir.getName(), contentZipFile);
+ }
+ }
+ }
+ }
+
private String toString(Resource r, DriftDefinition c) {
- return "DriftDefinition[id: " + c.getId() + ", resourceId: "
+ r.getId() + ", name: " + c.getName() + "]";
+ return toString(r.getId(), c);
+ }
+
+ private String toString(int resourceId, DriftDefinition c) {
+ return "DriftDefinition[id: " + c.getId() + ", resourceId: "
+ resourceId + ", name: " + c.getName() + "]";
}
- private Headers createHeaders(Resource resource, DriftDefinition driftDef) {
+ private Headers createHeaders(Resource resource, DriftDefinition driftDefinition) {
Headers headers = new Headers();
headers.setResourceId(resource.getId());
- headers.setDriftDefinitionId(driftDef.getId());
- headers.setType(DriftChangeSetCategory.COVERAGE);
- headers.setDriftDefinitionName(driftDef.getName());
- headers.setBasedir(getAbsoluteBaseDirectory(resource.getId(),
driftDef).getAbsolutePath());
+ headers.setDriftDefinitionId(driftDefinition.getId());
+ headers.setType(COVERAGE);
+ headers.setDriftDefinitionName(driftDefinition.getName());
+ headers.setBasedir(getAbsoluteBaseDirectory(resource.getId(),
driftDefinition).getAbsolutePath());
return headers;
}
@@ -256,55 +288,69 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
@Override
- public void sendChangeSetToServer(int resourceId, DriftDefinition driftDef,
DriftChangeSetCategory type) {
- try {
- if (!schedulesQueue.contains(resourceId, driftDef)) {
- return;
- }
+ public void sendChangeSetToServer(DriftDetectionSummary detectionSummary) {
+ int resourceId = detectionSummary.getSchedule().getResourceId();
+ DriftDefinition driftDefinition =
detectionSummary.getSchedule().getDriftDefinition();
- File changeSetFile = changeSetMgr.findChangeSet(resourceId,
driftDef.getName(), type);
- if (changeSetFile == null) {
- log.warn("changeset[resourceId: " + resourceId + ",
driftDefinition: " + driftDef.getName()
- + "] was not found. Cancelling request to send change set "
+ "to server");
- return;
- }
+ if (!schedulesQueue.contains(resourceId, driftDefinition)) {
+ return;
+ }
- DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
+ File changeSetFile;
+ if (detectionSummary.getType() == COVERAGE) {
+ changeSetFile = detectionSummary.getNewSnapshot();
+ } else {
+ changeSetFile = detectionSummary.getDriftChangeSet();
+ }
+ if (changeSetFile == null) {
+ log.warn("changeset[resourceId: " + resourceId + ",
driftDefinition: " + driftDefinition.getName()
+ + "] was not found. Cancelling request to send change set " +
"to server");
+ return;
+ }
- // TODO Include the version in the change set file name to ensure the file
name is unique
- String fileName = "changeset_" + System.currentTimeMillis() +
".zip";
- final File zipFile = new File(changeSetFile.getParentFile(), fileName);
- ZipOutputStream stream = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(zipFile)));
+ DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
+ String fileName = "changeset_" + System.currentTimeMillis() +
".zip";
+ final File zipFile = new File(changeSetFile.getParentFile(), fileName);
+ ZipOutputStream stream = null;
+
+ try {
+ stream = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(zipFile)));
FileInputStream fis = new FileInputStream(changeSetFile);
stream.putNextEntry(new ZipEntry(changeSetFile.getName()));
StreamUtil.copy(fis, stream, false);
fis.close();
stream.close();
+ } catch (IOException e) {
+ zipFile.delete();
+ throw new DriftDetectionException("Failed to create change set zip file
" + zipFile.getPath(), e);
+ } finally {
+ try {
+ if (stream != null) {
+ stream.close();
+ }
+ } catch (IOException e) {
+ log.warn("An error occurred while trying to close change set zip
file output stream", e);
+ }
+ }
- // We want to clean up after we send the zip file to the server. We do this
by
- // deleting the files in the content directory and the content zip itself.
They
- // are no longer needed after being sent to the server. We cannot
immediately
- // delete the content zip file though because it is sent asynchronously, and
we
- // wind up deleting it before it is sent. The following approach allows us
to
- // safely delete it when the comm layer closes the remote input stream.
- //
- // jsanda
- DriftInputStream inputStream = new DriftInputStream(new
BufferedInputStream(new FileInputStream(zipFile)),
- new DeleteFile(zipFile));
-
- driftServer.sendChangesetZip(resourceId, zipFile.length(),
remoteInputStream(inputStream));
-
+ try {
+ driftServer.sendChangesetZip(resourceId, zipFile.length(),
remoteInputStream(new BufferedInputStream(
+ new FileInputStream(zipFile))));
} catch (IOException e) {
- log.error("An error occurred while trying to send changeset[resourceId:
" + resourceId
- + ", driftDefinition: " + driftDef.getName() + "]",
e);
+ throw new DriftDetectionException("Failed to set change set for " +
toString(resourceId, driftDefinition)
+ + " to server");
+ } catch (RuntimeException e) {
+ throw new DriftDetectionException("Failed to set change set for " +
toString(resourceId, driftDefinition)
+ + " to server");
}
}
@Override
- public void sendChangeSetContentToServer(int resourceId, String driftDefName, final
File contentDir) {
+ public void sendChangeSetContentToServer(int resourceId, String driftDefinitionName,
final File contentDir) {
try {
- String contentFileName = "content_" + System.currentTimeMillis() +
".zip";
+ String timestamp = Long.toString(System.currentTimeMillis());
+ String contentFileName = "content_" + timestamp +
".zip";
final File zipFile = new File(contentDir.getParentFile(), contentFileName);
ZipOutputStream stream = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(zipFile)));
@@ -316,22 +362,13 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
stream.close();
- // We want to clean up after we send the zip file to the server. We do this
by
- // deleting the files in the content directory and the content zip itself.
They
- // are no longer needed after being sent to the server. We cannot
immediately
- // delete the content zip file though because it is sent asynchronously, and
we
- // wind up deleting it before it is sent. The following approach allows us
to
- // safely delete it when the comm layer closes the remote input stream.
- //
- // jsanda
- DriftInputStream inputStream = new DriftInputStream(new
BufferedInputStream(new FileInputStream(zipFile)),
- new DeleteFile(zipFile));
-
- DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
- driftServer.sendFilesZip(resourceId, zipFile.length(),
remoteInputStream(inputStream));
+ // DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
+ // driftServer.sendFilesZip(resourceId, driftDefinitionName,
timestamp, zipFile.length(),
+ // remoteInputStream(new BufferedInputStream(new
FileInputStream(zipFile))));
+ sendContentZipFile(resourceId, driftDefinitionName, zipFile);
} catch (IOException e) {
log.error("An error occurred while trying to send content for
changeset[resourceId: " + resourceId
- + ", driftDefinition: " + driftDefName + "]", e);
+ + ", driftDefinition: " + driftDefinitionName + "]",
e);
}
for (File file : contentDir.listFiles()) {
@@ -341,17 +378,34 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
}
+ private void sendContentZipFile(int resourceId, String driftDefName, File
contentZipFile) {
+ try {
+ int startIndex = "content_".length();
+ int endIndex = contentZipFile.getName().indexOf(".");
+ String token = contentZipFile.getName().substring(startIndex, endIndex);
+
+ DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
+ driftServer.sendFilesZip(resourceId, driftDefName, token,
contentZipFile.length(),
+ remoteInputStream(new BufferedInputStream(new
FileInputStream(contentZipFile))));
+ } catch (FileNotFoundException e) {
+ log.error("An error occurred while trying to send change set content zip
file " + contentZipFile.getPath()
+ + " to server.", e);
+ }
+ }
+
@Override
- public void detectDrift(int resourceId, DriftDefinition driftDef) {
+ public void detectDrift(int resourceId, DriftDefinition driftDefinition) {
if (log.isInfoEnabled()) {
log.info("Received request to schedule drift detection immediately for
[resourceId: " + resourceId
- + ", driftDefId: " + driftDef.getId() + ", driftDefName:
" + driftDef.getName() + "]");
+ + ", driftDefinitionId: " + driftDefinition.getId() + ",
driftDefinitionName: "
+ + driftDefinition.getName() + "]");
}
- DriftDetectionSchedule schedule = schedulesQueue.remove(resourceId, driftDef);
+ DriftDetectionSchedule schedule = schedulesQueue.remove(resourceId,
driftDefinition);
if (schedule == null) {
- log.warn("No schedule found in the queue for [resourceId: " +
resourceId + ", driftDefId: "
- + driftDef.getId() + ", driftDefName: " + driftDef.getName() +
"]. No " + " work will be scheduled.");
+ log.warn("No schedule found in the queue for [resourceId: " +
resourceId + ", driftDefinitionId: "
+ + driftDefinition.getId() + ", driftDefinitionName: " +
driftDefinition.getName() + "]. No "
+ + " work will be scheduled.");
return;
}
log.debug("Resetting " + schedule + " for immediate
detection.");
@@ -368,8 +422,8 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
@Override
- public void scheduleDriftDetection(int resourceId, DriftDefinition driftDef) {
- DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId,
driftDef);
+ public void scheduleDriftDetection(int resourceId, DriftDefinition driftDefinition)
{
+ DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId,
driftDefinition);
if (log.isInfoEnabled()) {
log.info("Scheduling drift detection for " + schedule);
}
@@ -381,7 +435,7 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
ResourceContainer container =
getInventoryManager().getResourceContainer(resourceId);
if (container != null) {
- container.addDriftDefinition(driftDef);
+ container.addDriftDefinition(driftDefinition);
}
} else {
log.warn("Failed to add " + schedule + " to " +
schedulesQueue);
@@ -391,8 +445,8 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
@Override
public boolean requestDriftFiles(int resourceId, Headers headers, List<? extends
DriftFile> driftFiles) {
if (log.isInfoEnabled()) {
- log.info("Server is requesting files for [resourceId: " +
resourceId + ", driftDefId: "
- + headers.getDriftDefinitionId() + ", driftDefName: " +
headers.getDriftDefinitionName() + "]");
+ log.info("Server is requesting files for [resourceId: " +
resourceId + ", driftDefinitionId: "
+ + headers.getDriftDefinitionId() + ", driftDefinitionName: " +
headers.getDriftDefinitionName() + "]");
}
DriftFilesSender sender = new DriftFilesSender();
sender.setResourceId(resourceId);
@@ -407,15 +461,16 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
@Override
- public void unscheduleDriftDetection(final int resourceId, final DriftDefinition
driftDef) {
- log.info("Received request to unschedule drift detection for
[resourceId:" + resourceId + ", driftDefId: "
- + driftDef.getId() + ", driftDefName: " + driftDef.getName() +
"].");
+ public void unscheduleDriftDetection(final int resourceId, final DriftDefinition
driftDefinition) {
+ log.info("Received request to unschedule drift detection for
[resourceId:" + resourceId
+ + ", driftDefinitionId: " + driftDefinition.getId() + ",
driftDefinitionName: " + driftDefinition.getName()
+ + "].");
- DriftDetectionSchedule schedule = schedulesQueue.removeAndExecute(resourceId,
driftDef, new Runnable() {
+ DriftDetectionSchedule schedule = schedulesQueue.removeAndExecute(resourceId,
driftDefinition, new Runnable() {
@Override
public void run() {
File resourceDir = new File(changeSetsDir,
Integer.toString(resourceId));
- File changeSetDir = new File(resourceDir, driftDef.getName());
+ File changeSetDir = new File(resourceDir, driftDefinition.getName());
purge(changeSetDir, true);
log.debug("Removed change set directory " +
changeSetDir.getAbsolutePath());
@@ -435,12 +490,12 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
@Override
- public void updateDriftDetection(int resourceId, DriftDefinition driftDef) {
- log.info("Received request to update schedule for [resourceId: " +
resourceId + ", driftDefId: "
- + driftDef.getId() + ", driftDefName: " + driftDef.getName() +
"]");
- DriftDetectionSchedule updatedSchedule = schedulesQueue.update(resourceId,
driftDef);
+ public void updateDriftDetection(int resourceId, DriftDefinition driftDefinition) {
+ log.info("Received request to update schedule for [resourceId: " +
resourceId + ", driftDefinitionId: "
+ + driftDefinition.getId() + ", driftDefinitionName: " +
driftDefinition.getName() + "]");
+ DriftDetectionSchedule updatedSchedule = schedulesQueue.update(resourceId,
driftDefinition);
if (updatedSchedule == null) {
- updatedSchedule = new DriftDetectionSchedule(resourceId, driftDef);
+ updatedSchedule = new DriftDetectionSchedule(resourceId, driftDefinition);
if (log.isInfoEnabled()) {
log.info("No matching schedule was found in the queue. This must be
a request to add a new "
+ "schedule. Adding " + updatedSchedule + " to "
+ schedulesQueue);
@@ -464,31 +519,75 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
InventoryManager inventoryMgr =
PluginContainer.getInstance().getInventoryManager();
ResourceContainer container = inventoryMgr.getResourceContainer(resourceId);
if (container != null) {
- container.addDriftDefinition(driftDef);
+ container.addDriftDefinition(driftDefinition);
+ }
+ }
+
+ @Override
+ public void ackChangeSet(int resourceId, String driftDefName) {
+ log.info("Received server change set ack for [resourceId: " +
resourceId + ", driftDefinition:" + driftDefName
+ + "]");
+
+ File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
+ File changeSetDir = new File(resourceDir, driftDefName);
+
+ if (!changeSetDir.exists()) {
+ log.warn("Cannot complete acknowledgement. Change set directory " +
changeSetDir.getPath()
+ + " does not exist.");
+ return;
+ }
+
+ File snapshot = changeSetMgr.findChangeSet(resourceId, driftDefName, COVERAGE);
+ File previousSnapshot = new File(snapshot.getParentFile(), snapshot.getName() +
".previous");
+
+ previousSnapshot.delete();
+ deleteZipFiles(changeSetDir, "changeset_");
+ }
+
+ @Override
+ public void ackChangeSetContent(int resourceId, String driftDefName, String token) {
+ log.info("Received server change set content ack for [resourceId: " +
resourceId + ", driftDefinitionName: "
+ + driftDefName + "]");
+
+ File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
+ File changeSetDir = new File(resourceDir, driftDefName);
+
+ if (!changeSetDir.exists()) {
+ log.warn("Cannot complete acknowledgement. Change set directory " +
changeSetDir.getPath()
+ + " does not exist.");
+ return;
+ }
+
+ deleteZipFiles(changeSetDir, "content_" + token);
+ }
+
+ private void deleteZipFiles(File dir, final String prefix) {
+ for (File file : dir.listFiles(new ZipFileNameFilter(prefix))) {
+ file.delete();
}
}
/**
- * Given a drift definition, this examines the config and its associated resource to
determine where exactly
+ * Given a drift definition, this examines the def and its associated resource to
determine where exactly
* the base directory is that should be monitoried.
*
- * @param resourceId The id of the resource to which the config belongs
- * @param driftDef describes what is to be monitored for drift
+ * @param resourceId The id of the resource to which the def belongs
+ * @param driftDefinition describes what is to be monitored for drift
*
- * @return absolute directory location where the drift definition base directory is
referring
+ * @return absolute directory location where the drift def base directory is
referring
*/
@Override
- public File getAbsoluteBaseDirectory(int resourceId, DriftDefinition driftDef) {
+ public File getAbsoluteBaseDirectory(int resourceId, DriftDefinition driftDefinition)
{
// get the resource entity stored in our local inventory
InventoryManager im = getInventoryManager();
ResourceContainer container = im.getResourceContainer(resourceId);
Resource resource = container.getResource();
- // find out the type of base location that is specified by the drift config
- DriftDefinition.BaseDirectory baseDir = driftDef.getBasedir();
+ // find out the type of base location that is specified by the drift def
+ DriftDefinition.BaseDirectory baseDir = driftDefinition.getBasedir();
if (baseDir == null) {
- throw new IllegalArgumentException("Missing basedir in drift
def");
+ throw new IllegalArgumentException("Missing basedir in drift
definition");
}
// based on the type of base location, determine the root base directory
@@ -562,17 +661,16 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
return PluginContainer.getInstance().getMeasurementManager();
}
- private static class DeleteFile implements Runnable {
+ private static class ZipFileNameFilter implements FilenameFilter {
+ private String prefix;
- private File file;
-
- public DeleteFile(File file) {
- this.file = file;
+ public ZipFileNameFilter(String prefix) {
+ this.prefix = prefix;
}
@Override
- public void run() {
- file.delete();
+ public boolean accept(File dir, String name) {
+ return name.startsWith(prefix) && name.endsWith(".zip");
}
}
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
index 35e62d8..b24849b 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
@@ -37,9 +37,9 @@ import org.rhq.core.pc.drift.DriftManager;
import org.rhq.core.pc.inventory.InventoryManager;
/**
- * This class handles syncing drift definitions during inventory sync. This class is
- * intended to server as the public interface (so to speak) to {@link InventoryManager}
for
- * syncing drift definitions.
+ * This class handles syncing drift definitions and drift content during inventory sync.
+ * This class is intended to server as the public interface (so to speak) to
+ * {@link InventoryManager} for syncing drift definitions and content.
* <br/><br/>
* Please review the docs for each of the setter methods to determine which properties
* should be set before invoking any business logic methods.
@@ -89,13 +89,19 @@ public class DriftSyncManager {
dataDir = dataDirectory;
}
- public void syncDefsWithServer(Set<Integer> resourceIds) {
- log.info("Starting server sync for drift definitions...");
- long startTime = System.currentTimeMillis();
-
- Map<Integer, List<DriftDefinition>> defs =
driftServer.getDriftDefinitions(resourceIds);
- DriftDefinitionComparator comparator = new DriftDefinitionComparator(
- BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
+ /**
+ * Synchronized both drift definitions and drift content with the server. The drift
+ * definition sync goes from server to agent in that the drift definitions in the
+ * local inventory are updated to match the drift definitions on the server
+ * inventory.
+ * <br/><br/>
+ * The content sync works as follows. Any change set content zip files found locally
+ * resent to the server under the assumption that the content has not been persisted
on
+ * the server.
+ *
+ * @param resourceIds The ids of resources that need to be synced.
+ */
+ public void syncWithServer(Set<Integer> resourceIds) {
DriftSynchronizerFactory synchronizerFactory = new DriftSynchronizerFactory();
DriftSynchronizer synchronizer;
@@ -105,18 +111,31 @@ public class DriftSyncManager {
synchronizer = synchronizerFactory.getRuntimeSynchronizer(driftMgr);
}
+ syncConfigs(synchronizer, resourceIds);
+ syncContent(synchronizer);
+ }
+
+ private void syncConfigs(DriftSynchronizer synchronizer, Set<Integer>
resourceIds) {
+ log.info("Starting server sync for drift definitions...");
+ long startTime = System.currentTimeMillis();
+
+ Map<Integer, List<DriftDefinition>> driftDefs =
driftServer.getDriftDefinitions(resourceIds);
+ DriftDefinitionComparator comparator = new DriftDefinitionComparator(
+ BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
+
int totalDeleted = 0;
int totalAdded = 0;
- for (Integer resourceId : defs.keySet()) {
- Set<DriftDefinition> resourceDefsOnServer = new
TreeSet<DriftDefinition>(comparator);
- resourceDefsOnServer.addAll(defs.get(resourceId));
+ for (Integer resourceId : driftDefs.keySet()) {
+ Set<DriftDefinition> resourceConfigsOnServer = new
TreeSet<DriftDefinition>(comparator);
+ resourceConfigsOnServer.addAll(driftDefs.get(resourceId));
- List<DriftDefinition> deletedDefs =
synchronizer.getDeletedDefinitions(resourceId, resourceDefsOnServer);
+ List<DriftDefinition> deletedDefs =
synchronizer.getDeletedDefinitions(resourceId,
+ resourceConfigsOnServer);
totalDeleted += deletedDefs.size();
synchronizer.purgeFromLocalInventory(resourceId, deletedDefs);
- List<DriftDefinition> addedDefs =
synchronizer.getAddedDefinitions(resourceId, resourceDefsOnServer);
+ List<DriftDefinition> addedDefs =
synchronizer.getAddedDefinitions(resourceId, resourceConfigsOnServer);
totalAdded += addedDefs.size();
synchronizer.addToLocalInventory(resourceId, addedDefs);
}
@@ -128,6 +147,16 @@ public class DriftSyncManager {
}
}
+ private void syncContent(DriftSynchronizer synchronizer) {
+ log.info("Starting drift content sync...");
+ long startTime = System.currentTimeMillis();
+ synchronizer.syncChangeSetContent();
+ long endTime = System.currentTimeMillis();
+ if (log.isInfoEnabled()) {
+ log.info("Finished drift content sync in " + (endTime - startTime)
+ " ms");
+ }
+ }
+
/**
* This method determines whether or not this is a sync being done at start up (or
* more precisely during PC initialization). It does by checking to see if
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 99c7101..a637a51 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,29 +2,39 @@ package org.rhq.core.pc.drift;
import java.io.File;
-import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftDefinition;
class DriftClientTestStub implements DriftClient {
private File basedir;
- @Override
- public void sendChangeSetToServer(int resourceId, DriftDefinition
driftConfiguration,
- DriftChangeSetCategory type) {
+ private boolean failingOnSendChangeSet;
+ @Override
+ public void sendChangeSetToServer(DriftDetectionSummary detectionSummary) {
+ if (failingOnSendChangeSet) {
+ throw new RuntimeException("Failed to send change set to server");
+ }
}
@Override
- public void sendChangeSetContentToServer(int resourceId, String
driftConfigurationName, File contentDir) {
+ public void sendChangeSetContentToServer(int resourceId, String driftDefinitionName,
File contentDir) {
}
@Override
- public File getAbsoluteBaseDirectory(int resourceId, DriftDefinition
driftConfiguration) {
+ public File getAbsoluteBaseDirectory(int resourceId, DriftDefinition driftDefinition)
{
return basedir;
}
public void setBaseDir(File basedir) {
this.basedir = basedir;
}
+
+ public boolean isFailingOnSendChangeSet() {
+ return failingOnSendChangeSet;
+ }
+
+ public void setFailingOnSendChangeSet(boolean failing) {
+ failingOnSendChangeSet = failing;
+ }
}
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 0a3b10c..50f2899 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
@@ -19,6 +19,20 @@
package org.rhq.core.pc.drift;
+import static java.util.Arrays.asList;
+import static java.util.Collections.emptyList;
+import static org.apache.commons.io.FileUtils.touch;
+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.core.domain.drift.DriftChangeSetCategory.DRIFT;
+import static org.rhq.test.AssertUtils.assertCollectionMatchesNoOrder;
+import static org.rhq.test.AssertUtils.assertPropertiesMatch;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
@@ -36,20 +50,6 @@ import org.rhq.common.drift.Headers;
import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftDefinition;
-import static java.util.Arrays.asList;
-import static java.util.Collections.emptyList;
-import static org.apache.commons.io.FileUtils.touch;
-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.core.domain.drift.DriftChangeSetCategory.DRIFT;
-import static org.rhq.test.AssertUtils.assertCollectionMatchesNoOrder;
-import static org.rhq.test.AssertUtils.assertPropertiesMatch;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
public class DriftDetectorTest extends DriftTest {
ScheduleQueue scheduleQueue;
@@ -80,7 +80,7 @@ public class DriftDetectorTest extends DriftTest {
// create an empty directory
File libDir = mkdir(resourceDir, "lib");
- DriftDefinition driftConfig = driftConfiguration("coverage-test",
resourceDir.getAbsolutePath());
+ DriftDefinition driftConfig = driftDefinition("coverage-test",
resourceDir.getAbsolutePath());
scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(),
driftConfig));
detector.run();
@@ -100,17 +100,16 @@ public class DriftDetectorTest extends DriftTest {
File server1Conf = createRandomFile(confDir, "server-1.conf");
File server2Conf = createRandomFile(confDir, "server-2.conf");
- DriftDefinition config = driftConfiguration("multiple-files-test",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("multiple-files-test",
resourceDir.getAbsolutePath());
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
- File changeSet = changeSet(config.getName(), COVERAGE);
- List<FileEntry> entries = asList(
- addedFileEntry("conf/server-1.conf", sha256(server1Conf)),
- addedFileEntry("conf/server-2.conf", sha256(server2Conf)));
+ File changeSet = changeSet(def.getName(), COVERAGE);
+ List<FileEntry> entries =
asList(addedFileEntry("conf/server-1.conf", sha256(server1Conf)),
addedFileEntry(
+ "conf/server-2.conf", sha256(server2Conf)));
- assertHeaderEquals(changeSet, createHeaders(config, COVERAGE));
+ assertHeaderEquals(changeSet, createHeaders(def, COVERAGE));
assertFileEntriesMatch("Each file in a directory should be included in a
coverage change set", entries,
changeSet);
}
@@ -124,17 +123,16 @@ public class DriftDetectorTest extends DriftTest {
File libDir = mkdir(resourceDir, "lib");
File serverLib = createRandomFile(libDir, "server.jar");
- DriftDefinition config = driftConfiguration("sibling-dirs-test",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("sibling-dirs-test",
resourceDir.getAbsolutePath());
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
- File changeSet = changeSet(config.getName(), COVERAGE);
- List<FileEntry> entries = asList(
- addedFileEntry("conf/server.conf", sha256(serverConf)),
- addedFileEntry("lib/server.jar", sha256(serverLib)));
+ File changeSet = changeSet(def.getName(), COVERAGE);
+ List<FileEntry> entries =
asList(addedFileEntry("conf/server.conf", sha256(serverConf)), addedFileEntry(
+ "lib/server.jar", sha256(serverLib)));
- assertHeaderEquals(changeSet, createHeaders(config, COVERAGE));
+ assertHeaderEquals(changeSet, createHeaders(def, COVERAGE));
assertFileEntriesMatch("A coverage change set should include files from
multiple, sibling directories",
entries, changeSet);
}
@@ -148,17 +146,16 @@ public class DriftDetectorTest extends DriftTest {
File subConfDir = mkdir(confDir, "subconf");
File server2Conf = createRandomFile(subConfDir, "server-2.conf");
- DriftDefinition config = driftConfiguration("nested-dirs-test",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("nested-dirs-test",
resourceDir.getAbsolutePath());
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
- File changeSet = changeSet(config.getName(), COVERAGE);
- List<FileEntry> entries = asList(
- addedFileEntry("conf/server-1.conf", sha256(server1Conf)),
- addedFileEntry("conf/subconf/server-2.conf",
sha256(server2Conf)));
+ File changeSet = changeSet(def.getName(), COVERAGE);
+ List<FileEntry> entries =
asList(addedFileEntry("conf/server-1.conf", sha256(server1Conf)),
addedFileEntry(
+ "conf/subconf/server-2.conf", sha256(server2Conf)));
- assertHeaderEquals(changeSet, createHeaders(config, COVERAGE));
+ assertHeaderEquals(changeSet, createHeaders(def, COVERAGE));
assertFileEntriesMatch("A coverage change set should include files in nested
sub directories", entries,
changeSet);
}
@@ -169,23 +166,29 @@ public class DriftDetectorTest extends DriftTest {
File confDir = mkdir(resourceDir, "conf");
File serverConf = createRandomFile(confDir, "server.conf");
- DriftDefinition config = driftConfiguration("nothing-to-update",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("nothing-to-update",
resourceDir.getAbsolutePath());
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
- File changeSet = changeSet(config.getName(), COVERAGE);
+ File changeSet = changeSet(def.getName(), COVERAGE);
String originalHash = sha256(changeSet);
+ // Reset the schedule so that detection will run again the next time we call
+ // detection.run()
+ DriftDetectionSchedule schedule = scheduleQueue.remove(resourceId(), def);
+ schedule.resetSchedule();
+ scheduleQueue.addSchedule(schedule);
+
// Run the detector again. Note that nothing has changed so the snapshot should
// remain the same and no drift change set file should be generated.
detector.run();
String newHash = sha256(changeSet);
- assertEquals(newHash, originalHash, "The snapshot file should not have
changed since there was no drift.");
+ assertEquals(newHash, originalHash, "The snapshot file should not have
changed since there was no drift. ");
- File driftChangeSet = changeSet(config.getName(), DRIFT);
+ File driftChangeSet = changeSet(def.getName(), DRIFT);
assertFalse(driftChangeSet.exists(), "A drift change set file should not
have been generated since there was "
+ "no drift");
@@ -193,63 +196,100 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
- public void skipScheduledThatHasConfigDisabled() throws Exception {
+ public void skipDetectionForScheduledThatIsDisabled() throws Exception {
detector.setDriftClient(new DriftClientTestStub() {
{
setBaseDir(resourceDir);
}
@Override
- public void sendChangeSetToServer(int resourceId, DriftDefinition
driftConfiguration,
- DriftChangeSetCategory type) {
+ public void sendChangeSetToServer(DriftDetectionSummary detectionSummary) {
throw new RuntimeException("Should not invoke drift client when
drift configuration is disabled");
}
});
- DriftDefinition config = driftConfiguration("disabled-config-test",
resourceDir.getAbsolutePath());
- config.setEnabled(false);
+ DriftDefinition def = driftDefinition("disabled-config-test",
resourceDir.getAbsolutePath());
+ def.setEnabled(false);
File confDir = mkdir(resourceDir, "conf");
File server1Conf = new File(confDir, "server-1.conf");
touch(server1Conf);
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
}
@SuppressWarnings("unchecked")
@Test
+ public void skipDetectionWhenPreviousSnapshotFileExists() throws Exception {
+ // The presence of a previous snapshot file means that the server has
+ // not acknowledged that it has received and processed the change set.
+ DriftDefinition def = driftDefinition("previous-snapshot-test",
resourceDir.getAbsolutePath());
+
+ File confDir = mkdir(resourceDir, "conf");
+ createRandomFile(confDir, "server.conf");
+
+ DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(), def);
+ scheduleQueue.addSchedule(schedule);
+ detector.run();
+
+ // create some drift and generate a new snapshot
+ createRandomFile(confDir, "server-1.conf");
+ schedule.resetSchedule();
+ detector.run();
+
+ File snapshot = changeSet(def.getName(), COVERAGE);
+ String newHash = sha256(snapshot);
+ File previousSnapshot = previousChangeSet(def.getName());
+ String oldHash = sha256(previousSnapshot);
+
+ // create some drift and make sure drift detection does not run.
+ createRandomFile(confDir, "server-2.conf");
+ schedule.resetSchedule();
+ // Tell driftClient to throw an exception if detector attempts to send
+ // the change set report to the server. The detector should never call
+ // driftClient in this scenario.
+ driftClient.setFailingOnSendChangeSet(true);
+ detector.run();
+
+ assertEquals(sha256(snapshot), newHash, "The snapshot should not have
changed since the previous snapshot "
+ + "is still on disk.");
+ assertEquals(sha256(previousSnapshot), oldHash, "The previous snapshot
should not have changed since "
+ + "drift detection should not have run until the server acked the
previous snapshot.");
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
public void includeAddedFileInDriftChangeSet() throws Exception {
- DriftDefinition config = driftConfiguration("file-added-drift-test",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("file-added-drift-test",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
- ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(config, COVERAGE));
+ ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(def, COVERAGE));
writer.write(addedFileEntry("conf/server-1.conf",
sha256(server1Conf)));
writer.close();
// Create some drift
File server2Conf = createRandomFile(confDir, "server-2.conf");
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
- File driftChangeSet = changeSet(config.getName(), DRIFT);
+ File driftChangeSet = changeSet(def.getName(), DRIFT);
List<FileEntry> driftEntries =
asList(addedFileEntry("conf/server-2.conf", sha256(server2Conf)));
// verify that the drift change set was generated
assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
- assertHeaderEquals(driftChangeSet, createHeaders(config, DRIFT, 1));
+ assertHeaderEquals(driftChangeSet, createHeaders(def, DRIFT, 1));
assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
- File coverageChangeSet = changeSet(config.getName(), COVERAGE);
- List<FileEntry> coverageEntries = asList(
- addedFileEntry("conf/server-1.conf", sha256(server1Conf)),
+ File coverageChangeSet = changeSet(def.getName(), COVERAGE);
+ List<FileEntry> coverageEntries =
asList(addedFileEntry("conf/server-1.conf", sha256(server1Conf)),
addedFileEntry("conf/server-2.conf", sha256(server2Conf)));
// verify that the coverage change set was updated
- assertHeaderEquals(coverageChangeSet, createHeaders(config, COVERAGE, 1));
+ assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 1));
assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
coverageChangeSet);
}
@@ -257,13 +297,13 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
public void includeModifiedFileInDriftChangeSet() throws Exception {
- DriftDefinition config = driftConfiguration("file-modified-drift-test",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("file-modified-drift-test",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
String oldHash = sha256(server1Conf);
- ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(config, COVERAGE));
+ ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(def, COVERAGE));
writer.write(addedFileEntry("conf/server-1.conf", oldHash));
writer.close();
@@ -272,22 +312,22 @@ public class DriftDetectorTest extends DriftTest {
server1Conf = createRandomFile(confDir, "server-1.conf");
String newHash = sha256(server1Conf);
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
- File driftChangeSet = changeSet(config.getName(), DRIFT);
+ File driftChangeSet = changeSet(def.getName(), DRIFT);
List<FileEntry> driftEntries =
asList(changedFileEntry("conf/server-1.conf", oldHash, newHash));
// verify that the drift change set was generated
assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
- assertHeaderEquals(driftChangeSet, createHeaders(config, DRIFT, 1));
+ assertHeaderEquals(driftChangeSet, createHeaders(def, DRIFT, 1));
assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
- File coverageChangeSet = changeSet(config.getName(), COVERAGE);
+ File coverageChangeSet = changeSet(def.getName(), COVERAGE);
List<FileEntry> coverageEntries =
asList(changedFileEntry("conf/server-1.conf", oldHash, newHash));
// verify that the coverage change set was updated
- assertHeaderEquals(coverageChangeSet, createHeaders(config, COVERAGE, 1));
+ assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 1));
assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
coverageChangeSet);
}
@@ -295,12 +335,12 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test(enabled = false)
public void includeFiledAddedInNewDirectoryInDriftChangeSet() throws Exception {
- DriftDefinition config = driftConfiguration("file-added-in-new-dir",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("file-added-in-new-dir",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
- ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(config, COVERAGE));
+ ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(def, COVERAGE));
writer.write(addedFileEntry("conf/server-1.conf",
sha256(server1Conf)));
writer.close();
@@ -308,24 +348,23 @@ public class DriftDetectorTest extends DriftTest {
File subconfDir = mkdir(confDir, "subconf");
File server2Conf = createRandomFile(subconfDir, "server-2.conf");
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
- File driftChangeSet = changeSet(config.getName(), DRIFT);
+ File driftChangeSet = changeSet(def.getName(), DRIFT);
List<FileEntry> driftEntries =
asList(addedFileEntry("conf/subconf/server-2.conf", sha256(server2Conf)));
// verify that the drift change set was generated
assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
- assertHeaderEquals(driftChangeSet, createHeaders(config, DRIFT, 1));
+ assertHeaderEquals(driftChangeSet, createHeaders(def, DRIFT, 1));
assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
- File coverageChangeSet = changeSet(config.getName(), COVERAGE);
- List<FileEntry> coverageEntries = asList(
- addedFileEntry("conf/server-1.conf", sha256(server1Conf)),
+ File coverageChangeSet = changeSet(def.getName(), COVERAGE);
+ List<FileEntry> coverageEntries =
asList(addedFileEntry("conf/server-1.conf", sha256(server1Conf)),
addedFileEntry("conf/subconf/server-2.conf",
sha256(server2Conf)));
// verify that the coverage change set was updated
- assertHeaderEquals(coverageChangeSet, createHeaders(config, COVERAGE, 1));
+ assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 1));
assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
coverageChangeSet);
}
@@ -333,7 +372,7 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
public void includeRemovedFileInDriftChangeSet() throws Exception {
- DriftDefinition config = driftConfiguration("file-removed-drift-test",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("file-removed-drift-test",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
@@ -341,7 +380,7 @@ public class DriftDetectorTest extends DriftTest {
String server2ConfHash = sha256(server2Conf);
- ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(config, COVERAGE));
+ ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(def, COVERAGE));
writer.write(addedFileEntry("conf/server-1.conf",
sha256(server1Conf)));
writer.write(addedFileEntry("conf/server-2.conf", server2ConfHash));
writer.close();
@@ -349,22 +388,22 @@ public class DriftDetectorTest extends DriftTest {
// create some drift
server2Conf.delete();
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
detector.run();
- File driftChangeSet = changeSet(config.getName(), DRIFT);
+ File driftChangeSet = changeSet(def.getName(), DRIFT);
List<FileEntry> driftEntries =
asList(removedFileEntry("conf/server-2.conf", server2ConfHash));
// verify that the drift change set was generated
assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
- assertHeaderEquals(driftChangeSet, createHeaders(config, DRIFT, 1));
+ assertHeaderEquals(driftChangeSet, createHeaders(def, DRIFT, 1));
assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
// verify that the coverage change set was updated
- File coverageChangeSet = changeSet(config.getName(), COVERAGE);
+ File coverageChangeSet = changeSet(def.getName(), COVERAGE);
List<FileEntry> coverageEntries =
asList(addedFileEntry("conf/server-1.conf", sha256(server1Conf)));
- assertHeaderEquals(coverageChangeSet, createHeaders(config, COVERAGE, 1));
+ assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 1));
assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
coverageChangeSet);
}
@@ -372,13 +411,13 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
public void includeFilesInRemovedDirectoryInDriftChangeSet() throws Exception {
- DriftDefinition config = driftConfiguration("dir-removed-test",
resourceDir.getAbsolutePath());
+ DriftDefinition def = driftDefinition("dir-removed-test",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
String server1Hash = sha256(server1Conf);
- ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(config, COVERAGE));
+ ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resourceId(),
createHeaders(def, COVERAGE));
writer.write(addedFileEntry("conf/server-1.conf", server1Hash));
writer.close();
@@ -386,22 +425,187 @@ public class DriftDetectorTest extends DriftTest {
server1Conf.delete();
confDir.delete();
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
+ detector.run();
+
+ File driftChangeSet = changeSet(def.getName(), DRIFT);
+ List<FileEntry> driftEntries =
asList(removedFileEntry("conf/server-1.conf", server1Hash));
+
+ // verify that the drift change set was generated
+ assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
+ assertHeaderEquals(driftChangeSet, createHeaders(def, DRIFT, 1));
+ assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
+
+ // verify that the coverage change set was updated
+ File coverageChangeSet = changeSet(def.getName(), COVERAGE);
+ List<FileEntry> coverageEntries = emptyList();
+
+ assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 1));
+ assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
+ coverageChangeSet);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void revertToPreviousSnapshotWhenSendingChangeSetFails() throws Exception {
+ DriftDefinition def = driftDefinition("revert-snapshot-test",
resourceDir.getAbsolutePath());
+ DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(), def);
+
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = createRandomFile(confDir, "server.conf");
+
+ scheduleQueue.addSchedule(schedule);
+ // generate the initial snapshot
+ detector.run();
+
+ // Now generate a drift change set
+ createRandomFile(confDir, "server-1.conf");
+ schedule.resetSchedule();
+ detector.run();
+
+ File changeSet = changeSet(def.getName(), COVERAGE);
+ String currentHash = sha256(changeSet);
+
+ // Need to delete the previous version snapshot file; otherwise, the
+ // next detection run will be skipped.
+ previousChangeSet(def.getName()).delete();
+
+ // generate some more drift, and fail on sending the change set
+ // to the server
+ createRandomFile(confDir, "server-2.conf");
+ schedule.resetSchedule();
+ driftClient.setFailingOnSendChangeSet(true);
+ try {
+ detector.run();
+ } catch (RuntimeException e) {
+ }
+
+ String newHash = sha256(changeSet);
+
+ assertEquals(newHash, currentHash, "The snapshot file should be reverted if
sending the new snapshot "
+ + "to the server fails.");
+ // The previous version file must be deleted on revert; otherwise, drift
+ // detection will not run for the schedule if the previous version file
+ // is found on disk.
+ assertFalse(previousChangeSet(def.getName()).exists(), "The copy of the
previous version snapshot file "
+ + "should be deleted once we have reverted back to it and have a new,
current snapsot file.");
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void purgeSnapshotWhenSendingInitialChangeSetFails() throws Exception {
+ // If we have just generated the initial change set and sending it to
+ // the server fails, then there is no prior snapshot version to which
+ // we can revert. We therefore need to purge the snapshot file and
+ // allow DriftDetector to simply regenerate the initial change set again.
+
+ DriftDefinition def = driftDefinition("purge-snapshot-test",
resourceDir.getAbsolutePath());
+
+ File confDir = mkdir(resourceDir, "conf");
+ createRandomFile(confDir, "server.conf");
+
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
+ driftClient.setFailingOnSendChangeSet(true);
+ try {
+ detector.run();
+ } catch (RuntimeException e) {
+ }
+
+ assertFalse(changeSet(def.getName(), COVERAGE).exists(), "Snapshot file
should be deleted when "
+ + "only the initial change set has been generated and sending change
send report to server fails");
+ }
+
+ @Test
+ public void ignoreFilesThatAreNotReadableForCoverageChangeSet() throws Exception {
+ DriftDefinition def = driftDefinition("nonreadable-files-coverage",
resourcesDir.getAbsolutePath());
+
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = createRandomFile(confDir, "server-1.conf");
+ File server2Conf = createRandomFile(confDir, "server-2.conf");
+ assertTrue(server2Conf.setReadable(false), "Failed to make " +
server2Conf.getPath() + " write only");
+
+ scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), def));
+ detector.run();
+
+ File changeSet = changeSet(def.getName(), COVERAGE);
+ List<FileEntry> entries =
asList(addedFileEntry("conf/server-1.conf", sha256(server1Conf)));
+
+ assertHeaderEquals(changeSet, createHeaders(def, COVERAGE));
+ assertFileEntriesMatch("Files that are non-readable should be skipped but
other, readable file should still "
+ + "be included in the change set", entries, changeSet);
+ }
+
+ @Test
+ public void ignoreNewFilesThatAreNotReadableForDriftChangeSet() throws Exception {
+ DriftDefinition def = driftDefinition("nonreadable-files-drfit",
resourceDir.getAbsolutePath());
+ DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(), def);
+
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = createRandomFile(confDir, "server-1.conf");
+ String oldServer1Hash = sha256(server1Conf);
+
+ scheduleQueue.addSchedule(schedule);
+ detector.run();
+
+ // create some drift that includes a new file that is not readable
+ server1Conf.delete();
+ server1Conf = createRandomFile(confDir, "server-1.conf");
+ String newServer1Hash = sha256(server1Conf);
+
+ File server2Conf = createRandomFile(confDir, "server-2.conf");
+ assertTrue(server2Conf.setReadable(false), "Failed to make " +
server2Conf.getPath() + " write only");
+
+ schedule.resetSchedule();
+ detector.run();
+
+ File driftChangeSet = changeSet(def.getName(), DRIFT);
+ List<FileEntry> driftEntries =
asList(changedFileEntry("conf/server-1.conf", oldServer1Hash, newServer1Hash));
+
+ // verify that the drift change set was generated
+ assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
+ assertHeaderEquals(driftChangeSet, createHeaders(def, DRIFT, 1));
+ assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
+
+ // verify that the coverage change set was updated
+ File coverageChangeSet = changeSet(def.getName(), COVERAGE);
+ List<FileEntry> coverageEntries =
asList(changedFileEntry("conf/server-1.conf", oldServer1Hash, newServer1Hash));
+
+ assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 1));
+ assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
+ coverageChangeSet);
+ }
+
+ @Test
+ public void markFileUnderDriftDetectionAsRemovedWhenItIsMadeNonReadable() throws
Exception {
+ DriftDefinition def = driftDefinition("file-made-nonreadable",
resourceDir.getAbsolutePath());
+ DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(), def);
+
+ File confDir = mkdir(resourceDir, "conf");
+ File server1Conf = createRandomFile(confDir, "server-1.conf");
+ String server1Hash = sha256(server1Conf);
+
+ scheduleQueue.addSchedule(schedule);
+ detector.run();
+
+ // make the file non-readable and run the detector again
+ assertTrue(server1Conf.setReadable(false), "Failed to make " +
server1Conf.getPath() + " write only");
+
+ schedule.resetSchedule();
detector.run();
- File driftChangeSet = changeSet(config.getName(), DRIFT);
+ File driftChangeSet = changeSet(def.getName(), DRIFT);
List<FileEntry> driftEntries =
asList(removedFileEntry("conf/server-1.conf", server1Hash));
// verify that the drift change set was generated
assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
- assertHeaderEquals(driftChangeSet, createHeaders(config, DRIFT, 1));
+ assertHeaderEquals(driftChangeSet, createHeaders(def, DRIFT, 1));
assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
// verify that the coverage change set was updated
- File coverageChangeSet = changeSet(config.getName(), COVERAGE);
+ File coverageChangeSet = changeSet(def.getName(), COVERAGE);
List<FileEntry> coverageEntries = emptyList();
- assertHeaderEquals(coverageChangeSet, createHeaders(config, COVERAGE, 1));
+ assertHeaderEquals(coverageChangeSet, createHeaders(def, COVERAGE, 1));
assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
coverageChangeSet);
}
@@ -409,8 +613,8 @@ public class DriftDetectorTest extends DriftTest {
void assertHeaderEquals(File changeSet, Headers expected) throws Exception {
ChangeSetReader reader = new ChangeSetReaderImpl(new BufferedReader(new
FileReader(changeSet)));
Headers actual = reader.getHeaders();
- assertPropertiesMatch(expected, actual, "Headers for " +
changeSet.getPath() + " do not match " +
- "expected values");
+ assertPropertiesMatch(expected, actual, "Headers for " +
changeSet.getPath() + " do not match "
+ + "expected values");
}
void assertFileEntriesMatch(String msg, List<FileEntry> expected, File
changeSet) throws Exception {
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
index 696561a..319787c 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
@@ -19,6 +19,17 @@
package org.rhq.core.pc.drift;
+import static java.util.Arrays.asList;
+import static org.apache.commons.io.FileUtils.deleteDirectory;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
+import static org.rhq.core.util.ZipUtil.unzipFile;
+import static org.rhq.test.AssertUtils.assertCollectionMatchesNoOrder;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
@@ -40,17 +51,6 @@ import org.rhq.core.pc.ServerServices;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
-import static java.util.Arrays.asList;
-import static org.apache.commons.io.FileUtils.deleteDirectory;
-import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
-import static org.rhq.core.util.ZipUtil.unzipFile;
-import static org.rhq.test.AssertUtils.assertCollectionMatchesNoOrder;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
public class DriftManagerTest extends DriftTest {
private File tmpDir;
@@ -75,32 +75,37 @@ public class DriftManagerTest extends DriftTest {
driftMgr = new TestDriftManager();
driftMgr.setConfiguration(pcConfig);
+ driftMgr.setChangeSetMgr(changeSetMgr);
}
@Test
public void writeChangeSetZipFileToChangeSetDirectory() throws Exception {
- final DriftDefinition config =
driftConfiguration("write-changeset-file", resourceDir.getAbsolutePath());
+ final DriftDefinition config = driftDefinition("write-changeset-file",
resourceDir.getAbsolutePath());
final File changeSetDir = changeSetDir(config.getName());
createRandomFile(changeSetDir, "changeset.txt");
setDriftServiceCallback(new DriftServiceCallback() {
@Override
public void execute() {
- assertThatZipFileExists(changeSetDir, "changeset_",
- "Expected to find change set zip file " +
- "in " + changeSetDir.getPath() + ". The file name
should follow the pattern " +
- "changeset_<integer_timestamp>.zip");
+ assertThatZipFileExists(changeSetDir, "changeset_",
"Expected to find change set zip file " + "in "
+ + changeSetDir.getPath() + ". The file name should follow the
pattern "
+ + "changeset_<integer_timestamp>.zip");
}
});
+ DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(),
config);
+ DriftDetectionSummary detectionSummary = new DriftDetectionSummary();
+ detectionSummary.setSchedule(schedule);
+ detectionSummary.setType(COVERAGE);
+
driftMgr.setChangeSetMgr(changeSetMgr);
- driftMgr.getSchedulesQueue().addSchedule(new DriftDetectionSchedule(resourceId(),
config));
- driftMgr.sendChangeSetToServer(resourceId(), config, COVERAGE);
+ driftMgr.getSchedulesQueue().addSchedule(schedule);
+ driftMgr.sendChangeSetToServer(detectionSummary);
}
@Test
public void sendChangeSetReportInZipFile() throws Exception {
- final DriftDefinition config =
driftConfiguration("send-changeset-in-zip", resourceDir.getAbsolutePath());
+ final DriftDefinition config = driftDefinition("send-changeset-in-zip",
resourceDir.getAbsolutePath());
final File changeSetDir = changeSetDir(config.getName());
final File changeSetFile = createRandomFile(changeSetDir,
"changeset.txt");
@@ -111,32 +116,31 @@ public class DriftManagerTest extends DriftTest {
}
});
+ DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(),
config);
+ DriftDetectionSummary detectionSummary = new DriftDetectionSummary();
+ detectionSummary.setSchedule(schedule);
+ detectionSummary.setType(COVERAGE);
+
driftMgr.setChangeSetMgr(changeSetMgr);
driftMgr.getSchedulesQueue().addSchedule(new DriftDetectionSchedule(resourceId(),
config));
- driftMgr.sendChangeSetToServer(resourceId(), config, COVERAGE);
+ driftMgr.sendChangeSetToServer(detectionSummary);
}
@Test
- public void cleanUpAfterSendingChangeSetToServer() throws Exception {
- final DriftDefinition config =
driftConfiguration("send-changeset-in-zip", resourceDir.getAbsolutePath());
- final File changeSetDir = changeSetDir(config.getName());
- createRandomFile(changeSetDir, "changeset.txt");
-
- driftMgr.setChangeSetMgr(changeSetMgr);
- driftMgr.getSchedulesQueue().addSchedule(new DriftDetectionSchedule(resourceId(),
config));
- driftMgr.sendChangeSetToServer(resourceId(), config, COVERAGE);
-
- // clean up should not happen until after the input stream is closed. The remote
- // input stream is consumed asynchronously; so, we have to wait until the stream
- // is closed. We could otherwise disrupt the transmission of bits.
-
- File changeSetZip = assertThatZipFileExists(changeSetDir, "changeset_",
"Expected to find change set zip " +
- "zip file in " + changeSetDir.getPath() + ". The file name
should follow the pattern " +
- "changeset_<integer_timestamp>.zip");
+ public void cleanUpWhenServerAcksChangeSet() throws Exception {
+ DriftDefinition config =
driftDefinition("clean-up-when-server-acks-changeset",
resourceDir.getAbsolutePath());
+ File changeSetDir = changeSetDir(config.getName());
+ File snapshotFile = createRandomFile(changeSetDir, "changeset.txt");
+ File previousSnapshotFile = createRandomFile(changeSetDir,
"changeset.txt.previous");
+ File changeSetZipFile = createRandomFile(changeSetDir, "changeset_" +
System.currentTimeMillis() + ".zip");
- driftServerService.inputStream.close();
+ driftMgr.ackChangeSet(resourceId(), config.getName());
- assertFalse(changeSetZip.exists(), "The change set zip should be deleted
when the remote input stream is closed.");
+ assertTrue(snapshotFile.exists(), "Snapshot file should exist after server
acks change set");
+ assertFalse(previousSnapshotFile.exists(), "Previous version snapshot file
should be deleted when server "
+ + "acks change set");
+ assertEquals(findChangeSetZipFiles(changeSetDir).size(), 0, "All change set
zip files should be deleted when "
+ + "server acks change set");
}
@Test
@@ -151,9 +155,9 @@ public class DriftManagerTest extends DriftTest {
setDriftServiceCallback(new DriftServiceCallback() {
@Override
public void execute() {
- assertThatZipFileExists(changeSetDir, "content_",
"Expected to find content zip file in " +
- changeSetDir.getPath() + ". The file name should follow the
pattern " +
- "content_<integer_timestamp>.zip");
+ assertThatZipFileExists(changeSetDir, "content_",
"Expected to find content zip file in "
+ + changeSetDir.getPath() + ". The file name should follow the
pattern "
+ + "content_<integer_timestamp>.zip");
}
});
@@ -177,48 +181,42 @@ public class DriftManagerTest extends DriftTest {
});
driftMgr.sendChangeSetContentToServer(resourceId(), configName, contentDir);
+
+ // verify that the content directory is purged
+ assertThatDirectoryIsEmpty(contentDir);
}
@Test
- public void cleanUpAfterSendingContentToServer() throws Exception {
- String configName = "clean-up-after-sending-content";
+ public void cleanUpWhenServerAcksChangeSetContent() throws Exception {
+ String configName = "cleanup-when-server-acks-content";
File changeSetDir = changeSetDir(configName);
File contentDir = mkdir(changeSetDir, "content");
- createRandomFile(contentDir, "content-1");
- createRandomFile(contentDir, "content-2");
-
- driftMgr.sendChangeSetContentToServer(resourceId(), configName, contentDir);
-
- // clean up should not happen until after the input stream is closed. The remote
- // input stream is consumed asynchronously; so, we have to wait until the stream
- // is closed. We could otherwise disrupt the transmission of bits.
- File contentZipFile = assertThatZipFileExists(changeSetDir,
"content_",
- "Expected to find content zip file in " +
- changeSetDir.getPath() + ". The file name should have a pattern of
content_integer_timestamp>.zip");
+ String token = Long.toString(System.currentTimeMillis());
+ File contentZipFile = createRandomFile(changeSetDir, "content_" + token
+ ".zip");
- driftServerService.inputStream.close();
+ driftMgr.ackChangeSetContent(resourceId(), configName, token);
- assertFalse(contentZipFile.exists(), "The content zip should be deleted when
the remote input stream is closed");
- assertThatDirectoryIsEmpty(contentDir);
+ assertFalse(contentZipFile.exists(), "Content zip file should be purged
after server sends content ack");
}
@Test
public void unschedulingDetectionRemovesScheduleFromQueue() throws Exception {
- DriftDefinition config = driftConfiguration("remove-from-queue",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftDefinition("remove-from-queue",
resourceDir.getAbsolutePath());
driftMgr.scheduleDriftDetection(resourceId(), config);
- driftMgr.scheduleDriftDetection(resourceId() + 5,
driftConfiguration("another-config", "."));
+ driftMgr.scheduleDriftDetection(resourceId() + 5,
driftDefinition("another-config", "."));
driftMgr.unscheduleDriftDetection(resourceId(), config);
- assertFalse(driftMgr.getSchedulesQueue().contains(resourceId(), config),
- new DriftDetectionSchedule(resourceId(), config) + " should have been
removed from the schedule queue");
+ assertFalse(driftMgr.getSchedulesQueue().contains(resourceId(), config), new
DriftDetectionSchedule(
+ resourceId(), config)
+ + " should have been removed from the schedule queue");
}
@Test
public void unschedulingDetectionRemovesDriftConfigFromResourceContainer() throws
Exception {
- DriftDefinition config = driftConfiguration("remove-from-queue",
resourceDir.getAbsolutePath());
- DriftDefinition config2 = driftConfiguration("do-not-remove",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftDefinition("remove-from-queue",
resourceDir.getAbsolutePath());
+ DriftDefinition config2 = driftDefinition("do-not-remove",
resourceDir.getAbsolutePath());
driftMgr.scheduleDriftDetection(resourceId(), config);
driftMgr.scheduleDriftDetection(resourceId(), config2);
@@ -232,7 +230,7 @@ public class DriftManagerTest extends DriftTest {
@Test
public void unschedulingDetectionDeletesChangeSetDirectoryWhenScheduleIsNotActive()
throws Exception {
- DriftDefinition config = driftConfiguration("delete-changeset-dir",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftDefinition("delete-changeset-dir",
resourceDir.getAbsolutePath());
File changeSetDir = changeSetDir(config.getName());
File contentDir = mkdir(changeSetDir, "content");
@@ -247,7 +245,7 @@ public class DriftManagerTest extends DriftTest {
@Test
public void unschedulingDetectionDeletesChangeSetDirectoryWhenScheduleIsDeactivated()
throws Exception {
- DriftDefinition config = driftConfiguration("delete-changeset-dir",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftDefinition("delete-changeset-dir",
resourceDir.getAbsolutePath());
File changeSetDir = changeSetDir(config.getName());
File contentDir = mkdir(changeSetDir, "content");
@@ -258,12 +256,22 @@ public class DriftManagerTest extends DriftTest {
driftMgr.getSchedulesQueue().getNextSchedule();
driftMgr.unscheduleDriftDetection(resourceId(), config);
- assertTrue(changeSetDir.exists(), "The change set directory should not be
deleted while the schedule is " +
- "still active.");
+ assertTrue(changeSetDir.exists(), "The change set directory should not be
deleted while the schedule is "
+ + "still active.");
driftMgr.getSchedulesQueue().deactivateSchedule();
- assertFalse(changeSetDir.exists(), "The change set directory should have
been deleted after the schedule is " +
- "deactivated.");
+ assertFalse(changeSetDir.exists(), "The change set directory should have
been deleted after the schedule is "
+ + "deactivated.");
+ }
+
+ private List<File> findChangeSetZipFiles(File dir) {
+ File[] files = dir.listFiles(new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.startsWith("changeset_") &&
name.endsWith(".zip");
+ }
+ });
+ return asList(files);
}
/**
@@ -295,8 +303,8 @@ public class DriftManagerTest extends DriftTest {
String expectedHash = sha256(expectedFile);
String actualHash = sha256(actualFile);
- assertEquals(actualHash, expectedHash, "The zip file content is wrong.
The SHA-256 hash does not match " +
- "for " + expectedFile.getName());
+ assertEquals(actualHash, expectedHash, "The zip file content is wrong.
The SHA-256 hash does not match "
+ + "for " + expectedFile.getName());
}
}
@@ -351,6 +359,8 @@ public class DriftManagerTest extends DriftTest {
private static class TestDriftServerService implements DriftServerService {
public int resourceId;
+ public String driftConfigName;
+ public String token;
public long fileSize;
public InputStream inputStream;
@@ -368,8 +378,11 @@ public class DriftManagerTest extends DriftTest {
}
@Override
- public void sendFilesZip(int resourceId, long zipSize, InputStream zipStream) {
+ public void sendFilesZip(int resourceId, String driftConfigName, String token,
long zipSize,
+ InputStream zipStream) {
this.resourceId = resourceId;
+ this.driftConfigName = driftConfigName;
+ this.token = token;
fileSize = zipSize;
inputStream = zipStream;
@@ -384,7 +397,7 @@ public class DriftManagerTest extends DriftTest {
}
@Override
- public DriftSnapshot getCurrentSnapshot(int driftConfigurationId) {
+ public DriftSnapshot getCurrentSnapshot(int driftDefinitionId) {
return null;
}
}
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 ad32251..1d39499 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
@@ -19,6 +19,13 @@
package org.rhq.core.pc.drift;
+import static java.util.Arrays.asList;
+import static org.apache.commons.io.FileUtils.deleteDirectory;
+import static org.apache.commons.io.IOUtils.write;
+import static org.apache.commons.io.IOUtils.writeLines;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
+import static
org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext.fileSystem;
+
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -34,13 +41,6 @@ import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftDefinition;
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.write;
-import static org.apache.commons.io.IOUtils.writeLines;
-import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
-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
* directories for change sets and for fake resources. Before each test method is run, a
@@ -104,10 +104,10 @@ public class DriftTest {
protected File resourceDir;
/**
- * The default interval assigned to drift configurations created using
- * {@link #driftConfiguration(String, String)}
+ * The default interval assigned to drift definitions created using
+ * {@link #driftDefinition(String, String)}
*/
- protected long defaultInterval = 1800L; // 30 minutes;
+ protected long defaultInterval = 1800L; // 30 minutes;
private MessageDigestGenerator digestGenerator;
@@ -178,11 +178,11 @@ public class DriftTest {
}
/**
- * Returns the change set file for the specified drift configuration for the
resource
+ * Returns the change set file for the specified drift definition 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
+ * @param config The drift definition name
* @param type Determines whether a coverage or drift change set file is to be
returned
* @return The change set file
* @throws IOException
@@ -192,10 +192,10 @@ public class DriftTest {
}
/**
- * Returns the previous snapshot file for the specified drift configuration for the
+ * Returns the previous snapshot file for the specified drift definition for the
* resource with the id that can be obtained from {@link #resourceId()}.
*
- * @param config The drift configuration name
+ * @param config The drift definition name
* @return The previous snapshot file
* @throws Exception
*/
@@ -247,11 +247,11 @@ public class DriftTest {
* used as the context for the basedir which means the path specified is used as is.
* The interval property is set to {@link #defaultInterval}.
*
- * @param name The configuration name
+ * @param name The definition name
* @param basedir An absolute path of the base directory
- * @return The drift configuration object
+ * @return The drift definition object
*/
- protected DriftDefinition driftConfiguration(String name, String basedir) {
+ protected DriftDefinition driftDefinition(String name, String basedir) {
DriftDefinition config = new DriftDefinition(new Configuration());
config.setName(name);
config.setBasedir(new DriftDefinition.BaseDirectory(fileSystem, basedir));
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
index 0e57f71..eb1df17 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
@@ -37,6 +37,7 @@ import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.util.PageList;
+import org.rhq.core.domain.util.PageOrdering;
public class DriftServerServiceImpl implements DriftServerService {
@Override
@@ -50,10 +51,11 @@ public class DriftServerServiceImpl implements DriftServerService {
}
@Override
- public void sendFilesZip(int resourceId, long zipSize, InputStream zipStream) {
+ public void sendFilesZip(int resourceId, String driftDefinitionName, String token,
long zipSize,
+ InputStream zipStream) {
try {
DriftManagerLocal driftManager = getDriftManager();
- driftManager.addFiles(resourceId, zipSize, zipStream);
+ driftManager.addFiles(resourceId, driftDefinitionName, token, zipSize,
zipStream);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -66,13 +68,13 @@ public class DriftServerServiceImpl implements DriftServerService {
criteria.fetchConfiguration(true);
Subject overlord = getSubjectManager().getOverlord();
- PageList<DriftDefinition> configs =
getDriftManager().findDriftDefinitionsByCriteria(overlord, criteria);
+ PageList<DriftDefinition> definitions =
getDriftManager().findDriftDefinitionsByCriteria(overlord, criteria);
Map<Integer, List<DriftDefinition>> map = new HashMap<Integer,
List<DriftDefinition>>();
for (Integer resourceId : resourceIds) {
map.put(resourceId, new ArrayList<DriftDefinition>());
}
- for (DriftDefinition c : configs) {
+ for (DriftDefinition c : definitions) {
List<DriftDefinition> list = map.get(c.getResource().getId());
list.add(c);
map.put(c.getResource().getId(), list);
@@ -82,9 +84,10 @@ public class DriftServerServiceImpl implements DriftServerService {
}
@Override
- public DriftSnapshot getCurrentSnapshot(int driftConfigurationId) {
+ public DriftSnapshot getCurrentSnapshot(int driftDefinitionId) {
DriftChangeSetCriteria criteria = new GenericDriftChangeSetCriteria();
- criteria.addFilterDriftDefinitionId(driftConfigurationId);
+ criteria.addFilterDriftDefinitionId(driftDefinitionId);
+ criteria.addSortVersion(PageOrdering.ASC);
Subject overlord = getSubjectManager().getOverlord();
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
index 575fd74..54d5967 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
@@ -299,7 +299,7 @@ public class JPADriftServerBean implements JPADriftServerLocal {
AgentClient agentClient =
agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
DriftAgentService service = agentClient.getDriftAgentService();
- service.ackChangeSet(resourceId,
reader.getHeaders().getDriftConfigurationName());
+ service.ackChangeSet(resourceId,
reader.getHeaders().getDriftDefinitionName());
// send a message to the agent requesting the empty JPADriftFile
content
if (!emptyDriftFiles.isEmpty()) {
commit e68f4218873c954e24a6c15939b7d89cf7c276bc
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Thu Sep 29 20:13:56 2011 -0400
First pass at Drift Carousel view, this is a work in progress!
- New generic Carousel base class view, somewhat analogous to Table
- New DriftCarousel view which serves as the default detail view for a
drift definition.
- Tweaked title handling in Table as it was confusing, now Carousel and
Table title handling is basically the same. This touched a few files
with minor refactor changes.
- It was too confusing, so I pushed terminology change from Drift
Configuration to Drift [Detection] Definition through the code layer
(painfully huge refactor). Previously it was only pushed through the
presentation layer (I18N mainly). DB layer is still a TODO.
- note, a few classname changes were part of this
diff --git
a/modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetReaderImpl.java
b/modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetReaderImpl.java
index b8c383a..5da6078 100644
--- a/modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetReaderImpl.java
+++ b/modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetReaderImpl.java
@@ -95,8 +95,8 @@ public class ChangeSetReaderImpl implements ChangeSetReader {
headers = new Headers();
try {
headers.setResourceId(Integer.parseInt(reader.readLine()));
- headers.setDriftCofigurationId(Integer.parseInt(reader.readLine()));
- headers.setDriftConfigurationName(reader.readLine());
+ headers.setDriftDefinitionId(Integer.parseInt(reader.readLine()));
+ headers.setDriftDefinitionName(reader.readLine());
headers.setBasedir(reader.readLine());
headers.setType(DriftChangeSetCategory.fromCode(reader.readLine()));
headers.setVersion(Integer.parseInt(reader.readLine()));
diff --git
a/modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetWriterImpl.java
b/modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetWriterImpl.java
index fb6d7c3..c0fdf50 100644
--- a/modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetWriterImpl.java
+++ b/modules/common/drift/src/main/java/org/rhq/common/drift/ChangeSetWriterImpl.java
@@ -47,8 +47,8 @@ public class ChangeSetWriterImpl implements ChangeSetWriter {
private void writeHeaders(Headers headers) throws IOException {
writer.write(headers.getResourceId() + "\n");
- writer.write(headers.getDriftCofigurationId() + "\n");
- writer.write(headers.getDriftConfigurationName() + "\n");
+ writer.write(headers.getDriftDefinitionId() + "\n");
+ writer.write(headers.getDriftDefinitionName() + "\n");
writer.write(headers.getBasedir() + "\n");
writer.write(headers.getType().code() + "\n");
writer.write(headers.getVersion() + "\n");
diff --git a/modules/common/drift/src/main/java/org/rhq/common/drift/Headers.java
b/modules/common/drift/src/main/java/org/rhq/common/drift/Headers.java
index f482ccb..fb13e94 100644
--- a/modules/common/drift/src/main/java/org/rhq/common/drift/Headers.java
+++ b/modules/common/drift/src/main/java/org/rhq/common/drift/Headers.java
@@ -32,9 +32,9 @@ public class Headers implements Serializable {
private static final long serialVersionUID = 1L;
- private int driftCofigurationId;
+ private int driftDefinitionId;
- private String driftConfigurationName;
+ private String driftDefinitionName;
private String basedir;
@@ -59,31 +59,31 @@ public class Headers implements Serializable {
}
/**
- * @return The id of the drift configuration to which the change set belongs.
+ * @return The id of the drift definition to which the change set belongs.
*/
- public int getDriftCofigurationId() {
- return driftCofigurationId;
+ public int getDriftDefinitionId() {
+ return driftDefinitionId;
}
/**
- * @param driftCofigurationId The id of the drift configuration to which the change
set belongs
+ * @param driftDefinitionId The id of the drift def to which the change set belongs
*/
- public void setDriftCofigurationId(int driftCofigurationId) {
- this.driftCofigurationId = driftCofigurationId;
+ public void setDriftDefinitionId(int driftDefinitionId) {
+ this.driftDefinitionId = driftDefinitionId;
}
/**
- * @return The name of the drift configuration to which the change set belongs
+ * @return The name of the drift def to which the change set belongs
*/
- public String getDriftConfigurationName() {
- return driftConfigurationName;
+ public String getDriftDefinitionName() {
+ return driftDefinitionName;
}
/**
- * @param name The name of the drift configuration to which the change set belongs
+ * @param name The name of the drift def to which the change set belongs
*/
- public void setDriftConfigurationName(String name) {
- driftConfigurationName = name;
+ public void setDriftDefinitionName(String name) {
+ driftDefinitionName = name;
}
/**
diff --git
a/modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetReaderImplTest.java
b/modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetReaderImplTest.java
index 6df07f0..5df79fa 100644
---
a/modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetReaderImplTest.java
+++
b/modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetReaderImplTest.java
@@ -31,8 +31,8 @@ public class ChangeSetReaderImplTest {
Headers actualHeaders = reader.getHeaders();
Headers expectedHeaders = new Headers();
expectedHeaders.setResourceId(1);
- expectedHeaders.setDriftCofigurationId(1);
- expectedHeaders.setDriftConfigurationName("file-added-test");
+ expectedHeaders.setDriftDefinitionId(1);
+ expectedHeaders.setDriftDefinitionName("file-added-test");
expectedHeaders.setBasedir("myresource");
expectedHeaders.setType(COVERAGE);
expectedHeaders.setVersion(1);
@@ -63,8 +63,8 @@ public class ChangeSetReaderImplTest {
Headers actualHeaders = reader.getHeaders();
Headers expectedHeaders = new Headers();
expectedHeaders.setResourceId(1);
- expectedHeaders.setDriftCofigurationId(1);
- expectedHeaders.setDriftConfigurationName("file-removed-test");
+ expectedHeaders.setDriftDefinitionId(1);
+ expectedHeaders.setDriftDefinitionName("file-removed-test");
expectedHeaders.setBasedir("myresource");
expectedHeaders.setType(COVERAGE);
expectedHeaders.setVersion(1);
@@ -96,8 +96,8 @@ public class ChangeSetReaderImplTest {
Headers actualHeaders = reader.getHeaders();
Headers expectedHeaders = new Headers();
expectedHeaders.setResourceId(1);
- expectedHeaders.setDriftCofigurationId(1);
- expectedHeaders.setDriftConfigurationName("file-changed-test");
+ expectedHeaders.setDriftDefinitionId(1);
+ expectedHeaders.setDriftDefinitionName("file-changed-test");
expectedHeaders.setBasedir("myresource");
expectedHeaders.setType(COVERAGE);
expectedHeaders.setVersion(1);
@@ -128,8 +128,8 @@ public class ChangeSetReaderImplTest {
Headers actualHeaders = reader.getHeaders();
Headers expectedHeaders = new Headers();
expectedHeaders.setResourceId(1);
- expectedHeaders.setDriftCofigurationId(1);
- expectedHeaders.setDriftConfigurationName("file-name-test");
+ expectedHeaders.setDriftDefinitionId(1);
+ expectedHeaders.setDriftDefinitionName("file-name-test");
expectedHeaders.setBasedir("myresource");
expectedHeaders.setType(COVERAGE);
expectedHeaders.setVersion(1);
diff --git
a/modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetWriterImplTest.java
b/modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetWriterImplTest.java
index 40fff48..251021a 100644
---
a/modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetWriterImplTest.java
+++
b/modules/common/drift/src/test/java/org/rhq/common/drift/ChangeSetWriterImplTest.java
@@ -63,8 +63,8 @@ public class ChangeSetWriterImplTest {
Headers headers = new Headers();
headers.setResourceId(1);
- headers.setDriftCofigurationId(2);
- headers.setDriftConfigurationName("add-file-test");
+ headers.setDriftDefinitionId(2);
+ headers.setDriftDefinitionName("add-file-test");
headers.setBasedir(resourceDir.getAbsolutePath());
headers.setType(COVERAGE);
headers.setVersion(1);
@@ -91,8 +91,8 @@ public class ChangeSetWriterImplTest {
File changeSetFile = new File(changeSetsDir, "removed-file-test");
Headers headers = new Headers();
headers.setResourceId(1);
- headers.setDriftCofigurationId(2);
- headers.setDriftConfigurationName("removed-file-test");
+ headers.setDriftDefinitionId(2);
+ headers.setDriftDefinitionName("removed-file-test");
headers.setBasedir(resourceDir.getAbsolutePath());
headers.setType(COVERAGE);
headers.setVersion(1);
@@ -119,8 +119,8 @@ public class ChangeSetWriterImplTest {
File changeSetFile = new File(changeSetsDir, "changed-file-test");
Headers headers = new Headers();
headers.setResourceId(1);
- headers.setDriftCofigurationId(2);
- headers.setDriftConfigurationName("changed-file-test");
+ headers.setDriftDefinitionId(2);
+ headers.setDriftDefinitionName("changed-file-test");
headers.setBasedir(resourceDir.getAbsolutePath());
headers.setType(COVERAGE);
headers.setVersion(1);
@@ -149,9 +149,9 @@ public class ChangeSetWriterImplTest {
void assertHeadersEquals(List<String> lines, Headers headers) {
assertEquals(lines.get(0), Integer.toString(headers.getResourceId()), "The
first header entry should be the " +
"resurce id.");
- assertEquals(lines.get(1), Integer.toString(headers.getDriftCofigurationId()),
"The second header entry " +
+ assertEquals(lines.get(1), Integer.toString(headers.getDriftDefinitionId()),
"The second header entry " +
"should be the drift configuration id.");
- assertEquals(lines.get(2), headers.getDriftConfigurationName(), "The third
header entry should be the drift " +
+ assertEquals(lines.get(2), headers.getDriftDefinitionName(), "The third
header entry should be the drift " +
"configuration name.");
assertEquals(lines.get(3), headers.getBasedir(), "The fourth header entry
should be the drift configuration " +
"base directory.");
diff --git
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
index d58c766..c121cfa 100644
---
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
+++
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/agent/drift/DriftAgentService.java
@@ -22,7 +22,7 @@ package org.rhq.core.clientapi.agent.drift;
import java.util.List;
import org.rhq.common.drift.Headers;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftFile;
/**
@@ -67,7 +67,7 @@ public interface DriftAgentService {
* @param driftConfiguration Specifies how the detection should be carried out. This
* includes any filtering rules that should be applied.
*/
- void detectDrift(int resourceId, DriftConfiguration driftConfiguration);
+ void detectDrift(int resourceId, DriftDefinition driftConfiguration);
/**
* Requests that the agent start performing drift detection for a resource with the
@@ -80,9 +80,9 @@ public interface DriftAgentService {
*
* @param resourceId The id of the resource for which the request is being made
* @param driftConfiguration Specifies how and when the detection should be carried
out
- * @see DriftConfiguration
+ * @see DriftDefinition
*/
- void scheduleDriftDetection(int resourceId, DriftConfiguration driftConfiguration);
+ void scheduleDriftDetection(int resourceId, DriftDefinition driftConfiguration);
/**
* Requests that the agent stop performing the specified drift detection for the
resource. (In
@@ -90,9 +90,9 @@ public interface DriftAgentService {
*
* @param resourceId The id of the resource for which the request is being made
* @param driftConfiguration The doomed drift config
- * @see DriftConfiguration
+ * @see DriftDefinition
*/
- void unscheduleDriftDetection(int resourceId, DriftConfiguration
driftConfiguration);
+ void unscheduleDriftDetection(int resourceId, DriftDefinition driftConfiguration);
/**
* Requests that the agent update its processing of the specified driftConfiguration.
The filters
@@ -100,9 +100,9 @@ public interface DriftAgentService {
*
* @param resourceId The id of the resource for which the request is being made
* @param driftConfiguration The updated driftConfiguration.
- * @see DriftConfiguration
+ * @see DriftDefinition
*/
- void updateDriftDetection(int resourceId, DriftConfiguration driftConfiguration);
+ void updateDriftDetection(int resourceId, DriftDefinition driftConfiguration);
/**
* This method is invoked to inform the agent that the server has successfully
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 e856e2b..08b2180 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
@@ -499,7 +499,7 @@ public class PluginMetadataParser {
+ descriptor.getName() + "]");
}
driftConfigNames.add(descriptor.getName());
-
resourceType.addDriftConfigurationTemplate(driftMetadataParser.parseDriftMetadata(descriptor));
+
resourceType.addDriftDefinitionTemplate(driftMetadataParser.parseDriftMetadata(descriptor));
}
driftConfigNames = null; // don't need this anymore
diff --git
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
index 4f1deef..c7c88ef 100644
---
a/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
+++
b/modules/core/client-api/src/main/java/org/rhq/core/clientapi/server/drift/DriftServerService.java
@@ -25,7 +25,7 @@ import java.util.Map;
import java.util.Set;
import org.rhq.core.communications.command.annotation.Asynchronous;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftSnapshot;
/**
@@ -117,7 +117,7 @@ public interface DriftServerService {
@Asynchronous(guaranteedDelivery = true)
void sendFilesZip(int resourceId, String driftConfigName, String token, long zipSize,
InputStream zipStream);
- Map<Integer, List<DriftConfiguration>>
getDriftConfigurations(Set<Integer> resourceIds);
+ Map<Integer, List<DriftDefinition>>
getDriftDefinitions(Set<Integer> resourceIds);
DriftSnapshot getCurrentSnapshot(int driftConfigurationId);
}
diff --git
a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
index 7adf6fa..6f134d2 100644
---
a/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
+++
b/modules/core/client-api/src/test/java/org/rhq/core/clientapi/agent/metadata/test/PluginMetadataParserTest.java
@@ -40,9 +40,9 @@ import org.rhq.core.domain.configuration.PropertySimple;
import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.configuration.definition.ConfigurationFormat;
import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftConfigurationDefinition;
-import org.rhq.core.domain.drift.DriftConfiguration.BaseDirectory;
+import org.rhq.core.domain.drift.DriftDefinition.BaseDirectory;
import org.rhq.core.domain.drift.Filter;
import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
import org.rhq.core.domain.resource.ResourceType;
@@ -379,7 +379,7 @@ public class PluginMetadataParserTest {
verifyDriftConfiguration(descriptor, "TestServer", "test1",
new AssertDriftTemplateRunnable() {
@Override
public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
- DriftConfiguration dc = new
DriftConfiguration(driftTemplate.getConfiguration());
+ DriftDefinition dc = new
DriftDefinition(driftTemplate.getConfiguration());
BaseDirectory basedir = dc.getBasedir();
assertEquals(basedir.getValueContext(),
BaseDirValueContext.pluginConfiguration, "Bad value context");
assertEquals(basedir.getValueName(), "var.lib.test1", "Bad
value name");
@@ -638,7 +638,7 @@ public class PluginMetadataParserTest {
@Override
public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
Configuration config = driftTemplate.getConfiguration();
- DriftConfiguration dconfig = new DriftConfiguration(config);
+ DriftDefinition dconfig = new DriftDefinition(config);
assertEquals(dconfig.getInterval(), 11111L);
assertEquals(dconfig.getBasedir().getValueContext(),
BaseDirValueContext.pluginConfiguration);
@@ -678,7 +678,7 @@ public class PluginMetadataParserTest {
@Override
public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
Configuration config = driftTemplate.getConfiguration();
- DriftConfiguration dconfig = new DriftConfiguration(config);
+ DriftDefinition dconfig = new DriftDefinition(config);
assertEquals(dconfig.getInterval(), 22222L);
assertEquals(dconfig.getBasedir().getValueContext(),
BaseDirValueContext.resourceConfiguration);
@@ -718,7 +718,7 @@ public class PluginMetadataParserTest {
@Override
public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
Configuration config = driftTemplate.getConfiguration();
- DriftConfiguration dconfig = new DriftConfiguration(config);
+ DriftDefinition dconfig = new DriftDefinition(config);
assertEquals(dconfig.getInterval(), 33333L);
assertEquals(dconfig.getBasedir().getValueContext(),
BaseDirValueContext.measurementTrait);
@@ -780,7 +780,7 @@ public class PluginMetadataParserTest {
@Override
public void assertDriftTemplate(ConfigurationTemplate driftTemplate) throws
Exception {
Configuration config = driftTemplate.getConfiguration();
- DriftConfiguration dconfig = new DriftConfiguration(config);
+ DriftDefinition dconfig = new DriftDefinition(config);
assertEquals(dconfig.getInterval(), 44444L);
assertEquals(dconfig.getBasedir().getValueContext(),
BaseDirValueContext.fileSystem);
@@ -805,7 +805,7 @@ public class PluginMetadataParserTest {
Map<String, PluginMetadataParser> parsersByPlugin = new HashMap<String,
PluginMetadataParser>(0);
PluginMetadataParser parser = new PluginMetadataParser(descriptor,
parsersByPlugin);
ResourceType resourceType = findResourceType(parser, resourceTypeName);
- Set<ConfigurationTemplate> driftTemplates =
resourceType.getDriftConfigurationTemplates();
+ Set<ConfigurationTemplate> driftTemplates =
resourceType.getDriftDefinitionTemplates();
ConfigurationTemplate driftTemplate = null;
for (ConfigurationTemplate template : driftTemplates) {
if (template.getName().equals(driftConfigName)) {
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftChangeSetCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftChangeSetCriteria.java
index a3c61a6..8a7df2d 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftChangeSetCriteria.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftChangeSetCriteria.java
@@ -58,9 +58,9 @@ public interface DriftChangeSetCriteria extends BaseCriteria {
Integer getFilterResourceId();
- void addFilterDriftConfigurationId(Integer filterDriftConfigId);
+ void addFilterDriftDefinitionId(Integer filterDriftDefId);
- Integer getFilterDriftConfigurationId();
+ Integer getFilterDriftDefintionId();
void addFilterCategory(DriftChangeSetCategory filterCategory);
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftConfigurationCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftConfigurationCriteria.java
deleted file mode 100644
index e2ed959..0000000
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftConfigurationCriteria.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.core.domain.criteria;
-
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlRootElement;
-
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.util.CriteriaUtils;
-import org.rhq.core.domain.util.PageOrdering;
-
-/**
- * RHQ Criteria query support for DriftConfiguration. This is not drift server plugin
supported, DriftConfiguration
- * is a native entity.
- *
- * @author Jay Shaughnessy
- */
-@XmlRootElement
-(a)XmlAccessorType(XmlAccessType.FIELD)
-@SuppressWarnings("unused")
-public class DriftConfigurationCriteria extends Criteria {
- private static final long serialVersionUID = 1L;
-
- private Integer filterId;
- private String filterName;
- private List<Integer> filterResourceIds; // needs override
-
- private Boolean fetchConfiguration;
- private Boolean fetchResource;
-
- private PageOrdering sortName;
-
- public DriftConfigurationCriteria() {
- filterOverrides.put("resourceIds", "resource.id IN ( ? )");
- }
-
- @Override
- public Class<DriftConfiguration> getPersistentClass() {
- return DriftConfiguration.class;
- }
-
- public void addFilterId(String filterId) {
- if (filterId != null) {
- this.filterId = Integer.parseInt(filterId);
- }
- }
-
- public void addFilterName(String name) {
- this.filterName = name;
- }
-
- public void addFilterResourceIds(Integer... filterResourceIds) {
- this.filterResourceIds = CriteriaUtils.getListIgnoringNulls(filterResourceIds);
- }
-
- public void fetchConfiguration(Boolean fetchConfiguration) {
- this.fetchConfiguration = fetchConfiguration;
- }
-
- public void fetchResource(Boolean fetchResource) {
- this.fetchResource = fetchResource;
- }
-
- public void addSortName(PageOrdering sortName) {
- addSortField("name");
- this.sortName = sortName;
- }
-}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftDefinitionCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftDefinitionCriteria.java
new file mode 100644
index 0000000..d5bb40c
--- /dev/null
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/DriftDefinitionCriteria.java
@@ -0,0 +1,85 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.core.domain.criteria;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.util.CriteriaUtils;
+import org.rhq.core.domain.util.PageOrdering;
+
+/**
+ * RHQ Criteria query support for @{link DriftDefinition}. This is not drift server
plugin supported,
+ * DriftDefintition is a native entity.
+ *
+ * @author Jay Shaughnessy
+ */
+@XmlRootElement
+(a)XmlAccessorType(XmlAccessType.FIELD)
+@SuppressWarnings("unused")
+public class DriftDefinitionCriteria extends Criteria {
+ private static final long serialVersionUID = 1L;
+
+ private Integer filterId;
+ private String filterName;
+ private List<Integer> filterResourceIds; // needs override
+
+ private Boolean fetchConfiguration;
+ private Boolean fetchResource;
+
+ private PageOrdering sortName;
+
+ public DriftDefinitionCriteria() {
+ filterOverrides.put("resourceIds", "resource.id IN ( ? )");
+ }
+
+ @Override
+ public Class<DriftDefinition> getPersistentClass() {
+ return DriftDefinition.class;
+ }
+
+ public void addFilterId(Integer filterId) {
+ this.filterId = filterId;
+ }
+
+ public void addFilterName(String name) {
+ this.filterName = name;
+ }
+
+ public void addFilterResourceIds(Integer... filterResourceIds) {
+ this.filterResourceIds = CriteriaUtils.getListIgnoringNulls(filterResourceIds);
+ }
+
+ public void fetchConfiguration(Boolean fetchConfiguration) {
+ this.fetchConfiguration = fetchConfiguration;
+ }
+
+ public void fetchResource(Boolean fetchResource) {
+ this.fetchResource = fetchResource;
+ }
+
+ public void addSortName(PageOrdering sortName) {
+ addSortField("name");
+ this.sortName = sortName;
+ }
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/GenericDriftChangeSetCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/GenericDriftChangeSetCriteria.java
index 073d89e..a4b4255 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/GenericDriftChangeSetCriteria.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/GenericDriftChangeSetCriteria.java
@@ -52,7 +52,7 @@ public class GenericDriftChangeSetCriteria implements Serializable,
DriftChangeS
private Integer filterResourceId;
- private Integer filterDriftConfigId;
+ private Integer filterDriftDefId;
private DriftChangeSetCategory filterCategory;
@@ -133,13 +133,13 @@ public class GenericDriftChangeSetCriteria implements Serializable,
DriftChangeS
}
@Override
- public void addFilterDriftConfigurationId(Integer filterDriftConfigId) {
- this.filterDriftConfigId = filterDriftConfigId;
+ public void addFilterDriftDefinitionId(Integer filterDriftDefId) {
+ this.filterDriftDefId = filterDriftDefId;
}
@Override
- public Integer getFilterDriftConfigurationId() {
- return filterDriftConfigId;
+ public Integer getFilterDriftDefintionId() {
+ return filterDriftDefId;
}
@Override
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/JPADriftChangeSetCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/JPADriftChangeSetCriteria.java
index a7262a2..c522996 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/JPADriftChangeSetCriteria.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/JPADriftChangeSetCriteria.java
@@ -41,7 +41,7 @@ public class JPADriftChangeSetCriteria extends Criteria implements
DriftChangeSe
private Integer filterId;
private Integer filterInitial; // needs override
private Integer filterResourceId; // needs override
- private Integer filterDriftConfigurationId; // needs override
+ private Integer filterDriftDefinitionId; // needs override
private Integer filterVersion;
private Integer filterStartVersion;
private Integer filterEndVersion;
@@ -49,7 +49,7 @@ public class JPADriftChangeSetCriteria extends Criteria implements
DriftChangeSe
private Long filterCreatedBefore;
private DriftChangeSetCategory filterCategory;
private Boolean fetchDrifts;
- private Boolean fetchDriftConfiguration;
+ private Boolean fetchDriftDefinition;
private PageOrdering sortVersion;
@@ -64,13 +64,13 @@ public class JPADriftChangeSetCriteria extends Criteria implements
DriftChangeSe
filterOverrides.put("endVersion", "version <= ?");
filterOverrides.put("createdAfter", "ctime >= ?");
filterOverrides.put("createdBefore", "ctime <= ?");
- filterOverrides.put("driftConfigurationId", "driftConfiguration.id
= ?");
+ filterOverrides.put("driftDefinitionId", "driftDefinition.id =
?");
if (null != changeSetCriteria) {
this.addFilterCategory(changeSetCriteria.getFilterCategory());
this.addFilterCreatedAfter(changeSetCriteria.getFilterCreatedAfter());
this.addFilterCreatedBefore(changeSetCriteria.getFilterCreatedBefore());
-
this.addFilterDriftConfigurationId(changeSetCriteria.getFilterDriftConfigurationId());
+
this.addFilterDriftDefinitionId(changeSetCriteria.getFilterDriftDefintionId());
this.addFilterEndVersion(changeSetCriteria.getFilterEndVersion());
this.addFilterId(changeSetCriteria.getFilterId());
this.addFilterResourceId(changeSetCriteria.getFilterResourceId());
@@ -164,13 +164,13 @@ public class JPADriftChangeSetCriteria extends Criteria implements
DriftChangeSe
}
@Override
- public void addFilterDriftConfigurationId(Integer filterDriftConfigId) {
- this.filterDriftConfigurationId = filterDriftConfigId;
+ public void addFilterDriftDefinitionId(Integer filterDriftDefId) {
+ this.filterDriftDefinitionId = filterDriftDefId;
}
@Override
- public Integer getFilterDriftConfigurationId() {
- return filterDriftConfigurationId;
+ public Integer getFilterDriftDefintionId() {
+ return filterDriftDefinitionId;
}
public void addFilterCategory(DriftChangeSetCategory filterCategory) {
@@ -191,8 +191,8 @@ public class JPADriftChangeSetCriteria extends Criteria implements
DriftChangeSe
return fetchDrifts;
}
- public void fetchDriftConfiguration(boolean fetchDriftConfiguration) {
- this.fetchDriftConfiguration = fetchDriftConfiguration;
+ public void fetchDriftDefinition(boolean fetchDriftDefinition) {
+ this.fetchDriftDefinition = fetchDriftDefinition;
}
public void addSortVersion(PageOrdering sortVersion) {
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceCriteria.java
index 87e1d8f..0386ea3 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceCriteria.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceCriteria.java
@@ -90,7 +90,7 @@ public class ResourceCriteria extends TaggedCriteria {
private boolean fetchResourceErrors;
private boolean fetchEventSources;
private boolean fetchProductVersion;
- private boolean fetchDriftConfigurations;
+ private boolean fetchDriftDefinitions;
private PageOrdering sortName;
private PageOrdering sortInventoryStatus;
@@ -331,8 +331,8 @@ public class ResourceCriteria extends TaggedCriteria {
this.fetchProductVersion = fetchProductVersion;
}
- public void fetchDriftConfigurations(boolean fetchDriftConfigurations) {
- this.fetchDriftConfigurations = fetchDriftConfigurations;
+ public void fetchDriftDefinitions(boolean fetchDriftDefinitions) {
+ this.fetchDriftDefinitions = fetchDriftDefinitions;
}
public void addSortName(PageOrdering sortName) {
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceTypeCriteria.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceTypeCriteria.java
index 2cf1025..7abb782 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceTypeCriteria.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/criteria/ResourceTypeCriteria.java
@@ -74,7 +74,7 @@ public class ResourceTypeCriteria extends Criteria {
private boolean fetchProductVersions;
private boolean fetchBundleType;
private boolean fetchResources;
- private boolean fetchDriftConfigurationTemplates;
+ private boolean fetchDriftDefinitionTemplates;
private boolean fetchBundleConfiguration;
private PageOrdering sortName;
@@ -204,8 +204,8 @@ public class ResourceTypeCriteria extends Criteria {
this.fetchResources = fetchResources;
}
- public void fetchDriftConfigurationTemplates(boolean
fetchDriftConfigurationTemplates) {
- this.fetchDriftConfigurationTemplates = fetchDriftConfigurationTemplates;
+ public void fetchDriftDefinitionTemplates(boolean fetchDriftDefinitionTemplates) {
+ this.fetchDriftDefinitionTemplates = fetchDriftDefinitionTemplates;
}
public void fetchBundleConfiguration(boolean fetchBundleConfiguration) {
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftChangeSet.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftChangeSet.java
index 5ad5796..a5a5e3c 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftChangeSet.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftChangeSet.java
@@ -31,10 +31,10 @@ import
org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
* the contract required for defining and persisting a DriftChangeSet. Drift server
plugins
* are responsible for managing persistence.
* <p/>
- * Each DriftChangeSet belongs to a particular {@link DriftConfiguration} which
specifies
- * the rules for how drift detection is performed (by the agent). A DriftConfiguration
is
+ * Each DriftChangeSet belongs to a particular {@link DriftDefinition} which specifies
+ * the rules for how drift detection is performed (by the agent). A DriftDefinition is
* in turn owned by a {@link org.rhq.core.domain.resource.Resource Resource} and a
resource
- * can have multiple drift configurations.
+ * can have multiple drift definitions.
*
* @param <D> A server plugin's Drift implementation
*
@@ -64,18 +64,18 @@ public interface DriftChangeSet<D extends Drift<?, ?>> {
/**
* Every change set must be assigned a version that is unique within the context of
the
- * owning {@link DriftConfiguration}. This is analgous to a revision number in a
+ * owning {@link DriftDefinition}. This is analgous to a revision number in a
* version control system like SVN.
*
* @return The change set version number that is unique within the context of its
- * owning {@link DriftConfiguration}.
+ * owning {@link DriftDefinition}.
*/
int getVersion();
/**
* Sets the change set version number. Note that change set version numbers
* <strong>must</strong> be unique within the context of the owning
- * {@link DriftConfiguration}. Change sets should be assigned version numbers in
+ * {@link DriftDefinition}. Change sets should be assigned version numbers in
* increasing order. The first change set saved should have a version of N, the
second
* should have a value of N + 1, etc.
*
@@ -99,49 +99,49 @@ public interface DriftChangeSet<D extends Drift<?, ?>> {
void setCategory(DriftChangeSetCategory category);
/**
- * Returns the drift handling mode of the owning drift configuration at the time of
change
- * set creation. Because the value set on the owning drift configuration can change,
the
+ * Returns the drift handling mode of the owning drift definition at the time of
change
+ * set creation. Because the value set on the owning drift definition can change,
the
* value must be stored with the change set such that it can be applied consistently
when
* handling the associated drift.
*
- * @return The {@link DriftConfiguration.DriftHandlingMode} mode
+ * @return The {@link DriftDefinition.DriftHandlingMode} mode
*/
DriftHandlingMode getDriftHandlingMode();
/**
* Sets the drift handling mode for the change set. It should be set to the owning
drift
- * configuration's drift handling mode at the time of change set creation.
Because the
- * value set on the owning drift configuration can change, the value must be stored
with
+ * definition's drift handling mode at the time of change set creation. Because
the
+ * value set on the owning drift definition can change, the value must be stored with
* the change set such that it can be applied consistently when handling the
associated drift.
*
- * @param driftHandlingMode The {@link DriftConfiguration.DriftHandlingMode} mode
+ * @param driftHandlingMode The {@link DriftDefinition.DriftHandlingMode} mode
*/
void setDriftHandlingMode(DriftHandlingMode driftHandlingMode);
/**
- * Returns the id of the owning drift configuration. Note that while server plugins
are
+ * Returns the id of the owning drift definition. Note that while server plugins are
* responsible for managing the persistence of change sets, the RHQ server manages
the
- * persistence of the owning drift configuration.
+ * persistence of the owning drift definition.
*
- * @return The {@link DriftConfiguration} id
+ * @return The {@link DriftDefinition} id
*/
- int getDriftConfigurationId();
+ int getDriftDefinitionId();
/**
- * Sets the id of the owning drift configuration. Note that while server plugins are
+ * Sets the id of the owning drift definition. Note that while server plugins are
* responsible for managing the persistence of change sets, the RHQ server manages
the
- * persistence of the drift configuration.
+ * persistence of the drift definition.
*
- * @param id The {@link DriftConfiguration} id
+ * @param id The {@link DriftDefinition} id
*/
- void setDriftConfigurationId(int id);
+ void setDriftDefinitionId(int id);
/**
- * Returns the id of the resource to which the drift configuration is assigned. Note
+ * Returns the id of the resource to which the drift definition is assigned. Note
* that the RHQ server and not drift server plugins manage the persistence of the
* resource.
*
- * @return The id of the resource to which the drift configuration belongs
+ * @return The id of the resource to which the drift definition belongs
*/
int getResourceId();
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftComposite.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftComposite.java
index 072f432..5dbd57a 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftComposite.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftComposite.java
@@ -39,7 +39,7 @@ public class DriftComposite implements Serializable {
this.resource = resource;
}
- public String getDriftConfigName() {
+ public String getDriftDefinitionName() {
return driftConfigName;
}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
deleted file mode 100644
index d7ac85a..0000000
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfiguration.java
+++ /dev/null
@@ -1,421 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.core.domain.drift;
-
-import static java.util.Collections.emptyList;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.PrePersist;
-import javax.persistence.SequenceGenerator;
-import javax.persistence.Table;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.Property;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.configuration.PropertyMap;
-import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
-import org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
-import org.rhq.core.domain.resource.Resource;
-
-/**
- * This is a convienence wrapper around a Configuration object whose schema is that
- * of {@link DriftConfigurationDefinition}.
- *
- * Note that this is not an actual Configuration object - it's got a HAS-A
relationship
- * with Configuration.
- *
- * This object also has an optional relationship with a Resource.
- *
- * @author John Sanda
- * @author John Mazzitelli
- * @author Jay Shaughnessy
- */
-@Entity
-@Table(name = "RHQ_DRIFT_CONFIG")
-@SequenceGenerator(name = "SEQ", sequenceName =
"RHQ_DRIFT_CONFIG_ID_SEQ")
-public class DriftConfiguration implements Serializable {
- private static final long serialVersionUID = 1L;
-
- @Column(name = "ID", nullable = false)
- @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
- @Id
- private int id;
-
- @Column(name = "CTIME", nullable = false)
- private Long ctime = -1L;
-
- @Column(name = "NAME", nullable = false)
- private String name;
-
- @Column(name = "IS_ENABLED", nullable = false)
- private boolean isEnabled;
-
- @Column(name = "DRIFT_HANDLING_MODE", nullable = false)
- @Enumerated(EnumType.STRING)
- private DriftHandlingMode driftHandlingMode;
-
- // unit = millis
- @Column(name = "INTERVAL", nullable = false)
- private long interval;
-
- @JoinColumn(name = "CONFIG_ID", referencedColumnName = "ID",
nullable = false)
- @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = false)
- private Configuration configuration;
-
- @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "ID",
nullable = true)
- @ManyToOne(optional = true)
- private Resource resource = null;
-
- // required for jaxb/web services stuff
- protected DriftConfiguration() {
- }
-
- public DriftConfiguration(Configuration c) {
- this.setConfiguration(c);
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
- public Long getCtime() {
- return ctime;
- }
-
- @PrePersist
- void onPersist() {
- this.ctime = System.currentTimeMillis();
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- if (null == name) {
- throw new IllegalArgumentException("Drift congig name can not be
null");
- }
-
- this.name = name;
- this.setNameProperty(name);
- }
-
- public boolean isEnabled() {
- return isEnabled;
- }
-
- /**
- * If null set to default
- * @param isEnabled
- */
- public void setEnabled(Boolean isEnabled) {
- if (isEnabled == null) {
- isEnabled = DriftConfigurationDefinition.DEFAULT_ENABLED;
- }
-
- this.isEnabled = isEnabled;
- this.setEnabledProperty(isEnabled);
- }
-
- public DriftHandlingMode getDriftHandlingMode() {
- return driftHandlingMode;
- }
-
- public void setDriftHandlingMode(DriftHandlingMode driftHandlingMode) {
- if (null == driftHandlingMode) {
- driftHandlingMode =
DriftConfigurationDefinition.DEFAULT_DRIFT_HANDLING_MODE;
- }
-
- this.driftHandlingMode = driftHandlingMode;
- this.setDriftHandlingModeProperty(driftHandlingMode);
- }
-
- public long getInterval() {
- return interval;
- }
-
- /**
- * If null, set to default.
- * @param interval
- */
- public void setInterval(Long interval) {
- if (interval == null) {
- interval = DriftConfigurationDefinition.DEFAULT_INTERVAL;
- }
-
- this.interval = interval;
- this.setIntervalProperty(interval);
- }
-
- public Configuration getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(Configuration configuration) {
- this.configuration = configuration;
- this.name = this.getNameProperty();
- this.isEnabled = this.getIsEnabledProperty();
- this.interval = this.getIntervalProperty();
- this.driftHandlingMode = this.getDriftHandlingModeProperty();
- }
-
- public Resource getResource() {
- return resource;
- }
-
- public void setResource(Resource resource) {
- this.resource = resource;
- if (this.resource != null) {
- this.resource.getDriftConfigurations().add(this);
- }
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("DriftConfiguration [id=").append(id).append(",
name=").append(name).append(", enabled=")
- .append(isEnabled).append(",
interval=").append(interval).append(",
resource=").append(resource).append(
- ", basedir=").append(getBasedir()).append(",
includes=").append(getIncludes()).append(", excludes=")
- .append(getExcludes()).append("]");
- return builder.toString();
- }
-
- public static class BaseDirectory implements Serializable {
- private static final long serialVersionUID = 1L;
- private BaseDirValueContext context;
- private String name;
-
- // required for jaxb/web services remoting
- protected BaseDirectory() {
- }
-
- public BaseDirectory(BaseDirValueContext context, String name) {
- this.context = context;
- this.name = name;
- }
-
- public BaseDirValueContext getValueContext() {
- return context;
- }
-
- public String getValueName() {
- return name;
- }
-
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("BaseDirectory
[context=").append(context).append(",
name=").append(name).append("]");
- return builder.toString();
- }
-
- @Override
- public int hashCode() {
- int result = 1;
- result = 31 * result + ((context == null) ? 0 : context.hashCode());
- result = 31 * result + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof BaseDirectory)) {
- return false;
- }
- BaseDirectory other = (BaseDirectory) obj;
- if (context == null) {
- if (other.context != null) {
- return false;
- }
- } else if (!context.equals(other.context)) {
- return false;
- }
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- return true;
- }
- }
-
- private String getNameProperty() {
- return configuration.getSimpleValue(DriftConfigurationDefinition.PROP_NAME,
null);
- }
-
- private void setNameProperty(String name) {
- if (name == null) {
- throw new IllegalArgumentException("name is null");
- }
- configuration.put(new PropertySimple(DriftConfigurationDefinition.PROP_NAME,
name));
- }
-
- public BaseDirectory getBasedir() {
- PropertyMap map =
configuration.getMap(DriftConfigurationDefinition.PROP_BASEDIR);
- if (map == null) {
- return null;
- }
-
- String valueContext =
map.getSimpleValue(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT, null);
- String valueName =
map.getSimpleValue(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME, null);
-
- BaseDirValueContext valueContextEnum;
-
- if (valueContext == null) {
- throw new NullPointerException("valueContext is null");
- } else {
- try {
- valueContextEnum = BaseDirValueContext.valueOf(valueContext);
- } catch (Exception e) {
- throw new IllegalArgumentException("Invalid valueContext: " +
valueContext);
- }
- }
-
- if (valueName == null) {
- throw new NullPointerException("valueName is null");
- }
-
- return new BaseDirectory(valueContextEnum, valueName);
- }
-
- public void setBasedir(BaseDirectory basedir) {
- if (basedir == null) {
- throw new NullPointerException("basedir is null");
- }
- if (basedir.getValueContext() == null) {
- throw new NullPointerException("valueContext is null");
- }
- if (basedir.getValueName() == null) {
- throw new NullPointerException("valueName is null");
- }
-
- String valueContext = basedir.getValueContext().name();
- String valueName = basedir.getValueName();
-
- PropertyMap basedirMap = new
PropertyMap(DriftConfigurationDefinition.PROP_BASEDIR);
- basedirMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT, valueContext));
- basedirMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME, valueName));
-
- configuration.put(basedirMap);
- }
-
- private Long getIntervalProperty() {
- return
Long.parseLong(configuration.getSimpleValue(DriftConfigurationDefinition.PROP_INTERVAL,
String
- .valueOf(DriftConfigurationDefinition.DEFAULT_INTERVAL)));
- }
-
- private void setIntervalProperty(Long interval) {
- configuration.put(new PropertySimple(DriftConfigurationDefinition.PROP_INTERVAL,
interval.toString()));
- }
-
- private DriftHandlingMode getDriftHandlingModeProperty() {
- return DriftHandlingMode.valueOf(configuration.getSimpleValue(
- DriftConfigurationDefinition.PROP_DRIFT_HANDLING_MODE,
- DriftConfigurationDefinition.DEFAULT_DRIFT_HANDLING_MODE.name()));
- }
-
- private void setDriftHandlingModeProperty(DriftHandlingMode mode) {
- configuration.put(new
PropertySimple(DriftConfigurationDefinition.PROP_DRIFT_HANDLING_MODE, mode.name()));
- }
-
- private boolean getIsEnabledProperty() {
- return configuration.getSimpleValue(DriftConfigurationDefinition.PROP_ENABLED,
-
String.valueOf(DriftConfigurationDefinition.DEFAULT_ENABLED)).equals("true");
- }
-
- private void setEnabledProperty(boolean enabled) {
- configuration.put(new PropertySimple(DriftConfigurationDefinition.PROP_ENABLED,
String.valueOf(enabled)));
- }
-
- public List<Filter> getIncludes() {
- return getFilters(DriftConfigurationDefinition.PROP_INCLUDES);
- }
-
- public List<Filter> getExcludes() {
- return getFilters(DriftConfigurationDefinition.PROP_EXCLUDES);
- }
-
- public void addInclude(Filter filter) {
- PropertyList filtersList =
configuration.getList(DriftConfigurationDefinition.PROP_INCLUDES);
- if (filtersList == null) {
- // this is going to be our first include filter - make sure we create an
initial list and put it in the config
- filtersList = new PropertyList(DriftConfigurationDefinition.PROP_INCLUDES);
- configuration.put(filtersList);
- }
-
- PropertyMap filterMap = new
PropertyMap(DriftConfigurationDefinition.PROP_INCLUDES_INCLUDE);
- filterMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATH,
filter.getPath()));
- filterMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATTERN,
filter.getPattern()));
- filtersList.add(filterMap);
- }
-
- public void addExclude(Filter filter) {
- PropertyList filtersList =
configuration.getList(DriftConfigurationDefinition.PROP_EXCLUDES);
- if (filtersList == null) {
- // this is going to be our first include filter - make sure we create an
initial list and put it in the config
- filtersList = new PropertyList(DriftConfigurationDefinition.PROP_EXCLUDES);
- configuration.put(filtersList);
- }
-
- PropertyMap filterMap = new
PropertyMap(DriftConfigurationDefinition.PROP_EXCLUDES_EXCLUDE);
- filterMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATH,
filter.getPath()));
- filterMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATTERN,
filter.getPattern()));
- filtersList.add(filterMap);
- }
-
- private List<Filter> getFilters(String type) {
- PropertyList filtersListProperty = configuration.getList(type);
- if (filtersListProperty == null) {
- return emptyList();
- }
-
- List<Filter> filters = new ArrayList<Filter>();
- for (Property property : filtersListProperty.getList()) {
- PropertyMap filter = (PropertyMap) property;
- filters.add(new
Filter(filter.getSimpleValue(DriftConfigurationDefinition.PROP_PATH, ""),
filter
- .getSimpleValue(DriftConfigurationDefinition.PROP_PATTERN,
"")));
- }
-
- return filters;
- }
-}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationComparator.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationComparator.java
deleted file mode 100644
index d530ab4..0000000
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftConfigurationComparator.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-package org.rhq.core.domain.drift;
-
-import java.util.Comparator;
-import java.util.List;
-
-/**
- * Compares two {@link DriftConfiguration} objects. The comparison can either
- * compare basedir/includes-excludes filters or ignore them. Will also compare
- * name, interval, enabled flag.
- *
- * @author John Mazzitelli
- */
-public class DriftConfigurationComparator implements Comparator<DriftConfiguration>
{
-
- public enum CompareMode {
- /**
- * The comparator will only check the base information: name, enabled, interval,
driftHandlingMode
- * The basedir/includes-excludes filters will be ignored.
- */
- ONLY_BASE_INFO,
-
- /**
- * The comparator will only check the basedir/includes-excludes filters.
- * The base information will be ignored (see {@link #ONLY_BASE_INFO} for what
those are).
- */
- ONLY_DIRECTORY_SPECIFICATIONS,
-
- /**
- * The comparator will check both the basedir/includes-excludes filters and
- * the base information (see {@link #ONLY_BASE_INFO} for what those are).
- */
- BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS;
- };
-
- private final CompareMode compareMode;
-
- public DriftConfigurationComparator(CompareMode mode) {
- this.compareMode = mode;
- }
-
- @Override
- public int compare(DriftConfiguration dc1, DriftConfiguration dc2) {
- if (compareMode != CompareMode.ONLY_DIRECTORY_SPECIFICATIONS) {
- if (dc1.getName() != null) {
- if (dc2.getName() != null) {
- int results = dc1.getName().compareTo(dc2.getName());
- if (results != 0) {
- return results;
- }
- } else {
- return 1; // dc1's name is not null, but dc2's name is null,
not equal!
- }
- } else if (dc2.getName() != null) {
- return -1; // dc1's name is null, but dc2's name is not null, not
equal!
- }
-
- if (dc1.getInterval() != dc2.getInterval()) {
- return dc1.getInterval() < dc2.getInterval() ? -1 : 1;
- }
-
- if (dc1.getDriftHandlingMode() != dc2.getDriftHandlingMode()) {
- return dc1.getDriftHandlingMode().ordinal() <
dc2.getDriftHandlingMode().ordinal() ? -1 : 1;
- }
-
- if (dc1.isEnabled() != dc2.isEnabled()) {
- return dc1.isEnabled() ? 1 : -1; // so false sorts before true, seems
logical to me
- }
- }
-
- if (compareMode != CompareMode.ONLY_BASE_INFO) {
- if (dc1.getBasedir() != null) {
- if (!dc1.getBasedir().equals(dc2.getBasedir())) {
- int hash1 = dc1.getBasedir().hashCode();
- int hash2 = (dc2.getBasedir() != null) ? dc2.getBasedir().hashCode()
: 0;
- return hash1 < hash2 ? -1 : 1;
- }
- } else if (dc2.getBasedir() != null) {
- return -1; // dc1's basedir is null, but dc2's basedir is not
null, not equal!
- }
-
- List<Filter> filters1 = dc1.getIncludes();
- List<Filter> filters2 = dc2.getIncludes();
- int results = compareFilters(filters1, filters2);
- if (results != 0) {
- return results;
- }
-
- filters1 = dc1.getExcludes();
- filters2 = dc2.getExcludes();
- results = compareFilters(filters1, filters2);
- if (results != 0) {
- return results;
- }
- }
-
- return 0;
- }
-
- private int compareFilters(List<Filter> filters1, List<Filter> filters2)
{
- if (filters1 == null) {
- return (filters2 == null) ? 0 : -1;
- } else if (filters2 == null) {
- return 1;
- }
-
- // at this point, we know both filters1 and filters2 are non-null
- // let's do the next easiest check - size. If the lists are different sizes,
then clearly they are different
- if (filters1.size() != filters2.size()) {
- return (filters1.size() < filters2.size()) ? -1 : 1;
- }
-
- // they are the same size, let's see if they have the same items. We only
need to see if one contains
- // all of the other; because they are the same size, if filters1 contains all the
filters2 items,
- // then clearly the other way is true too (filters2 contains all of filters1
items).
- if (!filters1.containsAll(filters2)) {
- return -1; // unsure if we need to do further anaylsis to determine if -1 or
1 should be returned; for now, don't worry about it
- }
-
- return 0;
- }
-}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDefinition.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDefinition.java
new file mode 100644
index 0000000..33bb483
--- /dev/null
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDefinition.java
@@ -0,0 +1,421 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.core.domain.drift;
+
+import static java.util.Collections.emptyList;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.PrePersist;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
+import org.rhq.core.domain.resource.Resource;
+
+/**
+ * This is a convienence wrapper around a Configuration object whose schema is that
+ * of {@link DriftConfigurationDefinition}.
+ *
+ * Note that this is not an actual Configuration object - it's got a HAS-A
relationship
+ * with Configuration.
+ *
+ * This object also has an optional relationship with a Resource.
+ *
+ * @author John Sanda
+ * @author John Mazzitelli
+ * @author Jay Shaughnessy
+ */
+@Entity
+@Table(name = "RHQ_DRIFT_CONFIG")
+@SequenceGenerator(name = "SEQ", sequenceName =
"RHQ_DRIFT_CONFIG_ID_SEQ")
+public class DriftDefinition implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ @Column(name = "ID", nullable = false)
+ @GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
+ @Id
+ private int id;
+
+ @Column(name = "CTIME", nullable = false)
+ private Long ctime = -1L;
+
+ @Column(name = "NAME", nullable = false)
+ private String name;
+
+ @Column(name = "IS_ENABLED", nullable = false)
+ private boolean isEnabled;
+
+ @Column(name = "DRIFT_HANDLING_MODE", nullable = false)
+ @Enumerated(EnumType.STRING)
+ private DriftHandlingMode driftHandlingMode;
+
+ // unit = millis
+ @Column(name = "INTERVAL", nullable = false)
+ private long interval;
+
+ @JoinColumn(name = "CONFIG_ID", referencedColumnName = "ID",
nullable = false)
+ @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = false)
+ private Configuration configuration;
+
+ @JoinColumn(name = "RESOURCE_ID", referencedColumnName = "ID",
nullable = true)
+ @ManyToOne(optional = true)
+ private Resource resource = null;
+
+ // required for jaxb/web services stuff
+ protected DriftDefinition() {
+ }
+
+ public DriftDefinition(Configuration c) {
+ this.setConfiguration(c);
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public Long getCtime() {
+ return ctime;
+ }
+
+ @PrePersist
+ void onPersist() {
+ this.ctime = System.currentTimeMillis();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ if (null == name) {
+ throw new IllegalArgumentException("Drift congig name can not be
null");
+ }
+
+ this.name = name;
+ this.setNameProperty(name);
+ }
+
+ public boolean isEnabled() {
+ return isEnabled;
+ }
+
+ /**
+ * If null set to default
+ * @param isEnabled
+ */
+ public void setEnabled(Boolean isEnabled) {
+ if (isEnabled == null) {
+ isEnabled = DriftConfigurationDefinition.DEFAULT_ENABLED;
+ }
+
+ this.isEnabled = isEnabled;
+ this.setEnabledProperty(isEnabled);
+ }
+
+ public DriftHandlingMode getDriftHandlingMode() {
+ return driftHandlingMode;
+ }
+
+ public void setDriftHandlingMode(DriftHandlingMode driftHandlingMode) {
+ if (null == driftHandlingMode) {
+ driftHandlingMode =
DriftConfigurationDefinition.DEFAULT_DRIFT_HANDLING_MODE;
+ }
+
+ this.driftHandlingMode = driftHandlingMode;
+ this.setDriftHandlingModeProperty(driftHandlingMode);
+ }
+
+ public long getInterval() {
+ return interval;
+ }
+
+ /**
+ * If null, set to default.
+ * @param interval
+ */
+ public void setInterval(Long interval) {
+ if (interval == null) {
+ interval = DriftConfigurationDefinition.DEFAULT_INTERVAL;
+ }
+
+ this.interval = interval;
+ this.setIntervalProperty(interval);
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ this.name = this.getNameProperty();
+ this.isEnabled = this.getIsEnabledProperty();
+ this.interval = this.getIntervalProperty();
+ this.driftHandlingMode = this.getDriftHandlingModeProperty();
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ if (this.resource != null) {
+ this.resource.getDriftDefinitions().add(this);
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("DriftDefinition [id=").append(id).append(",
name=").append(name).append(", enabled=").append(
+ isEnabled).append(", interval=").append(interval).append(",
resource=").append(resource).append(
+ ", basedir=").append(getBasedir()).append(",
includes=").append(getIncludes()).append(", excludes=")
+ .append(getExcludes()).append("]");
+ return builder.toString();
+ }
+
+ public static class BaseDirectory implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private BaseDirValueContext context;
+ private String name;
+
+ // required for jaxb/web services remoting
+ protected BaseDirectory() {
+ }
+
+ public BaseDirectory(BaseDirValueContext context, String name) {
+ this.context = context;
+ this.name = name;
+ }
+
+ public BaseDirValueContext getValueContext() {
+ return context;
+ }
+
+ public String getValueName() {
+ return name;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("BaseDirectory
[context=").append(context).append(",
name=").append(name).append("]");
+ return builder.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 1;
+ result = 31 * result + ((context == null) ? 0 : context.hashCode());
+ result = 31 * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof BaseDirectory)) {
+ return false;
+ }
+ BaseDirectory other = (BaseDirectory) obj;
+ if (context == null) {
+ if (other.context != null) {
+ return false;
+ }
+ } else if (!context.equals(other.context)) {
+ return false;
+ }
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+ }
+
+ private String getNameProperty() {
+ return configuration.getSimpleValue(DriftConfigurationDefinition.PROP_NAME,
null);
+ }
+
+ private void setNameProperty(String name) {
+ if (name == null) {
+ throw new IllegalArgumentException("name is null");
+ }
+ configuration.put(new PropertySimple(DriftConfigurationDefinition.PROP_NAME,
name));
+ }
+
+ public BaseDirectory getBasedir() {
+ PropertyMap map =
configuration.getMap(DriftConfigurationDefinition.PROP_BASEDIR);
+ if (map == null) {
+ return null;
+ }
+
+ String valueContext =
map.getSimpleValue(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT, null);
+ String valueName =
map.getSimpleValue(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME, null);
+
+ BaseDirValueContext valueContextEnum;
+
+ if (valueContext == null) {
+ throw new NullPointerException("valueContext is null");
+ } else {
+ try {
+ valueContextEnum = BaseDirValueContext.valueOf(valueContext);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Invalid valueContext: " +
valueContext);
+ }
+ }
+
+ if (valueName == null) {
+ throw new NullPointerException("valueName is null");
+ }
+
+ return new BaseDirectory(valueContextEnum, valueName);
+ }
+
+ public void setBasedir(BaseDirectory basedir) {
+ if (basedir == null) {
+ throw new NullPointerException("basedir is null");
+ }
+ if (basedir.getValueContext() == null) {
+ throw new NullPointerException("valueContext is null");
+ }
+ if (basedir.getValueName() == null) {
+ throw new NullPointerException("valueName is null");
+ }
+
+ String valueContext = basedir.getValueContext().name();
+ String valueName = basedir.getValueName();
+
+ PropertyMap basedirMap = new
PropertyMap(DriftConfigurationDefinition.PROP_BASEDIR);
+ basedirMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUECONTEXT, valueContext));
+ basedirMap.put(new
PropertySimple(DriftConfigurationDefinition.PROP_BASEDIR_VALUENAME, valueName));
+
+ configuration.put(basedirMap);
+ }
+
+ private Long getIntervalProperty() {
+ return
Long.parseLong(configuration.getSimpleValue(DriftConfigurationDefinition.PROP_INTERVAL,
String
+ .valueOf(DriftConfigurationDefinition.DEFAULT_INTERVAL)));
+ }
+
+ private void setIntervalProperty(Long interval) {
+ configuration.put(new PropertySimple(DriftConfigurationDefinition.PROP_INTERVAL,
interval.toString()));
+ }
+
+ private DriftHandlingMode getDriftHandlingModeProperty() {
+ return DriftHandlingMode.valueOf(configuration.getSimpleValue(
+ DriftConfigurationDefinition.PROP_DRIFT_HANDLING_MODE,
+ DriftConfigurationDefinition.DEFAULT_DRIFT_HANDLING_MODE.name()));
+ }
+
+ private void setDriftHandlingModeProperty(DriftHandlingMode mode) {
+ configuration.put(new
PropertySimple(DriftConfigurationDefinition.PROP_DRIFT_HANDLING_MODE, mode.name()));
+ }
+
+ private boolean getIsEnabledProperty() {
+ return configuration.getSimpleValue(DriftConfigurationDefinition.PROP_ENABLED,
+
String.valueOf(DriftConfigurationDefinition.DEFAULT_ENABLED)).equals("true");
+ }
+
+ private void setEnabledProperty(boolean enabled) {
+ configuration.put(new PropertySimple(DriftConfigurationDefinition.PROP_ENABLED,
String.valueOf(enabled)));
+ }
+
+ public List<Filter> getIncludes() {
+ return getFilters(DriftConfigurationDefinition.PROP_INCLUDES);
+ }
+
+ public List<Filter> getExcludes() {
+ return getFilters(DriftConfigurationDefinition.PROP_EXCLUDES);
+ }
+
+ public void addInclude(Filter filter) {
+ PropertyList filtersList =
configuration.getList(DriftConfigurationDefinition.PROP_INCLUDES);
+ if (filtersList == null) {
+ // this is going to be our first include filter - make sure we create an
initial list and put it in the config
+ filtersList = new PropertyList(DriftConfigurationDefinition.PROP_INCLUDES);
+ configuration.put(filtersList);
+ }
+
+ PropertyMap filterMap = new
PropertyMap(DriftConfigurationDefinition.PROP_INCLUDES_INCLUDE);
+ filterMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATH,
filter.getPath()));
+ filterMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATTERN,
filter.getPattern()));
+ filtersList.add(filterMap);
+ }
+
+ public void addExclude(Filter filter) {
+ PropertyList filtersList =
configuration.getList(DriftConfigurationDefinition.PROP_EXCLUDES);
+ if (filtersList == null) {
+ // this is going to be our first include filter - make sure we create an
initial list and put it in the config
+ filtersList = new PropertyList(DriftConfigurationDefinition.PROP_EXCLUDES);
+ configuration.put(filtersList);
+ }
+
+ PropertyMap filterMap = new
PropertyMap(DriftConfigurationDefinition.PROP_EXCLUDES_EXCLUDE);
+ filterMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATH,
filter.getPath()));
+ filterMap.put(new PropertySimple(DriftConfigurationDefinition.PROP_PATTERN,
filter.getPattern()));
+ filtersList.add(filterMap);
+ }
+
+ private List<Filter> getFilters(String type) {
+ PropertyList filtersListProperty = configuration.getList(type);
+ if (filtersListProperty == null) {
+ return emptyList();
+ }
+
+ List<Filter> filters = new ArrayList<Filter>();
+ for (Property property : filtersListProperty.getList()) {
+ PropertyMap filter = (PropertyMap) property;
+ filters.add(new
Filter(filter.getSimpleValue(DriftConfigurationDefinition.PROP_PATH, ""),
filter
+ .getSimpleValue(DriftConfigurationDefinition.PROP_PATTERN,
"")));
+ }
+
+ return filters;
+ }
+}
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDefinitionComparator.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDefinitionComparator.java
new file mode 100644
index 0000000..ac3d069
--- /dev/null
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/DriftDefinitionComparator.java
@@ -0,0 +1,140 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.core.domain.drift;
+
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * Compares two {@link DriftDefinition} objects. The comparison can either
+ * compare basedir/includes-excludes filters or ignore them. Will also compare
+ * name, interval, enabled flag.
+ *
+ * @author John Mazzitelli
+ */
+public class DriftDefinitionComparator implements Comparator<DriftDefinition> {
+
+ public enum CompareMode {
+ /**
+ * The comparator will only check the base information: name, enabled, interval,
driftHandlingMode
+ * The basedir/includes-excludes filters will be ignored.
+ */
+ ONLY_BASE_INFO,
+
+ /**
+ * The comparator will only check the basedir/includes-excludes filters.
+ * The base information will be ignored (see {@link #ONLY_BASE_INFO} for what
those are).
+ */
+ ONLY_DIRECTORY_SPECIFICATIONS,
+
+ /**
+ * The comparator will check both the basedir/includes-excludes filters and
+ * the base information (see {@link #ONLY_BASE_INFO} for what those are).
+ */
+ BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS;
+ };
+
+ private final CompareMode compareMode;
+
+ public DriftDefinitionComparator(CompareMode mode) {
+ this.compareMode = mode;
+ }
+
+ @Override
+ public int compare(DriftDefinition dc1, DriftDefinition dc2) {
+ if (compareMode != CompareMode.ONLY_DIRECTORY_SPECIFICATIONS) {
+ if (dc1.getName() != null) {
+ if (dc2.getName() != null) {
+ int results = dc1.getName().compareTo(dc2.getName());
+ if (results != 0) {
+ return results;
+ }
+ } else {
+ return 1; // dc1's name is not null, but dc2's name is null,
not equal!
+ }
+ } else if (dc2.getName() != null) {
+ return -1; // dc1's name is null, but dc2's name is not null, not
equal!
+ }
+
+ if (dc1.getInterval() != dc2.getInterval()) {
+ return dc1.getInterval() < dc2.getInterval() ? -1 : 1;
+ }
+
+ if (dc1.getDriftHandlingMode() != dc2.getDriftHandlingMode()) {
+ return dc1.getDriftHandlingMode().ordinal() <
dc2.getDriftHandlingMode().ordinal() ? -1 : 1;
+ }
+
+ if (dc1.isEnabled() != dc2.isEnabled()) {
+ return dc1.isEnabled() ? 1 : -1; // so false sorts before true, seems
logical to me
+ }
+ }
+
+ if (compareMode != CompareMode.ONLY_BASE_INFO) {
+ if (dc1.getBasedir() != null) {
+ if (!dc1.getBasedir().equals(dc2.getBasedir())) {
+ int hash1 = dc1.getBasedir().hashCode();
+ int hash2 = (dc2.getBasedir() != null) ? dc2.getBasedir().hashCode()
: 0;
+ return hash1 < hash2 ? -1 : 1;
+ }
+ } else if (dc2.getBasedir() != null) {
+ return -1; // dc1's basedir is null, but dc2's basedir is not
null, not equal!
+ }
+
+ List<Filter> filters1 = dc1.getIncludes();
+ List<Filter> filters2 = dc2.getIncludes();
+ int results = compareFilters(filters1, filters2);
+ if (results != 0) {
+ return results;
+ }
+
+ filters1 = dc1.getExcludes();
+ filters2 = dc2.getExcludes();
+ results = compareFilters(filters1, filters2);
+ if (results != 0) {
+ return results;
+ }
+ }
+
+ return 0;
+ }
+
+ private int compareFilters(List<Filter> filters1, List<Filter> filters2)
{
+ if (filters1 == null) {
+ return (filters2 == null) ? 0 : -1;
+ } else if (filters2 == null) {
+ return 1;
+ }
+
+ // at this point, we know both filters1 and filters2 are non-null
+ // let's do the next easiest check - size. If the lists are different sizes,
then clearly they are different
+ if (filters1.size() != filters2.size()) {
+ return (filters1.size() < filters2.size()) ? -1 : 1;
+ }
+
+ // they are the same size, let's see if they have the same items. We only
need to see if one contains
+ // all of the other; because they are the same size, if filters1 contains all the
filters2 items,
+ // then clearly the other way is true too (filters2 contains all of filters1
items).
+ if (!filters1.containsAll(filters2)) {
+ return -1; // unsure if we need to do further anaylsis to determine if -1 or
1 should be returned; for now, don't worry about it
+ }
+
+ return 0;
+ }
+}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADrift.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADrift.java
index b56597e..c9fb8c3 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADrift.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADrift.java
@@ -50,19 +50,19 @@ import javax.persistence.Table;
@NamedQueries( { @NamedQuery(name = JPADrift.QUERY_DELETE_BY_RESOURCES, query =
"" //
+ "DELETE FROM JPADrift d " //
+ " WHERE d.changeSet IN ( SELECT dcs FROM JPADriftChangeSet dcs WHERE
dcs.resource.id IN ( :resourceIds ) ) )"), //
- @NamedQuery(name = JPADrift.QUERY_DELETE_BY_DRIFTCONFIG_RESOURCE, query =
"" //
+ @NamedQuery(name = JPADrift.QUERY_DELETE_BY_DRIFTDEF_RESOURCE, query = ""
//
+ "DELETE FROM JPADrift d " //
+ " WHERE d.changeSet.id IN " //
+ " (SELECT dcs.id " //
+ " FROM JPADriftChangeSet dcs " //
- + " WHERE dcs.driftConfiguration.name = :driftConfigurationName AND
dcs.resource.id = :resourceId)") })
+ + " WHERE dcs.driftDefinition.name = :driftDefinitionName AND
dcs.resource.id = :resourceId)") })
@Table(name = "RHQ_DRIFT")
@SequenceGenerator(name = "SEQ", sequenceName = "RHQ_DRIFT_ID_SEQ")
public class JPADrift implements Serializable, Drift<JPADriftChangeSet,
JPADriftFile> {
private static final long serialVersionUID = 1L;
public static final String QUERY_DELETE_BY_RESOURCES =
"JPADrift.deleteByResources";
- public static final String QUERY_DELETE_BY_DRIFTCONFIG_RESOURCE =
"JPADrift.deleteByDriftConfigResource";
+ public static final String QUERY_DELETE_BY_DRIFTDEF_RESOURCE =
"JPADrift.deleteByDriftDefResource";
@Column(name = "ID", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADriftChangeSet.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADriftChangeSet.java
index 1f82848..79ef691 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADriftChangeSet.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/JPADriftChangeSet.java
@@ -57,13 +57,13 @@ import org.rhq.core.domain.resource.Resource;
@NamedQueries( { @NamedQuery(name = JPADriftChangeSet.QUERY_DELETE_BY_RESOURCES, query =
"" //
+ "DELETE FROM JPADriftChangeSet dcs " //
+ " WHERE dcs.resource.id IN ( :resourceIds )"), //
- @NamedQuery(name = JPADriftChangeSet.QUERY_DELETE_BY_DRIFTCONFIG_RESOURCE, query =
"" //
+ @NamedQuery(name = JPADriftChangeSet.QUERY_DELETE_BY_DRIFTDEF_RESOURCE, query =
"" //
+ "DELETE FROM JPADriftChangeSet dcs " //
+ " WHERE dcs.resource.id = :resourceId " //
- + " AND dcs.driftConfiguration.id IN " //
+ + " AND dcs.driftDefinition.id IN " //
+ " (SELECT dc.id " //
- + " FROM DriftConfiguration dc " //
- + " WHERE dc.resource.id = :resourceId AND dc.name =
:driftConfigurationName)" //
+ + " FROM DriftDefinition dc " //
+ + " WHERE dc.resource.id = :resourceId AND dc.name =
:driftDefinitionName)" //
) })
@Table(name = "RHQ_DRIFT_CHANGE_SET")
@SequenceGenerator(name = "SEQ", sequenceName =
"RHQ_DRIFT_CHANGE_SET_ID_SEQ")
@@ -71,7 +71,7 @@ public class JPADriftChangeSet implements Serializable,
DriftChangeSet<JPADrift>
private static final long serialVersionUID = 1L;
public static final String QUERY_DELETE_BY_RESOURCES =
"JPADriftChangeSet.deleteByResources";
- public static final String QUERY_DELETE_BY_DRIFTCONFIG_RESOURCE =
"JPADriftChangeSet.deleteByDriftConfigResource";
+ public static final String QUERY_DELETE_BY_DRIFTDEF_RESOURCE =
"JPADriftChangeSet.deleteByDriftDefResource";
@Column(name = "ID", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "SEQ")
@@ -93,9 +93,9 @@ public class JPADriftChangeSet implements Serializable,
DriftChangeSet<JPADrift>
// @ManyToOne(optional = false)
// TODO: remove this eager load, the drift tree build should be written to not need
this
@ManyToOne(fetch = FetchType.EAGER, optional = false)
- private DriftConfiguration driftConfiguration;
+ private DriftDefinition driftDefinition;
- // Note, this is mode at the time of the changeset processing. We cant use
driftConfiguration.mode because
+ // Note, this is mode at the time of the changeset processing. We cant use
driftDefinition.mode because
// that is the "live" setting.
@Column(name = "DRIFT_CONFIG_MODE", nullable = false)
@Enumerated(EnumType.STRING)
@@ -112,12 +112,12 @@ public class JPADriftChangeSet implements Serializable,
DriftChangeSet<JPADrift>
}
public JPADriftChangeSet(Resource resource, int version, DriftChangeSetCategory
category,
- DriftConfiguration driftConfiguration) {
+ DriftDefinition driftDefinition) {
this.resource = resource;
this.version = version;
this.category = category;
- this.driftConfiguration = driftConfiguration;
- this.driftHandlingMode = driftConfiguration.getDriftHandlingMode();
+ this.driftDefinition = driftDefinition;
+ this.driftHandlingMode = driftDefinition.getDriftHandlingMode();
}
@Override
@@ -173,12 +173,12 @@ public class JPADriftChangeSet implements Serializable,
DriftChangeSet<JPADrift>
this.resource = resource;
}
- public DriftConfiguration getDriftConfiguration() {
- return driftConfiguration;
+ public DriftDefinition getDriftDefinition() {
+ return driftDefinition;
}
- public void setDriftConfiguration(DriftConfiguration driftConfiguration) {
- this.driftConfiguration = driftConfiguration;
+ public void setDriftDefinition(DriftDefinition driftDefinition) {
+ this.driftDefinition = driftDefinition;
}
public DriftHandlingMode getDriftHandlingMode() {
@@ -190,13 +190,13 @@ public class JPADriftChangeSet implements Serializable,
DriftChangeSet<JPADrift>
}
@Override
- public int getDriftConfigurationId() {
- return this.driftConfiguration.getId();
+ public int getDriftDefinitionId() {
+ return this.driftDefinition.getId();
}
@Override
- public void setDriftConfigurationId(int id) {
- this.driftConfiguration.setId(id);
+ public void setDriftDefinitionId(int id) {
+ this.driftDefinition.setId(id);
}
@Override
diff --git
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/dto/DriftChangeSetDTO.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/dto/DriftChangeSetDTO.java
index 8912791..304b90e 100644
---
a/modules/core/domain/src/main/java/org/rhq/core/domain/drift/dto/DriftChangeSetDTO.java
+++
b/modules/core/domain/src/main/java/org/rhq/core/domain/drift/dto/DriftChangeSetDTO.java
@@ -68,12 +68,12 @@ public class DriftChangeSetDTO implements
DriftChangeSet<DriftDTO>, Serializable
}
@Override
- public int getDriftConfigurationId() {
+ public int getDriftDefinitionId() {
return configId;
}
@Override
- public void setDriftConfigurationId(int id) {
+ public void setDriftDefinitionId(int id) {
configId = id;
}
diff --git a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
index 1eb495e..933f158 100644
--- a/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
+++ b/modules/core/domain/src/main/java/org/rhq/core/domain/resource/Resource.java
@@ -69,7 +69,7 @@ import org.rhq.core.domain.content.InstalledPackageHistory;
import org.rhq.core.domain.content.Repo;
import org.rhq.core.domain.content.ResourceRepo;
import org.rhq.core.domain.dashboard.Dashboard;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.event.EventSource;
import org.rhq.core.domain.measurement.Availability;
import org.rhq.core.domain.measurement.MeasurementSchedule;
@@ -1077,7 +1077,7 @@ public class Resource implements Comparable<Resource>,
Serializable {
@OneToMany(mappedBy = "resource", fetch = FetchType.LAZY, cascade = {
CascadeType.ALL })
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
- private Set<DriftConfiguration> driftConfigurations = null;
+ private Set<DriftDefinition> driftDefinitions = null;
public Resource() {
}
@@ -1747,21 +1747,21 @@ public class Resource implements Comparable<Resource>,
Serializable {
this.dashboards = dashboards;
}
- public Set<DriftConfiguration> getDriftConfigurations() {
- if (this.driftConfigurations == null) {
- this.driftConfigurations = new LinkedHashSet<DriftConfiguration>();
+ public Set<DriftDefinition> getDriftDefinitions() {
+ if (this.driftDefinitions == null) {
+ this.driftDefinitions = new LinkedHashSet<DriftDefinition>();
}
- return driftConfigurations;
+ return driftDefinitions;
}
- public void setDriftConfigurations(Set<DriftConfiguration> driftConfigurations)
{
- this.driftConfigurations = driftConfigurations;
+ public void setDriftDefinitions(Set<DriftDefinition> driftDefinitions) {
+ this.driftDefinitions = driftDefinitions;
}
- public void addDriftConfiguration(DriftConfiguration driftConfiguration) {
- getDriftConfigurations().add(driftConfiguration);
- driftConfiguration.setResource(this);
+ public void addDriftDefinition(DriftDefinition driftDefinition) {
+ getDriftDefinitions().add(driftDefinition);
+ driftDefinition.setResource(this);
}
public int compareTo(Resource that) {
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 6fcdcc5..240b703 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
@@ -177,7 +177,7 @@ import org.rhq.core.domain.util.Summary;
+ " (SELECT COUNT(packageType) FROM rt.packageTypes
packageType)," // content
+ " (SELECT COUNT(metricDef) FROM rt.metricDefinitions metricDef
WHERE metricDef.dataType = 3)," // calltime
+ " (SELECT COUNT(propDef) FROM rt.pluginConfigurationDefinition
pluginConfig JOIN pluginConfig.propertyDefinitions propDef WHERE propDef.name =
'snapshotLogEnabled')," //
- + " (SELECT COUNT(driftConfig) FROM rt.driftConfigurationTemplates
driftConfig)," // drift
+ + " (SELECT COUNT(driftDef) FROM rt.driftDefinitionTemplates
driftDef)," // drift
+ " (SELECT COUNT(bundleConfig) FROM rt.bundleConfiguration
bundleConfig)" // bundle
+ " ) " //
+ " FROM ResourceType rt " //
@@ -400,7 +400,7 @@ public class ResourceType implements Serializable,
Comparable<ResourceType> {
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "RHQ_DRIFT_TEMPLATE_MAP", joinColumns = @JoinColumn(name
= "RESOURCE_TYPE_ID", nullable = false), inverseJoinColumns = @JoinColumn(name =
"CONFIG_TEMPLATE_ID", nullable = false))
- private Set<ConfigurationTemplate> driftConfigurationTemplates = new
HashSet<ConfigurationTemplate>();
+ private Set<ConfigurationTemplate> driftDefinitionTemplates = new
HashSet<ConfigurationTemplate>();
// note that this is mapped to a Configuration entity, which is what it really is.
However, our getter/setter
// only provides access to this via ResourceTypeBundleConfiguration to encapsulate
the innards of this implementation
@@ -829,15 +829,15 @@ public class ResourceType implements Serializable,
Comparable<ResourceType> {
}
// 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;
+ public Set<ConfigurationTemplate> getDriftDefinitionTemplates() {
+ return driftDefinitionTemplates;
}
- public void addDriftConfigurationTemplate(ConfigurationTemplate template) {
- if (driftConfigurationTemplates == null) {
- driftConfigurationTemplates = new HashSet<ConfigurationTemplate>(1);
+ public void addDriftDefinitionTemplate(ConfigurationTemplate template) {
+ if (driftDefinitionTemplates == null) {
+ driftDefinitionTemplates = new HashSet<ConfigurationTemplate>(1);
}
- driftConfigurationTemplates.add(template);
+ driftDefinitionTemplates.add(template);
}
@Override
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftConfigurationTest.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftConfigurationTest.java
index 3540b29..ddf1ffe 100644
---
a/modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftConfigurationTest.java
+++
b/modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftConfigurationTest.java
@@ -15,17 +15,17 @@ import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
-import org.rhq.core.domain.drift.DriftConfigurationComparator.CompareMode;
+import org.rhq.core.domain.drift.DriftDefinitionComparator.CompareMode;
import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
import org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
public class DriftConfigurationTest {
@Test
public void getCompareIgnoreIncludesExcludes() {
- DriftConfigurationComparator comparator = new
DriftConfigurationComparator(CompareMode.ONLY_BASE_INFO);
+ DriftDefinitionComparator comparator = new
DriftDefinitionComparator(CompareMode.ONLY_BASE_INFO);
- DriftConfiguration dc1 = new DriftConfiguration(new Configuration());
- DriftConfiguration dc2 = new DriftConfiguration(new Configuration());
+ DriftDefinition dc1 = new DriftDefinition(new Configuration());
+ DriftDefinition dc2 = new DriftDefinition(new Configuration());
// make sure our comparator can deal with all the nulls that are in empty
configs
assert comparator.compare(dc1, dc2) == 0 : dc1 + " should equal " +
dc2;
@@ -66,8 +66,8 @@ public class DriftConfigurationTest {
assert comparator.compare(dc1, dc2) == 0 : dc1 + " should equal " +
dc2; // sanity check - we should be back to equals
// add some includes and excludes that are different and test that they are
ignored by our comparator
- dc1.setBasedir(new
DriftConfiguration.BaseDirectory(BaseDirValueContext.fileSystem, "/foo"));
- dc2.setBasedir(new
DriftConfiguration.BaseDirectory(BaseDirValueContext.pluginConfiguration,
"blah"));
+ dc1.setBasedir(new DriftDefinition.BaseDirectory(BaseDirValueContext.fileSystem,
"/foo"));
+ dc2.setBasedir(new
DriftDefinition.BaseDirectory(BaseDirValueContext.pluginConfiguration,
"blah"));
dc1.addInclude(new Filter("ipath1", "ipattern1"));
dc2.addInclude(new Filter("ipath2", "ipattern2"));
dc1.addExclude(new Filter("epath1", "epattern1"));
@@ -76,18 +76,18 @@ public class DriftConfigurationTest {
assert comparator.compare(dc1, dc2) == 0 : dc1 + " should equal (ignoring
basedir/includes/excludes) " + dc2;
// now show that our non-ignoring comparator would detect a different
- comparator = new
DriftConfigurationComparator(CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
+ comparator = new
DriftDefinitionComparator(CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
assert comparator.compare(dc1, dc2) != 0 : dc1 + " should not equal (not
ignoring basedir/includes/excludes) "
+ dc2;
}
@Test
public void getCompareBaseInfoAndIncludesExcludes() {
- DriftConfigurationComparator comparator = new DriftConfigurationComparator(
+ DriftDefinitionComparator comparator = new DriftDefinitionComparator(
CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
- DriftConfiguration dc1 = new DriftConfiguration(new Configuration());
- DriftConfiguration dc2 = new DriftConfiguration(new Configuration());
+ DriftDefinition dc1 = new DriftDefinition(new Configuration());
+ DriftDefinition dc2 = new DriftDefinition(new Configuration());
dc1.setEnabled(true);
dc1.setInterval(1000L);
@@ -104,11 +104,11 @@ public class DriftConfigurationTest {
@Test
public void getCompareOnlyIncludesExcludes() {
- DriftConfigurationComparator comparator = new DriftConfigurationComparator(
+ DriftDefinitionComparator comparator = new DriftDefinitionComparator(
CompareMode.ONLY_DIRECTORY_SPECIFICATIONS);
- DriftConfiguration dc1 = new DriftConfiguration(new Configuration());
- DriftConfiguration dc2 = new DriftConfiguration(new Configuration());
+ DriftDefinition dc1 = new DriftDefinition(new Configuration());
+ DriftDefinition dc2 = new DriftDefinition(new Configuration());
dc1.setEnabled(false);
dc1.setInterval(1111L);
@@ -135,16 +135,16 @@ public class DriftConfigurationTest {
* @param dc1 the initial drift config1 to test
* @param dc2 the initial drift config2 to test
*/
- private void getCompareBaseInfoAndIncludesExcludes(DriftConfigurationComparator
comparator, DriftConfiguration dc1,
- DriftConfiguration dc2) {
+ private void getCompareBaseInfoAndIncludesExcludes(DriftDefinitionComparator
comparator, DriftDefinition dc1,
+ DriftDefinition dc2) {
assert comparator.compare(dc1, dc2) == 0 : dc1 + " should equal " +
dc2; // sanity check
- dc1.setBasedir(new
DriftConfiguration.BaseDirectory(BaseDirValueContext.pluginConfiguration,
"hello.world"));
+ dc1.setBasedir(new
DriftDefinition.BaseDirectory(BaseDirValueContext.pluginConfiguration,
"hello.world"));
assert comparator.compare(dc1, dc2) != 0 : dc1 + " should not equal " +
dc2;
assert comparator.compare(dc2, dc1) != 0 : dc2 + " should not equal " +
dc1;
- dc2.setBasedir(new
DriftConfiguration.BaseDirectory(BaseDirValueContext.pluginConfiguration,
"hello.world"));
+ dc2.setBasedir(new
DriftDefinition.BaseDirectory(BaseDirValueContext.pluginConfiguration,
"hello.world"));
assert comparator.compare(dc1, dc2) == 0 : dc1 + " should now be equal
" + dc2;
assert comparator.compare(dc2, dc1) == 0 : dc2 + " should now be equal
" + dc1;
@@ -201,8 +201,8 @@ public class DriftConfigurationTest {
assert comparator.compare(dc2, dc1) != 0 : dc2 + " should not equal " +
dc1;
// we don't provide an API to clear filters, so just create new drift configs
and test different excludes
- dc1 = new DriftConfiguration(new Configuration());
- dc2 = new DriftConfiguration(new Configuration());
+ dc1 = new DriftDefinition(new Configuration());
+ dc2 = new DriftDefinition(new Configuration());
assert comparator.compare(dc1, dc2) == 0 : dc1 + " should equal " +
dc2; // sanity check
dc1.addExclude(new Filter("epathA", "epatternA"));
dc2.addExclude(new Filter("epathZ", "epatternZ"));
@@ -216,7 +216,7 @@ public class DriftConfigurationTest {
Configuration config = new Configuration();
config.put(new PropertySimple("name", name));
- DriftConfiguration driftConfig = new DriftConfiguration(config);
+ DriftDefinition driftConfig = new DriftDefinition(config);
assertEquals(driftConfig.getName(), name, "Failed to get drift configuration
name");
}
@@ -232,7 +232,7 @@ public class DriftConfigurationTest {
config.put(map);
- DriftConfiguration driftConfig = new DriftConfiguration(config);
+ DriftDefinition driftConfig = new DriftDefinition(config);
assertEquals(driftConfig.getBasedir().getValueName(), basedir,
"Failed to get drift configuration base directory");
@@ -244,7 +244,7 @@ public class DriftConfigurationTest {
Configuration config = new Configuration();
config.put(new PropertySimple("interval", interval));
- DriftConfiguration driftConfig = new DriftConfiguration(config);
+ DriftDefinition driftConfig = new DriftDefinition(config);
assertEquals(driftConfig.getInterval(), interval, "Failed to get drift
configuration interval");
}
@@ -254,7 +254,7 @@ public class DriftConfigurationTest {
DriftHandlingMode mode = DriftHandlingMode.normal;
Configuration config = new Configuration();
config.put(new
PropertySimple(DriftConfigurationDefinition.PROP_DRIFT_HANDLING_MODE, mode.name()));
- DriftConfiguration driftConfig = new DriftConfiguration(config);
+ DriftDefinition driftConfig = new DriftDefinition(config);
assertEquals(driftConfig.getDriftHandlingMode(), mode, "Failed to get drift
configuration drift handling mode");
mode = DriftHandlingMode.plannedChanges;
@@ -278,7 +278,7 @@ public class DriftConfigurationTest {
config.put(includes);
- DriftConfiguration driftConfig = new DriftConfiguration(config);
+ DriftDefinition driftConfig = new DriftDefinition(config);
List<Filter> actual = driftConfig.getIncludes();
List<Filter> expected = asList(new Filter(path1, pattern1), new
Filter(path2, pattern2));
@@ -303,7 +303,7 @@ public class DriftConfigurationTest {
config.put(excludes);
- DriftConfiguration driftConfig = new DriftConfiguration(config);
+ DriftDefinition driftConfig = new DriftDefinition(config);
List<Filter> actual = driftConfig.getExcludes();
List<Filter> expected = asList(new Filter(path1, pattern1), new
Filter(path2, pattern2));
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftSnapshotTest.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftSnapshotTest.java
index 97f7faa..077f01b 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftSnapshotTest.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/drift/DriftSnapshotTest.java
@@ -211,12 +211,12 @@ public class DriftSnapshotTest {
}
@Override
- public int getDriftConfigurationId() {
+ public int getDriftDefinitionId() {
return configId;
}
@Override
- public void setDriftConfigurationId(int id) {
+ public void setDriftDefinitionId(int id) {
configId = id;
}
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java
index 6a6ba13..a1f4340 100644
---
a/modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java
+++
b/modules/core/domain/src/test/java/org/rhq/core/domain/resource/ResourceTypeTest.java
@@ -89,7 +89,7 @@ public class ResourceTypeTest extends UnitilsTestNG {
public void findDriftConfigurationTemplates() {
ResourceType type = entityMgr.find(ResourceType.class, -8);
- assertEquals(type.getDriftConfigurationTemplates().size(), 2);
+ assertEquals(type.getDriftDefinitionTemplates().size(), 2);
}
void assertDeletedTypesIgnored(List<ResourceType> types) {
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 f7787ad..1fc9fe9 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
@@ -26,7 +26,7 @@ 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;
+import org.rhq.core.domain.drift.DriftDefinition;
public interface ChangeSetManager {
@@ -34,32 +34,32 @@ public interface ChangeSetManager {
/**
* Locates the latest coverage change set for the specified resource id and drift
- * configuration.
+ * definition.
*
* @param resourceId The id of the resource to which the change set belongs
- * @param driftConfigurationName The name of the drift configuration for which the
+ * @param driftDefinitionName The name of the drift definition 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, String driftConfigurationName) throws
IOException;
+ File findChangeSet(int resourceId, String driftDefinitionName) throws IOException;
File findChangeSet(int resourceId, String name, DriftChangeSetCategory type);
/**
- * Locates the latest change set for the given resource and drift configuration and
+ * Locates the latest change set for the given resource and drift definition and
* returns a ChangeSetReader for that change set. Note that a resource can have
- * multiple drift configurations; so, both the resource id and the drift
configuration
+ * multiple drift definitions; so, both the resource id and the drift definition
* are required to uniquely identify a particular change set.
*
* @param resourceId The id of the resource to which the change set belongs
- * @param driftConfigurationName The name of the drift configuration for which the
+ * @param driftDefinitionName The name of the drift definition 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.
+ * and driftDefinition. Returns null if no change set has previously been generated.
* @see ChangeSetReader
*/
- ChangeSetReader getChangeSetReader(int resourceId, String driftConfigurationName)
throws IOException;
+ ChangeSetReader getChangeSetReader(int resourceId, String driftDefinitionName) throws
IOException;
ChangeSetReader getChangeSetReader(File changeSetFile) throws IOException;
@@ -71,6 +71,6 @@ public interface ChangeSetManager {
void updateChangeSet(int resourceId, Headers headers) throws IOException;
- void addFileToChangeSet(int resourceId, DriftConfiguration driftConfiguration, File
file);
+ void addFileToChangeSet(int resourceId, DriftDefinition driftDefinition, 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 6cc5e6d..132a7ca 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
@@ -19,6 +19,8 @@
package org.rhq.core.pc.drift;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
+
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -32,11 +34,9 @@ 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;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.util.stream.StreamUtil;
-import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
-
public class ChangeSetManagerImpl implements ChangeSetManager {
private File changeSetsDir;
@@ -47,7 +47,7 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
@Override
public boolean changeSetExists(int resourceId, Headers headers) {
- File changeSetDir = findChangeSetDir(resourceId,
headers.getDriftConfigurationName());
+ File changeSetDir = findChangeSetDir(resourceId,
headers.getDriftDefinitionName());
if (changeSetDir == null || !changeSetDir.exists()) {
return false;
}
@@ -55,8 +55,8 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
@Override
- public File findChangeSet(int resourceId, String driftConfigurationName) throws
IOException {
- File changeSetDir = findChangeSetDir(resourceId, driftConfigurationName);
+ public File findChangeSet(int resourceId, String driftDefinitionName) throws
IOException {
+ File changeSetDir = findChangeSetDir(resourceId, driftDefinitionName);
File changeSetFile = new File(changeSetDir, "changeset.txt");
if (changeSetFile.exists()) {
@@ -85,9 +85,8 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
}
@Override
- public ChangeSetReader getChangeSetReader(int resourceId, String
driftConfigurationName)
- throws IOException {
- File changeSetFile = findChangeSet(resourceId, driftConfigurationName);
+ public ChangeSetReader getChangeSetReader(int resourceId, String driftDefinitionName)
throws IOException {
+ File changeSetFile = findChangeSet(resourceId, driftDefinitionName);
if (changeSetFile == null) {
return null;
@@ -104,7 +103,7 @@ 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());
+ File changeSetDir = new File(resourceDir, headers.getDriftDefinitionName());
if (!changeSetDir.exists()) {
changeSetDir.mkdirs();
@@ -127,7 +126,7 @@ 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());
+ File changeSetDir = new File(resourceDir, headers.getDriftDefinitionName());
return new ChangeSetWriterImpl(new File(changeSetDir,
"changeset.working"), headers);
}
@@ -135,7 +134,7 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
@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 changeSetDir = new File(resourceDir, headers.getDriftDefinitionName());
File newChangeSet = new File(changeSetDir, "changeset.working");
File changeSet = new File(changeSetDir, "changeset.txt");
@@ -145,21 +144,21 @@ public class ChangeSetManagerImpl implements ChangeSetManager {
changeSet.delete();
- StreamUtil.copy(new BufferedInputStream(new FileInputStream(newChangeSet)),
- new BufferedOutputStream(new FileOutputStream(changeSet)));
+ StreamUtil.copy(new BufferedInputStream(new FileInputStream(newChangeSet)), new
BufferedOutputStream(
+ new FileOutputStream(changeSet)));
}
@Override
- public void addFileToChangeSet(int resourceId, DriftConfiguration driftConfiguration,
File file) {
+ public void addFileToChangeSet(int resourceId, DriftDefinition driftDefinition, File
file) {
}
- private File findChangeSetDir(int resourceId, String driftConfigurationName) {
+ private File findChangeSetDir(int resourceId, String driftDefinitionName) {
File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
if (!resourceDir.exists()) {
return null;
}
- return new File(resourceDir, driftConfigurationName);
+ return new File(resourceDir, driftDefinitionName);
}
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 33d859f..8cbf2fc 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,7 +2,7 @@ package org.rhq.core.pc.drift;
import java.io.File;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
/**
* This is a client interface to the server that drift-related tasks call to interact
with
@@ -18,11 +18,11 @@ public interface DriftClient {
* server, the content directory is purged.
*
* @param resourceId
- * @param driftConfigurationName
+ * @param driftDefinitionName
* @param contentDir
*/
- void sendChangeSetContentToServer(int resourceId, String driftConfigurationName, File
contentDir);
+ void sendChangeSetContentToServer(int resourceId, String driftDefinitionName, File
contentDir);
- File getAbsoluteBaseDirectory(int resourceId, DriftConfiguration
driftConfiguration);
+ File getAbsoluteBaseDirectory(int resourceId, DriftDefinition driftDefinition);
}
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 65e4b72..8ddfc03 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
@@ -2,7 +2,7 @@ package org.rhq.core.pc.drift;
import java.io.Serializable;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
public class DriftDetectionSchedule implements Comparable<DriftDetectionSchedule>,
Serializable {
@@ -10,13 +10,13 @@ public class DriftDetectionSchedule implements
Comparable<DriftDetectionSchedule
private int resourceId;
- private DriftConfiguration driftConfig;
+ private DriftDefinition driftDef;
private long nextScan;
- public DriftDetectionSchedule(int resourceId, DriftConfiguration configuration) {
+ public DriftDetectionSchedule(int resourceId, DriftDefinition definition) {
this.resourceId = resourceId;
- driftConfig = configuration;
+ this.driftDef = definition;
nextScan = -1;
}
@@ -24,8 +24,8 @@ public class DriftDetectionSchedule implements
Comparable<DriftDetectionSchedule
return resourceId;
}
- public DriftConfiguration getDriftConfiguration() {
- return driftConfig;
+ public DriftDefinition getDriftDefinition() {
+ return driftDef;
}
public long getNextScan() {
@@ -33,7 +33,7 @@ public class DriftDetectionSchedule implements
Comparable<DriftDetectionSchedule
}
public void updateShedule() {
- nextScan = System.currentTimeMillis() + (driftConfig.getInterval() * 1000);
+ nextScan = System.currentTimeMillis() + (driftDef.getInterval() * 1000);
}
public void resetSchedule() {
@@ -41,8 +41,8 @@ public class DriftDetectionSchedule implements
Comparable<DriftDetectionSchedule
}
public DriftDetectionSchedule copy() {
- DriftDetectionSchedule copy = new DriftDetectionSchedule(resourceId,
- new
DriftConfiguration(driftConfig.getConfiguration().deepCopyWithoutProxies()));
+ DriftDetectionSchedule copy = new DriftDetectionSchedule(resourceId, new
DriftDefinition(driftDef
+ .getConfiguration().deepCopyWithoutProxies()));
copy.nextScan = nextScan;
return copy;
}
@@ -85,7 +85,7 @@ public class DriftDetectionSchedule implements
Comparable<DriftDetectionSchedule
@Override
public String toString() {
- return getClass().getSimpleName() + "[resourceId: " + resourceId +
", driftConfigurationId: " +
- driftConfig.getId() + ", driftConfigurationName: " +
driftConfig.getName() + "]";
+ return getClass().getSimpleName() + "[resourceId: " + resourceId +
", driftDefinitionId: " + driftDef.getId()
+ + ", driftDefinitionName: " + driftDef.getName() + "]";
}
}
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 1aedea3..cba943f 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
@@ -19,8 +19,15 @@
package org.rhq.core.pc.drift;
+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.core.domain.drift.DriftChangeSetCategory.DRIFT;
+import static org.rhq.core.util.file.FileUtil.copyFile;
+import static org.rhq.core.util.file.FileUtil.forEachFile;
+
import java.io.File;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashSet;
import java.util.LinkedList;
@@ -35,18 +42,10 @@ import org.rhq.common.drift.ChangeSetWriter;
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.domain.drift.DriftDefinition;
import org.rhq.core.util.MessageDigestGenerator;
import org.rhq.core.util.file.FileVisitor;
-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.core.domain.drift.DriftChangeSetCategory.DRIFT;
-import static org.rhq.core.util.file.FileUtil.copyFile;
-import static org.rhq.core.util.file.FileUtil.forEachFile;
-
public class DriftDetector implements Runnable {
private Log log = LogFactory.getLog(DriftDetector.class);
@@ -72,7 +71,7 @@ public class DriftDetector implements Runnable {
@Override
public void run() {
- log.debug("Starting drift detection...");
+ log.debug("Starting drift detection..");
long startTime = System.currentTimeMillis();
try {
if (log.isDebugEnabled()) {
@@ -95,35 +94,30 @@ public class DriftDetector implements Runnable {
return;
}
- if (!schedule.getDriftConfiguration().isEnabled()) {
- log.debug("Skipping " + schedule + " because the drift
configuration is disabled.");
+ if (!schedule.getDriftDefinition().isEnabled()) {
+ log.debug("Skipping " + schedule + " because the drift
definition is disabled.");
return;
}
- if (previousSnapshotExists(schedule)) {
- log.debug("Skipping " + schedule + " because server has
not yet acked previous change set");
- return;
- }
+ DriftDefinition driftDef = schedule.getDriftDefinition();
+ DriftChangeSetCategory changeSetType = null;
+ int changes = 0;
- DriftDetectionSummary detectionSummary = new DriftDetectionSummary();
- detectionSummary.setSchedule(schedule);
try {
if (changeSetMgr.changeSetExists(schedule.getResourceId(),
createHeaders(schedule, COVERAGE, 0))) {
- detectionSummary.setType(DRIFT);
- generateDriftChangeSet(detectionSummary);
+ changeSetType = DRIFT;
+ changes = generateDriftChangeSet(schedule);
} else {
- detectionSummary.setType(COVERAGE);
- generateSnapshot(detectionSummary);
- }
- if (detectionSummary.getType() == COVERAGE ||
detectionSummary.getDriftChangeSet() != null) {
- driftClient.sendChangeSetToServer(detectionSummary);
+ changeSetType = COVERAGE;
+ generateSnapshot(schedule);
}
} catch (IOException e) {
- log.error("Drift detection failed: " + e.getMessage(), e);
- revertSnapshot(detectionSummary);
- } catch (RuntimeException e) {
- log.error("Drift detection failed: " + e.getMessage(), e);
- revertSnapshot(detectionSummary);
+ // TODO Call ChangeSetManager here to rollback any thing that was written
to disk.
+ log.error("An error occurred while scanning for drift", e);
+ }
+
+ if (changeSetType == COVERAGE || changes > 0) {
+ driftClient.sendChangeSetToServer(schedule.getResourceId(), driftDef,
changeSetType);
}
} catch (Throwable t) {
Throwable cause = t.getCause();
@@ -144,22 +138,12 @@ public class DriftDetector implements Runnable {
}
}
- private boolean previousSnapshotExists(DriftDetectionSchedule schedule) {
- File snapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
- schedule.getDriftConfiguration().getName(), COVERAGE);
- File previousSnapshot = new File(snapshot.getParentFile(), snapshot.getName() +
".previous");
- return previousSnapshot.exists();
- }
-
- private void generateDriftChangeSet(DriftDetectionSummary summary) throws IOException
{
- final DriftDetectionSchedule schedule = summary.getSchedule();
-
+ private int generateDriftChangeSet(final DriftDetectionSchedule schedule) throws
IOException {
log.debug("Generating drift change set for " + schedule);
- final File basedir = new File(basedir(schedule.getResourceId(),
schedule.getDriftConfiguration()));
- File currentSnapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
- schedule.getDriftConfiguration().getName(), COVERAGE);
- final ChangeSetReader coverageReader =
changeSetMgr.getChangeSetReader(currentSnapshot);
+ final File basedir = new File(basedir(schedule.getResourceId(),
schedule.getDriftDefinition()));
+ final ChangeSetReader coverageReader =
changeSetMgr.getChangeSetReader(schedule.getResourceId(), schedule
+ .getDriftDefinition().getName());
final Set<File> processedFiles = new HashSet<File>();
final List<FileEntry> snapshotEntries = new LinkedList<FileEntry>();
final List<FileEntry> deltaEntries = new LinkedList<FileEntry>();
@@ -170,22 +154,16 @@ public class DriftDetector implements Runnable {
File file = new File(basedir, entry.getFile());
if (!file.exists()) {
// The file has been deleted since the last scan
- if (log.isDebugEnabled()) {
- log.debug("Detected deleted file for " + schedule + "
--> " + file.getAbsolutePath());
- }
- deltaEntries.add(removedFileEntry(entry.getFile(), entry.getNewSHA()));
- } else if (!file.canRead()) {
- processedFiles.add(file);
- if (log.isDebugEnabled()) {
- log.debug(file.getPath() + " is no longer readable. Treating it
as a deleted file.");
+ if (log.isInfoEnabled()) {
+ log.info("Detected deleted file for " + schedule + "
--> " + file.getAbsolutePath());
}
deltaEntries.add(removedFileEntry(entry.getFile(), entry.getNewSHA()));
} else {
processedFiles.add(file);
String currentSHA = sha256(file);
if (!currentSHA.equals(entry.getNewSHA())) {
- if (log.isDebugEnabled()) {
- log.debug("Detected modified file for " + schedule +
" --> " + file.getAbsolutePath());
+ if (log.isInfoEnabled()) {
+ log.info("Detected modified file for " + schedule +
" --> " + file.getAbsolutePath());
}
FileEntry modifiedEntry = changedFileEntry(entry.getFile(),
entry.getNewSHA(), currentSHA);
deltaEntries.add(modifiedEntry);
@@ -200,100 +178,79 @@ public class DriftDetector implements Runnable {
// If the basedir is still valid we need to do a directory tree scan to look for
newly added files
if (basedir.isDirectory()) {
- forEachFile(basedir, new FilterFileVisitor(basedir,
schedule.getDriftConfiguration().getIncludes(),
- schedule.getDriftConfiguration().getExcludes(), new FileVisitor() {
- @Override
- public void visit(File file) {
- try {
- if (processedFiles.contains(file)) {
- return;
- }
-
- if (!file.canRead()) {
- if (log.isDebugEnabled()) {
- log.debug("Skipping " + file.getPath() +
" since it is not readable.");
- return;
- }
- }
-
- if (log.isInfoEnabled()) {
- log.info("Detected added file for " + schedule
+ " --> " + file.getAbsolutePath());
- }
+ forEachFile(basedir, new FilterFileVisitor(basedir,
schedule.getDriftDefinition().getIncludes(), schedule
+ .getDriftDefinition().getExcludes(), new FileVisitor() {
+ @Override
+ public void visit(File file) {
+ try {
+ if (processedFiles.contains(file)) {
+ return;
+ }
- FileEntry newEntry = addedFileEntry(relativePath(basedir,
file), sha256(file));
- deltaEntries.add(newEntry);
- snapshotEntries.add(newEntry);
- } catch (IOException e) {
- log.error("An error occurred while generating a drift
change set for " + schedule + ": "
- + e.getMessage());
- throw new DriftDetectionException("An error occurred
while generating a drift change set",
- e);
+ if (log.isInfoEnabled()) {
+ log.info("Detected added file for " + schedule +
" --> " + file.getAbsolutePath());
}
+
+ FileEntry newEntry = addedFileEntry(relativePath(basedir, file),
sha256(file));
+ deltaEntries.add(newEntry);
+ snapshotEntries.add(newEntry);
+ } catch (IOException e) {
+ log.error("An error occurred while generating a drift change
set for " + schedule + ": "
+ + e.getMessage());
+ throw new DriftDetectionException("An error occurred while
generating a drift change set", e);
}
- }));
+ }
+ }));
}
if (deltaEntries.isEmpty()) {
// If nothing has changed, there is no need to add/update any files
- summary.setNewSnapshot(currentSnapshot);
- } else {
- File oldSnapshot = new File(currentSnapshot.getParentFile(),
currentSnapshot.getName() +
- ".previous");
- copyFile(currentSnapshot, oldSnapshot);
- currentSnapshot.delete();
-
- Headers deltaHeaders = createHeaders(schedule, DRIFT, newVersion);
- Headers snapshotHeaders = createHeaders(schedule, COVERAGE, newVersion);
-
- File driftChangeSet = changeSetMgr.findChangeSet(schedule.getResourceId(),
- schedule.getDriftConfiguration().getName(), DRIFT);
- ChangeSetWriter deltaWriter = changeSetMgr.getChangeSetWriter(driftChangeSet,
deltaHeaders);
-
- File newSnapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
- schedule.getDriftConfiguration().getName(), COVERAGE);
- ChangeSetWriter newSnapshotWriter =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(),
- snapshotHeaders);
-
- summary.setDriftChangeSet(driftChangeSet);
- summary.setNewSnapshot(newSnapshot);
- summary.setOldSnapshot(oldSnapshot);
-
- for (FileEntry entry : deltaEntries) {
- deltaWriter.write(entry);
- }
- deltaWriter.close();
+ return 0;
+ }
- for (FileEntry entry : snapshotEntries) {
- newSnapshotWriter.write(entry);
- }
- newSnapshotWriter.close();
+ File snapshotFile = changeSetMgr.findChangeSet(schedule.getResourceId(),
schedule.getDriftDefinition()
+ .getName(), COVERAGE);
+ File backupSnapshotFile = new File(snapshotFile.getParentFile(),
snapshotFile.getName() + ".bak");
+ copyFile(snapshotFile, snapshotFile);
+
+ Headers deltaHeaders = createHeaders(schedule, DRIFT, newVersion);
+ Headers snapshotHeaders = createHeaders(schedule, COVERAGE, newVersion);
+
+ ChangeSetWriter deltaWriter =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(), deltaHeaders);
+ ChangeSetWriter snapshotWriter =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(), snapshotHeaders);
+
+ for (FileEntry entry : deltaEntries) {
+ deltaWriter.write(entry);
+ }
+ deltaWriter.close();
+
+ for (FileEntry entry : snapshotEntries) {
+ snapshotWriter.write(entry);
}
+ snapshotWriter.close();
+ backupSnapshotFile.delete();
+
+ return deltaEntries.size();
}
- private void generateSnapshot(DriftDetectionSummary summary) throws IOException {
- final DriftDetectionSchedule schedule = summary.getSchedule();
+ private void generateSnapshot(final DriftDetectionSchedule schedule) throws
IOException {
log.debug("Generating coverage change set for " + schedule);
- File snapshot = changeSetMgr.findChangeSet(schedule.getResourceId(),
schedule.getDriftConfiguration().getName(),
- COVERAGE);
- final ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(snapshot,
createHeaders(schedule, COVERAGE, 0));
- final DriftConfiguration config = schedule.getDriftConfiguration();
- final File basedir = new File(basedir(schedule.getResourceId(), config));
+ final ChangeSetWriter writer =
changeSetMgr.getChangeSetWriter(schedule.getResourceId(), createHeaders(
+ schedule, COVERAGE, 0));
+ final DriftDefinition driftDef = schedule.getDriftDefinition();
+ final File basedir = new File(basedir(schedule.getResourceId(), driftDef));
if (basedir.isDirectory()) {
- forEachFile(basedir, new FilterFileVisitor(basedir, config.getIncludes(),
config.getExcludes(),
+ forEachFile(basedir, new FilterFileVisitor(basedir, driftDef.getIncludes(),
driftDef.getExcludes(),
new FileVisitor() {
@Override
public void visit(File file) {
try {
- if (!file.canRead()) {
- if (log.isDebugEnabled()) {
- log.debug("Skipping " + file.getPath() +
" since it is not readable.");
- }
- return;
- }
- if (log.isDebugEnabled()) {
- log.debug("Adding " + file.getPath() + "
to coverage change set for " + schedule);
+ if (log.isInfoEnabled()) {
+ log
+ .info("Adding " + file.getAbsolutePath() +
" to coverage change set for "
+ + schedule);
}
writer.write(addedFileEntry(relativePath(basedir, file),
sha256(file)));
} catch (IOException e) {
@@ -306,7 +263,6 @@ public class DriftDetector implements Runnable {
}));
}
writer.close();
- summary.setNewSnapshot(snapshot);
}
private String relativePath(File basedir, File file) {
@@ -320,66 +276,20 @@ public class DriftDetector implements Runnable {
return digestGenerator.calcDigestString(file);
}
- private String basedir(int resourceId, DriftConfiguration driftConfig) {
- return driftClient.getAbsoluteBaseDirectory(resourceId,
driftConfig).getAbsolutePath();
+ private String basedir(int resourceId, DriftDefinition driftDef) {
+ return driftClient.getAbsoluteBaseDirectory(resourceId,
driftDef).getAbsolutePath();
}
private Headers createHeaders(DriftDetectionSchedule schedule, DriftChangeSetCategory
type, int version) {
Headers headers = new Headers();
headers.setResourceId(schedule.getResourceId());
- headers.setDriftCofigurationId(schedule.getDriftConfiguration().getId());
- headers.setDriftConfigurationName(schedule.getDriftConfiguration().getName());
- headers.setBasedir(basedir(schedule.getResourceId(),
schedule.getDriftConfiguration()));
+ headers.setDriftDefinitionId(schedule.getDriftDefinition().getId());
+ headers.setDriftDefinitionName(schedule.getDriftDefinition().getName());
+ headers.setBasedir(basedir(schedule.getResourceId(),
schedule.getDriftDefinition()));
headers.setType(type);
headers.setVersion(version);
return headers;
}
- private void revertSnapshot(DriftDetectionSummary summary) throws IOException {
- log.info("Reverting snapshot for " + summary.getSchedule());
-
- DriftDetectionSchedule scheudle = summary.getSchedule();
- File newSnapshot = changeSetMgr.findChangeSet(scheudle.getResourceId(),
- scheudle.getDriftConfiguration().getName(), COVERAGE);
-
- // We want to delete the snapshot file regardless of whether the drift detection
- // was for an initial coverage change set or for a drift change set. We do not
know
- // the state of the snapshot file so we have to delete it. If we have only
generated
- // the initial coverage change set, then it will get regenerated.
- newSnapshot.delete();
-
- if (summary.getType() == DRIFT) {
- File oldSnapshotBackup = summary.getOldSnapshot();
- // If we generated a drift change set, we need to check for a back up of the
- // previous snapshot. We revert to the back up. If no back up is found, we
log
- // an error.
- if (oldSnapshotBackup != null && oldSnapshotBackup.exists()) {
- copyFile(oldSnapshotBackup, newSnapshot);
- // We have to delete to the previous version snapshot file; otherwise,
- // subsequent detection runs will be skipped.
- oldSnapshotBackup.delete();
- } else {
- // TODO Should we throw an exception and/or disable detection?
- // If we fall into this else block, that means we were not able to
revert
- // to the previous snapshot version, and we may be in an inconsistent
state.
- log.error("Cannot revert snapshot to previous version for " +
summary.getSchedule() +
- ". Snapshot back up file not found.");
- }
- }
- deleteZipFiles(newSnapshot.getParentFile());
- }
-
- private void deleteZipFiles(File dir) {
- File[] files = dir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(".zip");
- }
- });
- for (File file : files) {
- file.delete();
- }
- }
-
}
\ No newline at end of file
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java
index 5cd4d4b..9bfd900 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/DriftFilesSender.java
@@ -51,7 +51,7 @@ public class DriftFilesSender implements Runnable {
@Override
public void run() {
try {
- File changeSet = changeSetMgr.findChangeSet(resourceId,
headers.getDriftConfigurationName());
+ File changeSet = changeSetMgr.findChangeSet(resourceId,
headers.getDriftDefinitionName());
File contentDir = new File(changeSet.getParentFile(), "content");
contentDir.mkdir();
@@ -63,14 +63,14 @@ public class DriftFilesSender implements Runnable {
copyFile(file, new File(contentDir, driftFile.getHashId()));
}
}
- driftClient.sendChangeSetContentToServer(resourceId,
headers.getDriftConfigurationName(), contentDir);
+ driftClient.sendChangeSetContentToServer(resourceId,
headers.getDriftDefinitionName(), contentDir);
} catch (IOException e) {
log.error("Failed to send drift files.", e);
}
}
private File find(DriftFile driftFile) throws IOException {
- ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId,
headers.getDriftConfigurationName());
+ ChangeSetReader reader = changeSetMgr.getChangeSetReader(resourceId,
headers.getDriftDefinitionName());
for (FileEntry entry : reader) {
if (entry.getNewSHA().equals(driftFile.getHashId())) {
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 8fd065f..f655dd7 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
@@ -19,13 +19,17 @@
package org.rhq.core.pc.drift;
+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.DriftDefinitionComparator.CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS;
+import static org.rhq.core.util.file.FileUtil.purge;
+
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.FilenameFilter;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -42,7 +46,9 @@ import org.rhq.core.clientapi.agent.drift.DriftAgentService;
import org.rhq.core.clientapi.server.drift.DriftServerService;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.drift.Drift;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.drift.DriftDefinitionComparator;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.resource.Resource;
@@ -55,12 +61,6 @@ import org.rhq.core.pc.inventory.ResourceContainer;
import org.rhq.core.pc.measurement.MeasurementManager;
import org.rhq.core.util.stream.StreamUtil;
-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.core.util.file.FileUtil.purge;
-
public class DriftManager extends AgentService implements DriftAgentService, DriftClient,
ContainerService {
private final Log log = LogFactory.getLog(DriftManager.class);
@@ -94,7 +94,6 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
@Override
public void initialize() {
- long initStartTime = System.currentTimeMillis();
changeSetsDir.mkdir();
changeSetMgr = new ChangeSetManagerImpl(changeSetsDir);
@@ -107,13 +106,9 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
long startTime = System.currentTimeMillis();
initSchedules(inventoryMgr.getPlatform(), inventoryMgr);
long endTime = System.currentTimeMillis();
+ log.info("Finished initializing drift detection schedules in " +
(endTime - startTime) + " ms");
- if (log.isInfoEnabled()) {
- log.info("Finished initializing drift detection schedules in " +
(endTime - startTime) + " ms");
- }
-
- scanForContentToResend();
- purgeDeletedDriftConfigDirs();
+ purgeDeletedDriftDefDirs();
driftThreadPool = new ScheduledThreadPoolExecutor(5);
@@ -127,10 +122,6 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
initialized = true;
- long initEndTime = System.currentTimeMillis();
- if (log.isInfoEnabled()) {
- log.info("Finished initialization in " + (initEndTime -
initStartTime) + " ms");
- }
}
private void initSchedules(Resource r, InventoryManager inventoryMgr) {
@@ -146,13 +137,13 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
log.debug("Rescheduling drift detection for " + r);
- for (DriftConfiguration c : container.getDriftConfigurations()) {
+ for (DriftDefinition c : container.getDriftDefinitions()) {
try {
syncWithServer(r, c);
schedulesQueue.addSchedule(new DriftDetectionSchedule(r.getId(), c));
} catch (IOException e) {
- log.error("Failed to sync with server for " + toString(r, c) +
". Drift detection will not be " +
- "scheduled.", e);
+ log.error("Failed to sync with server for " + toString(r, c) +
". Drift detection will not be "
+ + "scheduled.", e);
}
}
@@ -161,101 +152,78 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
}
- private void syncWithServer(Resource resource, DriftConfiguration configuration)
throws IOException {
- Headers headers = createHeaders(resource, configuration);
+ private void syncWithServer(Resource resource, DriftDefinition driftDef) throws
IOException {
+ Headers headers = createHeaders(resource, driftDef);
if (!changeSetMgr.changeSetExists(resource.getId(), headers)) {
- log.info("No snapshot found for " + toString(resource,
configuration) + ". Downloading snapshot from " +
- "server");
+ log.info("No snapshot found for " + toString(resource, driftDef) +
". Downloading snapshot from "
+ + "server");
DriftSnapshot snapshot =
pluginContainerConfiguration.getServerServices().getDriftServerService()
- .getCurrentSnapshot(configuration.getId());
+ .getCurrentSnapshot(driftDef.getId());
if (snapshot.getVersion() == -1) {
// A version of -1 indicates that no change sets have been reported
- // for this configuration. This can occur when a user creates a
- // drift configuration while the agent is offline for example. At
+ // for this def. This can occur when a user creates a
+ // drift def while the agent is offline for example. At
// this point we just return and allow the agent to generate the
// initial snapshot file.
if (log.isDebugEnabled()) {
- log.debug("The server does not have any change sets for " +
toString(resource, configuration) +
- ". An initial snapshot needs to be generated.");
+ log.debug("The server does not have any change sets for " +
toString(resource, driftDef)
+ + ". An initial snapshot needs to be generated.");
}
return;
}
- headers.setVersion(snapshot.getVersion());
-
- log.info("Preparing to write snapshot at version " +
snapshot.getVersion() + " to disk for " +
- toString(resource, configuration));
+ log.info("Preparing to write snapshot at version " +
snapshot.getVersion() + " to disk for "
+ + toString(resource, driftDef));
ChangeSetWriter writer = changeSetMgr.getChangeSetWriter(resource.getId(),
headers);
for (Drift drift : snapshot.getEntries()) {
switch (drift.getCategory()) {
- case FILE_ADDED:
- writer.write(addedFileEntry(drift.getPath(),
drift.getNewDriftFile().getHashId()));
- break;
- case FILE_CHANGED:
- writer.write(changedFileEntry(drift.getPath(),
drift.getOldDriftFile().getHashId(),
- drift.getNewDriftFile().getHashId()));
- break;
- default: // FILE_REMOVED
- writer.write(removedFileEntry(drift.getPath(),
drift.getOldDriftFile().getHashId()));
+ case FILE_ADDED:
+ writer.write(addedFileEntry(drift.getPath(),
drift.getNewDriftFile().getHashId()));
+ break;
+ case FILE_CHANGED:
+ writer.write(changedFileEntry(drift.getPath(),
drift.getOldDriftFile().getHashId(), drift
+ .getNewDriftFile().getHashId()));
+ break;
+ default: // FILE_REMOVED
+ writer.write(removedFileEntry(drift.getPath(),
drift.getOldDriftFile().getHashId()));
}
}
writer.close();
}
}
- private void purgeDeletedDriftConfigDirs() {
- log.info("Checking for deleted drift configurations");
+ private void purgeDeletedDriftDefDirs() {
+ log.info("Checking for deleted drift definitions");
+ DriftDefinitionComparator comparator = new DriftDefinitionComparator(
+ BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
for (File resourceDir : changeSetsDir.listFiles()) {
int resourceId = Integer.parseInt(resourceDir.getName());
- for (File configDir : resourceDir.listFiles()) {
- DriftConfiguration config = new DriftConfiguration(new Configuration());
- config.setName(configDir.getName());
- if (!schedulesQueue.contains(resourceId, config)) {
- log.info("Detected deleted drift configuration,
DriftConfiguration[name: " + config.getName() +
- ", resourceId: " + resourceId + "]");
- log.info("Deleting drift configuration directory " +
configDir.getPath());
- purge(configDir, true);
- }
- }
- }
- }
-
- /**
- * Scans the changesets directory for any change set content zip files. This method
- * assumes that any content zip files found have not been received or persisted by
the
- * server. Each content zip file is resent to the server.
- */
- public void scanForContentToResend() {
- log.info("Scanning for change set content to resend...");
- for (File resourceDir : changeSetsDir.listFiles()) {
- for (File configDir : resourceDir.listFiles()) {
- for (File contentZipFile : configDir.listFiles(new
ZipFileNameFilter("content_"))) {
- if (log.isDebugEnabled()) {
- log.debug("Resending " + contentZipFile.getPath());
- }
- sendContentZipFile(Integer.parseInt(resourceDir.getName()),
configDir.getName(), contentZipFile);
+ for (File defDir : resourceDir.listFiles()) {
+ DriftDefinition def = new DriftDefinition(new Configuration());
+ def.setName(defDir.getName());
+ if (!schedulesQueue.contains(resourceId, def)) {
+ log.info("Detected deleted drift definition,
DriftDefinition[name: " + def.getName()
+ + ", resourceId: " + resourceId + "]");
+ log.info("Deleting drift definition directory " +
defDir.getPath());
+ purge(defDir, true);
}
}
}
}
- private String toString(Resource r, DriftConfiguration c) {
- return toString(r.getId(), c);
+ private String toString(Resource r, DriftDefinition c) {
+ return "DriftDefinition[id: " + c.getId() + ", resourceId: "
+ r.getId() + ", name: " + c.getName() + "]";
}
- private String toString(int resourceId, DriftConfiguration c) {
- return "DriftConfiguration[id: " + c.getId() + ", resourceId:
" + resourceId + ", name: " + c.getName() + "]";
- }
-
- private Headers createHeaders(Resource resource, DriftConfiguration configuration) {
+ private Headers createHeaders(Resource resource, DriftDefinition driftDef) {
Headers headers = new Headers();
headers.setResourceId(resource.getId());
- headers.setDriftCofigurationId(configuration.getId());
- headers.setType(COVERAGE);
- headers.setDriftConfigurationName(configuration.getName());
- headers.setBasedir(getAbsoluteBaseDirectory(resource.getId(),
configuration).getAbsolutePath());
+ headers.setDriftDefinitionId(driftDef.getId());
+ headers.setType(DriftChangeSetCategory.COVERAGE);
+ headers.setDriftDefinitionName(driftDef.getName());
+ headers.setBasedir(getAbsoluteBaseDirectory(resource.getId(),
driftDef).getAbsolutePath());
return headers;
}
@@ -288,70 +256,55 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
@Override
- public void sendChangeSetToServer(DriftDetectionSummary detectionSummary) {
- int resourceId = detectionSummary.getSchedule().getResourceId();
- DriftConfiguration driftConfiguration =
detectionSummary.getSchedule().getDriftConfiguration();
-
- if (!schedulesQueue.contains(resourceId, driftConfiguration)) {
- return;
- }
+ public void sendChangeSetToServer(int resourceId, DriftDefinition driftDef,
DriftChangeSetCategory type) {
+ try {
+ if (!schedulesQueue.contains(resourceId, driftDef)) {
+ return;
+ }
- File changeSetFile;
- if (detectionSummary.getType() == COVERAGE) {
- changeSetFile = detectionSummary.getNewSnapshot();
- } else {
- changeSetFile = detectionSummary.getDriftChangeSet();
- }
- if (changeSetFile == null) {
- log.warn("changeset[resourceId: " + resourceId + ",
driftConfiguration: " +
- driftConfiguration.getName() + "] was not found. Cancelling request
to send change set " +
- "to server");
- return;
- }
+ File changeSetFile = changeSetMgr.findChangeSet(resourceId,
driftDef.getName(), type);
+ if (changeSetFile == null) {
+ log.warn("changeset[resourceId: " + resourceId + ",
driftDefinition: " + driftDef.getName()
+ + "] was not found. Cancelling request to send change set "
+ "to server");
+ return;
+ }
- DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
+ DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
- String fileName = "changeset_" + System.currentTimeMillis() +
".zip";
- final File zipFile = new File(changeSetFile.getParentFile(), fileName);
- ZipOutputStream stream = null;
+ // TODO Include the version in the change set file name to ensure the file
name is unique
+ String fileName = "changeset_" + System.currentTimeMillis() +
".zip";
+ final File zipFile = new File(changeSetFile.getParentFile(), fileName);
+ ZipOutputStream stream = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(zipFile)));
- try {
- stream = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(zipFile)));
FileInputStream fis = new FileInputStream(changeSetFile);
stream.putNextEntry(new ZipEntry(changeSetFile.getName()));
StreamUtil.copy(fis, stream, false);
fis.close();
stream.close();
- } catch (IOException e) {
- zipFile.delete();
- throw new DriftDetectionException("Failed to create change set zip file
" + zipFile.getPath(), e);
- } finally {
- try {
- if (stream != null) {
- stream.close();
- }
- } catch (IOException e) {
- log.warn("An error occurred while trying to close change set zip
file output stream", e);
- }
- }
- try {
- driftServer.sendChangesetZip(resourceId, zipFile.length(),
remoteInputStream(new BufferedInputStream(
- new FileInputStream(zipFile))));
+ // We want to clean up after we send the zip file to the server. We do this
by
+ // deleting the files in the content directory and the content zip itself.
They
+ // are no longer needed after being sent to the server. We cannot
immediately
+ // delete the content zip file though because it is sent asynchronously, and
we
+ // wind up deleting it before it is sent. The following approach allows us
to
+ // safely delete it when the comm layer closes the remote input stream.
+ //
+ // jsanda
+ DriftInputStream inputStream = new DriftInputStream(new
BufferedInputStream(new FileInputStream(zipFile)),
+ new DeleteFile(zipFile));
+
+ driftServer.sendChangesetZip(resourceId, zipFile.length(),
remoteInputStream(inputStream));
+
} catch (IOException e) {
- throw new DriftDetectionException("Failed to set change set for "
+
- toString(resourceId, driftConfiguration) + " to server");
- } catch (RuntimeException e) {
- throw new DriftDetectionException("Failed to set change set for "
+
- toString(resourceId, driftConfiguration) + " to server");
+ log.error("An error occurred while trying to send changeset[resourceId:
" + resourceId
+ + ", driftDefinition: " + driftDef.getName() + "]",
e);
}
}
@Override
- public void sendChangeSetContentToServer(int resourceId, String
driftConfigurationName, final File contentDir) {
+ public void sendChangeSetContentToServer(int resourceId, String driftDefName, final
File contentDir) {
try {
- String timestamp = Long.toString(System.currentTimeMillis());
- String contentFileName = "content_" + timestamp +
".zip";
+ String contentFileName = "content_" + System.currentTimeMillis() +
".zip";
final File zipFile = new File(contentDir.getParentFile(), contentFileName);
ZipOutputStream stream = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(zipFile)));
@@ -363,13 +316,22 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
stream.close();
-// DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
-// driftServer.sendFilesZip(resourceId, driftConfigurationName, timestamp,
zipFile.length(),
-// remoteInputStream(new BufferedInputStream(new
FileInputStream(zipFile))));
- sendContentZipFile(resourceId, driftConfigurationName, zipFile);
+ // We want to clean up after we send the zip file to the server. We do this
by
+ // deleting the files in the content directory and the content zip itself.
They
+ // are no longer needed after being sent to the server. We cannot
immediately
+ // delete the content zip file though because it is sent asynchronously, and
we
+ // wind up deleting it before it is sent. The following approach allows us
to
+ // safely delete it when the comm layer closes the remote input stream.
+ //
+ // jsanda
+ DriftInputStream inputStream = new DriftInputStream(new
BufferedInputStream(new FileInputStream(zipFile)),
+ new DeleteFile(zipFile));
+
+ DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
+ driftServer.sendFilesZip(resourceId, zipFile.length(),
remoteInputStream(inputStream));
} catch (IOException e) {
log.error("An error occurred while trying to send content for
changeset[resourceId: " + resourceId
- + ", driftConfiguration: " + driftConfigurationName +
"]", e);
+ + ", driftDefinition: " + driftDefName + "]", e);
}
for (File file : contentDir.listFiles()) {
@@ -379,34 +341,17 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
}
- private void sendContentZipFile(int resourceId, String driftConfigName, File
contentZipFile) {
- try {
- int startIndex = "content_".length();
- int endIndex = contentZipFile.getName().indexOf(".");
- String token = contentZipFile.getName().substring(startIndex, endIndex);
-
- DriftServerService driftServer =
pluginContainerConfiguration.getServerServices().getDriftServerService();
- driftServer.sendFilesZip(resourceId, driftConfigName, token,
contentZipFile.length(),
- remoteInputStream(new BufferedInputStream(new
FileInputStream(contentZipFile))));
- } catch (FileNotFoundException e) {
- log.error("An error occurred while trying to send change set content zip
file " +
- contentZipFile.getPath() + " to server.", e);
- }
- }
-
@Override
- public void detectDrift(int resourceId, DriftConfiguration driftConfiguration) {
+ public void detectDrift(int resourceId, DriftDefinition driftDef) {
if (log.isInfoEnabled()) {
log.info("Received request to schedule drift detection immediately for
[resourceId: " + resourceId
- + ", driftConfigurationId: " + driftConfiguration.getId() +
", driftConfigurationName: "
- + driftConfiguration.getName() + "]");
+ + ", driftDefId: " + driftDef.getId() + ", driftDefName:
" + driftDef.getName() + "]");
}
- DriftDetectionSchedule schedule = schedulesQueue.remove(resourceId,
driftConfiguration);
+ DriftDetectionSchedule schedule = schedulesQueue.remove(resourceId, driftDef);
if (schedule == null) {
- log.warn("No schedule found in the queue for [resourceId: " +
resourceId + ", driftConfigurationId: "
- + driftConfiguration.getId() + ", driftConfigurationName: " +
driftConfiguration.getName() + "]. No "
- + " work will be scheduled.");
+ log.warn("No schedule found in the queue for [resourceId: " +
resourceId + ", driftDefId: "
+ + driftDef.getId() + ", driftDefName: " + driftDef.getName() +
"]. No " + " work will be scheduled.");
return;
}
log.debug("Resetting " + schedule + " for immediate
detection.");
@@ -423,8 +368,8 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
@Override
- public void scheduleDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
- DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId,
driftConfiguration);
+ public void scheduleDriftDetection(int resourceId, DriftDefinition driftDef) {
+ DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId,
driftDef);
if (log.isInfoEnabled()) {
log.info("Scheduling drift detection for " + schedule);
}
@@ -436,7 +381,7 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
ResourceContainer container =
getInventoryManager().getResourceContainer(resourceId);
if (container != null) {
- container.addDriftConfiguration(driftConfiguration);
+ container.addDriftDefinition(driftDef);
}
} else {
log.warn("Failed to add " + schedule + " to " +
schedulesQueue);
@@ -446,9 +391,8 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
@Override
public boolean requestDriftFiles(int resourceId, Headers headers, List<? extends
DriftFile> driftFiles) {
if (log.isInfoEnabled()) {
- log.info("Server is requesting files for [resourceId: " +
resourceId + ", driftConfigurationId: " +
- headers.getDriftCofigurationId() + ", driftConfigurationName: "
+ headers.getDriftConfigurationName() +
- "]");
+ log.info("Server is requesting files for [resourceId: " +
resourceId + ", driftDefId: "
+ + headers.getDriftDefinitionId() + ", driftDefName: " +
headers.getDriftDefinitionName() + "]");
}
DriftFilesSender sender = new DriftFilesSender();
sender.setResourceId(resourceId);
@@ -463,26 +407,24 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
@Override
- public void unscheduleDriftDetection(final int resourceId, final DriftConfiguration
driftConfiguration) {
- log.info("Received request to unschedule drift detection for
[resourceId:" + resourceId +
- ", driftConfigurationId: " + driftConfiguration.getId() + ",
driftConfigurationName: " +
- driftConfiguration.getName() + "].");
-
- DriftDetectionSchedule schedule = schedulesQueue.removeAndExecute(resourceId,
driftConfiguration,
- new Runnable() {
- @Override
- public void run() {
- File resourceDir = new File(changeSetsDir,
Integer.toString(resourceId));
- File changeSetDir = new File(resourceDir,
driftConfiguration.getName());
- purge(changeSetDir, true);
-
- log.debug("Removed change set directory " +
changeSetDir.getAbsolutePath());
- }
- });
+ public void unscheduleDriftDetection(final int resourceId, final DriftDefinition
driftDef) {
+ log.info("Received request to unschedule drift detection for
[resourceId:" + resourceId + ", driftDefId: "
+ + driftDef.getId() + ", driftDefName: " + driftDef.getName() +
"].");
+
+ DriftDetectionSchedule schedule = schedulesQueue.removeAndExecute(resourceId,
driftDef, new Runnable() {
+ @Override
+ public void run() {
+ File resourceDir = new File(changeSetsDir,
Integer.toString(resourceId));
+ File changeSetDir = new File(resourceDir, driftDef.getName());
+ purge(changeSetDir, true);
+
+ log.debug("Removed change set directory " +
changeSetDir.getAbsolutePath());
+ }
+ });
if (schedule != null) {
ResourceContainer container =
getInventoryManager().getResourceContainer(resourceId);
if (container != null) {
- container.removeDriftConfiguration(schedule.getDriftConfiguration());
+ container.removeDriftDefinition(schedule.getDriftDefinition());
}
}
@@ -493,15 +435,15 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
}
@Override
- public void updateDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
- log.info("Received request to update schedule for [resourceId: " +
resourceId + ", driftConfigurationId: " +
- driftConfiguration.getId() + ", driftConfigurationName: " +
driftConfiguration.getName() + "]");
- DriftDetectionSchedule updatedSchedule = schedulesQueue.update(resourceId,
driftConfiguration);
+ public void updateDriftDetection(int resourceId, DriftDefinition driftDef) {
+ log.info("Received request to update schedule for [resourceId: " +
resourceId + ", driftDefId: "
+ + driftDef.getId() + ", driftDefName: " + driftDef.getName() +
"]");
+ DriftDetectionSchedule updatedSchedule = schedulesQueue.update(resourceId,
driftDef);
if (updatedSchedule == null) {
- updatedSchedule = new DriftDetectionSchedule(resourceId,
driftConfiguration);
+ updatedSchedule = new DriftDetectionSchedule(resourceId, driftDef);
if (log.isInfoEnabled()) {
- log.info("No matching schedule was found in the queue. This must be
a request to add a new " +
- "schedule. Adding " + updatedSchedule + " to " +
schedulesQueue);
+ log.info("No matching schedule was found in the queue. This must be
a request to add a new "
+ + "schedule. Adding " + updatedSchedule + " to "
+ schedulesQueue);
}
boolean added = schedulesQueue.addSchedule(updatedSchedule);
if (added) {
@@ -522,65 +464,21 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
InventoryManager inventoryMgr =
PluginContainer.getInstance().getInventoryManager();
ResourceContainer container = inventoryMgr.getResourceContainer(resourceId);
if (container != null) {
- container.addDriftConfiguration(driftConfiguration);
- }
- }
-
- @Override
- public void ackChangeSet(int resourceId, String driftConfigName) {
- log.info("Received server change set ack for [resourceId: " +
resourceId + ", driftConfiguration:" +
- driftConfigName + "]");
-
- File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
- File changeSetDir = new File(resourceDir, driftConfigName);
-
- if (!changeSetDir.exists()) {
- log.warn("Cannot complete acknowledgement. Change set directory " +
changeSetDir.getPath() +
- " does not exist.");
- return;
- }
-
- File snapshot = changeSetMgr.findChangeSet(resourceId, driftConfigName,
COVERAGE);
- File previousSnapshot = new File(snapshot.getParentFile(), snapshot.getName() +
".previous");
-
- previousSnapshot.delete();
- deleteZipFiles(changeSetDir, "changeset_");
- }
-
- @Override
- public void ackChangeSetContent(int resourceId, String driftConfigName, String token)
{
- log.info("Received server change set content ack for [resourceId: " +
resourceId +
- ", driftConfigurationName: " + driftConfigName + "]");
-
- File resourceDir = new File(changeSetsDir, Integer.toString(resourceId));
- File changeSetDir = new File(resourceDir, driftConfigName);
-
- if (!changeSetDir.exists()) {
- log.warn("Cannot complete acknowledgement. Change set directory " +
changeSetDir.getPath() +
- " does not exist.");
- return;
- }
-
- deleteZipFiles(changeSetDir, "content_" + token);
- }
-
- private void deleteZipFiles(File dir, final String prefix) {
- for (File file : dir.listFiles(new ZipFileNameFilter(prefix))) {
- file.delete();
+ container.addDriftDefinition(driftDef);
}
}
/**
- * Given a drift configuration, this examines the config and its associated resource
to determine where exactly
+ * Given a drift definition, this examines the config and its associated resource to
determine where exactly
* the base directory is that should be monitoried.
*
* @param resourceId The id of the resource to which the config belongs
- * @param driftConfiguration describes what is to be monitored for drift
+ * @param driftDef describes what is to be monitored for drift
*
- * @return absolute directory location where the drift configuration base directory
is referring
+ * @return absolute directory location where the drift definition base directory is
referring
*/
@Override
- public File getAbsoluteBaseDirectory(int resourceId, DriftConfiguration
driftConfiguration) {
+ public File getAbsoluteBaseDirectory(int resourceId, DriftDefinition driftDef) {
// get the resource entity stored in our local inventory
InventoryManager im = getInventoryManager();
@@ -588,9 +486,9 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
Resource resource = container.getResource();
// find out the type of base location that is specified by the drift config
- DriftConfiguration.BaseDirectory baseDir = driftConfiguration.getBasedir();
+ DriftDefinition.BaseDirectory baseDir = driftDef.getBasedir();
if (baseDir == null) {
- throw new IllegalArgumentException("Missing basedir in drift
config");
+ throw new IllegalArgumentException("Missing basedir in drift
def");
}
// based on the type of base location, determine the root base directory
@@ -664,16 +562,17 @@ public class DriftManager extends AgentService implements
DriftAgentService, Dri
return PluginContainer.getInstance().getMeasurementManager();
}
- private static class ZipFileNameFilter implements FilenameFilter {
- private String prefix;
+ private static class DeleteFile implements Runnable {
- public ZipFileNameFilter(String prefix) {
- this.prefix = prefix;
+ private File file;
+
+ public DeleteFile(File file) {
+ this.file = file;
}
@Override
- public boolean accept(File dir, String name) {
- return name.startsWith(prefix) && name.endsWith(".zip");
+ public void run() {
+ file.delete();
}
}
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueue.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueue.java
index a453f74..8d45b75 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueue.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueue.java
@@ -1,20 +1,20 @@
package org.rhq.core.pc.drift;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfigurationComparator;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.drift.DriftDefinitionComparator;
/**
* Manages the drift detection schedules that are processed by the drift detector. The
* queue has a concept of the currently "active" schedule. This is identified
simply as
* the schedule returned from {@link #getNextSchedule()} which is the previous head of
the
* queue. A reference to the active schedule needs to be maintained because at any point
in
- * time the server can send a request to update the drift configuration that is attached
to
+ * time the server can send a request to update the drift definition that is attached to
* a schedule. That schedule will either be on the queue waiting to be processed or in
the
* "active" state meaning it is currently being processed by the drift
detector.
*/
public interface ScheduleQueue {
- DriftDetectionSchedule[] toArray();
+ DriftDetectionSchedule[] toArray();
/**
* Removes the head of the queue and returns a copy of the schedule that was
removed.
@@ -46,49 +46,49 @@ public interface ScheduleQueue {
boolean addSchedule(DriftDetectionSchedule schedule);
/**
- * Checks the queue for a schedule with specified resource id and drift
configuration
- * whose name matches the specified configuration.
+ * Checks the queue for a schedule with specified resource id and drift definition
+ * whose name matches the specified definition.
*
* @param resourceId The resource id of the schedule
- * @param config The drift configuration of the schedule
+ * @param driftDef The drift definition of the schedule
* @return true if the queue contains a schedule with the specified resource id and
a
- * drift configuration whose name matches the name of the specified configuration.
+ * drift definition whose name matches the name of the specified definition.
*/
- boolean contains(int resourceId, DriftConfiguration config);
+ boolean contains(int resourceId, DriftDefinition driftDef);
- boolean contains(int resourceId, DriftConfiguration config,
DriftConfigurationComparator comparator);
+ boolean contains(int resourceId, DriftDefinition driftDef, DriftDefinitionComparator
comparator);
/**
* This method attempts to update the schedule identified by the resource id the and
- * the drift configuration. More specifically, the schedule is identified by a
- * combination of resource id and drift configuraiton name. If the schedule to be
+ * the drift definition. More specifically, the schedule is identified by a
+ * combination of resource id and drift definition name. If the schedule to be
* updated is the active schedule, it is immediately updated and then placed back on
* the queue the next time {@link #deactivateSchedule()} is called. If the schedule
* is on the queue, it is removed, updated, and then added back onto the queue.
*
* @param resourceId The resource id
- * @param config A {@link DriftConfiguration} belonging the resource with the
specified id
+ * @param driftDef A {@link DriftDefinition} belonging the resource with the
specified id
* @return A copy of the updated schedule or null if no update was performed
*/
- DriftDetectionSchedule update(int resourceId, DriftConfiguration config);
+ DriftDetectionSchedule update(int resourceId, DriftDefinition driftDef);
/**
- * Removes the schedule identified by the resource id and the drift configuration.
More
+ * Removes the schedule identified by the resource id and the drift definition. More
* specifically, the schedule is identified by a combination of resource id drift
- * configuration name. This method can remove either the active schedule or a
schedule
+ * definition name. This method can remove either the active schedule or a schedule
* on the queue.
*
* @param resourceId The resource id
*
- * @param config A {@link DriftConfiguration} belonging the resource with the
specified id
+ * @param driftDef A {@link DriftDefinition} belonging the resource with the
specified id
*
* @return The {@link DriftDetectionSchedule} that is removed or null if no matching
* schedule is found.
*/
- DriftDetectionSchedule remove(int resourceId, DriftConfiguration config);
+ DriftDetectionSchedule remove(int resourceId, DriftDefinition driftDef);
/**
- * Removes the schedule identified by the resource id and the drift configuration
name.
+ * Removes the schedule identified by the resource id and the drift definition name.
* This method can remove either the active schedule or a schedule on the queue.
When
* the schedule is in the queue, <code>task</code> is executed
immediately after the
* schedule is removed from the queue. If the schedule is active, then
<code>task</code>
@@ -106,13 +106,13 @@ public interface ScheduleQueue {
* is not in used before task is executed.
*
* @param resourceId The resource id
- * @param config A {@link DriftConfiguration} belonging the resource with the
specified id
+ * @param driftDef A {@link DriftDefinition} belonging the resource with the
specified id
* @param task A callback to perform any post-processing when the schedule is
removed
* from the queue
* @return The {@link DriftDetectionSchedule} that is removed or null if no matching
* schedule is found.
*/
- DriftDetectionSchedule removeAndExecute(int resourceId, DriftConfiguration config,
Runnable task);
+ DriftDetectionSchedule removeAndExecute(int resourceId, DriftDefinition driftDef,
Runnable task);
/**
* Removes all elements from the queue and deactivates the active schedule.
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueueImpl.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueueImpl.java
index e5fa56e..13e20b6 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueueImpl.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/ScheduleQueueImpl.java
@@ -7,8 +7,8 @@ import java.util.List;
import java.util.PriorityQueue;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfigurationComparator;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.drift.DriftDefinitionComparator;
public class ScheduleQueueImpl implements ScheduleQueue {
@@ -41,22 +41,21 @@ public class ScheduleQueueImpl implements ScheduleQueue {
}
}
- private boolean isActiveSchedule(int resourceId, DriftConfiguration config) {
+ private boolean isActiveSchedule(int resourceId, DriftDefinition driftDef) {
try {
lock.readLock().lock();
return activeSchedule != null && activeSchedule.getResourceId() ==
resourceId
- &&
activeSchedule.getDriftConfiguration().getName().equals(config.getName());
+ &&
activeSchedule.getDriftDefinition().getName().equals(driftDef.getName());
} finally {
lock.readLock().unlock();
}
}
- private boolean isActiveSchedule(int resourceId, DriftConfiguration config,
- DriftConfigurationComparator comparator) {
+ private boolean isActiveSchedule(int resourceId, DriftDefinition driftDef,
DriftDefinitionComparator comparator) {
try {
lock.readLock().lock();
return activeSchedule != null && activeSchedule.getResourceId() ==
resourceId
- && comparator.compare(activeSchedule.getDriftConfiguration(),
config) == 0;
+ && comparator.compare(activeSchedule.getDriftDefinition(),
driftDef) == 0;
} finally {
lock.readLock().unlock();
}
@@ -94,15 +93,15 @@ public class ScheduleQueueImpl implements ScheduleQueue {
}
@Override
- public boolean contains(int resourceId, DriftConfiguration config) {
- if (isActiveSchedule(resourceId, config)) {
+ public boolean contains(int resourceId, DriftDefinition driftDef) {
+ if (isActiveSchedule(resourceId, driftDef)) {
return true;
}
try {
lock.readLock().lock();
for (DriftDetectionSchedule schedule : queue) {
- if (schedule.getResourceId() == resourceId &&
- schedule.getDriftConfiguration().getName().equals(config.getName()))
{
+ if (schedule.getResourceId() == resourceId
+ &&
schedule.getDriftDefinition().getName().equals(driftDef.getName())) {
return true;
}
}
@@ -113,15 +112,15 @@ public class ScheduleQueueImpl implements ScheduleQueue {
}
@Override
- public boolean contains(int resourceId, DriftConfiguration config,
DriftConfigurationComparator comparator) {
- if (isActiveSchedule(resourceId, config, comparator)) {
+ public boolean contains(int resourceId, DriftDefinition driftDef,
DriftDefinitionComparator comparator) {
+ if (isActiveSchedule(resourceId, driftDef, comparator)) {
return true;
}
try {
lock.readLock().lock();
for (DriftDetectionSchedule schedule : queue) {
- if (schedule.getResourceId() == resourceId &&
- comparator.compare(schedule.getDriftConfiguration(), config) == 0) {
+ if (schedule.getResourceId() == resourceId
+ && comparator.compare(schedule.getDriftDefinition(),
driftDef) == 0) {
return true;
}
}
@@ -132,15 +131,15 @@ public class ScheduleQueueImpl implements ScheduleQueue {
}
@Override
- public DriftDetectionSchedule remove(int resourceId, DriftConfiguration config) {
- return removeAndExecute(resourceId, config, NO_OP);
+ public DriftDetectionSchedule remove(int resourceId, DriftDefinition driftDef) {
+ return removeAndExecute(resourceId, driftDef, NO_OP);
}
@Override
- public DriftDetectionSchedule removeAndExecute(int resourceId, DriftConfiguration
config, Runnable task) {
+ public DriftDetectionSchedule removeAndExecute(int resourceId, DriftDefinition
driftDef, Runnable task) {
try {
lock.writeLock().lock();
- if (isActiveSchedule(resourceId, config)) {
+ if (isActiveSchedule(resourceId, driftDef)) {
deactivationTask = task;
DriftDetectionSchedule removedSchedule = activeSchedule;
activeSchedule = null;
@@ -151,7 +150,7 @@ public class ScheduleQueueImpl implements ScheduleQueue {
while (iterator.hasNext()) {
DriftDetectionSchedule schedule = iterator.next();
if (schedule.getResourceId() == resourceId
- &&
schedule.getDriftConfiguration().getName().equals(config.getName())) {
+ &&
schedule.getDriftDefinition().getName().equals(driftDef.getName())) {
iterator.remove();
task.run();
return schedule;
@@ -165,13 +164,13 @@ public class ScheduleQueueImpl implements ScheduleQueue {
}
@Override
- public DriftDetectionSchedule update(int resourceId, DriftConfiguration config) {
- DriftDetectionSchedule schedule = remove(resourceId, config);
+ public DriftDetectionSchedule update(int resourceId, DriftDefinition driftDef) {
+ DriftDetectionSchedule schedule = remove(resourceId, driftDef);
if (schedule == null) {
return null;
}
- update(schedule, config);
+ update(schedule, driftDef);
try {
lock.writeLock().lock();
@@ -184,9 +183,9 @@ public class ScheduleQueueImpl implements ScheduleQueue {
}
}
- private void update(DriftDetectionSchedule schedule, DriftConfiguration config) {
- schedule.getDriftConfiguration().setEnabled(config.isEnabled());
- schedule.getDriftConfiguration().setInterval(config.getInterval());
+ private void update(DriftDetectionSchedule schedule, DriftDefinition driftDef) {
+ schedule.getDriftDefinition().setEnabled(driftDef.isEnabled());
+ schedule.getDriftDefinition().setInterval(driftDef.getInterval());
}
@Override
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
index 434ddc1..35e62d8 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSyncManager.java
@@ -19,6 +19,8 @@
package org.rhq.core.pc.drift.sync;
+import static
org.rhq.core.domain.drift.DriftDefinitionComparator.CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS;
+
import java.io.File;
import java.util.List;
import java.util.Map;
@@ -29,17 +31,15 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.rhq.core.clientapi.server.drift.DriftServerService;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfigurationComparator;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.drift.DriftDefinitionComparator;
import org.rhq.core.pc.drift.DriftManager;
import org.rhq.core.pc.inventory.InventoryManager;
-import static
org.rhq.core.domain.drift.DriftConfigurationComparator.CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS;
-
/**
- * This class handles syncing drift configurations and drift content during inventory
sync.
- * This class is intended to server as the public interface (so to speak) to
- * {@link InventoryManager} for syncing drift configurations and content.
+ * This class handles syncing drift definitions during inventory sync. This class is
+ * intended to server as the public interface (so to speak) to {@link InventoryManager}
for
+ * syncing drift definitions.
* <br/><br/>
* Please review the docs for each of the setter methods to determine which properties
* should be set before invoking any business logic methods.
@@ -89,19 +89,13 @@ public class DriftSyncManager {
dataDir = dataDirectory;
}
- /**
- * Synchronized both drift configurations and drift content with the server. The
drift
- * configuration sync goes from server to agent in that the drift configurations in
the
- * local inventory are updated to match the drift configurations on the server
- * inventory.
- * <br/><br/>
- * The content sync works as follows. Any change set content zip files found locally
- * resent to the server under the assumption that the content has not been persisted
on
- * the server.
- *
- * @param resourceIds The ids of resources that need to be synced.
- */
- public void syncWithServer(Set<Integer> resourceIds) {
+ public void syncDefsWithServer(Set<Integer> resourceIds) {
+ log.info("Starting server sync for drift definitions...");
+ long startTime = System.currentTimeMillis();
+
+ Map<Integer, List<DriftDefinition>> defs =
driftServer.getDriftDefinitions(resourceIds);
+ DriftDefinitionComparator comparator = new DriftDefinitionComparator(
+ BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
DriftSynchronizerFactory synchronizerFactory = new DriftSynchronizerFactory();
DriftSynchronizer synchronizer;
@@ -111,50 +105,26 @@ public class DriftSyncManager {
synchronizer = synchronizerFactory.getRuntimeSynchronizer(driftMgr);
}
- syncConfigs(synchronizer, resourceIds);
- syncContent(synchronizer);
- }
-
- private void syncConfigs(DriftSynchronizer synchronizer, Set<Integer>
resourceIds) {
- log.info("Starting server sync for drift configurations...");
- long startTime = System.currentTimeMillis();
-
- Map<Integer, List<DriftConfiguration>> configs =
driftServer.getDriftConfigurations(resourceIds);
- DriftConfigurationComparator comparator = new DriftConfigurationComparator(
- BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
-
int totalDeleted = 0;
int totalAdded = 0;
- for (Integer resourceId : configs.keySet()) {
- Set<DriftConfiguration> resourceConfigsOnServer = new
TreeSet<DriftConfiguration>(comparator);
- resourceConfigsOnServer.addAll(configs.get(resourceId));
-
- List<DriftConfiguration> deletedConfigs =
synchronizer.getDeletedConfigurations(resourceId,
- resourceConfigsOnServer);
- totalDeleted += deletedConfigs.size();
- synchronizer.purgeFromLocalInventory(resourceId, deletedConfigs);
+ for (Integer resourceId : defs.keySet()) {
+ Set<DriftDefinition> resourceDefsOnServer = new
TreeSet<DriftDefinition>(comparator);
+ resourceDefsOnServer.addAll(defs.get(resourceId));
- List<DriftConfiguration> addedConfigs =
synchronizer.getAddedConfigurations(resourceId,
- resourceConfigsOnServer);
- totalAdded += addedConfigs.size();
- synchronizer.addToLocalInventory(resourceId, addedConfigs);
- }
+ List<DriftDefinition> deletedDefs =
synchronizer.getDeletedDefinitions(resourceId, resourceDefsOnServer);
+ totalDeleted += deletedDefs.size();
+ synchronizer.purgeFromLocalInventory(resourceId, deletedDefs);
- long endTime = System.currentTimeMillis();
- if (log.isInfoEnabled()) {
- log.info("Finished server sync for drift configurations. " +
totalAdded + " added and " + totalDeleted +
- " deleted in " + (endTime - startTime) + " ms");
+ List<DriftDefinition> addedDefs =
synchronizer.getAddedDefinitions(resourceId, resourceDefsOnServer);
+ totalAdded += addedDefs.size();
+ synchronizer.addToLocalInventory(resourceId, addedDefs);
}
- }
- private void syncContent(DriftSynchronizer synchronizer) {
- log.info("Starting drift content sync...");
- long startTime = System.currentTimeMillis();
- synchronizer.syncChangeSetContent();
long endTime = System.currentTimeMillis();
if (log.isInfoEnabled()) {
- log.info("Finished drift content sync in " + (endTime - startTime)
+ " ms");
+ log.info("Finished server sync for drift definitions. " +
totalAdded + " added and " + totalDeleted
+ + " deleted in " + (endTime - startTime) + " ms");
}
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSynchronizer.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSynchronizer.java
index 90c4955..9a8f0cf 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSynchronizer.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/DriftSynchronizer.java
@@ -22,67 +22,65 @@ package org.rhq.core.pc.drift.sync;
import java.util.List;
import java.util.Set;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
/**
- * A DriftSynchronizer is responsible for sycning {@link DriftConfiguration}s in the
+ * A DriftSynchronizer is responsible for sycning {@link DriftDefinition}s in the
* server's with those in the local inventory.
*/
public interface DriftSynchronizer {
/**
- * Determines which drift configurations for a resource have been deleted on the
server
+ * Determines which drift definitions for a resource have been deleted on the server
* and need to be purged from the local inventory. This method should not make any
* changes to the local inventory. It also handles syncing content with the server.
Any
* change set content found on the agent and that is not known to be on the server
* should be sent to the server.
*
* @param resourceId
- * @param configurationsFromServer A set of drift configurations belonging to the
- * resource with the specified id. The set uses a {@link
org.rhq.core.domain.drift.DriftConfigurationComparator DriftConfigurationComparator}
- * with the compare mode set to {@link
org.rhq.core.domain.drift.DriftConfigurationComparator.CompareMode#BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS
BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS}.
- * @return A list of drift configurations that need to be purged from the local
inventory.
+ * @param definitionsFromServer A set of drift definitions belonging to the
+ * resource with the specified id. The set uses a {@link
org.rhq.core.domain.drift.DriftDefinitionComparator driftDefinitionComparator}
+ * with the compare mode set to {@link
org.rhq.core.domain.drift.DriftDefinitionComparator.CompareMode#BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS
BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS}.
+ * @return A list of drift definitions that need to be purged from the local
inventory.
*/
- List<DriftConfiguration> getDeletedConfigurations(int resourceId,
- Set<DriftConfiguration> configurationsFromServer);
-
+ List<DriftDefinition> getDeletedDefinitions(int resourceId,
Set<DriftDefinition> definitionsFromServer);
/**
- * Removes the drift configurations from local inventory. Implementations are
responsible
+ * Removes the drift definitions from local inventory. Implementations are
responsible
* for deciding how that is to be done. For example, if the plugin container is not
- * fully initialized, then purging will involve removing configurations from the
+ * fully initialized, then purging will involve removing definitions from the
* {@link org.rhq.core.pc.inventory.ResourceContainer ResourceContainer}. But if the
* plugin container is initialized, then drift detection will have to be
unscheduled.
*
* @param resourceId
- * @param configurations The drift configurations to purge from local inventory
+ * @param definitions The drift definitions to purge from local inventory
*/
- void purgeFromLocalInventory(int resourceId, List<DriftConfiguration>
configurations);
+ void purgeFromLocalInventory(int resourceId, List<DriftDefinition>
definitions);
/**
- * Determines which drift configurations for a resource have been added on the
server
+ * Determines which drift definitions for a resource have been added on the server
* and need to be added to the local inventory. This method should not make any
changes
* to the local inventory.
*
* @param resourceId
- * @param configurationsFromServer A set of drift configurations belonging to the
- * resource with the specified id. The set uses a {@link
org.rhq.core.domain.drift.DriftConfigurationComparator DriftConfigurationComparator}
- * with the compare mode set to {@link
org.rhq.core.domain.drift.DriftConfigurationComparator.CompareMode#BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS
BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS}.
- * @return A list of drift configurations that need to be purged from the local
inventory.
+ * @param definitionsFromServer A set of drift definitions belonging to the
+ * resource with the specified id. The set uses a {@link
org.rhq.core.domain.drift.DriftDefinitionComparator driftDefinitionComparator}
+ * with the compare mode set to {@link
org.rhq.core.domain.drift.DriftDefinitionComparator.CompareMode#BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS
BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS}.
+ * @return A list of drift definitions that need to be purged from the local
inventory.
*/
- List<DriftConfiguration> getAddedConfigurations(int resourceId,
Set<DriftConfiguration> configurationsFromServer);
+ List<DriftDefinition> getAddedDefinitions(int resourceId,
Set<DriftDefinition> definitionsFromServer);
/**
- * Adds the drift configurations to the local inventory. Implementations are
responsible
+ * Adds the drift definitions to the local inventory. Implementations are
responsible
* for deciding how that is to be done. For example, if the plugin container is not
- * fully initialized, then adding a configuration will involve adding it to the
+ * fully initialized, then adding a definition will involve adding it to the
* {@link org.rhq.core.pc.inventory.ResourceContainer ResourceContainer}. But if the
* plugin container is initialized, drift detection will have to be scheduled.
*
* @param resourceId
- * @param configurations The drift configurations to add to the local inventory.
+ * @param definitions The drift definitions to add to the local inventory.
*/
- void addToLocalInventory(int resourceId, List<DriftConfiguration>
configurations);
+ void addToLocalInventory(int resourceId, List<DriftDefinition> definitions);
/**
* This is an optional operation as it can only be performed when
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/RuntimeSynchronizer.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/RuntimeSynchronizer.java
index 94cea4c..679db62 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/RuntimeSynchronizer.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/RuntimeSynchronizer.java
@@ -19,6 +19,8 @@
package org.rhq.core.pc.drift.sync;
+import static
org.rhq.core.domain.drift.DriftDefinitionComparator.CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS;
+
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -26,20 +28,18 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfigurationComparator;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.drift.DriftDefinitionComparator;
import org.rhq.core.pc.drift.DriftDetectionSchedule;
import org.rhq.core.pc.drift.DriftManager;
import org.rhq.core.pc.drift.ScheduleQueue;
-import static
org.rhq.core.domain.drift.DriftConfigurationComparator.CompareMode.BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS;
-
/**
- * As its name implies, this class synchronizes drift configurations at runtime. By
runtime
+ * As its name implies, this class synchronizes drift definitions at runtime. By runtime
* we mean when {@link DriftManager} is fully initialized. Updating the local inventory
is
- * done through DriftManager. When this class determines that a drift configuration
needs
+ * done through DriftManager. When this class determines that a drift definition needs
* to be purged from the local inventory, it does so by calling DriftManager to
unschedule
- * drift detection. Likewise when this class determines that a drift configuration needs
+ * drift detection. Likewise when this class determines that a drift definition needs
* to be added to the local inventory, it does so by calling DriftManager to schedule
* detection.
* <br/><br/>
@@ -58,49 +58,47 @@ class RuntimeSynchronizer implements DriftSynchronizer {
}
@Override
- public List<DriftConfiguration> getDeletedConfigurations(int resourceId,
- Set<DriftConfiguration> configurationsFromServer) {
- log.debug("Checking for drift configurations that need to be deleted for
resource id " + resourceId);
- List<DriftConfiguration> deleted = new
LinkedList<DriftConfiguration>();
+ public List<DriftDefinition> getDeletedDefinitions(int resourceId,
Set<DriftDefinition> definitionsFromServer) {
+ log.debug("Checking for drift definitions that need to be deleted for
resource id " + resourceId);
+ List<DriftDefinition> deleted = new LinkedList<DriftDefinition>();
ScheduleQueue queue = driftMgr.getSchedulesQueue();
for (DriftDetectionSchedule schedule : getSchedulesForResource(resourceId,
queue.toArray())) {
- if (!configurationsFromServer.contains(schedule.getDriftConfiguration())) {
+ if (!definitionsFromServer.contains(schedule.getDriftDefinition())) {
if (log.isDebugEnabled()) {
- log.debug("Detected stale drift configuration that needs to be
purged - " +
- toString(resourceId, schedule.getDriftConfiguration()));
+ log.debug("Detected stale drift definition that needs to be
purged - "
+ + toString(resourceId, schedule.getDriftDefinition()));
}
- deleted.add(schedule.getDriftConfiguration());
+ deleted.add(schedule.getDriftDefinition());
}
}
return deleted;
}
@Override
- public void purgeFromLocalInventory(int resourceId, List<DriftConfiguration>
configurations) {
- log.debug("Preparing to unschedule drift detection and purge from local
inventory drift configurations " +
- "that have been deleted on the server for resource id " +
resourceId);
+ public void purgeFromLocalInventory(int resourceId, List<DriftDefinition>
definitions) {
+ log.debug("Preparing to unschedule drift detection and purge from local
inventory drift definitions "
+ + "that have been deleted on the server for resource id " +
resourceId);
- for (DriftConfiguration c : configurations) {
+ for (DriftDefinition c : definitions) {
driftMgr.unscheduleDriftDetection(resourceId, c);
}
}
@Override
- public List<DriftConfiguration> getAddedConfigurations(int resourceId,
- Set<DriftConfiguration> configurationsFromServer) {
- log.debug("Checking for drift configurations that need to be added for
resource id " + resourceId);
+ public List<DriftDefinition> getAddedDefinitions(int resourceId,
Set<DriftDefinition> definitionsFromServer) {
+ log.debug("Checking for drift definitions that need to be added for resource
id " + resourceId);
ScheduleQueue queue = driftMgr.getSchedulesQueue();
- DriftConfigurationComparator comparator = new DriftConfigurationComparator(
+ DriftDefinitionComparator comparator = new DriftDefinitionComparator(
BOTH_BASE_INFO_AND_DIRECTORY_SPECIFICATIONS);
- List<DriftConfiguration> added = new
LinkedList<DriftConfiguration>();
+ List<DriftDefinition> added = new LinkedList<DriftDefinition>();
- for (DriftConfiguration c : configurationsFromServer) {
+ for (DriftDefinition c : definitionsFromServer) {
if (!queue.contains(resourceId, c, comparator)) {
if (log.isDebugEnabled()) {
- log.debug("Detected new drift configuration that needs to be
added to local inventory - " +
- toString(resourceId, c));
+ log.debug("Detected new drift definition that needs to be added
to local inventory - "
+ + toString(resourceId, c));
}
added.add(c);
}
@@ -109,11 +107,11 @@ class RuntimeSynchronizer implements DriftSynchronizer {
}
@Override
- public void addToLocalInventory(int resourceId, List<DriftConfiguration>
configurations) {
- log.debug("Adding drift configurations to local inventory and creating drift
detection schedules for " +
- "resource id " + resourceId);
+ public void addToLocalInventory(int resourceId, List<DriftDefinition>
definitions) {
+ log.debug("Adding drift definitions to local inventory and creating drift
detection schedules for "
+ + "resource id " + resourceId);
- for (DriftConfiguration c : configurations) {
+ for (DriftDefinition c : definitions) {
if (log.isDebugEnabled()) {
log.debug("Adding " + toString(resourceId, c) + " to local
inventory");
}
@@ -126,8 +124,8 @@ class RuntimeSynchronizer implements DriftSynchronizer {
driftMgr.scanForContentToResend();
}
- private String toString(int rid, DriftConfiguration c) {
- return "DriftConfiguration[id: " + c.getId() + ", name: " +
c.getName() + ", resourceId: " + rid + "]";
+ private String toString(int rid, DriftDefinition c) {
+ return "DriftDefinition[id: " + c.getId() + ", name: " +
c.getName() + ", resourceId: " + rid + "]";
}
private List<DriftDetectionSchedule> getSchedulesForResource(int resourceId,
DriftDetectionSchedule[] schedules) {
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/StartupSynchronizer.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/StartupSynchronizer.java
index 0e8ed59..42221a9 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/StartupSynchronizer.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/drift/sync/StartupSynchronizer.java
@@ -19,6 +19,8 @@
package org.rhq.core.pc.drift.sync;
+import static org.rhq.core.util.file.FileUtil.purge;
+
import java.io.File;
import java.util.LinkedList;
import java.util.List;
@@ -27,20 +29,18 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.pc.inventory.InventoryManager;
import org.rhq.core.pc.inventory.ResourceContainer;
-import static org.rhq.core.util.file.FileUtil.purge;
-
/**
- * As its name implies, this class synchronizes drift configurations at start up or any
+ * As its name implies, this class synchronizes drift definitions at start up or any
* time when the plugin container is not fully initialized. If the plugin container is
not
* fully initialized, then that means {@link org.rhq.core.pc.drift.DriftManager
DriftManager}
* is not available to call into to schedule or unschedule drift detection.
- * StartupSynchronizer therefore deals only with the drift configurations attached to
+ * StartupSynchronizer therefore deals only with the drift definitions attached to
* {@link ResourceContainer} objects. As part of its initialization DriftManager
- * creates or recreates detection schedules from the configurations attached to the
+ * creates or recreates detection schedules from the definitions attached to the
* resource containers.
*/
class StartupSynchronizer implements DriftSynchronizer {
@@ -56,17 +56,15 @@ class StartupSynchronizer implements DriftSynchronizer {
}
@Override
- public List<DriftConfiguration> getDeletedConfigurations(int resourceId,
- Set<DriftConfiguration> configurationsFromServer) {
- log.debug("Checking for drift configurations that need to be deleted for
resource id " + resourceId);
- List<DriftConfiguration> deleted = new
LinkedList<DriftConfiguration>();
+ public List<DriftDefinition> getDeletedDefinitions(int resourceId,
Set<DriftDefinition> definitionsFromServer) {
+ log.debug("Checking for drift definitions that need to be deleted for
resource id " + resourceId);
+ List<DriftDefinition> deleted = new LinkedList<DriftDefinition>();
ResourceContainer container = inventoryMgr.getResourceContainer(resourceId);
- for (DriftConfiguration c : container.getDriftConfigurations()) {
- if (!configurationsFromServer.contains(c)) {
+ for (DriftDefinition c : container.getDriftDefinitions()) {
+ if (!definitionsFromServer.contains(c)) {
if (log.isDebugEnabled()) {
- log.debug("Detected stale drift configuration that needs to be
purged - " +
- toString(resourceId, c));
+ log.debug("Detected stale drift definition that needs to be
purged - " + toString(resourceId, c));
}
deleted.add(c);
}
@@ -76,17 +74,17 @@ class StartupSynchronizer implements DriftSynchronizer {
}
@Override
- public void purgeFromLocalInventory(int resourceId, List<DriftConfiguration>
configurations) {
- log.debug("Preparing to purge from local inventory drift configurations that
have been deleted on the server "
+ public void purgeFromLocalInventory(int resourceId, List<DriftDefinition>
definitions) {
+ log.debug("Preparing to purge from local inventory drift definitions that
have been deleted on the server "
+ "for resource id " + resourceId);
ResourceContainer container = inventoryMgr.getResourceContainer(resourceId);
File resourceSnapshotsDir = new File(snapshotsDir,
Integer.toString(resourceId));
- for (DriftConfiguration c : configurations) {
+ for (DriftDefinition c : definitions) {
if (log.isDebugEnabled()) {
log.debug("Purging " + toString(resourceId, c) + " from
local inventory");
}
- container.removeDriftConfiguration(c);
+ container.removeDriftDefinition(c);
File snapshotDir = new File(resourceSnapshotsDir, c.getName());
if (snapshotDir.exists()) {
if (log.isDebugEnabled()) {
@@ -98,19 +96,17 @@ class StartupSynchronizer implements DriftSynchronizer {
}
@Override
- public List<DriftConfiguration> getAddedConfigurations(int resourceId,
- Set<DriftConfiguration> configurationsFromServer) {
- log.debug("Checking for drift configurations that need to be added for
resource id " + resourceId);
+ public List<DriftDefinition> getAddedDefinitions(int resourceId,
Set<DriftDefinition> definitionsFromServer) {
+ log.debug("Checking for drift definitions that need to be added for resource
id " + resourceId);
ResourceContainer container = inventoryMgr.getResourceContainer(resourceId);
- List<DriftConfiguration> added = new
LinkedList<DriftConfiguration>();
-
+ List<DriftDefinition> added = new LinkedList<DriftDefinition>();
- for (DriftConfiguration c : configurationsFromServer) {
- if (!container.containsDriftConfiguration(c)) {
+ for (DriftDefinition c : definitionsFromServer) {
+ if (!container.containsDriftDefinition(c)) {
if (log.isDebugEnabled()) {
- log.debug("Detected new drift configuration that needs to be
added to local inventory - " +
- toString(resourceId, c));
+ log.debug("Detected new drift definition that needs to be added
to local inventory - "
+ + toString(resourceId, c));
}
added.add(c);
}
@@ -119,15 +115,15 @@ class StartupSynchronizer implements DriftSynchronizer {
}
@Override
- public void addToLocalInventory(int resourceId, List<DriftConfiguration>
configurations) {
- log.debug("Adding drift configurations to local inventory for resource id
" + resourceId);
+ public void addToLocalInventory(int resourceId, List<DriftDefinition>
definitions) {
+ log.debug("Adding drift definitions to local inventory for resource id
" + resourceId);
ResourceContainer container = inventoryMgr.getResourceContainer(resourceId);
- for (DriftConfiguration c : configurations) {
+ for (DriftDefinition c : definitions) {
if (log.isDebugEnabled()) {
log.debug("Adding " + toString(resourceId, c) + " to local
inventory");
}
- container.addDriftConfiguration(c);
+ container.addDriftDefinition(c);
}
}
@@ -135,7 +131,7 @@ class StartupSynchronizer implements DriftSynchronizer {
public void syncChangeSetContent() {
}
- private String toString(int rid, DriftConfiguration c) {
- return "DriftConfiguration[id: " + c.getId() + ", name: " +
c.getName() + ", resourceId: " + rid + "]";
+ private String toString(int rid, DriftDefinition c) {
+ return "DriftDefinition[id: " + c.getId() + ", name: " +
c.getName() + ", resourceId: " + rid + "]";
}
}
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
index bfdb2a3..a8927a5 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/InventoryManager.java
@@ -243,19 +243,16 @@ public class InventoryManager extends AgentService implements
ContainerService,
// inside EmbJopr).
if (configuration.isInsideAgent()) {
// After an initial delay (5s by default), periodically run an
availability check (every 1m by default).
-
availabilityThreadPoolExecutor.scheduleWithFixedDelay(availabilityExecutor,
- configuration.getAvailabilityScanInitialDelay(),
configuration.getAvailabilityScanPeriod(),
- TimeUnit.SECONDS);
+
availabilityThreadPoolExecutor.scheduleWithFixedDelay(availabilityExecutor, configuration
+ .getAvailabilityScanInitialDelay(),
configuration.getAvailabilityScanPeriod(), TimeUnit.SECONDS);
// After an initial delay (10s by default), periodically run a server
discovery scan (every 15m by default).
- inventoryThreadPoolExecutor.scheduleWithFixedDelay(serverScanExecutor,
- configuration.getServerDiscoveryInitialDelay(),
configuration.getServerDiscoveryPeriod(),
- TimeUnit.SECONDS);
+ inventoryThreadPoolExecutor.scheduleWithFixedDelay(serverScanExecutor,
configuration
+ .getServerDiscoveryInitialDelay(),
configuration.getServerDiscoveryPeriod(), TimeUnit.SECONDS);
// After an initial delay (20s by default), periodically run a service
discovery scan (every 1d by default).
- inventoryThreadPoolExecutor.scheduleWithFixedDelay(serviceScanExecutor,
- configuration.getServiceDiscoveryInitialDelay(),
configuration.getServiceDiscoveryPeriod(),
- TimeUnit.SECONDS);
+ inventoryThreadPoolExecutor.scheduleWithFixedDelay(serviceScanExecutor,
configuration
+ .getServiceDiscoveryInitialDelay(),
configuration.getServiceDiscoveryPeriod(), TimeUnit.SECONDS);
}
} finally {
inventoryLock.writeLock().unlock();
@@ -312,8 +309,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
long timeout = getDiscoveryComponentTimeout(context.getResourceType());
try {
- ResourceDiscoveryComponent proxy =
this.discoveryComponentProxyFactory.getDiscoveryComponentProxy(
- context.getResourceType(), component, timeout, parentResourceContainer);
+ ResourceDiscoveryComponent proxy =
this.discoveryComponentProxyFactory.getDiscoveryComponentProxy(context
+ .getResourceType(), component, timeout, parentResourceContainer);
Set<DiscoveredResourceDetails> results =
proxy.discoverResources(context);
return results;
} catch (TimeoutException te) {
@@ -348,8 +345,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
long timeout = getDiscoveryComponentTimeout(context.getResourceType());
try {
- ManualAddFacet proxy =
this.discoveryComponentProxyFactory.getDiscoveryComponentProxy(
- context.getResourceType(), component, timeout, ManualAddFacet.class,
parentResourceContainer);
+ ManualAddFacet proxy =
this.discoveryComponentProxyFactory.getDiscoveryComponentProxy(context
+ .getResourceType(), component, timeout, ManualAddFacet.class,
parentResourceContainer);
DiscoveredResourceDetails result = proxy.discoverResource(pluginConfig,
context);
return result;
} catch (TimeoutException te) {
@@ -388,8 +385,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
component, timeout, ClassLoaderFacet.class, parentContainer);
ResourceDiscoveryContext discoveryContext = new
ResourceDiscoveryContext(resourceType, parentComponent,
- parentResourceContext, SystemInfoFactory.createSystemInfo(), null, null,
- this.configuration.getContainerName(),
this.configuration.getPluginContainerDeployment());
+ parentResourceContext, SystemInfoFactory.createSystemInfo(), null, null,
this.configuration
+ .getContainerName(), this.configuration.getPluginContainerDeployment());
// Configurations are not immutable, so clone the plugin config, so the plugin
will not be able to change the
// actual PC-managed plugin config.
@@ -677,8 +674,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
ResourceDiscoveryContext<ResourceComponent<?>>
discoveryContext = new ResourceDiscoveryContext<ResourceComponent<?>>(
resourceType, parentResourceComponent,
parentResourceContainer.getResourceContext(),
SystemInfoFactory.createSystemInfo(), new
ArrayList<ProcessScanResult>(0),
- new ArrayList<Configuration>(0),
this.configuration.getContainerName(),
- this.configuration.getPluginContainerDeployment());
+ new ArrayList<Configuration>(0),
this.configuration.getContainerName(), this.configuration
+ .getPluginContainerDeployment());
// Ask the plugin's discovery component to find the new resource,
throwing exceptions if it cannot be
// found at all.
@@ -880,7 +877,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
if ((this.platform != null) && (this.platform.getInventoryStatus() ==
InventoryStatus.NEW)
&& newPlatformWasDeletedRecently) {
// let's make sure we are registered; its probable that our platform
was deleted and we need to re-register
- log.info("No committed resources to send in our availability report
- the platform/agent was deleted, let's re-register again");
+ log
+ .info("No committed resources to send in our availability report
- the platform/agent was deleted, let's re-register again");
registerWithServer();
newPlatformWasDeletedRecently = false; // we've tried to recover from
our platform being deleted, let's not do it again
}
@@ -923,8 +921,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
log.debug("Availability report content: " +
report.toString(log.isTraceEnabled()));
}
- boolean ok =
configuration.getServerServices().getDiscoveryServerService()
- .mergeAvailabilityReport(report);
+ boolean ok =
configuration.getServerServices().getDiscoveryServerService().mergeAvailabilityReport(
+ report);
if (!ok) {
// I guess I could immediately call
executeAvailabilityScanImmediately and pass its results to
// mergeAvailabilityReport again right now, but what happens if
we've queued up a bunch of
@@ -970,9 +968,10 @@ public class InventoryManager extends AgentService implements
ContainerService,
(System.currentTimeMillis() - startTime)));
}
} catch (StaleTypeException e) {
- log.error("Failed to merge inventory report with server. The report
contains one or more resource types "
- + "that have been marked for deletion. Notifying the plugin
container that a reboot is needed to purge "
- + "stale types.");
+ log
+ .error("Failed to merge inventory report with server. The report
contains one or more resource types "
+ + "that have been marked for deletion. Notifying the plugin
container that a reboot is needed to purge "
+ + "stale types.");
PluginContainer.getInstance().notifyRebootRequestListener();
return false;
} catch (InvalidInventoryReportException e) {
@@ -980,7 +979,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
if ((this.platform != null) && (this.platform.getInventoryStatus() ==
InventoryStatus.NEW)
&& newPlatformWasDeletedRecently) {
// let's make sure we are registered; its probable that our platform
was deleted and we need to re-register
- log.info("The inventory report was invalid probably because the
platform/Agent was deleted; let's re-register...");
+ log
+ .info("The inventory report was invalid probably because the
platform/Agent was deleted; let's re-register...");
registerWithServer();
newPlatformWasDeletedRecently = false; // we've tried to recover from
our platform being deleted, let's not do it again
}
@@ -1176,8 +1176,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
parent.removeChildResource(resource);
}
- PluginContainer.getInstance().getMeasurementManager()
- .unscheduleCollection(Collections.singleton(resource.getId()));
+ PluginContainer.getInstance().getMeasurementManager().unscheduleCollection(
+ Collections.singleton(resource.getId()));
if (this.resourceContainers.remove(resource.getUuid()) == null) {
if (log.isDebugEnabled()) {
@@ -1283,8 +1283,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
logMessage.append("description, ");
}
- logMessage.replace(logMessage.length() - 1, logMessage.length(),
"to become [")
- .append(existingResource.toString()).append("]");
+ logMessage.replace(logMessage.length() - 1, logMessage.length(),
"to become [").append(
+ existingResource.toString()).append("]");
log.info(logMessage.toString());
} else {
@@ -1520,8 +1520,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
log.warn("Cannot give activated resource its discovery component.
Cause: " + e);
}
-
ConfigurationUtility.normalizeConfiguration(resource.getPluginConfiguration(),
- type.getPluginConfigurationDefinition());
+
ConfigurationUtility.normalizeConfiguration(resource.getPluginConfiguration(), type
+ .getPluginConfigurationDefinition());
ResourceComponent<?> parentComponent = null;
if (resource.getParentResource() != null) {
@@ -1659,8 +1659,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
resource.setConnected(false); // invalid plugin configuration infers the resource
component is disconnected
// Give the server-side an error message describing the connection failure that
can be
// displayed on the resource's Inventory page.
- ResourceError resourceError = new ResourceError(resource,
ResourceErrorType.INVALID_PLUGIN_CONFIGURATION,
- t.getLocalizedMessage(), ThrowableUtil.getStackAsString(t),
System.currentTimeMillis());
+ ResourceError resourceError = new ResourceError(resource,
ResourceErrorType.INVALID_PLUGIN_CONFIGURATION, t
+ .getLocalizedMessage(), ThrowableUtil.getStackAsString(t),
System.currentTimeMillis());
return sendResourceErrorToServer(resourceError);
}
@@ -1919,7 +1919,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
}
} else {
// This is very strange - there are no platform types - we should never be
missing the built-in platform plugin.
- log.error("Missing platform plugin(s) - falling back to dummy platform
impl; this should only occur in tests!");
+ log
+ .error("Missing platform plugin(s) - falling back to dummy platform
impl; this should only occur in tests!");
// TODO: Set sysprop (e.g. rhq.test.mode=true) in integration tests,
// and throw a runtime exception here if that sysprop is not set.
return getTestPlatform();
@@ -2042,7 +2043,7 @@ public class InventoryManager extends AgentService implements
ContainerService,
private boolean supportsDriftManagement(Resource r) {
PluginMetadataManager metaDataMgr =
PluginContainer.getInstance().getPluginManager().getMetadataManager();
ResourceType type = metaDataMgr.getType(r.getResourceType());
- return type.getDriftConfigurationTemplates() != null &&
!type.getDriftConfigurationTemplates().isEmpty();
+ return type.getDriftDefinitionTemplates() != null &&
!type.getDriftDefinitionTemplates().isEmpty();
}
private void syncSchedules(Set<Resource> resources) {
@@ -2304,8 +2305,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
try {
ResourceDiscoveryContext context = new ResourceDiscoveryContext(resourceType,
parentComponent,
parentResourceContext, SystemInfoFactory.createSystemInfo(),
processScanResults,
- Collections.EMPTY_LIST, this.configuration.getContainerName(),
- this.configuration.getPluginContainerDeployment());
+ Collections.EMPTY_LIST, this.configuration.getContainerName(),
this.configuration
+ .getPluginContainerDeployment());
newResources = new HashSet<Resource>();
try {
Set<DiscoveredResourceDetails> discoveredResources =
invokeDiscoveryComponent(parentContainer,
@@ -2541,8 +2542,8 @@ public class InventoryManager extends AgentService implements
ContainerService,
if (log.isDebugEnabled()) {
log.debug("Merging [" + modifiedResourceIds.size() + "]
modified Resources into local inventory...");
}
- Set<Resource> modifiedResources =
configuration.getServerServices().getDiscoveryServerService()
- .getResources(modifiedResourceIds, false);
+ Set<Resource> modifiedResources =
configuration.getServerServices().getDiscoveryServerService().getResources(
+ modifiedResourceIds, false);
syncSchedules(modifiedResources); // RHQ-792, mtime is the indicator that
schedules should be sync'ed too
syncDriftConfigurations(modifiedResources);
for (Resource modifiedResource : modifiedResources) {
@@ -2791,9 +2792,10 @@ public class InventoryManager extends AgentService implements
ContainerService,
log.info("Resource activation and upgrade finished.");
} catch (Throwable t) {
- log.error(
- "Resource activation or upgrade failed with an exception. An attempt
to merely activate the resources will be made now.",
- t);
+ log
+ .error(
+ "Resource activation or upgrade failed with an exception. An
attempt to merely activate the resources will be made now.",
+ t);
//make sure to at least activate the resources
activateAndUpgradeResourceRecursively(getPlatform(), false);
diff --git
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
index 791857b..854e624 100644
---
a/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
+++
b/modules/core/plugin-container/src/main/java/org/rhq/core/pc/inventory/ResourceContainer.java
@@ -49,7 +49,7 @@ import org.jetbrains.annotations.Nullable;
import org.rhq.core.clientapi.agent.PluginContainerException;
import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.measurement.Availability;
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
@@ -67,6 +67,7 @@ import org.rhq.core.pluginapi.inventory.ResourceContext;
* @author John Mazzitelli
* @author Ian Springer
*/
+@SuppressWarnings("unchecked")
public class ResourceContainer implements Serializable {
private static final long serialVersionUID = 1L;
@@ -90,7 +91,7 @@ public class ResourceContainer implements Serializable {
private SynchronizationState synchronizationState = SynchronizationState.NEW;
private Set<MeasurementScheduleRequest> measurementSchedule = new
HashSet<MeasurementScheduleRequest>();
private Set<ResourcePackageDetails> installedPackages = new
HashSet<ResourcePackageDetails>();
- private Map<String, DriftConfiguration> driftConfigurations = new
HashMap<String, DriftConfiguration>();
+ private Map<String, DriftDefinition> driftDefinitions = new HashMap<String,
DriftDefinition>();
// transient fields
private transient ResourceComponent resourceComponent;
@@ -245,27 +246,27 @@ public class ResourceContainer implements Serializable {
}
}
- public Collection<DriftConfiguration> getDriftConfigurations() {
+ public Collection<DriftDefinition> getDriftDefinitions() {
synchronized (this) {
- return driftConfigurations.values();
+ return driftDefinitions.values();
}
}
- public boolean containsDriftConfiguration(DriftConfiguration c) {
+ public boolean containsDriftDefinition(DriftDefinition d) {
synchronized (this) {
- return driftConfigurations.containsKey(c.getName());
+ return driftDefinitions.containsKey(d.getName());
}
}
- public void addDriftConfiguration(DriftConfiguration c) {
+ public void addDriftDefinition(DriftDefinition d) {
synchronized (this) {
- driftConfigurations.put(c.getName(), c);
+ driftDefinitions.put(d.getName(), d);
}
}
- public void removeDriftConfiguration(DriftConfiguration c) {
+ public void removeDriftDefinition(DriftDefinition d) {
synchronized (this) {
- driftConfigurations.remove(c.getName());
+ driftDefinitions.remove(d.getName());
}
}
@@ -330,7 +331,6 @@ public class ResourceContainer implements Serializable {
*
* @throws PluginContainerException if the component does not exist or does not
implement the interface
*/
- @SuppressWarnings("unchecked")
public <T> T createResourceComponentProxy(Class<T> facetInterface,
FacetLockType lockType, long timeout,
boolean daemonThread, boolean onlyIfStarted) throws PluginContainerException {
if (onlyIfStarted) {
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 88cda7f..05d9ccc 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
@@ -94,8 +94,8 @@ public class ChangeSetManagerImplTest extends DriftTest {
Headers createHeaders(String driftConfigName, DriftChangeSetCategory type) {
Headers headers = new Headers();
headers.setResourceId(resourceId());
- headers.setDriftCofigurationId(1);
- headers.setDriftConfigurationName(driftConfigName);
+ headers.setDriftDefinitionId(1);
+ headers.setDriftDefinitionName(driftConfigName);
headers.setBasedir(resourceDir.getPath());
headers.setType(type);
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 a5581ca..99c7101 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,19 +2,17 @@ package org.rhq.core.pc.drift;
import java.io.File;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftChangeSetCategory;
+import org.rhq.core.domain.drift.DriftDefinition;
class DriftClientTestStub implements DriftClient {
private File basedir;
- private boolean failingOnSendChangeSet;
-
@Override
- public void sendChangeSetToServer(DriftDetectionSummary detectionSummary) {
- if (failingOnSendChangeSet) {
- throw new RuntimeException("Failed to send change set to server");
- }
+ public void sendChangeSetToServer(int resourceId, DriftDefinition
driftConfiguration,
+ DriftChangeSetCategory type) {
+
}
@Override
@@ -22,19 +20,11 @@ class DriftClientTestStub implements DriftClient {
}
@Override
- public File getAbsoluteBaseDirectory(int resourceId, DriftConfiguration
driftConfiguration) {
+ public File getAbsoluteBaseDirectory(int resourceId, DriftDefinition
driftConfiguration) {
return basedir;
}
public void setBaseDir(File basedir) {
this.basedir = basedir;
}
-
- public boolean isFailingOnSendChangeSet() {
- return failingOnSendChangeSet;
- }
-
- public void setFailingOnSendChangeSet(boolean failing) {
- failingOnSendChangeSet = failing;
- }
}
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 4811044..0a3b10c 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
@@ -34,7 +34,7 @@ import org.rhq.common.drift.ChangeSetWriter;
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.domain.drift.DriftDefinition;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
@@ -80,7 +80,7 @@ public class DriftDetectorTest extends DriftTest {
// create an empty directory
File libDir = mkdir(resourceDir, "lib");
- DriftConfiguration driftConfig = driftConfiguration("coverage-test",
resourceDir.getAbsolutePath());
+ DriftDefinition driftConfig = driftConfiguration("coverage-test",
resourceDir.getAbsolutePath());
scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(),
driftConfig));
detector.run();
@@ -100,7 +100,7 @@ public class DriftDetectorTest extends DriftTest {
File server1Conf = createRandomFile(confDir, "server-1.conf");
File server2Conf = createRandomFile(confDir, "server-2.conf");
- DriftConfiguration config = driftConfiguration("multiple-files-test",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("multiple-files-test",
resourceDir.getAbsolutePath());
scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
detector.run();
@@ -124,7 +124,7 @@ public class DriftDetectorTest extends DriftTest {
File libDir = mkdir(resourceDir, "lib");
File serverLib = createRandomFile(libDir, "server.jar");
- DriftConfiguration config = driftConfiguration("sibling-dirs-test",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("sibling-dirs-test",
resourceDir.getAbsolutePath());
scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
detector.run();
@@ -148,7 +148,7 @@ public class DriftDetectorTest extends DriftTest {
File subConfDir = mkdir(confDir, "subconf");
File server2Conf = createRandomFile(subConfDir, "server-2.conf");
- DriftConfiguration config = driftConfiguration("nested-dirs-test",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("nested-dirs-test",
resourceDir.getAbsolutePath());
scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
detector.run();
@@ -169,7 +169,7 @@ public class DriftDetectorTest extends DriftTest {
File confDir = mkdir(resourceDir, "conf");
File serverConf = createRandomFile(confDir, "server.conf");
- DriftConfiguration config = driftConfiguration("nothing-to-update",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("nothing-to-update",
resourceDir.getAbsolutePath());
scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
detector.run();
@@ -177,19 +177,13 @@ public class DriftDetectorTest extends DriftTest {
File changeSet = changeSet(config.getName(), COVERAGE);
String originalHash = sha256(changeSet);
- // Reset the schedule so that detection will run again the next time we call
- // detection.run()
- DriftDetectionSchedule schedule = scheduleQueue.remove(resourceId(), config);
- schedule.resetSchedule();
- scheduleQueue.addSchedule(schedule);
-
// Run the detector again. Note that nothing has changed so the snapshot should
// remain the same and no drift change set file should be generated.
detector.run();
String newHash = sha256(changeSet);
- assertEquals(newHash, originalHash, "The snapshot file should not have
changed since there was no drift. ");
+ assertEquals(newHash, originalHash, "The snapshot file should not have
changed since there was no drift.");
File driftChangeSet = changeSet(config.getName(), DRIFT);
@@ -199,19 +193,20 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
- public void skipDetectionForScheduledThatIsDisabled() throws Exception {
+ public void skipScheduledThatHasConfigDisabled() throws Exception {
detector.setDriftClient(new DriftClientTestStub() {
{
setBaseDir(resourceDir);
}
@Override
- public void sendChangeSetToServer(DriftDetectionSummary detectionSummary) {
+ public void sendChangeSetToServer(int resourceId, DriftDefinition
driftConfiguration,
+ DriftChangeSetCategory type) {
throw new RuntimeException("Should not invoke drift client when
drift configuration is disabled");
}
});
- DriftConfiguration config = driftConfiguration("disabled-config-test",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("disabled-config-test",
resourceDir.getAbsolutePath());
config.setEnabled(false);
File confDir = mkdir(resourceDir, "conf");
@@ -224,47 +219,8 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
- public void skipDetectionWhenPreviousSnapshotFileExists() throws Exception {
- // The presence of a previous snapshot file means that the server has
- // not acknowledged that it has received and processed the change set.
- DriftConfiguration config =
driftConfiguration("previous-snapshot-test", resourceDir.getAbsolutePath());
-
- File confDir = mkdir(resourceDir, "conf");
- createRandomFile(confDir, "server.conf");
-
- DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(),
config);
- scheduleQueue.addSchedule(schedule);
- detector.run();
-
- // create some drift and generate a new snapshot
- createRandomFile(confDir, "server-1.conf");
- schedule.resetSchedule();
- detector.run();
-
- File snapshot = changeSet(config.getName(), COVERAGE);
- String newHash = sha256(snapshot);
- File previousSnapshot = previousChangeSet(config.getName());
- String oldHash = sha256(previousSnapshot);
-
- // create some drift and make sure drift detection does not run.
- createRandomFile(confDir, "server-2.conf");
- schedule.resetSchedule();
- // Tell driftClient to throw an exception if detector attempts to send
- // the change set report to the server. The detector should never call
- // driftClient in this scenario.
- driftClient.setFailingOnSendChangeSet(true);
- detector.run();
-
- assertEquals(sha256(snapshot), newHash, "The snapshot should not have
changed since the previous snapshot " +
- "is still on disk.");
- assertEquals(sha256(previousSnapshot), oldHash, "The previous snapshot
should not have changed since " +
- "drift detection should not have run until the server acked the previous
snapshot.");
- }
-
- @SuppressWarnings("unchecked")
- @Test
public void includeAddedFileInDriftChangeSet() throws Exception {
- DriftConfiguration config = driftConfiguration("file-added-drift-test",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("file-added-drift-test",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
@@ -301,7 +257,7 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
public void includeModifiedFileInDriftChangeSet() throws Exception {
- DriftConfiguration config =
driftConfiguration("file-modified-drift-test", resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("file-modified-drift-test",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
@@ -339,7 +295,7 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test(enabled = false)
public void includeFiledAddedInNewDirectoryInDriftChangeSet() throws Exception {
- DriftConfiguration config = driftConfiguration("file-added-in-new-dir",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("file-added-in-new-dir",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
@@ -377,7 +333,7 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
public void includeRemovedFileInDriftChangeSet() throws Exception {
- DriftConfiguration config =
driftConfiguration("file-removed-drift-test", resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("file-removed-drift-test",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
@@ -416,7 +372,7 @@ public class DriftDetectorTest extends DriftTest {
@SuppressWarnings("unchecked")
@Test
public void includeFilesInRemovedDirectoryInDriftChangeSet() throws Exception {
- DriftConfiguration config = driftConfiguration("dir-removed-test",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("dir-removed-test",
resourceDir.getAbsolutePath());
File confDir = mkdir(resourceDir, "conf");
File server1Conf = createRandomFile(confDir, "server-1.conf");
@@ -450,169 +406,6 @@ public class DriftDetectorTest extends DriftTest {
coverageChangeSet);
}
- @SuppressWarnings("unchecked")
- @Test
- public void revertToPreviousSnapshotWhenSendingChangeSetFails() throws Exception {
- DriftConfiguration config = driftConfiguration("revert-snapshot-test",
resourceDir.getAbsolutePath());
- DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(),
config);
-
- File confDir = mkdir(resourceDir, "conf");
- File server1Conf = createRandomFile(confDir, "server.conf");
-
- scheduleQueue.addSchedule(schedule);
- // generate the initial snapshot
- detector.run();
-
- // Now generate a drift change set
- createRandomFile(confDir, "server-1.conf");
- schedule.resetSchedule();
- detector.run();
-
- File changeSet = changeSet(config.getName(), COVERAGE);
- String currentHash = sha256(changeSet);
-
- // Need to delete the previous version snapshot file; otherwise, the
- // next detection run will be skipped.
- previousChangeSet(config.getName()).delete();
-
- // generate some more drift, and fail on sending the change set
- // to the server
- createRandomFile(confDir, "server-2.conf");
- schedule.resetSchedule();
- driftClient.setFailingOnSendChangeSet(true);
- try {
- detector.run();
- } catch (RuntimeException e) {}
-
- String newHash = sha256(changeSet);
-
- assertEquals(newHash, currentHash, "The snapshot file should be reverted if
sending the new snapshot " +
- "to the server fails.");
- // The previous version file must be deleted on revert; otherwise, drift
- // detection will not run for the schedule if the previous version file
- // is found on disk.
- assertFalse(previousChangeSet(config.getName()).exists(), "The copy of the
previous version snapshot file " +
- "should be deleted once we have reverted back to it and have a new,
current snapsot file.");
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void purgeSnapshotWhenSendingInitialChangeSetFails() throws Exception {
- // If we have just generated the initial change set and sending it to
- // the server fails, then there is no prior snapshot version to which
- // we can revert. We therefore need to purge the snapshot file and
- // allow DriftDetector to simply regenerate the initial change set again.
-
- DriftConfiguration config = driftConfiguration("purge-snapshot-test",
resourceDir.getAbsolutePath());
-
- File confDir = mkdir(resourceDir, "conf");
- createRandomFile(confDir, "server.conf");
-
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
- driftClient.setFailingOnSendChangeSet(true);
- try {
- detector.run();
- } catch (RuntimeException e) {}
-
- assertFalse(changeSet(config.getName(), COVERAGE).exists(), "Snapshot file
should be deleted when " +
- "only the initial change set has been generated and sending change send
report to server fails");
- }
-
- @Test
- public void ignoreFilesThatAreNotReadableForCoverageChangeSet() throws Exception {
- DriftConfiguration config =
driftConfiguration("nonreadable-files-coverage",
resourcesDir.getAbsolutePath());
-
- File confDir = mkdir(resourceDir, "conf");
- File server1Conf = createRandomFile(confDir, "server-1.conf");
- File server2Conf = createRandomFile(confDir, "server-2.conf");
- assertTrue(server2Conf.setReadable(false), "Failed to make " +
server2Conf.getPath() + " write only");
-
- scheduleQueue.addSchedule(new DriftDetectionSchedule(resourceId(), config));
- detector.run();
-
- File changeSet = changeSet(config.getName(), COVERAGE);
- List<FileEntry> entries =
asList(addedFileEntry("conf/server-1.conf", sha256(server1Conf)));
-
- assertHeaderEquals(changeSet, createHeaders(config, COVERAGE));
- assertFileEntriesMatch("Files that are non-readable should be skipped but
other, readable file should still " +
- "be included in the change set", entries, changeSet);
- }
-
- @Test
- public void ignoreNewFilesThatAreNotReadableForDriftChangeSet() throws Exception {
- DriftConfiguration config =
driftConfiguration("nonreadable-files-drfit", resourceDir.getAbsolutePath());
- DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(),
config);
-
- File confDir = mkdir(resourceDir, "conf");
- File server1Conf = createRandomFile(confDir, "server-1.conf");
- String oldServer1Hash = sha256(server1Conf);
-
- scheduleQueue.addSchedule(schedule);
- detector.run();
-
- // create some drift that includes a new file that is not readable
- server1Conf.delete();
- server1Conf = createRandomFile(confDir, "server-1.conf");
- String newServer1Hash = sha256(server1Conf);
-
- File server2Conf = createRandomFile(confDir, "server-2.conf");
- assertTrue(server2Conf.setReadable(false), "Failed to make " +
server2Conf.getPath() + " write only");
-
- schedule.resetSchedule();
- detector.run();
-
- File driftChangeSet = changeSet(config.getName(), DRIFT);
- List<FileEntry> driftEntries =
asList(changedFileEntry("conf/server-1.conf", oldServer1Hash,
newServer1Hash));
-
- // verify that the drift change set was generated
- assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
- assertHeaderEquals(driftChangeSet, createHeaders(config, DRIFT, 1));
- assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
-
- // verify that the coverage change set was updated
- File coverageChangeSet = changeSet(config.getName(), COVERAGE);
- List<FileEntry> coverageEntries =
asList(changedFileEntry("conf/server-1.conf", oldServer1Hash,
newServer1Hash));
-
- assertHeaderEquals(coverageChangeSet, createHeaders(config, COVERAGE, 1));
- assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
- coverageChangeSet);
- }
-
- @Test
- public void markFileUnderDriftDetectionAsRemovedWhenItIsMadeNonReadable() throws
Exception {
- DriftConfiguration config = driftConfiguration("file-made-nonreadable",
resourceDir.getAbsolutePath());
- DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(),
config);
-
- File confDir = mkdir(resourceDir, "conf");
- File server1Conf = createRandomFile(confDir, "server-1.conf");
- String server1Hash = sha256(server1Conf);
-
- scheduleQueue.addSchedule(schedule);
- detector.run();
-
- // make the file non-readable and run the detector again
- assertTrue(server1Conf.setReadable(false), "Failed to make " +
server1Conf.getPath() + " write only");
-
- schedule.resetSchedule();
- detector.run();
-
- File driftChangeSet = changeSet(config.getName(), DRIFT);
- List<FileEntry> driftEntries =
asList(removedFileEntry("conf/server-1.conf", server1Hash));
-
- // verify that the drift change set was generated
- assertTrue(driftChangeSet.exists(), "Expected to find drift change set
" + driftChangeSet.getPath());
- assertHeaderEquals(driftChangeSet, createHeaders(config, DRIFT, 1));
- assertFileEntriesMatch("The drift change set does not match the expected
values", driftEntries, driftChangeSet);
-
- // verify that the coverage change set was updated
- File coverageChangeSet = changeSet(config.getName(), COVERAGE);
- List<FileEntry> coverageEntries = emptyList();
-
- assertHeaderEquals(coverageChangeSet, createHeaders(config, COVERAGE, 1));
- assertFileEntriesMatch("The coverage change set was not updated as
expected", coverageEntries,
- coverageChangeSet);
- }
-
void assertHeaderEquals(File changeSet, Headers expected) throws Exception {
ChangeSetReader reader = new ChangeSetReaderImpl(new BufferedReader(new
FileReader(changeSet)));
Headers actual = reader.getHeaders();
@@ -631,15 +424,15 @@ public class DriftDetectorTest extends DriftTest {
assertCollectionMatchesNoOrder(msg, expected, actual);
}
- Headers createHeaders(DriftConfiguration driftConfig, DriftChangeSetCategory type) {
+ Headers createHeaders(DriftDefinition driftConfig, DriftChangeSetCategory type) {
return createHeaders(driftConfig, type, 0);
}
- Headers createHeaders(DriftConfiguration driftConfig, DriftChangeSetCategory type,
int version) {
+ Headers createHeaders(DriftDefinition driftConfig, DriftChangeSetCategory type, int
version) {
Headers headers = new Headers();
headers.setResourceId(resourceId());
- headers.setDriftCofigurationId(driftConfig.getId());
- headers.setDriftConfigurationName(driftConfig.getName());
+ headers.setDriftDefinitionId(driftConfig.getId());
+ headers.setDriftDefinitionName(driftConfig.getName());
headers.setBasedir(resourceDir.getAbsolutePath());
headers.setType(type);
headers.setVersion(version);
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 bace111..a70ab8c 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
@@ -179,8 +179,8 @@ public class DriftFilesSenderTest extends DriftTest {
Headers createHeaders(String configName, DriftChangeSetCategory type) {
Headers headers = new Headers();
headers.setResourceId(resourceId());
- headers.setDriftCofigurationId(0);
- headers.setDriftConfigurationName(configName);
+ headers.setDriftDefinitionId(0);
+ headers.setDriftDefinitionName(configName);
headers.setBasedir(resourceDir.getAbsolutePath());
headers.setType(type);
diff --git
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
index ae3a940..696561a 100644
---
a/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
+++
b/modules/core/plugin-container/src/test/java/org/rhq/core/pc/drift/DriftManagerTest.java
@@ -32,7 +32,7 @@ import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.rhq.core.clientapi.server.drift.DriftServerService;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.pc.PluginContainerConfiguration;
@@ -75,12 +75,11 @@ public class DriftManagerTest extends DriftTest {
driftMgr = new TestDriftManager();
driftMgr.setConfiguration(pcConfig);
- driftMgr.setChangeSetMgr(changeSetMgr);
}
@Test
public void writeChangeSetZipFileToChangeSetDirectory() throws Exception {
- final DriftConfiguration config =
driftConfiguration("write-changeset-file", resourceDir.getAbsolutePath());
+ final DriftDefinition config =
driftConfiguration("write-changeset-file", resourceDir.getAbsolutePath());
final File changeSetDir = changeSetDir(config.getName());
createRandomFile(changeSetDir, "changeset.txt");
@@ -94,19 +93,14 @@ public class DriftManagerTest extends DriftTest {
}
});
- DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(),
config);
- DriftDetectionSummary detectionSummary = new DriftDetectionSummary();
- detectionSummary.setSchedule(schedule);
- detectionSummary.setType(COVERAGE);
-
driftMgr.setChangeSetMgr(changeSetMgr);
- driftMgr.getSchedulesQueue().addSchedule(schedule);
- driftMgr.sendChangeSetToServer(detectionSummary);
+ driftMgr.getSchedulesQueue().addSchedule(new DriftDetectionSchedule(resourceId(),
config));
+ driftMgr.sendChangeSetToServer(resourceId(), config, COVERAGE);
}
@Test
public void sendChangeSetReportInZipFile() throws Exception {
- final DriftConfiguration config =
driftConfiguration("send-changeset-in-zip", resourceDir.getAbsolutePath());
+ final DriftDefinition config =
driftConfiguration("send-changeset-in-zip", resourceDir.getAbsolutePath());
final File changeSetDir = changeSetDir(config.getName());
final File changeSetFile = createRandomFile(changeSetDir,
"changeset.txt");
@@ -117,32 +111,32 @@ public class DriftManagerTest extends DriftTest {
}
});
- DriftDetectionSchedule schedule = new DriftDetectionSchedule(resourceId(),
config);
- DriftDetectionSummary detectionSummary = new DriftDetectionSummary();
- detectionSummary.setSchedule(schedule);
- detectionSummary.setType(COVERAGE);
-
driftMgr.setChangeSetMgr(changeSetMgr);
driftMgr.getSchedulesQueue().addSchedule(new DriftDetectionSchedule(resourceId(),
config));
- driftMgr.sendChangeSetToServer(detectionSummary);
+ driftMgr.sendChangeSetToServer(resourceId(), config, COVERAGE);
}
@Test
- public void cleanUpWhenServerAcksChangeSet() throws Exception {
- DriftConfiguration config =
driftConfiguration("clean-up-when-server-acks-changeset",
- resourceDir.getAbsolutePath());
- File changeSetDir = changeSetDir(config.getName());
- File snapshotFile = createRandomFile(changeSetDir, "changeset.txt");
- File previousSnapshotFile = createRandomFile(changeSetDir,
"changeset.txt.previous");
- File changeSetZipFile = createRandomFile(changeSetDir, "changeset_" +
System.currentTimeMillis() + ".zip");
+ public void cleanUpAfterSendingChangeSetToServer() throws Exception {
+ final DriftDefinition config =
driftConfiguration("send-changeset-in-zip", resourceDir.getAbsolutePath());
+ final File changeSetDir = changeSetDir(config.getName());
+ createRandomFile(changeSetDir, "changeset.txt");
- driftMgr.ackChangeSet(resourceId(), config.getName());
+ driftMgr.setChangeSetMgr(changeSetMgr);
+ driftMgr.getSchedulesQueue().addSchedule(new DriftDetectionSchedule(resourceId(),
config));
+ driftMgr.sendChangeSetToServer(resourceId(), config, COVERAGE);
+
+ // clean up should not happen until after the input stream is closed. The remote
+ // input stream is consumed asynchronously; so, we have to wait until the stream
+ // is closed. We could otherwise disrupt the transmission of bits.
+
+ File changeSetZip = assertThatZipFileExists(changeSetDir, "changeset_",
"Expected to find change set zip " +
+ "zip file in " + changeSetDir.getPath() + ". The file name
should follow the pattern " +
+ "changeset_<integer_timestamp>.zip");
- assertTrue(snapshotFile.exists(), "Snapshot file should exist after server
acks change set");
- assertFalse(previousSnapshotFile.exists(), "Previous version snapshot file
should be deleted when server " +
- "acks change set");
- assertEquals(findChangeSetZipFiles(changeSetDir).size(), 0, "All change set
zip files should be deleted when " +
- "server acks change set");
+ driftServerService.inputStream.close();
+
+ assertFalse(changeSetZip.exists(), "The change set zip should be deleted
when the remote input stream is closed.");
}
@Test
@@ -183,28 +177,35 @@ public class DriftManagerTest extends DriftTest {
});
driftMgr.sendChangeSetContentToServer(resourceId(), configName, contentDir);
-
- // verify that the content directory is purged
- assertThatDirectoryIsEmpty(contentDir);
}
@Test
- public void cleanUpWhenServerAcksChangeSetContent() throws Exception {
- String configName = "cleanup-when-server-acks-content";
+ public void cleanUpAfterSendingContentToServer() throws Exception {
+ String configName = "clean-up-after-sending-content";
File changeSetDir = changeSetDir(configName);
File contentDir = mkdir(changeSetDir, "content");
- String token = Long.toString(System.currentTimeMillis());
- File contentZipFile = createRandomFile(changeSetDir, "content_" + token
+ ".zip");
+ createRandomFile(contentDir, "content-1");
+ createRandomFile(contentDir, "content-2");
+
+ driftMgr.sendChangeSetContentToServer(resourceId(), configName, contentDir);
- driftMgr.ackChangeSetContent(resourceId(), configName, token);
+ // clean up should not happen until after the input stream is closed. The remote
+ // input stream is consumed asynchronously; so, we have to wait until the stream
+ // is closed. We could otherwise disrupt the transmission of bits.
+ File contentZipFile = assertThatZipFileExists(changeSetDir,
"content_",
+ "Expected to find content zip file in " +
+ changeSetDir.getPath() + ". The file name should have a pattern of
content_integer_timestamp>.zip");
- assertFalse(contentZipFile.exists(), "Content zip file should be purged
after server sends content ack");
+ driftServerService.inputStream.close();
+
+ assertFalse(contentZipFile.exists(), "The content zip should be deleted when
the remote input stream is closed");
+ assertThatDirectoryIsEmpty(contentDir);
}
@Test
public void unschedulingDetectionRemovesScheduleFromQueue() throws Exception {
- DriftConfiguration config = driftConfiguration("remove-from-queue",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("remove-from-queue",
resourceDir.getAbsolutePath());
driftMgr.scheduleDriftDetection(resourceId(), config);
driftMgr.scheduleDriftDetection(resourceId() + 5,
driftConfiguration("another-config", "."));
@@ -216,8 +217,8 @@ public class DriftManagerTest extends DriftTest {
@Test
public void unschedulingDetectionRemovesDriftConfigFromResourceContainer() throws
Exception {
- DriftConfiguration config = driftConfiguration("remove-from-queue",
resourceDir.getAbsolutePath());
- DriftConfiguration config2 = driftConfiguration("do-not-remove",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("remove-from-queue",
resourceDir.getAbsolutePath());
+ DriftDefinition config2 = driftConfiguration("do-not-remove",
resourceDir.getAbsolutePath());
driftMgr.scheduleDriftDetection(resourceId(), config);
driftMgr.scheduleDriftDetection(resourceId(), config2);
@@ -226,12 +227,12 @@ public class DriftManagerTest extends DriftTest {
ResourceContainer container =
driftMgr.getInventoryManager().getResourceContainer(resourceId());
assertCollectionMatchesNoOrder(config + " should have been removed from the
resource container ",
- asList(config2), container.getDriftConfigurations());
+ asList(config2), container.getDriftDefinitions());
}
@Test
public void unschedulingDetectionDeletesChangeSetDirectoryWhenScheduleIsNotActive()
throws Exception {
- DriftConfiguration config = driftConfiguration("delete-changeset-dir",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("delete-changeset-dir",
resourceDir.getAbsolutePath());
File changeSetDir = changeSetDir(config.getName());
File contentDir = mkdir(changeSetDir, "content");
@@ -246,7 +247,7 @@ public class DriftManagerTest extends DriftTest {
@Test
public void unschedulingDetectionDeletesChangeSetDirectoryWhenScheduleIsDeactivated()
throws Exception {
- DriftConfiguration config = driftConfiguration("delete-changeset-dir",
resourceDir.getAbsolutePath());
+ DriftDefinition config = driftConfiguration("delete-changeset-dir",
resourceDir.getAbsolutePath());
File changeSetDir = changeSetDir(config.getName());
File contentDir = mkdir(changeSetDir, "content");
@@ -265,16 +266,6 @@ public class DriftManagerTest extends DriftTest {
"deactivated.");
}
- private List<File> findChangeSetZipFiles(File dir) {
- File[] files = dir.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.startsWith("changeset_") &&
name.endsWith(".zip");
- }
- });
- return asList(files);
- }
-
/**
* This method first verifies that each of the expected files is contained in the
the
* zip file. Then it verifies that the content for each file in the zip file matches
@@ -360,8 +351,6 @@ public class DriftManagerTest extends DriftTest {
private static class TestDriftServerService implements DriftServerService {
public int resourceId;
- public String driftConfigName;
- public String token;
public long fileSize;
public InputStream inputStream;
@@ -379,11 +368,8 @@ public class DriftManagerTest extends DriftTest {
}
@Override
- public void sendFilesZip(int resourceId, String driftConfigName, String token,
long zipSize,
- InputStream zipStream) {
+ public void sendFilesZip(int resourceId, long zipSize, InputStream zipStream) {
this.resourceId = resourceId;
- this.driftConfigName = driftConfigName;
- this.token = token;
fileSize = zipSize;
inputStream = zipStream;
@@ -393,7 +379,7 @@ public class DriftManagerTest extends DriftTest {
}
@Override
- public Map<Integer, List<DriftConfiguration>>
getDriftConfigurations(Set<Integer> resourceIds) {
+ public Map<Integer, List<DriftDefinition>>
getDriftDefinitions(Set<Integer> resourceIds) {
return null;
}
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 a267402..ad32251 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
@@ -31,7 +31,7 @@ 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.domain.drift.DriftDefinition;
import org.rhq.core.util.MessageDigestGenerator;
import static java.util.Arrays.asList;
@@ -243,7 +243,7 @@ public class DriftTest {
}
/**
- * Creates a {@link DriftConfiguration} with the specified basedir. The file system
is
+ * Creates a {@link DriftDefinition} with the specified basedir. The file system is
* used as the context for the basedir which means the path specified is used as is.
* The interval property is set to {@link #defaultInterval}.
*
@@ -251,10 +251,10 @@ public class DriftTest {
* @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());
+ protected DriftDefinition driftConfiguration(String name, String basedir) {
+ DriftDefinition config = new DriftDefinition(new Configuration());
config.setName(name);
- config.setBasedir(new DriftConfiguration.BaseDirectory(fileSystem, basedir));
+ config.setBasedir(new DriftDefinition.BaseDirectory(fileSystem, basedir));
config.setEnabled(true);
config.setInterval(defaultInterval);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java
index fa9fa06..78bdd58 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/LinkManager.java
@@ -104,34 +104,34 @@ public class LinkManager {
public static String getEntityTabLink(EntityContext entityContext, String tabName,
String subTabName) {
String link;
switch (entityContext.getType()) {
- case Resource:
- link = getResourceTabLink(entityContext.getResourceId(), tabName,
subTabName);
- break;
- case ResourceGroup:
- if (entityContext.isAutoGroup()) {
- link = getAutoGroupTabLink(entityContext.getGroupId(), tabName,
subTabName);
- } else if (entityContext.isAutoCluster()) {
- link = getAutoClusterTabLink(entityContext.getGroupId(), tabName,
subTabName);
- } else {
- link = getResourceGroupTabLink(entityContext.getGroupId(), tabName,
subTabName);
- }
- break;
- case SubsystemView:
- if (tabName.equals("Alerts") &&
subTabName.equals("Definitions")) {
- link = "#Reports/Subsystems/AlertDefinitions";
- } else if (tabName.equals("Alerts") &&
subTabName.equals("History")) {
- link = "#Reports/Subsystems/RecentAlerts";
- } else if (tabName.equals("Operations") &&
subTabName.equals("History")) {
- link = "#Reports/Subsystems/RecentOperations";
- } else if (tabName.equals("Configuration") &&
subTabName.equals("History")) {
- link = "#Reports/Subsystems/ConfigurationHistoryView";
- } else {
- throw new IllegalArgumentException("Subsystem link not supported
for tab " + tabName + ">"
- + subTabName + ".");
- }
- break;
- default:
- throw new IllegalArgumentException("Unsupported entity context type:
" + entityContext.getType());
+ case Resource:
+ link = getResourceTabLink(entityContext.getResourceId(), tabName,
subTabName);
+ break;
+ case ResourceGroup:
+ if (entityContext.isAutoGroup()) {
+ link = getAutoGroupTabLink(entityContext.getGroupId(), tabName,
subTabName);
+ } else if (entityContext.isAutoCluster()) {
+ link = getAutoClusterTabLink(entityContext.getGroupId(), tabName,
subTabName);
+ } else {
+ link = getResourceGroupTabLink(entityContext.getGroupId(), tabName,
subTabName);
+ }
+ break;
+ case SubsystemView:
+ if (tabName.equals("Alerts") &&
subTabName.equals("Definitions")) {
+ link = "#Reports/Subsystems/AlertDefinitions";
+ } else if (tabName.equals("Alerts") &&
subTabName.equals("History")) {
+ link = "#Reports/Subsystems/RecentAlerts";
+ } else if (tabName.equals("Operations") &&
subTabName.equals("History")) {
+ link = "#Reports/Subsystems/RecentOperations";
+ } else if (tabName.equals("Configuration") &&
subTabName.equals("History")) {
+ link = "#Reports/Subsystems/ConfigurationHistoryView";
+ } else {
+ throw new IllegalArgumentException("Subsystem link not supported for
tab " + tabName + ">" + subTabName
+ + ".");
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported entity context type:
" + entityContext.getType());
}
return link;
}
@@ -491,8 +491,8 @@ public class LinkManager {
return "#Resource/" + resourceId + "/Drift/History/" +
driftId;
}
- public static String getDriftConfigurationLink(int resourceId, int driftConfigId) {
- return "#Resource/" + resourceId + "/Drift/Configuration/" +
driftConfigId;
+ public static String getDriftDefinitionEditLink(int resourceId, int driftDefId) {
+ return "#Resource/" + resourceId + "/Drift/Definitions/" +
driftDefId + "/Edit";
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java
index 92913f9..2474f02 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/ConditionsEditor.java
@@ -163,13 +163,13 @@ public class ConditionsEditor extends LocatableVLayout {
// the drift config.
if (type != resourceType) {
// paranoia, unsure if this is needed but clear out
any old drift config still hanging around
- if (resourceType.getDriftConfigurationTemplates() !=
null) {
-
resourceType.getDriftConfigurationTemplates().clear();
+ if (resourceType.getDriftDefinitionTemplates() !=
null) {
+
resourceType.getDriftDefinitionTemplates().clear();
}
// if the newly loaded resource type supports drift,
put it in our type object
- if (type.getDriftConfigurationTemplates() != null) {
- for (ConfigurationTemplate ct :
type.getDriftConfigurationTemplates()) {
-
resourceType.addDriftConfigurationTemplate(ct);
+ if (type.getDriftDefinitionTemplates() != null) {
+ for (ConfigurationTemplate ct :
type.getDriftDefinitionTemplates()) {
+ resourceType.addDriftDefinitionTemplate(ct);
}
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
index 23b59f6..5142a7c 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/alert/definitions/NewConditionEditor.java
@@ -133,7 +133,7 @@ public class NewConditionEditor extends LocatableDynamicForm {
this.supportsEvents = (rtype.getEventDefinitions() != null &&
rtype.getEventDefinitions().size() > 0);
this.supportsResourceConfig = (rtype.getResourceConfigurationDefinition() !=
null);
- this.supportsDrift = (rtype.getDriftConfigurationTemplates() != null &&
rtype.getDriftConfigurationTemplates()
+ this.supportsDrift = (rtype.getDriftDefinitionTemplates() != null &&
rtype.getDriftDefinitionTemplates()
.size() > 0);
Set<MeasurementDefinition> metricDefinitions =
rtype.getMetricDefinitions();
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/Carousel.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/Carousel.java
new file mode 100644
index 0000000..9388bbc
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/Carousel.java
@@ -0,0 +1,1135 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.components.carousel;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.google.gwt.event.dom.client.KeyCodes;
+import com.smartgwt.client.data.Criteria;
+import com.smartgwt.client.data.SortSpecifier;
+import com.smartgwt.client.types.Overflow;
+import com.smartgwt.client.types.SelectionStyle;
+import com.smartgwt.client.types.VerticalAlignment;
+import com.smartgwt.client.util.BooleanCallback;
+import com.smartgwt.client.util.SC;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.HTMLFlow;
+import com.smartgwt.client.widgets.IButton;
+import com.smartgwt.client.widgets.Img;
+import com.smartgwt.client.widgets.Label;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.events.DoubleClickHandler;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.HiddenItem;
+import com.smartgwt.client.widgets.form.fields.SelectItem;
+import com.smartgwt.client.widgets.form.fields.TextItem;
+import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
+import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
+import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent;
+import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler;
+import com.smartgwt.client.widgets.layout.HLayout;
+import com.smartgwt.client.widgets.layout.LayoutSpacer;
+import com.smartgwt.client.widgets.menu.IMenuButton;
+import com.smartgwt.client.widgets.menu.MenuItem;
+import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent;
+
+import org.rhq.core.domain.search.SearchSubsystem;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.RefreshableView;
+import org.rhq.enterprise.gui.coregui.client.components.form.SearchBarItem;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableHLayout;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIMenuButton;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableMenu;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableToolStrip;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
+
+/**
+ * Similar to (i.e. originally a copy of) Table but instead of encapsulating a ListGrid,
it manages a list of
+ * @{link CarouselMember}s, offering horizontal presentation of the member canvases, high
level filtering, and
+ * other member-wide handling.
+ *
+ * @author Jay Shaughnessy
+ */
+@SuppressWarnings("unchecked")
+public abstract class Carousel extends LocatableHLayout implements RefreshableView {
+
+ private static final String FILTER_CAROUSEL_START = "CarouselStart";
+ private static final String FILTER_CAROUSEL_SIZE = "CarouselSize";
+
+ private LocatableVLayout contents;
+
+ private HLayout titleLayout;
+ private Canvas titleComponent;
+ private HTMLFlow titleCanvas;
+ private String titleString;
+ private List<String> titleIcons = new ArrayList<String>();
+
+ private Canvas carouselDetails;
+
+ private CarouselFilter filterForm;
+
+ private LocatableHLayout carouselHolder;
+
+ private Label carouselInfo;
+
+ private boolean showTitle = true;
+ private boolean showFooter = true;
+ private boolean showFooterRefresh = true;
+ private boolean showFilterForm = true;
+
+ private Criteria initialCriteria;
+ private boolean initialCriteriaFixed = true;
+ @SuppressWarnings("unused")
+ private SortSpecifier[] sortSpecifiers;
+ @SuppressWarnings("unused")
+ private String[] excludedFieldNames;
+ @SuppressWarnings("unused")
+ private boolean autoFetchData;
+ @SuppressWarnings("unused")
+ private boolean flexRowDisplay = true;
+ private boolean hideSearchBar = false;
+ private String initialSearchBarSearchText = null;
+
+ private List<CarouselActionInfo> carouselActions = new
ArrayList<CarouselActionInfo>();
+ private boolean carouselActionDisableOverride = false;
+ protected List<Canvas> extraWidgetsAboveFooter = new
ArrayList<Canvas>();
+ protected List<Canvas> extraWidgetsInMainFooter = new
ArrayList<Canvas>();
+ private LocatableToolStrip footer;
+ private LocatableToolStrip footerExtraWidgets;
+ private LocatableIButton refreshButton;
+ private LocatableIButton nextButton;
+ private LocatableIButton previousButton;
+ private LocatableIButton widthButton;
+
+ // null indicates filtering on the member number
+ private Integer carouselStartFilter = null;
+ // null indicates no limit to the carousel size. This can be dangerous.
+ private Integer carouselSizeFilter = null;
+ private boolean carouselDirty = false;
+ private boolean carouselUsingFixedWidths = false;
+
+ public Carousel(String locatorId) {
+ this(locatorId, null, null, null, null, true);
+ }
+
+ public Carousel(String locatorId, String titleString) {
+ this(locatorId, titleString, null, null, null, true);
+ }
+
+ public Carousel(String locatorId, String titleString, Criteria criteria) {
+ this(locatorId, titleString, criteria, null, null, true);
+ }
+
+ public Carousel(String locatorId, String titleString, SortSpecifier[] sortSpecifiers)
{
+ this(locatorId, titleString, null, sortSpecifiers, null, true);
+ }
+
+ protected Carousel(String locatorId, String titleString, SortSpecifier[]
sortSpecifiers, Criteria criteria) {
+ this(locatorId, titleString, criteria, sortSpecifiers, null, true);
+ }
+
+ public Carousel(String locatorId, String titleString, boolean autoFetchData) {
+ this(locatorId, titleString, null, null, null, autoFetchData);
+ }
+
+ public Carousel(String locatorId, String titleString, SortSpecifier[] sortSpecifiers,
String[] excludedFieldNames) {
+ this(locatorId, titleString, null, sortSpecifiers, excludedFieldNames, true);
+ }
+
+ public Carousel(String locatorId, String titleString, Criteria criteria,
SortSpecifier[] sortSpecifiers,
+ String[] excludedFieldNames) {
+ this(locatorId, titleString, criteria, sortSpecifiers, excludedFieldNames,
true);
+ }
+
+ public Carousel(String locatorId, String titleString, Criteria criteria,
SortSpecifier[] sortSpecifiers,
+ String[] excludedFieldNames, boolean autoFetchData) {
+ super(locatorId);
+
+ setWidth100();
+ setHeight100();
+ setOverflow(Overflow.HIDDEN);
+
+ this.titleString = titleString;
+ this.initialCriteria = criteria;
+ this.sortSpecifiers = sortSpecifiers;
+ this.excludedFieldNames = excludedFieldNames;
+ this.autoFetchData = autoFetchData;
+ }
+
+ /**
+ * If this returns true, then even if a {@link #getSearchSubsystem() search
subsystem}
+ * is defined by the class, the search bar will not be shown.
+ *
+ * @return true if the search bar is to be hidden (default is false)
+ */
+ public boolean getHideSearchBar() {
+ return this.hideSearchBar;
+ }
+
+ public void setHideSearchBar(boolean flag) {
+ this.hideSearchBar = flag;
+ }
+
+ public String getInitialSearchBarSearchText() {
+ return this.initialSearchBarSearchText;
+ }
+
+ public void setInitialSearchBarSearchText(String text) {
+ this.initialSearchBarSearchText = text;
+ }
+
+ public void setFlexRowDisplay(boolean flexRowDisplay) {
+ this.flexRowDisplay = flexRowDisplay;
+ }
+
+ @Override
+ protected void onInit() {
+ super.onInit();
+
+ contents = new LocatableVLayout(extendLocatorId("Contents"));
+ contents.setWidth100();
+ contents.setHeight100();
+ //contents.setOverflow(Overflow.AUTO);
+ addMember(contents);
+
+ filterForm = new CarouselFilter(this);
+
+ /*
+ * carousel filters and search bar are currently mutually exclusive
+ */
+
+ if (getSearchSubsystem() == null) {
+ configureCarouselFilters();
+
+ } else {
+ if (!this.hideSearchBar) {
+ final SearchBarItem searchFilter = new SearchBarItem("search",
MSG.common_button_search(),
+ getSearchSubsystem(), getInitialSearchBarSearchText());
+ setFilterFormItems(searchFilter);
+ }
+ }
+
+ carouselHolder = new LocatableHLayout(extendLocatorId("Holder"));
+ carouselHolder.setOverflow(Overflow.AUTO);
+ carouselHolder.setWidth100();
+ contents.addMember(carouselHolder);
+ }
+
+ protected SelectionStyle getDefaultSelectionStyle() {
+ return SelectionStyle.MULTIPLE;
+ }
+
+ @Override
+ protected void onDraw() {
+ try {
+ super.onDraw();
+
+ for (Canvas child : contents.getMembers()) {
+ contents.removeChild(child);
+ }
+
+ // Title
+ this.titleCanvas = new HTMLFlow();
+ setTitleString(this.titleString);
+
+ if (showTitle) {
+ titleLayout = new
LocatableHLayout(contents.extendLocatorId("Title"));
+ titleLayout.setAutoHeight();
+ titleLayout.setAlign(VerticalAlignment.BOTTOM);
+ contents.addMember(titleLayout, 0);
+ }
+
+ if (null != carouselDetails) {
+ contents.addMember(carouselDetails);
+ }
+
+ if (filterForm.hasContent()) {
+ contents.addMember(filterForm);
+ }
+
+ contents.addMember(carouselHolder);
+
+ // Footer
+
+ // A second toolstrip that optionally appears before the main footer - it
will contain extra widgets.
+ // This is hidden from view unless extra widgets are actually added to the
carousel above the main footer.
+ this.footerExtraWidgets = new
LocatableToolStrip(contents.extendLocatorId("FooterExtraWidgets"));
+ footerExtraWidgets.setPadding(5);
+ footerExtraWidgets.setWidth100();
+ footerExtraWidgets.setMembersMargin(15);
+ footerExtraWidgets.hide();
+ contents.addMember(footerExtraWidgets);
+
+ this.footer = new
LocatableToolStrip(contents.extendLocatorId("Footer"));
+ footer.setPadding(5);
+ footer.setWidth100();
+ footer.setMembersMargin(15);
+ contents.addMember(footer);
+
+ // The ListGrid has been created and configured
+ // Now give subclasses a chance to configure the carousel
+ configureCarousel();
+
+ Label carouselInfo = new Label();
+ carouselInfo.setWrap(false);
+ setCarouselInfo(carouselInfo);
+ refreshRowCount();
+
+ if (showTitle) {
+ drawTitle();
+ }
+
+ if (showFooter) {
+ drawFooter();
+ }
+ } catch (Exception e) {
+
CoreGUI.getErrorHandler().handleError(MSG.view_table_drawFail(this.toString()), e);
+ }
+ }
+
+ private void refreshRowCount() {
+ }
+
+ @Override
+ public void destroy() {
+ SeleniumUtility.destroyMembers(contents);
+ super.destroy();
+ }
+
+ private void drawTitle() {
+ for (String headerIcon : titleIcons) {
+ Img img = new Img(headerIcon, 24, 24);
+ img.setPadding(4);
+ titleLayout.addMember(img);
+ }
+
+ titleLayout.addMember(titleCanvas);
+
+ if (titleComponent != null) {
+ titleLayout.addMember(new LayoutSpacer());
+ titleLayout.addMember(titleComponent);
+ }
+ }
+
+ private void drawFooter() {
+ // populate the extraWidgets toolstrip
+ footerExtraWidgets.removeMembers(footerExtraWidgets.getMembers());
+ if (!extraWidgetsAboveFooter.isEmpty()) {
+ for (Canvas extraWidgetCanvas : extraWidgetsAboveFooter) {
+ footerExtraWidgets.addMember(extraWidgetCanvas);
+ }
+ footerExtraWidgets.show();
+ }
+
+ footer.removeMembers(footer.getMembers());
+
+ for (final CarouselActionInfo carouselAction : carouselActions) {
+
+ if (null == carouselAction.getValueMap()) {
+ // button action
+ IButton button = new LocatableIButton(carouselAction.getLocatorId(),
carouselAction.getTitle());
+ button.setDisabled(true);
+ button.setOverflow(Overflow.VISIBLE);
+ button.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ disableAllFooterControls();
+ if (carouselAction.confirmMessage != null) {
+ String message =
carouselAction.confirmMessage.replaceAll("\\#", "TODO:");
+
+ SC.ask(message, new BooleanCallback() {
+ public void execute(Boolean confirmed) {
+ if (confirmed) {
+ carouselAction.action.executeAction(null);
+ } else {
+ refreshCarouselInfo();
+ }
+ }
+ });
+ } else {
+ carouselAction.action.executeAction(null);
+ }
+ }
+ });
+
+ carouselAction.actionCanvas = button;
+ footer.addMember(button);
+
+ } else {
+ // menu action
+ LocatableMenu menu = new LocatableMenu(carouselAction.getLocatorId() +
"Menu");
+ final Map<String, ? extends Object> menuEntries =
carouselAction.getValueMap();
+ for (final String key : menuEntries.keySet()) {
+ MenuItem item = new MenuItem(key);
+ item.addClickHandler(new
com.smartgwt.client.widgets.menu.events.ClickHandler() {
+ public void onClick(MenuItemClickEvent event) {
+ disableAllFooterControls();
+
carouselAction.getAction().executeAction(menuEntries.get(key));
+ }
+ });
+ menu.addItem(item);
+ }
+
+ IMenuButton menuButton = new
LocatableIMenuButton(carouselAction.getLocatorId(), carouselAction
+ .getTitle());
+ menuButton.setMenu(menu);
+ menuButton.setDisabled(true);
+ menuButton.setAutoFit(true); // this makes it pretty tight, but maybe
better than the default, which is pretty wide
+ menuButton.setOverflow(Overflow.VISIBLE);
+ menuButton.setShowMenuBelow(false);
+
+ carouselAction.actionCanvas = menuButton;
+ footer.addMember(menuButton);
+ }
+ }
+
+ for (Canvas extraWidgetCanvas : extraWidgetsInMainFooter) {
+ footer.addMember(extraWidgetCanvas);
+ }
+
+ footer.addMember(new LayoutSpacer());
+
+ widthButton = new LocatableIButton(extendLocatorId("Width"),
MSG.common_button_fixedWidth());
+ widthButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ carouselUsingFixedWidths = !carouselUsingFixedWidths;
+ widthButton.setTitle(carouselUsingFixedWidths ?
MSG.common_button_scaleToFit() : MSG
+ .common_button_fixedWidth());
+ buildCarousel(true);
+ }
+ });
+ footer.addMember(widthButton);
+
+ if (isShowFooterRefresh()) {
+ this.refreshButton = new
LocatableIButton(extendLocatorId("Refresh"), MSG.common_button_refresh());
+ refreshButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ disableAllFooterControls();
+ refresh();
+ }
+ });
+ footer.addMember(refreshButton);
+ }
+
+ previousButton = new LocatableIButton(extendLocatorId("Previous"),
MSG.common_button_previous());
+ previousButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ disableAllFooterControls();
+ previous();
+ }
+ });
+ footer.addMember(previousButton);
+
+ nextButton = new LocatableIButton(extendLocatorId("Next"),
MSG.common_button_next());
+ nextButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ disableAllFooterControls();
+ next();
+ }
+ });
+ footer.addMember(nextButton);
+
+ footer.addMember(carouselInfo);
+
+ // Ensure buttons are initially set correctly.
+ refreshCarouselInfo();
+ }
+
+ private void previous() {
+ if (null == carouselSizeFilter) {
+ carouselSizeFilter = getDefaultCarouselSize();
+ }
+ if (null != carouselStartFilter) {
+ int newStart = carouselStartFilter + carouselSizeFilter;
+ setCarouselStartFilter(newStart);
+ }
+ buildCarousel(true);
+ }
+
+ private void next() {
+ if (null == carouselSizeFilter) {
+ carouselSizeFilter = getDefaultCarouselSize();
+ }
+
+ if (null != carouselStartFilter) {
+ int newStart = carouselStartFilter - carouselSizeFilter;
+ newStart = (newStart < carouselSizeFilter) ? carouselSizeFilter :
newStart;
+ setCarouselStartFilter(newStart);
+ }
+ buildCarousel(true);
+ }
+
+ protected abstract int getDefaultCarouselSize();
+
+ protected abstract String getCarouselMemberFixedWidth();
+
+ protected abstract String getCarouselStartFilterLabel();
+
+ protected abstract String getCarouselSizeFilterLabel();
+
+ private void disableAllFooterControls() {
+ for (CarouselActionInfo action : carouselActions) {
+ action.actionCanvas.disable();
+ }
+ for (Canvas extraWidget : extraWidgetsAboveFooter) {
+ extraWidget.disable();
+ }
+ for (Canvas extraWidget : extraWidgetsInMainFooter) {
+ extraWidget.disable();
+ }
+ if (isShowFooterRefresh() && this.refreshButton != null) {
+ this.refreshButton.disable();
+ }
+ }
+
+ /**
+ * Subclasses can use this as a chance to configure the list grid after it has been
+ * created but before it has been drawn to the DOM. This is also the proper place to
add
+ * actions so that they're rendered in the footer.
+ */
+ protected void configureCarousel() {
+ return;
+ }
+
+ /**
+ * If not overriden this will append the standard carousel filters to those already
supplied. To ensure
+ * the supplied form items end a row, call {@link FormItem#setEndRow(Boolean)} as
needed. The filter form is
+ * set to use 6 columns, which allows the carousle filters to fit on one row.
+ * @param formItems
+ */
+ public void setFilterFormItems(FormItem... formItems) {
+ // since Arrays.copyOf is unsupported...
+ FormItem[] carouselFormItems = new FormItem[2 + formItems.length];
+ int i = 0;
+ for (FormItem item : formItems) {
+ carouselFormItems[i++] = item;
+ }
+
+ // drift file path filter
+ TextItem startFilter = new TextItem(FILTER_CAROUSEL_START,
getCarouselStartFilterLabel());
+ TextItem numFilter = new TextItem(FILTER_CAROUSEL_SIZE,
getCarouselSizeFilterLabel());
+ carouselFormItems[i++] = startFilter;
+ carouselFormItems[i++] = numFilter;
+
+ this.filterForm.setNumCols(4);
+ this.filterForm.setItems(carouselFormItems);
+ }
+
+ /**
+ * Overriding components can use this as a chance to add {@link FormItem}s which will
filter
+ * the carousel members that display their data. If not overriden the standard
carousel filters are applied.
+ */
+ protected void configureCarouselFilters() {
+ setFilterFormItems();
+ }
+
+ /**
+ * Set the Carousel's title string. This will subsequently call {@link
#updateTitleCanvas(String)}.
+ * @param titleString
+ */
+ public void setTitleString(String titleString) {
+ this.titleString = titleString;
+ if (this.titleCanvas != null) {
+ updateTitleCanvas(titleString);
+ }
+ }
+
+ public Canvas getTitleCanvas() {
+ return this.titleCanvas;
+ }
+
+ /**
+ * To set the Carousel's title, call {@link #setTitleString(String)}. This is
primarily declared for purposes of
+ * override.
+ * @param titleString
+ */
+ public void updateTitleCanvas(String titleString) {
+ if (titleString == null) {
+ titleString = "";
+ }
+ if (titleString.length() > 0) {
+ titleCanvas.setWidth100();
+ titleCanvas.setHeight(35);
+ titleCanvas.setContents(titleString);
+ titleCanvas.setPadding(4);
+ titleCanvas.setStyleName("HeaderLabel");
+ } else {
+ titleCanvas.setWidth100();
+ titleCanvas.setHeight(0);
+ titleCanvas.setContents(null);
+ titleCanvas.setPadding(0);
+ titleCanvas.setStyleName("normal");
+ }
+
+ titleCanvas.markForRedraw();
+ }
+
+ /**
+ * Returns the encompassing canvas that contains all content for this component.
+ * This content includes the carousel members, the buttons, etc.
+ */
+ public Canvas getCarouselContents() {
+ return this.contents;
+ }
+
+ public boolean isShowTitle() {
+ return showTitle;
+ }
+
+ public void setShowTitle(boolean showTitle) {
+ this.showTitle = showTitle;
+ }
+
+ public boolean isShowFooter() {
+ return showFooter;
+ }
+
+ public void setShowFooter(boolean showFooter) {
+ this.showFooter = showFooter;
+ }
+
+ protected boolean isInitialCriteriaFixed() {
+ return initialCriteriaFixed;
+ }
+
+ /**
+ * @param initialCriteriaFixed If true initialCriteria is applied to all subsequent
fetch criteria. If false
+ * initialCriteria is used only for the initial autoFetch. Irrelevant if autoFetch is
false. Default is true.
+ */
+ protected void setInitialCriteriaFixed(boolean initialCriteriaFixed) {
+ this.initialCriteriaFixed = initialCriteriaFixed;
+ }
+
+ /**
+ *
+ * @return the current criteria, which includes any fixed criteria, as well as any
user-specified filters; may be
+ * null if there are no fixed criteria or user-specified filters
+ */
+ protected Criteria getCurrentCriteria() {
+ Criteria criteria = null;
+
+ // If this carousel has a filter form (filters OR search bar),
+ // we need to refresh it as per the filtering, combined with any fixed criteria.
+ if (this.filterForm != null && this.filterForm.hasContent()) {
+
+ criteria = this.filterForm.getValuesAsCriteria();
+
+ if (this.initialCriteriaFixed) {
+ if (criteria != null) {
+ if (this.initialCriteria != null) {
+ // There is fixed criteria - add it to the filter form criteria.
+ addCriteria(criteria, this.initialCriteria);
+ }
+ } else {
+ criteria = this.initialCriteria;
+ }
+ }
+ } else if (this.initialCriteriaFixed) {
+
+ criteria = this.initialCriteria;
+ }
+
+ return criteria;
+ }
+
+ // SmartGWT 2.4's version of Criteria.addCriteria for some reason doesn't
have else clauses for the array types
+ // and it doesn't handle Object types properly (seeing odd behavior because of
this), so this method explicitly
+ // supports adding array types and Objects.
+ // This method takes the src criteria and adds it to the dest criteria.
+ private static void addCriteria(Criteria dest, Criteria src) {
+ Map otherMap = src.getValues();
+ Set otherKeys = otherMap.keySet();
+ for (Iterator i = otherKeys.iterator(); i.hasNext();) {
+ String field = (String) i.next();
+ Object value = otherMap.get(field);
+
+ if (value instanceof Integer) {
+ dest.addCriteria(field, (Integer) value);
+ } else if (value instanceof Float) {
+ dest.addCriteria(field, (Float) value);
+ } else if (value instanceof String) {
+ dest.addCriteria(field, (String) value);
+ } else if (value instanceof Date) {
+ dest.addCriteria(field, (Date) value);
+ } else if (value instanceof Boolean) {
+ dest.addCriteria(field, (Boolean) value);
+ } else if (value instanceof Integer[]) {
+ dest.addCriteria(field, (Integer[]) value);
+ } else if (value instanceof Double[]) {
+ dest.addCriteria(field, (Double[]) value);
+ } else if (value instanceof String[]) {
+ dest.addCriteria(field, (String[]) value);
+ } else {
+ // this is the magic piece - we need to get attrib as an object and set
that value
+ dest.setAttribute(field, src.getAttributeAsObject(field));
+ }
+ }
+ }
+
+ public void setCarouselDetails(Canvas carouselDetails) {
+ this.carouselDetails = carouselDetails;
+ }
+
+ public Canvas getCarouselDetails() {
+ return carouselDetails;
+ }
+
+ public void setTitleComponent(Canvas canvas) {
+ this.titleComponent = canvas;
+ }
+
+ /**
+ * Note: To prevent user action while a current action completes, all widgets on the
footer are disabled
+ * when footer actions take place, typically a button click. It is up to the action
to ensure the page
+ * (via refresh() or CoreGUI.refresh()) or footer (via refreshCarouselActions) are
refreshed as needed at action
+ * completion. Failure to do so may leave the widgets disabled.
+ */
+ public void addCarouselAction(String locatorId, String title, CarouselAction action)
{
+ this.addCarouselAction(locatorId, title, null, null, action);
+ }
+
+ /**
+ * Note: To prevent user action while a current action completes, all widgets on the
footer are disabled
+ * when footer actions take place, typically a button click. It is up to the action
to ensure the page
+ * (via refresh() or CoreGUI.refresh()) or footer (via refreshCarouselActions) are
refreshed as needed at action
+ * completion. Failure to do so may leave the widgets disabled.
+ */
+ public void addCarouselAction(String locatorId, String title, String confirmation,
CarouselAction action) {
+ this.addCarouselAction(locatorId, title, confirmation, null, action);
+ }
+
+ /**
+ * Note: To prevent user action while a current action completes, all widgets on the
footer are disabled
+ * when footer actions take place, typically a button click. It is up to the action
to ensure the page
+ * (via refresh() or CoreGUI.refresh()) or footer (via refreshCarouselActions) are
refreshed as needed at action
+ * completion. Failure to do so may leave the widgets disabled.
+ */
+ public void addCarouselAction(String locatorId, String title, String confirmation,
+ LinkedHashMap<String, ? extends Object> valueMap, CarouselAction action) {
+ // If the specified locator ID is qualified, strip off the ancestry prefix, so we
can make sure its locator ID
+ // extends the footer's locator ID as it should.
+ int underscoreIndex = locatorId.lastIndexOf('_');
+ String unqualifiedLocatorId;
+ if (underscoreIndex >= 0 && underscoreIndex != (locatorId.length() -
1)) {
+ unqualifiedLocatorId = locatorId.substring(underscoreIndex + 1);
+ } else {
+ unqualifiedLocatorId = locatorId;
+ }
+ CarouselActionInfo info = new
CarouselActionInfo(this.footer.extendLocatorId(unqualifiedLocatorId), title,
+ confirmation, valueMap, action);
+ carouselActions.add(info);
+ }
+
+ public void addCarouselMember(Canvas member) {
+ member.setWidth(carouselUsingFixedWidths ? getCarouselMemberFixedWidth() :
"*");
+ this.carouselHolder.addMember(member);
+ }
+
+ public void setListGridDoubleClickHandler(DoubleClickHandler handler) {
+ //doubleClickHandler = handler;
+ }
+
+ /**
+ * Adds extra widgets to the bottom of the carousel view.
+ * <br/><br/>
+ * Note: To prevent user action while a current action completes, all widgets on the
footer are disabled
+ * when footer actions take place, typically a button click. It is up to the action
to ensure the page
+ * (via refresh() or CoreGUI.refresh()) or footer (via refreshCarouselActions) are
refreshed as needed at action
+ * completion. Failure to do so may leave the widgets disabled.
+ *
+ * @param widget the new widget to add to the view
+ * @param aboveFooter if true, the widget will be placed in a second toolstrip just
above the main footer.
+ * if false, the widget will be placed in the main footer
toolstrip itself. This is
+ * useful if the widget is really big and won't fit in the
main footer along with the
+ * rest of the main footer members.
+ */
+ public void addExtraWidget(Canvas widget, boolean aboveFooter) {
+ if (aboveFooter) {
+ this.extraWidgetsAboveFooter.add(widget);
+ } else {
+ this.extraWidgetsInMainFooter.add(widget);
+ }
+ }
+
+ public void setHeaderIcon(String headerIcon) {
+ if (this.titleIcons.size() > 0) {
+ this.titleIcons.clear();
+ }
+ addHeaderIcon(headerIcon);
+ }
+
+ public void addHeaderIcon(String headerIcon) {
+ this.titleIcons.add(headerIcon);
+ }
+
+ /**
+ * By default, all actions have buttons that are enabled or
+ * disabled based on if and how many rows are selected. There are
+ * times when you don't want the user to be able to press action
+ * buttons regardless of which rows are selected. This method let's
+ * you set this override-disable flag.
+ *
+ * Note: this also effects the double-click handler - if this disable override
+ * is on, the double-click handler is not called.
+ *
+ * @param disabled if true, all action buttons will be disabled
+ * if false, action buttons will be enabled based on their
predefined
+ * selection enablement rule.
+ */
+ public void setCarouselActionDisableOverride(boolean disabled) {
+ this.carouselActionDisableOverride = disabled;
+ refreshCarouselInfo();
+ }
+
+ public boolean getCarouselActionDisableOverride() {
+ return this.carouselActionDisableOverride;
+ }
+
+ /**
+ * Refreshes the members, filtered by any fixed criteria, as well as any
user-specified filters.
+ */
+ public void refresh() {
+ Criteria criteria = getCurrentCriteria();
+
+ Map<String, Object> criteriaMap = (criteria != null) ? criteria.getValues()
: Collections
+ .<String, Object> emptyMap();
+ Integer carouselStart;
+ Integer carouselSize;
+ try {
+ carouselSize = Integer.valueOf((String)
criteriaMap.get(FILTER_CAROUSEL_SIZE));
+ } catch (Exception e) {
+ carouselSize = null;
+ }
+ try {
+ carouselStart = Integer.valueOf((String)
criteriaMap.get(FILTER_CAROUSEL_START));
+ } catch (Exception e) {
+ carouselStart = null;
+ }
+ if (carouselStartFilter != carouselStart) {
+ if (null == carouselStartFilter ||
!carouselStartFilter.equals(carouselStart)) {
+ carouselStartFilter = carouselStart;
+ carouselDirty = true;
+ }
+ }
+ if (carouselSizeFilter != carouselSize) {
+ if (null == carouselSizeFilter || !carouselSizeFilter.equals(carouselSize))
{
+ carouselSizeFilter = carouselSize;
+ carouselDirty = true;
+ }
+ }
+
+ // if we're channging the entire carousel then rebuild, otherwise, just
refresh the members
+ if (carouselDirty) {
+ buildCarousel(true);
+
+ } else {
+ for (Canvas member : carouselHolder.getMembers()) {
+ CarouselMember carouselMember = (CarouselMember) member;
+ carouselMember.refresh(criteria);
+ }
+ }
+
+ // TODO: it would be best if this was actually called after the async return of
the member refreshes
+ refreshCarouselInfo();
+ }
+
+ protected void buildCarousel(boolean isRefresh) {
+ if (null != carouselHolder) {
+ carouselHolder.destroyMembers();
+ }
+ }
+
+ public void refreshCarouselInfo() {
+ if (this.showFooter && (this.carouselHolder != null)) {
+ if (this.carouselActionDisableOverride) {
+ //this.listGrid.setSelectionType(SelectionStyle.NONE);
+ } else {
+ //this.listGrid.setSelectionType(getDefaultSelectionStyle());
+ }
+
+ //int selectionCount = this.listGrid.getSelection().length;
+ for (CarouselActionInfo carouselAction : this.carouselActions) {
+ if (carouselAction.actionCanvas != null) { // if null, we haven't
initialized our buttons yet, so skip this
+ boolean enabled = (!this.carouselActionDisableOverride &&
carouselAction.action.isEnabled());
+ carouselAction.actionCanvas.setDisabled(!enabled);
+ }
+ }
+ for (Canvas extraWidget : this.extraWidgetsAboveFooter) {
+ extraWidget.enable();
+ if (extraWidget instanceof CarouselWidget) {
+ ((CarouselWidget) extraWidget).refresh(carouselHolder.getMembers());
+ }
+ }
+ for (Canvas extraWidget : this.extraWidgetsInMainFooter) {
+ extraWidget.enable();
+ if (extraWidget instanceof CarouselWidget) {
+ ((CarouselWidget) extraWidget).refresh(carouselHolder.getMembers());
+ }
+ }
+ refreshRowCount();
+ if (isShowFooterRefresh() && this.refreshButton != null) {
+ this.refreshButton.enable();
+ }
+ }
+ }
+
+ protected String getDataTypeName() {
+ return "item";
+ }
+
+ protected String getDataTypeNamePlural() {
+ return "items";
+ }
+
+ protected String getDeleteConfirmMessage() {
+ return MSG.common_msg_deleteConfirm(getDataTypeNamePlural());
+ }
+
+ // -------------- Inner utility classes ------------- //
+
+ /**
+ * A subclass of SmartGWT's DynamicForm widget that provides a more convenient
interface for filtering a
+ * {@link Carousel} of data.
+ *
+ * @author Joseph Marques
+ */
+ private static class CarouselFilter extends LocatableDynamicForm implements
KeyPressHandler, ChangedHandler,
+ com.google.gwt.event.dom.client.KeyPressHandler {
+
+ private Carousel carousel;
+ private SearchBarItem searchBarItem;
+ private HiddenItem hiddenItem;
+
+ public CarouselFilter(Carousel carousel) {
+ super(carousel.extendLocatorId("CarouselFilter"));
+ setIsGroup(true);
+ setGroupTitle(MSG.common_label_filters());
+ setWidth100();
+ setPadding(5);
+ this.carousel = carousel;
+ }
+
+ @Override
+ public void setItems(FormItem... items) {
+ for (FormItem nextFormItem : items) {
+ nextFormItem.setWrapTitle(false);
+ nextFormItem.setWidth(300); // wider than default
+ if (nextFormItem instanceof TextItem) {
+ nextFormItem.addKeyPressHandler(this);
+ } else if (nextFormItem instanceof SelectItem) {
+ nextFormItem.addChangedHandler(this);
+ } else if (nextFormItem instanceof SearchBarItem) {
+ searchBarItem = (SearchBarItem) nextFormItem;
+ searchBarItem.getSearchBar().addKeyPressHandler(this);
+ String name = searchBarItem.getName();
+ searchBarItem.setName(name + "_hidden");
+ hiddenItem = new HiddenItem(name);
+ hiddenItem.setValue(searchBarItem.getSearchBar().getValue());
+ }
+ }
+
+ if (hiddenItem != null) {
+ FormItem[] tmpItems = new FormItem[items.length + 1];
+ System.arraycopy(items, 0, tmpItems, 0, items.length);
+ tmpItems[items.length] = hiddenItem;
+ items = tmpItems;
+ }
+
+ super.setItems(items);
+ }
+
+ private void fetchFilteredCarouselData() {
+ carousel.refresh();
+ }
+
+ public void onKeyPress(KeyPressEvent event) {
+ if (event.getKeyName().equals("Enter") == false) {
+ return;
+ }
+ fetchFilteredCarouselData();
+ }
+
+ public void onChanged(ChangedEvent event) {
+ fetchFilteredCarouselData();
+ }
+
+ public boolean hasContent() {
+ return super.getFields().length != 0;
+ }
+
+ @Override
+ public void onKeyPress(com.google.gwt.event.dom.client.KeyPressEvent event) {
+ if (event.getCharCode() != KeyCodes.KEY_ENTER) {
+ return;
+ }
+ // TODO: figure out why this event is being sent twice
+ hiddenItem.setValue(searchBarItem.getSearchBar().getValue());
+ fetchFilteredCarouselData();
+ }
+ }
+
+ public static class CarouselActionInfo {
+ private String locatorId;
+ private String title;
+ private String confirmMessage;
+ private LinkedHashMap<String, ? extends Object> valueMap;
+ private CarouselAction action;
+ private Canvas actionCanvas;
+
+ protected CarouselActionInfo(String locatorId, String title, String
confirmMessage,
+ LinkedHashMap<String, ? extends Object> valueMap, CarouselAction
action) {
+ this.locatorId = locatorId;
+ this.title = title;
+ this.confirmMessage = confirmMessage;
+ this.valueMap = valueMap;
+ this.action = action;
+ }
+
+ public String getLocatorId() {
+ return locatorId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String getConfirmMessage() {
+ return confirmMessage;
+ }
+
+ public LinkedHashMap<String, ? extends Object> getValueMap() {
+ return valueMap;
+ }
+
+ public Canvas getActionCanvas() {
+ return actionCanvas;
+ }
+
+ public void setActionCanvas(Canvas actionCanvas) {
+ this.actionCanvas = actionCanvas;
+ }
+
+ public CarouselAction getAction() {
+ return action;
+ }
+
+ public void setAction(CarouselAction action) {
+ this.action = action;
+ }
+
+ }
+
+ public boolean isShowFooterRefresh() {
+ return showFooterRefresh;
+ }
+
+ public void setShowFooterRefresh(boolean showFooterRefresh) {
+ this.showFooterRefresh = showFooterRefresh;
+ }
+
+ public Label getCarouselInfo() {
+ return carouselInfo;
+ }
+
+ public void setCarouselInfo(Label carouselInfo) {
+ this.carouselInfo = carouselInfo;
+ }
+
+ public boolean isShowFilterForm() {
+ return showFilterForm;
+ }
+
+ public void setShowFilterForm(boolean showFilterForm) {
+ this.showFilterForm = showFilterForm;
+ }
+
+ /*
+ * by default, no search bar is shown above this. if this represents a subsystem
that is capable
+ * of search, return the specific object here.
+ */
+ protected SearchSubsystem getSearchSubsystem() {
+ return null;
+ }
+
+ protected Integer getCarouselStartFilter() {
+ return carouselStartFilter;
+ }
+
+ protected void setCarouselStartFilter(Integer carouselStartFilter) {
+ this.carouselStartFilter = carouselStartFilter;
+ this.filterForm.getItem(FILTER_CAROUSEL_START).setValue(carouselStartFilter);
+ this.filterForm.getItem(FILTER_CAROUSEL_START).redraw();
+ }
+
+ protected Integer getCarouselSizeFilter() {
+ return carouselSizeFilter;
+ }
+
+ protected void setCarouselSizeFilter(Integer carouselSizeFilter) {
+ this.carouselSizeFilter = carouselSizeFilter;
+ this.filterForm.getItem(FILTER_CAROUSEL_SIZE).setValue(carouselSizeFilter);
+ this.filterForm.getItem(FILTER_CAROUSEL_SIZE).redraw();
+ }
+
+ protected boolean isCarouselDirty() {
+ return carouselDirty;
+ }
+
+ protected void setCarouselDirty(boolean carouselDirty) {
+ this.carouselDirty = carouselDirty;
+ }
+
+ protected boolean isCarouselUsingFixedWidths() {
+ return carouselUsingFixedWidths;
+ }
+
+ protected void setCarouselUsingFixedWidths(boolean carouselUsingFixedWidths) {
+ this.carouselUsingFixedWidths = carouselUsingFixedWidths;
+ }
+
+ private interface CarouselAction {
+
+ /**
+ * Returns true if the action should be enabled based on the currently selected
record(s).
+ *
+ * @param selection the currently selected record(s)
+ *
+ * @return true if the action should be enabled based on the currently selected
record(s)
+ */
+ boolean isEnabled(); //TODO add arg
+
+ /**
+ * Execute the action with the currently selected record(s) as the target(s).
+ *
+ * @param selection the currently selected record(s)
+ * @param actionValue a value optionally supplied by the action (for example, a
menuItem action's selection)
+ */
+ void executeAction(Object actionValue); //TODO add arg
+ }
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/CarouselMember.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/CarouselMember.java
new file mode 100644
index 0000000..5d6e8b8
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/CarouselMember.java
@@ -0,0 +1,35 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+package org.rhq.enterprise.gui.coregui.client.components.carousel;
+
+import com.smartgwt.client.data.Criteria;
+
+/**
+ * @author Jay Shaughnessy
+ */
+public interface CarouselMember {
+
+ /**
+ * Refresh the carousel member using, if applicable, the current criteria set for the
Carousel.
+ *
+ * @param criteria
+ */
+ void refresh(Criteria criteria);
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/CarouselWidget.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/CarouselWidget.java
new file mode 100644
index 0000000..48f650f
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/carousel/CarouselWidget.java
@@ -0,0 +1,28 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.components.carousel;
+
+import com.smartgwt.client.widgets.Canvas;
+
+/**
+ * @author Jay Shaughnessy
+ */
+public interface CarouselWidget {
+ void refresh(Canvas[] carouselMembers);
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
index 60e52ee..c7ed1de 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/components/table/Table.java
@@ -108,7 +108,7 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
private LocatableVLayout contents;
- private HTMLFlow title;
+ private HTMLFlow titleCanvas;
private HLayout titleLayout;
private Canvas titleComponent;
@@ -124,7 +124,7 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
private boolean showFooterRefresh = true;
private boolean showFilterForm = true;
- private String tableTitle;
+ private String titleString;
private Criteria initialCriteria;
private boolean initialCriteriaFixed = true;
private SortSpecifier[] sortSpecifiers;
@@ -186,7 +186,7 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
setHeight100();
setOverflow(Overflow.HIDDEN);
- this.tableTitle = tableTitle;
+ this.titleString = tableTitle;
this.initialCriteria = criteria;
this.sortSpecifiers = sortSpecifiers;
this.excludedFieldNames = excludedFieldNames;
@@ -296,8 +296,8 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
}
// Title
- this.title = new HTMLFlow();
- setTableTitle(this.tableTitle);
+ this.titleCanvas = new HTMLFlow();
+ updateTitleCanvas(this.titleString);
if (showHeader) {
titleLayout = new
LocatableHLayout(contents.extendLocatorId("Title"));
@@ -413,7 +413,7 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
titleLayout.addMember(img);
}
- titleLayout.addMember(title);
+ titleLayout.addMember(titleCanvas);
if (titleComponent != null) {
titleLayout.addMember(new LayoutSpacer());
@@ -568,17 +568,51 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
}
- public String getTitle() {
- return this.tableTitle;
+ public String getTitleString() {
+ return this.titleString;
}
- public void setTitle(String title) {
- this.tableTitle = title;
- if (this.title != null) {
- setTableTitle(title);
+ /**
+ * Set the Table's title string. This will subsequently call {@link
#updateTitleCanvas(String)}.
+ * @param titleString
+ */
+ public void setTitleString(String titleString) {
+ this.titleString = titleString;
+ if (this.titleCanvas != null) {
+ updateTitleCanvas(titleString);
}
}
+ public Canvas getTitleCanvas() {
+ return this.titleCanvas;
+ }
+
+ /**
+ * To set the Table's title, call {@link #setTitleString(String)}. This is
primarily declared for purposes of
+ * override.
+ * @param titleString
+ */
+ public void updateTitleCanvas(String titleString) {
+ if (titleString == null) {
+ titleString = "";
+ }
+ if (titleString.length() > 0) {
+ titleCanvas.setWidth100();
+ titleCanvas.setHeight(35);
+ titleCanvas.setContents(titleString);
+ titleCanvas.setPadding(4);
+ titleCanvas.setStyleName("HeaderLabel");
+ } else {
+ titleCanvas.setWidth100();
+ titleCanvas.setHeight(0);
+ titleCanvas.setContents(null);
+ titleCanvas.setPadding(0);
+ titleCanvas.setStyleName("normal");
+ }
+
+ titleCanvas.markForRedraw();
+ }
+
/**
* Returns the encompassing canvas that contains all content for this table
component.
* This content includes the list grid, the buttons, etc.
@@ -615,6 +649,18 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
}
}
+ protected Criteria getInitialCriteria() {
+ return initialCriteria;
+ }
+
+ /**
+ * Can be called in constructor to reset initialCriteria.
+ * @param initialCriteria
+ */
+ protected void setInitialCriteria(Criteria initialCriteria) {
+ this.initialCriteria = initialCriteria;
+ }
+
protected boolean isInitialCriteriaFixed() {
return initialCriteriaFixed;
}
@@ -693,27 +739,6 @@ public class Table<DS extends RPCDataSource> extends
LocatableHLayout implements
}
}
- public void setTableTitle(String titleString) {
- if (titleString == null) {
- titleString = "";
- }
- if (titleString.length() > 0) {
- title.setWidth100();
- title.setHeight(35);
- title.setContents(titleString);
- title.setPadding(4);
- title.setStyleName("HeaderLabel");
- } else {
- title.setWidth100();
- title.setHeight(0);
- title.setContents(null);
- title.setPadding(0);
- title.setStyleName("normal");
- }
-
- title.markForRedraw();
- }
-
public DS getDataSource() {
return dataSource;
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeDataSource.java
index e8fb327..6935d42 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeDataSource.java
@@ -36,7 +36,7 @@ import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
import org.rhq.core.domain.criteria.GenericDriftCriteria;
import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftChangeSet;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.util.PageList;
import org.rhq.core.domain.util.PageOrdering;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
@@ -194,9 +194,9 @@ public abstract class AbstractDriftChangeSetsTreeDataSource extends
RPCDataSourc
@Override
public ListGridRecord copyValues(Object from) {
TreeNode node;
- if (from instanceof DriftConfiguration) {
- DriftConfiguration driftConfig = (DriftConfiguration) from;
- node = new
AbstractDriftChangeSetsTreeView.DriftConfigurationTreeNode(driftConfig);
+ if (from instanceof DriftDefinition) {
+ DriftDefinition driftConfig = (DriftDefinition) from;
+ node = new
AbstractDriftChangeSetsTreeView.DriftDefinitionTreeNode(driftConfig);
} else if (from instanceof DriftChangeSet) {
DriftChangeSet changeset = (DriftChangeSet) from;
node = new AbstractDriftChangeSetsTreeView.ChangeSetTreeNode(changeset);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeView.java
index fb63830..329d331 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/AbstractDriftChangeSetsTreeView.java
@@ -43,7 +43,7 @@ import com.smartgwt.client.widgets.tree.events.NodeContextClickHandler;
import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftChangeSet;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.ImageManager;
@@ -102,8 +102,8 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
TreeNode eventNode = event.getNode();
Menu menu = null;
- if (eventNode instanceof DriftConfigurationTreeNode) {
- menu =
buildDriftConfigurationTreeNodeContextMenu((DriftConfigurationTreeNode) eventNode);
+ if (eventNode instanceof DriftDefinitionTreeNode) {
+ menu =
buildDriftConfigurationTreeNodeContextMenu((DriftDefinitionTreeNode) eventNode);
} else if (eventNode instanceof ChangeSetTreeNode) {
menu = buildChangeSetTreeNodeContextMenu((ChangeSetTreeNode)
eventNode);
} else if (eventNode instanceof DriftTreeNode) {
@@ -182,21 +182,21 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
*
* @param doomedDriftConfig the drift config to remove
*/
- protected abstract void deleteDriftConfiguration(DriftConfiguration
doomedDriftConfig);
+ protected abstract void deleteDriftDefinition(DriftDefinition doomedDriftConfig);
/**
* Immediately asks for a drift detection scan to be run.
*
* @param driftConfiguration identifies the drift whose detection scan should be
initiated.
*/
- protected abstract void detectDrift(DriftConfiguration driftConfiguration);
+ protected abstract void detectDrift(DriftDefinition driftConfiguration);
/**
* Builds the right-mouse-click context menu for the given drift configuration node
* @param node the drift configuration node whose menu is to be displayed
* @return the context menu to display
*/
- protected Menu buildDriftConfigurationTreeNodeContextMenu(final
DriftConfigurationTreeNode node) {
+ protected Menu buildDriftConfigurationTreeNodeContextMenu(final
DriftDefinitionTreeNode node) {
Menu contextMenu = new Menu();
@@ -218,8 +218,8 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
deleteItem.setIcon(Window.getImgURL(ImageManager.getRemoveIcon()));
deleteItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
- DriftConfiguration driftConfig = node.getDriftConfiguration();
- deleteDriftConfiguration(driftConfig);
+ DriftDefinition driftConfig = node.getDriftConfiguration();
+ deleteDriftDefinition(driftConfig);
}
});
contextMenu.addItem(deleteItem);
@@ -228,7 +228,7 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
MenuItem detectNowItem = new MenuItem(MSG.view_drift_button_detectNow());
detectNowItem.addClickHandler(new ClickHandler() {
public void onClick(MenuItemClickEvent event) {
- DriftConfiguration driftConfig = node.getDriftConfiguration();
+ DriftDefinition driftConfig = node.getDriftConfiguration();
detectDrift(driftConfig);
}
});
@@ -323,10 +323,10 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
return ((TreeNode) node).getTitle();
}
- static class DriftConfigurationTreeNode extends TreeNode {
+ static class DriftDefinitionTreeNode extends TreeNode {
public static final String ATTR_DRIFT_CONFIG_OBJECT = "object";
- public DriftConfigurationTreeNode(DriftConfiguration driftConfig) {
+ public DriftDefinitionTreeNode(DriftDefinition driftConfig) {
setIsFolder(true);
if (driftConfig.isEnabled()) {
setIcon("subsystems/drift/DriftConfig_Folder_16.png");
@@ -339,13 +339,13 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
setAttribute(ATTR_DRIFT_CONFIG_OBJECT, driftConfig);
}
- public int getDriftConfigurationId() {
+ public int getDriftDefinitionId() {
String idAttrib = getAttribute("id");
return Integer.parseInt(idAttrib);
}
- public DriftConfiguration getDriftConfiguration() {
- return (DriftConfiguration) getAttributeAsObject(ATTR_DRIFT_CONFIG_OBJECT);
+ public DriftDefinition getDriftConfiguration() {
+ return (DriftDefinition) getAttributeAsObject(ATTR_DRIFT_CONFIG_OBJECT);
}
@Override
@@ -353,7 +353,7 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
return super.getName();
}
- private String buildNodeName(DriftConfiguration driftConfig) {
+ private String buildNodeName(DriftDefinition driftConfig) {
return driftConfig.getName();
}
}
@@ -362,7 +362,7 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
public ChangeSetTreeNode(DriftChangeSet<?> changeset) {
setIsFolder(true);
setShowOpenIcon(true);
- String parentID = String.valueOf(changeset.getDriftConfigurationId());
+ String parentID = String.valueOf(changeset.getDriftDefinitionId());
setParentID(parentID);
setID(parentID + "_" + changeset.getId());
setName(padWithZeroes(changeset.getVersion())); // we sort on this column,
hence we make sure the version # is padded
@@ -405,7 +405,7 @@ public abstract class AbstractDriftChangeSetsTreeView extends
LocatableTreeGrid
setIsFolder(false);
setIcon(ImageManager.getDriftCategoryIcon(drift.getCategory()));
DriftChangeSet<?> changeset = drift.getChangeSet();
- setParentID(String.valueOf(changeset.getDriftConfigurationId()) +
"_" + changeset.getId());
+ setParentID(String.valueOf(changeset.getDriftDefinitionId()) + "_"
+ changeset.getId());
setID('D' + drift.getId()); // prefix with a 'D' so it
doesn't conflict with driftConfig node IDs
setName(drift.getPath()); // we sort on this column
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftCarouselMemberView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftCarouselMemberView.java
new file mode 100644
index 0000000..2276dd9
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftCarouselMemberView.java
@@ -0,0 +1,189 @@
+/*
+ * RHQ Management Platform
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift;
+
+import java.util.ArrayList;
+import java.util.Date;
+
+import com.smartgwt.client.data.Criteria;
+import com.smartgwt.client.data.DSRequest;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.grid.HoverCustomizer;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.criteria.GenericDriftCriteria;
+import org.rhq.core.domain.drift.DriftChangeSet;
+import org.rhq.core.domain.resource.composite.ResourceComposite;
+import org.rhq.enterprise.gui.coregui.client.components.carousel.CarouselMember;
+import org.rhq.enterprise.gui.coregui.client.components.table.TimestampCellFormatter;
+
+/**
+ * @author Jay Shaughnessy
+ */
+@SuppressWarnings("unchecked")
+public class DriftCarouselMemberView extends DriftHistoryView implements CarouselMember
{
+
+ private DriftChangeSet changeSet;
+ private Criteria carouselCriteria;
+
+ public static DriftCarouselMemberView get(String locatorId, ResourceComposite
composite,
+ DriftChangeSet driftChangeSet) {
+ //String tableTitle = MSG.view_drift_table_resourceHistory();
+ EntityContext context =
EntityContext.forResource(composite.getResource().getId());
+ boolean hasWriteAccess = composite.getResourcePermission().isDrift();
+ return new DriftCarouselMemberView(locatorId, context, driftChangeSet,
hasWriteAccess);
+ }
+
+ public DriftCarouselMemberView(String locatorId, EntityContext context,
DriftChangeSet driftChangeSet,
+ boolean hasWriteAccess) {
+
+ super(locatorId, null, context, hasWriteAccess);
+
+ this.changeSet = driftChangeSet;
+ ((DriftCarouselDataSource)
getDataSource()).setChangeSetId(this.changeSet.getId());
+
+ // no need to refresh the drift instances, they are fixed.
+ setShowFooterRefresh(false);
+
+ //setWidth("500px");
+ }
+
+ @Override
+ public DriftDataSource getDataSource() {
+ if (null == dataSource) {
+ dataSource = new DriftCarouselDataSource(getContext());
+ }
+
+ return dataSource;
+ }
+
+ @Override
+ protected void configureTableFilters() {
+ // filter settings come from the Carousel view and are applied to all Drift
views
+ }
+
+ @Override
+ protected Criteria getCurrentCriteria() {
+ return carouselCriteria;
+ }
+
+ @Override
+ public void refresh(Criteria carouselCriteria) {
+ this.carouselCriteria = carouselCriteria;
+ super.refresh();
+ }
+
+ public void updateTitleCanvas(String titleString) {
+ StringBuilder sb = new StringBuilder("<span
class=\"HeaderLabel\">");
+ sb.append(MSG.view_drift_table_snapshot());
+ sb.append(" ");
+ sb.append(changeSet.getVersion());
+ sb.append("</span><br/>");
+ sb.append(TimestampCellFormatter.DATE_TIME_FORMAT_MEDIUM.format(new
Date(this.changeSet.getCtime())));
+
+ Canvas titleCanvas = getTitleCanvas();
+ titleCanvas.setWidth100();
+ titleCanvas.setHeight(35);
+ titleCanvas.setContents(sb.toString());
+ titleCanvas.setPadding(4);
+
+ titleCanvas.markForRedraw();
+ }
+
+ public static class DriftCarouselDataSource extends DriftDataSource {
+
+ private String changeSetId;
+
+ /**
+ * Note, the changeSetId must be set prior to any fetches.
+ * @param context
+ */
+ DriftCarouselDataSource(EntityContext context) {
+ super(context);
+ }
+
+ protected String getChangeSetId() {
+ return changeSetId;
+ }
+
+ protected void setChangeSetId(String changeSetId) {
+ this.changeSetId = changeSetId;
+ }
+
+ @Override
+ protected GenericDriftCriteria getFetchCriteria(DSRequest request) {
+ GenericDriftCriteria criteria = super.getFetchCriteria(request);
+
+ if (null == criteria) {
+ criteria = new GenericDriftCriteria();
+ }
+
+ criteria.addFilterChangeSetId(changeSetId);
+ return criteria;
+ }
+
+ /**
+ * The view that contains the list grid which will display this datasource's
data will call this
+ * method to get the field information which is used to control the display of
the data.
+ *
+ * @return list grid fields used to display the datasource data
+ */
+ @Override
+ public ArrayList<ListGridField> getListGridFields() {
+ ArrayList<ListGridField> fields = new
ArrayList<ListGridField>(7);
+
+ ListGridField categoryField = new ListGridField(ATTR_CATEGORY,
MSG.common_title_category());
+ categoryField.setType(ListGridFieldType.IMAGE);
+ categoryField.setAlign(Alignment.CENTER);
+ categoryField.setShowHover(true);
+ categoryField.setHoverCustomizer(new HoverCustomizer() {
+ @Override
+ public String hoverHTML(Object value, ListGridRecord record, int rowNum,
int colNum) {
+ String cat = record.getAttribute(ATTR_CATEGORY);
+ if (CATEGORY_ICON_ADD.equals(cat)) {
+ return MSG.view_drift_category_fileAdded();
+ } else if (CATEGORY_ICON_CHANGE.equals(cat)) {
+ return MSG.view_drift_category_fileChanged();
+ } else if (CATEGORY_ICON_REMOVE.equals(cat)) {
+ return MSG.view_drift_category_fileRemoved();
+ } else if (CATEGORY_ICON_NEW.equals(cat)) {
+ return MSG.view_drift_category_fileNew();
+ } else {
+ return ""; // will never get here
+ }
+ }
+ });
+ fields.add(categoryField);
+
+ ListGridField pathField = new ListGridField(ATTR_PATH,
MSG.common_title_path());
+ fields.add(pathField);
+
+ categoryField.setWidth(80);
+ pathField.setWidth("*");
+
+ return fields;
+ }
+ }
+
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftCarouselView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftCarouselView.java
new file mode 100644
index 0000000..e653144
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftCarouselView.java
@@ -0,0 +1,201 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift;
+
+import java.util.LinkedHashMap;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.widgets.form.fields.SelectItem;
+import com.smartgwt.client.widgets.form.fields.TextItem;
+
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.criteria.DriftDefinitionCriteria;
+import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
+import org.rhq.core.domain.drift.DriftCategory;
+import org.rhq.core.domain.drift.DriftChangeSet;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.core.domain.util.PageOrdering;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.ImageManager;
+import org.rhq.enterprise.gui.coregui.client.components.carousel.Carousel;
+import org.rhq.enterprise.gui.coregui.client.components.form.EnumSelectItem;
+import org.rhq.enterprise.gui.coregui.client.gwt.DriftGWTServiceAsync;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+
+/**
+ * @author Jay Shaughnessy
+ */
+public class DriftCarouselView extends Carousel {
+
+ private static final int CAROUSEL_DEFAULT_SIZE = 4;
+ private static final String CAROUSEL_MEMBER_FIXED_WIDTH = "250px";
+
+ private int driftDefId;
+ private EntityContext context;
+ private boolean hasWriteAccess;
+
+ private DriftGWTServiceAsync driftService = GWTServiceLookup.getDriftService();
+
+ public DriftCarouselView(String locatorId, EntityContext entityContext, int
driftDefId, boolean hasWriteAccess) {
+ super(locatorId);
+
+ this.context = entityContext;
+ this.driftDefId = driftDefId;
+ this.hasWriteAccess = hasWriteAccess;
+ }
+
+ @Override
+ protected void onDraw() {
+
+ DriftDefinitionCriteria defCriteria = new DriftDefinitionCriteria();
+ defCriteria.addFilterId(driftDefId);
+ defCriteria.fetchConfiguration(true);
+
+ driftService.findDriftDefinitionsByCriteria(defCriteria, new
AsyncCallback<PageList<DriftDefinition>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(MSG.view_drift_failure_load(),
caught);
+ }
+
+ public void onSuccess(PageList<DriftDefinition> result) {
+ // Create and add the details canvas for the def
+ addTitleString(result.get(0));
+
+ buildCarousel(false);
+ }
+ });
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void buildCarousel(final boolean isRefresh) {
+ super.buildCarousel(isRefresh);
+
+ // Fetch the ChangeSet headers
+ GenericDriftChangeSetCriteria changeSetCriteria = new
GenericDriftChangeSetCriteria();
+ changeSetCriteria.addFilterDriftDefinitionId(driftDefId);
+ setChangeSetVersionCriteria(changeSetCriteria);
+
+ changeSetCriteria.addSortVersion(PageOrdering.DESC);
+
+ driftService.findDriftChangeSetsByCriteria(changeSetCriteria,
+ new AsyncCallback<PageList<? extends DriftChangeSet>>() {
+
+ public void onSuccess(PageList<? extends DriftChangeSet> result) {
+
+ Integer carouselSize = getCarouselSizeFilter();
+ carouselSize = (null == carouselSize || carouselSize < 1) ?
CAROUSEL_DEFAULT_SIZE : carouselSize;
+ int size = carouselSize;
+ Integer carouselStart = null;
+
+ for (DriftChangeSet changeSet : result) {
+ DriftCarouselMemberView view = new
DriftCarouselMemberView(extendLocatorId(changeSet
+ .getId()), context, changeSet, hasWriteAccess);
+ addCarouselMember(view);
+
+ if (null == carouselStart) {
+ carouselStart = changeSet.getVersion();
+ }
+
+ if (--size == 0) {
+ break;
+ }
+ }
+
+ if (!isRefresh) {
+ DriftCarouselView.super.onDraw();
+ }
+
+ setCarouselStartFilter(carouselStart);
+ setCarouselSizeFilter(carouselSize);
+ setCarouselDirty(false);
+ }
+
+ public void onFailure(Throwable caught) {
+
CoreGUI.getErrorHandler().handleError(MSG.view_drift_snapshots_tree_loadFailure(),
caught);
+ }
+ });
+ }
+
+ @Override
+ protected int getDefaultCarouselSize() {
+ return CAROUSEL_DEFAULT_SIZE;
+ }
+
+ @Override
+ protected String getCarouselMemberFixedWidth() {
+ return CAROUSEL_MEMBER_FIXED_WIDTH;
+ }
+
+ private void setChangeSetVersionCriteria(GenericDriftChangeSetCriteria
changeSetCriteria) {
+ Integer carouselStart;
+
+ try {
+ carouselStart = Integer.valueOf(getCarouselStartFilter());
+ } catch (Exception e) {
+ carouselStart = null;
+ }
+
+ if (null != carouselStart) {
+ changeSetCriteria.addFilterEndVersion(String.valueOf(carouselStart));
+ }
+ changeSetCriteria.addFilterStartVersion("1");
+ }
+
+ private void addTitleString(DriftDefinition driftDef) {
+
+ setTitleString(driftDef.getName());
+ }
+
+ @Override
+ protected void configureCarouselFilters() {
+ // drift category filter
+ LinkedHashMap<String, String> categories = new LinkedHashMap<String,
String>(3);
+ categories.put(DriftCategory.FILE_ADDED.name(),
MSG.view_drift_category_fileAdded());
+ categories.put(DriftCategory.FILE_CHANGED.name(),
MSG.view_drift_category_fileChanged());
+ categories.put(DriftCategory.FILE_REMOVED.name(),
MSG.view_drift_category_fileRemoved());
+ LinkedHashMap<String, String> categoryIcons = new LinkedHashMap<String,
String>(3);
+ categoryIcons.put(DriftCategory.FILE_ADDED.name(),
ImageManager.getDriftCategoryIcon(DriftCategory.FILE_ADDED));
+ categoryIcons.put(DriftCategory.FILE_CHANGED.name(), ImageManager
+ .getDriftCategoryIcon(DriftCategory.FILE_CHANGED));
+ categoryIcons.put(DriftCategory.FILE_REMOVED.name(), ImageManager
+ .getDriftCategoryIcon(DriftCategory.FILE_REMOVED));
+ SelectItem categoryFilter = new EnumSelectItem(DriftDataSource.FILTER_CATEGORIES,
MSG.common_title_category(),
+ DriftCategory.class, categories, categoryIcons);
+
+ // drift file path filter
+ TextItem pathFilter = new TextItem(DriftDataSource.FILTER_PATH,
MSG.common_title_path());
+ pathFilter.setEndRow(true);
+
+ if (isShowFilterForm()) {
+ setFilterFormItems(categoryFilter, pathFilter);
+ }
+ }
+
+ @Override
+ protected String getCarouselStartFilterLabel() {
+ return MSG.view_drift_carousel_startFilterLabel();
+ }
+
+ @Override
+ protected String getCarouselSizeFilterLabel() {
+ return MSG.view_drift_carousel_sizeFilterLabel();
+ }
+
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationDataSource.java
deleted file mode 100644
index 189f398..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationDataSource.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.drift;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.data.DSRequest;
-import com.smartgwt.client.data.DSResponse;
-import com.smartgwt.client.data.Record;
-import com.smartgwt.client.rpc.RPCResponse;
-import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.ListGridFieldType;
-import com.smartgwt.client.widgets.grid.CellFormatter;
-import com.smartgwt.client.widgets.grid.HoverCustomizer;
-import com.smartgwt.client.widgets.grid.ListGridField;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-
-import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.criteria.DriftConfigurationCriteria;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfiguration.BaseDirectory;
-import org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.ImageManager;
-import org.rhq.enterprise.gui.coregui.client.LinkManager;
-import org.rhq.enterprise.gui.coregui.client.gwt.DriftGWTServiceAsync;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
-import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
-
-/**
- * @author Jay Shaughnessy
- * @author John Mazzitelli
- */
-public class DriftConfigurationDataSource extends RPCDataSource<DriftConfiguration,
DriftConfigurationCriteria> {
-
- public static final String ATTR_ENTITY = "object";
- public static final String ATTR_ID = "id";
- public static final String ATTR_NAME = "name";
- public static final String ATTR_INTERVAL = "interval";
- public static final String ATTR_DRIFT_HANDLING_MODE = "driftHandlingMode";
- public static final String ATTR_BASE_DIR_STRING = "baseDirString";
- public static final String ATTR_ENABLED = "enabled";
-
- public static final String DRIFT_HANDLING_MODE_NORMAL =
MSG.view_drift_table_driftHandlingMode_normal();
- public static final String DRIFT_HANDLING_MODE_PLANNED =
MSG.view_drift_table_driftHandlingMode_plannedChanges();
-
- private DriftGWTServiceAsync driftService = GWTServiceLookup.getDriftService();
- private EntityContext entityContext;
-
- public DriftConfigurationDataSource() {
- this(EntityContext.forSubsystemView());
- }
-
- public DriftConfigurationDataSource(EntityContext context) {
- this.entityContext = context;
- addDataSourceFields();
- }
-
- /**
- * The view that contains the list grid which will display this datasource's data
will call this
- * method to get the field information which is used to control the display of the
data.
- *
- * @return list grid fields used to display the datasource data
- */
- public ArrayList<ListGridField> getListGridFields() {
- ArrayList<ListGridField> fields = new ArrayList<ListGridField>(6);
-
- ListGridField nameField = new ListGridField(ATTR_NAME, MSG.common_title_name());
- fields.add(nameField);
-
- ListGridField enabledField = new ListGridField(ATTR_ENABLED,
MSG.common_title_enabled());
- enabledField.setType(ListGridFieldType.IMAGE);
- enabledField.setAlign(Alignment.CENTER);
- fields.add(enabledField);
-
- ListGridField driftHandlingModeField = new
ListGridField(ATTR_DRIFT_HANDLING_MODE, MSG
- .view_drift_table_driftHandlingMode());
- fields.add(driftHandlingModeField);
-
- ListGridField intervalField = new ListGridField(ATTR_INTERVAL,
MSG.common_title_interval());
- fields.add(intervalField);
-
- ListGridField baseDirField = new ListGridField(ATTR_BASE_DIR_STRING,
MSG.view_drift_table_baseDir());
- // can't sort on this because it's not an entity field, it's derived
from the config only
- baseDirField.setCanSort(false);
- fields.add(baseDirField);
-
- if (this.entityContext.type != EntityContext.Type.Resource) {
- ListGridField resourceNameField = new
ListGridField(AncestryUtil.RESOURCE_NAME, MSG.common_title_resource());
- resourceNameField.setCellFormatter(new CellFormatter() {
- public String format(Object o, ListGridRecord listGridRecord, int i, int
i1) {
- Integer resourceId =
listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID);
- String url = LinkManager.getResourceLink(resourceId);
- return SeleniumUtility.getLocatableHref(url, o.toString(), null);
- }
- });
- resourceNameField.setShowHover(true);
- resourceNameField.setHoverCustomizer(new HoverCustomizer() {
- public String hoverHTML(Object value, ListGridRecord listGridRecord, int
rowNum, int colNum) {
- return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
- }
- });
- fields.add(resourceNameField);
-
- ListGridField ancestryField = AncestryUtil.setupAncestryListGridField();
- fields.add(ancestryField);
-
- nameField.setWidth("20%");
- enabledField.setWidth(60);
- driftHandlingModeField.setWidth("10%");
- intervalField.setWidth(100);
- baseDirField.setWidth("*");
- resourceNameField.setWidth("20%");
- ancestryField.setWidth("40%");
- } else {
- nameField.setWidth("20%");
- enabledField.setWidth(60);
- driftHandlingModeField.setWidth("10%");
- intervalField.setWidth(100);
- baseDirField.setWidth("*");
- }
-
- return fields;
- }
-
- @Override
- protected void executeFetch(final DSRequest request, final DSResponse response,
- final DriftConfigurationCriteria criteria) {
- this.driftService.findDriftConfigurationsByCriteria(criteria,
- new AsyncCallback<PageList<DriftConfiguration>>() {
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_drift_failure_load(),
caught);
- response.setStatus(RPCResponse.STATUS_FAILURE);
- processResponse(request.getRequestId(), response);
- }
-
- public void onSuccess(PageList<DriftConfiguration> result) {
- dataRetrieved(result, response, request);
- }
- });
- }
-
- /**
- * Additional processing to support entity-specific or cross-resource views, and
something that can be overidden.
- */
- protected void dataRetrieved(final PageList<DriftConfiguration> result, final
DSResponse response,
- final DSRequest request) {
- switch (entityContext.type) {
-
- // no need to disambiguate, the drift configs are for a single resource
- case Resource:
- response.setData(buildRecords(result));
- // for paging to work we have to specify size of full result set
- response.setTotalRows(getTotalRows(result, response, request));
- processResponse(request.getRequestId(), response);
- break;
-
- case ResourceGroup:
- //TODO
-
- default:
- throw new IllegalArgumentException("Unsupported Context Type: " +
entityContext);
- }
- }
-
- /**
- * Sub-classes can override this to add fine-grained control over the result set
size. By default the
- * total rows are set to the total result set for the query, allowing proper paging.
But some views (portlets)
- * may want to limit results to a small set (like most recent).
- * @param result
- * @param response
- * @param request
- *
- * @return should not exceed result.size().
- */
- protected int getTotalRows(final Collection<DriftConfiguration> result, final
DSResponse response,
- final DSRequest request) {
- return result.size();
- }
-
- @Override
- protected DriftConfigurationCriteria getFetchCriteria(DSRequest request) {
-
- DriftConfigurationCriteria criteria = new DriftConfigurationCriteria();
- switch (entityContext.getType()) {
- case Resource:
- criteria.addFilterResourceIds(entityContext.getResourceId());
- break;
-
- case ResourceGroup:
- //TODO
-
- default:
- // no filter
- }
-
- criteria.fetchConfiguration(true);
- criteria.setPageControl(getPageControl(request));
-
- return criteria;
- }
-
- /*
- @Override
- protected String getSortFieldForColumn(String columnName) {
- if (AncestryUtil.RESOURCE_ANCESTRY.equals(columnName)) {
- return "ancestry";
- }
-
- return super.getSortFieldForColumn(columnName);
- }
- */
-
- @Override
- public DriftConfiguration copyValues(Record from) {
- return (DriftConfiguration) from.getAttributeAsObject(ATTR_ENTITY);
- }
-
- @Override
- public ListGridRecord copyValues(DriftConfiguration from) {
- return convert(from);
- }
-
- public static ListGridRecord convert(DriftConfiguration from) {
- ListGridRecord record = new ListGridRecord();
-
- record.setAttribute(ATTR_ENTITY, from);
-
- record.setAttribute(ATTR_ID, from.getId());
- record.setAttribute(ATTR_NAME, from.getName());
- record.setAttribute(ATTR_DRIFT_HANDLING_MODE,
getDriftHandlingModeDisplayName(from.getDriftHandlingMode()));
- record.setAttribute(ATTR_INTERVAL, String.valueOf(from.getInterval()));
- record.setAttribute(ATTR_BASE_DIR_STRING, getBaseDirString(from.getBasedir()));
- record.setAttribute(ATTR_ENABLED,
ImageManager.getAvailabilityIcon(from.isEnabled()));
-
- // // for ancestry handling
- // Resource resource = ...
- // record.setAttribute(AncestryUtil.RESOURCE_ID, resource.getId());
- // record.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
- // record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
- // record.setAttribute(AncestryUtil.RESOURCE_TYPE_ID,
resource.getResourceType().getId());
-
- return record;
- }
-
- public static String getDriftHandlingModeDisplayName(DriftHandlingMode
driftHandlingMode) {
- switch (driftHandlingMode) {
- case plannedChanges:
- return DRIFT_HANDLING_MODE_PLANNED;
-
- default:
- return DRIFT_HANDLING_MODE_NORMAL;
- }
- }
-
- private static String getBaseDirString(BaseDirectory basedir) {
- return basedir.getValueContext() + ":" + basedir.getValueName();
- }
-
- protected EntityContext getEntityContext() {
- return entityContext;
- }
-
- protected void setEntityContext(EntityContext entityContext) {
- this.entityContext = entityContext;
- }
-
-}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
deleted file mode 100644
index 0ae1f7a..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationEditView.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.drift;
-
-import java.util.EnumSet;
-import java.util.Map;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.widgets.IButton;
-import com.smartgwt.client.widgets.events.ClickEvent;
-import com.smartgwt.client.widgets.events.ClickHandler;
-import com.smartgwt.client.widgets.toolbar.ToolStrip;
-
-import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfigurationDefinition;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.LinkManager;
-import org.rhq.enterprise.gui.coregui.client.RefreshableView;
-import
org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
-import
org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeEvent;
-import
org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeListener;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import
org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceDetailView;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-import org.rhq.enterprise.gui.coregui.client.util.message.MessageCenter;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-
-/**
- * A view for editing a Resource's configuration.
- *
- * @author Jay Shaughnessy
- */
-public class DriftConfigurationEditView extends LocatableVLayout implements
PropertyValueChangeListener,
- RefreshableView {
-
- private EntityContext context;
- private int driftConfigId;
- private boolean hasWriteAccess;
- private ConfigurationEditor editor;
- private ToolStrip buttonbar;
- private IButton saveButton;
-
- private boolean refreshing = false;
-
- public DriftConfigurationEditView(String locatorId, EntityContext context, int
driftConfigId, boolean hasWriteAccess) {
- super(locatorId);
-
- this.context = context;
- this.driftConfigId = driftConfigId;
- this.hasWriteAccess = hasWriteAccess;
- }
-
- @Override
- protected void onDraw() {
- super.onDraw();
-
- this.buttonbar = new ToolStrip();
- buttonbar.setWidth100();
- buttonbar.setExtraSpace(10);
- buttonbar.setMembersMargin(5);
- buttonbar.setLayoutMargin(5);
-
- this.saveButton = new LocatableIButton(this.extendLocatorId("Save"),
MSG.common_button_save());
- this.saveButton.addClickHandler(new ClickHandler() {
- public void onClick(ClickEvent clickEvent) {
- save();
- }
- });
- buttonbar.addMember(saveButton);
- // The button bar will remain hidden until the configuration has been
successfully loaded.
- buttonbar.setVisible(false);
- addMember(buttonbar);
-
- refresh();
-
- if (!this.hasWriteAccess) {
- Message message = new Message(MSG.view_configurationDetails_noPermission(),
Message.Severity.Info, EnumSet
- .of(Message.Option.Transient, Message.Option.Sticky));
- CoreGUI.getMessageCenter().notify(message);
- }
- }
-
- @Override
- public void refresh() {
- if (this.refreshing) {
- return; // we are already in the process of refreshing, don't do it
again
- }
-
- this.refreshing = true;
- this.buttonbar.setVisible(false);
-
- if (editor != null) {
- editor.destroy();
- removeMember(editor);
- }
-
- GWTServiceLookup.getDriftService().getDriftConfiguration(driftConfigId,
- new AsyncCallback<DriftConfiguration>() {
- @Override
- public void onSuccess(final DriftConfiguration result) {
-
- editor = new ConfigurationEditor(extendLocatorId("Editor"),
DriftConfigurationDefinition
- .getInstanceForExistingConfiguration(),
result.getConfiguration());
- editor.setOverflow(Overflow.AUTO);
-
editor.addPropertyValueChangeListener(DriftConfigurationEditView.this);
- editor.setReadOnly(!hasWriteAccess);
- addMember(editor);
-
- saveButton.disable();
- buttonbar.setVisible(true);
- markForRedraw();
- refreshing = false;
- }
-
- @Override
- public void onFailure(Throwable caught) {
- refreshing = false;
- CoreGUI.getErrorHandler().handleError("Failed to load
configuration.", caught);
- }
- });
- }
-
- private void save() {
- Configuration updatedConfiguration = editor.getConfiguration();
-
- GWTServiceLookup.getDriftService().updateDriftConfiguration(context,
- new DriftConfiguration(updatedConfiguration), new AsyncCallback<Void>()
{
- public void onFailure(Throwable caught) {
-
CoreGUI.getErrorHandler().handleError(MSG.view_configurationDetails_error_updateFailure(),
caught);
- }
-
- public void onSuccess(Void result) {
- Message message = new Message(MSG.view_drift_success_defUpdated(),
Message.Severity.Info);
-
- switch (context.getType()) {
- case Resource:
- int resourceId = context.getResourceId();
-
- String driftHistoryUrl =
LinkManager.getResourceTabLink(resourceId,
- ResourceDetailView.Tab.DRIFT,
ResourceDetailView.ConfigurationSubTab.HISTORY);
- driftHistoryUrl = driftHistoryUrl.substring(1); // chop off the
leading '#'
- CoreGUI.goToView(driftHistoryUrl, message);
-
- break;
-
- default:
- throw new IllegalArgumentException("Entity Context Type not
supported [" + context + "]");
- }
- }
- });
- }
-
- @Override
- public void propertyValueChanged(PropertyValueChangeEvent event) {
- MessageCenter messageCenter = CoreGUI.getMessageCenter();
- Message message;
- if (event.isInvalidPropertySetChanged()) {
- Map<String, String> invalidPropertyNames =
event.getInvalidPropertyNames();
- if (invalidPropertyNames.isEmpty()) {
- this.saveButton.enable();
- message = new Message(MSG.view_configurationDetails_allPropertiesValid(),
Message.Severity.Info,
- EnumSet.of(Message.Option.Transient, Message.Option.Sticky));
- } else {
- this.saveButton.disable();
- message = new
Message(MSG.view_configurationDetails_somePropertiesInvalid(invalidPropertyNames.values()
- .toString()), Message.Severity.Error,
EnumSet.of(Message.Option.Transient, Message.Option.Sticky));
- }
- messageCenter.notify(message);
- } else {
- this.saveButton.enable();
- }
- }
-
-}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationView.java
deleted file mode 100644
index 00fa49f..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftConfigurationView.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright 2011, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.drift;
-
-import java.util.ArrayList;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.smartgwt.client.data.Criteria;
-import com.smartgwt.client.data.Record;
-import com.smartgwt.client.data.RecordList;
-import com.smartgwt.client.data.ResultSet;
-import com.smartgwt.client.data.SortSpecifier;
-import com.smartgwt.client.types.SortDirection;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.grid.ListGrid;
-import com.smartgwt.client.widgets.grid.ListGridField;
-import com.smartgwt.client.widgets.grid.ListGridRecord;
-
-import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.drift.DriftCategory;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
-import org.rhq.enterprise.gui.coregui.client.components.table.TableAction;
-import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
-import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
-import org.rhq.enterprise.gui.coregui.client.components.view.ViewName;
-import org.rhq.enterprise.gui.coregui.client.drift.wizard.DriftAddConfigWizard;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-
-/**
- * A view that displays a paginated table of {@link
org.rhq.core.domain.drift.DriftConfiguration}s, along with the
- * ability to filter (maybe) those drift configs, sort those drift configs, double-click
a row to view/edit the
- * drift config, and perform various actionns: add/delete, etc.
- * This view full respects the user's authorization, and will not allow actions on
the drifts unless the user is
- * either the inventory manager or has MANAGE_DRIFT permission on every resource
corresponding to the drift configs
- * being operated on.
- *
- * @author Jay Shaughnessy
- */
-public class DriftConfigurationView extends
TableSection<DriftConfigurationDataSource> {
-
- public static final ViewName SUBSYSTEM_VIEW_ID = new ViewName("DriftDefs",
MSG.common_title_definitions());
-
- private static SortSpecifier DEFAULT_SORT_SPECIFIER = new
SortSpecifier(DriftConfigurationDataSource.ATTR_NAME,
- SortDirection.ASCENDING);
-
- private static final Criteria INITIAL_CRITERIA = new Criteria();
-
- private EntityContext context;
- private boolean hasWriteAccess;
- private DriftConfigurationDataSource dataSource;
-
- static {
- DriftCategory[] categoryValues = DriftCategory.values();
- String[] categoryNames = new String[categoryValues.length];
- int i = 0;
- for (DriftCategory c : categoryValues) {
- categoryNames[i++] = c.name();
- }
-
- // Add any INITIAL_CRITERIA here (non currently)
- }
-
- // for subsystem views
- public DriftConfigurationView(String locatorId) {
- this(locatorId, SUBSYSTEM_VIEW_ID.getTitle(), EntityContext.forSubsystemView(),
false);
- }
-
- public DriftConfigurationView(String locatorId, EntityContext entityContext) {
- this(locatorId, SUBSYSTEM_VIEW_ID.getTitle(), entityContext, false);
- }
-
- public DriftConfigurationView(String locatorId, String tableTitle, EntityContext
entityContext) {
- this(locatorId, tableTitle, entityContext, false);
- }
-
- protected DriftConfigurationView(String locatorId, String tableTitle, EntityContext
context, boolean hasWriteAccess) {
- super(locatorId, tableTitle, INITIAL_CRITERIA, new SortSpecifier[] {
DEFAULT_SORT_SPECIFIER });
- this.context = context;
- this.hasWriteAccess = hasWriteAccess;
-
- setInitialCriteriaFixed(false);
- setDataSource(getDataSource());
- }
-
- @Override
- public DriftConfigurationDataSource getDataSource() {
- if (null == this.dataSource) {
- this.dataSource = new DriftConfigurationDataSource(context);
- }
- return this.dataSource;
- }
-
- @Override
- protected void configureTableFilters() {
- // currently no table filters
- }
-
- @Override
- protected void configureTable() {
- ArrayList<ListGridField> dataSourceFields =
getDataSource().getListGridFields();
- getListGrid().setFields(dataSourceFields.toArray(new
ListGridField[dataSourceFields.size()]));
- setupTableInteractions(this.hasWriteAccess);
-
- super.configureTable();
- }
-
- private void setupTableInteractions(final boolean hasWriteAccess) {
- TableActionEnablement deleteEnablement = hasWriteAccess ?
TableActionEnablement.ANY
- : TableActionEnablement.NEVER;
- TableActionEnablement detectNowEnablement = hasWriteAccess ?
TableActionEnablement.SINGLE
- : TableActionEnablement.NEVER;
-
- addTableAction("Add", MSG.common_button_add(), null, new TableAction()
{
- public boolean isEnabled(ListGridRecord[] selection) {
- return hasWriteAccess;
- }
-
- public void executeAction(ListGridRecord[] selection, Object actionValue) {
- add();
- }
- });
-
- addTableAction("Delete", MSG.common_button_delete(),
MSG.view_drift_delete_configConfirm(),
- new AbstractTableAction(deleteEnablement) {
- public void executeAction(ListGridRecord[] selection, Object actionValue)
{
- delete(selection);
- }
- });
-
- addTableAction("DeleteAll", MSG.common_button_delete_all(),
MSG.view_drift_delete_configConfirmAll(),
- new TableAction() {
- public boolean isEnabled(ListGridRecord[] selection) {
- ListGrid grid = getListGrid();
- ResultSet resultSet = (null != grid) ? grid.getResultSet() : null;
- return (hasWriteAccess && grid != null && resultSet
!= null && !resultSet.isEmpty());
- }
-
- public void executeAction(ListGridRecord[] selection, Object actionValue)
{
- deleteAll();
- }
- });
-
- addTableAction("DetectNow", MSG.view_drift_button_detectNow(), null,
new AbstractTableAction(
- detectNowEnablement) {
- public void executeAction(ListGridRecord[] selection, Object actionValue) {
- detectDrift(selection); // will only ever be a single selection - see
detectNowEnablement variable
- }
- });
- }
-
- private void add() {
- DriftAddConfigWizard.showWizard(context, this);
- // we can refresh the table buttons immediately since the wizard is a dialog,
the
- // user can't access enabled buttons anyway.
- DriftConfigurationView.this.refreshTableInfo();
- }
-
- private void delete(ListGridRecord[] records) {
- final String[] driftConfigNames = new String[records.length];
- for (int i = 0, selectionLength = records.length; i < selectionLength; i++) {
- ListGridRecord record = records[i];
- String driftConfigName =
record.getAttribute(DriftConfigurationDataSource.ATTR_NAME);
- driftConfigNames[i] = driftConfigName;
- }
-
- deleteDriftConfigurationsByName(driftConfigNames);
- }
-
- private void deleteAll() {
- final RecordList records = getListGrid().getDataAsRecordList();
- final int numRecords = records.getLength();
- final String[] driftConfigNames = new String[numRecords];
- for (int i = 0; i < numRecords; i++) {
- Record record = records.get(i);
- String driftConfigName =
record.getAttribute(DriftConfigurationDataSource.ATTR_NAME);
- driftConfigNames[i] = driftConfigName;
- }
-
- deleteDriftConfigurationsByName(driftConfigNames);
- }
-
- private void deleteDriftConfigurationsByName(final String[] driftConfigNames) {
- GWTServiceLookup.getDriftService().deleteDriftConfigurationsByContext(context,
driftConfigNames,
- new AsyncCallback<Integer>() {
- public void onSuccess(Integer resultCount) {
- CoreGUI.getMessageCenter().notify(
- new
Message(MSG.view_drift_success_deleteConfigs(String.valueOf(resultCount)),
- Message.Severity.Info));
- refresh();
- }
-
- public void onFailure(Throwable caught) {
-
CoreGUI.getErrorHandler().handleError(MSG.view_drift_failure_deleteDefs(), caught);
- }
- });
- }
-
- private void detectDrift(ListGridRecord[] records) {
- // we will only ever have a single record selected, hence why we can access the
[0] item
- DriftConfiguration driftConfig = (DriftConfiguration) records[0]
- .getAttributeAsObject(DriftConfigurationDataSource.ATTR_ENTITY);
- GWTServiceLookup.getDriftService().detectDrift(context, driftConfig, new
AsyncCallback<Void>() {
- public void onSuccess(Void result) {
- CoreGUI.getMessageCenter().notify(
- new Message(MSG.view_drift_success_detectNow(),
Message.Severity.Info));
- refresh();
- }
-
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(MSG.view_drift_failure_detectNow(),
caught);
- }
- });
- }
-
- @Override
- public Canvas getDetailsView(Integer driftConfigId) {
- return new DriftConfigurationEditView(extendLocatorId("ConfigEdit"),
context, driftConfigId, hasWriteAccess);
- }
-
- public EntityContext getContext() {
- return context;
- }
-}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDataSource.java
index cdb85b7..ba0dd8d 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDataSource.java
@@ -73,7 +73,7 @@ public class DriftDataSource extends RPCDataSource<DriftComposite,
GenericDriftC
public static final String ATTR_CTIME = "ctime";
public static final String ATTR_CATEGORY = "category";
public static final String ATTR_CHANGESET_VERSION = "changeSetVersion";
- public static final String ATTR_CHANGESET_CONFIG = "changSetConfig";
+ public static final String ATTR_CHANGESET_DEF_NAME = "changSetDef";
public static final String ATTR_PATH = "path";
public static final String FILTER_CATEGORIES = "categories";
@@ -83,7 +83,7 @@ public class DriftDataSource extends RPCDataSource<DriftComposite,
GenericDriftC
private DriftGWTServiceAsync driftService = GWTServiceLookup.getDriftService();
- private EntityContext entityContext;
+ protected EntityContext entityContext;
public DriftDataSource() {
this(EntityContext.forSubsystemView());
@@ -109,8 +109,8 @@ public class DriftDataSource extends RPCDataSource<DriftComposite,
GenericDriftC
ctimeField.setHoverCustomizer(TimestampCellFormatter.getHoverCustomizer(ATTR_CTIME));
fields.add(ctimeField);
- ListGridField changeSetConfigField = new ListGridField(ATTR_CHANGESET_CONFIG,
MSG.common_title_definition());
- fields.add(changeSetConfigField);
+ ListGridField changeSetDefField = new ListGridField(ATTR_CHANGESET_DEF_NAME,
MSG.common_title_definition());
+ fields.add(changeSetDefField);
ListGridField changeSetVersionField = new ListGridField(ATTR_CHANGESET_VERSION,
MSG.view_drift_table_snapshot());
fields.add(changeSetVersionField);
@@ -195,15 +195,15 @@ public class DriftDataSource extends
RPCDataSource<DriftComposite, GenericDriftC
}
public void onSuccess(PageList<DriftComposite> result) {
- // only get the desired config names (substring match)
+ // only get the desired def names (substring match)
// note - this does not alter the PageList row count, which, I think,
makes this
// ok without messing up paging.
- String configFilter = getFilter(request, FILTER_DEFINITION,
String.class);
- if (null != configFilter && !configFilter.isEmpty()) {
- configFilter = configFilter.toLowerCase();
+ String defFilter = getFilter(request, FILTER_DEFINITION, String.class);
+ if (null != defFilter && !defFilter.isEmpty()) {
+ defFilter = defFilter.toLowerCase();
for (Iterator<DriftComposite> i =
result.getValues().iterator(); i.hasNext();) {
DriftComposite composite = i.next();
- if
(!composite.getDriftConfigName().toLowerCase().contains(configFilter)) {
+ if
(!composite.getDriftDefinitionName().toLowerCase().contains(defFilter)) {
i.remove();
}
}
@@ -284,12 +284,13 @@ public class DriftDataSource extends
RPCDataSource<DriftComposite, GenericDriftC
DriftCategory[] categoriesFilter = getArrayFilter(request, FILTER_CATEGORIES,
DriftCategory.class);
if (categoriesFilter == null || categoriesFilter.length == 0) {
- return null; // user didn't select any priorities - return null to
indicate no data should be displayed
+ return null; // user didn't select any categories - return null to
indicate no data should be displayed
}
String changeSetFilter = getFilter(request, FILTER_SNAPSHOT, String.class);
String pathFilter = getFilter(request, FILTER_PATH, String.class);
- // note, this criteria does not allow for query-time config name filtering. That
filter is applied lazily
+
+ // NOTE! This criteria does not allow for query-time definition name filtering.
That filter is applied lazily
// to the query results.
GenericDriftCriteria criteria = new GenericDriftCriteria();
@@ -369,7 +370,7 @@ public class DriftDataSource extends RPCDataSource<DriftComposite,
GenericDriftC
break;
}
record.setAttribute(ATTR_PATH, drift.getPath());
- record.setAttribute(ATTR_CHANGESET_CONFIG, from.getDriftConfigName());
+ record.setAttribute(ATTR_CHANGESET_DEF_NAME, from.getDriftDefinitionName());
record.setAttribute(ATTR_CHANGESET_VERSION, drift.getChangeSet().getVersion());
// for ancestry handling
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionDataSource.java
new file mode 100644
index 0000000..f9c5f1d
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionDataSource.java
@@ -0,0 +1,313 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.data.DSRequest;
+import com.smartgwt.client.data.DSResponse;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.rpc.RPCResponse;
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.ListGridFieldType;
+import com.smartgwt.client.widgets.grid.CellFormatter;
+import com.smartgwt.client.widgets.grid.HoverCustomizer;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
+import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
+
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.criteria.DriftDefinitionCriteria;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
+import org.rhq.core.domain.drift.DriftDefinition.BaseDirectory;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.ImageManager;
+import org.rhq.enterprise.gui.coregui.client.LinkManager;
+import org.rhq.enterprise.gui.coregui.client.gwt.DriftGWTServiceAsync;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.inventory.resource.AncestryUtil;
+import org.rhq.enterprise.gui.coregui.client.util.RPCDataSource;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.SeleniumUtility;
+
+/**
+ * @author Jay Shaughnessy
+ * @author John Mazzitelli
+ */
+public class DriftDefinitionDataSource extends RPCDataSource<DriftDefinition,
DriftDefinitionCriteria> {
+
+ public static final String ATTR_ENTITY = "object";
+ public static final String ATTR_ID = "id";
+ public static final String ATTR_NAME = "name";
+ public static final String ATTR_INTERVAL = "interval";
+ public static final String ATTR_DRIFT_HANDLING_MODE = "driftHandlingMode";
+ public static final String ATTR_BASE_DIR_STRING = "baseDirString";
+ public static final String ATTR_ENABLED = "enabled";
+ public static final String ATTR_EDIT = "edit";
+
+ public static final String DRIFT_HANDLING_MODE_NORMAL =
MSG.view_drift_table_driftHandlingMode_normal();
+ public static final String DRIFT_HANDLING_MODE_PLANNED =
MSG.view_drift_table_driftHandlingMode_plannedChanges();
+
+ private DriftGWTServiceAsync driftService = GWTServiceLookup.getDriftService();
+ private EntityContext entityContext;
+
+ public DriftDefinitionDataSource() {
+ this(EntityContext.forSubsystemView());
+ }
+
+ public DriftDefinitionDataSource(EntityContext context) {
+ this.entityContext = context;
+ addDataSourceFields();
+ }
+
+ /**
+ * The view that contains the list grid which will display this datasource's data
will call this
+ * method to get the field information which is used to control the display of the
data.
+ *
+ * @return list grid fields used to display the datasource data
+ */
+ public ArrayList<ListGridField> getListGridFields() {
+ ArrayList<ListGridField> fields = new ArrayList<ListGridField>(6);
+
+ ListGridField nameField = new ListGridField(ATTR_NAME, MSG.common_title_name());
+ fields.add(nameField);
+
+ ListGridField enabledField = new ListGridField(ATTR_ENABLED,
MSG.common_title_enabled());
+ enabledField.setType(ListGridFieldType.IMAGE);
+ enabledField.setAlign(Alignment.CENTER);
+ fields.add(enabledField);
+
+ ListGridField driftHandlingModeField = new
ListGridField(ATTR_DRIFT_HANDLING_MODE, MSG
+ .view_drift_table_driftHandlingMode());
+ fields.add(driftHandlingModeField);
+
+ ListGridField intervalField = new ListGridField(ATTR_INTERVAL,
MSG.common_title_interval());
+ fields.add(intervalField);
+
+ ListGridField baseDirField = new ListGridField(ATTR_BASE_DIR_STRING,
MSG.view_drift_table_baseDir());
+ // can't sort on this because it's not an entity field, it's derived
from the config only
+ baseDirField.setCanSort(false);
+ fields.add(baseDirField);
+
+ ListGridField editField = new ListGridField(ATTR_EDIT, "Edit?"); //TODO
I18N
+ editField.setType(ListGridFieldType.IMAGE);
+ editField.setAlign(Alignment.CENTER);
+ editField.addRecordClickHandler(new RecordClickHandler() {
+
+ public void onRecordClick(RecordClickEvent event) {
+ switch (entityContext.getType()) {
+ case Resource:
+
CoreGUI.goToView(LinkManager.getDriftDefinitionEditLink(entityContext.getResourceId(),
event
+ .getRecord().getAttributeAsInt(ATTR_ID)));
+ break;
+ default:
+ throw new IllegalArgumentException("Entity Type not
supported");
+ }
+ }
+ });
+ fields.add(editField);
+
+ if (this.entityContext.type != EntityContext.Type.Resource) {
+ ListGridField resourceNameField = new
ListGridField(AncestryUtil.RESOURCE_NAME, MSG.common_title_resource());
+ resourceNameField.setCellFormatter(new CellFormatter() {
+ public String format(Object o, ListGridRecord listGridRecord, int i, int
i1) {
+ Integer resourceId =
listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID);
+ String url = LinkManager.getResourceLink(resourceId);
+ return SeleniumUtility.getLocatableHref(url, o.toString(), null);
+ }
+ });
+ resourceNameField.setShowHover(true);
+ resourceNameField.setHoverCustomizer(new HoverCustomizer() {
+ public String hoverHTML(Object value, ListGridRecord listGridRecord, int
rowNum, int colNum) {
+ return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
+ }
+ });
+ fields.add(resourceNameField);
+
+ ListGridField ancestryField = AncestryUtil.setupAncestryListGridField();
+ fields.add(ancestryField);
+
+ nameField.setWidth("20%");
+ enabledField.setWidth(60);
+ driftHandlingModeField.setWidth("10%");
+ intervalField.setWidth(100);
+ baseDirField.setWidth("*");
+ editField.setWidth(70);
+ resourceNameField.setWidth("20%");
+ ancestryField.setWidth("40%");
+ } else {
+ nameField.setWidth("20%");
+ enabledField.setWidth(60);
+ driftHandlingModeField.setWidth("10%");
+ intervalField.setWidth(100);
+ baseDirField.setWidth("*");
+ editField.setWidth(70);
+ }
+
+ return fields;
+ }
+
+ @Override
+ protected void executeFetch(final DSRequest request, final DSResponse response,
+ final DriftDefinitionCriteria criteria) {
+ this.driftService.findDriftDefinitionsByCriteria(criteria, new
AsyncCallback<PageList<DriftDefinition>>() {
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(MSG.view_drift_failure_load(),
caught);
+ response.setStatus(RPCResponse.STATUS_FAILURE);
+ processResponse(request.getRequestId(), response);
+ }
+
+ public void onSuccess(PageList<DriftDefinition> result) {
+ dataRetrieved(result, response, request);
+ }
+ });
+ }
+
+ /**
+ * Additional processing to support entity-specific or cross-resource views, and
something that can be overidden.
+ */
+ protected void dataRetrieved(final PageList<DriftDefinition> result, final
DSResponse response,
+ final DSRequest request) {
+ switch (entityContext.type) {
+
+ // no need to disambiguate, the drift defs are for a single resource
+ case Resource:
+ response.setData(buildRecords(result));
+ // for paging to work we have to specify size of full result set
+ response.setTotalRows(getTotalRows(result, response, request));
+ processResponse(request.getRequestId(), response);
+ break;
+
+ case ResourceGroup:
+ //TODO
+
+ default:
+ throw new IllegalArgumentException("Unsupported Context Type: " +
entityContext);
+ }
+ }
+
+ /**
+ * Sub-classes can override this to add fine-grained control over the result set
size. By default the
+ * total rows are set to the total result set for the query, allowing proper paging.
But some views (portlets)
+ * may want to limit results to a small set (like most recent).
+ * @param result
+ * @param response
+ * @param request
+ *
+ * @return should not exceed result.size().
+ */
+ protected int getTotalRows(final Collection<DriftDefinition> result, final
DSResponse response,
+ final DSRequest request) {
+ return result.size();
+ }
+
+ @Override
+ protected DriftDefinitionCriteria getFetchCriteria(DSRequest request) {
+
+ DriftDefinitionCriteria criteria = new DriftDefinitionCriteria();
+ switch (entityContext.getType()) {
+ case Resource:
+ criteria.addFilterResourceIds(entityContext.getResourceId());
+ break;
+
+ case ResourceGroup:
+ //TODO
+
+ default:
+ // no filter
+ }
+
+ criteria.fetchConfiguration(true);
+ criteria.setPageControl(getPageControl(request));
+
+ return criteria;
+ }
+
+ /*
+ @Override
+ protected String getSortFieldForColumn(String columnName) {
+ if (AncestryUtil.RESOURCE_ANCESTRY.equals(columnName)) {
+ return "ancestry";
+ }
+
+ return super.getSortFieldForColumn(columnName);
+ }
+ */
+
+ @Override
+ public DriftDefinition copyValues(Record from) {
+ return (DriftDefinition) from.getAttributeAsObject(ATTR_ENTITY);
+ }
+
+ @Override
+ public ListGridRecord copyValues(DriftDefinition from) {
+ return convert(from);
+ }
+
+ public static ListGridRecord convert(DriftDefinition from) {
+ ListGridRecord record = new ListGridRecord();
+
+ record.setAttribute(ATTR_ENTITY, from);
+
+ record.setAttribute(ATTR_ID, from.getId());
+ record.setAttribute(ATTR_NAME, from.getName());
+ record.setAttribute(ATTR_DRIFT_HANDLING_MODE,
getDriftHandlingModeDisplayName(from.getDriftHandlingMode()));
+ record.setAttribute(ATTR_INTERVAL, String.valueOf(from.getInterval()));
+ record.setAttribute(ATTR_BASE_DIR_STRING, getBaseDirString(from.getBasedir()));
+ record.setAttribute(ATTR_ENABLED,
ImageManager.getAvailabilityIcon(from.isEnabled()));
+ // fixed value, just the edit icon
+ record.setAttribute(ATTR_EDIT, ImageManager.getEditIcon());
+
+ // // for ancestry handling
+ // Resource resource = ...
+ // record.setAttribute(AncestryUtil.RESOURCE_ID, resource.getId());
+ // record.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
+ // record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
+ // record.setAttribute(AncestryUtil.RESOURCE_TYPE_ID,
resource.getResourceType().getId());
+
+ return record;
+ }
+
+ public static String getDriftHandlingModeDisplayName(DriftHandlingMode
driftHandlingMode) {
+ switch (driftHandlingMode) {
+ case plannedChanges:
+ return DRIFT_HANDLING_MODE_PLANNED;
+
+ default:
+ return DRIFT_HANDLING_MODE_NORMAL;
+ }
+ }
+
+ private static String getBaseDirString(BaseDirectory basedir) {
+ return basedir.getValueContext() + ":" + basedir.getValueName();
+ }
+
+ protected EntityContext getEntityContext() {
+ return entityContext;
+ }
+
+ protected void setEntityContext(EntityContext entityContext) {
+ this.entityContext = entityContext;
+ }
+
+}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionEditView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionEditView.java
new file mode 100644
index 0000000..1808dfa
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionEditView.java
@@ -0,0 +1,192 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift;
+
+import java.util.EnumSet;
+import java.util.Map;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.types.Overflow;
+import com.smartgwt.client.widgets.IButton;
+import com.smartgwt.client.widgets.events.ClickEvent;
+import com.smartgwt.client.widgets.events.ClickHandler;
+import com.smartgwt.client.widgets.toolbar.ToolStrip;
+
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.LinkManager;
+import org.rhq.enterprise.gui.coregui.client.RefreshableView;
+import
org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
+import
org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeEvent;
+import
org.rhq.enterprise.gui.coregui.client.components.configuration.PropertyValueChangeListener;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import
org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceDetailView;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message;
+import org.rhq.enterprise.gui.coregui.client.util.message.MessageCenter;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableIButton;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
+
+/**
+ * A view for editing a Resource's configuration.
+ *
+ * @author Jay Shaughnessy
+ */
+public class DriftDefinitionEditView extends LocatableVLayout implements
PropertyValueChangeListener, RefreshableView {
+
+ private EntityContext context;
+ private int driftDefId;
+ private boolean hasWriteAccess;
+ private ConfigurationEditor editor;
+ private ToolStrip buttonbar;
+ private IButton saveButton;
+
+ private boolean refreshing = false;
+
+ public DriftDefinitionEditView(String locatorId, EntityContext context, int
driftDefId, boolean hasWriteAccess) {
+ super(locatorId);
+
+ this.context = context;
+ this.driftDefId = driftDefId;
+ this.hasWriteAccess = hasWriteAccess;
+ }
+
+ @Override
+ protected void onDraw() {
+ super.onDraw();
+
+ this.buttonbar = new ToolStrip();
+ buttonbar.setWidth100();
+ buttonbar.setExtraSpace(10);
+ buttonbar.setMembersMargin(5);
+ buttonbar.setLayoutMargin(5);
+
+ this.saveButton = new LocatableIButton(this.extendLocatorId("Save"),
MSG.common_button_save());
+ this.saveButton.addClickHandler(new ClickHandler() {
+ public void onClick(ClickEvent clickEvent) {
+ save();
+ }
+ });
+ buttonbar.addMember(saveButton);
+ // The button bar will remain hidden until the definition has been successfully
loaded.
+ buttonbar.setVisible(false);
+ addMember(buttonbar);
+
+ refresh();
+
+ if (!this.hasWriteAccess) {
+ Message message = new Message(MSG.view_configurationDetails_noPermission(),
Message.Severity.Info, EnumSet
+ .of(Message.Option.Transient, Message.Option.Sticky));
+ CoreGUI.getMessageCenter().notify(message);
+ }
+ }
+
+ @Override
+ public void refresh() {
+ if (this.refreshing) {
+ return; // we are already in the process of refreshing, don't do it
again
+ }
+
+ this.refreshing = true;
+ this.buttonbar.setVisible(false);
+
+ if (editor != null) {
+ editor.destroy();
+ removeMember(editor);
+ }
+
+ GWTServiceLookup.getDriftService().getDriftDefinition(driftDefId, new
AsyncCallback<DriftDefinition>() {
+ @Override
+ public void onSuccess(final DriftDefinition result) {
+
+ editor = new ConfigurationEditor(extendLocatorId("Editor"),
DriftConfigurationDefinition
+ .getInstanceForExistingConfiguration(), result.getConfiguration());
+ editor.setOverflow(Overflow.AUTO);
+ editor.addPropertyValueChangeListener(DriftDefinitionEditView.this);
+ editor.setReadOnly(!hasWriteAccess);
+ addMember(editor);
+
+ saveButton.disable();
+ buttonbar.setVisible(true);
+ markForRedraw();
+ refreshing = false;
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ refreshing = false;
+ CoreGUI.getErrorHandler().handleError("Failed to load
definition.", caught);
+ }
+ });
+ }
+
+ private void save() {
+ Configuration updatedConfiguration = editor.getConfiguration();
+
+ GWTServiceLookup.getDriftService().updateDriftDefinition(context, new
DriftDefinition(updatedConfiguration),
+ new AsyncCallback<Void>() {
+ public void onFailure(Throwable caught) {
+
CoreGUI.getErrorHandler().handleError(MSG.view_configurationDetails_error_updateFailure(),
caught);
+ }
+
+ public void onSuccess(Void result) {
+ Message message = new Message(MSG.view_drift_success_defUpdated(),
Message.Severity.Info);
+
+ switch (context.getType()) {
+ case Resource:
+ int resourceId = context.getResourceId();
+
+ String driftHistoryUrl =
LinkManager.getResourceTabLink(resourceId,
+ ResourceDetailView.Tab.DRIFT,
ResourceDetailView.ConfigurationSubTab.HISTORY);
+ driftHistoryUrl = driftHistoryUrl.substring(1); // chop off the
leading '#'
+ CoreGUI.goToView(driftHistoryUrl, message);
+
+ break;
+
+ default:
+ throw new IllegalArgumentException("Entity Context Type not
supported [" + context + "]");
+ }
+ }
+ });
+ }
+
+ @Override
+ public void propertyValueChanged(PropertyValueChangeEvent event) {
+ MessageCenter messageCenter = CoreGUI.getMessageCenter();
+ Message message;
+ if (event.isInvalidPropertySetChanged()) {
+ Map<String, String> invalidPropertyNames =
event.getInvalidPropertyNames();
+ if (invalidPropertyNames.isEmpty()) {
+ this.saveButton.enable();
+ message = new Message(MSG.view_configurationDetails_allPropertiesValid(),
Message.Severity.Info,
+ EnumSet.of(Message.Option.Transient, Message.Option.Sticky));
+ } else {
+ this.saveButton.disable();
+ message = new
Message(MSG.view_configurationDetails_somePropertiesInvalid(invalidPropertyNames.values()
+ .toString()), Message.Severity.Error,
EnumSet.of(Message.Option.Transient, Message.Option.Sticky));
+ }
+ messageCenter.notify(message);
+ } else {
+ this.saveButton.enable();
+ }
+ }
+
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionsView.java
new file mode 100644
index 0000000..d858fc2
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDefinitionsView.java
@@ -0,0 +1,259 @@
+/*
+ * RHQ Management Platform
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift;
+
+import java.util.ArrayList;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.smartgwt.client.data.Criteria;
+import com.smartgwt.client.data.Record;
+import com.smartgwt.client.data.RecordList;
+import com.smartgwt.client.data.ResultSet;
+import com.smartgwt.client.data.SortSpecifier;
+import com.smartgwt.client.types.SortDirection;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.grid.ListGrid;
+import com.smartgwt.client.widgets.grid.ListGridField;
+import com.smartgwt.client.widgets.grid.ListGridRecord;
+
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.drift.DriftCategory;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.ViewPath;
+import org.rhq.enterprise.gui.coregui.client.components.table.AbstractTableAction;
+import org.rhq.enterprise.gui.coregui.client.components.table.TableAction;
+import org.rhq.enterprise.gui.coregui.client.components.table.TableActionEnablement;
+import org.rhq.enterprise.gui.coregui.client.components.table.TableSection;
+import org.rhq.enterprise.gui.coregui.client.components.view.ViewName;
+import org.rhq.enterprise.gui.coregui.client.drift.wizard.DriftAddDefinitionWizard;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message;
+
+/**
+ * A list view that displays a paginated table of {@link
org.rhq.core.domain.drift.DriftDefinition}s. It has offers various
+ * options on the list like filtering (maybe) and sorting, add new/delete. Double-click
drills down to the carousel view for
+ * inspecting drift for the definition. Also, allows an edit view for the def's
underlying Config. This view full respects
+ * the user's authorization, and will not allow actions on the drift defs unless the
user is either the inventory
+ * manager or has MANAGE_DRIFT permission on every resource corresponding to the drift
defs being operated on.
+ *
+ * @author Jay Shaughnessy
+ */
+public class DriftDefinitionsView extends TableSection<DriftDefinitionDataSource>
{
+
+ public static final ViewName SUBSYSTEM_VIEW_ID = new ViewName("DriftDefs",
MSG.common_title_definitions());
+
+ private static SortSpecifier DEFAULT_SORT_SPECIFIER = new
SortSpecifier(DriftDefinitionDataSource.ATTR_NAME,
+ SortDirection.ASCENDING);
+
+ private static final Criteria INITIAL_CRITERIA = new Criteria();
+
+ private EntityContext context;
+ private boolean hasWriteAccess;
+ private DriftDefinitionDataSource dataSource;
+ private boolean useCarouselDetailsView;
+
+ static {
+ DriftCategory[] categoryValues = DriftCategory.values();
+ String[] categoryNames = new String[categoryValues.length];
+ int i = 0;
+ for (DriftCategory c : categoryValues) {
+ categoryNames[i++] = c.name();
+ }
+
+ // Add any INITIAL_CRITERIA here (non currently)
+ }
+
+ // for subsystem views
+ public DriftDefinitionsView(String locatorId) {
+ this(locatorId, SUBSYSTEM_VIEW_ID.getTitle(), EntityContext.forSubsystemView(),
false);
+ }
+
+ public DriftDefinitionsView(String locatorId, EntityContext entityContext) {
+ this(locatorId, SUBSYSTEM_VIEW_ID.getTitle(), entityContext, false);
+ }
+
+ public DriftDefinitionsView(String locatorId, String tableTitle, EntityContext
entityContext) {
+ this(locatorId, tableTitle, entityContext, false);
+ }
+
+ protected DriftDefinitionsView(String locatorId, String tableTitle, EntityContext
context, boolean hasWriteAccess) {
+ super(locatorId, tableTitle, INITIAL_CRITERIA, new SortSpecifier[] {
DEFAULT_SORT_SPECIFIER });
+ this.context = context;
+ this.hasWriteAccess = hasWriteAccess;
+
+ setInitialCriteriaFixed(false);
+ setDataSource(getDataSource());
+ }
+
+ @Override
+ public DriftDefinitionDataSource getDataSource() {
+ if (null == this.dataSource) {
+ this.dataSource = new DriftDefinitionDataSource(context);
+ }
+ return this.dataSource;
+ }
+
+ @Override
+ protected void configureTableFilters() {
+ // currently no table filters
+ }
+
+ @Override
+ protected void configureTable() {
+ ArrayList<ListGridField> dataSourceFields =
getDataSource().getListGridFields();
+ getListGrid().setFields(dataSourceFields.toArray(new
ListGridField[dataSourceFields.size()]));
+ setupTableInteractions(this.hasWriteAccess);
+
+ super.configureTable();
+ }
+
+ private void setupTableInteractions(final boolean hasWriteAccess) {
+ TableActionEnablement deleteEnablement = hasWriteAccess ?
TableActionEnablement.ANY
+ : TableActionEnablement.NEVER;
+ TableActionEnablement detectNowEnablement = hasWriteAccess ?
TableActionEnablement.SINGLE
+ : TableActionEnablement.NEVER;
+
+ addTableAction("Add", MSG.common_button_add(), null, new TableAction()
{
+ public boolean isEnabled(ListGridRecord[] selection) {
+ return hasWriteAccess;
+ }
+
+ public void executeAction(ListGridRecord[] selection, Object actionValue) {
+ add();
+ }
+ });
+
+ addTableAction("Delete", MSG.common_button_delete(),
MSG.view_drift_delete_defConfirm(),
+ new AbstractTableAction(deleteEnablement) {
+ public void executeAction(ListGridRecord[] selection, Object actionValue)
{
+ delete(selection);
+ }
+ });
+
+ addTableAction("DeleteAll", MSG.common_button_delete_all(),
MSG.view_drift_delete_defConfirmAll(),
+ new TableAction() {
+ public boolean isEnabled(ListGridRecord[] selection) {
+ ListGrid grid = getListGrid();
+ ResultSet resultSet = (null != grid) ? grid.getResultSet() : null;
+ return (hasWriteAccess && grid != null && resultSet
!= null && !resultSet.isEmpty());
+ }
+
+ public void executeAction(ListGridRecord[] selection, Object actionValue)
{
+ deleteAll();
+ }
+ });
+
+ addTableAction("DetectNow", MSG.view_drift_button_detectNow(), null,
new AbstractTableAction(
+ detectNowEnablement) {
+ public void executeAction(ListGridRecord[] selection, Object actionValue) {
+ detectDrift(selection); // will only ever be a single selection - see
detectNowEnablement variable
+ }
+ });
+ }
+
+ private void add() {
+ DriftAddDefinitionWizard.showWizard(context, this);
+ // we can refresh the table buttons immediately since the wizard is a dialog,
the
+ // user can't access enabled buttons anyway.
+ DriftDefinitionsView.this.refreshTableInfo();
+ }
+
+ private void delete(ListGridRecord[] records) {
+ final String[] driftDefNames = new String[records.length];
+ for (int i = 0, selectionLength = records.length; i < selectionLength; i++) {
+ ListGridRecord record = records[i];
+ String driftDefName =
record.getAttribute(DriftDefinitionDataSource.ATTR_NAME);
+ driftDefNames[i] = driftDefName;
+ }
+
+ deleteDriftDefinitionsByName(driftDefNames);
+ }
+
+ private void deleteAll() {
+ final RecordList records = getListGrid().getDataAsRecordList();
+ final int numRecords = records.getLength();
+ final String[] driftDefNames = new String[numRecords];
+ for (int i = 0; i < numRecords; i++) {
+ Record record = records.get(i);
+ String driftDefName =
record.getAttribute(DriftDefinitionDataSource.ATTR_NAME);
+ driftDefNames[i] = driftDefName;
+ }
+
+ deleteDriftDefinitionsByName(driftDefNames);
+ }
+
+ private void deleteDriftDefinitionsByName(final String[] driftDefNames) {
+ GWTServiceLookup.getDriftService().deleteDriftDefinitionsByContext(context,
driftDefNames,
+ new AsyncCallback<Integer>() {
+ public void onSuccess(Integer resultCount) {
+ CoreGUI.getMessageCenter().notify(
+ new
Message(MSG.view_drift_success_deleteDefs(String.valueOf(resultCount)),
+ Message.Severity.Info));
+ refresh();
+ }
+
+ public void onFailure(Throwable caught) {
+
CoreGUI.getErrorHandler().handleError(MSG.view_drift_failure_deleteDefs(), caught);
+ }
+ });
+ }
+
+ private void detectDrift(ListGridRecord[] records) {
+ // we will only ever have a single record selected, hence why we can access the
[0] item
+ DriftDefinition driftDef = (DriftDefinition) records[0]
+ .getAttributeAsObject(DriftDefinitionDataSource.ATTR_ENTITY);
+ GWTServiceLookup.getDriftService().detectDrift(context, driftDef, new
AsyncCallback<Void>() {
+ public void onSuccess(Void result) {
+ CoreGUI.getMessageCenter().notify(
+ new Message(MSG.view_drift_success_detectNow(),
Message.Severity.Info));
+ refresh();
+ }
+
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(MSG.view_drift_failure_detectNow(),
caught);
+ }
+ });
+ }
+
+ @Override
+ public void renderView(ViewPath viewPath) {
+ // we have two detail views for drift defs, the config editor and the carousel.
figure out which one we're
+ // dealing with. The default is the carousel, anything further in the path we
assume to be /Edit
+ if (!viewPath.isEnd()) {
+ this.useCarouselDetailsView = viewPath.isNextEnd();
+ }
+
+ super.renderView(viewPath);
+ }
+
+ @Override
+ public Canvas getDetailsView(Integer driftDefId) {
+ if (this.useCarouselDetailsView) {
+ return new DriftCarouselView(extendLocatorId("Carousel"), context,
driftDefId, hasWriteAccess);
+ }
+
+ return new DriftDefinitionEditView(extendLocatorId("DefintionEdit"),
context, driftDefId, hasWriteAccess);
+ }
+
+ public EntityContext getContext() {
+ return context;
+ }
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
index 6961071..8d7baf5 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
@@ -215,7 +215,7 @@ public class DriftDetailsView extends LocatableVLayout {
changeSetVersion.setValue(changeSet.getVersion());
StaticTextItem changeSetDriftHandling = new
StaticTextItem("changeSetDriftHandling", MSG
.view_drift_table_driftHandlingMode());
-
changeSetDriftHandling.setValue(DriftConfigurationDataSource.getDriftHandlingModeDisplayName(changeSet
+
changeSetDriftHandling.setValue(DriftDefinitionDataSource.getDriftHandlingModeDisplayName(changeSet
.getDriftHandlingMode()));
changeSetForm.setItems(changeSetId, changeSetCategory, changeSetVersion,
changeSetDriftHandling);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftHistoryView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftHistoryView.java
index ca5bcb8..970750a 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftHistoryView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftHistoryView.java
@@ -64,7 +64,8 @@ public class DriftHistoryView extends
StringIDTableSection<DriftDataSource> {
private EntityContext context;
private boolean hasWriteAccess;
- private DriftDataSource dataSource;
+
+ protected DriftDataSource dataSource;
static {
DriftCategory[] categoryValues = DriftCategory.values();
@@ -122,12 +123,12 @@ public class DriftHistoryView extends
StringIDTableSection<DriftDataSource> {
SelectItem categoryFilter = new EnumSelectItem(DriftDataSource.FILTER_CATEGORIES,
MSG.common_title_category(),
DriftCategory.class, categories, categoryIcons);
- TextItem configurationFilter = new TextItem(DriftDataSource.FILTER_DEFINITION,
MSG.common_title_definition());
+ TextItem definitionFilter = new TextItem(DriftDataSource.FILTER_DEFINITION,
MSG.common_title_definition());
TextItem changeSetFilter = new TextItem(DriftDataSource.FILTER_SNAPSHOT,
MSG.view_drift_table_snapshot());
TextItem pathFilter = new TextItem(DriftDataSource.FILTER_PATH,
MSG.common_title_path());
if (isShowFilterForm()) {
- setFilterFormItems(configurationFilter, changeSetFilter, categoryFilter,
pathFilter);
+ setFilterFormItems(definitionFilter, changeSetFilter, categoryFilter,
pathFilter);
}
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeDataSource.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeDataSource.java
index 4da7eac..6302503 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeDataSource.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeDataSource.java
@@ -28,7 +28,7 @@ import com.smartgwt.client.data.DSResponse;
import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
import org.rhq.core.domain.criteria.ResourceCriteria;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
@@ -57,10 +57,10 @@ public class ResourceDriftChangeSetsTreeDataSource extends
AbstractDriftChangeSe
protected void fetchDriftConfigurations(final DSRequest request, final DSResponse
response) {
ResourceCriteria criteria = new ResourceCriteria();
criteria.addFilterId(context.getResourceId());
- criteria.fetchDriftConfigurations(true);
+ criteria.fetchDriftDefinitions(true);
this.resourceService.findResourcesByCriteria(criteria, new
AsyncCallback<PageList<Resource>>() {
public void onSuccess(PageList<Resource> result) {
- Set<DriftConfiguration> driftConfigs =
result.get(0).getDriftConfigurations();
+ Set<DriftDefinition> driftConfigs =
result.get(0).getDriftDefinitions();
response.setData(buildRecords(driftConfigs));
response.setTotalRows(result.getTotalSize());
processResponse(request.getRequestId(), response);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeView.java
index 9869a24..17cc752 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftChangeSetsTreeView.java
@@ -23,7 +23,7 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.widgets.tree.TreeNode;
import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.enterprise.gui.coregui.client.CoreGUI;
import org.rhq.enterprise.gui.coregui.client.LinkManager;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
@@ -55,21 +55,21 @@ public class ResourceDriftChangeSetsTreeView extends
AbstractDriftChangeSetsTree
String driftId = ((DriftTreeNode) node).getDriftId();
String path = LinkManager.getDriftHistoryLink(this.context.resourceId,
driftId);
return path;
- } else if (node instanceof DriftConfigurationTreeNode) {
- int driftConfigId = ((DriftConfigurationTreeNode)
node).getDriftConfigurationId();
- String path = LinkManager.getDriftConfigurationLink(this.context.resourceId,
driftConfigId);
+ } else if (node instanceof DriftDefinitionTreeNode) {
+ int driftDefId = ((DriftDefinitionTreeNode) node).getDriftDefinitionId();
+ String path = LinkManager.getDriftDefinitionEditLink(this.context.resourceId,
driftDefId);
return path;
}
return null;
}
@Override
- protected void deleteDriftConfiguration(DriftConfiguration doomedDriftConfig) {
- GWTServiceLookup.getDriftService().deleteDriftConfigurationsByContext(context,
- new String[] { doomedDriftConfig.getName() }, new
AsyncCallback<Integer>() {
+ protected void deleteDriftDefinition(DriftDefinition doomedDriftDef) {
+ GWTServiceLookup.getDriftService().deleteDriftDefinitionsByContext(context,
+ new String[] { doomedDriftDef.getName() }, new AsyncCallback<Integer>()
{
public void onSuccess(Integer resultCount) {
CoreGUI.getMessageCenter().notify(
- new
Message(MSG.view_drift_success_deleteConfigs(String.valueOf(resultCount)),
+ new
Message(MSG.view_drift_success_deleteDefs(String.valueOf(resultCount)),
Message.Severity.Info));
refresh();
}
@@ -82,8 +82,8 @@ public class ResourceDriftChangeSetsTreeView extends
AbstractDriftChangeSetsTree
}
@Override
- protected void detectDrift(DriftConfiguration driftConfig) {
- GWTServiceLookup.getDriftService().detectDrift(context, driftConfig, new
AsyncCallback<Void>() {
+ protected void detectDrift(DriftDefinition driftDef) {
+ GWTServiceLookup.getDriftService().detectDrift(context, driftDef, new
AsyncCallback<Void>() {
public void onSuccess(Void result) {
CoreGUI.getMessageCenter().notify(
new Message(MSG.view_drift_success_detectNow(),
Message.Severity.Info));
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftConfigurationView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftConfigurationView.java
deleted file mode 100644
index c6163ac..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftConfigurationView.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright 2011, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.drift;
-
-import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.resource.composite.ResourceComposite;
-
-/**
- * @author Jay Shaughnessy
- */
-public class ResourceDriftConfigurationView extends DriftConfigurationView {
- public static ResourceDriftConfigurationView get(String locatorId, ResourceComposite
composite) {
- String tableTitle = MSG.view_drift_table_resourceDef();
- EntityContext context =
EntityContext.forResource(composite.getResource().getId());
- boolean hasWriteAccess = composite.getResourcePermission().isDrift();
- return new ResourceDriftConfigurationView(locatorId, tableTitle, context,
hasWriteAccess);
- }
-
- private ResourceDriftConfigurationView(String locatorId, String tableTitle,
EntityContext context,
- boolean hasWriteAccess) {
- super(locatorId, tableTitle, context, hasWriteAccess);
- }
-}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftDefinitionsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftDefinitionsView.java
new file mode 100644
index 0000000..a32638a
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/ResourceDriftDefinitionsView.java
@@ -0,0 +1,40 @@
+/*
+ * RHQ Management Platform
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift;
+
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.resource.composite.ResourceComposite;
+
+/**
+ * @author Jay Shaughnessy
+ */
+public class ResourceDriftDefinitionsView extends DriftDefinitionsView {
+ public static ResourceDriftDefinitionsView get(String locatorId, ResourceComposite
composite) {
+ String tableTitle = MSG.view_drift_table_resourceDef();
+ EntityContext context =
EntityContext.forResource(composite.getResource().getId());
+ boolean hasWriteAccess = composite.getResourcePermission().isDrift();
+ return new ResourceDriftDefinitionsView(locatorId, tableTitle, context,
hasWriteAccess);
+ }
+
+ private ResourceDriftDefinitionsView(String locatorId, String tableTitle,
EntityContext context,
+ boolean hasWriteAccess) {
+ super(locatorId, tableTitle, context, hasWriteAccess);
+ }
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/AbstractDriftAddConfigWizard.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/AbstractDriftAddConfigWizard.java
deleted file mode 100644
index 545912a..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/AbstractDriftAddConfigWizard.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.drift.wizard;
-
-import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.enterprise.gui.coregui.client.components.wizard.AbstractWizard;
-import org.rhq.enterprise.gui.coregui.client.components.wizard.WizardView;
-
-/**
- * @author Jay Shaughnessy
- */
-public abstract class AbstractDriftAddConfigWizard extends AbstractWizard {
-
- private EntityContext context;
- private ResourceType type;
-
- private Configuration newStartingConfiguration;
- private DriftConfiguration newDriftConfiguration;
-
- private WizardView view;
-
- public AbstractDriftAddConfigWizard(final EntityContext context, ResourceType type)
{
- if (context == null) {
- throw new NullPointerException("context == null");
- }
-
- if (type == null) {
- throw new NullPointerException("type == null");
- }
-
- this.context = context;
- this.type = type;
- }
-
- public String getSubtitle() {
- return null;
- }
-
- abstract public void execute();
-
- public void display() {
- view = new WizardView(this);
- view.displayDialog();
- }
-
- public EntityContext getEntityContext() {
- return context;
- }
-
- public ResourceType getType() {
- return type;
- }
-
- public Configuration getNewStartingConfiguration() {
- return newStartingConfiguration;
- }
-
- public void setNewStartingConfiguration(Configuration newStartingConfiguration) {
- this.newStartingConfiguration = newStartingConfiguration;
- }
-
- public DriftConfiguration getNewDriftConfiguration() {
- return newDriftConfiguration;
- }
-
- public void setNewConfiguration(Configuration newDriftConfiguration) {
- this.newDriftConfiguration = new DriftConfiguration(newDriftConfiguration);
- }
-
- public void cancel() {
- // nothing to do
- }
-
-}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/AbstractDriftAddDefinitionWizard.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/AbstractDriftAddDefinitionWizard.java
new file mode 100644
index 0000000..541c268
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/AbstractDriftAddDefinitionWizard.java
@@ -0,0 +1,93 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift.wizard;
+
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.enterprise.gui.coregui.client.components.wizard.AbstractWizard;
+import org.rhq.enterprise.gui.coregui.client.components.wizard.WizardView;
+
+/**
+ * @author Jay Shaughnessy
+ */
+public abstract class AbstractDriftAddDefinitionWizard extends AbstractWizard {
+
+ private EntityContext context;
+ private ResourceType type;
+
+ private Configuration newStartingConfiguration;
+ private DriftDefinition newDriftDefinition;
+
+ private WizardView view;
+
+ public AbstractDriftAddDefinitionWizard(final EntityContext context, ResourceType
type) {
+ if (context == null) {
+ throw new NullPointerException("context == null");
+ }
+
+ if (type == null) {
+ throw new NullPointerException("type == null");
+ }
+
+ this.context = context;
+ this.type = type;
+ }
+
+ public String getSubtitle() {
+ return null;
+ }
+
+ abstract public void execute();
+
+ public void display() {
+ view = new WizardView(this);
+ view.displayDialog();
+ }
+
+ public EntityContext getEntityContext() {
+ return context;
+ }
+
+ public ResourceType getType() {
+ return type;
+ }
+
+ public Configuration getNewStartingConfiguration() {
+ return newStartingConfiguration;
+ }
+
+ public void setNewStartingConfiguration(Configuration newStartingConfiguration) {
+ this.newStartingConfiguration = newStartingConfiguration;
+ }
+
+ public DriftDefinition getNewDriftDefinition() {
+ return newDriftDefinition;
+ }
+
+ public void setNewConfiguration(Configuration newDriftConfiguration) {
+ this.newDriftDefinition = new DriftDefinition(newDriftConfiguration);
+ }
+
+ public void cancel() {
+ // nothing to do
+ }
+
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizard.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizard.java
deleted file mode 100644
index 5af4465..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizard.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.drift.wizard;
-
-import java.util.ArrayList;
-
-import com.google.gwt.user.client.rpc.AsyncCallback;
-
-import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.criteria.ResourceCriteria;
-import org.rhq.core.domain.criteria.ResourceTypeCriteria;
-import org.rhq.core.domain.resource.Resource;
-import org.rhq.core.domain.resource.ResourceType;
-import org.rhq.core.domain.util.PageList;
-import org.rhq.enterprise.gui.coregui.client.CoreGUI;
-import org.rhq.enterprise.gui.coregui.client.components.table.Table;
-import org.rhq.enterprise.gui.coregui.client.components.wizard.WizardStep;
-import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
-import org.rhq.enterprise.gui.coregui.client.util.message.Message;
-
-/**
- * @author Jay Shaughnessy
- */
-public class DriftAddConfigWizard extends AbstractDriftAddConfigWizard {
-
- private Table<?> table;
-
- public DriftAddConfigWizard(EntityContext context, ResourceType type, Table<?>
table) {
-
- super(context, type);
- this.table = table;
-
- final ArrayList<WizardStep> steps = new ArrayList<WizardStep>();
-
- steps.add(new DriftAddConfigWizardInfoStep(DriftAddConfigWizard.this));
- steps.add(new DriftAddConfigWizardConfigStep(DriftAddConfigWizard.this));
-
- setSteps(steps);
- }
-
- public String getWindowTitle() {
- return MSG.view_drift_wizard_addDef_windowTitle();
- }
-
- public String getTitle() {
- return MSG.view_drift_wizard_addDef_title(getType().getName());
- }
-
- public String getSubtitle() {
- return null;
- }
-
- public void execute() {
- EntityContext context = getEntityContext();
- switch (context.getType()) {
- case Resource:
-
- ResourceCriteria rc = new ResourceCriteria();
- rc.addFilterId(context.getResourceId());
- rc.fetchResourceType(true);
- GWTServiceLookup.getDriftService().updateDriftConfiguration(context,
getNewDriftConfiguration(),
- new AsyncCallback<Void>() {
- public void onSuccess(Void result) {
- CoreGUI.getMessageCenter().notify(
- new
Message(MSG.view_drift_wizard_addDef_success(getNewDriftConfiguration().getName()),
- Message.Severity.Info));
- getView().closeDialog();
- DriftAddConfigWizard.this.table.refresh();
- }
-
- public void onFailure(Throwable caught) {
- CoreGUI.getErrorHandler().handleError(
-
MSG.view_drift_wizard_addDef_failure(getNewDriftConfiguration().getName()), caught);
- getView().closeDialog();
- }
- });
-
- break;
-
- default:
- throw new IllegalArgumentException("Entity Context Type not supported
[" + context + "]");
- }
-
- }
-
- public static void showWizard(final EntityContext context, final Table<?>
table) {
- assert context != null;
-
- switch (context.getType()) {
- case Resource:
- ResourceCriteria rc = new ResourceCriteria();
- rc.addFilterId(context.getResourceId());
- rc.fetchResourceType(true);
- GWTServiceLookup.getResourceService().findResourcesByCriteria(rc, new
AsyncCallback<PageList<Resource>>() {
- public void onSuccess(PageList<Resource> result) {
- if (result.isEmpty()) {
- throw new IllegalArgumentException("Entity not found ["
+ context + "]");
- }
-
- final Resource resource = result.get(0);
-
- // bypass type cache because this is infrequent an we don't need
to cache the
- // drift config templates
- ResourceTypeCriteria rtc = new ResourceTypeCriteria();
- rtc.addFilterId(resource.getResourceType().getId());
- rtc.fetchDriftConfigurationTemplates(true);
-
GWTServiceLookup.getResourceTypeGWTService().findResourceTypesByCriteria(rtc,
- new AsyncCallback<PageList<ResourceType>>() {
- public void onSuccess(PageList<ResourceType> result) {
- if (result.isEmpty()) {
- throw new IllegalArgumentException("Resource
Type not found ["
- + resource.getResourceType().getId() +
"]");
- }
-
- DriftAddConfigWizard wizard = new
DriftAddConfigWizard(context, result.get(0), table);
- wizard.startWizard();
- }
-
- public void onFailure(Throwable caught) {
-
CoreGUI.getErrorHandler().handleError(MSG.widget_typeTree_loadFail(), caught);
- }
- });
-
- }
-
- public void onFailure(Throwable caught) {
-
CoreGUI.getErrorHandler().handleError(MSG.view_inventory_resources_loadFailed(), caught);
- }
- });
-
- break;
-
- default:
- throw new IllegalArgumentException("Entity Context Type not supported
[" + context + "]");
- }
- }
-
- @Override
- public void cancel() {
- super.cancel();
- }
-
-}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizardConfigStep.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizardConfigStep.java
deleted file mode 100644
index c450086..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizardConfigStep.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.drift.wizard;
-
-import com.smartgwt.client.types.Overflow;
-import com.smartgwt.client.widgets.Canvas;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
-import org.rhq.core.domain.drift.DriftConfigurationDefinition;
-import
org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
-import org.rhq.enterprise.gui.coregui.client.components.wizard.AbstractWizardStep;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.Locatable;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
-
-/**
- * @author Jay Shaughnessy
- */
-public class DriftAddConfigWizardConfigStep extends AbstractWizardStep {
-
- private LocatableVLayout vLayout;
- private ConfigurationEditor editor;
- AbstractDriftAddConfigWizard wizard;
-
- public DriftAddConfigWizardConfigStep(AbstractDriftAddConfigWizard wizard) {
- this.wizard = wizard;
- }
-
- public Canvas getCanvas(Locatable parent) {
- // This VLayout allows us to set overflow on it and be able to scroll the config
editor but always
- // be able to see the wizard's next/cancel buttons. This vlayout also
provides for easier expansion if we add more items.
- if (vLayout == null) {
- String locatorId = (null == parent) ? "DriftConfig" :
parent.extendLocatorId("DriftConfig");
- vLayout = new LocatableVLayout(locatorId);
-
- vLayout.setOverflow(Overflow.AUTO);
-
- ConfigurationDefinition def = DriftConfigurationDefinition.getInstance();
- Configuration startingConfig = wizard.getNewStartingConfiguration();
- editor = new ConfigurationEditor(vLayout.extendLocatorId("Editor"),
def, startingConfig);
- vLayout.addMember(editor);
- }
-
- return vLayout;
- }
-
- public boolean nextPage() {
- if (editor != null && editor.validate()) {
- wizard.setNewConfiguration(editor.getConfiguration());
- wizard.execute();
- return true;
- }
-
- return false;
- }
-
- public String getName() {
- return MSG.widget_resourceFactoryWizard_editConfigStepName();
- }
-}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizardInfoStep.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizardInfoStep.java
deleted file mode 100644
index 6abc7e6..0000000
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddConfigWizardInfoStep.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * RHQ Management Platform
- * Copyright (C) 2011 Red Hat, Inc.
- * All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-package org.rhq.enterprise.gui.coregui.client.drift.wizard;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import com.smartgwt.client.types.Alignment;
-import com.smartgwt.client.types.TitleOrientation;
-import com.smartgwt.client.widgets.Canvas;
-import com.smartgwt.client.widgets.form.fields.FormItem;
-import com.smartgwt.client.widgets.form.fields.SelectItem;
-import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
-import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
-
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
-import org.rhq.enterprise.gui.coregui.client.components.wizard.AbstractWizardStep;
-import org.rhq.enterprise.gui.coregui.client.util.FormUtility;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.Locatable;
-import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
-
-/**
- * @author Jay Shaughnessy
- */
-public class DriftAddConfigWizardInfoStep extends AbstractWizardStep {
-
- private LocatableDynamicForm form;
- private AbstractDriftAddConfigWizard wizard;
- private Map<String, ConfigurationTemplate> templates;
-
- public DriftAddConfigWizardInfoStep(AbstractDriftAddConfigWizard wizard) {
- this.wizard = wizard;
- }
-
- public Canvas getCanvas(Locatable parent) {
- if (form == null) {
-
- if (parent != null) {
- form = new
LocatableDynamicForm(parent.extendLocatorId("DriftAddConfigInfo"));
- } else {
- form = new LocatableDynamicForm("DriftAddConfigInfo");
- }
- form.setNumCols(1);
- List<FormItem> formItems = new ArrayList<FormItem>(2);
-
- SelectItem templateSelect = new SelectItem("template",
MSG.view_drift_wizard_addDef_templatePrompt());
- templateSelect.setTitleOrientation(TitleOrientation.TOP);
- templateSelect.setAlign(Alignment.LEFT);
- templateSelect.setWidth(300);
- templateSelect.setRequired(true);
- FormUtility.addContextualHelp(templateSelect,
MSG.view_drift_wizard_addDef_templateHelp());
-
- Set<ConfigurationTemplate> templates =
wizard.getType().getDriftConfigurationTemplates();
- final HashMap<String, ConfigurationTemplate> templatesMap = new
HashMap<String, ConfigurationTemplate>(
- templates.size());
- if (!templates.isEmpty()) {
- for (ConfigurationTemplate template : templates) {
- templatesMap.put(template.getName(), template);
- }
- } else {
- // there should be at least one template for any resource type that
supports drift monitoring
- throw new IllegalStateException(
- "At least one drift configuration template should exist for the
resource type");
- }
-
- Set<String> templatesMapKeySet = templatesMap.keySet();
- String[] templatesMapKeySetArray = templatesMapKeySet.toArray(new
String[templatesMap.size()]);
- templateSelect.setValueMap(templatesMapKeySetArray);
- if (templatesMapKeySetArray.length == 1) {
- // there is only one, select it for the user
- String theOne = templatesMapKeySetArray[0];
- templateSelect.setValue(theOne);
-
wizard.setNewStartingConfiguration(templatesMap.get(theOne).createConfiguration());
- }
- templateSelect.addChangedHandler(new ChangedHandler() {
- public void onChanged(ChangedEvent event) {
- Object value = event.getValue();
- if (value == null) {
- value = "";
- }
-
wizard.setNewStartingConfiguration(templatesMap.get(value).createConfiguration());
- }
- });
-
- formItems.add(templateSelect);
-
- form.setItems(formItems.toArray(new FormItem[formItems.size()]));
- }
-
- return form;
- }
-
- public boolean nextPage() {
- return form.validate();
- }
-
- public String getName() {
- return MSG.view_drift_wizard_addDef_infoStepName();
- }
-
- public Configuration getStartingConfiguration() {
- String template = form.getValueAsString("template");
- return templates.get(template).createConfiguration();
- }
-}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizard.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizard.java
new file mode 100644
index 0000000..d61ee51
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizard.java
@@ -0,0 +1,160 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift.wizard;
+
+import java.util.ArrayList;
+
+import com.google.gwt.user.client.rpc.AsyncCallback;
+
+import org.rhq.core.domain.common.EntityContext;
+import org.rhq.core.domain.criteria.ResourceCriteria;
+import org.rhq.core.domain.criteria.ResourceTypeCriteria;
+import org.rhq.core.domain.resource.Resource;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.domain.util.PageList;
+import org.rhq.enterprise.gui.coregui.client.CoreGUI;
+import org.rhq.enterprise.gui.coregui.client.components.table.Table;
+import org.rhq.enterprise.gui.coregui.client.components.wizard.WizardStep;
+import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
+import org.rhq.enterprise.gui.coregui.client.util.message.Message;
+
+/**
+ * @author Jay Shaughnessy
+ */
+public class DriftAddDefinitionWizard extends AbstractDriftAddDefinitionWizard {
+
+ private Table<?> table;
+
+ public DriftAddDefinitionWizard(EntityContext context, ResourceType type,
Table<?> table) {
+
+ super(context, type);
+ this.table = table;
+
+ final ArrayList<WizardStep> steps = new ArrayList<WizardStep>();
+
+ steps.add(new DriftAddDefinitionWizardInfoStep(DriftAddDefinitionWizard.this));
+ steps.add(new
DriftAddDefinitionWizardConfigStep(DriftAddDefinitionWizard.this));
+
+ setSteps(steps);
+ }
+
+ public String getWindowTitle() {
+ return MSG.view_drift_wizard_addDef_windowTitle();
+ }
+
+ public String getTitle() {
+ return MSG.view_drift_wizard_addDef_title(getType().getName());
+ }
+
+ public String getSubtitle() {
+ return null;
+ }
+
+ public void execute() {
+ EntityContext context = getEntityContext();
+ switch (context.getType()) {
+ case Resource:
+
+ ResourceCriteria rc = new ResourceCriteria();
+ rc.addFilterId(context.getResourceId());
+ rc.fetchResourceType(true);
+ GWTServiceLookup.getDriftService().updateDriftDefinition(context,
getNewDriftDefinition(),
+ new AsyncCallback<Void>() {
+ public void onSuccess(Void result) {
+ CoreGUI.getMessageCenter().notify(
+ new
Message(MSG.view_drift_wizard_addDef_success(getNewDriftDefinition().getName()),
+ Message.Severity.Info));
+ getView().closeDialog();
+ DriftAddDefinitionWizard.this.table.refresh();
+ }
+
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError(
+
MSG.view_drift_wizard_addDef_failure(getNewDriftDefinition().getName()), caught);
+ getView().closeDialog();
+ }
+ });
+
+ break;
+
+ default:
+ throw new IllegalArgumentException("Entity Context Type not supported
[" + context + "]");
+ }
+
+ }
+
+ public static void showWizard(final EntityContext context, final Table<?>
table) {
+ assert context != null;
+
+ switch (context.getType()) {
+ case Resource:
+ ResourceCriteria rc = new ResourceCriteria();
+ rc.addFilterId(context.getResourceId());
+ rc.fetchResourceType(true);
+ GWTServiceLookup.getResourceService().findResourcesByCriteria(rc, new
AsyncCallback<PageList<Resource>>() {
+ public void onSuccess(PageList<Resource> result) {
+ if (result.isEmpty()) {
+ throw new IllegalArgumentException("Entity not found ["
+ context + "]");
+ }
+
+ final Resource resource = result.get(0);
+
+ // bypass type cache because this is infrequent an we don't need
to cache the
+ // drift def templates
+ ResourceTypeCriteria rtc = new ResourceTypeCriteria();
+ rtc.addFilterId(resource.getResourceType().getId());
+ rtc.fetchDriftDefinitionTemplates(true);
+
GWTServiceLookup.getResourceTypeGWTService().findResourceTypesByCriteria(rtc,
+ new AsyncCallback<PageList<ResourceType>>() {
+ public void onSuccess(PageList<ResourceType> result) {
+ if (result.isEmpty()) {
+ throw new IllegalArgumentException("Resource
Type not found ["
+ + resource.getResourceType().getId() +
"]");
+ }
+
+ DriftAddDefinitionWizard wizard = new
DriftAddDefinitionWizard(context, result.get(0),
+ table);
+ wizard.startWizard();
+ }
+
+ public void onFailure(Throwable caught) {
+
CoreGUI.getErrorHandler().handleError(MSG.widget_typeTree_loadFail(), caught);
+ }
+ });
+
+ }
+
+ public void onFailure(Throwable caught) {
+
CoreGUI.getErrorHandler().handleError(MSG.view_inventory_resources_loadFailed(), caught);
+ }
+ });
+
+ break;
+
+ default:
+ throw new IllegalArgumentException("Entity Context Type not supported
[" + context + "]");
+ }
+ }
+
+ @Override
+ public void cancel() {
+ super.cancel();
+ }
+
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizardConfigStep.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizardConfigStep.java
new file mode 100644
index 0000000..52a8667
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizardConfigStep.java
@@ -0,0 +1,76 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift.wizard;
+
+import com.smartgwt.client.types.Overflow;
+import com.smartgwt.client.widgets.Canvas;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition;
+import
org.rhq.enterprise.gui.coregui.client.components.configuration.ConfigurationEditor;
+import org.rhq.enterprise.gui.coregui.client.components.wizard.AbstractWizardStep;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.Locatable;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableVLayout;
+
+/**
+ * @author Jay Shaughnessy
+ */
+public class DriftAddDefinitionWizardConfigStep extends AbstractWizardStep {
+
+ private LocatableVLayout vLayout;
+ private ConfigurationEditor editor;
+ AbstractDriftAddDefinitionWizard wizard;
+
+ public DriftAddDefinitionWizardConfigStep(AbstractDriftAddDefinitionWizard wizard) {
+ this.wizard = wizard;
+ }
+
+ public Canvas getCanvas(Locatable parent) {
+ // This VLayout allows us to set overflow on it and be able to scroll the config
editor but always
+ // be able to see the wizard's next/cancel buttons. This vlayout also
provides for easier expansion if we add more items.
+ if (vLayout == null) {
+ String locatorId = (null == parent) ? "DriftDefConfig" :
parent.extendLocatorId("DriftDefConfig");
+ vLayout = new LocatableVLayout(locatorId);
+
+ vLayout.setOverflow(Overflow.AUTO);
+
+ ConfigurationDefinition def = DriftConfigurationDefinition.getInstance();
+ Configuration startingConfig = wizard.getNewStartingConfiguration();
+ editor = new ConfigurationEditor(vLayout.extendLocatorId("Editor"),
def, startingConfig);
+ vLayout.addMember(editor);
+ }
+
+ return vLayout;
+ }
+
+ public boolean nextPage() {
+ if (editor != null && editor.validate()) {
+ wizard.setNewConfiguration(editor.getConfiguration());
+ wizard.execute();
+ return true;
+ }
+
+ return false;
+ }
+
+ public String getName() {
+ return MSG.widget_resourceFactoryWizard_editConfigStepName();
+ }
+}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizardInfoStep.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizardInfoStep.java
new file mode 100644
index 0000000..5cacee2
--- /dev/null
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/wizard/DriftAddDefinitionWizardInfoStep.java
@@ -0,0 +1,125 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2011 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.rhq.enterprise.gui.coregui.client.drift.wizard;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import com.smartgwt.client.types.Alignment;
+import com.smartgwt.client.types.TitleOrientation;
+import com.smartgwt.client.widgets.Canvas;
+import com.smartgwt.client.widgets.form.fields.FormItem;
+import com.smartgwt.client.widgets.form.fields.SelectItem;
+import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
+import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
+
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
+import org.rhq.enterprise.gui.coregui.client.components.wizard.AbstractWizardStep;
+import org.rhq.enterprise.gui.coregui.client.util.FormUtility;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.Locatable;
+import org.rhq.enterprise.gui.coregui.client.util.selenium.LocatableDynamicForm;
+
+/**
+ * @author Jay Shaughnessy
+ */
+public class DriftAddDefinitionWizardInfoStep extends AbstractWizardStep {
+
+ private LocatableDynamicForm form;
+ private AbstractDriftAddDefinitionWizard wizard;
+ private Map<String, ConfigurationTemplate> templates;
+
+ public DriftAddDefinitionWizardInfoStep(AbstractDriftAddDefinitionWizard wizard) {
+ this.wizard = wizard;
+ }
+
+ public Canvas getCanvas(Locatable parent) {
+ if (form == null) {
+
+ if (parent != null) {
+ form = new
LocatableDynamicForm(parent.extendLocatorId("DriftAddDefInfo"));
+ } else {
+ form = new LocatableDynamicForm("DriftAddDefInfo");
+ }
+ form.setNumCols(1);
+ List<FormItem> formItems = new ArrayList<FormItem>(2);
+
+ SelectItem templateSelect = new SelectItem("template",
MSG.view_drift_wizard_addDef_templatePrompt());
+ templateSelect.setTitleOrientation(TitleOrientation.TOP);
+ templateSelect.setAlign(Alignment.LEFT);
+ templateSelect.setWidth(300);
+ templateSelect.setRequired(true);
+ FormUtility.addContextualHelp(templateSelect,
MSG.view_drift_wizard_addDef_templateHelp());
+
+ Set<ConfigurationTemplate> templates =
wizard.getType().getDriftDefinitionTemplates();
+ final HashMap<String, ConfigurationTemplate> templatesMap = new
HashMap<String, ConfigurationTemplate>(
+ templates.size());
+ if (!templates.isEmpty()) {
+ for (ConfigurationTemplate template : templates) {
+ templatesMap.put(template.getName(), template);
+ }
+ } else {
+ // there should be at least one template for any resource type that
supports drift monitoring
+ throw new IllegalStateException(
+ "At least one drift definition template should exist for the
resource type");
+ }
+
+ Set<String> templatesMapKeySet = templatesMap.keySet();
+ String[] templatesMapKeySetArray = templatesMapKeySet.toArray(new
String[templatesMap.size()]);
+ templateSelect.setValueMap(templatesMapKeySetArray);
+ if (templatesMapKeySetArray.length == 1) {
+ // there is only one, select it for the user
+ String theOne = templatesMapKeySetArray[0];
+ templateSelect.setValue(theOne);
+
wizard.setNewStartingConfiguration(templatesMap.get(theOne).createConfiguration());
+ }
+ templateSelect.addChangedHandler(new ChangedHandler() {
+ public void onChanged(ChangedEvent event) {
+ Object value = event.getValue();
+ if (value == null) {
+ value = "";
+ }
+
wizard.setNewStartingConfiguration(templatesMap.get(value).createConfiguration());
+ }
+ });
+
+ formItems.add(templateSelect);
+
+ form.setItems(formItems.toArray(new FormItem[formItems.size()]));
+ }
+
+ return form;
+ }
+
+ public boolean nextPage() {
+ return form.validate();
+ }
+
+ public String getName() {
+ return MSG.view_drift_wizard_addDef_infoStepName();
+ }
+
+ public Configuration getStartingConfiguration() {
+ String template = form.getValueAsString("template");
+ return templates.get(template).createConfiguration();
+ }
+}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
index d4faced..0b99c87 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
@@ -22,13 +22,13 @@ import com.google.gwt.user.client.rpc.RemoteService;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.criteria.DriftConfigurationCriteria;
+import org.rhq.core.domain.criteria.DriftDefinitionCriteria;
import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
import org.rhq.core.domain.criteria.GenericDriftCriteria;
import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftChangeSet;
import org.rhq.core.domain.drift.DriftComposite;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftDetails;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.drift.FileDiffReport;
@@ -42,24 +42,23 @@ public interface DriftGWTService extends RemoteService {
DriftSnapshot createSnapshot(Subject subject, GenericDriftChangeSetCriteria criteria)
throws RuntimeException;
/**
- * Delete all named drift configurations for the specified context if the current
user has permission to do so (i.e. either
+ * Delete all named drift definitions for the specified context if the current user
has permission to do so (i.e. either
* the MANAGE_INVENTORY global permission, or the MANAGE_DRIFT permission for all
corresponding resources).
*
* @param entityContext the context for deletion
- * @param driftConfigNames the names of the configs to delete
- * @return the number of drift configs deleted
+ * @param driftDefNames the names of the definitions to delete
+ * @return the number of drift definisions deleted
*/
- int deleteDriftConfigurationsByContext(EntityContext entityContext, String[]
driftConfigNames)
- throws RuntimeException;
+ int deleteDriftDefinitionsByContext(EntityContext entityContext, String[]
driftDefNames) throws RuntimeException;
/**
- * One time on-demand request to detect drift on the specified entities, using the
supplied config.
+ * One time on-demand request to detect drift on the specified entities, using the
supplied def.
*
* @param entityContext
- * @param driftConfig
+ * @param driftDef
* @throws RuntimeException
*/
- void detectDrift(EntityContext entityContext, DriftConfiguration driftConfig) throws
RuntimeException;
+ void detectDrift(EntityContext entityContext, DriftDefinition driftDef) throws
RuntimeException;
/**
* Find all drift changesets that match the specified criteria.
@@ -74,14 +73,13 @@ public interface DriftGWTService extends RemoteService {
PageList<DriftComposite> findDriftCompositesByCriteria(GenericDriftCriteria
criteria) throws RuntimeException;
/**
- * Find all drift configurations that match the specified criteria.
+ * Find all drift definitions that match the specified criteria.
*
* @param criteria the criteria
*
- * @return all drift configurations that matches the specified criteria
+ * @return all drift definitions that matches the specified criteria
*/
- PageList<DriftConfiguration>
findDriftConfigurationsByCriteria(DriftConfigurationCriteria criteria)
- throws RuntimeException;
+ PageList<DriftDefinition>
findDriftDefinitionsByCriteria(DriftDefinitionCriteria criteria) throws RuntimeException;
/**
* Find all drifts that match the specified criteria.
@@ -93,28 +91,28 @@ public interface DriftGWTService extends RemoteService {
PageList<? extends Drift<?, ?>> findDriftsByCriteria(GenericDriftCriteria
criteria) throws RuntimeException;
/**
- * Get the specified drift configuration.
+ * Get the specified drift definition.
*
- * @param driftConfigId
+ * @param driftDefId
* @return
* @throws RuntimeException
*/
- DriftConfiguration getDriftConfiguration(int driftConfigId) throws RuntimeException;
+ DriftDefinition getDriftDefinition(int driftDefId) throws RuntimeException;
/**
- * Update the provided driftConfig (identified by name) on the specified
EntityContext. If it exists it will be replaced. If not it will
+ * Update the provided driftDef (identified by name) on the specified EntityContext.
If it exists it will be replaced. If not it will
* be added. Agents, if available, will be notified of the change.
*
* @param entityContext
- * @param driftConfig
+ * @param driftDef
*/
- void updateDriftConfiguration(EntityContext entityContext, DriftConfiguration
driftConfig) throws RuntimeException;
+ void updateDriftDefinition(EntityContext entityContext, DriftDefinition driftDef)
throws RuntimeException;
String getDriftFileBits(String hash) throws RuntimeException;
- FileDiffReport generateUnifiedDiff(Drift drift) throws RuntimeException;
+ FileDiffReport generateUnifiedDiff(Drift<?, ?> drift) throws RuntimeException;
- boolean isBinaryFile(Drift drift) throws RuntimeException;
+ boolean isBinaryFile(Drift<?, ?> drift) throws RuntimeException;
DriftDetails getDriftDetails(String driftId) throws RuntimeException;
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
index 1ecd83f..3b553ca 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/groups/detail/ResourceGroupDetailView.java
@@ -51,7 +51,7 @@ import
org.rhq.enterprise.gui.coregui.client.components.tab.TwoLevelTab;
import org.rhq.enterprise.gui.coregui.client.components.tab.TwoLevelTabSelectedEvent;
import org.rhq.enterprise.gui.coregui.client.components.view.ViewFactory;
import org.rhq.enterprise.gui.coregui.client.components.view.ViewName;
-import org.rhq.enterprise.gui.coregui.client.drift.ResourceDriftConfigurationView;
+import org.rhq.enterprise.gui.coregui.client.drift.ResourceDriftDefinitionsView;
import org.rhq.enterprise.gui.coregui.client.drift.ResourceDriftHistoryView;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.InventoryView;
@@ -471,7 +471,7 @@ public class ResourceGroupDetailView extends
AbstractTwoLevelTabSetView<Resource
updateSubTab(this.driftTab, this.driftConfig, true, true, new ViewFactory()
{
@Override
public Canvas createView() {
- return
ResourceDriftConfigurationView.get(driftConfig.extendLocatorId("View"), null);
+ return
ResourceDriftDefinitionsView.get(driftConfig.extendLocatorId("View"), null);
}
});
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
index ae39e50..40d9388 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/detail/ResourceDetailView.java
@@ -51,7 +51,7 @@ import
org.rhq.enterprise.gui.coregui.client.components.tab.TwoLevelTab;
import org.rhq.enterprise.gui.coregui.client.components.view.ViewFactory;
import org.rhq.enterprise.gui.coregui.client.components.view.ViewName;
import org.rhq.enterprise.gui.coregui.client.drift.ResourceDriftChangeSetsView;
-import org.rhq.enterprise.gui.coregui.client.drift.ResourceDriftConfigurationView;
+import org.rhq.enterprise.gui.coregui.client.drift.ResourceDriftDefinitionsView;
import org.rhq.enterprise.gui.coregui.client.drift.ResourceDriftHistoryView;
import org.rhq.enterprise.gui.coregui.client.gwt.GWTServiceLookup;
import org.rhq.enterprise.gui.coregui.client.inventory.InventoryView;
@@ -540,7 +540,7 @@ public class ResourceDetailView extends
AbstractTwoLevelTabSetView<ResourceCompo
updateSubTab(this.driftTab, this.driftDefinitions, true, true, new
ViewFactory() {
@Override
public Canvas createView() {
- return
ResourceDriftConfigurationView.get(driftDefinitions.extendLocatorId("View"),
+ return
ResourceDriftDefinitionsView.get(driftDefinitions.extendLocatorId("View"),
resourceComposite);
}
});
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/type/ResourceTypeRepository.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/type/ResourceTypeRepository.java
index d9689aa..b9cd91b 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/type/ResourceTypeRepository.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/inventory/resource/type/ResourceTypeRepository.java
@@ -247,7 +247,7 @@ public class ResourceTypeRepository {
criteria.fetchSubCategory(true);
break;
case driftConfigurationTemplates:
- criteria.fetchDriftConfigurationTemplates(true);
+ criteria.fetchDriftDefinitionTemplates(true);
break;
default:
Log.error("ERROR: metadataType " + metadataType.name()
@@ -353,12 +353,12 @@ public class ResourceTypeRepository {
cachedType.setSubCategory(type.getSubCategory());
break;
case driftConfigurationTemplates:
- if (cachedType.getDriftConfigurationTemplates() !=
null) {
-
cachedType.getDriftConfigurationTemplates().clear(); // remove any old ones hanging
around
+ if (cachedType.getDriftDefinitionTemplates() != null)
{
+ cachedType.getDriftDefinitionTemplates().clear();
// remove any old ones hanging around
}
- if (type.getDriftConfigurationTemplates() != null) {
- for (ConfigurationTemplate ct :
type.getDriftConfigurationTemplates()) {
-
cachedType.addDriftConfigurationTemplate(ct);
+ if (type.getDriftDefinitionTemplates() != null) {
+ for (ConfigurationTemplate ct :
type.getDriftDefinitionTemplates()) {
+ cachedType.addDriftDefinitionTemplate(ct);
}
}
break;
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestDataSourceResponseStatisticsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestDataSourceResponseStatisticsView.java
index 83a8579..26a7177 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestDataSourceResponseStatisticsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestDataSourceResponseStatisticsView.java
@@ -162,7 +162,7 @@ public class TestDataSourceResponseStatisticsView extends Table {
timerTitleString = null;
}
- setTableTitle(getTableTitle());
+ updateTitleCanvas(getTableTitle());
if (window != null) {
window.setTitle(getTableTitle());
}
@@ -263,7 +263,7 @@ public class TestDataSourceResponseStatisticsView extends Table {
timerTitleString = " (refresh every " + timeout +
"s)";
}
- setTableTitle(getTableTitle());
+ updateTitleCanvas(getTableTitle());
if (window != null) {
window.setTitle(getTableTitle());
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestRemoteServiceStatisticsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestRemoteServiceStatisticsView.java
index 8195198..af14f3b 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestRemoteServiceStatisticsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/test/TestRemoteServiceStatisticsView.java
@@ -200,13 +200,13 @@ public class TestRemoteServiceStatisticsView extends Table {
refreshOnPageChange = false;
if (timeout.intValue() == -1) {
- setTableTitle(TABLE_TITLE);
+ updateTitleCanvas(TABLE_TITLE);
} else if (timeout.intValue() == 0) {
refreshOnPageChange = true;
- setTableTitle(TABLE_TITLE + " (refresh on page
change)");
+ updateTitleCanvas(TABLE_TITLE + " (refresh on page
change)");
} else {
refreshTimer.scheduleRepeating(timeout.intValue() * 1000);
- setTableTitle(TABLE_TITLE + " (refresh every " +
timeout + "s)");
+ updateTitleCanvas(TABLE_TITLE + " (refresh every "
+ timeout + "s)");
}
refreshTableInfo();
}
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
index 1a6b896..be1edfc 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/util/message/MessageCenterView.java
@@ -138,7 +138,7 @@ public class MessageCenterView extends Table implements
MessageCenter.MessageLis
protected void configureTable() {
getListGrid().setEmptyMessage(MSG.view_messageCenter_noRecentMessages());
-
setTableTitle(MSG.view_messageCenter_lastNMessages(String.valueOf(CoreGUI.getMessageCenter().getMaxMessages())));
+
updateTitleCanvas(MSG.view_messageCenter_lastNMessages(String.valueOf(CoreGUI.getMessageCenter().getMaxMessages())));
ListGridField severityField = new ListGridField(FIELD_SEVERITY);
severityField.setType(ListGridFieldType.ICON);
@@ -259,7 +259,7 @@ public class MessageCenterView extends Table implements
MessageCenter.MessageLis
try {
Integer maxSize = (Integer) actionValue;
CoreGUI.getMessageCenter().setMaxMessages(maxSize.intValue());
-
setTableTitle(MSG.view_messageCenter_lastNMessages(maxSize.toString()));
+
updateTitleCanvas(MSG.view_messageCenter_lastNMessages(maxSize.toString()));
refresh();
} catch (Throwable e) {
Log.error("Cannot set max messages", e);
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
index 55f9f7e..6e41279 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
@@ -20,13 +20,13 @@ package org.rhq.enterprise.gui.coregui.server.gwt;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.criteria.DriftConfigurationCriteria;
+import org.rhq.core.domain.criteria.DriftDefinitionCriteria;
import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
import org.rhq.core.domain.criteria.GenericDriftCriteria;
import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftChangeSet;
import org.rhq.core.domain.drift.DriftComposite;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftDetails;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.drift.FileDiffReport;
@@ -45,22 +45,22 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
private DriftManagerLocal driftManager = LookupUtil.getDriftManager();
@Override
- public int deleteDriftConfigurationsByContext(EntityContext entityContext, String[]
driftConfigNames)
+ public int deleteDriftDefinitionsByContext(EntityContext entityContext, String[]
driftDefinitionNames)
throws RuntimeException {
try {
- for (String driftConfigName : driftConfigNames) {
- this.driftManager.deleteDriftConfiguration(getSessionSubject(),
entityContext, driftConfigName);
+ for (String driftDefName : driftDefinitionNames) {
+ this.driftManager.deleteDriftDefinition(getSessionSubject(),
entityContext, driftDefName);
}
- return driftConfigNames.length;
+ return driftDefinitionNames.length;
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
}
@Override
- public void detectDrift(EntityContext entityContext, DriftConfiguration driftConfig)
throws RuntimeException {
+ public void detectDrift(EntityContext entityContext, DriftDefinition driftDef) throws
RuntimeException {
try {
- this.driftManager.detectDrift(getSessionSubject(), entityContext,
driftConfig);
+ this.driftManager.detectDrift(getSessionSubject(), entityContext, driftDef);
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
@@ -101,12 +101,12 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
}
@Override
- public PageList<DriftConfiguration>
findDriftConfigurationsByCriteria(DriftConfigurationCriteria criteria)
+ public PageList<DriftDefinition>
findDriftDefinitionsByCriteria(DriftDefinitionCriteria criteria)
throws RuntimeException {
try {
- PageList<DriftConfiguration> results =
driftManager.findDriftConfigurationsByCriteria(getSessionSubject(),
+ PageList<DriftDefinition> results =
driftManager.findDriftDefinitionsByCriteria(getSessionSubject(),
criteria);
- return SerialUtility.prepare(results,
"DriftService.findDriftConfigurationsByCriteria");
+ return SerialUtility.prepare(results,
"DriftService.findDriftDefinitionsByCriteria");
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
@@ -123,20 +123,19 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
}
@Override
- public DriftConfiguration getDriftConfiguration(int driftConfigId) throws
RuntimeException {
+ public DriftDefinition getDriftDefinition(int driftDefId) throws RuntimeException {
try {
- DriftConfiguration driftConfig =
driftManager.getDriftConfiguration(getSessionSubject(), driftConfigId);
- return SerialUtility.prepare(driftConfig,
"DriftService.getDriftConfiguration");
+ DriftDefinition driftDef =
driftManager.getDriftDefinition(getSessionSubject(), driftDefId);
+ return SerialUtility.prepare(driftDef,
"DriftService.getDriftDefinition");
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
}
@Override
- public void updateDriftConfiguration(EntityContext entityContext, DriftConfiguration
driftConfig)
- throws RuntimeException {
+ public void updateDriftDefinition(EntityContext entityContext, DriftDefinition
driftDef) throws RuntimeException {
try {
- this.driftManager.updateDriftConfiguration(getSessionSubject(),
entityContext, driftConfig);
+ this.driftManager.updateDriftDefinition(getSessionSubject(), entityContext,
driftDef);
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
@@ -152,7 +151,7 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
}
@Override
- public FileDiffReport generateUnifiedDiff(Drift drift) throws RuntimeException {
+ public FileDiffReport generateUnifiedDiff(Drift<?, ?> drift) throws
RuntimeException {
try {
return driftManager.generateUnifiedDiff(drift);
} catch (Throwable t) {
@@ -171,7 +170,7 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
}
@Override
- public boolean isBinaryFile(Drift drift) throws RuntimeException {
+ public boolean isBinaryFile(Drift<?, ?> drift) throws RuntimeException {
try {
return driftManager.isBinaryFile(drift);
} catch (Throwable t) {
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 9e4311a..bbb8889 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
@@ -25,6 +25,7 @@ common_button_disable = Disable
common_button_edit = Edit
common_button_enable = Enable
common_button_finish = Finish
+common_button_fixedWidth = Fixed Width
common_button_import = Import
common_button_new = New
common_button_next = Next
@@ -34,6 +35,7 @@ common_button_purgeAll = Purge All
common_button_refresh = Refresh
common_button_reset = Reset
common_button_save = Save
+common_button_scaleToFit = Scale To Fit
common_button_schedule = Schedule
common_button_search = Search
common_button_set = Set
@@ -55,6 +57,7 @@ common_label_ago = ago
common_label_all = ALL
common_label_all_resources = all resources
common_label_day = day
+common_label_filters = Filters
common_label_hour = hour
common_label_item = item
common_label_items = items
@@ -1117,12 +1120,14 @@ view_dashboards_portlets_refresh_success1 = Updated interval for
portlets that a
view_dashboards_portlets_refresh_success2 = Stopping reload for portlets that
auto-refresh
view_dashboards_title = Dashboard
view_drift_button_detectNow = Detect Now
+view_drift_carousel_sizeFilterLabel = Number of Snapshots
+view_drift_carousel_startFilterLabel = Starting Snapshot
view_drift_category_fileAdded = File Added
view_drift_category_fileChanged = File Changed
view_drift_category_fileNew = Newly Detected
view_drift_category_fileRemoved = File Removed
-view_drift_delete_configConfirm = Delete the selected drift detection definition(s)?
-view_drift_delete_configConfirmAll = Delete all drift detection definition?
+view_drift_delete_defConfirm = Delete the selected drift detection definition(s)?
+view_drift_delete_defConfirmAll = Delete all drift detection definition?
view_drift_failure_deleteDefs = Failed to delete some or all drift detection
definitions.
view_drift_failure_detectNow = Failed to submit drift detection run request
view_drift_failure_load = Failed to fetch drift instances
@@ -1132,7 +1137,7 @@ view_drift_snapshots_tree_loadDefFailure = Failed to load drift
detection defini
view_drift_snapshots_tree_loadFailure = Failed to load drift snapshot tree.
view_drift_success_defUpdated = Drift detection definition updated and will affect the
next detection run as applicable.
view_drift_success_delete = Successfully deleted {0} drift instances
-view_drift_success_deleteConfigs = Successfully deleted {0} drift detection definitions
+view_drift_success_deleteDefs = Successfully deleted {0} drift detection definitions
view_drift_success_detectNow = Successfully submitted drift detection run request
view_drift_table_baseDir = Base Directory
view_drift_table_driftHandlingMode = Drift Handling
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
index 2c84b0b..a3a5d9f 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_de.properties
@@ -27,6 +27,7 @@ common_button_disable = Deaktivieren
common_button_edit = Bearbeiten
common_button_enable = Aktivieren
common_button_finish = Beenden
+##common_button_fixedWidth = Fixed Width
common_button_import = Importieren
common_button_new = Neu
common_button_next = Weiter
@@ -36,6 +37,7 @@ common_button_purgeAll = Alle löschen
common_button_refresh = Neu laden
common_button_reset = Zurücksetzen
common_button_save = Speichern
+##common_button_scaleToFit = Scale To Fit
common_button_schedule = Planen
common_button_search = Suchen
common_button_set = Setzen
@@ -57,6 +59,7 @@ common_calendar_september_short = Sept
common_label_all = ALLE
common_label_all_resources = Alle Ressourcen
common_label_day = Tag
+##common_label_filters = Filters
common_label_hour = Stunde
common_label_item = Eintrag
common_label_items = Einträge
@@ -949,12 +952,14 @@ view_dashboardsManager_message_title_details = <h1>Willkommen
bei RHQ</h1>\n<p>D
view_dashboards_confirm1 = Sind Sie sicher, dass Sie löschen möchten
view_dashboards_title = Dashboard
##view_drift_button_detectNow = Detect Now
+##view_drift_carousel_sizeFilterLabel = Number of Snapshots
+##view_drift_carousel_startFilterLabel = Starting Snapshot
##view_drift_category_fileAdded = File Added
##view_drift_category_fileChanged = File Changed
##view_drift_category_fileNew = Newly Detected
##view_drift_category_fileRemoved = File Removed
-##view_drift_delete_configConfirm = Delete the selected drift detection definition(s)?
-##view_drift_delete_configConfirmAll = Delete all drift detection definition?
+view_drift_delete_defConfirm = Delete the selected drift detection definition(s)?
+view_drift_delete_defConfirmAll = Delete all drift detection definition?
##view_drift_failure_deleteDefs = Failed to delete some or all drift detection
definitions.
##view_drift_failure_detectNow = Failed to submit drift detection run request
##view_drift_failure_load = Failed to fetch drift instances
@@ -964,7 +969,7 @@ view_dashboards_title = Dashboard
##view_drift_snapshots_tree_loadFailure = Failed to load drift snapshot tree.
##view_drift_success_defUpdated = Drift detection definition updated and will affect the
next detection run as applicable.
##view_drift_success_delete = Successfully deleted {0} drift instances
-##view_drift_success_deleteConfigs = Successfully deleted {0} drift detection
definitions
+view_drift_success_deleteDefs = Successfully deleted {0} drift detection definitions
##view_drift_success_detectNow = Successfully submitted drift detection run request
##view_drift_table_baseDir = Base Directory
##view_drift_table_driftHandlingMode = Drift Handling
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
index 0730e55..6c726ea 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_ja.properties
@@ -27,6 +27,7 @@ common_button_disable = 無効
common_button_edit = 編集
common_button_enable = 有効
common_button_finish = 完了
+##common_button_fixedWidth = Fixed Width
common_button_import = インポート
common_button_new = 新規
common_button_next = 次へ
@@ -36,6 +37,7 @@ common_button_purgeAll = すべてをパージ
common_button_refresh = リフレッシュ
common_button_reset = リセット
common_button_save = 保存
+##common_button_scaleToFit = Scale To Fit
common_button_schedule = スケジュール
common_button_search = 検索
common_button_set = 設定
@@ -57,6 +59,7 @@ common_label_ago = 前
common_label_all = すべての
common_label_all_resources = すべてのリソース
common_label_day = 日
+##common_label_filters = Filters
common_label_hour = 時間
common_label_item = 項目
common_label_items = 項目
@@ -1109,12 +1112,14 @@ view_dashboards_portlets_refresh_success1 = ポートレットの自動リフレ
view_dashboards_portlets_refresh_success2 = 自動リフレッシュするポートレットのリロードを停止しています
view_dashboards_title = ダッシュボード
##view_drift_button_detectNow = Detect Now
+##view_drift_carousel_sizeFilterLabel = Number of Snapshots
+##view_drift_carousel_startFilterLabel = Starting Snapshot
##view_drift_category_fileAdded = File Added
##view_drift_category_fileChanged = File Changed
##view_drift_category_fileNew = Newly Detected
##view_drift_category_fileRemoved = File Removed
-##view_drift_delete_configConfirm = Delete the selected drift detection definition(s)?
-##view_drift_delete_configConfirmAll = Delete all drift detection definition?
+view_drift_delete_defConfirm = Delete the selected drift detection definition(s)?
+view_drift_delete_defConfirmAll = Delete all drift detection definition?
##view_drift_failure_deleteDefs = Failed to delete some or all drift detection
definitions.
##view_drift_failure_detectNow = Failed to submit drift detection run request
##view_drift_failure_load = Failed to fetch drift instances
@@ -1124,7 +1129,7 @@ view_dashboards_title = ダッシュボード
##view_drift_snapshots_tree_loadFailure = Failed to load drift snapshot tree.
##view_drift_success_defUpdated = Drift detection definition updated and will affect the
next detection run as applicable.
##view_drift_success_delete = Successfully deleted {0} drift instances
-##view_drift_success_deleteConfigs = Successfully deleted {0} drift detection
definitions
+view_drift_success_deleteDefs = Successfully deleted {0} drift detection definitions
##view_drift_success_detectNow = Successfully submitted drift detection run request
##view_drift_table_baseDir = Base Directory
##view_drift_table_driftHandlingMode = Drift Handling
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
index fe0c5dc..825ef50 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_pt.properties
@@ -25,6 +25,7 @@ common_button_disable = Desabilitar
common_button_edit = Editar
common_button_enable = Habilitar
common_button_finish = Finalizar
+##common_button_fixedWidth = Fixed Width
common_button_import = Importar
common_button_new = Novo
common_button_next = Pr\u00F3ximo
@@ -34,6 +35,7 @@ common_button_purgeAll = Remover Todos
common_button_refresh = Atualizar
common_button_reset = Limpar
common_button_save = Salvar
+##common_button_scaleToFit = Scale To Fit
common_button_schedule = Agendar
common_button_search = Procurar
common_button_set = Definir
@@ -55,6 +57,7 @@ common_calendar_september_short = set
common_label_all = TODOS
common_label_all_resources = todos os recursos
common_label_day = dia
+##common_label_filters = Filters
common_label_hour = hora
common_label_item = item
common_label_items = itens
@@ -1137,12 +1140,14 @@ view_dashboards_portlets_refresh_success1 = Intervalo de
atualiza\u00E7\u00E3o d
view_dashboards_portlets_refresh_success2 = Parando a atualiza\u00E7\u00E3o
autom\u00E1tica dos portlets din\u00E2micos
view_dashboards_title = Dashboard
view_drift_button_detectNow = Detectar agora
+##view_drift_carousel_sizeFilterLabel = Number of Snapshots
+##view_drift_carousel_startFilterLabel = Starting Snapshot
view_drift_category_fileAdded = Arquivo adicionado
view_drift_category_fileChanged = Arquivo alterado
##view_drift_category_fileNew = Newly Detected
##view_drift_category_fileRemoved = Arquivo removido
-##view_drift_delete_configConfirm = Delete the selected drift detection definition(s)?
-##view_drift_delete_configConfirmAll = Delete all drift detection definition?
+view_drift_delete_defConfirm = Delete the selected drift detection definition(s)?
+view_drift_delete_defConfirmAll = Delete all drift detection definition?
##view_drift_failure_deleteDefs = Failed to delete some or all drift detection
definitions.
view_drift_failure_detectNow = Falha ao submeter a requisi��o de detec��o do drift
view_drift_failure_load = Falha ao recuperar os dados do drift
@@ -1152,7 +1157,7 @@ view_drift_failure_load = Falha ao recuperar os dados do drift
##view_drift_snapshots_tree_loadFailure = Failed to load drift snapshot tree.
##view_drift_success_defUpdated = Drift detection definition updated and will affect the
next detection run as applicable.
view_drift_success_delete = Drifts {0} exclu�dos com sucesso!
-##view_drift_success_deleteConfigs = Successfully deleted {0} drift detection
definitions
+view_drift_success_deleteDefs = Successfully deleted {0} drift detection definitions
view_drift_success_detectNow = Requisi��o de detec��o de drift submetida com sucesso.
##view_drift_table_baseDir = Diret�rio Base
##view_drift_table_driftHandlingMode = Drift Handling
diff --git
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
index 1905e96..9214c91 100644
---
a/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
+++
b/modules/enterprise/gui/coregui/src/main/resources/org/rhq/enterprise/gui/coregui/client/Messages_zh.properties
@@ -25,6 +25,7 @@ common_button_disable = \u7981\u7528
common_button_edit = \u7f16\u8f91
common_button_enable = \u542f\u7528
common_button_finish = \u5b8c\u6210
+##common_button_fixedWidth = Fixed Width
common_button_import = \u5bfc\u5165
common_button_new = \u65b0\u5efa
common_button_next = \u4e0b\u4e00\u6b65
@@ -34,6 +35,7 @@ common_button_purgeAll = \u6e05\u9664\u6240\u6709
common_button_refresh = \u5237\u65b0
common_button_reset = \u91cd\u7f6e
common_button_save = \u4fdd\u5b58
+##common_button_scaleToFit = Scale To Fit
common_button_schedule = \u8ba1\u5212
common_button_search = \u68c0\u7d22
common_button_set = Set
@@ -55,6 +57,7 @@ common_calendar_september_short = \u4e5d\u6708
common_label_all = \u6240\u6709
common_label_all_resources = \u6240\u6709\u8d44\u6e90
common_label_day = \u5929
+##common_label_filters = Filters
common_label_hour = \u5c0f\u65f6
common_label_item = \u9879
common_label_items = \u9879
@@ -1117,12 +1120,14 @@ view_dashboards_portlets_refresh_success1 =
\u6210\u529f\u4fee\u6539portlets\u81
view_dashboards_portlets_refresh_success2 =
\u6210\u529f\u505c\u7528portlets\u81ea\u52a8\u5237\u65b0\u7684\u91cd\u8f7d
view_dashboards_title = \u7edf\u8ba1\u8868\u76d8
##view_drift_button_detectNow = Detect Now
+##view_drift_carousel_sizeFilterLabel = Number of Snapshots
+##view_drift_carousel_startFilterLabel = Starting Snapshot
##view_drift_category_fileAdded = File Added
##view_drift_category_fileChanged = File Changed
##view_drift_category_fileNew = Newly Detected
##view_drift_category_fileRemoved = File Removed
-##view_drift_delete_configConfirm = Delete the selected drift detection definition(s)?
-##view_drift_delete_configConfirmAll = Delete all drift detection definition?
+view_drift_delete_defConfirm = Delete the selected drift detection definition(s)?
+view_drift_delete_defConfirmAll = Delete all drift detection definition?
##view_drift_failure_deleteDefs = Failed to delete some or all drift detection
definitions.
##view_drift_failure_detectNow = Failed to submit drift detection run request
##view_drift_failure_load = Failed to fetch drift instances
@@ -1132,7 +1137,7 @@ view_dashboards_title = \u7edf\u8ba1\u8868\u76d8
##view_drift_snapshots_tree_loadFailure = Failed to load drift snapshot tree.
##view_drift_success_defUpdated = Drift detection definition updated and will affect the
next detection run as applicable.
##view_drift_success_delete = Successfully deleted {0} drift instances
-##view_drift_success_deleteConfigs = Successfully deleted {0} drift detection
definitions
+view_drift_success_deleteDefs = Successfully deleted {0} drift detection definitions
##view_drift_success_detectNow = Successfully submitted drift detection run request
##view_drift_table_baseDir = Base Directory
##view_drift_table_driftHandlingMode = Drift Handling
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
index 7527fdc..1abb690 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/engine/model/DriftCacheElement.java
@@ -65,7 +65,7 @@ public class DriftCacheElement extends
AbstractCacheElement<Object> {
}
if (driftConfigNameRegex != null) {
- if
(!driftConfigNameRegex.matcher(summary.getDriftConfigurationName()).matches()) {
+ if
(!driftConfigNameRegex.matcher(summary.getDriftDefinitionName()).matches()) {
return false; // drift config name did not match, our condition is
false so don't alert
}
}
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
index aafd0bb..de0f3bf 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
@@ -18,6 +18,10 @@
*/
package org.rhq.enterprise.server.drift;
+import static java.util.Arrays.asList;
+import static javax.ejb.TransactionAttributeType.NOT_SUPPORTED;
+import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
+
import java.io.File;
import java.io.InputStream;
import java.util.HashSet;
@@ -37,6 +41,9 @@ import javax.jms.Session;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
+import difflib.DiffUtils;
+import difflib.Patch;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -46,22 +53,22 @@ import org.rhq.core.clientapi.agent.drift.DriftAgentService;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.common.EntityContext;
import org.rhq.core.domain.criteria.DriftChangeSetCriteria;
-import org.rhq.core.domain.criteria.DriftConfigurationCriteria;
import org.rhq.core.domain.criteria.DriftCriteria;
+import org.rhq.core.domain.criteria.DriftDefinitionCriteria;
import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
import org.rhq.core.domain.criteria.GenericDriftCriteria;
import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftChangeSet;
import org.rhq.core.domain.drift.DriftComposite;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfigurationComparator;
-import org.rhq.core.domain.drift.DriftConfigurationComparator.CompareMode;
import org.rhq.core.domain.drift.DriftConfigurationDefinition;
-import org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
+import org.rhq.core.domain.drift.DriftDefinition;
+import org.rhq.core.domain.drift.DriftDefinitionComparator;
import org.rhq.core.domain.drift.DriftDetails;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.drift.FileDiffReport;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition.DriftHandlingMode;
+import org.rhq.core.domain.drift.DriftDefinitionComparator.CompareMode;
import org.rhq.core.domain.resource.Resource;
import org.rhq.core.domain.util.PageList;
import org.rhq.enterprise.server.RHQConstants;
@@ -79,13 +86,6 @@ import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
import org.rhq.enterprise.server.util.CriteriaQueryRunner;
import org.rhq.enterprise.server.util.LookupUtil;
-import difflib.DiffUtils;
-import difflib.Patch;
-
-import static java.util.Arrays.asList;
-import static javax.ejb.TransactionAttributeType.NOT_SUPPORTED;
-import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
-
/**
* The SLSB supporting Drift management to clients.
*
@@ -226,7 +226,7 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
}
@Override
- public void detectDrift(Subject subject, EntityContext context, DriftConfiguration
driftConfig) {
+ public void detectDrift(Subject subject, EntityContext context, DriftDefinition
driftDef) {
switch (context.getType()) {
case Resource:
int resourceId = context.getResourceId();
@@ -240,11 +240,11 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
// this is a one-time on-demand call. If it fails throw an exception to make
sure the user knows it
// did not happen. But clean it up a bit if it's a connect exception
try {
- service.detectDrift(resourceId, driftConfig);
+ service.detectDrift(resourceId, driftDef);
} catch (CannotConnectException e) {
throw new IllegalStateException(
"Agent could not be reached and may be down (see server logs for
more). Could not perform drift detection request ["
- + driftConfig + "]");
+ + driftDef + "]");
}
break;
@@ -256,52 +256,52 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
@Override
@TransactionAttribute(NOT_SUPPORTED)
- public void deleteDriftConfiguration(Subject subject, EntityContext entityContext,
String driftConfigName) {
+ public void deleteDriftDefinition(Subject subject, EntityContext entityContext,
String driftDefName) {
switch (entityContext.getType()) {
case Resource:
int resourceId = entityContext.getResourceId();
- DriftConfigurationCriteria criteria = new DriftConfigurationCriteria();
- criteria.addFilterName(driftConfigName);
+ DriftDefinitionCriteria criteria = new DriftDefinitionCriteria();
+ criteria.addFilterName(driftDefName);
criteria.addFilterResourceIds(resourceId);
criteria.setStrict(true);
- PageList<DriftConfiguration> results =
driftManager.findDriftConfigurationsByCriteria(subject, criteria);
- DriftConfiguration doomedDriftConfig = null;
+ PageList<DriftDefinition> results =
driftManager.findDriftDefinitionsByCriteria(subject, criteria);
+ DriftDefinition doomedDriftDef = null;
if (results != null && results.size() == 1) {
- doomedDriftConfig = results.get(0);
+ doomedDriftDef = results.get(0);
}
- if (doomedDriftConfig != null) {
+ if (doomedDriftDef != null) {
// TODO security check!
- // tell the agent first - we don't want the agent reporting on the
drift config after we delete it
+ // tell the agent first - we don't want the agent reporting on the
drift def after we delete it
boolean unscheduledOnAgent = false;
try {
AgentClient agentClient =
agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
DriftAgentService service = agentClient.getDriftAgentService();
- service.unscheduleDriftDetection(resourceId, doomedDriftConfig);
+ service.unscheduleDriftDetection(resourceId, doomedDriftDef);
unscheduledOnAgent = true;
} catch (Exception e) {
- log.warn(" Unable to inform agent of unscheduled drift detection
[" + doomedDriftConfig + "]", e);
+ log.warn(" Unable to inform agent of unscheduled drift detection
[" + doomedDriftDef + "]", e);
}
- // purge all data related to this drift configuration
+ // purge all data related to this drift definition
try {
- driftManager.purgeByDriftConfigurationName(subject, resourceId,
doomedDriftConfig.getName());
+ driftManager.purgeByDriftDefinitionName(subject, resourceId,
doomedDriftDef.getName());
} catch (Exception e) {
- String warnMessage = "Failed to purge data for drift
configuration [" + driftConfigName
+ String warnMessage = "Failed to purge data for drift definition
[" + driftDefName
+ "] for resource [" + resourceId + "].";
if (unscheduledOnAgent) {
- warnMessage += " The agent was told to stop detecting drift
for that configuration.";
+ warnMessage += " The agent was told to stop detecting drift
for that definition.";
}
log.warn(warnMessage, e);
}
- // now purge the drift config itself
- driftManager.deleteResourceDriftConfiguration(subject, resourceId,
doomedDriftConfig.getId());
+ // now purge the drift def itself
+ driftManager.deleteResourceDriftDefinition(subject, resourceId,
doomedDriftDef.getId());
} else {
- throw new IllegalArgumentException("Resource does not have drift
config named [" + driftConfigName
+ throw new IllegalArgumentException("Resource does not have drift
definition named [" + driftDefName
+ "]");
}
break;
@@ -312,8 +312,8 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
}
@Override
- public void deleteResourceDriftConfiguration(Subject subject, int resourceId, int
driftConfigId) {
- DriftConfiguration doomed = entityManager.getReference(DriftConfiguration.class,
driftConfigId);
+ public void deleteResourceDriftDefinition(Subject subject, int resourceId, int
driftDefId) {
+ DriftDefinition doomed = entityManager.getReference(DriftDefinition.class,
driftDefId);
doomed.getResource().setAgentSynchronizationNeeded();
entityManager.remove(doomed);
return;
@@ -335,13 +335,12 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
}
@Override
- public PageList<DriftConfiguration> findDriftConfigurationsByCriteria(Subject
subject,
- DriftConfigurationCriteria criteria) {
+ public PageList<DriftDefinition> findDriftDefinitionsByCriteria(Subject
subject, DriftDefinitionCriteria criteria) {
CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject,
criteria);
- CriteriaQueryRunner<DriftConfiguration> queryRunner = new
CriteriaQueryRunner<DriftConfiguration>(criteria,
+ CriteriaQueryRunner<DriftDefinition> queryRunner = new
CriteriaQueryRunner<DriftDefinition>(criteria,
generator, entityManager);
- PageList<DriftConfiguration> result = queryRunner.execute();
+ PageList<DriftDefinition> result = queryRunner.execute();
return result;
}
@@ -354,11 +353,11 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
}
@Override
- public DriftConfiguration getDriftConfiguration(Subject subject, int driftConfigId)
{
- DriftConfiguration result = entityManager.find(DriftConfiguration.class,
driftConfigId);
+ public DriftDefinition getDriftDefinition(Subject subject, int driftDefId) {
+ DriftDefinition result = entityManager.find(DriftDefinition.class, driftDefId);
if (null == result) {
- throw new IllegalArgumentException("Drift Configuration Id [" +
driftConfigId + "] not found.");
+ throw new IllegalArgumentException("Drift Definition Id [" +
driftDefId + "] not found.");
}
// force lazy loads
@@ -394,19 +393,19 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
}
/**
- * This purges the persisted data related to drift configuration, but it does NOT
talk to the agent to tell the agent
- * about this nor does it actually delete the drift config itself.
+ * This purges the persisted data related to drift definition, but it does NOT talk
to the agent to tell the agent
+ * about this nor does it actually delete the drift def itself.
*
- * If you want to delete a drift configuration and all that that entails, you must
use
- * {@link #deleteDriftConfiguration(Subject, EntityContext, String)} instead.
+ * If you want to delete a drift definition and all that that entails, you must use
+ * {@link #deleteDriftDefinition(Subject, EntityContext, String)} instead.
*
* This method is really for internal use only.
*/
@Override
@TransactionAttribute(NOT_SUPPORTED)
- public void purgeByDriftConfigurationName(Subject subject, int resourceId, String
driftConfigName) throws Exception {
+ public void purgeByDriftDefinitionName(Subject subject, int resourceId, String
driftDefName) throws Exception {
DriftServerPluginFacet driftServerPlugin = getServerPlugin();
- driftServerPlugin.purgeByDriftConfigurationName(subject, resourceId,
driftConfigName);
+ driftServerPlugin.purgeByDriftDefinitionName(subject, resourceId, driftDefName);
}
@Override
@@ -454,12 +453,12 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
}
@Override
- public void updateDriftConfiguration(Subject subject, EntityContext entityContext,
DriftConfiguration driftConfig) {
+ public void updateDriftDefinition(Subject subject, EntityContext entityContext,
DriftDefinition driftDef) {
- // before we do anything, make sure the drift config name is valid
- if
(!driftConfig.getName().matches(DriftConfigurationDefinition.PROP_NAME_REGEX_PATTERN)) {
+ // before we do anything, make sure the drift def name is valid
+ if
(!driftDef.getName().matches(DriftConfigurationDefinition.PROP_NAME_REGEX_PATTERN)) {
throw new IllegalArgumentException("Drift configuration name contains
invalid characters: "
- + driftConfig.getName());
+ + driftDef.getName());
}
switch (entityContext.getType()) {
@@ -470,28 +469,28 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
throw new IllegalArgumentException("Entity not found [" +
entityContext + "]");
}
- // Update or add the driftConfig as necessary
- DriftConfigurationComparator comparator = new DriftConfigurationComparator(
+ // Update or add the driftDef as necessary
+ DriftDefinitionComparator comparator = new DriftDefinitionComparator(
CompareMode.ONLY_DIRECTORY_SPECIFICATIONS);
boolean isUpdated = false;
- for (DriftConfiguration dc : resource.getDriftConfigurations()) {
- if (dc.getName().equals(driftConfig.getName())) {
+ for (DriftDefinition dc : resource.getDriftDefinitions()) {
+ if (dc.getName().equals(driftDef.getName())) {
// compare the directory specs (basedir/includes-excludes filters
only - if they are different, abort.
- // you cannot update drift config that changes
basedir/includes/excludes from the original.
- // the user must delete the drift config and create a new one, as
opposed to trying to update the existing one.
- if (comparator.compare(driftConfig, dc) == 0) {
- dc.setConfiguration(driftConfig.getConfiguration());
+ // you cannot update drift def that changes basedir/includes/excludes
from the original.
+ // the user must delete the drift def and create a new one, as
opposed to trying to update the existing one.
+ if (comparator.compare(driftDef, dc) == 0) {
+ dc.setConfiguration(driftDef.getConfiguration());
isUpdated = true;
break;
} else {
throw new IllegalArgumentException(
- "You cannot change an existing drift configuration's
base directory or includes/excludes filters.");
+ "You cannot change an existing drift definition's
base directory or includes/excludes filters.");
}
}
}
if (!isUpdated) {
- resource.addDriftConfiguration(driftConfig);
+ resource.addDriftDefinition(driftDef);
}
resource.setAgentSynchronizationNeeded();
resource = entityManager.merge(resource);
@@ -504,9 +503,9 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
AgentClient agentClient =
agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
DriftAgentService service = agentClient.getDriftAgentService();
try {
- service.updateDriftDetection(resourceId, driftConfig);
+ service.updateDriftDetection(resourceId, driftDef);
} catch (Exception e) {
- log.warn(" Unable to inform agent of unscheduled drift detection
[" + driftConfig + "]", e);
+ log.warn(" Unable to inform agent of unscheduled drift detection
[" + driftDef + "]", e);
}
break;
@@ -591,7 +590,7 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
private DriftChangeSet<?> loadPreviousChangeSet(Subject subject, Drift<?,
?> drift) {
GenericDriftChangeSetCriteria criteria = new GenericDriftChangeSetCriteria();
criteria.addFilterResourceId(drift.getChangeSet().getResourceId());
-
criteria.addFilterDriftConfigurationId(drift.getChangeSet().getDriftConfigurationId());
+
criteria.addFilterDriftDefinitionId(drift.getChangeSet().getDriftDefinitionId());
criteria.addFilterVersion(Integer.toString(drift.getChangeSet().getVersion() -
1));
PageList<? extends DriftChangeSet<?>> results =
findDriftChangeSetsByCriteria(subject, criteria);
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
index c11482e..194d0b0 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
@@ -26,9 +26,9 @@ import javax.ejb.Local;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.common.EntityContext;
-import org.rhq.core.domain.criteria.DriftConfigurationCriteria;
+import org.rhq.core.domain.criteria.DriftDefinitionCriteria;
import org.rhq.core.domain.drift.Drift;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftDetails;
import org.rhq.core.domain.drift.FileDiffReport;
import org.rhq.core.domain.util.PageList;
@@ -65,47 +65,47 @@ public interface DriftManagerLocal extends DriftServerPluginFacet,
DriftManagerR
File changeSetFilesZip) throws Exception;
/**
- * Remove the provided driftConfig (identified by name) on the specified
entityContext.
+ * Remove the provided driftDef (identified by name) on the specified entityContext.
* Agents, if available, will be notified of the change.
* @param subject
* @param entityContext
- * @param driftConfigName
+ * @param driftDefName
*/
- void deleteDriftConfiguration(Subject subject, EntityContext entityContext, String
driftConfigName);
+ void deleteDriftDefinition(Subject subject, EntityContext entityContext, String
driftDefName);
/**
* This is for internal use only - do not call it unless you know what you are
doing.
*/
- void deleteResourceDriftConfiguration(Subject subject, int resourceId, int
driftConfigId);
+ void deleteResourceDriftDefinition(Subject subject, int resourceId, int driftDefId);
/**
- * One time on-demand request to detect drift on the specified entities, using the
supplied config.
+ * One time on-demand request to detect drift on the specified entities, using the
supplied def.
*
* @param entityContext
- * @param driftConfig
+ * @param driftDef
* @throws RuntimeException
*/
- void detectDrift(Subject subject, EntityContext context, DriftConfiguration
driftConfig);
+ void detectDrift(Subject subject, EntityContext context, DriftDefinition driftDef);
- PageList<DriftConfiguration> findDriftConfigurationsByCriteria(Subject subject,
DriftConfigurationCriteria criteria);
+ PageList<DriftDefinition> findDriftDefinitionsByCriteria(Subject subject,
DriftDefinitionCriteria criteria);
/**
- * Get the specified drift configuration. Note, the full Configuration is fetched.
+ * Get the specified drift definition. Note, the full Configuration is fetched.
*
- * @param driftConfigId
- * @return The drift configuration
- * @throws RuntimeException, IllegalArgumentException if entity or driftConfig not
found.
+ * @param driftDefId
+ * @return The drift definition
+ * @throws RuntimeException, IllegalArgumentException if entity or driftDef not
found.
*/
- DriftConfiguration getDriftConfiguration(Subject subject, int driftConfigId);
+ DriftDefinition getDriftDefinition(Subject subject, int driftDefId);
/**
- * Update the provided driftConfig (identified by name) on the specified
EntityContext. If it exists it will be replaced. If not it will
+ * Update the provided driftDef (identified by name) on the specified EntityContext.
If it exists it will be replaced. If not it will
* be added. Agents, if available, will be notified of the change.
* @param subject
* @param entityContext
- * @param driftConfig
+ * @param driftDef
*/
- void updateDriftConfiguration(Subject subject, EntityContext entityContext,
DriftConfiguration driftConfig);
+ void updateDriftDefinition(Subject subject, EntityContext entityContext,
DriftDefinition driftDef);
/**
* This will remove all drift files that are no longer referenced by drift entries.
This is a maintenance method
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
index c017ca3..0e57f71 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftServerServiceImpl.java
@@ -19,6 +19,9 @@
*/
package org.rhq.enterprise.server.drift;
+import static org.rhq.enterprise.server.util.LookupUtil.getDriftManager;
+import static org.rhq.enterprise.server.util.LookupUtil.getSubjectManager;
+
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
@@ -29,15 +32,11 @@ import java.util.Set;
import org.rhq.core.clientapi.server.drift.DriftServerService;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.criteria.DriftChangeSetCriteria;
-import org.rhq.core.domain.criteria.DriftConfigurationCriteria;
+import org.rhq.core.domain.criteria.DriftDefinitionCriteria;
import org.rhq.core.domain.criteria.GenericDriftChangeSetCriteria;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftSnapshot;
import org.rhq.core.domain.util.PageList;
-import org.rhq.core.domain.util.PageOrdering;
-
-import static org.rhq.enterprise.server.util.LookupUtil.getDriftManager;
-import static org.rhq.enterprise.server.util.LookupUtil.getSubjectManager;
public class DriftServerServiceImpl implements DriftServerService {
@Override
@@ -51,31 +50,30 @@ public class DriftServerServiceImpl implements DriftServerService {
}
@Override
- public void sendFilesZip(int resourceId, String driftConfigName, String token, long
zipSize,
- InputStream zipStream) {
+ public void sendFilesZip(int resourceId, long zipSize, InputStream zipStream) {
try {
DriftManagerLocal driftManager = getDriftManager();
- driftManager.addFiles(resourceId, driftConfigName, token, zipSize,
zipStream);
+ driftManager.addFiles(resourceId, zipSize, zipStream);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
- public Map<Integer, List<DriftConfiguration>>
getDriftConfigurations(Set<Integer> resourceIds) {
- DriftConfigurationCriteria criteria = new DriftConfigurationCriteria();
+ public Map<Integer, List<DriftDefinition>>
getDriftDefinitions(Set<Integer> resourceIds) {
+ DriftDefinitionCriteria criteria = new DriftDefinitionCriteria();
criteria.addFilterResourceIds(resourceIds.toArray(new
Integer[resourceIds.size()]));
criteria.fetchConfiguration(true);
Subject overlord = getSubjectManager().getOverlord();
- PageList<DriftConfiguration> configs =
getDriftManager().findDriftConfigurationsByCriteria(overlord, criteria);
+ PageList<DriftDefinition> configs =
getDriftManager().findDriftDefinitionsByCriteria(overlord, criteria);
- Map<Integer, List<DriftConfiguration>> map = new HashMap<Integer,
List<DriftConfiguration>>();
+ Map<Integer, List<DriftDefinition>> map = new HashMap<Integer,
List<DriftDefinition>>();
for (Integer resourceId : resourceIds) {
- map.put(resourceId, new ArrayList<DriftConfiguration>());
+ map.put(resourceId, new ArrayList<DriftDefinition>());
}
- for (DriftConfiguration c : configs) {
- List<DriftConfiguration> list = map.get(c.getResource().getId());
+ for (DriftDefinition c : configs) {
+ List<DriftDefinition> list = map.get(c.getResource().getId());
list.add(c);
map.put(c.getResource().getId(), list);
}
@@ -86,8 +84,7 @@ public class DriftServerServiceImpl implements DriftServerService {
@Override
public DriftSnapshot getCurrentSnapshot(int driftConfigurationId) {
DriftChangeSetCriteria criteria = new GenericDriftChangeSetCriteria();
- criteria.addFilterDriftConfigurationId(driftConfigurationId);
- criteria.addSortVersion(PageOrdering.ASC);
+ criteria.addFilterDriftDefinitionId(driftConfigurationId);
Subject overlord = getSubjectManager().getOverlord();
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
index e808b92..575fd74 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerBean.java
@@ -19,6 +19,9 @@
*/
package org.rhq.enterprise.server.drift;
+import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
+import static org.rhq.core.domain.drift.DriftFileStatus.LOADED;
+
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
@@ -55,7 +58,7 @@ import org.rhq.core.domain.criteria.JPADriftCriteria;
import org.rhq.core.domain.drift.DriftChangeSet;
import org.rhq.core.domain.drift.DriftChangeSetCategory;
import org.rhq.core.domain.drift.DriftComposite;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.domain.drift.DriftFileStatus;
import org.rhq.core.domain.drift.DriftSnapshot;
@@ -77,9 +80,6 @@ import org.rhq.enterprise.server.plugin.pc.drift.DriftChangeSetSummary;
import org.rhq.enterprise.server.util.CriteriaQueryGenerator;
import org.rhq.enterprise.server.util.CriteriaQueryRunner;
-import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
-import static org.rhq.core.domain.drift.DriftFileStatus.LOADED;
-
/**
* The SLSB method implementation needed to support the JPA (RHQ Default) Drift Server
Plugin.
*
@@ -114,26 +114,26 @@ public class JPADriftServerBean implements JPADriftServerLocal {
@Override
@TransactionAttribute(REQUIRES_NEW)
- public void purgeByDriftConfigurationName(Subject subject, int resourceId, String
driftConfigName) throws Exception {
+ public void purgeByDriftDefinitionName(Subject subject, int resourceId, String
driftDefName) throws Exception {
int driftsDeleted;
int changeSetsDeleted;
StopWatch timer = new StopWatch();
// purge all drift entities first
- Query q =
entityManager.createNamedQuery(JPADrift.QUERY_DELETE_BY_DRIFTCONFIG_RESOURCE);
+ Query q =
entityManager.createNamedQuery(JPADrift.QUERY_DELETE_BY_DRIFTDEF_RESOURCE);
q.setParameter("resourceId", resourceId);
- q.setParameter("driftConfigurationName", driftConfigName);
+ q.setParameter("driftDefinitionName", driftDefName);
driftsDeleted = q.executeUpdate();
// now purge all changesets
- q =
entityManager.createNamedQuery(JPADriftChangeSet.QUERY_DELETE_BY_DRIFTCONFIG_RESOURCE);
+ q =
entityManager.createNamedQuery(JPADriftChangeSet.QUERY_DELETE_BY_DRIFTDEF_RESOURCE);
q.setParameter("resourceId", resourceId);
- q.setParameter("driftConfigurationName", driftConfigName);
+ q.setParameter("driftDefinitionName", driftDefName);
changeSetsDeleted = q.executeUpdate();
log.info("Purged [" + driftsDeleted + "] drift items and [" +
changeSetsDeleted
- + "] changesets associated with drift config [" + driftConfigName +
"] from resource [" + resourceId
+ + "] changesets associated with drift def [" + driftDefName +
"] from resource [" + resourceId
+ "]. Elapsed time=[" + timer.getElapsed() + "]ms");
return;
}
@@ -176,8 +176,8 @@ public class JPADriftServerBean implements JPADriftServerLocal {
PageList<DriftComposite> result = new PageList<DriftComposite>();
for (JPADrift drift : drifts) {
JPADriftChangeSet changeSet = drift.getChangeSet();
- DriftConfiguration driftConfig = changeSet.getDriftConfiguration();
- result.add(new DriftComposite(drift, changeSet.getResource(),
driftConfig.getName()));
+ DriftDefinition driftDef = changeSet.getDriftDefinition();
+ result.add(new DriftComposite(drift, changeSet.getResource(),
driftDef.getName()));
}
return result;
@@ -247,9 +247,9 @@ public class JPADriftServerBean implements JPADriftServerLocal {
stream)), false);
// store the new change set info (not the actual blob)
- DriftConfiguration config = findDriftConfiguration(resource,
reader.getHeaders());
- if (config == null) {
- log.error("Unable to locate DriftConfiguration for
Resource [" + resource
+ DriftDefinition driftDef = findDriftDefinition(resource,
reader.getHeaders());
+ if (driftDef == null) {
+ log.error("Unable to locate DriftDefinition for Resource
[" + resource
+ "]. Change set cannot be saved.");
return false;
}
@@ -262,13 +262,13 @@ public class JPADriftServerBean implements JPADriftServerLocal {
int version = reader.getHeaders().getVersion();
DriftChangeSetCategory category = reader.getHeaders().getType();
- driftChangeSet = new JPADriftChangeSet(resource, version,
category, config);
+ driftChangeSet = new JPADriftChangeSet(resource, version,
category, driftDef);
entityManager.persist(driftChangeSet);
summary.setCategory(category);
summary.setResourceId(resourceId);
-
summary.setDriftConfigurationName(reader.getHeaders().getDriftConfigurationName());
- summary.setDriftHandlingMode(config.getDriftHandlingMode());
+
summary.setDriftDefinitionName(reader.getHeaders().getDriftDefinitionName());
+ summary.setDriftHandlingMode(driftDef.getDriftHandlingMode());
summary.setCreatedTime(driftChangeSet.getCtime());
for (FileEntry entry : reader) {
@@ -357,29 +357,10 @@ public class JPADriftServerBean implements JPADriftServerLocal {
return result;
}
- /**
- * This method only exists temporarily until the version header is added to the
change
- * set meta data file. This method determines the version by looking at the number
of
- * change sets in the database.
- *
- * @param r The resource
- * @param c The drift configuration
- * @return The next change set version number
- */
- private int getChangeSetVersion(Resource r, DriftConfiguration c) {
- JPADriftChangeSetCriteria criteria = new JPADriftChangeSetCriteria();
- criteria.addFilterResourceId(r.getId());
- criteria.addFilterDriftConfigurationId(c.getId());
- List<? extends DriftChangeSet<?>> changeSets =
findDriftChangeSetsByCriteria(subjectManager.getOverlord(),
- criteria);
-
- return changeSets.size();
- }
-
- private DriftConfiguration findDriftConfiguration(Resource resource, Headers headers)
{
- for (DriftConfiguration driftConfig : resource.getDriftConfigurations()) {
- if (driftConfig.getName().equals(headers.getDriftConfigurationName())) {
- return driftConfig;
+ private DriftDefinition findDriftDefinition(Resource resource, Headers headers) {
+ for (DriftDefinition driftDef : resource.getDriftDefinitions()) {
+ if (driftDef.getName().equals(headers.getDriftDefinitionName())) {
+ return driftDef;
}
}
return null;
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerLocal.java
index 841b45e..534cce5 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/JPADriftServerLocal.java
@@ -115,7 +115,7 @@ public interface JPADriftServerLocal {
* This is for internal use only - do not call it unless you know what you are
doing.
* This purges all drift entities and changeset entities associated with the drift
config.
*/
- void purgeByDriftConfigurationName(Subject subject, int resourceId, String
driftConfigName) throws Exception;
+ void purgeByDriftDefinitionName(Subject subject, int resourceId, String
driftConfigName) throws Exception;
/**
* SUPPORTS JPA DRIFT SERVER PLUGIN
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftChangeSetSummary.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftChangeSetSummary.java
index 045a3dc..7ac2365 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftChangeSetSummary.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftChangeSetSummary.java
@@ -39,7 +39,7 @@ public class DriftChangeSetSummary {
private long createdTime;
private DriftChangeSetCategory category;
private int resourceId;
- private String driftConfigurationName;
+ private String driftDefinitionName;
private DriftHandlingMode driftHandlingMode;
private List<String> driftPathnames;
@@ -51,11 +51,10 @@ public class DriftChangeSetSummary {
public String toString() {
if (category == DriftChangeSetCategory.COVERAGE) {
return "[" + new Date(createdTime) + "] Initial drift coverage
includes ["
- + obtainDriftPathnamesList().size() + "] files using drift
configuration [" + driftConfigurationName
- + "]";
+ + obtainDriftPathnamesList().size() + "] files using drift
definition [" + driftDefinitionName + "]";
} else {
return "[" + new Date(createdTime) + "] Drift detected in
[" + obtainDriftPathnamesList().size()
- + "] files using drift configuration [" +
driftConfigurationName + "]";
+ + "] files using drift definition [" + driftDefinitionName +
"]";
}
}
@@ -83,12 +82,12 @@ public class DriftChangeSetSummary {
this.resourceId = resourceId;
}
- public String getDriftConfigurationName() {
- return driftConfigurationName;
+ public String getDriftDefinitionName() {
+ return driftDefinitionName;
}
- public void setDriftConfigurationName(String driftConfigurationName) {
- this.driftConfigurationName = driftConfigurationName;
+ public void setDriftDefinitionName(String driftDefinitionName) {
+ this.driftDefinitionName = driftDefinitionName;
}
public List<String> getDriftPathnames() {
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftServerPluginFacet.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftServerPluginFacet.java
index cedf437..2167f95 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftServerPluginFacet.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/plugin/pc/drift/DriftServerPluginFacet.java
@@ -86,14 +86,14 @@ public interface DriftServerPluginFacet {
void saveChangeSetFiles(Subject subject, File changeSetFilesZip) throws Exception;
/**
- * When a user wants to completely remove all data related to a drift configuration,
+ * When a user wants to completely remove all data related to a drift definition,
* this method will be called to give the plugin a chance to clean up any data
related
- * to the drift configuration that is going to be deleted.
+ * to the drift definition that is going to be deleted.
* @param Subject
- * @param resourceId the resource whose drift configuration is being purged
- * @param driftConfigName identifies the data that is to be purged
+ * @param resourceId the resource whose drift definition is being purged
+ * @param driftDefName identifies the data that is to be purged
*/
- void purgeByDriftConfigurationName(Subject subject, int resourceId, String
driftConfigName) throws Exception;
+ void purgeByDriftDefinitionName(Subject subject, int resourceId, String driftDefName)
throws Exception;
/**
* This will remove all drift files that are no longer referenced by drift entries.
This is a maintenance method
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
index 6a10c30..0006b33 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/resource/ResourceManagerBean.java
@@ -417,8 +417,8 @@ public class ResourceManagerBean implements ResourceManagerLocal,
ResourceManage
// our unidirectional one-to-many mapping of drift config makes it not possible
to easily bulk delete drift config
// so remove them here and let cascading of delete_orphan do the work
- if (attachedResource.getDriftConfigurations() != null) {
- attachedResource.getDriftConfigurations().clear();
+ if (attachedResource.getDriftDefinitions() != null) {
+ attachedResource.getDriftDefinitions().clear();
}
// one more thing, delete any autogroup backing groups
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 7e9bc1a..6b1c7dd 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
@@ -459,8 +459,8 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
// are different do we have to do anything to the persisted metadata.
//
- Set<ConfigurationTemplate> existingDriftTemplates =
existingType.getDriftConfigurationTemplates();
- Set<ConfigurationTemplate> newDriftTemplates =
resourceType.getDriftConfigurationTemplates();
+ Set<ConfigurationTemplate> existingDriftTemplates =
existingType.getDriftDefinitionTemplates();
+ Set<ConfigurationTemplate> newDriftTemplates =
resourceType.getDriftDefinitionTemplates();
if (existingDriftTemplates.size() != newDriftTemplates.size()) {
isSame = false;
} else {
@@ -508,11 +508,11 @@ public class ResourceMetadataManagerBean implements
ResourceMetadataManagerLocal
for (ConfigurationTemplate doomed : existingDriftTemplates) {
entityManager.remove(doomed);
}
- existingType.getDriftConfigurationTemplates().clear();
+ existingType.getDriftDefinitionTemplates().clear();
for (ConfigurationTemplate toPersist : newDriftTemplates) {
entityManager.persist(toPersist);
- existingType.addDriftConfigurationTemplate(toPersist);
+ existingType.addDriftDefinitionTemplate(toPersist);
}
}
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftManagerBeanTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftManagerBeanTest.java
index ab84ce5..2544540 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftManagerBeanTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/drift/DriftManagerBeanTest.java
@@ -18,6 +18,13 @@
*/
package org.rhq.enterprise.server.drift;
+import static org.apache.commons.io.FileUtils.deleteDirectory;
+import static org.apache.commons.io.FileUtils.toFile;
+import static org.rhq.common.drift.FileEntry.addedFileEntry;
+import static org.rhq.common.drift.FileEntry.changedFileEntry;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
+import static org.rhq.core.domain.drift.DriftChangeSetCategory.DRIFT;
+
import java.io.File;
import java.util.Iterator;
import java.util.List;
@@ -45,11 +52,11 @@ import org.rhq.core.domain.criteria.ResourceCriteria;
import org.rhq.core.domain.drift.Drift;
import org.rhq.core.domain.drift.DriftCategory;
import org.rhq.core.domain.drift.DriftChangeSet;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfiguration.BaseDirectory;
-import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.domain.drift.DriftFileStatus;
+import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
+import org.rhq.core.domain.drift.DriftDefinition.BaseDirectory;
import org.rhq.core.domain.resource.Agent;
import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
@@ -63,13 +70,6 @@ import org.rhq.enterprise.server.test.AbstractEJB3Test;
import org.rhq.enterprise.server.test.TestServerCommunicationsService;
import org.rhq.enterprise.server.util.LookupUtil;
-import static org.apache.commons.io.FileUtils.deleteDirectory;
-import static org.apache.commons.io.FileUtils.toFile;
-import static org.rhq.common.drift.FileEntry.addedFileEntry;
-import static org.rhq.common.drift.FileEntry.changedFileEntry;
-import static org.rhq.core.domain.drift.DriftChangeSetCategory.COVERAGE;
-import static org.rhq.core.domain.drift.DriftChangeSetCategory.DRIFT;
-
/**
* Test for {@link DriftManagerBean} SLSB.
*
@@ -104,7 +104,7 @@ public class DriftManagerBeanTest extends AbstractEJB3Test {
driftServerService = new DriftServerServiceImpl();
TestServerCommunicationsService agentServiceContainer = prepareForTestAgents();
- agentServiceContainer.driftService = new TestConfigService();
+ agentServiceContainer.driftService = new TestDefService();
}
@AfterClass
@@ -141,8 +141,8 @@ public class DriftManagerBeanTest extends AbstractEJB3Test {
Headers headers = new Headers();
headers.setResourceId(newResource.getId());
- headers.setDriftCofigurationId(1);
- headers.setDriftConfigurationName("test-1");
+ headers.setDriftDefinitionId(1);
+ headers.setDriftDefinitionName("test-1");
headers.setBasedir(rootDir.getAbsolutePath());
headers.setType(COVERAGE);
headers.setVersion(0);
@@ -212,100 +212,96 @@ public class DriftManagerBeanTest extends AbstractEJB3Test {
}
@Test(enabled = ENABLE_TESTS)
- public void testDriftConfig() throws Exception {
+ public void testDriftDef() throws Exception {
Configuration config = new Configuration();
- DriftConfiguration driftConfigPojo = new DriftConfiguration(config);
- driftConfigPojo.setName("testDriftConfig");
- driftConfigPojo.setInterval(60L);
- driftConfigPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem,
"foo/bar"));
+ DriftDefinition driftDefPojo = new DriftDefinition(config);
+ driftDefPojo.setName("testDriftDef");
+ driftDefPojo.setInterval(60L);
+ driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem,
"foo/bar"));
- driftManager
- .updateDriftConfiguration(overlord,
EntityContext.forResource(newResource.getId()), driftConfigPojo);
+ driftManager.updateDriftDefinition(overlord,
EntityContext.forResource(newResource.getId()), driftDefPojo);
ResourceManagerLocal resourceManager = LookupUtil.getResourceManager();
ResourceCriteria c = new ResourceCriteria();
c.addFilterId(newResource.getId());
- c.fetchDriftConfigurations(true);
+ c.fetchDriftDefinitions(true);
List<Resource> resources =
resourceManager.findResourcesByCriteria(overlord, c);
assertEquals(1, resources.size());
- Set<DriftConfiguration> driftConfigs =
resources.get(0).getDriftConfigurations();
- assertNotNull(driftConfigs);
- assertEquals(3, driftConfigs.size());
- DriftConfiguration driftConfig = null;
- for (Iterator<DriftConfiguration> i = driftConfigs.iterator();
i.hasNext();) {
- driftConfig = i.next();
- if (driftConfigPojo.getName().equals(driftConfig.getName()))
+ Set<DriftDefinition> driftDefs = resources.get(0).getDriftDefinitions();
+ assertNotNull(driftDefs);
+ assertEquals(3, driftDefs.size());
+ DriftDefinition driftDef = null;
+ for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext();) {
+ driftDef = i.next();
+ if (driftDefPojo.getName().equals(driftDef.getName()))
break;
}
- assertTrue(driftConfig.getConfiguration().getId() > 0); // persisted
- assertEquals(driftConfigPojo.getName(), driftConfig.getName());
- assertEquals(driftConfigPojo.getBasedir(), driftConfig.getBasedir());
- assertEquals(driftConfigPojo.getInterval(), driftConfig.getInterval());
+ assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
+ assertEquals(driftDefPojo.getName(), driftDef.getName());
+ assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
+ assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
- driftConfigPojo.setInterval(120L);
- driftManager
- .updateDriftConfiguration(overlord,
EntityContext.forResource(newResource.getId()), driftConfigPojo);
+ driftDefPojo.setInterval(120L);
+ driftManager.updateDriftDefinition(overlord,
EntityContext.forResource(newResource.getId()), driftDefPojo);
resources = resourceManager.findResourcesByCriteria(overlord, c);
assertEquals(1, resources.size());
- driftConfigs = resources.get(0).getDriftConfigurations();
- assertNotNull(driftConfigs);
- assertEquals(3, driftConfigs.size());
- driftConfig = null;
- for (Iterator<DriftConfiguration> i = driftConfigs.iterator();
i.hasNext();) {
- driftConfig = i.next();
- if (driftConfigPojo.getName().equals(driftConfig.getName()))
+ driftDefs = resources.get(0).getDriftDefinitions();
+ assertNotNull(driftDefs);
+ assertEquals(3, driftDefs.size());
+ driftDef = null;
+ for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext();) {
+ driftDef = i.next();
+ if (driftDefPojo.getName().equals(driftDef.getName()))
break;
}
- assertEquals(driftConfigPojo.getName(), driftConfig.getName());
- assertTrue(driftConfig.getConfiguration().getId() > 0); // persisted
- assertEquals(driftConfigPojo.getBasedir(), driftConfig.getBasedir());
- assertEquals(120L, driftConfig.getInterval());
+ assertEquals(driftDefPojo.getName(), driftDef.getName());
+ assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
+ assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
+ assertEquals(120L, driftDef.getInterval());
- driftConfigPojo.setName("testDriftConfig-2");
- driftConfigPojo.setInterval(30L);
- driftConfigPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem,
"foo/baz"));
+ driftDefPojo.setName("testDriftDef-2");
+ driftDefPojo.setInterval(30L);
+ driftDefPojo.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem,
"foo/baz"));
- driftManager
- .updateDriftConfiguration(overlord,
EntityContext.forResource(newResource.getId()), driftConfigPojo);
+ driftManager.updateDriftDefinition(overlord,
EntityContext.forResource(newResource.getId()), driftDefPojo);
resources = resourceManager.findResourcesByCriteria(overlord, c);
assertEquals(1, resources.size());
- driftConfigs = resources.get(0).getDriftConfigurations();
- assertNotNull(driftConfigs);
- assertEquals(4, driftConfigs.size());
- for (Iterator<DriftConfiguration> i = driftConfigs.iterator();
i.hasNext();) {
- driftConfig = i.next();
- if ("testDriftConfig".equals(driftConfig.getName())) {
- assertTrue(driftConfig.getConfiguration().getId() > 0); // persisted
- assertEquals("foo/bar",
driftConfig.getBasedir().getValueName());
- assertEquals(BaseDirValueContext.fileSystem,
driftConfig.getBasedir().getValueContext());
- assertEquals(120L, driftConfig.getInterval());
- } else if ("testDriftConfig-2".equals(driftConfig.getName())) {
- assertTrue(driftConfig.getConfiguration().getId() > 0); // persisted
- assertEquals(driftConfigPojo.getBasedir(), driftConfig.getBasedir());
- assertEquals(driftConfigPojo.getInterval(), driftConfig.getInterval());
- } else if (!"test-1".equals(driftConfig.getName()) &&
!"test-2".equals(driftConfig.getName())) {
- fail("Unexpected drift config name: " +
driftConfig.getName());
+ driftDefs = resources.get(0).getDriftDefinitions();
+ assertNotNull(driftDefs);
+ assertEquals(4, driftDefs.size());
+ for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext();) {
+ driftDef = i.next();
+ if ("testDriftDef".equals(driftDef.getName())) {
+ assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
+ assertEquals("foo/bar", driftDef.getBasedir().getValueName());
+ assertEquals(BaseDirValueContext.fileSystem,
driftDef.getBasedir().getValueContext());
+ assertEquals(120L, driftDef.getInterval());
+ } else if ("testDriftDef-2".equals(driftDef.getName())) {
+ assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
+ assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
+ assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
+ } else if (!"test-1".equals(driftDef.getName()) &&
!"test-2".equals(driftDef.getName())) {
+ fail("Unexpected drift def name: " + driftDef.getName());
}
}
- driftManager.deleteDriftConfiguration(overlord,
EntityContext.forResource(newResource.getId()),
- "testDriftConfig");
+ driftManager.deleteDriftDefinition(overlord,
EntityContext.forResource(newResource.getId()), "testDriftDef");
resources = resourceManager.findResourcesByCriteria(overlord, c);
assertEquals(1, resources.size());
- driftConfigs = resources.get(0).getDriftConfigurations();
- assertNotNull(driftConfigs);
- assertEquals(3, driftConfigs.size());
- for (Iterator<DriftConfiguration> i = driftConfigs.iterator();
i.hasNext();) {
- driftConfig = i.next();
- if (driftConfigPojo.getName().equals(driftConfig.getName()))
+ driftDefs = resources.get(0).getDriftDefinitions();
+ assertNotNull(driftDefs);
+ assertEquals(3, driftDefs.size());
+ for (Iterator<DriftDefinition> i = driftDefs.iterator(); i.hasNext();) {
+ driftDef = i.next();
+ if (driftDefPojo.getName().equals(driftDef.getName()))
break;
}
- assertTrue(driftConfig.getConfiguration().getId() > 0); // persisted
- assertEquals(driftConfigPojo.getName(), driftConfig.getName());
- assertEquals(driftConfigPojo.getBasedir(), driftConfig.getBasedir());
- assertEquals(driftConfigPojo.getInterval(), driftConfig.getInterval());
+ assertTrue(driftDef.getConfiguration().getId() > 0); // persisted
+ assertEquals(driftDefPojo.getName(), driftDef.getName());
+ assertEquals(driftDefPojo.getBasedir(), driftDef.getBasedir());
+ assertEquals(driftDefPojo.getInterval(), driftDef.getInterval());
}
private void deleteDriftFiles() throws Exception {
@@ -349,18 +345,18 @@ public class DriftManagerBeanTest extends AbstractEJB3Test {
em.persist(agent);
em.flush();
- DriftConfiguration test1Config = new DriftConfiguration(new
Configuration());
- test1Config.setName("test-1");
+ DriftDefinition test1Def = new DriftDefinition(new Configuration());
+ test1Def.setName("test-1");
- DriftConfiguration test2Config = new DriftConfiguration(new
Configuration());
- test2Config.setName("test-2");
+ DriftDefinition test2Def = new DriftDefinition(new Configuration());
+ test2Def.setName("test-2");
resource = new Resource("reskey" + System.currentTimeMillis(),
"resname", resourceType);
resource.setUuid("" + new Random().nextInt());
resource.setAgent(agent);
resource.setInventoryStatus(InventoryStatus.COMMITTED);
- resource.addDriftConfiguration(test1Config);
- resource.addDriftConfiguration(test2Config);
+ resource.addDriftDefinition(test1Def);
+ resource.addDriftDefinition(test2Def);
em.persist(resource);
} catch (Exception e) {
@@ -424,7 +420,7 @@ public class DriftManagerBeanTest extends AbstractEJB3Test {
return digestGenerator.calcDigestString(s);
}
- private class TestConfigService implements DriftAgentService {
+ private class TestDefService implements DriftAgentService {
@Override
public boolean requestDriftFiles(int resourceId, Headers headers, List<?
extends DriftFile> driftFiles) {
@@ -432,20 +428,20 @@ public class DriftManagerBeanTest extends AbstractEJB3Test {
}
@Override
- public void scheduleDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
+ public void scheduleDriftDetection(int resourceId, DriftDefinition
DriftDefinition) {
}
@Override
- public void detectDrift(int resourceId, DriftConfiguration driftConfiguration) {
+ public void detectDrift(int resourceId, DriftDefinition DriftDefinition) {
}
@Override
- public void unscheduleDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
+ public void unscheduleDriftDetection(int resourceId, DriftDefinition
DriftDefinition) {
}
@Override
- public void updateDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
+ public void updateDriftDetection(int resourceId, DriftDefinition DriftDefinition)
{
}
@Override
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/inventory/UninventoryTest.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/inventory/UninventoryTest.java
index 403fc25..02696b8 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/inventory/UninventoryTest.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/inventory/UninventoryTest.java
@@ -30,9 +30,9 @@ import org.testng.annotations.Test;
import org.rhq.core.domain.auth.Subject;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
-import org.rhq.core.domain.drift.DriftConfiguration;
-import org.rhq.core.domain.drift.DriftConfiguration.BaseDirectory;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
+import org.rhq.core.domain.drift.DriftDefinition.BaseDirectory;
import org.rhq.core.domain.resource.Agent;
import org.rhq.core.domain.resource.InventoryStatus;
import org.rhq.core.domain.resource.Resource;
@@ -57,45 +57,45 @@ public class UninventoryTest extends AbstractEJB3Test {
}
}
- public void testDriftConfigRemoval() throws Exception {
+ public void testDriftDefRemoval() throws Exception {
ResourceTypeCreator rtCreator = new ResourceTypeCreator() {
public void modifyResourceTypeToPersist(ResourceType resourceType,
EntityManager em) {
- ConfigurationTemplate template = new
ConfigurationTemplate("drift1", "drift config template");
+ ConfigurationTemplate template = new
ConfigurationTemplate("drift1", "drift def template");
Configuration config = new Configuration();
- DriftConfiguration driftConfig = new DriftConfiguration(config);
- driftConfig.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem,
"/"));
- driftConfig.setName("drift1");
- template.setConfiguration(driftConfig.getConfiguration());
- resourceType.addDriftConfigurationTemplate(template);
+ DriftDefinition driftDef = new DriftDefinition(config);
+ driftDef.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem,
"/"));
+ driftDef.setName("drift1");
+ template.setConfiguration(driftDef.getConfiguration());
+ resourceType.addDriftDefinitionTemplate(template);
}
};
ResourceCreator rCreator = new ResourceCreator() {
public void modifyResourceToPersist(Resource resource, EntityManager em) {
Configuration config = new Configuration();
- DriftConfiguration driftConfig = new DriftConfiguration(config);
- driftConfig.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem,
"/boo"));
- driftConfig.setName("drift-config-name");
- resource.addDriftConfiguration(driftConfig);
+ DriftDefinition driftDef = new DriftDefinition(config);
+ driftDef.setBasedir(new BaseDirectory(BaseDirValueContext.fileSystem,
"/boo"));
+ driftDef.setName("drift-def-name");
+ resource.addDriftDefinition(driftDef);
}
};
Resource resource = createNewResource(rtCreator, rCreator);
- int templateId =
resource.getResourceType().getDriftConfigurationTemplates().iterator().next().getId();
- int driftConfigId = resource.getDriftConfigurations().iterator().next().getId();
+ int templateId =
resource.getResourceType().getDriftDefinitionTemplates().iterator().next().getId();
+ int driftDefId = resource.getDriftDefinitions().iterator().next().getId();
// sanity check, make sure things are in the DB now
Query qTemplate;
- Query qConfig;
+ Query qDef;
String qTemplateString = "select ct from ConfigurationTemplate ct where
ct.id = :id";
- String qConfigString = "select dc from DriftConfiguration dc where dc.id =
:id";
+ String qDefString = "select dc from DriftDefinition dc where dc.id =
:id";
getTransactionManager().begin();
try {
qTemplate =
getEntityManager().createQuery(qTemplateString).setParameter("id", templateId);
- qConfig =
getEntityManager().createQuery(qConfigString).setParameter("id",
driftConfigId);
+ qDef =
getEntityManager().createQuery(qDefString).setParameter("id", driftDefId);
assertEquals("drift template didn't get added", 1,
qTemplate.getResultList().size());
- assertEquals("drift template config didn't get added", 1,
qConfig.getResultList().size());
+ assertEquals("drift template def didn't get added", 1,
qDef.getResultList().size());
} finally {
getTransactionManager().commit();
}
@@ -107,9 +107,9 @@ public class UninventoryTest extends AbstractEJB3Test {
getTransactionManager().begin();
try {
qTemplate =
getEntityManager().createQuery(qTemplateString).setParameter("id", templateId);
- qConfig =
getEntityManager().createQuery(qConfigString).setParameter("id",
driftConfigId);
+ qDef =
getEntityManager().createQuery(qDefString).setParameter("id", driftDefId);
assertEquals("drift template didn't get purged", 0,
qTemplate.getResultList().size());
- assertEquals("drift template config didn't get purged", 0,
qConfig.getResultList().size());
+ assertEquals("drift template def didn't get purged", 0,
qDef.getResultList().size());
} finally {
getTransactionManager().commit();
}
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 ca9ee2a..7f895b9 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
@@ -30,7 +30,7 @@ import org.rhq.core.domain.content.PackageType;
import org.rhq.core.domain.criteria.OperationDefinitionCriteria;
import org.rhq.core.domain.criteria.ResourceCriteria;
import org.rhq.core.domain.criteria.ResourceTypeCriteria;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftConfigurationDefinition;
import org.rhq.core.domain.drift.Filter;
import org.rhq.core.domain.drift.DriftConfigurationDefinition.BaseDirValueContext;
@@ -66,7 +66,7 @@ public class ResourceMetadataManagerBeanTest extends MetadataBeanTest {
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();
+ ConfigurationTemplate driftTemplate =
type1.getDriftDefinitionTemplates().iterator().next();
Configuration bundleConfig =
type1.getResourceTypeBundleConfiguration().getBundleConfiguration();
Configuration driftConfig = driftTemplate.getConfiguration();
@@ -163,11 +163,11 @@ public class ResourceMetadataManagerBeanTest extends
MetadataBeanTest {
ResourceType type = assertResourceTypeAssociationEquals("ServerA",
"TestPlugin", "driftConfigurationTemplates",
asList("drift-pc", "drift-fs"));
- DriftConfiguration driftConfig = null;
- Set<ConfigurationTemplate> drifts = type.getDriftConfigurationTemplates();
+ DriftDefinition driftConfig = null;
+ Set<ConfigurationTemplate> drifts = type.getDriftDefinitionTemplates();
for (ConfigurationTemplate drift : drifts) {
if (drift.getName().equals("drift-pc")) {
- driftConfig = new DriftConfiguration(drift.getConfiguration());
+ driftConfig = new DriftDefinition(drift.getConfiguration());
assertTrue(driftConfig.isEnabled());
assertEquals(BaseDirValueContext.pluginConfiguration,
driftConfig.getBasedir().getValueContext());
assertEquals("connectionPropertyX",
driftConfig.getBasedir().getValueName());
@@ -184,7 +184,7 @@ public class ResourceMetadataManagerBeanTest extends MetadataBeanTest
{
assertEquals("/hello", filter.getPath());
assertEquals("", filter.getPattern());
} else if (drift.getName().equals("drift-fs")) {
- driftConfig = new DriftConfiguration(drift.getConfiguration());
+ driftConfig = new DriftDefinition(drift.getConfiguration());
assertTrue(driftConfig.isEnabled());
assertEquals(BaseDirValueContext.fileSystem,
driftConfig.getBasedir().getValueContext());
assertEquals("/", driftConfig.getBasedir().getValueName());
@@ -285,11 +285,11 @@ public class ResourceMetadataManagerBeanTest extends
MetadataBeanTest {
ResourceType type = assertResourceTypeAssociationEquals("ServerA",
"TestPlugin", "driftConfigurationTemplates",
asList("drift-rc", "drift-mt"));
- DriftConfiguration driftConfig = null;
- Set<ConfigurationTemplate> drifts = type.getDriftConfigurationTemplates();
+ DriftDefinition driftConfig = null;
+ Set<ConfigurationTemplate> drifts = type.getDriftDefinitionTemplates();
for (ConfigurationTemplate drift : drifts) {
if (drift.getName().equals("drift-rc")) {
- driftConfig = new DriftConfiguration(drift.getConfiguration());
+ driftConfig = new DriftDefinition(drift.getConfiguration());
assertTrue(driftConfig.isEnabled());
assertEquals(BaseDirValueContext.resourceConfiguration,
driftConfig.getBasedir().getValueContext());
assertEquals("resourceConfig1",
driftConfig.getBasedir().getValueName());
@@ -297,7 +297,7 @@ public class ResourceMetadataManagerBeanTest extends MetadataBeanTest
{
assertEquals(0, driftConfig.getIncludes().size());
assertEquals(0, driftConfig.getExcludes().size());
} else if (drift.getName().equals("drift-mt")) {
- driftConfig = new DriftConfiguration(drift.getConfiguration());
+ driftConfig = new DriftDefinition(drift.getConfiguration());
assertTrue(driftConfig.isEnabled());
assertEquals(BaseDirValueContext.measurementTrait,
driftConfig.getBasedir().getValueContext());
assertEquals("trait1",
driftConfig.getBasedir().getValueName());
diff --git
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/TestAgentClient.java
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/TestAgentClient.java
index 43d0ded..1515869 100644
---
a/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/TestAgentClient.java
+++
b/modules/enterprise/server/jar/src/test/java/org/rhq/enterprise/server/test/TestAgentClient.java
@@ -58,7 +58,7 @@ import org.rhq.core.domain.content.transfer.ResourcePackageDetails;
import org.rhq.core.domain.discovery.AvailabilityReport;
import org.rhq.core.domain.discovery.MergeResourceResponse;
import org.rhq.core.domain.discovery.ResourceSyncInfo;
-import org.rhq.core.domain.drift.DriftConfiguration;
+import org.rhq.core.domain.drift.DriftDefinition;
import org.rhq.core.domain.drift.DriftFile;
import org.rhq.core.domain.measurement.Availability;
import org.rhq.core.domain.measurement.MeasurementData;
@@ -336,19 +336,19 @@ public class TestAgentClient implements AgentClient,
BundleAgentService, DriftAg
}
@Override
- public void scheduleDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
+ public void scheduleDriftDetection(int resourceId, DriftDefinition
driftConfiguration) {
}
@Override
- public void detectDrift(int resourceId, DriftConfiguration driftConfiguration) {
+ public void detectDrift(int resourceId, DriftDefinition driftConfiguration) {
}
@Override
- public void unscheduleDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
+ public void unscheduleDriftDetection(int resourceId, DriftDefinition
driftConfiguration) {
}
@Override
- public void updateDriftDetection(int resourceId, DriftConfiguration
driftConfiguration) {
+ public void updateDriftDetection(int resourceId, DriftDefinition driftConfiguration)
{
}
@Override
diff --git
a/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/MongoDBDriftServer.java
b/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/MongoDBDriftServer.java
index ceeacfd..1c78182 100644
---
a/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/MongoDBDriftServer.java
+++
b/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/MongoDBDriftServer.java
@@ -127,13 +127,13 @@ public class MongoDBDriftServer implements DriftServerPluginFacet,
ServerPluginC
MongoDBChangeSet changeSet = new MongoDBChangeSet();
changeSet.setCategory(headers.getType());
changeSet.setResourceId(resourceId);
- changeSet.setDriftConfigurationId(headers.getDriftCofigurationId());
+ changeSet.setDriftDefinitionId(headers.getDriftDefinitionId());
changeSet.setDriftHandlingMode(DriftHandlingMode.normal);
changeSet.setVersion(headers.getVersion());
summary.setCategory(headers.getType());
summary.setResourceId(resourceId);
- summary.setDriftConfigurationName(headers.getDriftConfigurationName());
+ summary.setDriftDefinitionName(headers.getDriftDefinitionName());
summary.setCreatedTime(changeSet.getCtime());
for (FileEntry fileEntry : reader) {
@@ -294,7 +294,7 @@ public class MongoDBDriftServer implements DriftServerPluginFacet,
ServerPluginC
}
@Override
- public void purgeByDriftConfigurationName(Subject subject, int resourceId, String
driftConfigName) throws Exception {
+ public void purgeByDriftDefinitionName(Subject subject, int resourceId, String
driftDefName) throws Exception {
// TODO implement me!
}
@@ -328,7 +328,7 @@ public class MongoDBDriftServer implements DriftServerPluginFacet,
ServerPluginC
DriftChangeSetDTO dto = new DriftChangeSetDTO();
dto.setId(changeSet.getId());
// TODO copy resource id
- dto.setDriftConfigurationId(changeSet.getDriftConfigurationId());
+ dto.setDriftDefinitionId(changeSet.getDriftDefinitionId());
dto.setVersion(changeSet.getVersion());
dto.setCtime(changeSet.getCtime());
dto.setCategory(changeSet.getCategory());
diff --git
a/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSet.java
b/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSet.java
index 0bdd2fd..d13466b 100644
---
a/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSet.java
+++
b/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSet.java
@@ -114,12 +114,12 @@ public class MongoDBChangeSet implements
DriftChangeSet<MongoDBChangeSetEntry>,
}
@Override
- public int getDriftConfigurationId() {
+ public int getDriftDefinitionId() {
return configId;
}
@Override
- public void setDriftConfigurationId(int id) {
+ public void setDriftDefinitionId(int id) {
configId = id;
}
diff --git
a/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSetEntry.java
b/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSetEntry.java
index e236266..df8cad2 100644
---
a/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSetEntry.java
+++
b/modules/enterprise/server/plugins/drift-mongodb/src/main/java/org/rhq/enterprise/server/plugins/drift/mongodb/entities/MongoDBChangeSetEntry.java
@@ -35,7 +35,7 @@ public class MongoDBChangeSetEntry implements Drift<MongoDBChangeSet,
MongoDBFil
/**
* This is the path relative to the base directory defined in the
- * {@link org.rhq.core.domain.drift.DriftConfiguration}
+ * {@link org.rhq.core.domain.drift.DriftDefinition}
*/
private String path;
diff --git
a/modules/enterprise/server/plugins/drift-mongodb/src/test/java/org/rhq/enterprise/server/plugins/drift/mongodb/dao/ChangeSetDAOTest.java
b/modules/enterprise/server/plugins/drift-mongodb/src/test/java/org/rhq/enterprise/server/plugins/drift/mongodb/dao/ChangeSetDAOTest.java
index 1c3c3c7..6abaaac 100644
---
a/modules/enterprise/server/plugins/drift-mongodb/src/test/java/org/rhq/enterprise/server/plugins/drift/mongodb/dao/ChangeSetDAOTest.java
+++
b/modules/enterprise/server/plugins/drift-mongodb/src/test/java/org/rhq/enterprise/server/plugins/drift/mongodb/dao/ChangeSetDAOTest.java
@@ -90,7 +90,7 @@ public class ChangeSetDAOTest {
MongoDBChangeSet expected = new MongoDBChangeSet();
expected.setCategory(COVERAGE);
expected.setVersion(1);
- expected.setDriftConfigurationId(1);
+ expected.setDriftDefinitionId(1);
expected.setResourceId(1);
expected.setDriftHandlingMode(normal);
@@ -105,7 +105,7 @@ public class ChangeSetDAOTest {
MongoDBChangeSet expected = new MongoDBChangeSet();
expected.setCategory(DRIFT);
expected.setResourceId(1);
- expected.setDriftConfigurationId(1);
+ expected.setDriftDefinitionId(1);
expected.setVersion(1);
MongoDBChangeSetEntry entry = new MongoDBChangeSetEntry();
@@ -137,7 +137,7 @@ public class ChangeSetDAOTest {
expected.setCategory(DRIFT);
expected.setVersion(1);
expected.setResourceId(1);
- expected.setDriftConfigurationId(1);
+ expected.setDriftDefinitionId(1);
expected.add(new MongoDBChangeSetEntry("foo", FILE_ADDED)).add(new
MongoDBChangeSetEntry("bar", FILE_ADDED));
dao.save(expected);
@@ -153,14 +153,14 @@ public class ChangeSetDAOTest {
c1.setCategory(DRIFT);
c1.setVersion(1);
c1.setResourceId(1);
- c1.setDriftConfigurationId(1);
+ c1.setDriftDefinitionId(1);
dao.save(c1);
MongoDBChangeSet c2 = new MongoDBChangeSet();
c2.setCategory(DRIFT);
c2.setVersion(1);
c2.setResourceId(2);
- c2.setDriftConfigurationId(2);
+ c2.setDriftDefinitionId(2);
GenericDriftCriteria criteria = new GenericDriftCriteria();
criteria.addFilterResourceIds(1);
@@ -427,7 +427,7 @@ public class ChangeSetDAOTest {
changeSet.setCategory(category);
changeSet.setVersion(version);
changeSet.setResourceId(resourceId);
- changeSet.setDriftConfigurationId(driftConfigId);
+ changeSet.setDriftDefinitionId(driftConfigId);
return changeSet;
}
diff --git
a/modules/enterprise/server/plugins/drift-rhq/src/main/java/org/rhq/enterprise/server/plugins/drift/JPADriftServerPluginComponent.java
b/modules/enterprise/server/plugins/drift-rhq/src/main/java/org/rhq/enterprise/server/plugins/drift/JPADriftServerPluginComponent.java
index ee542d0..ef962b2 100644
---
a/modules/enterprise/server/plugins/drift-rhq/src/main/java/org/rhq/enterprise/server/plugins/drift/JPADriftServerPluginComponent.java
+++
b/modules/enterprise/server/plugins/drift-rhq/src/main/java/org/rhq/enterprise/server/plugins/drift/JPADriftServerPluginComponent.java
@@ -115,8 +115,8 @@ public class JPADriftServerPluginComponent implements
DriftServerPluginFacet, Se
}
@Override
- public void purgeByDriftConfigurationName(Subject subject, int resourceId, String
driftConfigName) throws Exception {
- getJPADriftServer().purgeByDriftConfigurationName(subject, resourceId,
driftConfigName);
+ public void purgeByDriftDefinitionName(Subject subject, int resourceId, String
driftDefName) throws Exception {
+ getJPADriftServer().purgeByDriftDefinitionName(subject, resourceId,
driftDefName);
}
@Override