Search in sources :

Example 96 with Pair

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

the class StorageHandlingCommandBase method getLatestOVFDisk.

/**
 * Returns the best match for OVF disk from all the disks. If no OVF disk was found, it returns null for disk and
 * size 0. If there are OVF disks, we first match the updated ones, and from them we retrieve the one which was last
 * updated.
 *
 * @param ovfStoreDiskImages
 *            - A list of OVF_STORE disks
 * @return A Pair which contains the best OVF disk to retrieve data from and its size.
 */
private Pair<DiskImage, Long> getLatestOVFDisk(List<DiskImage> ovfStoreDiskImages) {
    Date foundOvfDiskUpdateDate = new Date();
    boolean isFoundOvfDiskUpdated = false;
    Long size = 0L;
    Disk ovfDisk = null;
    for (DiskImage ovfStoreDisk : ovfStoreDiskImages) {
        boolean isBetterOvfDiskFound = false;
        Map<String, Object> diskDescriptionMap;
        try {
            diskDescriptionMap = JsonHelper.jsonToMap(ovfStoreDisk.getDescription());
        } catch (IOException e) {
            log.warn("Exception while generating json containing ovf store info: {}", e.getMessage());
            log.debug("Exception", e);
            continue;
        }
        boolean isUpdated = Boolean.valueOf(diskDescriptionMap.get(OvfInfoFileConstants.IsUpdated).toString());
        Date date = getDateFromDiskDescription(diskDescriptionMap);
        if (date == null) {
            continue;
        }
        if (isFoundOvfDiskUpdated && !isUpdated) {
            continue;
        }
        if ((isUpdated && !isFoundOvfDiskUpdated) || date.after(foundOvfDiskUpdateDate)) {
            isBetterOvfDiskFound = true;
        }
        if (isBetterOvfDiskFound) {
            isFoundOvfDiskUpdated = isUpdated;
            foundOvfDiskUpdateDate = date;
            ovfDisk = ovfStoreDisk;
            size = Long.valueOf(diskDescriptionMap.get(OvfInfoFileConstants.Size).toString());
        }
    }
    return new Pair<>((DiskImage) ovfDisk, size);
}
Also used : IOException(java.io.IOException) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) UnregisteredDisk(org.ovirt.engine.core.common.businessentities.storage.UnregisteredDisk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Date(java.util.Date) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 97 with Pair

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

the class CINDERStorageHelper method registerLibvirtSecrets.

public Pair<Boolean, EngineFault> registerLibvirtSecrets(StorageDomain storageDomain, VDS vds, List<LibvirtSecret> libvirtSecrets) {
    VDSReturnValue returnValue;
    if (!libvirtSecrets.isEmpty()) {
        try {
            returnValue = backend.getResourceManager().runVdsCommand(VDSCommandType.RegisterLibvirtSecrets, new RegisterLibvirtSecretsVDSParameters(vds.getId(), libvirtSecrets));
        } catch (RuntimeException e) {
            log.error("Failed to register libvirt secret for storage domain {} on vds {}. Error: {}", storageDomain.getName(), vds.getName(), e.getMessage());
            log.debug("Exception", e);
            return new Pair<>(false, null);
        }
        if (!returnValue.getSucceeded()) {
            addMessageToAuditLog(AuditLogType.FAILED_TO_REGISTER_LIBVIRT_SECRET, storageDomain, vds);
            log.error("Failed to register libvirt secret for storage domain {} on vds {}.", storageDomain.getName(), vds.getName());
            EngineFault engineFault = new EngineFault();
            engineFault.setError(returnValue.getVdsError().getCode());
            return new Pair<>(false, engineFault);
        }
    }
    return new Pair<>(true, null);
}
Also used : RegisterLibvirtSecretsVDSParameters(org.ovirt.engine.core.common.vdscommands.RegisterLibvirtSecretsVDSParameters) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 98 with Pair

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

the class CINDERStorageHelper method runConnectionStorageToDomain.

@Override
protected Pair<Boolean, EngineFault> runConnectionStorageToDomain(StorageDomain storageDomain, Guid vdsId, int type) {
    Provider<?> provider = providerDao.get(Guid.createGuidFromString(storageDomain.getStorage()));
    List<LibvirtSecret> libvirtSecrets = libvirtSecretDao.getAllByProviderId(provider.getId());
    VDS vds = vdsDao.get(vdsId);
    if (!isLibrbdAvailable(vds)) {
        log.error("Couldn't found librbd1 package on vds {} (needed for storage domain {}).", vds.getName(), storageDomain.getName());
        addMessageToAuditLog(AuditLogType.NO_LIBRBD_PACKAGE_AVAILABLE_ON_VDS, null, vds);
        return new Pair<>(false, null);
    }
    return registerLibvirtSecrets(storageDomain, vds, libvirtSecrets);
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) LibvirtSecret(org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 99 with Pair

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

the class ConnectAllHostsToLunCommand method connectVdsToLun.

/**
 * The following method will connect all provided lund to all running host in pool
 *
 * @param luns
 *            - the luns which should be connected
 * @return the map where the key is true/false value which means if connection successes/not successes and value is
 *         map of luns Ids -> connected hosts
 */
private Pair<Boolean, Map<String, List<Guid>>> connectVdsToLun(List<LUNs> luns) {
    Map<String, List<Guid>> resultMap = new HashMap<>();
    for (VDS vds : getAllRunningVdssInPool()) {
        // try to connect vds to luns and getDeviceList in order to refresh them
        for (LUNs lun : luns) {
            if (!connectStorageToLunByVdsId(vds, lun)) {
                log.error("Could not connect host '{}' to lun '{}'", vds.getName(), lun.getLUNId());
                setVds(vds);
                handleFailure(vds, lun);
                return new Pair<>(Boolean.FALSE, resultMap);
            } else {
                List<Guid> hosts = resultMap.get(lun.getLUNId());
                if (hosts == null) {
                    hosts = new ArrayList<>();
                    resultMap.put(lun.getLUNId(), hosts);
                }
                hosts.add(vds.getId());
            }
        }
        // Refresh all connected luns to host
        if (!validateConnectedLuns(vds, getParameters().getLunIds())) {
            return new Pair<>(Boolean.FALSE, resultMap);
        }
    }
    return new Pair<>(Boolean.TRUE, resultMap);
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 100 with Pair

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

the class SyncMacsOfDbNicsWithSnapshot method auditLogPerformedReplacements.

private void auditLogPerformedReplacements(List<Pair<String, String>> macReplacements) {
    AuditLogable event = new AuditLogableImpl();
    List<String> replacementsString = macReplacements.stream().map(e -> e.getFirst() + "->" + e.getSecond()).collect(Collectors.toList());
    String auditLogMessage = "Following MACs had to be reallocated: " + replacementsString;
    auditLogDirector.log(event, AuditLogType.MAC_ADDRESS_HAD_TO_BE_REALLOCATED, auditLogMessage);
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) EngineException(org.ovirt.engine.core.common.errors.EngineException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) EngineError(org.ovirt.engine.core.common.errors.EngineError) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NetworkInterface(org.ovirt.engine.core.common.businessentities.network.NetworkInterface) MacPool(org.ovirt.engine.core.bll.network.macpool.MacPool) AuditLogType(org.ovirt.engine.core.common.AuditLogType) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) Pair(org.ovirt.engine.core.common.utils.Pair) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl)

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