Search in sources :

Example 46 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class StorageDomainValidatorTest method validRunningVmsWithUnpluggedDisksForBackupDomain.

@Test
public void validRunningVmsWithUnpluggedDisksForBackupDomain() {
    // VM1
    VM vm1 = new VM();
    vm1.setName("firstVM");
    Map<Guid, Disk> attachedDisksForVm1 = new HashMap<>();
    DiskImage diskVm1 = new DiskImage();
    diskVm1.setStorageIds(new ArrayList<>(Collections.singletonList(domain.getId())));
    diskVm1.setPlugged(false);
    attachedDisksForVm1.put(Guid.newGuid(), diskVm1);
    vm1.setDiskMap(attachedDisksForVm1);
    List<VM> runningVMs = new ArrayList<>();
    runningVMs.add(vm1);
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(runningVMs);
    QueryReturnValue ret = new QueryReturnValue();
    ret.setReturnValue(new ArrayList<VmBase>());
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) Guid(org.ovirt.engine.core.compat.Guid) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Test(org.junit.Test)

Example 47 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class StorageDomainValidatorTest method validVmLeasesForBackupDomain.

@Test
public void validVmLeasesForBackupDomain() {
    when(vmDao.getAllActiveForStorageDomain(any())).thenReturn(Collections.EMPTY_LIST);
    QueryReturnValue ret = new QueryReturnValue();
    List<VmBase> vmLeases = new ArrayList<>();
    VM vm1 = new VM();
    vm1.setName("firstVM");
    vm1.setStatus(VMStatus.Down);
    vmLeases.add(vm1.getStaticData());
    ret.setReturnValue(vmLeases);
    ret.setSucceeded(true);
    doReturn(ret).when(validator).getEntitiesWithLeaseIdForStorageDomain(any());
    when(vmDao.get(vm1.getId())).thenReturn(vm1);
    assertThat(validator.isRunningVmsOrVmLeasesForBackupDomain(vmHandler), isValid());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VM(org.ovirt.engine.core.common.businessentities.VM) VmBase(org.ovirt.engine.core.common.businessentities.VmBase) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 48 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class BackendApiResource method setAuthenticatedUser.

/**
 * Set a link to the user of the current session
 * (the 'authenticated user') in the API object.
 * This link enables users a convenient way to see
 * which is the logged-in user, using the system.
 */
private void setAuthenticatedUser(Api api) {
    QueryReturnValue returnValue = runQuery(QueryType.GetUserBySessionId, new QueryParametersBase());
    DbUser authenticatedUser = (DbUser) returnValue.getReturnValue();
    User user = new User();
    user.setId(authenticatedUser.getId().toString());
    LinkHelper.addLinks(user);
    api.setAuthenticatedUser(user);
    api.setEffectiveUser(user);
// currently the authenticated and effective users are the same one,
// but if and when impersonation is introduced, they may be different.
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) User(org.ovirt.engine.api.model.User) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Example 49 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue 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 50 with QueryReturnValue

use of org.ovirt.engine.core.common.queries.QueryReturnValue in project ovirt-engine by oVirt.

the class BackendAssignedPermissionsResource method getUserById.

public DbUser getUserById(Guid userId) {
    IdQueryParameters queryParameters = new IdQueryParameters(userId);
    QueryReturnValue userQueryResponse = runQuery(QueryType.GetAnyDbUserByUserId, queryParameters);
    DbUser returnValue = null;
    if (userQueryResponse != null && userQueryResponse.getSucceeded()) {
        returnValue = userQueryResponse.getReturnValue();
    }
    return returnValue;
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Aggregations

QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)265 ArrayList (java.util.ArrayList)123 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)97 QueryType (org.ovirt.engine.core.common.queries.QueryType)85 List (java.util.List)74 Guid (org.ovirt.engine.core.compat.Guid)66 Frontend (org.ovirt.engine.ui.frontend.Frontend)64 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)54 VM (org.ovirt.engine.core.common.businessentities.VM)49 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)47 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)42 HashMap (java.util.HashMap)40 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)39 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)39 Test (org.junit.Test)38 Collection (java.util.Collection)34 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)33 Map (java.util.Map)31 ActionType (org.ovirt.engine.core.common.action.ActionType)31 VDS (org.ovirt.engine.core.common.businessentities.VDS)31