use of org.ovirt.engine.core.common.businessentities.Cluster 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.businessentities.Cluster in project ovirt-engine by oVirt.
the class GlusterSyncJob method removeDeletedVolumes.
private void removeDeletedVolumes(Guid clusterId, Map<Guid, GlusterVolumeEntity> volumesMap) {
List<Guid> idsToRemove = new ArrayList<>();
for (GlusterVolumeEntity volume : volumeDao.getByClusterId(clusterId)) {
if (!volumesMap.containsKey(volume.getId())) {
idsToRemove.add(volume.getId());
log.debug("Volume '{}' has been removed directly using the gluster CLI. Removing it from engine as well.", volume.getName());
logUtil.logVolumeMessage(volume, AuditLogType.GLUSTER_VOLUME_DELETED_FROM_CLI);
// Set the gluster cli schedule enabled flag back to true
if (Config.<String>getValue(ConfigValues.GlusterMetaVolumeName).equalsIgnoreCase(volume.getName())) {
Cluster cluster = clusterDao.get(clusterId);
cluster.setGlusterCliBasedSchedulingOn(true);
clusterDao.update(cluster);
}
}
}
if (!idsToRemove.isEmpty()) {
try {
volumeDao.removeAll(idsToRemove);
} catch (Exception e) {
log.error("Error while removing volumes from database!", e);
}
}
}
use of org.ovirt.engine.core.common.businessentities.Cluster in project ovirt-engine by oVirt.
the class GlusterSyncJob method updateExistingAndNewVolumes.
private void updateExistingAndNewVolumes(Guid clusterId, Map<Guid, GlusterVolumeEntity> volumesMap) {
Cluster cluster = clusterDao.get(clusterId);
for (Entry<Guid, GlusterVolumeEntity> entry : volumesMap.entrySet()) {
GlusterVolumeEntity volume = entry.getValue();
log.debug("Analyzing volume '{}'", volume.getName());
GlusterVolumeEntity existingVolume = volumeDao.getById(entry.getKey());
if (existingVolume == null) {
try {
createVolume(volume);
} catch (Exception e) {
log.error("Could not save volume {} in database: {}", volume.getName(), e.getMessage());
log.debug("Exception", e);
}
// Set the CLI based snapshot scheduling flag accordingly
disableCliSnapshotSchedulingFlag(cluster, volume);
} else {
try {
log.debug("Volume '{}' exists in engine. Checking if it needs to be updated.", existingVolume.getName());
updateVolume(existingVolume, volume);
} catch (Exception e) {
log.error("Error while updating volume '{}': {}", volume.getName(), e.getMessage());
log.debug("Exception", e);
}
}
}
}
use of org.ovirt.engine.core.common.businessentities.Cluster in project ovirt-engine by oVirt.
the class GlusterSyncJob method refreshSelfHealInfo.
/**
* Refreshes self heal info from GlusterFS. This method is scheduled less frequently as it uses the 'volume
* heal info' command, that adds significant overhead on Gluster processes, and hence should not be invoked too
* frequently.
*/
@OnTimerMethodAnnotation("refreshSelfHealInfo")
public void refreshSelfHealInfo() {
log.debug("Refreshing Gluster Self Heal Data");
for (Cluster cluster : clusterDao.getAll()) {
if (supportsGlusterSelfHealMonitoring(cluster)) {
try {
refreshSelfHealData(cluster);
} catch (Exception e) {
log.error("Error while refreshing Gluster self heal data of cluster '{}': {}", cluster.getName(), e.getMessage());
log.debug("Exception", e);
}
}
}
log.debug("Refreshing Gluster Self Heal data is completed");
}
use of org.ovirt.engine.core.common.businessentities.Cluster in project ovirt-engine by oVirt.
the class GlusterSyncJob method refreshLightWeightData.
/**
* Refreshes details of all volume across all clusters being managed in the engine. It can end up doing the
* following in engine DB to make sure that the volume details in engine DB are in sync with GlusterFS:<br>
* <li>Insert volumes</li><li>Delete volumes</li><li>Update properties of volume e.g. status, volume type</li><li>
* Add / remove bricks to / from volumes</li><li>Set / Unset volume options</li><br>
* These are all fetched using the 'volume info' command on gluster CLI, which is relatively lightweight, and hence
* this method is scheduled more frequently as compared to the other method <code>refreshHeavyWeightData</code>,
* which uses 'volume status' to fetch and update status of volume bricks.
*/
@OnTimerMethodAnnotation("refreshLightWeightData")
public void refreshLightWeightData() {
log.debug("Refreshing Gluster Data [lightweight]");
List<Cluster> clusters = clusterDao.getAll();
for (Cluster cluster : clusters) {
if (cluster.supportsGlusterService()) {
try {
refreshClusterData(cluster);
} catch (Exception e) {
log.error("Error while refreshing Gluster lightweight data of cluster '{}': {}", cluster.getName(), e.getMessage());
log.debug("Exception", e);
}
}
}
}
Aggregations