Search in sources :

Example 11 with Pair

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

the class GetUnregisteredBlockStorageDomainsQuery method getStorageDomainById.

/**
 * Retrieve a storage domain using a specified storage domain ID.
 *
 * @param storageDomainId the domain's ID
 * @return the storage domain
 */
@SuppressWarnings("unchecked")
protected StorageDomain getStorageDomainById(Guid storageDomainId) {
    VDSReturnValue returnValue;
    try {
        returnValue = executeHSMGetStorageDomainInfo(new HSMGetStorageDomainInfoVDSCommandParameters(getParameters().getVdsId(), storageDomainId));
    } catch (RuntimeException e) {
        log.error("Could not get info for storage domain ID: '{}': {}", storageDomainId, e.getMessage());
        log.debug("Exception", e);
        return null;
    }
    Pair<StorageDomainStatic, SANState> result = (Pair<StorageDomainStatic, SANState>) returnValue.getReturnValue();
    StorageDomainStatic storageDomainStatic = result.getFirst();
    storageDomainStatic.setStorageType(getParameters().getStorageType());
    StorageDomain storageDomain = new StorageDomain();
    storageDomain.setStorageStaticData(storageDomainStatic);
    return storageDomain;
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) SANState(org.ovirt.engine.core.common.businessentities.SANState) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 12 with Pair

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

the class DiskValidatorTest method testDiskAttachedToAnyNonDownVMWithProblems.

private void testDiskAttachedToAnyNonDownVMWithProblems(boolean checkOnlyPlugged, String expectedNames) {
    VM vmPausedPlugged = createVM();
    vmPausedPlugged.setName("vmPausedPlugged");
    vmPausedPlugged.setStatus(VMStatus.Paused);
    VmDevice device1 = new VmDevice();
    device1.setPlugged(true);
    Pair<VM, VmDevice> pair1 = new Pair<>(vmPausedPlugged, device1);
    VM vmDownPlugged = createVM();
    vmDownPlugged.setName("vmDownPlugged");
    VmDevice device2 = new VmDevice();
    device2.setPlugged(true);
    Pair<VM, VmDevice> pair2 = new Pair<>(vmDownPlugged, device2);
    VM vmRunningUnplugged = createVM();
    vmRunningUnplugged.setName("vmRunningUnplugged");
    vmRunningUnplugged.setStatus(VMStatus.Up);
    VmDevice device3 = new VmDevice();
    device3.setPlugged(false);
    Pair<VM, VmDevice> pair3 = new Pair<>(vmRunningUnplugged, device3);
    VM anotherPausedPlugged = createVM();
    anotherPausedPlugged.setName("anotherPausedPlugged");
    anotherPausedPlugged.setStatus(VMStatus.Paused);
    VmDevice device4 = new VmDevice();
    device4.setPlugged(true);
    Pair<VM, VmDevice> pair4 = new Pair<>(anotherPausedPlugged, device4);
    VM runningSnapshotPlugged = createVM();
    runningSnapshotPlugged.setName("runningSnapshotPlugged");
    runningSnapshotPlugged.setStatus(VMStatus.Up);
    VmDevice device5 = new VmDevice();
    device5.setPlugged(true);
    device5.setSnapshotId(Guid.newGuid());
    Pair<VM, VmDevice> pair5 = new Pair<>(runningSnapshotPlugged, device5);
    List<Pair<VM, VmDevice>> vmList = Arrays.asList(pair1, pair2, pair3, pair4, pair5);
    when(vmDao.getVmsWithPlugInfo(any())).thenReturn(vmList);
    String[] expectedReplacements = { ReplacementUtils.createSetVariableString(DiskValidator.DISK_NAME_VARIABLE, disk.getDiskAlias()), ReplacementUtils.createSetVariableString(DiskValidator.VM_LIST, expectedNames) };
    assertThat(validator.isDiskPluggedToAnyNonDownVm(checkOnlyPlugged), failsWith(EngineMessage.ACTION_TYPE_FAILED_DISK_PLUGGED_TO_NON_DOWN_VMS, expectedReplacements));
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 13 with Pair

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

the class DiskValidatorTest method prepareForCheckingIfDiskPluggedToVmsThatAreNotDown.

public List<Pair<VM, VmDevice>> prepareForCheckingIfDiskPluggedToVmsThatAreNotDown() {
    VM vm1 = createVM();
    VM vm2 = createVM();
    VmDevice device1 = createVmDeviceForDisk(vm1, disk);
    VmDevice device2 = createVmDeviceForDisk(vm1, disk);
    List<Pair<VM, VmDevice>> vmsInfo = new LinkedList<>();
    vmsInfo.add(new Pair<>(vm1, device1));
    vmsInfo.add(new Pair<>(vm2, device2));
    return vmsInfo;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) LinkedList(java.util.LinkedList) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 14 with Pair

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

the class VmDevicesMonitoringTest method testUpdateVmFromFullList.

@Test
public void testUpdateVmFromFullList() {
    initDevices();
    initDumpXmls();
    VmDevicesMonitoring.Change change = vmDevicesMonitoring.createChange(VDS_ID, 1L);
    Map<String, Object> vmInfo = getDumpXmls(VM_ID, getDeviceInfo(null, "balloon", "memballoon", null), getDeviceInfo(null, "controller", "virtio-serial", SERIAL_DEVICE_ADDRESS), getDeviceInfo(VIDEO_DEVICE_ID, "video", "cirrus", VIDEO_DEVICE_ADDRESS), getDeviceInfo(CDROM_DEVICE_ID, "disk", "cdrom", CDROM_DEVICE_ADDRESS));
    change.updateVmFromFullList(vmInfo);
    change.flush();
    change = vmDevicesMonitoring.createChange(VDS_ID, 1L);
    change.updateVm(VM_ID, INITIAL_HASH);
    change.flush();
    verify(resourceManager, never()).runVdsCommand(eq(VDSCommandType.FullList), any());
    verify(vmDeviceDao, never()).updateAllInBatch(any());
    verify(vmDeviceDao, never()).removeAll(any());
    verify(vmDeviceDao, times(1)).saveAll(any());
    ArgumentCaptor<List> updateHashesCaptor = ArgumentCaptor.forClass(List.class);
    verify(vmDynamicDao, times(2)).updateDevicesHashes(updateHashesCaptor.capture());
    List<List> values = updateHashesCaptor.getAllValues();
    List updatedHashes = values.get(0);
    assertEquals(1, updatedHashes.size());
    Pair<Guid, String> hashInfo = (Pair<Guid, String>) updatedHashes.get(0);
    assertEquals(VM_ID, hashInfo.getFirst());
    assertEquals(VmDevicesMonitoring.UPDATE_HASH, hashInfo.getSecond());
    updatedHashes = values.get(1);
    assertEquals(1, updatedHashes.size());
    hashInfo = (Pair<Guid, String>) updatedHashes.get(0);
    assertEquals(VM_ID, hashInfo.getFirst());
    assertEquals(INITIAL_HASH, hashInfo.getSecond());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test)

Example 15 with Pair

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

the class SpmStopVDSCommand method retrieveVdsExecutionLock.

private EngineLock retrieveVdsExecutionLock() {
    if (lock == null) {
        Map<String, Pair<String, String>> exsluciveLock = Collections.singletonMap(getParameters().getVdsId().toString(), new Pair<>(LockingGroup.VDS_EXECUTION.toString(), EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED.toString()));
        lock = new EngineLock(exsluciveLock, null);
    }
    return lock;
}
Also used : EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) 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