Search in sources :

Example 1 with IrsBaseVDSCommandParameters

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

the class RunVmCommand method guestToolsVersionTreatment.

/**
 * If vds version greater then vm's and vm not running with cd and there is appropriate RhevAgentTools image -
 * add it to vm as cd.
 */
private String guestToolsVersionTreatment() {
    boolean attachCd = false;
    String selectedToolsVersion = "";
    String selectedToolsClusterVersion = "";
    Guid isoDomainId = getActiveIsoDomainId();
    if (osRepository.isWindows(getVm().getVmOsId()) && null != isoDomainId) {
        // get cluster version of the vm tools
        Version vmToolsClusterVersion = null;
        if (getVm().getHasAgent()) {
            Version clusterVer = getVm().getPartialVersion();
            if (new Version("4.4").equals(clusterVer)) {
                vmToolsClusterVersion = new Version("2.1");
            } else {
                vmToolsClusterVersion = clusterVer;
            }
        }
        // Fetch cached Iso files from active Iso domain.
        List<RepoImage> repoFilesMap = getIsoDomainListSynchronizer().getCachedIsoListByDomainId(isoDomainId, ImageFileType.ISO);
        Version bestClusterVer = null;
        int bestToolVer = 0;
        for (RepoImage map : repoFilesMap) {
            String fileName = StringUtils.defaultString(map.getRepoImageId(), "");
            Matcher matchToolPattern = Pattern.compile(IsoDomainListSynchronizer.REGEX_TOOL_PATTERN).matcher(fileName);
            if (matchToolPattern.find()) {
                // Get cluster version and tool version of Iso tool.
                Version clusterVer = new Version(matchToolPattern.group(IsoDomainListSynchronizer.TOOL_CLUSTER_LEVEL));
                int toolVersion = Integer.parseInt(matchToolPattern.group(IsoDomainListSynchronizer.TOOL_VERSION));
                if (clusterVer.compareTo(getVm().getCompatibilityVersion()) <= 0) {
                    if ((bestClusterVer == null) || (clusterVer.compareTo(bestClusterVer) > 0)) {
                        bestToolVer = toolVersion;
                        bestClusterVer = clusterVer;
                    } else if (clusterVer.equals(bestClusterVer) && toolVersion > bestToolVer) {
                        bestToolVer = toolVersion;
                        bestClusterVer = clusterVer;
                    }
                }
            }
        }
        if (bestClusterVer != null && (vmToolsClusterVersion == null || vmToolsClusterVersion.compareTo(bestClusterVer) < 0 || (vmToolsClusterVersion.equals(bestClusterVer) && getVm().getHasAgent() && getVm().getGuestAgentVersion().getBuild() < bestToolVer))) {
            // Vm has no tools or there are new tools
            selectedToolsVersion = Integer.toString(bestToolVer);
            selectedToolsClusterVersion = bestClusterVer.toString();
            attachCd = true;
        }
    }
    if (attachCd) {
        String rhevToolsPath = String.format("%1$s%2$s_%3$s.iso", IsoDomainListSynchronizer.getGuestToolsSetupIsoPrefix(), selectedToolsClusterVersion, selectedToolsVersion);
        String isoDir = (String) runVdsCommand(VDSCommandType.IsoDirectory, new IrsBaseVDSCommandParameters(getVm().getStoragePoolId())).getReturnValue();
        rhevToolsPath = isoDir + File.separator + rhevToolsPath;
        return rhevToolsPath;
    }
    return null;
}
Also used : IrsBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters) RepoImage(org.ovirt.engine.core.common.businessentities.storage.RepoImage) Version(org.ovirt.engine.core.compat.Version) Matcher(java.util.regex.Matcher) Guid(org.ovirt.engine.core.compat.Guid)

Example 2 with IrsBaseVDSCommandParameters

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

the class DetachStorageDomainFromPoolCommand method detachNonMasterStorageDomain.

private boolean detachNonMasterStorageDomain() {
    log.info(" Detach storage domain: after connect");
    boolean detachSucceeded = detachNonMasterStorageDomainFromHost();
    log.info(" Detach storage domain: after disconnect storage");
    TransactionSupport.executeInNewTransaction(() -> {
        releaseStorageDomainMacPool(getVmsOnlyOnStorageDomain());
        detachStorageDomainWithEntities(getStorageDomain());
        removeStoragePoolIsoMapWithCompensation();
        // when detaching SD for data center, we should remove any attachment to qos, which is part of the old
        // data center
        diskProfileDao.nullifyQosForStorageDomain(getStorageDomain().getId());
        return null;
    });
    log.info(" Detach storage domain: after detach in vds");
    disconnectAllHostsInPool();
    if (detachSucceeded && getStorageDomain().getStorageDomainType() == StorageDomainType.ISO) {
        // reset iso for this pool in vdsBroker cache
        runVdsCommand(VDSCommandType.ResetISOPath, new IrsBaseVDSCommandParameters(getParameters().getStoragePoolId()));
    }
    return detachSucceeded;
}
Also used : IrsBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters)

Example 3 with IrsBaseVDSCommandParameters

use of org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters 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);
}
Also used : IrsBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters) DetachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters) ReconstructMasterParameters(org.ovirt.engine.core.common.action.ReconstructMasterParameters)

Example 4 with IrsBaseVDSCommandParameters

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

the class StorageHandlingCommandBase method handleDestroyStoragePoolCommand.

protected void handleDestroyStoragePoolCommand() {
    try {
        runVdsCommand(VDSCommandType.DestroyStoragePool, new IrsBaseVDSCommandParameters(getStoragePool().getId()));
    } catch (EngineException e) {
        try {
            TransactionSupport.executeInNewTransaction(() -> {
                runVdsCommand(VDSCommandType.SpmStopOnIrs, new SpmStopOnIrsVDSCommandParameters(getStoragePool().getId()));
                return null;
            });
        } catch (Exception e1) {
            log.error("Failed destroy storage pool with id '{}' and after that failed to stop spm: {}", getStoragePoolId(), e1.getMessage());
            log.debug("Exception", e1);
        }
        throw e;
    }
}
Also used : IrsBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters) SpmStopOnIrsVDSCommandParameters(org.ovirt.engine.core.vdsbroker.irsbroker.SpmStopOnIrsVDSCommandParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException) EngineException(org.ovirt.engine.core.common.errors.EngineException) IOException(java.io.IOException)

Example 5 with IrsBaseVDSCommandParameters

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

the class ReconstructMasterDomainCommand method executeCommand.

@Override
protected void executeCommand() {
    boolean reconstructOpSucceeded = reconstructMaster();
    setActionReturnValue(reconstructOpSucceeded);
    connectAndRefreshAllUpHosts(reconstructOpSucceeded);
    if (isLastMaster) {
        getCompensationContext().cleanupCompensationDataAfterSuccessfulCommand();
    }
    setSucceeded(!isLastMaster && reconstructOpSucceeded);
    if (getSucceeded()) {
        runVdsCommand(VDSCommandType.MarkPoolInReconstructMode, new IrsBaseVDSCommandParameters(getStoragePoolId()));
    }
}
Also used : IrsBaseVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters)

Aggregations

IrsBaseVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.IrsBaseVDSCommandParameters)5 IOException (java.io.IOException)1 Matcher (java.util.regex.Matcher)1 ReconstructMasterParameters (org.ovirt.engine.core.common.action.ReconstructMasterParameters)1 RepoImage (org.ovirt.engine.core.common.businessentities.storage.RepoImage)1 EngineException (org.ovirt.engine.core.common.errors.EngineException)1 DetachStorageDomainVDSCommandParameters (org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters)1 Guid (org.ovirt.engine.core.compat.Guid)1 Version (org.ovirt.engine.core.compat.Version)1 SpmStopOnIrsVDSCommandParameters (org.ovirt.engine.core.vdsbroker.irsbroker.SpmStopOnIrsVDSCommandParameters)1