Search in sources :

Example 41 with GlusterBrickEntity

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

the class GlusterBrickValidator method canRemoveBrick.

/**
 * Checks that all brick ids passed are valid, also updating the bricks with server name and brick directory using
 * the brick objects obtained from the volume.
 *
 * @param bricks
 *            The bricks to validate
 * @return true if all bricks have valid ids, else false
 */
public ValidationResult canRemoveBrick(List<GlusterBrickEntity> bricks, GlusterVolumeEntity volumeEntity, int replicaCount, boolean forceRemove) {
    if (replicaCount == 0) {
        replicaCount = volumeEntity.getReplicaCount();
    }
    if (bricks.isEmpty()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_BRICKS_REQUIRED);
    }
    if (volumeEntity.getBricks().size() == 1 || volumeEntity.getBricks().size() <= bricks.size()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_REMOVE_ALL_BRICKS_FROM_VOLUME);
    }
    if (volumeEntity.getVolumeType().isReplicatedType()) {
        if (replicaCount == volumeEntity.getReplicaCount() - 1 && !forceRemove) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_REDUCE_REPLICA_COUNT_WITH_DATA_MIGRATION);
        } else if (replicaCount < volumeEntity.getReplicaCount() - 1) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_REDUCE_REPLICA_COUNT_MORE_THAN_ONE);
        } else if (replicaCount > volumeEntity.getReplicaCount()) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_CAN_NOT_INCREASE_REPLICA_COUNT);
        }
    }
    for (GlusterBrickEntity brick : bricks) {
        if (brick.getId(false) == null && brick.getQualifiedName() == null) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_BRICKS_REQUIRED);
        }
        GlusterBrickEntity brickFromVolume = volumeEntity.getBrickWithId(brick.getId());
        if (brickFromVolume == null) {
            brickFromVolume = volumeEntity.getBrickWithQualifiedName(brick.getQualifiedName());
        }
        if (brickFromVolume == null) {
            return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_BRICK_INVALID);
        } else {
            // Fill required details from volume data
            brick.setId(brickFromVolume.getId());
            brick.setServerName(brickFromVolume.getServerName());
            brick.setBrickDirectory(brickFromVolume.getBrickDirectory());
        }
    }
    if (!forceRemove) {
        return canRebalance(volumeEntity);
    } else {
        return ValidationResult.VALID;
    }
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 42 with GlusterBrickEntity

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

the class GlusterBrickValidator method canStopOrCommitRemoveBrick.

public ValidationResult canStopOrCommitRemoveBrick(GlusterVolumeEntity volumeEntity, List<GlusterBrickEntity> paramBricks) {
    GlusterAsyncTask asyncTask = volumeEntity.getAsyncTask();
    if (asyncTask == null || asyncTask.getType() != GlusterTaskType.REMOVE_BRICK) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_VOLUME_INVALID_TASK_TYPE);
    }
    if (paramBricks.isEmpty()) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_BRICKS_REQUIRED);
    }
    List<GlusterBrickEntity> bricksForTask = getGlusterBrickDao().getGlusterVolumeBricksByTaskId(asyncTask.getTaskId());
    if (paramBricks.size() != bricksForTask.size() || !areBricksInTheList(volumeEntity, paramBricks, bricksForTask)) {
        return new ValidationResult(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_VOLUME_REMOVE_BRICKS_PARAMS_INVALID, String.format("$validBricks [%s]", getValidBrickNames(bricksForTask)));
    }
    return ValidationResult.VALID;
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) ValidationResult(org.ovirt.engine.core.bll.ValidationResult)

Example 43 with GlusterBrickEntity

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

the class GlusterSyncJob method createVolume.

/**
 * Creates a new volume in engine
 */
private void createVolume(final GlusterVolumeEntity volume) {
    if (volume.getBricks() == null) {
        log.warn("Bricks of volume '{}' were not fetched. " + "Hence will not add it to engine at this point.", volume.getName());
        return;
    }
    for (GlusterBrickEntity brick : volume.getBricks()) {
        if (brick == null) {
            log.warn("Volume '{}' contains a apparently corrupt brick(s). " + "Hence will not add it to engine at this point.", volume.getName());
            return;
        } else if (brick.getServerId() == null) {
            log.warn("Volume '{}' contains brick(s) from unknown hosts. " + "Hence will not add it to engine at this point.", volume.getName());
            return;
        }
        // Set initial brick status as similar to volume status.
        // As actual brick status is updated by another sync job,
        // till it happens, this gives better UI experience
        brick.setStatus(volume.getStatus());
    }
    logUtil.logVolumeMessage(volume, AuditLogType.GLUSTER_VOLUME_CREATED_FROM_CLI);
    if (!volume.getVolumeType().isSupported()) {
        logUtil.logAuditMessage(volume.getClusterId(), volume.getClusterName(), volume, null, AuditLogType.GLUSTER_VOLUME_TYPE_UNSUPPORTED, Collections.singletonMap(GlusterConstants.VOLUME_TYPE, volume.getVolumeType().toString()));
    }
    log.debug("Volume '{}' has been created directly using the gluster CLI. Creating it in engine as well.", volume.getName());
    volumeDao.save(volume);
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)

Example 44 with GlusterBrickEntity

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

the class GlusterSyncJob method refreshVolumeDetails.

public void refreshVolumeDetails(VDS upServer, GlusterVolumeEntity volume) {
    List<GlusterBrickEntity> bricksToUpdate = new ArrayList<>();
    List<GlusterBrickEntity> brickPropertiesToUpdate = new ArrayList<>();
    List<GlusterBrickEntity> brickPropertiesToAdd = new ArrayList<>();
    GlusterVolumeAdvancedDetails volumeAdvancedDetails = getVolumeAdvancedDetails(upServer, volume.getClusterId(), volume.getName());
    if (volumeAdvancedDetails == null) {
        log.error("Error while refreshing brick statuses for volume '{}'. Failed to get volume advanced details ", volume.getName());
        return;
    }
    if (volumeAdvancedDetails.getCapacityInfo() != null) {
        if (volume.getAdvancedDetails().getCapacityInfo() == null) {
            volumeDao.addVolumeCapacityInfo(volumeAdvancedDetails.getCapacityInfo());
        } else {
            volumeDao.updateVolumeCapacityInfo(volumeAdvancedDetails.getCapacityInfo());
        }
    }
    Map<Guid, BrickProperties> brickPropertiesMap = getBrickPropertiesMap(volumeAdvancedDetails);
    for (GlusterBrickEntity brick : volume.getBricks()) {
        BrickProperties brickProperties = brickPropertiesMap.get(brick.getId());
        if (brickProperties != null) {
            if (brickProperties.getStatus() != brick.getStatus()) {
                logBrickStatusChange(volume, brick, brickProperties.getStatus());
                brick.setStatus(brickProperties.getStatus());
                bricksToUpdate.add(brick);
            }
            if (brick.getBrickProperties() == null) {
                BrickDetails brickDetails = new BrickDetails();
                brickDetails.setBrickProperties(brickProperties);
                brick.setBrickDetails(brickDetails);
                brickPropertiesToAdd.add(brick);
            } else if (brickProperties.getTotalSize() != brick.getBrickProperties().getTotalSize() || brickProperties.getFreeSize() != brick.getBrickProperties().getFreeSize()) {
                brick.getBrickDetails().setBrickProperties(brickProperties);
                brickPropertiesToUpdate.add(brick);
            }
        }
    }
    if (!brickPropertiesToAdd.isEmpty()) {
        brickDao.addBrickProperties(brickPropertiesToAdd);
    }
    if (!brickPropertiesToUpdate.isEmpty()) {
        brickDao.updateBrickProperties(brickPropertiesToUpdate);
    }
    if (!bricksToUpdate.isEmpty()) {
        brickDao.updateBrickStatuses(bricksToUpdate);
    }
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) ArrayList(java.util.ArrayList) GlusterVolumeAdvancedDetails(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeAdvancedDetails) BrickDetails(org.ovirt.engine.core.common.businessentities.gluster.BrickDetails) Guid(org.ovirt.engine.core.compat.Guid) BrickProperties(org.ovirt.engine.core.common.businessentities.gluster.BrickProperties)

Example 45 with GlusterBrickEntity

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

the class GlusterSyncJob method removeDeletedBricks.

@SuppressWarnings("serial")
private void removeDeletedBricks(GlusterVolumeEntity existingVolume, List<GlusterBrickEntity> fetchedBricks) {
    List<Guid> idsToRemove = new ArrayList<>();
    for (final GlusterBrickEntity existingBrick : existingVolume.getBricks()) {
        if (!GlusterCoreUtil.containsBrick(fetchedBricks, existingBrick)) {
            idsToRemove.add(existingBrick.getId());
            log.info("Detected brick '{}' removed from volume '{}'. Removing it from engine DB as well.", existingBrick.getQualifiedName(), existingVolume.getName());
            logUtil.logAuditMessage(existingVolume.getClusterId(), existingVolume.getClusterName(), existingVolume, null, AuditLogType.GLUSTER_VOLUME_BRICK_REMOVED_FROM_CLI, Collections.singletonMap(GlusterConstants.BRICK, existingBrick.getQualifiedName()));
        }
    }
    if (!idsToRemove.isEmpty()) {
        try {
            brickDao.removeAll(idsToRemove);
        } catch (Exception e) {
            log.error("Error while removing bricks from database: {}", e.getMessage());
            log.debug("Exception", e);
        }
    }
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)132 ArrayList (java.util.ArrayList)63 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)43 Test (org.junit.Test)28 Guid (org.ovirt.engine.core.compat.Guid)19 GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)14 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)13 VDS (org.ovirt.engine.core.common.businessentities.VDS)11 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)11 List (java.util.List)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)9 BrickProperties (org.ovirt.engine.core.common.businessentities.gluster.BrickProperties)9 GlusterVolumeRemoveBricksParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeRemoveBricksParameters)7 BrickDetails (org.ovirt.engine.core.common.businessentities.gluster.BrickDetails)7 GlusterVolumeAdvancedDetails (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeAdvancedDetails)7 GlusterVolumeType (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType)7 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)7 Iterator (java.util.Iterator)5