Search in sources :

Example 76 with Pair

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

the class ISCSIStorageHelper method runConnectionStorageToDomain.

@SuppressWarnings("unchecked")
@Override
protected Pair<Boolean, EngineFault> runConnectionStorageToDomain(StorageDomain storageDomain, Guid vdsId, int type, LUNs lun, Guid storagePoolId) {
    boolean isSuccess = true;
    VDSReturnValue returnValue = null;
    List<StorageServerConnections> list = (lun == null) ? storageServerConnectionDao.getAllForVolumeGroup(storageDomain.getStorage()) : lun.getLunConnections();
    if (list.size() != 0) {
        if (VDSCommandType.forValue(type) == VDSCommandType.DisconnectStorageServer) {
            list = filterConnectionsUsedByOthers(list, storageDomain.getStorage(), lun != null ? lun.getLUNId() : "");
        } else if (VDSCommandType.forValue(type) == VDSCommandType.ConnectStorageServer) {
            list = updateIfaces(list, vdsId);
        }
        Guid poolId = storagePoolId;
        if (storageDomain != null && storageDomain.getStoragePoolId() != null) {
            poolId = storageDomain.getStoragePoolId();
        }
        returnValue = backend.getResourceManager().runVdsCommand(VDSCommandType.forValue(type), new StorageServerConnectionManagementVDSParameters(vdsId, poolId, StorageType.ISCSI, list));
        isSuccess = returnValue.getSucceeded();
        if (isSuccess && VDSCommandType.forValue(type) == VDSCommandType.ConnectStorageServer) {
            isSuccess = isConnectSucceeded((Map<String, String>) returnValue.getReturnValue(), list);
        }
    }
    EngineFault engineFault = null;
    if (!isSuccess && returnValue.getVdsError() != null) {
        engineFault = new EngineFault();
        engineFault.setError(returnValue.getVdsError().getCode());
    }
    return new Pair<>(isSuccess, engineFault);
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) StorageServerConnectionManagementVDSParameters(org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) Guid(org.ovirt.engine.core.compat.Guid) Map(java.util.Map) LUNStorageServerConnectionMap(org.ovirt.engine.core.common.businessentities.storage.LUNStorageServerConnectionMap) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 77 with Pair

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

the class MapVnicsFlowTest method testCases.

@Parameterized.Parameters
public static Collection<Object[]> testCases() {
    Pair nullMappingsAndNullOvfs = testNullMappingsAndNullOvfs();
    Pair nullMappingsAndEmptyOvfs = testNullMappingsAndEmptyOvfs();
    Pair emptyMappingsAndEmptyOvfs = testEmptyMappingsAndEmptyOvfs();
    Pair emptyMappingsAndNullOvfs = testEmptyMappingsAndNullOvfs();
    Pair someMappingsAndNullOvfs = testSomeMappingsAndNullOvfs();
    return Arrays.asList(new Object[][] { { nullMappingsAndNullOvfs.getFirst(), nullMappingsAndNullOvfs.getSecond() }, { nullMappingsAndEmptyOvfs.getFirst(), nullMappingsAndEmptyOvfs.getSecond() }, { emptyMappingsAndEmptyOvfs.getFirst(), emptyMappingsAndEmptyOvfs.getSecond() }, { emptyMappingsAndNullOvfs.getFirst(), emptyMappingsAndNullOvfs.getSecond() }, { someMappingsAndNullOvfs.getFirst(), someMappingsAndNullOvfs.getSecond() } });
}
Also used : Pair(org.ovirt.engine.core.common.utils.Pair)

Example 78 with Pair

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

the class LibvirtVmXmlBuilder method writeDisks.

private void writeDisks(List<VmDevice> devices) {
    Map<VmDeviceId, VmDevice> deviceIdToDevice = devices.stream().collect(Collectors.toMap(VmDevice::getId, dev -> dev));
    Map<Integer, Map<VmDevice, Integer>> vmDeviceSpaprVscsiUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForSpaprScsiDisks(vm);
    Map<Integer, Map<VmDevice, Integer>> vmDeviceVirtioScsiUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForVirtioScsiDisks(vm);
    int hdIndex = -1;
    int sdIndex = -1;
    int vdIndex = -1;
    int pinnedDriveIndex = 0;
    Map<Disk, VmDevice> vmDisksToDevices = vm.getDiskMap().values().stream().map(d -> new Pair<>(d, deviceIdToDevice.get(new VmDeviceId(d.getId(), vm.getId())))).filter(p -> p.getSecond() != null && p.getSecond().isManaged()).collect(Collectors.toMap(Pair::getFirst, Pair::getSecond));
    for (Entry<Disk, VmDevice> diskAndDevice : vmInfoBuildUtils.getSortedDisks(vmDisksToDevices, vm.getId())) {
        Disk disk = diskAndDevice.getKey();
        VmDevice device = diskAndDevice.getValue();
        DiskVmElement dve = disk.getDiskVmElementForVm(vm.getId());
        DiskInterface diskInterface = dve.getDiskInterface();
        int index = 0;
        int pinTo = 0;
        switch(diskInterface) {
            case IDE:
                index = hdIndex = skipCdIndices(++hdIndex, diskInterface);
                break;
            case VirtIO:
                pinTo = vmInfoBuildUtils.pinToIoThreads(vm, pinnedDriveIndex++);
                index = vdIndex = skipCdIndices(++vdIndex, diskInterface);
                break;
            case SPAPR_VSCSI:
            case VirtIO_SCSI:
                vmInfoBuildUtils.calculateAddressForScsiDisk(vm, disk, device, vmDeviceSpaprVscsiUnitMap, vmDeviceVirtioScsiUnitMap);
            case SATA:
                index = sdIndex = skipCdIndices(++sdIndex, diskInterface);
                break;
        }
        String dev = vmInfoBuildUtils.makeDiskName(dve.getDiskInterface().getName(), index);
        writeDisk(device, disk, dve, dev, pinTo);
    }
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) VmType(org.ovirt.engine.core.common.businessentities.VmType) PropagateErrors(org.ovirt.engine.core.common.businessentities.storage.PropagateErrors) VmInterfaceType(org.ovirt.engine.core.common.businessentities.network.VmInterfaceType) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LoggerFactory(org.slf4j.LoggerFactory) GraphicsInfo(org.ovirt.engine.core.common.businessentities.GraphicsInfo) VmCpuCountHelper(org.ovirt.engine.core.common.utils.VmCpuCountHelper) XmlTextWriter(org.ovirt.engine.core.utils.ovf.xml.XmlTextWriter) HugePageUtils(org.ovirt.engine.core.common.utils.HugePageUtils) ChipsetType(org.ovirt.engine.core.common.businessentities.ChipsetType) VmDeviceCommonUtils(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils) Map(java.util.Map) VdsNumaNode(org.ovirt.engine.core.common.businessentities.VdsNumaNode) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) StringMapUtils(org.ovirt.engine.core.utils.StringMapUtils) VmDeviceCommonUtils.updateVmDevicesBootOrder(org.ovirt.engine.core.common.utils.VmDeviceCommonUtils.updateVmDevicesBootOrder) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic) VdsStatistics(org.ovirt.engine.core.common.businessentities.VdsStatistics) Version(org.ovirt.engine.core.compat.Version) MemoizingSupplier(org.ovirt.engine.core.utils.MemoizingSupplier) DisplayType(org.ovirt.engine.core.common.businessentities.DisplayType) NetworkFilter(org.ovirt.engine.core.common.businessentities.network.NetworkFilter) DiskStorageType(org.ovirt.engine.core.common.businessentities.storage.DiskStorageType) VmNumaNode(org.ovirt.engine.core.common.businessentities.VmNumaNode) Collection(java.util.Collection) VmPayload(org.ovirt.engine.core.common.businessentities.VmPayload) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) HostDevice(org.ovirt.engine.core.common.businessentities.HostDevice) List(java.util.List) Stream(java.util.stream.Stream) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Entry(java.util.Map.Entry) Optional(java.util.Optional) GraphicsType(org.ovirt.engine.core.common.businessentities.GraphicsType) NumaSettingFactory(org.ovirt.engine.core.vdsbroker.vdsbroker.NumaSettingFactory) FeatureSupported(org.ovirt.engine.core.common.FeatureSupported) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDeviceType(org.ovirt.engine.core.common.utils.VmDeviceType) ArchitectureType(org.ovirt.engine.core.common.businessentities.ArchitectureType) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) NetworkUtils(org.ovirt.engine.core.utils.NetworkUtils) ArrayList(java.util.ArrayList) VmDeviceGeneralType(org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType) VmPropertiesUtils(org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils) HashSet(java.util.HashSet) ArchStrategyFactory(org.ovirt.engine.core.utils.archstrategy.ArchStrategyFactory) VdsProperties(org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties) HugePage(org.ovirt.engine.core.common.businessentities.HugePage) Network(org.ovirt.engine.core.common.businessentities.network.Network) VolumeFormat(org.ovirt.engine.core.common.businessentities.storage.VolumeFormat) Pair(org.ovirt.engine.core.common.utils.Pair) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VmHostDevice(org.ovirt.engine.core.common.businessentities.VmHostDevice) VnicProfile(org.ovirt.engine.core.common.businessentities.network.VnicProfile) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) VM(org.ovirt.engine.core.common.businessentities.VM) NumaTuneMode(org.ovirt.engine.core.common.businessentities.NumaTuneMode) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices) IoTuneUtils.ioTuneListFrom(org.ovirt.engine.core.vdsbroker.vdsbroker.IoTuneUtils.ioTuneListFrom) Comparator(java.util.Comparator) Collections(java.util.Collections) StorageQos(org.ovirt.engine.core.common.businessentities.qos.StorageQos) VmDeviceId(org.ovirt.engine.core.common.businessentities.VmDeviceId) VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) DiskVmElement(org.ovirt.engine.core.common.businessentities.storage.DiskVmElement) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Map(java.util.Map) HashMap(java.util.HashMap) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 79 with Pair

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

the class ManageGlusterServiceCommand method getCallableVdsCmdList.

private List<Callable<Pair<VDS, VDSReturnValue>>> getCallableVdsCmdList() {
    List<VDS> servers = glusterUtil.getAllUpServers(getClusterId());
    final List<String> serviceList = getServiceList();
    List<Callable<Pair<VDS, VDSReturnValue>>> commandList = new ArrayList<>();
    for (final VDS upServer : servers) {
        commandList.add(() -> {
            VDSReturnValue returnValue = runVdsCommand(VDSCommandType.ManageGlusterService, new GlusterServiceVDSParameters(upServer.getId(), serviceList, getParameters().getActionType()));
            Pair<VDS, VDSReturnValue> pairRetVal = new Pair<>(upServer, returnValue);
            if (returnValue.getSucceeded()) {
                updateService(upServer.getId(), (List<GlusterServerService>) returnValue.getReturnValue());
            } else {
                errors.add(returnValue.getVdsError().getMessage());
            }
            return pairRetVal;
        });
    }
    return commandList;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) GlusterServerService(org.ovirt.engine.core.common.businessentities.gluster.GlusterServerService) ArrayList(java.util.ArrayList) GlusterServiceVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterServiceVDSParameters) Callable(java.util.concurrent.Callable) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 80 with Pair

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

the class RemoveGlusterHookCommand method executeCommand.

@Override
protected void executeCommand() {
    entity = getGlusterHook();
    addCustomValue(GlusterConstants.HOOK_NAME, entity.getName());
    List<Callable<Pair<VDS, VDSReturnValue>>> taskList = new ArrayList<>();
    for (final VDS server : getServersInCluster()) {
        taskList.add(() -> {
            VDSReturnValue returnValue;
            returnValue = runVdsCommand(VDSCommandType.RemoveGlusterHook, new GlusterHookVDSParameters(server.getId(), entity.getGlusterCommand(), entity.getStage(), entity.getName()));
            return new Pair<>(server, returnValue);
        });
    }
    if (!taskList.isEmpty()) {
        List<Pair<VDS, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(taskList);
        for (Pair<VDS, VDSReturnValue> pairResult : pairResults) {
            VDSReturnValue retValue = pairResult.getSecond();
            if (!retValue.getSucceeded()) {
                errors.add(retValue.getVdsError().getMessage());
            }
        }
    }
    if (errors.size() > 0) {
        setSucceeded(false);
        errorType = AuditLogType.GLUSTER_HOOK_REMOVE_FAILED;
        handleVdsErrors(getAuditLogTypeValue(), errors);
        addCustomValue(GlusterConstants.FAILURE_MESSAGE, StringUtils.join(errors, System.lineSeparator()));
    } else {
        setSucceeded(true);
    }
    if (getSucceeded()) {
        entity.removeMissingConflict();
        glusterHooksDao.remove(entity.getId());
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) GlusterHookVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.GlusterHookVDSParameters) Callable(java.util.concurrent.Callable) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) 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