Search in sources :

Example 11 with QueryType

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

the class AbstractGwtDynamicHostPageServletTest method testRunQuery_GetUserBySessionId.

@Test
public void testRunQuery_GetUserBySessionId() {
    // $NON-NLS-1$
    String sessionId = "sessionId";
    QueryType queryType = QueryType.GetUserBySessionId;
    Object result = testServlet.runQuery(queryType, mockQueryParams, sessionId);
    assertEquals(result, mockUser);
    verify(mockQueryParams).setSessionId(sessionId);
    verify(mockQueryParams).setFiltered(testServlet.filterQueries());
    verify(mockBackend).runQuery(queryType, mockQueryParams);
}
Also used : QueryType(org.ovirt.engine.core.common.queries.QueryType) Test(org.junit.Test)

Example 12 with QueryType

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

the class RegisterEntityModel method updateClusterQuota.

private void updateClusterQuota(List<Cluster> clusters) {
    if (!isQuotaEnabled()) {
        return;
    }
    List<QueryType> queries = new ArrayList<>();
    List<QueryParametersBase> params = new ArrayList<>();
    for (Cluster cluster : clusters) {
        queries.add(QueryType.GetAllRelevantQuotasForCluster);
        params.add(new IdQueryParameters(cluster.getId()));
    }
    Frontend.getInstance().runMultipleQueries(queries, params, result -> {
        Map<Guid, List<Quota>> clusterQuotasMap = new HashMap<>();
        for (int i = 0; i < result.getReturnValues().size(); i++) {
            List<Quota> quotas = result.getReturnValues().get(i).getReturnValue();
            Guid clusterId = ((IdQueryParameters) result.getParameters().get(i)).getId();
            clusterQuotasMap.put(clusterId, quotas);
        }
        getClusterQuotasMap().setEntity(clusterQuotasMap);
    });
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid) 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)

Example 13 with QueryType

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

the class VmListModel method initRemoveDisksCheckboxes.

private void initRemoveDisksCheckboxes(final Map<Guid, EntityModel> vmsMap) {
    ArrayList<QueryParametersBase> params = new ArrayList<>();
    ArrayList<QueryType> queries = new ArrayList<>();
    for (Entry<Guid, EntityModel> entry : vmsMap.entrySet()) {
        if (entry.getValue().getIsChangable()) {
            // No point in fetching VM disks from ones that already determined
            // is unchangeable since they are already initialized
            params.add(new IdQueryParameters(entry.getKey()));
            queries.add(QueryType.GetAllDisksByVmId);
        }
    }
    // revise when refactoring org.ovirt.engine.ui.Frontend to support runMultipleQuery with a single query
    if (!params.isEmpty()) {
        Frontend.getInstance().runMultipleQueries(queries, params, result -> {
            for (int i = 0; i < result.getReturnValues().size(); i++) {
                if (result.getReturnValues().get(i).getSucceeded()) {
                    Guid vmId = ((IdQueryParameters) result.getParameters().get(i)).getId();
                    initRemoveDisksChecboxesPost(vmId, (List<Disk>) result.getReturnValues().get(i).getReturnValue());
                }
            }
        });
    }
}
Also used : IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) EntityModel(org.ovirt.engine.ui.uicommonweb.models.EntityModel) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) Guid(org.ovirt.engine.core.compat.Guid) QueryType(org.ovirt.engine.core.common.queries.QueryType) Disk(org.ovirt.engine.core.common.businessentities.storage.Disk)

Example 14 with QueryType

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

the class VmInstanceTypeManager method updateNetworkInterfacesByTemplate.

public void updateNetworkInterfacesByTemplate(VmBase vmBase) {
    QueryType queryType = (vmBase instanceof VmTemplate) ? QueryType.GetTemplateInterfacesByTemplateId : QueryType.GetVmInterfacesByVmId;
    AsyncQuery<QueryReturnValue> query = new AsyncQuery<>(returnValue -> {
        if (returnValue == null) {
            return;
        }
        List<VmNetworkInterface> nics = returnValue.getReturnValue();
        updateNetworkInterfaces(getNetworkProfileBehavior(), nics);
    });
    Frontend.getInstance().runQuery(queryType, new IdQueryParameters(vmBase.getId()), query);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) AsyncQuery(org.ovirt.engine.ui.frontend.AsyncQuery) QueryType(org.ovirt.engine.core.common.queries.QueryType)

Example 15 with QueryType

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

the class QueriesCommandBaseTest method testPermissionChecking.

/**
 * Tests Admin permission check
 */
@Test
public void testPermissionChecking() throws Exception {
    boolean[] booleans = { true, false };
    for (QueryType queryType : QueryType.values()) {
        for (boolean isFiltered : booleans) {
            for (boolean isUserAdmin : booleans) {
                for (boolean isInternalExecution : booleans) {
                    boolean shouldBeAbleToRunQuery;
                    if (isFiltered) {
                        shouldBeAbleToRunQuery = !queryType.isAdmin();
                    } else {
                        shouldBeAbleToRunQuery = isInternalExecution || isUserAdmin;
                    }
                    log.debug("Running on query: {}", this);
                    String sessionId = getClass().getSimpleName();
                    // Mock parameters
                    when(params.isFiltered()).thenReturn(isFiltered);
                    when(params.getSessionId()).thenReturn(sessionId);
                    Guid guid = mock(Guid.class);
                    // Set up the user id env.
                    when(mockDbUser.getId()).thenReturn(guid);
                    when(mockDbUser.isAdmin()).thenReturn(isUserAdmin);
                    when(mockSessionDataContainer.getUser(sessionId, false)).thenReturn(mockDbUser);
                    // Mock-Set the query as admin/user
                    QueriesCommandBase<?> query = mockQuery();
                    TestHelperQueriesCommandType.setQueryTypeFieldValue(query, queryType);
                    query.setInternalExecution(isInternalExecution);
                    query.executeCommand();
                    assertEquals("Running with type=" + queryType + " isUserAdmin=" + isUserAdmin + " isFiltered=" + isFiltered + " isInternalExecution=" + isInternalExecution + "\n " + "Query should succeed is: ", shouldBeAbleToRunQuery, query.getQueryReturnValue().getSucceeded());
                }
            }
        }
    }
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) QueryType(org.ovirt.engine.core.common.queries.QueryType) Test(org.junit.Test)

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