Search in sources :

Example 41 with Pair

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

the class AttachStorageDomainToPoolCommandTest method statusSetInMap.

@Test
public void statusSetInMap() {
    cmd.init();
    Guid storageDomainId = cmd.getStorageDomainId();
    Guid poolId = cmd.getStoragePoolId();
    doNothing().when(cmd).attemptToActivateDomain();
    doReturn(Collections.singletonList(new Pair<>(Guid.newGuid(), true))).when(cmd).connectHostsInUpToDomainStorageServer();
    StoragePool pool = new StoragePool();
    pool.setId(poolId);
    pool.setStatus(StoragePoolStatus.Up);
    when(storagePoolDao.get(any())).thenReturn(pool);
    when(isoMapDao.get(any())).thenReturn(map);
    when(storageDomainDao.getForStoragePool(any(), any())).thenReturn(new StorageDomain());
    when(storageDomainStaticDao.get(any())).thenReturn(new StorageDomainStatic());
    doReturn(pool.getId()).when(cmd).getStoragePoolIdFromVds();
    ActionReturnValue actionReturnValue = new ActionReturnValue();
    actionReturnValue.setSucceeded(true);
    when(backendInternal.runInternalAction(any(), any(), any())).thenReturn(actionReturnValue);
    StorageDomainStatic storageDomain = new StorageDomainStatic();
    storageDomain.setId(Guid.newGuid());
    storageDomain.setStorageDomainType(StorageDomainType.ImportExport);
    mockGetStorageDomainInfoVdsCommand(storageDomain);
    mockAttachStorageDomainVdsCommand();
    when(vdsDao.get(any())).thenReturn(vds);
    doReturn(Collections.emptyList()).when(cmd).getEntitiesFromStorageOvfDisk(storageDomainId, pool.getId());
    doReturn(Collections.emptyList()).when(cmd).getAllOVFDisks(storageDomainId, pool.getId());
    doAnswer(invocation -> {
        map = (StoragePoolIsoMap) invocation.getArguments()[0];
        return null;
    }).when(isoMapDao).save(any());
    cmd.setCompensationContext(mock(CompensationContext.class));
    cmd.executeCommand();
    assertNotNull(map);
    assertEquals(StorageDomainStatus.Maintenance, map.getStatus());
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) CompensationContext(org.ovirt.engine.core.bll.context.CompensationContext) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest)

Example 42 with Pair

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

the class GetBlockStorageDomainsWithAttachedStoragePoolGuidQueryTest method testNullStorageDomainListQuery.

@Test
public void testNullStorageDomainListQuery() {
    StoragePool storagePool = new StoragePool();
    storagePool.setStatus(StoragePoolStatus.Up);
    mockStoragePoolDao(storagePool);
    // Run 'HSMGetStorageDomainInfo' command
    VDSReturnValue returnValue = new VDSReturnValue();
    returnValue.setSucceeded(true);
    Pair<StorageDomainStatic, Guid> storageDomainToPoolId = new Pair<>(storageDomain.getStorageStaticData(), Guid.newGuid());
    returnValue.setReturnValue(storageDomainToPoolId);
    when(vdsBrokerFrontendMock.runVdsCommand(eq(VDSCommandType.HSMGetStorageDomainInfo), any())).thenReturn(returnValue);
    // Execute command
    getQuery().executeQueryCommand();
    // Assert the query's results
    List<StorageDomainStatic> returnedStorageDomainList = new ArrayList<>();
    assertEquals(returnedStorageDomainList, getQuery().getQueryReturnValue().getReturnValue());
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test)

Example 43 with Pair

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

the class AttachUserToVmFromPoolAndRunCommand method getExclusiveLocks.

@Override
protected Map<String, Pair<String, String>> getExclusiveLocks() {
    Map<String, Pair<String, String>> locks = new HashMap<>();
    locks.put(getAdUserId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.USER_VM_POOL, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
    if (!Guid.Empty.equals(getVmId()) && isVmPrestarted()) {
        EngineLock runLock = vmPoolHandler.createLock(getVmId());
        if (runLock.getExclusiveLocks() != null) {
            locks.putAll(runLock.getExclusiveLocks());
        }
    }
    return locks;
}
Also used : HashMap(java.util.HashMap) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 44 with Pair

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

the class CreateOvaCommand method runAnsiblePackOvaPlaybook.

private boolean runAnsiblePackOvaPlaybook(String vmName, String ovf, Collection<DiskImage> disks, Map<Guid, String> diskIdToPath) {
    AnsibleCommandBuilder command = new AnsibleCommandBuilder().hostnames(getVds().getHostName()).variables(new Pair<>("target_directory", getParameters().getDirectory()), new Pair<>("ova_name", getParameters().getName()), new Pair<>("ovirt_ova_pack_ovf", genOvfParameter(ovf)), new Pair<>("ovirt_ova_pack_disks", genDiskParameters(disks, diskIdToPath))).logFileDirectory(CREATE_OVA_LOG_DIRECTORY).logFilePrefix("ovirt-export-ova-ansible").logFileName(getVds().getHostName()).logFileSuffix(getCorrelationId()).playbook(AnsibleConstants.EXPORT_OVA_PLAYBOOK);
    boolean succeeded = false;
    try {
        succeeded = ansibleExecutor.runCommand(command).getAnsibleReturnCode() == AnsibleReturnCode.OK;
    } catch (IOException | InterruptedException e) {
        log.debug("Failed to create OVA", e);
    }
    if (!succeeded) {
        log.error("Failed to create OVA. Please check logs for more details: {}", command.logFile());
    }
    return succeeded;
}
Also used : AnsibleCommandBuilder(org.ovirt.engine.core.common.utils.ansible.AnsibleCommandBuilder) IOException(java.io.IOException) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 45 with Pair

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

the class CloneVmCommand method getSharedLocks.

@Override
protected Map<String, Pair<String, String>> getSharedLocks() {
    Map<String, Pair<String, String>> locks = new HashMap<>();
    for (DiskImage image : getImagesToCheckDestinationStorageDomains()) {
        locks.put(image.getId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.DISK, getDiskSharedLockMessage()));
    }
    locks.put(getSourceVmFromDb().getId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.VM, EngineMessage.ACTION_TYPE_FAILED_VM_IS_BEING_CLONED));
    return locks;
}
Also used : HashMap(java.util.HashMap) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) 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