}
}
resource.setAgentSynchronizationNeeded();
AgentClient agentClient = agentManager.getAgentClient(subjectManager.getOverlord(), resourceId);
DriftAgentService service = agentClient.getDriftAgentService();
try {
DriftSnapshot snapshot = null;
if (driftDef.getTemplate() != null && driftDef.getTemplate().isPinned()) {
snapshot = getSnapshot(subject, new DriftSnapshotRequest(driftDef.getId()));
}
// Do not pass attached entities to the following Agent call, which is outside Hibernate's control. Flush
// and clear the entities to ensure the work above is captured and we pass out a detached object.
entityManager.flush();
entityManager.clear();
if (snapshot != null) {
service.updateDriftDetection(resourceId, driftDef, snapshot);
} else {
service.updateDriftDetection(resourceId, driftDef);
}
} catch (Exception e) {
log.warn(" Unable to inform agent of unscheduled drift detection [" + driftDef + "]", e);
}