Search in sources :

Example 76 with QueryParametersBase

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

the class FrontendTest method testrunMultipleQueries_multiple_success.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple search query, with multiple requests, with *win* or *lin* as the parameter,
 *   searching for VMs</li>
 *   <li>Return success, the success status is succeeded</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunMultipleQueries_multiple_success() {
    // Don't immediately call process until both queries are in the queue.
    fakeScheduler.setThreshold(2);
    ArrayList<QueryType> queryTypeList = new ArrayList<>();
    queryTypeList.add(QueryType.Search);
    queryTypeList.add(QueryType.Search);
    ArrayList<QueryParametersBase> queryParamsList = new ArrayList<>();
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*win*", SearchType.VM));
    // $NON-NLS-1$
    queryParamsList.add(new SearchParameters("*lin*", SearchType.VM));
    // $NON-NLS-1$
    frontend.runMultipleQueries(queryTypeList, queryParamsList, mockMultipleQueryCallback, ASYNC_OPERATION_TARGET);
    verify(mockService).runMultipleQueries(eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
    // Call the failure handler.
    List<QueryReturnValue> result = new ArrayList<>();
    result.add(new QueryReturnValue());
    result.get(0).setSucceeded(true);
    result.add(new QueryReturnValue());
    result.get(1).setSucceeded(true);
    ArgumentCaptor<FrontendMultipleQueryAsyncResult> multipleResultCaptor = ArgumentCaptor.forClass(FrontendMultipleQueryAsyncResult.class);
    callbackMultipleQueries.getValue().onSuccess((ArrayList<QueryReturnValue>) result);
    verify(mockMultipleQueryCallback).executed(multipleResultCaptor.capture());
    assertEquals(// $NON-NLS-1$
    "callback result much match", // $NON-NLS-1$
    result, multipleResultCaptor.getValue().getReturnValues());
    verifyAsyncQuerySucceeded();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ArrayList(java.util.ArrayList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) QueryType(org.ovirt.engine.core.common.queries.QueryType) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) Test(org.junit.Test)

Example 77 with QueryParametersBase

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

the class FrontendTest method testrunQuery_success_succeeded_multiple_same_eventshandler_noconverter.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a search query, with *win* as the parameter, searching for VMs</li>
 *   <li>Immediately, before returning a result, call the same run query again</li>
 *   <li>Return success, the success status is succeeded</li>
 *   <li>No success converter defined</li>
 *   <li>Make sure that the result callback is called only once</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunQuery_success_succeeded_multiple_same_eventshandler_noconverter() {
    Object mockModel = new Object();
    when(mockAsyncQuery.getModel()).thenReturn(mockModel);
    // $NON-NLS-1$
    QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false);
    verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture());
    QueryReturnValue mockReturnValue = new QueryReturnValue();
    // $NON-NLS-1$
    mockReturnValue.setExceptionString("USER_IS_NOT_LOGGED_IN");
    // Return value set to success
    mockReturnValue.setSucceeded(true);
    callback.getValue().onSuccess(mockReturnValue);
    verify(mockAsyncCallback).onSuccess(mockReturnValue);
    verifyAsyncQuerySucceeded();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) Test(org.junit.Test)

Example 78 with QueryParametersBase

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

the class ChangeQuotaModel method init.

public void init(final ArrayList<DiskImage> disks) {
    ArrayList<QueryType> queryTypeList = new ArrayList<>();
    ArrayList<QueryParametersBase> queryParamsList = new ArrayList<>();
    Set<Guid> storageDomainIdSet = new HashSet<>();
    for (DiskImage diskImage : disks) {
        for (Guid storageDomainId : diskImage.getStorageIds()) {
            storageDomainIdSet.add(storageDomainId);
        }
    }
    for (Guid storageDomainId : storageDomainIdSet) {
        queryParamsList.add(new IdQueryParameters(storageDomainId));
        queryTypeList.add(QueryType.GetAllRelevantQuotasForStorage);
    }
    Frontend.getInstance().runMultipleQueries(queryTypeList, queryParamsList, result -> {
        Map<Guid, List<Quota>> storageDomainIdMap = new HashMap<>();
        for (int i = 0; i < result.getReturnValues().size(); i++) {
            QueryReturnValue retVal = result.getReturnValues().get(i);
            Guid storageId = ((IdQueryParameters) result.getParameters().get(i)).getId();
            storageDomainIdMap.put(storageId, (ArrayList<Quota>) retVal.getReturnValue());
        }
        ArrayList<ChangeQuotaItemModel> list = new ArrayList<>();
        Guid storageDomainId;
        for (DiskImage diskImage : disks) {
            for (int i = 0; i < diskImage.getStorageIds().size(); i++) {
                storageDomainId = diskImage.getStorageIds().get(i);
                ChangeQuotaItemModel itemModel = new ChangeQuotaItemModel();
                itemModel.setEntity(diskImage);
                itemModel.getObject().setEntity(diskImage.getDiskAlias());
                itemModel.getCurrentQuota().setEntity(diskImage.getQuotaNames() != null && diskImage.getQuotaNames().size() >= i + 1 ? diskImage.getQuotaNames().get(i) : null);
                itemModel.setStorageDomainId(storageDomainId);
                itemModel.setStorageDomainName(diskImage.getStoragesNames().get(i));
                itemModel.getQuota().setItems(storageDomainIdMap.get(storageDomainId));
                for (Quota quota : itemModel.getQuota().getItems()) {
                    if (!quota.getId().equals(diskImage.getQuotaId())) {
                        itemModel.getQuota().setSelectedItem(quota);
                        break;
                    }
                }
                list.add(itemModel);
            }
        }
        ChangeQuotaModel.this.setItems(list);
        ChangeQuotaModel.this.stopProgress();
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) Quota(org.ovirt.engine.core.common.businessentities.Quota) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) ArrayList(java.util.ArrayList) List(java.util.List) QueryType(org.ovirt.engine.core.common.queries.QueryType) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) HashSet(java.util.HashSet)

Example 79 with QueryParametersBase

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

the class EditProviderModel method preSave.

@Override
protected void preSave() {
    if (!stringsEqualIgnoreCase(getUrl().getEntity(), oldUrl)) {
        ArrayList<QueryType> queryTypes = new ArrayList<>();
        ArrayList<QueryParametersBase> queryParams = new ArrayList<>();
        final Set<VdcObjectType> providedTypes = provider.getType().getProvidedTypes();
        if (providedTypes.contains(VdcObjectType.Network)) {
            queryTypes.add(QueryType.GetAllNetworksForProvider);
            queryParams.add(new IdQueryParameters(provider.getId()));
        }
        if (!queryTypes.isEmpty()) {
            startProgress();
            Frontend.getInstance().runMultipleQueries(queryTypes, queryParams, result -> {
                stopProgress();
                Iterator<QueryReturnValue> i = result.getReturnValues().iterator();
                if (providedTypes.contains(VdcObjectType.Network)) {
                    providedNetworks = i.next().getReturnValue();
                }
                showConfirmation();
            });
            return;
        }
    }
    actualSave();
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) QueryType(org.ovirt.engine.core.common.queries.QueryType)

Example 80 with QueryParametersBase

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

the class AdElementListModel method searchMyGroups.

public void searchMyGroups() {
    getSearchInProgress().setEntity(true);
    AsyncQuery<QueryReturnValue> asyncQuery = new AsyncQuery<>(queryReturnValue -> {
        if (handleQueryError(queryReturnValue)) {
            return;
        }
        HashSet<String> excludeUsers = new HashSet<>();
        if (getExcludeItems() != null) {
            for (DbUser item : getExcludeItems()) {
                excludeUsers.add(item.getExternalId());
            }
        }
        setgroups(new ArrayList<>());
        addGroupsToModel(queryReturnValue, excludeUsers);
        setusers(new ArrayList<>());
        onUserAndAdGroupsLoaded();
    });
    asyncQuery.setHandleFailure(true);
    Frontend.getInstance().runQuery(QueryType.GetDirectoryGroupsForUser, new QueryParametersBase(), asyncQuery);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) HashSet(java.util.HashSet) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser)

Aggregations

QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)89 ArrayList (java.util.ArrayList)41 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)40 QueryType (org.ovirt.engine.core.common.queries.QueryType)37 Test (org.junit.Test)33 StorageServerConnectionQueryParametersBase (org.ovirt.engine.core.common.queries.StorageServerConnectionQueryParametersBase)22 SearchParameters (org.ovirt.engine.core.common.queries.SearchParameters)18 List (java.util.List)15 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)15 Guid (org.ovirt.engine.core.compat.Guid)13 HashMap (java.util.HashMap)11 StatusCodeException (com.google.gwt.user.client.rpc.StatusCodeException)9 HashSet (java.util.HashSet)7 Map (java.util.Map)6 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)6 Frontend (org.ovirt.engine.ui.frontend.Frontend)6 Collection (java.util.Collection)5 Quota (org.ovirt.engine.core.common.businessentities.Quota)5 DbUser (org.ovirt.engine.core.common.businessentities.aaa.DbUser)5 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)5