if (!changeSetMgr.changeSetExists(resource.getId(), headers)) {
log.info("No snapshot found for " + toString(resource.getId(), driftDefinition)
+ ". Downloading snapshot from server");
DriftServerService driftServer = pluginContainerConfiguration.getServerServices().getDriftServerService();
DriftSnapshot snapshot = driftServer.getCurrentSnapshot(driftDefinition.getId());
if (snapshot.getVersion() == -1) {
// A version of -1 indicates that no change sets have been reported
// 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.getId(), 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.getId(), driftDefinition));
File currentSnapshotFile = changeSetMgr
.findChangeSet(resource.getId(), driftDefinition.getName(), COVERAGE);
writeSnapshotToFile(snapshot, currentSnapshotFile, headers);
if (driftDefinition.isPinned()) {
log.debug(driftDefinition + " is pinned. Fetching pinned snapshot...");
// The pinned snapshot is always the initial change set and only the initial
// change set.
DriftSnapshot pinnedSnapshot = driftServer.getSnapshot(driftDefinition.getId(), 0, 0);
Headers pinnedHeaders = createHeaders(resource.getId(), driftDefinition);
File pinnedSnapshotFile = new File(currentSnapshotFile.getParent(), DriftDetector.FILE_SNAPSHOT_PINNED);
log.info("Preparing to write pinned snapshot to disk for "
+ toString(resource.getId(), driftDefinition));
writeSnapshotToFile(pinnedSnapshot, pinnedSnapshotFile, pinnedHeaders);
if (snapshot.getVersion() > 0) {
// Drift was previously reported. We will fetch a snapshot of the
// latest change set and write that to disk so that we avoid reporting
// drift that has already been reported to the server.
DriftSnapshot deltaSnapshot = driftServer.getSnapshot(driftDefinition.getId(),
snapshot.getVersion(), snapshot.getVersion());
File deltaFile = new File(currentSnapshotFile.getParentFile(), DriftDetector.FILE_CHANGESET_DELTA);
Headers deltaHeaders = createHeaders(resource.getId(), driftDefinition);
deltaHeaders.setVersion(snapshot.getVersion());
deltaHeaders.setType(DRIFT);