Search in sources :

Example 11 with EngineException

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);
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) LeaseVDSParameters(org.ovirt.engine.core.common.vdscommands.LeaseVDSParameters) VmLeaseVDSParameters(org.ovirt.engine.core.common.vdscommands.VmLeaseVDSParameters) VmLeaseVDSParameters(org.ovirt.engine.core.common.vdscommands.VmLeaseVDSParameters) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 12 with EngineException

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();
    }
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VDS(org.ovirt.engine.core.common.businessentities.VDS) EngineException(org.ovirt.engine.core.common.errors.EngineException) Guid(org.ovirt.engine.core.compat.Guid)

Example 13 with EngineException

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);
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) ConnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.ConnectStoragePoolVDSCommandParameters) Callable(java.util.concurrent.Callable) EngineException(org.ovirt.engine.core.common.errors.EngineException) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 14 with EngineException

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;
}
Also used : FormatStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.FormatStorageDomainVDSCommandParameters) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VDS(org.ovirt.engine.core.common.businessentities.VDS) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 15 with EngineException

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);
                }
            }
        }
    }
}
Also used : MutableLong(org.apache.commons.lang.mutable.MutableLong) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Aggregations

EngineException (org.ovirt.engine.core.common.errors.EngineException)107 Guid (org.ovirt.engine.core.compat.Guid)30 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)25 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)18 ArrayList (java.util.ArrayList)17 VDS (org.ovirt.engine.core.common.businessentities.VDS)11 HashMap (java.util.HashMap)7 Pair (org.ovirt.engine.core.common.utils.Pair)7 HashSet (java.util.HashSet)6 List (java.util.List)6 Callable (java.util.concurrent.Callable)6 Snapshot (org.ovirt.engine.core.common.businessentities.Snapshot)6 IOException (java.io.IOException)5 EntityInfo (org.ovirt.engine.core.common.asynctasks.EntityInfo)5 Map (java.util.Map)4 PersistentHostSetupNetworksParameters (org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters)4 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)4 Set (java.util.Set)3 VdsActionParameters (org.ovirt.engine.core.common.action.VdsActionParameters)3