use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class AddVmLeaseCommand method endSuccessfully.
@Override
protected void endSuccessfully() {
// it would be nicer to get this as part of the tasks rather
// than initiating another call to the host, this approach is
// easier and backward compatible though
VDSReturnValue retVal = null;
try {
retVal = runVdsCommand(VDSCommandType.GetVmLeaseInfo, new VmLeaseVDSParameters(getParameters().getStoragePoolId(), getParameters().getStorageDomainId(), getParameters().getVmId()));
} catch (EngineException e) {
log.error("Failure in getting lease info for VM {}, message: {}", getParameters().getVmId(), e.getMessage());
}
if (retVal == null || !retVal.getSucceeded()) {
log.error("Failed to get info on the lease of VM {}", getParameters().getVmId());
return;
}
vmDynamicDao.updateVmLeaseInfo(getParameters().getVmId(), (Map<String, String>) retVal.getReturnValue());
if (getParameters().isHotPlugLease()) {
boolean hotPlugSucceeded = false;
try {
hotPlugSucceeded = runVdsCommand(VDSCommandType.HotPlugLease, new LeaseVDSParameters(getParameters().getVdsId(), getParameters().getVmId(), getParameters().getStorageDomainId())).getSucceeded();
} catch (EngineException e) {
log.error("Failure in hot plugging a lease to VM {}, message: {}", getParameters().getVmId(), e.getMessage());
}
if (!hotPlugSucceeded) {
setVmId(getParameters().getVmId());
auditLog(this, AuditLogType.HOT_PLUG_LEASE_FAILED);
getReturnValue().setEndActionTryAgain(false);
setSucceeded(false);
return;
}
}
setSucceeded(true);
}
use of org.ovirt.engine.core.common.errors.EngineException 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.errors.EngineException in project ovirt-engine by oVirt.
the class ReconstructMasterDomainCommand method connectAndRefreshAllUpHosts.
private void connectAndRefreshAllUpHosts(final boolean commandSucceeded) {
if (isLastMaster || !commandSucceeded) {
log.warn("skipping connect and refresh for all hosts, last master '{}', command status '{}'", isLastMaster, commandSucceeded);
return;
}
List<Callable<Void>> tasks = new ArrayList<>();
for (final VDS vds : getAllRunningVdssInPool()) {
tasks.add(() -> {
try {
if (!connectVdsToNewMaster(vds)) {
log.warn("failed to connect vds '{}' to the new master '{}'", vds.getId(), getNewMasterStorageDomainId());
return null;
}
List<StoragePoolIsoMap> storagePoolIsoMap = storagePoolIsoMapDao.getAllForStoragePool(getStoragePool().getId());
try {
runVdsCommand(VDSCommandType.ConnectStoragePool, new ConnectStoragePoolVDSCommandParameters(vds, getStoragePool(), getNewMasterStorageDomainId(), storagePoolIsoMap, true));
} catch (EngineException ex) {
if (EngineError.StoragePoolUnknown == ex.getVdsError().getCode()) {
VDSReturnValue returnVal = runVdsCommand(VDSCommandType.ConnectStoragePool, new ConnectStoragePoolVDSCommandParameters(vds, getStoragePool(), getNewMasterStorageDomainId(), storagePoolIsoMap));
if (!returnVal.getSucceeded()) {
log.error("Post reconstruct actions (connectPool) did not complete on host '{}' in the pool. error {}", vds.getId(), returnVal.getVdsError().getMessage());
}
} else {
log.error("Post reconstruct actions (refreshPool)" + " did not complete on host '{}' in the pool. error {}", vds.getId(), ex.getMessage());
}
}
} catch (Exception e) {
log.error("Post reconstruct actions (connectPool,refreshPool,disconnect storage)" + " did not complete on host '{}' in the pool: {}", vds.getId(), e.getMessage());
log.debug("Exception", e);
}
return null;
});
}
ThreadPoolUtil.invokeAll(tasks);
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class RemoveStoragePoolCommand method regularRemoveStorageDomains.
private boolean regularRemoveStorageDomains(List<StorageDomain> storageDomains) {
boolean retVal = true;
final StorageDomain masterDomain = storageDomains.stream().filter(s -> s.getStorageDomainType() == StorageDomainType.Master).findFirst().orElse(null);
lockStorageDomain(masterDomain);
// destroying a pool is an SPM action. We need to connect all hosts
// to the pool. Later on, during spm election, one of the hosts will
// lock the pool
// and the spm status will be FREE. Only then we can invoke the
// destroy verb.
connectAllHostToPoolAndDomain(masterDomain);
List<VDS> vdss = getAllRunningVdssInPool();
for (StorageDomain storageDomain : storageDomains) {
if (storageDomain.getStorageDomainType() != StorageDomainType.Master) {
if (!removeDomainFromPool(storageDomain, vdss.get(0))) {
log.error("Unable to detach storage domain '{}' '{}'", storageDomain.getStorageName(), storageDomain.getId());
retVal = false;
}
}
}
masterDomainDetachWithDestroyPool(masterDomain);
runSynchronizeOperation(new DisconnectStoragePoolAsyncOperationFactory());
setSucceeded(true);
if (!getStoragePool().isLocal() || !masterDomain.isLocal()) {
for (VDS vds : vdss) {
storageHelperDirector.getItem(masterDomain.getStorageType()).disconnectStorageFromDomainByVdsId(masterDomain, vds.getId());
}
} else {
try {
runVdsCommand(VDSCommandType.FormatStorageDomain, new FormatStorageDomainVDSCommandParameters(vdss.get(0).getId(), masterDomain.getId()));
} catch (EngineException e) {
// Do nothing, exception already printed at logs
}
storageHelperDirector.getItem(masterDomain.getStorageType()).disconnectStorageFromDomainByVdsId(masterDomain, vdss.get(0).getId());
removeDomainFromDb(masterDomain);
}
return retVal;
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class IsoDomainListSynchronizer method refreshReposIfNeeded.
private void refreshReposIfNeeded(Guid storageDomainId, ImageFileType imageType, Boolean forceRefresh) {
MutableLong lastRefreshed = domainsLastRefreshedTime.computeIfAbsent(storageDomainId, k -> new MutableLong(-1));
if (shouldForceRefresh(forceRefresh) || shouldInvalidateCache(lastRefreshed.longValue())) {
synchronized (lastRefreshed) {
// Double check as another thread might have already finished a refresh and released the lock
if (shouldForceRefresh(forceRefresh) || shouldInvalidateCache(lastRefreshed.longValue())) {
boolean refreshSucceeded = refreshRepos(storageDomainId, imageType);
lastRefreshed.setValue(System.currentTimeMillis());
if (!refreshSucceeded) {
throw new EngineException(EngineError.IMAGES_NOT_SUPPORTED_ERROR);
}
}
}
}
}
Aggregations