}
String installPath = destroyedTemplateHostVO.getInstallPath();
if (installPath != null) {
Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, new DeleteTemplateCommand(secondaryStorageHost.getStorageUrl(), destroyedTemplateHostVO.getInstallPath()));
if (answer == null || !answer.getResult()) {
s_logger.debug("Failed to delete " + destroyedTemplateHostVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails()));
} else {
_vmTemplateHostDao.remove(destroyedTemplateHostVO.getId());
s_logger.debug("Deleted template at: " + destroyedTemplateHostVO.getInstallPath());
}
} else {
_vmTemplateHostDao.remove(destroyedTemplateHostVO.getId());
}
}
} catch (Exception e) {
s_logger.warn("problem cleaning up templates in secondary storage " + secondaryStorageHost, e);
}
}
// Cleanup snapshot in secondary storage hosts
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
try {
long hostId = secondaryStorageHost.getId();
List<Long> vIDs = findAllVolumeIdInSnapshotTable(hostId);
if (vIDs == null) {
continue;
}
for (Long volumeId : vIDs) {
boolean lock = false;
try {
VolumeVO volume = _volsDao.findByIdIncludingRemoved(volumeId);
if (volume.getRemoved() == null) {
volume = _volsDao.acquireInLockTable(volumeId, 10);
if (volume == null) {
continue;
}
lock = true;
}
List<String> snapshots = findAllSnapshotForVolume(volumeId);
if (snapshots == null) {
continue;
}
CleanupSnapshotBackupCommand cmd = new CleanupSnapshotBackupCommand(secondaryStorageHost.getStorageUrl(), secondaryStorageHost.getDataCenterId(), volume.getAccountId(),
volumeId, snapshots);
Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, cmd);
if ((answer == null) || !answer.getResult()) {
String details = "Failed to cleanup snapshots for volume " + volumeId + " due to " + (answer == null ? "null" : answer.getDetails());
s_logger.warn(details);
}
} catch (Exception e1) {
s_logger.warn("problem cleaning up snapshots in secondary storage " + secondaryStorageHost, e1);
} finally {
if (lock) {
_volsDao.releaseFromLockTable(volumeId);
}
}
}
} catch (Exception e2) {
s_logger.warn("problem cleaning up snapshots in secondary storage " + secondaryStorageHost, e2);
}
}
//CleanUp volumes on Secondary Storage.
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
try {
long hostId = secondaryStorageHost.getId();
List<VolumeHostVO> destroyedVolumeHostVOs = _volumeHostDao.listDestroyed(hostId);
s_logger.debug("Secondary storage garbage collector found " + destroyedVolumeHostVOs.size() + " templates to cleanup on secondary storage host: "
+ secondaryStorageHost.getName());
for (VolumeHostVO destroyedVolumeHostVO : destroyedVolumeHostVOs) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deleting volume host: " + destroyedVolumeHostVO);
}
String installPath = destroyedVolumeHostVO.getInstallPath();
if (installPath != null) {
Answer answer = _agentMgr.sendToSecStorage(secondaryStorageHost, new DeleteVolumeCommand(secondaryStorageHost.getStorageUrl(), destroyedVolumeHostVO.getInstallPath()));
if (answer == null || !answer.getResult()) {
s_logger.debug("Failed to delete " + destroyedVolumeHostVO + " due to " + ((answer == null) ? "answer is null" : answer.getDetails()));
} else {
_volumeHostDao.remove(destroyedVolumeHostVO.getId());
s_logger.debug("Deleted volume at: " + destroyedVolumeHostVO.getInstallPath());
}
} else {