Search in sources :

Example 71 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class InitVdsOnUpCommand method proceedVdsStats.

private Pair<Boolean, List<StorageDomainStatic>> proceedVdsStats(boolean shouldCheckReportedDomains, StoragePool storagePool) {
    Pair<Boolean, List<StorageDomainStatic>> returnValue = new Pair<>(true, null);
    try {
        runVdsCommand(VDSCommandType.GetStats, new VdsIdAndVdsVDSCommandParametersBase(getVds()));
        if (shouldCheckReportedDomains) {
            List<Guid> problematicDomainsIds = fetchDomainsReportedAsProblematic(getVds().getDomains(), storagePool);
            for (Guid domainId : problematicDomainsIds) {
                StorageDomainStatic domainInfo = storageDomainStaticDao.get(domainId);
                log.error("Storage Domain '{}' of pool '{}' is in problem in host '{}'", domainInfo != null ? domainInfo.getStorageName() : domainId, getStoragePool().getName(), getVds().getName());
                if (domainInfo == null || domainInfo.getStorageDomainType().isDataDomain()) {
                    returnValue.setFirst(false);
                    if (returnValue.getSecond() == null) {
                        returnValue.setSecond(new ArrayList<>());
                    }
                    returnValue.getSecond().add(domainInfo);
                }
            }
        }
    } catch (EngineException e) {
        log.error("Could not get Host statistics for Host '{}': {}", getVds().getName(), e.getMessage());
        log.debug("Exception", e);
        returnValue.setFirst(false);
    }
    return returnValue;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) VdsIdAndVdsVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase) EngineException(org.ovirt.engine.core.common.errors.EngineException) List(java.util.List) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 72 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class AddNetworkCommand method getExclusiveLocks.

@Override
protected Map<String, Pair<String, String>> getExclusiveLocks() {
    final Network network = getNetwork();
    Map<String, Pair<String, String>> locks = new HashMap<>();
    if (getNetworkName() != null) {
        locks.put(getNetworkName(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.NETWORK, EngineMessage.ACTION_TYPE_FAILED_NETWORK_IS_USED));
    }
    if (network.isExternal() && !isInternalExecution()) {
        locks.putAll(networkLocking.getNetworkProviderLock(network.getProvidedBy().getProviderId()));
    }
    return locks;
}
Also used : HashMap(java.util.HashMap) Network(org.ovirt.engine.core.common.businessentities.network.Network) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 73 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class RemoveDiskCommand method createSharedLocksForVmDisk.

private Map<String, Pair<String, String>> createSharedLocksForVmDisk() {
    List<VM> listVms = getVmsForDiskId();
    if (listVms.isEmpty()) {
        return null;
    }
    Map<String, Pair<String, String>> result = new HashMap<>();
    for (VM vm : listVms) {
        result.put(vm.getId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.VM, getDiskIsBeingRemovedLockMessage()));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 74 with Pair

use of org.ovirt.engine.core.common.utils.Pair 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)

Example 75 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class UpdateStorageServerConnectionCommand method getExclusiveLocks.

@Override
protected Map<String, Pair<String, String>> getExclusiveLocks() {
    Map<String, Pair<String, String>> locks = new HashMap<>();
    domains = getStorageDomainsByConnId(getConnection().getId());
    if (!domains.isEmpty()) {
        for (StorageDomain domain : domains) {
            locks.put(domain.getId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.STORAGE, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
        }
    }
    if (getConnection().getStorageType().isFileDomain()) {
        // lock the path to avoid at the same time if some other user tries to
        // add new storage connection to same path or edit another storage server connection to point to same path
        locks.put(getConnection().getConnection(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.STORAGE_CONNECTION, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
    } else {
        // for block domains, locking the target details
        locks.put(getConnection().getConnection() + ";" + getConnection().getIqn() + ";" + getConnection().getPort() + ";" + getConnection().getUserName(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.STORAGE_CONNECTION, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
        // lock lun disks and domains, not VMs , no need to load from db.
        if (getLuns() != null) {
            for (LUNs lun : getLuns()) {
                Guid diskId = lun.getDiskId();
                Guid storageDomainId = lun.getStorageDomainId();
                if (diskId != null) {
                    locks.put(diskId.toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.DISK, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
                }
                if (storageDomainId != null) {
                    locks.put(storageDomainId.toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.STORAGE, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
                }
            }
        }
    }
    // lock connection's id to avoid editing or removing this connection at the same time
    // by another user
    locks.put(getConnection().getId(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.STORAGE_CONNECTION, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
    return locks;
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

Pair (org.ovirt.engine.core.common.utils.Pair)147 ArrayList (java.util.ArrayList)61 Guid (org.ovirt.engine.core.compat.Guid)61 HashMap (java.util.HashMap)30 VDS (org.ovirt.engine.core.common.businessentities.VDS)26 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 Test (org.junit.Test)24 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)19 List (java.util.List)16 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Map (java.util.Map)13 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)13 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 VM (org.ovirt.engine.core.common.businessentities.VM)12 HashSet (java.util.HashSet)10 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)10 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)10 EngineException (org.ovirt.engine.core.common.errors.EngineException)9 Callable (java.util.concurrent.Callable)8 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)8