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;
}
}
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;
}
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);
}
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);
}
}
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);
}
}
}
Aggregations