Search in sources :

Example 96 with Cluster

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());
    }
}
Also used : HashMap(java.util.HashMap) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) EngineException(org.ovirt.engine.core.common.errors.EngineException) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)

Example 97 with Cluster

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);
        }
    }
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid)

Example 98 with Cluster

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);
            }
        }
    }
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid)

Example 99 with Cluster

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");
}
Also used : Cluster(org.ovirt.engine.core.common.businessentities.Cluster) OnTimerMethodAnnotation(org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation)

Example 100 with Cluster

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);
            }
        }
    }
}
Also used : Cluster(org.ovirt.engine.core.common.businessentities.Cluster) OnTimerMethodAnnotation(org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation)

Aggregations

Cluster (org.ovirt.engine.core.common.businessentities.Cluster)346 Test (org.junit.Test)83 ArrayList (java.util.ArrayList)80 Guid (org.ovirt.engine.core.compat.Guid)77 VDS (org.ovirt.engine.core.common.businessentities.VDS)54 List (java.util.List)50 VM (org.ovirt.engine.core.common.businessentities.VM)36 HashMap (java.util.HashMap)35 Map (java.util.Map)33 HashSet (java.util.HashSet)30 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)30 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)28 Version (org.ovirt.engine.core.compat.Version)27 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)26 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)26 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)25 Set (java.util.Set)24 QueryType (org.ovirt.engine.core.common.queries.QueryType)23 Collections (java.util.Collections)22 Frontend (org.ovirt.engine.ui.frontend.Frontend)22