Search in sources :

Example 56 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class InitVdsOnUpCommand method runConnectHostToPoolEvent.

private EventResult runConnectHostToPoolEvent(final Guid storagePoolId, final VDS vds) {
    EventResult result = new EventResult(true, EventType.VDSCONNECTTOPOOL);
    StoragePool storagePool = storagePoolDao.get(storagePoolId);
    StorageDomain masterDomain = storageDomainDao.getStorageDomains(storagePoolId, StorageDomainType.Master).get(0);
    List<StoragePoolIsoMap> storagePoolIsoMap = storagePoolIsoMapDao.getAllForStoragePool(storagePoolId);
    boolean masterDomainInactiveOrUnknown = masterDomain.getStatus() == StorageDomainStatus.Inactive || masterDomain.getStatus() == StorageDomainStatus.Unknown;
    VDSError error = null;
    try {
        VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.ConnectStoragePool, new ConnectStoragePoolVDSCommandParameters(vds, storagePool, masterDomain.getId(), storagePoolIsoMap));
        if (!vdsReturnValue.getSucceeded()) {
            error = vdsReturnValue.getVdsError();
        }
    } catch (EngineException e) {
        error = e.getVdsError();
    }
    if (error != null) {
        if (error.getCode() != EngineError.CannotConnectMultiplePools && masterDomainInactiveOrUnknown) {
            log.info("Could not connect host '{}' to pool '{}', as the master domain is in inactive/unknown" + " status - not failing the operation", vds.getName(), storagePool.getName());
        } else {
            log.error("Could not connect host '{}' to pool '{}': {}", vds.getName(), storagePool.getName(), error.getMessage());
            result.setSuccess(false);
        }
    }
    if (result.isSuccess()) {
        Pair<Boolean, List<StorageDomainStatic>> vdsStatsResults = proceedVdsStats(!masterDomainInactiveOrUnknown, storagePool);
        result.setSuccess(vdsStatsResults.getFirst());
        if (!result.isSuccess()) {
            result.setResultData(vdsStatsResults.getSecond());
            auditLogDirector.log(this, AuditLogType.VDS_STORAGE_VDS_STATS_FAILED);
        }
    }
    return result;
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) EngineException(org.ovirt.engine.core.common.errors.EngineException) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) EventResult(org.ovirt.engine.core.common.eventqueue.EventResult) VDSError(org.ovirt.engine.core.common.errors.VDSError) List(java.util.List) ArrayList(java.util.ArrayList) ConnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.ConnectStoragePoolVDSCommandParameters)

Example 57 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class RemoveNetworkParametersBuilder method buildParameters.

public ArrayList<ActionParametersBase> buildParameters(Network network, List<VdsNetworkInterface> labeledNics) {
    ArrayList<ActionParametersBase> parameters = new ArrayList<>();
    if (managementNetworkUtil.isManagementNetwork(network.getId())) {
        return parameters;
    }
    for (VdsNetworkInterface nic : labeledNics) {
        PersistentHostSetupNetworksParameters setupNetworkParams = createHostSetupNetworksParameters(nic.getVdsId());
        setupNetworkParams.setNetworkNames(network.getName());
        Map<String, VdsNetworkInterface> nicByNetworkName = NetworkUtils.hostInterfacesByNetworkName(getNics(nic.getVdsId()));
        VdsNetworkInterface nicToConfigure = getNicToConfigure(getNics(nic.getVdsId()), nic.getId());
        if (nicToConfigure == null) {
            throw new EngineException(EngineError.LABELED_NETWORK_INTERFACE_NOT_FOUND);
        }
        NetworkAttachment networkAttachment = getNetworkIdToAttachmentMap(nic.getVdsId()).get(network.getId());
        if (networkAttachment != null) {
            if (networkAttachment.getNicId().equals(nicToConfigure.getId())) {
                setupNetworkParams.getRemovedNetworkAttachments().add(networkAttachment.getId());
            }
        } else {
            VdsNetworkInterface nicWithNetwork = nicByNetworkName.get(network.getName());
            if (nicWithNetwork != null && NetworkCommonUtils.stripVlan(nicWithNetwork).equals(nic.getName())) {
                setupNetworkParams.getRemovedUnmanagedNetworks().add(network.getName());
            }
        }
        parameters.add(setupNetworkParams);
    }
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) NetworkAttachment(org.ovirt.engine.core.common.businessentities.network.NetworkAttachment)

Example 58 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class AddNetworksByLabelParametersBuilder method buildParameters.

/**
 * Adds a list of labeled networks to a host
 */
public PersistentHostSetupNetworksParameters buildParameters(Guid hostId, List<Network> labeledNetworks, Map<String, VdsNetworkInterface> nicsByLabel) {
    PersistentHostSetupNetworksParameters parameters = createHostSetupNetworksParameters(hostId);
    Set<Network> networksToAdd = getNetworksToConfigure(getNics(hostId), labeledNetworks);
    for (Network network : networksToAdd) {
        VdsNetworkInterface labeledNic = nicsByLabel.get(network.getLabel());
        VdsNetworkInterface nicToConfigure = getNicToConfigure(getNics(hostId), labeledNic.getId());
        if (nicToConfigure == null) {
            throw new EngineException(EngineError.LABELED_NETWORK_INTERFACE_NOT_FOUND);
        }
        // configure the network on the nic
        addAttachmentToParameters(nicToConfigure, network, parameters);
    }
    parameters.setNetworkNames(networksToAdd.stream().map(Network::getName).collect(Collectors.joining(", ")));
    return parameters;
}
Also used : PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) Network(org.ovirt.engine.core.common.businessentities.network.Network) EngineException(org.ovirt.engine.core.common.errors.EngineException) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 59 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class HostedEngineConfigFetcher method downloadDisk.

private byte[] downloadDisk(Guid spId, Guid sdId, DiskImage diskImage) {
    long downloadSize = Config.<Integer>getValue(ConfigValues.HostedEngineConfigDiskSizeInBytes);
    log.info("Found the HE configuration disk. Downloading the content in size of {} bytes", downloadSize);
    ActionReturnValue returnValue = backend.runInternalAction(ActionType.RetrieveImageData, new RetrieveImageDataParameters(spId, sdId, diskImage.getId(), diskImage.getImageId(), downloadSize));
    if (returnValue.getSucceeded()) {
        return (byte[]) returnValue.getActionReturnValue();
    } else {
        throw new EngineException(EngineError.ENGINE, "Failed to download the HE configuration disk");
    }
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineException(org.ovirt.engine.core.common.errors.EngineException) RetrieveImageDataParameters(org.ovirt.engine.core.bll.RetrieveImageDataParameters)

Example 60 with EngineException

use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.

the class SyncMacsOfDbNicsWithSnapshot method reallocateMacsWhichCouldntBeAddedToMacPool.

private void reallocateMacsWhichCouldntBeAddedToMacPool(List<String> macsFailedToBeAdded, List<? extends NetworkInterface> snapshotedNics) {
    if (macsFailedToBeAdded.isEmpty()) {
        return;
    }
    // not to ruin original for error reporting.
    List<String> macsFailedToBeAddedCopy = new ArrayList<>(macsFailedToBeAdded);
    try {
        List<Pair<String, String>> macReplacements = new ArrayList<>();
        for (NetworkInterface vmInterface : snapshotedNics) {
            String originalMacAddress = vmInterface.getMacAddress();
            if (macsFailedToBeAddedCopy.contains(originalMacAddress)) {
                macsFailedToBeAddedCopy.remove(originalMacAddress);
                String replacingMac = macPool.allocateNewMac();
                vmInterface.setMacAddress(replacingMac);
                macReplacements.add(new Pair<>(originalMacAddress, replacingMac));
            }
        }
        auditLogPerformedReplacements(macReplacements);
    } catch (EngineException ex) {
        if (EngineError.MAC_POOL_NO_MACS_LEFT.equals(ex.getErrorCode())) {
            auditLogImpossibilityToReplaceDuplicateMacs(macsFailedToBeAdded);
        }
        throw ex;
    }
}
Also used : ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) NetworkInterface(org.ovirt.engine.core.common.businessentities.network.NetworkInterface) Pair(org.ovirt.engine.core.common.utils.Pair)

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