Search in sources :

Example 26 with GlusterBrickEntity

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

the class VolumeBrickListModel method onAddBricks.

private void onAddBricks() {
    VolumeBrickModel volumeBrickModel = (VolumeBrickModel) getWindow();
    if (volumeBrickModel == null) {
        return;
    }
    if (!volumeBrickModel.validate()) {
        return;
    }
    GlusterVolumeEntity volumeEntity = getEntity();
    if (volumeEntity == null) {
        return;
    }
    ArrayList<GlusterBrickEntity> brickList = new ArrayList<>();
    for (Object model : volumeBrickModel.getBricks().getItems()) {
        GlusterBrickEntity brickEntity = (GlusterBrickEntity) ((EntityModel) model).getEntity();
        brickEntity.setVolumeId(volumeEntity.getId());
        brickList.add(brickEntity);
    }
    volumeBrickModel.setMessage(null);
    if (!validateReplicaStripeCount(volumeEntity, volumeBrickModel)) {
        return;
    }
    if (brickList.size() == 0) {
        volumeBrickModel.setMessage(ConstantsManager.getInstance().getConstants().emptyAddBricksMsg());
        return;
    }
    if (!VolumeBrickModel.validateBrickCount(volumeEntity.getVolumeType(), volumeEntity.getBricks().size() + brickList.size(), volumeBrickModel.getReplicaCountValue(), volumeBrickModel.getStripeCountValue(), false)) {
        volumeBrickModel.setMessage(VolumeBrickModel.getValidationFailedMsg(volumeEntity.getVolumeType(), false));
        return;
    }
    if ((volumeEntity.getVolumeType() == GlusterVolumeType.REPLICATE || volumeEntity.getVolumeType() == GlusterVolumeType.DISTRIBUTED_REPLICATE) && !volumeBrickModel.validateReplicateBricks(volumeEntity.getReplicaCount(), volumeEntity.getBricks())) {
        ConfirmationModel confirmModel = new ConfirmationModel();
        setConfirmWindow(confirmModel);
        confirmModel.setTitle(ConstantsManager.getInstance().getConstants().addBricksReplicateConfirmationTitle());
        confirmModel.setHelpTag(HelpTag.add_bricks_confirmation);
        // $NON-NLS-1$
        confirmModel.setHashName("add_bricks_confirmation");
        confirmModel.setMessage(ConstantsManager.getInstance().getConstants().addBricksToReplicateVolumeFromSameServerMsg());
        // $NON-NLS-1$
        UICommand okCommand = new UICommand("OnAddBricksInternal", this);
        okCommand.setTitle(ConstantsManager.getInstance().getConstants().yes());
        okCommand.setIsDefault(true);
        getConfirmWindow().getCommands().add(okCommand);
        // $NON-NLS-1$
        UICommand cancelCommand = new UICommand("CancelConfirmation", this);
        cancelCommand.setTitle(ConstantsManager.getInstance().getConstants().no());
        cancelCommand.setIsCancel(true);
        getConfirmWindow().getCommands().add(cancelCommand);
    } else {
        onAddBricksInternal();
    }
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) ArrayList(java.util.ArrayList) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)

Example 27 with GlusterBrickEntity

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

the class VolumeBrickModel method validateReplicateBricks.

public boolean validateReplicateBricks(int oldReplicaCount, List<GlusterBrickEntity> existingBricks) {
    int replicaCount = getReplicaCountValue();
    Set<String> servers = new HashSet<>();
    if (replicaCount > oldReplicaCount) {
        int count = 0;
        for (GlusterBrickEntity brick : existingBricks) {
            servers.add(brick.getServerName());
            count++;
        }
        for (Object model : bricks.getItems()) {
            if (count > replicaCount) {
                break;
            }
            GlusterBrickEntity brick = (GlusterBrickEntity) ((EntityModel) model).getEntity();
            if (servers.contains(brick.getServerName())) {
                return false;
            } else {
                servers.add(brick.getServerName());
            }
            count++;
        }
    } else {
        int count = 0;
        for (Object model : bricks.getItems()) {
            count++;
            GlusterBrickEntity brick = (GlusterBrickEntity) ((EntityModel) model).getEntity();
            if (servers.contains(brick.getServerName())) {
                return false;
            } else {
                servers.add(brick.getServerName());
            }
            if (count % replicaCount == 0) {
                servers.clear();
            }
        }
    }
    return true;
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) HashSet(java.util.HashSet)

Example 28 with GlusterBrickEntity

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

the class VolumeBrickModel method addBrick.

private void addBrick() {
    VDS server = servers.getSelectedItem();
    String brickDir = null;
    if (getShowBricksList().getEntity()) {
        brickDir = bricksFromServer.getSelectedItem();
    } else {
        brickDir = getBrickDirectory().getEntity();
    }
    if (server == null) {
        setMessage(ConstantsManager.getInstance().getConstants().emptyServerBrickMsg());
        return;
    }
    if (brickDir == null || brickDir.trim().length() == 0) {
        setMessage(ConstantsManager.getInstance().getConstants().emptyBrickDirectoryMsg());
        return;
    }
    brickDir = brickDir.trim();
    if (!validateBrickDirectory(brickDir)) {
        return;
    }
    GlusterBrickEntity brickEntity = new GlusterBrickEntity();
    brickEntity.setServerId(server.getId());
    brickEntity.setServerName(server.getHostName());
    brickEntity.setBrickDirectory(brickDir);
    EntityModel<GlusterBrickEntity> entityModel = new EntityModel<>(brickEntity);
    List<EntityModel<GlusterBrickEntity>> items = (List<EntityModel<GlusterBrickEntity>>) bricks.getItems();
    if (items == null) {
        items = new ArrayList<>();
    }
    for (EntityModel<GlusterBrickEntity> model : items) {
        GlusterBrickEntity existingBrick = model.getEntity();
        if (existingBrick.getServerId().equals(brickEntity.getServerId()) && existingBrick.getBrickDirectory().equals(brickEntity.getBrickDirectory())) {
            setMessage(ConstantsManager.getInstance().getConstants().duplicateBrickMsg());
            return;
        }
    }
    items.add(entityModel);
    bricks.setItems(null);
    bricks.setItems(items);
    clearBrickDetails();
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) VDS(org.ovirt.engine.core.common.businessentities.VDS) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) ArrayList(java.util.ArrayList) List(java.util.List)

Example 29 with GlusterBrickEntity

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

the class VolumeModel method addBricks.

public void addBricks() {
    if (getWindow() != null || getCluster().getSelectedItem() == null) {
        return;
    }
    final VolumeBrickModel volumeBrickModel = new VolumeBrickModel();
    volumeBrickModel.getVolumeType().setEntity(getTypeList().getSelectedItem());
    volumeBrickModel.getReplicaCount().setEntity(getReplicaCount().getEntity());
    volumeBrickModel.getReplicaCount().setIsChangeable(true);
    volumeBrickModel.getReplicaCount().setIsAvailable(getReplicaCount().getIsAvailable());
    volumeBrickModel.getStripeCount().setEntity(getStripeCount().getEntity());
    volumeBrickModel.getStripeCount().setIsChangeable(true);
    volumeBrickModel.getStripeCount().setIsAvailable(getStripeCount().getIsAvailable());
    Cluster cluster = getCluster().getSelectedItem();
    if (cluster != null) {
        volumeBrickModel.getForce().setIsAvailable(true);
        volumeBrickModel.getForce().setEntity(isForceAddBricks());
        volumeBrickModel.setIsBrickProvisioningSupported();
    }
    setWindow(volumeBrickModel);
    volumeBrickModel.setTitle(ConstantsManager.getInstance().getConstants().addBricksTitle());
    volumeBrickModel.setHelpTag(HelpTag.add_bricks);
    // $NON-NLS-1$
    volumeBrickModel.setHashName("add_bricks");
    AsyncDataProvider.getInstance().getHostListByCluster(volumeBrickModel.asyncQuery(hostList -> {
        Iterator<VDS> iterator = hostList.iterator();
        while (iterator.hasNext()) {
            if (iterator.next().getStatus() != VDSStatus.Up) {
                iterator.remove();
            }
        }
        volumeBrickModel.setHostList(hostList);
    }), getCluster().getSelectedItem().getName());
    // TODO: fetch the mount points to display
    if (getBricks().getItems() != null) {
        volumeBrickModel.getBricks().setItems(getBricks().getItems());
    } else {
        volumeBrickModel.getBricks().setItems(new ArrayList<EntityModel<GlusterBrickEntity>>());
    }
    // $NON-NLS-1$
    UICommand command = UICommand.createDefaultOkUiCommand("OnAddBricks", this);
    volumeBrickModel.getCommands().add(command);
    // $NON-NLS-1$
    volumeBrickModel.getCommands().add(UICommand.createCancelUiCommand("Cancel", this));
}
Also used : NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) GlusterVolumeType(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType) ApplicationMode(org.ovirt.engine.core.common.mode.ApplicationMode) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) VolumeListModel(org.ovirt.engine.ui.uicommonweb.models.volumes.VolumeListModel) Version(org.ovirt.engine.core.compat.Version) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) Model(org.ovirt.engine.ui.uicommonweb.models.Model) Iterator(java.util.Iterator) Linq(org.ovirt.engine.ui.uicommonweb.Linq) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ApplicationModeHelper(org.ovirt.engine.ui.uicommonweb.models.ApplicationModeHelper) List(java.util.List) VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) AsciiNameValidation(org.ovirt.engine.ui.uicommonweb.validation.AsciiNameValidation) LengthValidation(org.ovirt.engine.ui.uicommonweb.validation.LengthValidation) VDS(org.ovirt.engine.core.common.businessentities.VDS) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) Iterator(java.util.Iterator) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand)

Example 30 with GlusterBrickEntity

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

the class VolumeModel method clusterSelectedItemChanged.

private void clusterSelectedItemChanged() {
    setBricks(new ListModel<EntityModel<GlusterBrickEntity>>());
    if (getCluster().getSelectedItem() != null) {
        final Cluster cluster = getCluster().getSelectedItem();
        updateArbiterAvailability();
        updateDefaults();
        AsyncDataProvider.getInstance().isAnyHostUpInCluster(new AsyncQuery<>(returnValue -> {
            // In case the result of previous call is returned after selecting some other cluster
            if (!getCluster().getSelectedItem().getId().equals(cluster.getId())) {
                return;
            }
            if (returnValue) {
                getAddBricksCommand().setIsExecutionAllowed(true);
                setMessage(null);
            } else {
                getAddBricksCommand().setIsExecutionAllowed(false);
                setMessage(ConstantsManager.getInstance().getConstants().volumeEmptyClusterValidationMsg());
            }
        }), cluster.getName());
    } else {
        getAddBricksCommand().setIsExecutionAllowed(false);
        setMessage(null);
    }
}
Also used : NotEmptyValidation(org.ovirt.engine.ui.uicommonweb.validation.NotEmptyValidation) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) HelpTag(org.ovirt.engine.ui.uicommonweb.help.HelpTag) GlusterVolumeType(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType) ApplicationMode(org.ovirt.engine.core.common.mode.ApplicationMode) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) ConstantsManager(org.ovirt.engine.ui.uicompat.ConstantsManager) VolumeListModel(org.ovirt.engine.ui.uicommonweb.models.volumes.VolumeListModel) Version(org.ovirt.engine.core.compat.Version) AsyncDataProvider(org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider) Model(org.ovirt.engine.ui.uicommonweb.models.Model) Iterator(java.util.Iterator) Linq(org.ovirt.engine.ui.uicommonweb.Linq) IValidation(org.ovirt.engine.ui.uicommonweb.validation.IValidation) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ListModel(org.ovirt.engine.ui.uicommonweb.models.ListModel) ApplicationModeHelper(org.ovirt.engine.ui.uicommonweb.models.ApplicationModeHelper) List(java.util.List) VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) AsciiNameValidation(org.ovirt.engine.ui.uicommonweb.validation.AsciiNameValidation) LengthValidation(org.ovirt.engine.ui.uicommonweb.validation.LengthValidation) VDS(org.ovirt.engine.core.common.businessentities.VDS) PropertyChangedEventArgs(org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) Cluster(org.ovirt.engine.core.common.businessentities.Cluster)

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