Search in sources :

Example 21 with GlusterVolumeEntity

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

the class CreateGlusterVolumeCommand method executeCommand.

/*
     * (non-Javadoc)
     *
     * @see org.ovirt.engine.core.bll.CommandBase#executeCommand()
     */
@Override
protected void executeCommand() {
    // set the gluster volume name for audit purpose
    setGlusterVolumeName(getVolume().getName());
    if (getVolume().getTransportTypes() == null || getVolume().getTransportTypes().isEmpty()) {
        getVolume().addTransportType(TransportType.TCP);
    }
    // GLUSTER access protocol is enabled by default
    getVolume().addAccessProtocol(AccessProtocol.GLUSTER);
    if (!getVolume().getAccessProtocols().contains(AccessProtocol.NFS)) {
        getVolume().disableNFS();
    }
    if (getVolume().getAccessProtocols().contains(AccessProtocol.CIFS)) {
        getVolume().enableCifs();
    }
    VDSReturnValue returnValue = runVdsCommand(VDSCommandType.CreateGlusterVolume, new CreateGlusterVolumeVDSParameters(upServer.getId(), getVolume(), upServer.getClusterCompatibilityVersion(), getParameters().isForce()));
    setSucceeded(returnValue.getSucceeded());
    if (!getSucceeded()) {
        handleVdsError(AuditLogType.GLUSTER_VOLUME_CREATE_FAILED, returnValue.getVdsError().getMessage());
        return;
    }
    // Volume created successfully. Insert it to database.
    GlusterVolumeEntity createdVolume = (GlusterVolumeEntity) returnValue.getReturnValue();
    setVolumeType(createdVolume);
    setBrickOrder(createdVolume.getBricks());
    if (createdVolume.getIsArbiter()) {
        setArbiterFlag(createdVolume);
    }
    addVolumeToDb(createdVolume);
    // If we log successful volume creation at the end of this command,
    // the messages from SetGlusterVolumeOptionCommand appear first,
    // making it look like options were set before volume was created.
    // Hence we explicitly log the volume creation before setting the options.
    auditLogDirector.log(this, AuditLogType.GLUSTER_VOLUME_CREATE);
    // And don't log it at the end
    setCommandShouldBeLogged(false);
    // set all options of the volume
    setVolumeOptions(createdVolume);
    getReturnValue().setActionReturnValue(createdVolume.getId());
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) CreateGlusterVolumeVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.CreateGlusterVolumeVDSParameters)

Example 22 with GlusterVolumeEntity

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

the class CreateGlusterVolumeSnapshotCommand method pauseAndCreateSnapshotForGeoRepSessions.

private boolean pauseAndCreateSnapshotForGeoRepSessions() {
    if (georepSessions != null && georepSessions.size() > 0) {
        for (GlusterGeoRepSession session : georepSessions) {
            final GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
            if (slaveVolume == null) {
                // Continue to other geo-rep sessions and pause them for snapshot purpose
                continue;
            }
            VDS slaveUpServer = glusterUtil.getRandomUpServer(slaveVolume.getClusterId());
            if (slaveUpServer == null) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED, "No up server found in slave cluster of geo-rep session");
                setSucceeded(false);
                return false;
            }
            // Pause the geo-rep session if required
            if (!(session.getStatus() == GeoRepSessionStatus.CREATED || session.getStatus() == GeoRepSessionStatus.PAUSED || session.getStatus() == GeoRepSessionStatus.STOPPED)) {
                ActionReturnValue sessionPauseRetVal = null;
                try (EngineLock lock = acquireEngineLock(slaveVolume.getId(), LockingGroup.GLUSTER_SNAPSHOT)) {
                    sessionPauseRetVal = runInternalAction(ActionType.PauseGlusterVolumeGeoRepSession, new GlusterVolumeGeoRepSessionParameters(getGlusterVolumeId(), session.getId()));
                }
                if (sessionPauseRetVal != null && !sessionPauseRetVal.getSucceeded()) {
                    handleVdsErrors(AuditLogType.GLUSTER_VOLUME_GEO_REP_PAUSE_FAILED, sessionPauseRetVal.getExecuteFailedMessages());
                    setSucceeded(false);
                    return false;
                }
                session.setStatus(GeoRepSessionStatus.PAUSED);
                enginePausedSessions.add(session);
            }
            // Create snapshot for slave volume
            VDSReturnValue snapCreationRetVal = runVdsCommand(VDSCommandType.CreateGlusterVolumeSnapshot, new CreateGlusterVolumeSnapshotVDSParameters(slaveUpServer.getId(), session.getSlaveVolumeName(), snapshot.getSnapshotName(), snapshot.getDescription(), force));
            if (!snapCreationRetVal.getSucceeded()) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED, snapCreationRetVal.getVdsError().getMessage());
                setSucceeded(false);
                return false;
            } else {
                // Persist the snapshot details
                GlusterVolumeSnapshotEntity slaveVolumeSnapshot = (GlusterVolumeSnapshotEntity) snapCreationRetVal.getReturnValue();
                slaveVolumeSnapshot.setClusterId(slaveVolume.getClusterId());
                slaveVolumeSnapshot.setVolumeId(slaveVolume.getId());
                slaveVolumeSnapshot.setDescription(snapshot.getDescription());
                slaveVolumeSnapshot.setStatus(GlusterSnapshotStatus.DEACTIVATED);
                glusterVolumeSnapshotDao.save(slaveVolumeSnapshot);
                // check if the snapshot soft limit reached now for the volume and alert
                glusterUtil.alertVolumeSnapshotLimitsReached(slaveVolume);
            }
        }
    }
    return true;
}
Also used : CreateGlusterVolumeSnapshotVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.CreateGlusterVolumeSnapshotVDSParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeGeoRepSessionParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 23 with GlusterVolumeEntity

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

the class DeleteAllGlusterVolumeSnapshotsCommand method executeCommand.

@Override
public void executeCommand() {
    if (georepSessions != null) {
        for (GlusterGeoRepSession session : georepSessions) {
            GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
            if (slaveVolume == null) {
                // continue with other sessions and try to pause
                continue;
            }
            VDS slaveUpServer = glusterUtil.getRandomUpServer(slaveVolume.getClusterId());
            if (slaveUpServer == null) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_ALL_SNAPSHOTS_DELETE_FAILED, EngineError.NoUpServerFoundInRemoteCluster.name());
                setSucceeded(false);
                return;
            }
            List<GlusterVolumeSnapshotEntity> slaveVolumeSnapshots = glusterVolumeSnapshotDao.getAllByVolumeId(slaveVolume.getId());
            try (EngineLock lock = acquireEngineLock(session.getSlaveVolumeId(), LockingGroup.GLUSTER_SNAPSHOT)) {
                if (!deleteAllGlusterVolumeSnapshots(slaveUpServer.getId(), slaveVolume.getName(), slaveVolumeSnapshots)) {
                    return;
                }
                // Check and remove soft limit alert for the volume
                glusterUtil.checkAndRemoveVolumeSnapshotLimitsAlert(slaveVolume);
            }
        }
    }
    deleteAllGlusterVolumeSnapshots(getUpServer().getId(), getGlusterVolumeName(), snapshots);
    // Check and remove soft limit alert for the volume
    glusterUtil.checkAndRemoveVolumeSnapshotLimitsAlert(getGlusterVolume());
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 24 with GlusterVolumeEntity

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

the class DeleteGlusterVolumeCommand method validate.

@Override
protected boolean validate() {
    if (!super.validate()) {
        return false;
    }
    GlusterVolumeEntity volume = getGlusterVolume();
    if (volume.isOnline()) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_VOLUME_IS_UP);
        addValidationMessageVariable("volumeName", volume.getName());
        return false;
    }
    if (volume.getSnapshotsCount() > 0) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_VOLUME_HAS_SNAPSHOTS);
        addValidationMessageVariable("volumeName", volume.getName());
        addValidationMessageVariable("noOfSnapshots", volume.getSnapshotsCount());
        return false;
    }
    return true;
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)

Example 25 with GlusterVolumeEntity

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

the class DeleteGlusterVolumeSnapshotCommand method executeCommand.

@Override
public void executeCommand() {
    if (georepSessions != null) {
        for (GlusterGeoRepSession session : georepSessions) {
            GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
            if (slaveVolume == null) {
                // continue with other sessions and try to pause
                continue;
            }
            VDS slaveUpServer = glusterUtil.getRandomUpServer(slaveVolume.getClusterId());
            if (slaveUpServer == null) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_DELETE_FAILED, EngineError.NoUpServerFoundInRemoteCluster.name());
                setSucceeded(false);
                return;
            }
            try (EngineLock lock = acquireEngineLock(session.getSlaveVolumeId(), LockingGroup.GLUSTER_SNAPSHOT)) {
                if (!deleteGlusterVolumeSnapshot(slaveUpServer.getId(), slaveVolume.getName(), getSnapshot().getSnapshotName())) {
                    return;
                }
                // Check and remove soft limit alert for the volume
                glusterUtil.checkAndRemoveVolumeSnapshotLimitsAlert(slaveVolume);
            }
        }
    }
    deleteGlusterVolumeSnapshot(getUpServer().getId(), getGlusterVolumeName(), getSnapshot().getSnapshotName());
    // Check and remove soft limit alert for the volume
    glusterUtil.checkAndRemoveVolumeSnapshotLimitsAlert(getGlusterVolume());
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

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