use of org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters 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);
}
}
}
use of org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters in project ovirt-engine by oVirt.
the class ForceRemoveStorageDomainCommand method executeCommand.
@Override
protected void executeCommand() {
if (isAttachedStorageDomain() && hasRunningHostsInPool() && !isLastStorageInPool()) {
try {
// If master and there are more storage domains in the DC try to reconstruct.
if (getStorageDomain().getStorageDomainType() == StorageDomainType.Master) {
ReconstructMasterParameters reconstructMasterParameters = new ReconstructMasterParameters(getStoragePool().getId(), getStorageDomain().getId(), false);
reconstructMasterParameters.setTransactionScopeOption(TransactionScopeOption.RequiresNew);
runInternalAction(ActionType.ReconstructMasterDomain, reconstructMasterParameters);
}
// try to force detach first
DetachStorageDomainVDSCommandParameters detachParameters = new DetachStorageDomainVDSCommandParameters(getStoragePool().getId(), getStorageDomain().getId(), Guid.Empty, -1);
detachParameters.setForce(true);
runVdsCommand(VDSCommandType.DetachStorageDomain, detachParameters);
} catch (RuntimeException ex) {
log.error("Could not force detach storage domain '{}': {}", getStorageDomain().getStorageName(), ex.getMessage());
log.debug("Exception", ex);
}
} else {
log.info("Avoid running host operations like reconstruct/detach on force remove for storage domain '{}'." + "Storage domain attached to pool: '{}'" + "Active Hosts exists in DC: '{}'", getStorageDomain().getStorageName(), isAttachedStorageDomain(), hasRunningHostsInPool());
}
releaseStorageDomainMacPool(getVmsOnlyOnStorageDomain());
storageHelperDirector.getItem(getStorageDomain().getStorageType()).storageDomainRemoved(getStorageDomain().getStorageStaticData());
storageDomainDao.remove(getStorageDomain().getId());
if (isAttachedStorageDomain()) {
// if iso reset path for pool
if (getStorageDomain().getStorageDomainType() == StorageDomainType.ISO) {
// todo: when iso in multiple pools will be implemented, we
// should reset iso path for all related pools
runVdsCommand(VDSCommandType.ResetISOPath, new IrsBaseVDSCommandParameters(getStoragePool().getId()));
}
if (getStorageDomain().getStorageDomainType() == StorageDomainType.Master) {
calcStoragePoolStatusByDomainsStatus();
}
}
setSucceeded(true);
}
Aggregations