Search in sources :

Example 46 with StorageDomainStatic

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

the class BackendStorageDomainResource method isAttached.

@Override
public Response isAttached(Action action) {
    validateParameters(action, "host.id|name");
    Guid hostId = getHostId(action);
    org.ovirt.engine.core.common.businessentities.StorageDomain storageDomainToAttach = getEntity(org.ovirt.engine.core.common.businessentities.StorageDomain.class, QueryType.GetStorageDomainById, new IdQueryParameters(guid), guid.toString());
    StorageDomainsAndStoragePoolIdQueryParameters parameters = new StorageDomainsAndStoragePoolIdQueryParameters(storageDomainToAttach, null, hostId);
    parameters.setCheckStoragePoolStatus(false);
    List<StorageDomainStatic> attachedStorageDomains = getEntity(List.class, QueryType.GetStorageDomainsWithAttachedStoragePoolGuid, parameters, guid.toString(), true);
    // This is an atypical action, as it doesn't invoke a backend action, but a query. As a result we need to
    // create and populate the returned action object so that it looks like a real action result.
    Action result = new Action();
    result.setIsAttached(!attachedStorageDomains.isEmpty());
    result.setStatus(CreationStatus.COMPLETE.value());
    return Response.ok().entity(result).build();
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) Action(org.ovirt.engine.api.model.Action) StorageDomainsAndStoragePoolIdQueryParameters(org.ovirt.engine.core.common.queries.StorageDomainsAndStoragePoolIdQueryParameters) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Guid(org.ovirt.engine.core.compat.Guid) StorageDomainsAndStoragePoolIdQueryParameters(org.ovirt.engine.core.common.queries.StorageDomainsAndStoragePoolIdQueryParameters)

Example 47 with StorageDomainStatic

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

the class UpdateStoragePoolCommand method validate.

@Override
protected boolean validate() {
    StoragePoolValidator spValidator = createStoragePoolValidator();
    if (!validate(spValidator.exists())) {
        return false;
    }
    // Name related validations
    if (!StringUtils.equals(getOldStoragePool().getName(), getStoragePool().getName()) && !isStoragePoolUnique(getStoragePool().getName())) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_POOL_NAME_ALREADY_EXIST);
    }
    if (!checkStoragePoolNameLengthValid()) {
        return false;
    }
    List<StorageDomainStatic> poolDomains = storageDomainStaticDao.getAllForStoragePool(getStoragePool().getId());
    if (getOldStoragePool().isLocal() && !getStoragePool().isLocal() && poolDomains.stream().anyMatch(sdc -> sdc.getStorageType() == StorageType.LOCALFS)) {
        return failValidation(EngineMessage.ERROR_CANNOT_CHANGE_STORAGE_POOL_TYPE_WITH_LOCAL);
    }
    if (!getOldStoragePool().isLocal() && getStoragePool().isLocal()) {
        List<Cluster> clusters = clusterDao.getAllForStoragePool(getStoragePool().getId());
        if (clusters.size() > 1) {
            return failValidation(EngineMessage.CLUSTER_CANNOT_ADD_MORE_THEN_ONE_HOST_TO_LOCAL_STORAGE);
        }
        List<VDS> hosts = vdsDao.getAllForStoragePool(getStoragePool().getId());
        if (hosts.size() > 1) {
            return failValidation(EngineMessage.VDS_CANNOT_ADD_MORE_THEN_ONE_HOST_TO_LOCAL_STORAGE);
        }
    }
    if (!getOldStoragePool().getCompatibilityVersion().equals(getStoragePool().getCompatibilityVersion())) {
        if (!isStoragePoolVersionSupported()) {
            return failValidation(VersionSupport.getUnsupportedVersionMessage());
        } else // decreasing of compatibility version is allowed under conditions
        if (getStoragePool().getCompatibilityVersion().compareTo(getOldStoragePool().getCompatibilityVersion()) < 0) {
            if (!poolDomains.isEmpty() && !isCompatibilityVersionChangeAllowedForDomains(poolDomains)) {
                return false;
            }
            List<Network> networks = networkDao.getAllForDataCenter(getStoragePoolId());
            for (Network network : networks) {
                NetworkValidator validator = getNetworkValidator(network);
                if (!getManagementNetworkUtil().isManagementNetwork(network.getId()) || !validator.canNetworkCompatibilityBeDecreased()) {
                    return failValidation(EngineMessage.ACTION_TYPE_FAILED_CANNOT_DECREASE_DATA_CENTER_COMPATIBILITY_VERSION);
                }
            }
        } else if (!checkAllClustersLevel()) {
            // Check all clusters has at least the same compatibility version.
            return false;
        }
    }
    return validate(spValidator.isNotLocalfsWithDefaultCluster()) && validate(allMacsInEveryClusterCanBeMigratedToAnotherPool());
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) StringUtils(org.apache.commons.lang.StringUtils) NonTransactiveCommandAttribute(org.ovirt.engine.core.bll.NonTransactiveCommandAttribute) EngineException(org.ovirt.engine.core.common.errors.EngineException) SyncLunsParameters(org.ovirt.engine.core.common.action.SyncLunsParameters) DiskLunMap(org.ovirt.engine.core.common.businessentities.storage.DiskLunMap) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) VdsDao(org.ovirt.engine.core.dao.VdsDao) StoragePoolDao(org.ovirt.engine.core.dao.StoragePoolDao) Version(org.ovirt.engine.core.compat.Version) StorageFormatType(org.ovirt.engine.core.common.businessentities.StorageFormatType) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) ManagementNetworkUtil(org.ovirt.engine.core.bll.network.cluster.ManagementNetworkUtil) NetworkDao(org.ovirt.engine.core.dao.network.NetworkDao) Collectors(java.util.stream.Collectors) VmDao(org.ovirt.engine.core.dao.VmDao) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) ValidationResult(org.ovirt.engine.core.bll.ValidationResult) AuditLogType(org.ovirt.engine.core.common.AuditLogType) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) DiskLunMapDao(org.ovirt.engine.core.dao.DiskLunMapDao) Guid(org.ovirt.engine.core.compat.Guid) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) ArrayList(java.util.ArrayList) StoragePoolManagementParameter(org.ovirt.engine.core.common.action.StoragePoolManagementParameter) Inject(javax.inject.Inject) StorageDomainToPoolRelationValidator(org.ovirt.engine.core.bll.validator.storage.StorageDomainToPoolRelationValidator) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) Network(org.ovirt.engine.core.common.businessentities.network.Network) StorageDomainStaticDao(org.ovirt.engine.core.dao.StorageDomainStaticDao) VersionStorageFormatUtil(org.ovirt.engine.core.common.utils.VersionStorageFormatUtil) NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) VersionSupport(org.ovirt.engine.core.bll.utils.VersionSupport) EngineError(org.ovirt.engine.core.common.errors.EngineError) TransactionScopeOption(org.ovirt.engine.core.compat.TransactionScopeOption) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) MoveMacs(org.ovirt.engine.core.bll.MoveMacs) UpgradeStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.UpgradeStoragePoolVDSCommandParameters) RenamedEntityInfoProvider(org.ovirt.engine.core.bll.RenamedEntityInfoProvider) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) VDS(org.ovirt.engine.core.common.businessentities.VDS) StoragePoolValidator(org.ovirt.engine.core.bll.validator.storage.StoragePoolValidator) NetworkValidator(org.ovirt.engine.core.bll.validator.NetworkValidator) VDS(org.ovirt.engine.core.common.businessentities.VDS) Network(org.ovirt.engine.core.common.businessentities.network.Network) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) List(java.util.List) ArrayList(java.util.ArrayList)

Example 48 with StorageDomainStatic

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

the class InitVdsOnUpCommand method proceedVdsStats.

private Pair<Boolean, List<StorageDomainStatic>> proceedVdsStats(boolean shouldCheckReportedDomains, StoragePool storagePool) {
    Pair<Boolean, List<StorageDomainStatic>> returnValue = new Pair<>(true, null);
    try {
        runVdsCommand(VDSCommandType.GetStats, new VdsIdAndVdsVDSCommandParametersBase(getVds()));
        if (shouldCheckReportedDomains) {
            List<Guid> problematicDomainsIds = fetchDomainsReportedAsProblematic(getVds().getDomains(), storagePool);
            for (Guid domainId : problematicDomainsIds) {
                StorageDomainStatic domainInfo = storageDomainStaticDao.get(domainId);
                log.error("Storage Domain '{}' of pool '{}' is in problem in host '{}'", domainInfo != null ? domainInfo.getStorageName() : domainId, getStoragePool().getName(), getVds().getName());
                if (domainInfo == null || domainInfo.getStorageDomainType().isDataDomain()) {
                    returnValue.setFirst(false);
                    if (returnValue.getSecond() == null) {
                        returnValue.setSecond(new ArrayList<>());
                    }
                    returnValue.getSecond().add(domainInfo);
                }
            }
        }
    } catch (EngineException e) {
        log.error("Could not get Host statistics for Host '{}': {}", getVds().getName(), e.getMessage());
        log.debug("Exception", e);
        returnValue.setFirst(false);
    }
    return returnValue;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) VdsIdAndVdsVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase) EngineException(org.ovirt.engine.core.common.errors.EngineException) List(java.util.List) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 49 with StorageDomainStatic

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

the class InitVdsOnUpCommand method initializeStorage.

private boolean initializeStorage() {
    boolean returnValue = false;
    // connect any storage
    if (getStoragePool() == null || StoragePoolStatus.Uninitialized == getStoragePool().getStatus() || StoragePoolStatus.Maintenance == getStoragePool().getStatus()) {
        returnValue = true;
        connectPoolSucceeded = true;
    } else {
        ConnectHostToStoragePoolServersParameters params = new ConnectHostToStoragePoolServersParameters(getStoragePool(), getVds());
        CommandContext ctx = cloneContext();
        ctx.getExecutionContext().setJobRequired(false);
        runInternalAction(ActionType.ConnectHostToStoragePoolServers, params, ctx);
        EventResult connectResult = connectHostToPool();
        if (connectResult != null) {
            returnValue = connectResult.isSuccess();
            problematicDomains = (List<StorageDomainStatic>) connectResult.getResultData();
        }
        connectPoolSucceeded = returnValue;
    }
    return returnValue;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) ConnectHostToStoragePoolServersParameters(org.ovirt.engine.core.common.action.ConnectHostToStoragePoolServersParameters) EventResult(org.ovirt.engine.core.common.eventqueue.EventResult) CommandContext(org.ovirt.engine.core.bll.context.CommandContext)

Example 50 with StorageDomainStatic

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

the class UpdateVmDiskCommand method validateCanUpdateShareable.

/**
 * Validate whether a disk can be shareable. Disk can be shareable if it is not based on qcow FS,
 * which means it should not be based on a template image with thin provisioning,
 * it also should not contain snapshots and it is not bootable.
 * @return Indication whether the disk can be shared or not.
 */
private boolean validateCanUpdateShareable() {
    if (DiskStorageType.LUN == getOldDisk().getDiskStorageType()) {
        return true;
    }
    // Check if VM is not during snapshot.
    if (!isVmNotInPreviewSnapshot()) {
        return false;
    }
    if (isUpdatedToShareable(getOldDisk(), getNewDisk())) {
        StorageDomainStatic sds = storageDomainStaticDao.get(((DiskImage) getNewDisk()).getStorageIds().get(0));
        if (sds.getStorageType() == StorageType.GLUSTERFS) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_SHAREABLE_DISKS_NOT_SUPPORTED_ON_GLUSTER_DOMAIN);
        }
        List<DiskImage> diskImageList = getDiskImages(getOldDisk().getId());
        // disk and all the other images are the snapshots.
        if ((diskImageList.size() > 1) || !Guid.Empty.equals(((DiskImage) getOldDisk()).getImageTemplateId())) {
            return failValidation(EngineMessage.SHAREABLE_DISK_IS_NOT_SUPPORTED_FOR_DISK);
        }
        if (!isVolumeFormatSupportedForShareable(((DiskImage) getNewDisk()).getVolumeFormat())) {
            return failValidation(EngineMessage.SHAREABLE_DISK_IS_NOT_SUPPORTED_BY_VOLUME_FORMAT);
        }
    } else if (isUpdatedToNonShareable(getOldDisk(), getNewDisk())) {
        if (vmsDiskOrSnapshotAttachedTo.size() > 1) {
            return failValidation(EngineMessage.DISK_IS_ALREADY_SHARED_BETWEEN_VMS);
        }
    }
    return true;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Aggregations

StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)92 Guid (org.ovirt.engine.core.compat.Guid)39 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)35 ArrayList (java.util.ArrayList)33 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)31 Test (org.junit.Test)23 Pair (org.ovirt.engine.core.common.utils.Pair)19 StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)18 StorageDomainType (org.ovirt.engine.core.common.businessentities.StorageDomainType)15 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)15 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)14 List (java.util.List)13 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)13 StorageDomainManagementParameter (org.ovirt.engine.core.common.action.StorageDomainManagementParameter)13 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)13 VDS (org.ovirt.engine.core.common.businessentities.VDS)12 HashSet (java.util.HashSet)11 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)11 ActionType (org.ovirt.engine.core.common.action.ActionType)11 AttachStorageDomainToPoolParameters (org.ovirt.engine.core.common.action.AttachStorageDomainToPoolParameters)10