use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStoragePoolCommand method proccessDomainsForOvfUpdate.
protected void proccessDomainsForOvfUpdate(StoragePool pool) {
List<StorageDomain> domainsInPool = storageDomainDao.getAllForStoragePool(pool.getId());
for (StorageDomain domain : domainsInPool) {
if (!domain.getStorageDomainType().isDataDomain() || (domain.getStatus() != StorageDomainStatus.Active && getParameters().getStorageDomainId() != null && !domain.getId().equals(getParameters().getStorageDomainId()))) {
continue;
}
activeDataDomainsIds.add(domain.getId());
Integer ovfStoresCountForDomain = Config.<Integer>getValue(ConfigValues.StorageDomainOvfStoreCount);
List<StorageDomainOvfInfo> storageDomainOvfInfos = storageDomainOvfInfoDao.getAllForDomain(domain.getId());
if (storageDomainOvfInfos.size() < ovfStoresCountForDomain) {
proccessedDomains.add(domain.getId());
continue;
}
for (StorageDomainOvfInfo storageDomainOvfInfo : storageDomainOvfInfos) {
if (storageDomainOvfInfo.getStatus() == StorageDomainOvfInfoStatus.OUTDATED) {
proccessedDomains.add(storageDomainOvfInfo.getStorageDomainId());
break;
}
}
}
}
use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.
the class RemoveStorageDomainCommand method validate.
@Override
protected boolean validate() {
if (!super.validate()) {
return false;
}
StorageDomain dom = getStorageDomain();
if (dom == null) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_EXIST);
}
VDS vds = getVds();
boolean localFs = isLocalFs(dom);
if (vds == null) {
if (localFs) {
if (!initializeVds()) {
return false;
}
} else {
return failValidation(EngineMessage.CANNOT_REMOVE_STORAGE_DOMAIN_INVALID_HOST_ID);
}
} else if (vds.getStatus() != VDSStatus.Up) {
return failValidation(EngineMessage.CANNOT_REMOVE_STORAGE_DOMAIN_HOST_NOT_UP, String.format("$%1$s %2$s", "hostName", vds.getName()));
}
StorageDomainToPoolRelationValidator domainPoolValidator = createDomainToPoolValidator(dom);
if (!checkStorageDomain()) {
return false;
}
if (!localFs && !validate(domainPoolValidator.isStorageDomainNotInAnyPool())) {
return false;
}
if (localFs && isDomainAttached(dom) && !canDetachDomain(getParameters().getDestroyingPool())) {
return false;
}
if (getParameters().getDoFormat() && !localFs && isStorageDomainAttached(dom)) {
return failValidation(EngineMessage.ACTION_TYPE_FAILED_FORMAT_STORAGE_DOMAIN_WITH_ATTACHED_DATA_DOMAIN);
}
if (dom.getStorageType().isOpenStackDomain()) {
return failValidation(EngineMessage.ERROR_CANNOT_MANAGE_STORAGE_DOMAIN);
}
return true;
}
use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.
the class StorageDomainCommandBase method updateStorageDomainDynamicFromIrs.
protected void updateStorageDomainDynamicFromIrs() {
final StorageDomain sd = (StorageDomain) runVdsCommand(VDSCommandType.GetStorageDomainStats, new GetStorageDomainStatsVDSCommandParameters(getVds().getId(), getStorageDomain().getId())).getReturnValue();
TransactionSupport.executeInNewTransaction(() -> {
getCompensationContext().snapshotEntity(getStorageDomain().getStorageDynamicData());
storageDomainDynamicDao.update(sd.getStorageDynamicData());
getCompensationContext().stateChanged();
return null;
});
}
use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.
the class AddStoragePoolWithStoragesCommand method executeCommand.
@Override
protected void executeCommand() {
if (updateStorageDomainsInDb()) {
// setting storage pool status to maintenance
StoragePool storagePool = getStoragePool();
getCompensationContext().snapshotEntity(storagePool);
TransactionSupport.executeInNewTransaction(() -> {
getStoragePool().setStatus(StoragePoolStatus.Maintenance);
getStoragePool().setStoragePoolFormatType(masterStorageDomain.getStorageFormat());
storagePoolDao.update(getStoragePool());
getCompensationContext().stateChanged();
StoragePoolStatusHandler.poolStatusChanged(getStoragePool().getId(), getStoragePool().getStatus());
return null;
});
// Following code performs only read operations, therefore no need for new transaction
boolean result = false;
// Once we create a storage pool with multiple hosts, the engine should connect all
// the hosts in the storage pool,
// since the engine picks a random host to fetch all the unregistered disks.
boolean isStoragePoolCreated = false;
retVal = null;
for (VDS vds : getAllRunningVdssInPool()) {
setVds(vds);
for (Guid storageDomainId : getParameters().getStorages()) {
// now the domain should have the mapping
// with the pool in db
StorageDomain storageDomain = storageDomainDao.getForStoragePool(storageDomainId, getStoragePool().getId());
storageHelperDirector.getItem(storageDomain.getStorageType()).connectStorageToDomainByVdsId(storageDomain, getVds().getId());
}
if (!isStoragePoolCreated) {
// but didn't throw exception
if (!cleanDirtyMetaDataIfNeeded()) {
result = false;
} else {
retVal = addStoragePoolInIrs();
if (!retVal.getSucceeded() && retVal.getVdsError().getCode() == EngineError.StorageDomainAccessError) {
log.warn("Error creating storage pool on vds '{}' - continuing", vds.getName());
continue;
}
result = retVal.getSucceeded();
}
isStoragePoolCreated = true;
}
}
setSucceeded(result);
if (!result) {
if (retVal != null && retVal.getVdsError().getCode() != null) {
throw new EngineException(retVal.getVdsError().getCode(), retVal.getVdsError().getMessage());
} else {
// command
throw new EngineException(EngineError.ENGINE_ERROR_CREATING_STORAGE_POOL);
}
}
registerOvfStoreDisks();
}
// Create pool phase completed, no rollback is needed here, so compensation information needs to be cleared!
TransactionSupport.executeInNewTransaction(() -> {
getCompensationContext().cleanupCompensationDataAfterSuccessfulCommand();
return null;
});
freeLock();
// if create succeeded activate
if (getSucceeded()) {
activateStorageDomains();
}
}
use of org.ovirt.engine.core.common.businessentities.StorageDomain in project ovirt-engine by oVirt.
the class AddStoragePoolWithStoragesCommand method updateStorageDomainsInDb.
private boolean updateStorageDomainsInDb() {
boolean result = TransactionSupport.executeInNewTransaction(() -> {
for (Guid storageDomainId : getParameters().getStorages()) {
StorageDomain storageDomain = storageDomainDao.get(storageDomainId);
if (storageDomain != null) {
StoragePoolIsoMap mapFromDB = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(storageDomain.getId(), getStoragePool().getId()));
boolean existingInDb = mapFromDB != null;
if (existingInDb) {
getCompensationContext().snapshotEntity(mapFromDB);
}
final StorageDomainStatic staticDomain = storageDomain.getStorageStaticData();
boolean staticDomainChanged = false;
StorageFormatType requiredFormatType = VersionStorageFormatUtil.getForVersion(getStoragePool().getCompatibilityVersion());
if (staticDomain.getStorageFormat().compareTo(requiredFormatType) < 0) {
if (!staticDomainChanged) {
getCompensationContext().snapshotEntity(staticDomain);
}
staticDomain.setStorageFormat(requiredFormatType);
staticDomainChanged = true;
}
storageDomain.setStoragePoolId(getStoragePool().getId());
if (masterStorageDomain == null && storageDomain.getStorageDomainType() == StorageDomainType.Data) {
if (!staticDomainChanged) {
getCompensationContext().snapshotEntity(staticDomain);
}
storageDomain.setStorageDomainType(StorageDomainType.Master);
staticDomainChanged = true;
masterStorageDomain = storageDomain;
// The update of storage pool should be without compensation,
// this is why we run it in a different SUPRESS transaction.
updateStoragePoolMasterDomainVersionInDiffTransaction();
}
if (staticDomainChanged) {
storageDomainStaticDao.update(staticDomain);
}
storageDomain.setStatus(StorageDomainStatus.Locked);
if (existingInDb) {
storagePoolIsoMapDao.update(storageDomain.getStoragePoolIsoMapData());
} else {
storagePoolIsoMapDao.save(storageDomain.getStoragePoolIsoMapData());
getCompensationContext().snapshotNewEntity(storageDomain.getStoragePoolIsoMapData());
}
} else {
return false;
}
}
getCompensationContext().stateChanged();
return true;
});
return result && masterStorageDomain != null;
}
Aggregations