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);
}
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);
});
}
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());
}
}
});
}
}
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);
}
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());
}
}
}
}
}
Aggregations