Search in sources :

Example 31 with QueryType

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

the class FrontendTest method testrunMultipleQueries_404_failure.

/**
 * Run the following test case.
 * <ol>
 *   <li>Run a multiple search query, with only multiple requests, with *win* / *lin* as the parameter,
 *   searching for VMs</li>
 *   <li>Force a failure with an HTTP status code = 404</li>
 *   <li>Check to make sure the appropriate query start and query complete events are fired</li>
 * </ol>
 */
@Test
public void testrunMultipleQueries_404_failure() {
    // Don't immediately call process until both queries are in the queue.
    fakeScheduler.setThreshold(2);
    when(mockConstants.requestToServerFailedWithCode()).thenReturn(// $NON-NLS-1$
    "A Request to the Server failed with the following Status Code");
    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);
    StatusCodeException exception = new StatusCodeException(HttpServletResponse.SC_NOT_FOUND, // $NON-NLS-1$
    "404 status code");
    // Repeat 4 times, because of retries.
    for (int i = 1; i < RETRY_COUNT; i++) {
        // Reset the count so we can re-add both entries again.
        fakeScheduler.resetCount();
        verify(mockService, times(i)).runMultipleQueries(eq(queryTypeList), eq(queryParamsList), callbackMultipleQueries.capture());
        // Call the failure handler.
        callbackMultipleQueries.getValue().onFailure(exception);
    }
    ArgumentCaptor<FrontendFailureEventArgs> eventArgs = ArgumentCaptor.forClass(FrontendFailureEventArgs.class);
    verify(mockFrontendFailureEvent).raise(eq(Frontend.class), eventArgs.capture());
    assertEquals(// $NON-NLS-1$
    "Message text didn't match", // $NON-NLS-1$
    "A Request to the Server failed with the following Status Code: 404", eventArgs.getValue().getMessages().get(0).getText());
    verifyAsyncQueryFailed();
}
Also used : SearchParameters(org.ovirt.engine.core.common.queries.SearchParameters) ArrayList(java.util.ArrayList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) StatusCodeException(com.google.gwt.user.client.rpc.StatusCodeException) QueryType(org.ovirt.engine.core.common.queries.QueryType) Test(org.junit.Test)

Example 32 with QueryType

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

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

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

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

the class Frontend method runMultipleQueries.

/**
 * Run multiple queries in a single request to the back-end.
 * @param queryTypeList A list of {@code QueryType}s.
 * @param queryParamsList A list of parameters associated with each query.
 * @param callback The callback to call when the query completes.
 * @param state The state object.
 */
public void runMultipleQueries(final List<QueryType> queryTypeList, final List<QueryParametersBase> queryParamsList, final IFrontendMultipleQueryAsyncCallback callback, final Object state) {
    VdcOperationCallbackList<VdcOperation<QueryType, QueryParametersBase>, List<QueryReturnValue>> multiCallback = new VdcOperationCallbackList<VdcOperation<QueryType, QueryParametersBase>, List<QueryReturnValue>>() {

        @Override
        public void onSuccess(final List<VdcOperation<QueryType, QueryParametersBase>> operationList, final List<QueryReturnValue> resultObject) {
            // $NON-NLS-1$
            logger.finer("Succesful returned result from runMultipleQueries!");
            FrontendMultipleQueryAsyncResult f = new FrontendMultipleQueryAsyncResult(queryTypeList, queryParamsList, resultObject);
            callback.executed(f);
            fireAsyncQuerySucceededEvent(state);
        }

        @Override
        public void onFailure(final List<VdcOperation<QueryType, QueryParametersBase>> operationList, final Throwable caught) {
            try {
                if (ignoreFailure(caught)) {
                    return;
                }
                // $NON-NLS-1$
                logger.log(Level.SEVERE, "Failed to execute runMultipleQueries: " + caught, caught);
                FrontendMultipleQueryAsyncResult f = new FrontendMultipleQueryAsyncResult(queryTypeList, queryParamsList, null);
                failureEventHandler(caught);
                callback.executed(f);
            } finally {
                fireAsyncQueryFailedEvent(state);
            }
        }
    };
    List<VdcOperation<?, ?>> operationList = new ArrayList<>();
    for (int i = 0; i < queryTypeList.size(); i++) {
        QueryParametersBase parameters = queryParamsList.get(i);
        // Why do we do this?
        parameters.setRefresh(false);
        initQueryParamsFilter(parameters);
        operationList.add(new VdcOperation<>(queryTypeList.get(i), parameters, true, multiCallback, false));
    }
    fireAsyncOperationStartedEvent(state);
    getOperationManager().addOperationList(operationList);
}
Also used : VdcOperation(org.ovirt.engine.ui.frontend.communication.VdcOperation) ArrayList(java.util.ArrayList) FrontendMultipleQueryAsyncResult(org.ovirt.engine.ui.uicompat.FrontendMultipleQueryAsyncResult) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) VdcOperationCallbackList(org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList) QueryType(org.ovirt.engine.core.common.queries.QueryType)

Aggregations

QueryType (org.ovirt.engine.core.common.queries.QueryType)39 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)33 ArrayList (java.util.ArrayList)32 Test (org.junit.Test)22 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)21 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)15 Guid (org.ovirt.engine.core.compat.Guid)9 List (java.util.List)8 SearchParameters (org.ovirt.engine.core.common.queries.SearchParameters)6 HashMap (java.util.HashMap)5 ActionType (org.ovirt.engine.core.common.action.ActionType)5 Quota (org.ovirt.engine.core.common.businessentities.Quota)5 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)5 VM (org.ovirt.engine.core.common.businessentities.VM)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)4 StatusCodeException (com.google.gwt.user.client.rpc.StatusCodeException)3 Map (java.util.Map)3 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)3 Disk (org.ovirt.engine.core.common.businessentities.storage.Disk)3 Frontend (org.ovirt.engine.ui.frontend.Frontend)3