Search in sources :

Example 1 with AsyncTaskStatus

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

the class IrsProxy method proceedStoragePoolStats.

@SuppressWarnings("unchecked")
private void proceedStoragePoolStats(StoragePool storagePool) {
    // ugly patch because vdsm doesnt check if host is spm on spm
    // operations
    VDSReturnValue result = null;
    Guid curVdsId = currentVdsId;
    if (curVdsId != null) {
        result = resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(curVdsId, storagePoolId));
    }
    if (result == null || !result.getSucceeded() || (result.getSucceeded() && ((SpmStatusResult) result.getReturnValue()).getSpmStatus() != SpmStatus.SPM)) {
        // update pool status to problematic until fence will happen
        if (storagePool.getStatus() != StoragePoolStatus.NonResponsive && storagePool.getStatus() != StoragePoolStatus.NotOperational) {
            if (result != null && result.getVdsError() != null) {
                updateStoragePoolStatus(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC_WITH_ERROR, result.getVdsError().getCode());
            } else {
                updateStoragePoolStatus(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC, EngineError.ENGINE);
            }
        }
        // then cause failover with attempts
        if (result != null && !(result.getExceptionObject() instanceof VDSNetworkException)) {
            HashMap<Guid, AsyncTaskStatus> tasksList = (HashMap<Guid, AsyncTaskStatus>) resourceManager.runVdsCommand(VDSCommandType.HSMGetAllTasksStatuses, new VdsIdVDSCommandParametersBase(curVdsId)).getReturnValue();
            boolean allTasksFinished = true;
            if (tasksList != null) {
                for (AsyncTaskStatus taskStatus : tasksList.values()) {
                    if (AsyncTaskStatusEnum.finished != taskStatus.getStatus()) {
                        allTasksFinished = false;
                        break;
                    }
                }
            }
            if ((tasksList == null) || allTasksFinished) {
                nullifyInternalProxies();
            } else {
                if (_errorAttempts < Config.<Integer>getValue(ConfigValues.SPMFailOverAttempts)) {
                    _errorAttempts++;
                    log.warn("failed getting spm status for pool '{}' ({}), attempt number: {}", storagePoolId, storagePool.getName(), _errorAttempts);
                } else {
                    nullifyInternalProxies();
                    _errorAttempts = 0;
                }
            }
        }
    } else if (result.getSucceeded() && ((SpmStatusResult) result.getReturnValue()).getSpmStatus() == SpmStatus.SPM && (storagePool.getStatus() == StoragePoolStatus.NonResponsive || storagePool.getStatus() == StoragePoolStatus.Contend)) {
        // if recovered from network exception set back to up
        storagePoolDao.updateStatus(storagePool.getId(), StoragePoolStatus.Up);
        storagePool.setStatus(StoragePoolStatus.Up);
        getEventListener().storagePoolStatusChanged(storagePool.getId(), storagePool.getStatus());
    }
    List<StorageDomain> domainsInDb = storageDomainDao.getAllForStoragePool(storagePoolId);
    GetStoragePoolInfoVDSCommandParameters tempVar = new GetStoragePoolInfoVDSCommandParameters(storagePoolId);
    tempVar.setIgnoreFailoverLimit(true);
    VDSReturnValue storagePoolInfoResult = resourceManager.runVdsCommand(VDSCommandType.GetStoragePoolInfo, tempVar);
    if (storagePoolInfoResult.getSucceeded()) {
        KeyValuePairCompat<StoragePool, List<StorageDomain>> data = (KeyValuePairCompat<StoragePool, List<StorageDomain>>) storagePoolInfoResult.getReturnValue();
        int masterVersion = data.getKey().getMasterDomainVersion();
        HashSet<Guid> domainsInVds = new HashSet<>();
        List<StorageDomain> storageDomainsToSync = data.getValue().stream().peek(storageDomain -> domainsInVds.add(storageDomain.getId())).filter(storageDomain -> proceedStorageDomain(storageDomain, masterVersion, storagePool)).collect(Collectors.toList());
        if (!storageDomainsToSync.isEmpty()) {
            getEventListener().syncStorageDomainsLuns(getCurrentVdsId(), storageDomainsToSync.stream().map(StorageDomain::getId).collect(Collectors.toList()));
        }
        for (final StorageDomain domainInDb : domainsInDb) {
            if (domainInDb.getStorageDomainType() != StorageDomainType.Master && domainInDb.getStatus() != StorageDomainStatus.Locked && !domainInDb.getStorageType().isCinderDomain() && !domainsInVds.contains(domainInDb.getId())) {
                // domain not attached to pool anymore
                storagePoolIsoMapDao.remove(new StoragePoolIsoMapId(domainInDb.getId(), storagePoolId));
            }
        }
    }
    domainsInMaintenanceCheck(domainsInDb, storagePool);
}
Also used : SpmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters) VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) StoragePoolDomainHelper(org.ovirt.engine.core.vdsbroker.storage.StoragePoolDomainHelper) VdsSpmIdMap(org.ovirt.engine.core.common.businessentities.VdsSpmIdMap) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) StorageDomainDynamicDao(org.ovirt.engine.core.dao.StorageDomainDynamicDao) ScheduledFuture(java.util.concurrent.ScheduledFuture) LoggerFactory(org.slf4j.LoggerFactory) NonOperationalReason(org.ovirt.engine.core.common.businessentities.NonOperationalReason) EventType(org.ovirt.engine.core.common.eventqueue.EventType) ConnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.ConnectStoragePoolVDSCommandParameters) OnTimerMethodAnnotation(org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation) VdsDao(org.ovirt.engine.core.dao.VdsDao) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) Map(java.util.Map) Event(org.ovirt.engine.core.common.eventqueue.Event) StoragePoolDao(org.ovirt.engine.core.dao.StoragePoolDao) SpmStartVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStartVDSCommandParameters) ThreadPoolUtil(org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil) AuditLogableImpl(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableImpl) EnumSet(java.util.EnumSet) ManagedScheduledExecutorService(javax.enterprise.concurrent.ManagedScheduledExecutorService) Instance(javax.enterprise.inject.Instance) GetStoragePoolInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetStoragePoolInfoVDSCommandParameters) RefObject(org.ovirt.engine.core.compat.RefObject) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) Collection(java.util.Collection) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StorageConstants(org.ovirt.engine.core.common.constants.StorageConstants) Set(java.util.Set) EventQueue(org.ovirt.engine.core.common.eventqueue.EventQueue) BusinessEntitiesDefinitions(org.ovirt.engine.core.common.businessentities.BusinessEntitiesDefinitions) Collectors(java.util.stream.Collectors) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) VdsStaticDao(org.ovirt.engine.core.dao.VdsStaticDao) VdsDynamicDao(org.ovirt.engine.core.dao.VdsDynamicDao) VDSNetworkException(org.ovirt.engine.core.vdsbroker.vdsbroker.VDSNetworkException) List(java.util.List) VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) VDSDomainsData(org.ovirt.engine.core.common.businessentities.VDSDomainsData) IVdsEventListener(org.ovirt.engine.core.common.businessentities.IVdsEventListener) PostConstruct(javax.annotation.PostConstruct) AuditLogType(org.ovirt.engine.core.common.AuditLogType) SpmStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStatusVDSCommandParameters) DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters) SpmStatusResult(org.ovirt.engine.core.common.businessentities.SpmStatusResult) SpmStopVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SpmStopVDSCommandParameters) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) TransportFactory(org.ovirt.engine.core.vdsbroker.TransportFactory) ResourceManager(org.ovirt.engine.core.vdsbroker.ResourceManager) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) StorageDomainStatus(org.ovirt.engine.core.common.businessentities.StorageDomainStatus) ThreadPools(org.ovirt.engine.core.utils.threadpool.ThreadPools) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) StoragePoolIsoMapDao(org.ovirt.engine.core.dao.StoragePoolIsoMapDao) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) LinkedList(java.util.LinkedList) StorageDomainStaticDao(org.ovirt.engine.core.dao.StorageDomainStaticDao) Pair(org.ovirt.engine.core.common.utils.Pair) VdsSpmIdMapDao(org.ovirt.engine.core.dao.VdsSpmIdMapDao) Config(org.ovirt.engine.core.common.config.Config) VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) StoragePoolStatus(org.ovirt.engine.core.common.businessentities.StoragePoolStatus) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) AuditLogDirector(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) ExceptionUtils(org.apache.commons.lang.exception.ExceptionUtils) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) SpmStatus(org.ovirt.engine.core.common.businessentities.SpmStatus) LockManager(org.ovirt.engine.core.utils.lock.LockManager) EventResult(org.ovirt.engine.core.common.eventqueue.EventResult) EngineError(org.ovirt.engine.core.common.errors.EngineError) TransactionScopeOption(org.ovirt.engine.core.compat.TransactionScopeOption) AuditLogable(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogable) TimeUnit(java.util.concurrent.TimeUnit) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) StorageDomainDao(org.ovirt.engine.core.dao.StorageDomainDao) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) AsyncTaskStatusEnum(org.ovirt.engine.core.common.businessentities.AsyncTaskStatusEnum) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) KeyValuePairCompat(org.ovirt.engine.core.compat.KeyValuePairCompat) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) VDSNetworkException(org.ovirt.engine.core.vdsbroker.vdsbroker.VDSNetworkException) Guid(org.ovirt.engine.core.compat.Guid) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) GetStoragePoolInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.GetStoragePoolInfoVDSCommandParameters) SpmStatusResult(org.ovirt.engine.core.common.businessentities.SpmStatusResult) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 2 with AsyncTaskStatus

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

the class AbstractBackendResource method getVdsmTasksStatus.

private CreationStatus getVdsmTasksStatus(ActionReturnValue result) {
    CreationStatus asyncStatus = null;
    QueryReturnValue monitorResult = runQuery(QueryType.GetTasksStatusesByTasksIDs, new GetTasksStatusesByTasksIDsParameters(result.getVdsmTaskIdList()));
    if (monitorResult != null && monitorResult.getSucceeded() && monitorResult.getReturnValue() != null) {
        Mapper<AsyncTaskStatus, CreationStatus> mapper = getMapper(AsyncTaskStatus.class, CreationStatus.class);
        for (AsyncTaskStatus task : asCollection(AsyncTaskStatus.class, monitorResult.getReturnValue())) {
            asyncStatus = mapper.map(task, asyncStatus);
        }
    }
    return asyncStatus;
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) GetTasksStatusesByTasksIDsParameters(org.ovirt.engine.core.common.queries.GetTasksStatusesByTasksIDsParameters) CreationStatus(org.ovirt.engine.api.model.CreationStatus)

Example 3 with AsyncTaskStatus

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

the class BackendStorageDomainTemplateResourceTest method doTestImportAsync.

private void doTestImportAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus actionStatus) throws Exception {
    setUpGetEntityExpectations(1, StorageDomainType.ImportExport, GUIDS[2]);
    setUpGetDataCenterByStorageDomainExpectations(GUIDS[3]);
    setUriInfo(setUpActionExpectations(ActionType.ImportVmTemplate, ImportVmTemplateParameters.class, new String[] { "ContainerId", "StorageDomainId", "SourceDomainId", "DestDomainId", "StoragePoolId", "ClusterId" }, new Object[] { TEMPLATE_ID, GUIDS[2], STORAGE_DOMAIN_ID, GUIDS[2], DATA_CENTER_ID, GUIDS[1] }, asList(GUIDS[1]), asList(new AsyncTaskStatus(asyncStatus))));
    StorageDomain storageDomain = new StorageDomain();
    storageDomain.setId(GUIDS[2].toString());
    org.ovirt.engine.api.model.Cluster cluster = new org.ovirt.engine.api.model.Cluster();
    cluster.setId(GUIDS[1].toString());
    Action action = new Action();
    action.setStorageDomain(storageDomain);
    action.setCluster(cluster);
    Response response = resource.doImport(action);
    verifyActionResponse(response, URL_BASE, true, null);
    action = (Action) response.getEntity();
    assertTrue(action.isSetStatus());
    assertEquals(actionStatus.value(), action.getStatus());
}
Also used : Action(org.ovirt.engine.api.model.Action) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Response(javax.ws.rs.core.Response) BackendStorageDomainTemplatesResourceTest.setUpStorageDomain(org.ovirt.engine.api.restapi.resource.BackendStorageDomainTemplatesResourceTest.setUpStorageDomain) StorageDomain(org.ovirt.engine.api.model.StorageDomain) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) ImportVmTemplateParameters(org.ovirt.engine.core.common.action.ImportVmTemplateParameters)

Example 4 with AsyncTaskStatus

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

the class BackendStorageDomainDisksResourceTest method testAddIdentifyStorageDomainByName.

@Test
public void testAddIdentifyStorageDomainByName() throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    setUpHttpHeaderExpectations("Expect", "201-created");
    setUpEntityQueryExpectations(QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Disk model = getModel();
    model.getStorageDomains().getStorageDomains().get(0).setId(null);
    model.getStorageDomains().getStorageDomains().get(0).setName("Storage_Domain_1");
    setUpCreationExpectations(ActionType.AddDisk, AddDiskParameters.class, new String[] {}, new Object[] {}, true, true, GUIDS[0], asList(storagePoolId), asList(new AsyncTaskStatus(AsyncTaskStatusEnum.finished)), QueryType.GetDiskByDiskId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { GUIDS[0] }, getEntity(0));
    Response response = collection.add(model);
    assertEquals(201, response.getStatus());
    assertTrue(response.getEntity() instanceof Disk);
    verifyModel((Disk) response.getEntity(), 0);
    assertNull(((Disk) response.getEntity()).getCreationStatus());
}
Also used : Response(javax.ws.rs.core.Response) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus) Disk(org.ovirt.engine.api.model.Disk) Test(org.junit.Test)

Example 5 with AsyncTaskStatus

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

the class BackendSnapshotsResourceTest method doTestAddAsync.

private void doTestAddAsync(AsyncTaskStatusEnum asyncStatus, CreationStatus creationStatus) throws Exception {
    setUriInfo(setUpBasicUriExpectations());
    String ovfData = "data";
    org.ovirt.engine.core.common.businessentities.Snapshot resultSnapshot0 = new org.ovirt.engine.core.common.businessentities.Snapshot();
    resultSnapshot0.setVmConfiguration(ovfData);
    resultSnapshot0.setId(SNAPSHOT_IDS[0]);
    setUpEntityQueryExpectations(QueryType.GetSnapshotBySnapshotId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { SNAPSHOT_IDS[0] }, resultSnapshot0);
    setUpCreationExpectations(ActionType.CreateSnapshotForVm, CreateSnapshotForVmParameters.class, new String[] { "Description", "VmId" }, new Object[] { DESCRIPTIONS[0], VM_ID }, true, true, GUIDS[0], asList(TASK_ID), asList(new AsyncTaskStatus(asyncStatus)), QueryType.GetAllVmSnapshotsByVmId, IdQueryParameters.class, new String[] { "Id" }, new Object[] { VM_ID }, getEntity(0));
    Snapshot snapshot = new Snapshot();
    snapshot.setDescription(DESCRIPTIONS[0]);
    Response response = collection.add(snapshot);
    assertEquals(202, response.getStatus());
    assertTrue(response.getEntity() instanceof Snapshot);
    Snapshot responseSnapshot = (Snapshot) response.getEntity();
    verifyModel(responseSnapshot, 0);
    verifyAllContent(responseSnapshot, ConfigurationType.OVF, ovfData);
    Snapshot created = (Snapshot) response.getEntity();
    assertNotNull(created.getCreationStatus());
    assertEquals(creationStatus.value(), created.getCreationStatus());
}
Also used : Response(javax.ws.rs.core.Response) Snapshot(org.ovirt.engine.api.model.Snapshot) AsyncTaskStatus(org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)

Aggregations

AsyncTaskStatus (org.ovirt.engine.core.common.businessentities.AsyncTaskStatus)41 Response (javax.ws.rs.core.Response)26 Test (org.junit.Test)15 Template (org.ovirt.engine.api.model.Template)12 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)9 Action (org.ovirt.engine.api.model.Action)7 Disk (org.ovirt.engine.api.model.Disk)7 Guid (org.ovirt.engine.core.compat.Guid)7 StorageDomain (org.ovirt.engine.api.model.StorageDomain)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CreationStatus (org.ovirt.engine.api.model.CreationStatus)3 Vm (org.ovirt.engine.api.model.Vm)3 Collections (java.util.Collections)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Fault (org.ovirt.engine.api.model.Fault)2 SPMTask (org.ovirt.engine.core.bll.tasks.interfaces.SPMTask)2 SpmStatusResult (org.ovirt.engine.core.common.businessentities.SpmStatusResult)2