Search in sources :

Example 1 with StoragePoolStatus

use of org.ovirt.engine.core.common.businessentities.StoragePoolStatus in project ovirt-engine by oVirt.

the class ProcessOvfUpdateForStoragePoolCommandTest method mockAnswers.

private void mockAnswers() {
    doAnswer(invocation -> {
        VM vm = (VM) invocation.getArguments()[0];
        return vm.getId().toString();
    }).when(ovfUpdateProcessHelper).generateVmMetadata(any(), any());
    doAnswer(invocation -> {
        VmTemplate template = (VmTemplate) ((FullEntityOvfData) invocation.getArguments()[0]).getVmBase();
        return template.getId().toString();
    }).when(ovfUpdateProcessHelper).generateVmTemplateMetadata(any());
    doAnswer(invocation -> {
        List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
        return neededIds.stream().map(id -> vms.get(id)).collect(Collectors.toList());
    }).when(vmDao).getVmsByIds(any());
    doAnswer(invocation -> {
        List<Guid> neededIds = (List<Guid>) invocation.getArguments()[0];
        return neededIds.stream().map(id -> templates.get(id)).collect(Collectors.toList());
    }).when(vmTemplateDao).getVmTemplatesByIds(any());
    doAnswer(invocation -> {
        Map<Guid, KeyValuePairCompat<String, List<Guid>>> updateMap = (Map<Guid, KeyValuePairCompat<String, List<Guid>>>) invocation.getArguments()[1];
        assertTrue("too many ovfs were sent in one vdsm call", updateMap.size() <= ITEMS_COUNT_PER_UPDATE);
        return true;
    }).when(ovfUpdateProcessHelper).executeUpdateVmInSpmCommand(any(), any(), any());
    doReturn(true).when(ovfUpdateProcessHelper).executeRemoveVmInSpm(any(), any(), any());
    doAnswer(invocation -> {
        List<Guid> ids = (List<Guid>) invocation.getArguments()[0];
        List<Long> values = (List<Long>) invocation.getArguments()[1];
        assertFalse("update of ovf version in db shouldn't be called with an empty value list", values.isEmpty());
        assertTrue("update of ovf version in db shouldn't be called with more items then MAX_ITEMS_PER_SQL_STATEMENT", values.size() <= StorageConstants.OVF_MAX_ITEMS_PER_SQL_STATEMENT);
        assertEquals("the size of the list of ids for update is not the same as the size of the " + "list with the new ovf values", values.size(), ids.size());
        Guid[] ids_array = ids.toArray(new Guid[ids.size()]);
        Long[] values_array = values.toArray(new Long[values.size()]);
        for (int i = 0; i < ids_array.length; i++) {
            executedUpdatedOvfGenerationIdsInDb.put(ids_array[i], values_array[i]);
        }
        return null;
    }).when(vmAndTemplatesGenerationsDao).updateOvfGenerations(any(), any(), any());
    doAnswer(invocation -> {
        StoragePoolStatus desiredStatus = (StoragePoolStatus) invocation.getArguments()[0];
        return buildStoragePoolsList().stream().filter(p -> desiredStatus.equals(p.getStatus())).collect(Collectors.toList());
    }).when(storagePoolDao).getAllByStatus(any());
    doReturn(poolDomainsOvfInfo.values().stream().map(Pair::getSecond).collect(Collectors.toList())).when(storageDomainDao).getAllForStoragePool(any());
    doAnswer(invocation -> {
        Guid domainId = (Guid) invocation.getArguments()[0];
        Pair<List<StorageDomainOvfInfo>, StorageDomain> pair = poolDomainsOvfInfo.get(domainId);
        if (pair != null) {
            return pair.getFirst();
        }
        return null;
    }).when(storageDomainOvfInfoDao).getAllForDomain(any());
}
Also used : ClusterDao(org.ovirt.engine.core.dao.ClusterDao) SnapshotDao(org.ovirt.engine.core.dao.SnapshotDao) VmTemplateDao(org.ovirt.engine.core.dao.VmTemplateDao) VmStaticDao(org.ovirt.engine.core.dao.VmStaticDao) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) StorageDomainOvfInfoDao(org.ovirt.engine.core.dao.StorageDomainOvfInfoDao) StoragePoolDao(org.ovirt.engine.core.dao.StoragePoolDao) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) MockConfigRule.mockConfig(org.ovirt.engine.core.utils.MockConfigRule.mockConfig) Collection(java.util.Collection) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) StorageConstants(org.ovirt.engine.core.common.constants.StorageConstants) Set(java.util.Set) Mockito.doNothing(org.mockito.Mockito.doNothing) Collectors(java.util.stream.Collectors) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) VmDao(org.ovirt.engine.core.dao.VmDao) ProcessOvfUpdateParameters(org.ovirt.engine.core.common.action.ProcessOvfUpdateParameters) DbUserDao(org.ovirt.engine.core.dao.DbUserDao) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) VmAndTemplatesGenerationsDao(org.ovirt.engine.core.dao.VmAndTemplatesGenerationsDao) LabelDao(org.ovirt.engine.core.dao.LabelDao) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) MockConfigRule(org.ovirt.engine.core.utils.MockConfigRule) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Mock(org.mockito.Mock) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageDomainOvfInfo(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo) HashMap(java.util.HashMap) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) ArrayList(java.util.ArrayList) ImageStatus(org.ovirt.engine.core.common.businessentities.storage.ImageStatus) CollectionUtils(org.apache.commons.collections.CollectionUtils) AffinityGroupDao(org.ovirt.engine.core.dao.scheduling.AffinityGroupDao) StorageDomainOvfInfoStatus(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfoStatus) LinkedList(java.util.LinkedList) VmStatic(org.ovirt.engine.core.common.businessentities.VmStatic) Pair(org.ovirt.engine.core.common.utils.Pair) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) VmTemplateStatus(org.ovirt.engine.core.common.businessentities.VmTemplateStatus) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) PermissionDao(org.ovirt.engine.core.dao.PermissionDao) BaseCommandTest(org.ovirt.engine.core.bll.BaseCommandTest) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) VM(org.ovirt.engine.core.common.businessentities.VM) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VM(org.ovirt.engine.core.common.businessentities.VM) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 2 with StoragePoolStatus

use of org.ovirt.engine.core.common.businessentities.StoragePoolStatus in project ovirt-engine by oVirt.

the class StorageHandlingCommandBase method calcStoragePoolStatusByDomainsStatus.

protected void calcStoragePoolStatusByDomainsStatus() {
    StorageDomain masterDomain = storageDomainDao.getStorageDomains(getStoragePool().getId(), StorageDomainType.Master).stream().findFirst().orElse(null);
    // if no master then Uninitialized
    // if master not active maintenance
    StoragePoolStatus newStatus = (masterDomain == null) ? StoragePoolStatus.Uninitialized : (masterDomain.getStatus() != null && masterDomain.getStatus() == StorageDomainStatus.Maintenance) ? StoragePoolStatus.Maintenance : (masterDomain.getStatus() != null && masterDomain.getStatus() == StorageDomainStatus.Active) ? StoragePoolStatus.Up : StoragePoolStatus.NonResponsive;
    if (newStatus != getStoragePool().getStatus()) {
        log.info("Update storage pool '{}' status from '{} to '{}'", getStoragePool().getId(), getStoragePool().getStatus(), newStatus);
        getCompensationContext().snapshotEntity(getStoragePool());
        getStoragePool().setStatus(newStatus);
        StoragePool poolFromDb = storagePoolDao.get(getStoragePool().getId());
        if ((getStoragePool().getSpmVdsId() == null && poolFromDb.getSpmVdsId() != null) || (getStoragePool().getSpmVdsId() != null && !getStoragePool().getSpmVdsId().equals(poolFromDb.getSpmVdsId()))) {
            log.info("Set storage pool '{}' vds Id to '{}'", getStoragePool().getId(), poolFromDb.getSpmVdsId());
            getStoragePool().setSpmVdsId(poolFromDb.getSpmVdsId());
        }
        if (getStoragePool().getStatus() == StoragePoolStatus.Uninitialized) {
            log.info("Set storage pool '{}' vds Id to null", getStoragePool().getId(), poolFromDb.getSpmVdsId());
            getStoragePool().setSpmVdsId(null);
        }
        executeInScope(TransactionScopeOption.Required, () -> {
            storagePoolDao.update(getStoragePool());
            return null;
        });
        StoragePoolStatusHandler.poolStatusChanged(getStoragePool().getId(), getStoragePool().getStatus());
    }
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus)

Example 3 with StoragePoolStatus

use of org.ovirt.engine.core.common.businessentities.StoragePoolStatus in project ovirt-engine by oVirt.

the class IrsProxy method getHostFromVds.

private String getHostFromVds() {
    String returnValue = null;
    Guid curVdsId = (currentVdsId != null) ? currentVdsId : Guid.Empty;
    StoragePool storagePool = storagePoolDao.get(storagePoolId);
    if (storagePool == null) {
        log.info("hostFromVds::Finished elect spm, storage pool '{}' was removed", storagePoolId);
        return null;
    }
    List<VDS> prioritizedVdsInPool = getPrioritizedVdsInPool();
    currentVdsId = null;
    // If VDS is in initialize status, wait for it to be up (or until
    // configurable timeout is reached)
    waitForVdsIfIsInitializing(curVdsId);
    // update pool status to problematic while selecting spm
    StoragePoolStatus prevStatus = storagePool.getStatus();
    if (prevStatus != StoragePoolStatus.NonResponsive) {
        try {
            getEventListener().storagePoolStatusChange(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC_SEARCHING_NEW_SPM, EngineError.ENGINE, TransactionScopeOption.RequiresNew);
        } catch (RuntimeException ex) {
            throw new IRSStoragePoolStatusException(ex);
        }
    }
    VDS selectedVds = null;
    SpmStatusResult spmStatus = null;
    if (prioritizedVdsInPool != null && prioritizedVdsInPool.size() > 0) {
        selectedVds = prioritizedVdsInPool.get(0);
    } else if (!Guid.Empty.equals(curVdsId) && !getTriedVdssList().contains(curVdsId)) {
        selectedVds = vdsDao.get(curVdsId);
        if (selectedVds.getStatus() != VDSStatus.Up || selectedVds.getVdsSpmPriority() == BusinessEntitiesDefinitions.HOST_MIN_SPM_PRIORITY) {
            selectedVds = null;
        }
    }
    if (selectedVds != null) {
        // Stores origin host id in case and will be needed to disconnect from storage pool
        Guid selectedVdsId = selectedVds.getId();
        Integer selectedVdsSpmId = selectedVds.getVdsSpmId();
        triedVdssList.add(selectedVdsId);
        currentVdsId = selectedVds.getId();
        connectStoragePool(selectedVds, storagePool);
        VDSReturnValue returnValueFromVds = resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(selectedVds.getId(), storagePoolId));
        spmStatus = (SpmStatusResult) returnValueFromVds.getReturnValue();
        boolean ignoreSpmStatusResult = returnValueFromVds.getVdsError() != null && returnValueFromVds.getVdsError().getCode() == EngineError.InquireNotSupportedError;
        if (spmStatus != null || ignoreSpmStatusResult) {
            boolean performedPoolConnect = false;
            log.info("hostFromVds::selectedVds - '{}', spmStatus '{}', storage pool '{}', storage pool version '{}'", selectedVds.getName(), spmStatus != null ? spmStatus.getSpmStatus() : "unknown", storagePool.getName(), storagePool.getCompatibilityVersion());
            if (ignoreSpmStatusResult) {
                spmStatus = startSpm(storagePool, selectedVds, DEFAULT_PREV_ID, DEFAULT_LVER, DEFAULT_PREV_ID);
            } else {
                if (spmStatus.getSpmStatus() == SpmStatus.Unknown_Pool) {
                    connectStoragePool(selectedVds, storagePool);
                    performedPoolConnect = true;
                    // refresh spmStatus result
                    spmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(selectedVds.getId(), storagePoolId)).getReturnValue();
                    log.info("hostFromVds::Connected host to pool - selectedVds - {}, spmStatus {}, storage pool {}", selectedVds.getName(), spmStatus.getSpmStatus(), storagePool.getName());
                }
                RefObject<VDS> tempRefObject = new RefObject<>(selectedVds);
                spmStatus = handleSpmStatusResult(curVdsId, prioritizedVdsInPool, storagePool, tempRefObject, spmStatus);
                selectedVds = tempRefObject.argvalue;
            }
            if (selectedVds != null) {
                RefObject<VDS> tempRefObject2 = new RefObject<>(selectedVds);
                RefObject<SpmStatusResult> tempRefObject3 = new RefObject<>(spmStatus);
                returnValue = handleSelectedVdsForSPM(storagePool, tempRefObject2, tempRefObject3, prevStatus);
                selectedVds = tempRefObject2.argvalue;
                spmStatus = tempRefObject3.argvalue;
            } else {
                currentVdsId = null;
            }
            if (performedPoolConnect && selectedVds == null) {
                // if could not start spm on this host and connected to
                // pool here
                // then disconnect
                resourceManager.runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(selectedVdsId, storagePoolId, selectedVdsSpmId));
            }
        } else {
            log.info("hostFromVds::selectedVds - '{}', spmStatus returned null!", selectedVds.getName());
            if (returnValueFromVds.getExceptionObject() instanceof IRSNoMasterDomainException) {
                throw returnValueFromVds.getExceptionObject();
            }
        }
    }
    return returnValue;
}
Also used : SpmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VDS(org.ovirt.engine.core.common.businessentities.VDS) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) SpmStatusResult(org.ovirt.engine.core.common.businessentities.SpmStatusResult) RefObject(org.ovirt.engine.core.compat.RefObject) DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters)

Aggregations

StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)3 StoragePoolStatus (org.ovirt.engine.core.common.businessentities.StoragePoolStatus)3 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Before (org.junit.Before)1 ClassRule (org.junit.ClassRule)1