Search in sources :

Example 61 with GlusterVolumeEntity

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotListModel method createSnapshot.

private void createSnapshot() {
    if (getWindow() != null) {
        return;
    }
    GlusterVolumeEntity volumeEntity = getEntity();
    final GlusterVolumeSnapshotModel snapshotModel = new GlusterVolumeSnapshotModel(true, !volumeEntity.getSnapshotScheduled());
    snapshotModel.setHelpTag(HelpTag.new_volume_snapshot);
    // $NON-NLS-1$
    snapshotModel.setHashName("new_volume_snapshot");
    snapshotModel.setTitle(ConstantsManager.getInstance().getConstants().createScheduleVolumeSnapshotTitle());
    setWindow(snapshotModel);
    snapshotModel.startProgress();
    snapshotModel.getClusterName().setEntity(volumeEntity.getClusterName());
    snapshotModel.getVolumeName().setEntity(volumeEntity.getName());
    AsyncDataProvider.getInstance().getIsGlusterVolumeSnapshotCliScheduleEnabled(new AsyncQuery<>(isCliScheduleEnabled -> {
        snapshotModel.getDisableCliSchedule().setEntity(isCliScheduleEnabled);
        snapshotModel.stopProgress();
    }), volumeEntity.getClusterId());
    // $NON-NLS-1$
    UICommand okCommand = UICommand.createDefaultOkUiCommand("onCreateSnapshot", this);
    snapshotModel.getCommands().add(okCommand);
    // $NON-NLS-1$
    UICommand cancelCommand = UICommand.createCancelUiCommand("cancel", this);
    snapshotModel.getCommands().add(cancelCommand);
}
Also used : Time(java.sql.Time) TimeZoneType(org.ovirt.engine.core.common.TimeZoneType) Date(java.util.Date) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) AsyncCallback(org.ovirt.engine.ui.frontend.AsyncCallback) DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) ActionType(org.ovirt.engine.core.common.action.ActionType) Frontend(org.ovirt.engine.ui.frontend.Frontend) GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) ScheduleGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters) GlusterSnapshotStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterSnapshotStatus) Map(java.util.Map) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) GlusterVolumeParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeParameters) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) GlusterVolumeSnapshotActionParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeSnapshotActionParameters) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) CreateGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.CreateGlusterVolumeSnapshotParameters) GlusterVolumeSnapshotScheduleRecurrence(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotScheduleRecurrence) Linq(org.ovirt.engine.ui.uicommonweb.Linq) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus) List(java.util.List) UIConstants(org.ovirt.engine.ui.uicompat.UIConstants) Comparator(java.util.Comparator) Collections(java.util.Collections) EndDateOptions(org.ovirt.engine.ui.uicommonweb.models.gluster.GlusterVolumeSnapshotModel.EndDateOptions) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 62 with GlusterVolumeEntity

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity in project ovirt-engine by oVirt.

the class GlusterVolumeSnapshotListModel method scheduleSnapshot.

private void scheduleSnapshot(final GlusterVolumeSnapshotModel snapshotModel, boolean reschedule) {
    GlusterVolumeEntity volumeEntity = getEntity();
    final GlusterVolumeSnapshotSchedule schedule = new GlusterVolumeSnapshotSchedule();
    schedule.setSnapshotNamePrefix(snapshotModel.getSnapshotName().getEntity());
    schedule.setSnapshotDescription(snapshotModel.getDescription().getEntity());
    schedule.setClusterId(volumeEntity.getClusterId());
    schedule.setVolumeId(volumeEntity.getId());
    switch(snapshotModel.getRecurrence().getSelectedItem()) {
        case INTERVAL:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.INTERVAL);
            schedule.setInterval(Integer.valueOf(snapshotModel.getInterval().getSelectedItem()));
            break;
        case HOURLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.HOURLY);
            break;
        case DAILY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.DAILY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            break;
        case WEEKLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.WEEKLY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            StringBuilder sb = new StringBuilder();
            for (DayOfWeek day : snapshotModel.getDaysOfTheWeek().getSelectedItem()) {
                sb.append(day.name().substring(0, 3));
                // $NON-NLS-1$
                sb.append(',');
            }
            schedule.setDays(sb.toString());
            break;
        case MONTHLY:
            schedule.setRecurrence(GlusterVolumeSnapshotScheduleRecurrence.MONTHLY);
            schedule.setExecutionTime(getExecutionTime(snapshotModel));
            schedule.setDays(snapshotModel.getDaysOfMonth().getSelectedItem());
            break;
    }
    Date startAt = snapshotModel.getStartAt().getEntity();
    schedule.setStartDate(startAt);
    schedule.setTimeZone(snapshotModel.getTimeZones().getSelectedItem().getKey());
    if (snapshotModel.getEndByOptions().getSelectedItem() == EndDateOptions.NoEndDate) {
        schedule.setEndByDate(null);
    } else {
        schedule.setEndByDate(snapshotModel.getEndDate().getEntity());
    }
    ScheduleGlusterVolumeSnapshotParameters params = new ScheduleGlusterVolumeSnapshotParameters(schedule, snapshotModel.getDisableCliSchedule().getEntity());
    snapshotModel.startProgress();
    ActionType actionType = null;
    if (reschedule) {
        actionType = ActionType.RescheduleGlusterVolumeSnapshot;
    } else {
        actionType = ActionType.ScheduleGlusterVolumeSnapshot;
    }
    Frontend.getInstance().runAction(actionType, params, result -> {
        GlusterVolumeSnapshotListModel localModel = (GlusterVolumeSnapshotListModel) result.getState();
        snapshotModel.stopProgress();
        localModel.postSnapshotAction(result.getReturnValue());
    }, this, snapshotModel.getDisableCliSchedule().getEntity());
}
Also used : DayOfWeek(org.ovirt.engine.core.compat.DayOfWeek) GlusterVolumeSnapshotSchedule(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule) ActionType(org.ovirt.engine.core.common.action.ActionType) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) Date(java.util.Date) ScheduleGlusterVolumeSnapshotParameters(org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters)

Example 63 with GlusterVolumeEntity

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity in project ovirt-engine by oVirt.

the class UpdateClusterCommand method validate.

@Override
protected boolean validate() {
    boolean result = true;
    boolean hasVms = false;
    boolean hasVmOrHost = false;
    boolean sameCpuNames = false;
    boolean allVdssInMaintenance = false;
    List<VM> vmList = null;
    if (oldCluster == null) {
        addValidationMessage(EngineMessage.VDS_CLUSTER_IS_NOT_VALID);
        result = false;
    }
    // if the name was changed then make sure the new name is unique
    if (result && !StringUtils.equals(oldCluster.getName(), getCluster().getName())) {
        if (!isClusterUnique(getCluster().getName())) {
            addValidationMessage(EngineMessage.CLUSTER_CANNOT_DO_ACTION_NAME_IN_USE);
            result = false;
        }
    }
    if (result && !VersionSupport.checkVersionSupported(getCluster().getCompatibilityVersion())) {
        addValidationMessage(VersionSupport.getUnsupportedVersionMessage());
        result = false;
    }
    if (result) {
        allForCluster = vdsDao.getAllForCluster(oldCluster.getId());
    }
    // decreasing of compatibility version is only allowed when no hosts exists, and not beneath the DC version
    if (result && getCluster().getCompatibilityVersion().compareTo(oldCluster.getCompatibilityVersion()) < 0) {
        if (!allForCluster.isEmpty()) {
            result = false;
            addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_CANNOT_DECREASE_CLUSTER_WITH_HOSTS_COMPATIBILITY_VERSION);
        }
        if (oldCluster.getStoragePoolId() != null) {
            ClusterValidator validator = new ClusterValidator(dbFacade, oldCluster, getCpuFlagsManagerHandler());
            if (!validate(validator.dataCenterVersionMismatch())) {
                result = false;
                addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_CANNOT_DECREASE_COMPATIBILITY_VERSION_UNDER_DC);
            }
        }
    }
    if (result && oldCluster.getStoragePoolId() != null && !oldCluster.getStoragePoolId().equals(getCluster().getStoragePoolId())) {
        addValidationMessage(EngineMessage.CLUSTER_CANNOT_CHANGE_STORAGE_POOL);
        result = false;
    }
    // If both original Cpu and new Cpu are null, don't check Cpu validity
    if (result) {
        allVdssInMaintenance = areAllVdssInMaintenance(allForCluster);
    }
    // Validate the cpu only if the cluster supports Virt
    if (result && getCluster().supportsVirtService() && (oldCluster.getCpuName() != null || getCluster().getCpuName() != null)) {
        // Check that cpu exist
        if (!checkIfCpusExist()) {
            addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_CPU_NOT_FOUND);
            addValidationMessage(EngineMessage.VAR__TYPE__CLUSTER);
            result = false;
        } else {
            // vds in this cluster, cannot update
            if (!StringUtils.isEmpty(oldCluster.getCpuName()) && !checkIfCpusSameManufacture(oldCluster) && !allVdssInMaintenance) {
                addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_CPU_ILLEGAL);
                result = false;
            }
        }
    }
    if (result) {
        vmList = vmDao.getAllForCluster(oldCluster.getId());
        hasVmOrHost = !vmList.isEmpty() || !allForCluster.isEmpty();
    }
    // cannot change the processor architecture while there are attached hosts or VMs to the cluster
    if (result && getCluster().supportsVirtService() && !isArchitectureUpdatable() && hasVmOrHost) {
        addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_CPU_ARCHITECTURE_ILLEGAL);
        result = false;
    }
    if (result) {
        sameCpuNames = StringUtils.equals(oldCluster.getCpuName(), getCluster().getCpuName());
    }
    if (result) {
        boolean isOldCPUEmpty = StringUtils.isEmpty(oldCluster.getCpuName());
        if (!isOldCPUEmpty && !sameCpuNames && !isCpuUpdatable(oldCluster) && hasVmOrHost) {
            addValidationMessage(EngineMessage.CLUSTER_CPU_IS_NOT_UPDATABLE);
            result = false;
        }
    }
    if (result && !oldCluster.getCompatibilityVersion().equals(getCluster().getCompatibilityVersion())) {
        for (VM vm : vmList) {
            if (vm.isPreviewSnapshot()) {
                // can't change cluster version when a VM is in preview
                if (result) {
                    addValidationMessage(EngineMessage.CLUSTER_VERSION_CHANGE_VM_PREVIEW);
                    // and continue with adding validation messages
                    result = false;
                }
                addValidationMessage(vm.getName());
            }
        }
    }
    if (result) {
        List<VDS> vdss = new ArrayList<>();
        isAddedToStoragePool = oldCluster.getStoragePoolId() == null && getCluster().getStoragePoolId() != null;
        if (isAddedToStoragePool && !validateManagementNetwork()) {
            return false;
        }
        for (VDS vds : allForCluster) {
            if (vds.getStatus() == VDSStatus.Up) {
                if (isAddedToStoragePool) {
                    addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_VDS_UP);
                    return false;
                } else {
                    vdss.add(vds);
                }
            }
        }
        for (VDS vds : vdss) {
            if (!VersionSupport.checkClusterVersionSupported(getCluster().getCompatibilityVersion(), vds)) {
                result = false;
                addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_COMPATIBILITY_VERSION_WITH_LOWER_HOSTS);
                break;
            } else if (getCluster().supportsVirtService() && missingServerCpuFlags(vds) != null) {
                addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_CPU_WITH_LOWER_HOSTS);
                result = false;
                break;
            }
            if (!isSupportedEmulatedMachinesMatchClusterLevel(vds)) {
                return failValidation(EngineMessage.CLUSTER_CANNOT_UPDATE_COMPATIBILITY_VERSION_WITH_INCOMPATIBLE_EMULATED_MACHINE);
            }
        }
        if (result) {
            Set<SupportedAdditionalClusterFeature> additionalClusterFeaturesAdded = getAdditionalClusterFeaturesAdded();
            // New Features cannot be enabled if all up hosts are not supporting the selected feature
            if (CollectionUtils.isNotEmpty(additionalClusterFeaturesAdded) && !checkClusterFeaturesSupported(vdss, additionalClusterFeaturesAdded)) {
                addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_SUPPORTED_FEATURES_WITH_LOWER_HOSTS);
                result = false;
            }
        }
        if (result) {
            boolean notDownVms = false;
            boolean suspendedVms = false;
            hasVms = vmList.size() > 0;
            if (!sameCpuNames) {
                for (VM vm : vmList) {
                    if (vm.getStatus() == VMStatus.Suspended) {
                        suspendedVms = true;
                        break;
                    } else if (vm.getStatus() != VMStatus.Down) {
                        notDownVms = true;
                        break;
                    }
                }
                if (suspendedVms) {
                    addValidationMessage(EngineMessage.CLUSTER_CANNOT_UPDATE_CPU_WITH_SUSPENDED_VMS);
                    result = false;
                } else if (notDownVms) {
                    int compareResult = compareCpuLevels(oldCluster);
                    if (compareResult > 0) {
                        // Upgrade of CPU in same compability level is allowed if
                        // there
                        // are running VMs - but we should warn they
                        // cannot not be hibernated
                        addCustomValue("Cluster", getParameters().getCluster().getName());
                        auditLogDirector.log(this, AuditLogType.CANNOT_HIBERNATE_RUNNING_VMS_AFTER_CLUSTER_CPU_UPGRADE);
                    }
                }
            }
        }
    }
    if (result && getCluster().getStoragePoolId() != null) {
        StoragePool storagePool = storagePoolDao.get(getCluster().getStoragePoolId());
        if (oldCluster.getStoragePoolId() == null && storagePool.isLocal()) {
            // we allow only one cluster in localfs data center
            if (!clusterDao.getAllForStoragePool(getCluster().getStoragePoolId()).isEmpty()) {
                getReturnValue().getValidationMessages().add(EngineMessage.CLUSTER_CANNOT_ADD_MORE_THEN_ONE_HOST_TO_LOCAL_STORAGE.toString());
                result = false;
            } else if (Config.getValue(ConfigValues.AutoRegistrationDefaultClusterID).equals(getCluster().getId())) {
                addValidationMessage(EngineMessage.DEFAULT_CLUSTER_CANNOT_BE_ON_LOCALFS);
                result = false;
            }
        }
    }
    if (result) {
        if (!(getCluster().supportsGlusterService() || getCluster().supportsVirtService())) {
            addValidationMessage(EngineMessage.CLUSTER_AT_LEAST_ONE_SERVICE_MUST_BE_ENABLED);
            result = false;
        } else if (getCluster().supportsGlusterService() && getCluster().supportsVirtService() && !isAllowClusterWithVirtGluster()) {
            addValidationMessage(EngineMessage.CLUSTER_ENABLING_BOTH_VIRT_AND_GLUSTER_SERVICES_NOT_ALLOWED);
            result = false;
        }
    }
    if (result && hasVms && !getCluster().supportsVirtService()) {
        addValidationMessage(EngineMessage.CLUSTER_CANNOT_DISABLE_VIRT_WHEN_CLUSTER_CONTAINS_VMS);
        result = false;
    }
    if (result && !getCluster().supportsGlusterService()) {
        List<GlusterVolumeEntity> volumes = glusterVolumeDao.getByClusterId(getCluster().getId());
        if (volumes != null && volumes.size() > 0) {
            addValidationMessage(EngineMessage.CLUSTER_CANNOT_DISABLE_GLUSTER_WHEN_CLUSTER_CONTAINS_VOLUMES);
            result = false;
        }
    }
    if (result && getCluster().supportsTrustedService() && Config.<String>getValue(ConfigValues.AttestationServer).equals("")) {
        addValidationMessage(EngineMessage.CLUSTER_CANNOT_SET_TRUSTED_ATTESTATION_SERVER_NOT_CONFIGURED);
        result = false;
    }
    if (result && !FeatureSupported.isMigrationSupported(getArchitecture(), getCluster().getCompatibilityVersion()) && getCluster().getMigrateOnError() != MigrateOnErrorOptions.NO) {
        return failValidation(EngineMessage.MIGRATION_ON_ERROR_IS_NOT_SUPPORTED);
    }
    if (result) {
        result = validateClusterPolicy(oldCluster);
    }
    if (result && getParameters().isForceResetEmulatedMachine()) {
        for (VDS vds : allForCluster) {
            if (vds.getStatus() == VDSStatus.Up) {
                addValidationMessage(EngineMessage.CLUSTER_HOSTS_MUST_BE_DOWN);
                result = false;
                break;
            }
        }
    }
    ClusterValidator clusterValidator = new ClusterValidator(dbFacade, getCluster(), cpuFlagsManagerHandler);
    result = result && validate(clusterValidator.rngSourcesAllowed()) && validate(clusterValidator.memoryOptimizationConfiguration()) && validate(moveMacs.canMigrateMacsToAnotherMacPool(oldCluster, getNewMacPoolId())) && validateDefaultNetworkProvider() && validate(clusterValidator.supportedFirewallTypeForClusterVersion());
    return result;
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VDS(org.ovirt.engine.core.common.businessentities.VDS) ClusterValidator(org.ovirt.engine.core.bll.validator.ClusterValidator) ArrayList(java.util.ArrayList) SupportedAdditionalClusterFeature(org.ovirt.engine.core.common.businessentities.SupportedAdditionalClusterFeature) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) VM(org.ovirt.engine.core.common.businessentities.VM)

Example 64 with GlusterVolumeEntity

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity in project ovirt-engine by oVirt.

the class GlusterSnapshotSyncJob method refreshSnapshotsInCluster.

private void refreshSnapshotsInCluster(Cluster cluster) {
    if (!supportsGlusterSnapshotFeature(cluster)) {
        return;
    }
    final VDS upServer = glusterUtil.getRandomUpServer(cluster.getId());
    if (upServer == null) {
        log.info("No UP server found in cluster '{}' for snapshot monitoring", cluster.getName());
        return;
    }
    VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GetGlusterVolumeSnapshotInfo, new GlusterVolumeSnapshotVDSParameters(upServer.getId(), cluster.getId(), null));
    if (returnValue.getSucceeded()) {
        addOrUpdateSnapshots(cluster.getId(), (ArrayList<GlusterVolumeSnapshotEntity>) returnValue.getReturnValue());
        // check if the snapshot soft limit reached for a volume and alert
        List<GlusterVolumeEntity> volumes = volumeDao.getByClusterId(cluster.getId());
        for (final GlusterVolumeEntity volume : volumes) {
            // check if the snapshot soft limit reached for the volume and alert
            glusterUtil.alertVolumeSnapshotLimitsReached(volume);
            // Check and remove soft limit alert for the volume.
            // It might have fallen below the soft limit as part of deletions of snapshots
            glusterUtil.checkAndRemoveVolumeSnapshotLimitsAlert(volume);
        }
    } else {
        log.error("VDS Error {}", returnValue.getVdsError().getMessage());
        log.debug("VDS Error {}", returnValue.getVdsError());
    }
}
Also used : GlusterVolumeSnapshotVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeSnapshotVDSParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 65 with GlusterVolumeEntity

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity 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)

Aggregations

GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)220 ArrayList (java.util.ArrayList)57 GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)49 Test (org.junit.Test)47 Guid (org.ovirt.engine.core.compat.Guid)30 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)30 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)26 GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)20 VDS (org.ovirt.engine.core.common.businessentities.VDS)19 HashMap (java.util.HashMap)16 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)16 List (java.util.List)15 Map (java.util.Map)15 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)15 ActionType (org.ovirt.engine.core.common.action.ActionType)13 GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)13 GlusterVolumeSnapshotEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity)13 GlusterVolumeType (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType)13 GlusterVolumeRemoveBricksParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeRemoveBricksParameters)12 GlusterTaskType (org.ovirt.engine.core.common.asynctasks.gluster.GlusterTaskType)12