Search in sources :

Example 1 with HSMGetStorageDomainInfoVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters in project ovirt-engine by oVirt.

the class GetUnregisteredBlockStorageDomainsQuery method getStorageDomainById.

/**
 * Retrieve a storage domain using a specified storage domain ID.
 *
 * @param storageDomainId the domain's ID
 * @return the storage domain
 */
@SuppressWarnings("unchecked")
protected StorageDomain getStorageDomainById(Guid storageDomainId) {
    VDSReturnValue returnValue;
    try {
        returnValue = executeHSMGetStorageDomainInfo(new HSMGetStorageDomainInfoVDSCommandParameters(getParameters().getVdsId(), storageDomainId));
    } catch (RuntimeException e) {
        log.error("Could not get info for storage domain ID: '{}': {}", storageDomainId, e.getMessage());
        log.debug("Exception", e);
        return null;
    }
    Pair<StorageDomainStatic, SANState> result = (Pair<StorageDomainStatic, SANState>) returnValue.getReturnValue();
    StorageDomainStatic storageDomainStatic = result.getFirst();
    storageDomainStatic.setStorageType(getParameters().getStorageType());
    StorageDomain storageDomain = new StorageDomain();
    storageDomain.setStorageStaticData(storageDomainStatic);
    return storageDomain;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) SANState(org.ovirt.engine.core.common.businessentities.SANState) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 2 with HSMGetStorageDomainInfoVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters in project ovirt-engine by oVirt.

the class AddExistingFileStorageDomainCommand method checkExistingStorageDomain.

protected boolean checkExistingStorageDomain() {
    if (storageDomainStaticDao.get(getStorageDomain().getId()) != null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_ALREADY_EXIST);
    }
    Pair<StorageDomainStatic, Guid> domainFromIrs = executeHSMGetStorageDomainInfo(new HSMGetStorageDomainInfoVDSCommandParameters(getVdsId(), getStorageDomain().getId()));
    if (domainFromIrs == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST);
    }
    if (!concreteCheckExistingStorageDomain(domainFromIrs)) {
        return false;
    }
    initStorageDomainProperties(domainFromIrs);
    return true;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid)

Example 3 with HSMGetStorageDomainInfoVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters in project ovirt-engine by oVirt.

the class AttachStorageDomainToPoolCommand method executeCommand.

@Override
protected void executeCommand() {
    if (isCinderStorageDomain()) {
        handleCinderDomain();
        return;
    }
    if (getStoragePool().getStatus() == StoragePoolStatus.Uninitialized) {
        StoragePoolWithStoragesParameter parameters = new StoragePoolWithStoragesParameter(getStoragePool(), Collections.singletonList(getStorageDomain().getId()), getParameters().getSessionId());
        parameters.setIsInternal(true);
        parameters.setTransactionScopeOption(TransactionScopeOption.Suppress);
        ActionReturnValue returnValue = runInternalAction(ActionType.AddStoragePoolWithStorages, parameters, getContext().clone().withoutCompensationContext());
        setSucceeded(returnValue.getSucceeded());
        if (!returnValue.getSucceeded()) {
            getReturnValue().setFault(returnValue.getFault());
        }
    } else {
        map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getParameters().getStoragePoolId()));
        if (map == null) {
            executeInNewTransaction(() -> {
                map = new StoragePoolIsoMap(getStorageDomain().getId(), getParameters().getStoragePoolId(), StorageDomainStatus.Locked);
                storagePoolIsoMapDao.save(map);
                getCompensationContext().snapshotNewEntity(map);
                getCompensationContext().stateChanged();
                return null;
            });
            List<Pair<Guid, Boolean>> hostsConnectionResults = connectHostsInUpToDomainStorageServer();
            if (isAllHostConnectionFailed(hostsConnectionResults)) {
                log.error("Cannot connect storage connection server, aborting attach storage domain operation.");
                setSucceeded(false);
                return;
            }
            // Forcibly detach only data storage domains.
            if (getStorageDomain().getStorageDomainType() == StorageDomainType.Data) {
                @SuppressWarnings("unchecked") Pair<StorageDomainStatic, Guid> domainFromIrs = (Pair<StorageDomainStatic, Guid>) runVdsCommand(VDSCommandType.HSMGetStorageDomainInfo, new HSMGetStorageDomainInfoVDSCommandParameters(getVdsId(), getParameters().getStorageDomainId())).getReturnValue();
                // If the storage domain is already related to another Storage Pool, detach it by force.
                Guid storagePoolId = domainFromIrs.getSecond();
                if (storagePoolId != null) {
                    // Master domain version is not relevant since force remove at
                    // DetachStorageDomainVdsCommand does not use it.
                    // Storage pool id can be empty
                    DetachStorageDomainVDSCommandParameters detachParams = new DetachStorageDomainVDSCommandParameters(getStoragePoolIdFromVds(), getParameters().getStorageDomainId(), Guid.Empty, 0);
                    detachParams.setForce(true);
                    detachParams.setDetachFromOldStoragePool(true);
                    try {
                        runVdsCommand(VDSCommandType.DetachStorageDomain, detachParams);
                    } catch (EngineException e) {
                        log.warn("Detaching Storage Domain '{}' from it's previous storage pool '{}'" + " has failed. The meta data of the Storage Domain might still" + " indicate that it is attached to a different Storage Pool.", getParameters().getStorageDomainId(), Guid.Empty, 0);
                        throw e;
                    }
                }
                if (diskProfileDao.getAllForStorageDomain(getStorageDomain().getId()).isEmpty()) {
                    createDefaultDiskProfile();
                }
            }
            runVdsCommand(VDSCommandType.AttachStorageDomain, new AttachStorageDomainVDSCommandParameters(getParameters().getStoragePoolId(), getParameters().getStorageDomainId()));
            final List<OvfEntityData> unregisteredEntitiesFromOvfDisk = new ArrayList<>();
            if (getStorageDomain().getStorageDomainType().isDataDomain()) {
                List<OvfEntityData> returnValueFromStorageOvfDisk = getEntitiesFromStorageOvfDisk(getParameters().getStorageDomainId(), getStoragePoolIdFromVds());
                unregisteredEntitiesFromOvfDisk.addAll(returnValueFromStorageOvfDisk);
            }
            List<DiskImage> ovfStoreDiskImages = getAllOVFDisks(getParameters().getStorageDomainId(), getStoragePoolIdFromVds());
            executeInNewTransaction(() -> {
                final StorageDomainType sdType = getStorageDomain().getStorageDomainType();
                map.setStatus(StorageDomainStatus.Maintenance);
                storagePoolIsoMapDao.updateStatus(map.getId(), map.getStatus());
                if (sdType == StorageDomainType.Master) {
                    calcStoragePoolStatusByDomainsStatus();
                }
                if (getStorageDomain().getStorageDomainType().isDataDomain()) {
                    registerAllOvfDisks(ovfStoreDiskImages, getParameters().getStorageDomainId());
                    // Update unregistered entities
                    for (OvfEntityData ovf : unregisteredEntitiesFromOvfDisk) {
                        unregisteredOVFDataDao.removeEntity(ovf.getEntityId(), getParameters().getStorageDomainId());
                        unregisteredOVFDataDao.saveOVFData(ovf);
                        log.info("Adding OVF data of entity id '{}' and entity name '{}'", ovf.getEntityId(), ovf.getEntityName());
                    }
                    initUnregisteredDisksToDB(getParameters().getStorageDomainId());
                }
                // upgrade the domain format to the storage pool format
                updateStorageDomainFormatIfNeeded(getStorageDomain());
                return null;
            });
            if (getParameters().getActivate()) {
                attemptToActivateDomain();
            }
            setSucceeded(true);
        }
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) AttachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.AttachStorageDomainVDSCommandParameters) DetachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) EngineException(org.ovirt.engine.core.common.errors.EngineException) ArrayList(java.util.ArrayList) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolWithStoragesParameter(org.ovirt.engine.core.common.action.StoragePoolWithStoragesParameter) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 4 with HSMGetStorageDomainInfoVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters in project ovirt-engine by oVirt.

the class GetExistingStorageDomainListQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    ArrayList<StorageDomain> returnValue = new ArrayList<>();
    VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.HSMGetStorageDomainsList, new HSMGetStorageDomainsListVDSCommandParameters(getParameters().getId(), Guid.Empty, null, getParameters().getStorageDomainType(), getParameters().getPath()));
    if (vdsReturnValue.getSucceeded()) {
        ArrayList<Guid> guidsFromIrs = (ArrayList<Guid>) vdsReturnValue.getReturnValue();
        HashSet<Guid> guidsFromDb = new HashSet<>();
        if (guidsFromIrs.size() > 0) {
            List<StorageDomain> domainsInDb = storageDomainDao.getAll();
            for (StorageDomain domain : domainsInDb) {
                guidsFromDb.add(domain.getId());
            }
            for (Guid domainId : guidsFromIrs) {
                if (!guidsFromDb.contains(domainId)) {
                    Pair<StorageDomainStatic, Guid> domainFromIrs = (Pair<StorageDomainStatic, Guid>) runVdsCommand(VDSCommandType.HSMGetStorageDomainInfo, new HSMGetStorageDomainInfoVDSCommandParameters(getParameters().getId(), domainId)).getReturnValue();
                    StorageDomain domain = new StorageDomain();
                    domain.setStorageStaticData(domainFromIrs.getFirst());
                    domain.setStoragePoolId(domainFromIrs.getSecond());
                    if (getParameters().getStorageFormatType() == null || getParameters().getStorageFormatType() == domain.getStorageFormat()) {
                        if (getParameters().getStorageType() != null && domain.getStorageType().getValue() != getParameters().getStorageType().getValue()) {
                            log.warn("The storage type of domain {} has been changed from {} to {}", domain.getStorageName(), domain.getStorageType().toString(), getParameters().getStorageType().toString());
                            domain.setStorageType(getParameters().getStorageType());
                        }
                        returnValue.add(domain);
                    }
                }
            }
        }
        getQueryReturnValue().setReturnValue(returnValue);
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) ArrayList(java.util.ArrayList) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) HSMGetStorageDomainsListVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainsListVDSCommandParameters) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HashSet(java.util.HashSet) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 5 with HSMGetStorageDomainInfoVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters in project ovirt-engine by oVirt.

the class GetStorageDomainsWithAttachedStoragePoolGuidQuery method getAttachedStorageDomains.

protected List<StorageDomainStatic> getAttachedStorageDomains(List<StorageDomain> storageDomains) {
    VDSReturnValue vdsReturnValue = null;
    List<StorageDomainStatic> storageDomainsWithAttachedStoragePoolId = new ArrayList<>();
    // another Storage Pool
    for (StorageDomain storageDomain : storageDomains) {
        try {
            vdsReturnValue = runVdsCommand(VDSCommandType.HSMGetStorageDomainInfo, new HSMGetStorageDomainInfoVDSCommandParameters(getVdsId(), storageDomain.getId()));
        } catch (RuntimeException e) {
            logErrorMessage(storageDomain);
            continue;
        }
        if (!vdsReturnValue.getSucceeded()) {
            logErrorMessage(storageDomain);
            continue;
        }
        Pair<StorageDomainStatic, Guid> domainFromIrs = (Pair<StorageDomainStatic, Guid>) vdsReturnValue.getReturnValue();
        if (domainFromIrs.getSecond() != null) {
            storageDomainsWithAttachedStoragePoolId.add(domainFromIrs.getFirst());
        }
    }
    return storageDomainsWithAttachedStoragePoolId;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) ArrayList(java.util.ArrayList) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)7 HSMGetStorageDomainInfoVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters)7 Pair (org.ovirt.engine.core.common.utils.Pair)6 Guid (org.ovirt.engine.core.compat.Guid)5 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)4 ArrayList (java.util.ArrayList)3 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)3 HashSet (java.util.HashSet)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 StoragePoolWithStoragesParameter (org.ovirt.engine.core.common.action.StoragePoolWithStoragesParameter)1 OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)1 SANState (org.ovirt.engine.core.common.businessentities.SANState)1 StorageDomainType (org.ovirt.engine.core.common.businessentities.StorageDomainType)1 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)1 StoragePoolIsoMapId (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId)1 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 AttachStorageDomainVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.AttachStorageDomainVDSCommandParameters)1 DetachStorageDomainVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters)1 HSMGetStorageDomainsListVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainsListVDSCommandParameters)1