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());
}
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());
}
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;
}
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;
}
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;
}
Aggregations