use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class GlusterSnapshotSyncJob method addOrUpdateSnapshots.
private void addOrUpdateSnapshots(Guid clusterId, List<GlusterVolumeSnapshotEntity> fetchedSnapshots) {
Map<Guid, GlusterVolumeSnapshotEntity> fetchedSnapshotsMap = new HashMap<>();
for (GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) {
fetchedSnapshotsMap.put(fetchedSnapshot.getId(), fetchedSnapshot);
}
Cluster cluster = clusterDao.get(clusterId);
List<GlusterVolumeSnapshotEntity> existingSnapshots = volumeSnapshotDao.getAllByClusterId(clusterId);
Map<Guid, GlusterVolumeSnapshotEntity> existingSnapshotsMap = new HashMap<>();
for (GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) {
existingSnapshotsMap.put(existingSnapshot.getId(), existingSnapshot);
}
List<GlusterVolumeSnapshotEntity> updatedSnapshots = new ArrayList<>();
List<GlusterVolumeSnapshotEntity> newlyAddedSnapshots = new ArrayList<>();
List<GlusterVolumeSnapshotEntity> deletedSnapshots = new ArrayList<>();
for (final GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) {
GlusterVolumeSnapshotEntity correspondingExistingSnapshot = existingSnapshotsMap.get(fetchedSnapshot.getId());
if (correspondingExistingSnapshot == null) {
final GlusterVolumeEntity volume = volumeDao.getById(fetchedSnapshot.getVolumeId());
newlyAddedSnapshots.add(fetchedSnapshot);
log.debug("Detected new gluster volume snapshot '{}' for volume '{}' on cluster: '{}'", fetchedSnapshot.getSnapshotName(), volume.getName(), cluster.getName());
Map<String, String> customValues = new HashMap<>();
customValues.put("snapName", fetchedSnapshot.getSnapshotName());
customValues.put(GlusterConstants.VOLUME_NAME, volume.getName());
logUtil.logAuditMessage(clusterId, volume.getClusterName(), volume, null, AuditLogType.GLUSTER_VOLUME_SNAPSHOT_DETECTED_NEW, customValues);
} else if (correspondingExistingSnapshot.getStatus() != fetchedSnapshot.getStatus()) {
correspondingExistingSnapshot.setStatus(fetchedSnapshot.getStatus());
updatedSnapshots.add(correspondingExistingSnapshot);
}
}
for (final GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) {
GlusterVolumeSnapshotEntity correspondingFetchedSnapshot = fetchedSnapshotsMap.get(existingSnapshot.getId());
if (correspondingFetchedSnapshot == null) {
final GlusterVolumeEntity volume = volumeDao.getById(existingSnapshot.getVolumeId());
deletedSnapshots.add(existingSnapshot);
log.debug("Gluster volume snapshot '{}' detected removed for volume '{}' on cluster: '{}'", existingSnapshot.getSnapshotName(), volume.getName(), cluster.getName());
Map<String, String> customValues = new HashMap<>();
customValues.put("snapName", existingSnapshot.getSnapshotName());
customValues.put(GlusterConstants.VOLUME_NAME, volume.getName());
logUtil.logAuditMessage(clusterId, volume.getClusterName(), volume, null, AuditLogType.GLUSTER_VOLUME_SNAPSHOT_DELETED_FROM_CLI, customValues);
}
}
// update snapshot details
try (EngineLock lock = acquireVolumeSnapshotLock(clusterId)) {
saveNewSnapshots(newlyAddedSnapshots);
updateSnapshots(updatedSnapshots);
deleteSnapshots(deletedSnapshots);
} catch (Exception e) {
log.error("Exception ocuured while adding/updating snapshots from CLI - '{}'", e.getMessage());
log.debug("Exception", e);
throw new EngineException(EngineError.GlusterSnapshotInfoFailedException, e.getLocalizedMessage());
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class GlusterTasksSyncJob method updateGlusterAsyncTasks.
@OnTimerMethodAnnotation("gluster_async_task_poll_event")
public void updateGlusterAsyncTasks() {
log.debug("Refreshing gluster tasks list");
List<Cluster> clusters = clusterDao.getAll();
Map<Guid, Set<Guid>> tasksFromClustersMap = new HashMap<>();
for (Cluster cluster : clusters) {
if (!cluster.supportsGlusterService()) {
continue;
}
try {
Map<Guid, GlusterAsyncTask> runningTasks = provider.getTaskListForCluster(cluster.getId());
if (runningTasks != null) {
updateTasksInCluster(cluster, runningTasks);
tasksFromClustersMap.put(cluster.getId(), runningTasks.keySet());
}
} catch (EngineException e) {
log.error("Error updating tasks from CLI", e);
}
}
cleanUpOrphanTasks(tasksFromClustersMap);
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class GlusterTasksService method getTaskListForCluster.
public Map<Guid, GlusterAsyncTask> getTaskListForCluster(Guid id) {
VDS upServer = glusterUtil.getRandomUpServer(id);
if (upServer == null) {
log.info("No up server in cluster");
return null;
}
VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GlusterTasksList, new VdsIdVDSCommandParametersBase(upServer.getId()));
if (returnValue.getSucceeded()) {
List<GlusterAsyncTask> tasks = (List<GlusterAsyncTask>) returnValue.getReturnValue();
Map<Guid, GlusterAsyncTask> tasksMap = new HashMap<>();
for (GlusterAsyncTask task : tasks) {
tasksMap.put(task.getTaskId(), task);
}
return tasksMap;
} else {
log.error("Error: {}", returnValue.getVdsError());
throw new EngineException(EngineError.GlusterVolumeStatusAllFailedException, returnValue.getVdsError().getMessage());
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class ImagesHandler method addDiskImage.
/**
* Adds a disk image (Adds image, disk and relevant entities)
*
* @param image
* DiskImage to add
* @param active
* true if the image should be added as active
* @param imageStorageDomainMap
* storage domain map entry to map between the image and its storage domain
*/
public void addDiskImage(DiskImage image, boolean active, ImageStorageDomainMap imageStorageDomainMap, Guid vmId) {
try {
addImage(image, active, imageStorageDomainMap);
addDiskToVmIfNotExists(image, vmId);
} catch (RuntimeException ex) {
log.error("Failed adding new disk image and related entities to db: {}", ex.getMessage());
log.debug("Exception", ex);
throw new EngineException(EngineError.DB, ex);
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class RegisterDiskCommand method fetchQcowCompat.
private void fetchQcowCompat() {
if (getDiskImage().getDiskStorageType() == DiskStorageType.IMAGE && getDiskImage().getVolumeFormat().equals(VolumeFormat.COW)) {
DiskImage newDiskImage = getDiskImage();
try {
setQcowCompat(newDiskImage.getImage(), newDiskImage.getStoragePoolId(), newDiskImage.getId(), newDiskImage.getImageId(), getParameters().getStorageDomainId(), null);
// TODO: We should update the insert to also set qcow compat.
imageDao.update(newDiskImage.getImage());
} catch (EngineException e) {
// Logging only
log.error("Unable to update the image info for image '{}' (image group: '{}') on domain '{}'", newDiskImage.getImageId(), newDiskImage.getId(), getParameters().getStorageDomainId());
}
}
}
Aggregations