Search in sources :

Example 56 with QueryReturnValue

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

the class BackendVmKatelloErrataResource method list.

@Override
public KatelloErrata list() {
    ErrataData errataData = null;
    try {
        QueryReturnValue returnValue = runQuery(QueryType.GetErrataForVm, new GetErrataCountsParameters(asGuid(vmId)));
        if (!returnValue.getSucceeded()) {
            backendFailure(returnValue.getExceptionString());
        }
        errataData = returnValue.getReturnValue();
    } catch (Exception e) {
        handleError(e, false);
    }
    if (errataData == null) {
        return new KatelloErrata();
    }
    return mapCollection(errataData.getErrata());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ErrataData(org.ovirt.engine.core.common.businessentities.ErrataData) GetErrataCountsParameters(org.ovirt.engine.core.common.queries.GetErrataCountsParameters) KatelloErrata(org.ovirt.engine.api.model.KatelloErrata)

Example 57 with QueryReturnValue

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

the class BackendOpenStackNetworksResource method getBackendCollection.

private Map<Network, Set<Guid>> getBackendCollection() {
    try {
        IdQueryParameters parameters = new IdQueryParameters(asGuid(providerId));
        QueryReturnValue result = runQuery(QueryType.GetAllExternalNetworksOnProvider, parameters);
        if (!result.getSucceeded()) {
            backendFailure(result.getExceptionString());
        }
        return result.getReturnValue();
    } catch (Exception exception) {
        return handleError(exception, false);
    }
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters)

Example 58 with QueryReturnValue

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

the class StorageDomainHelper method addAttachedDataCenterReferences.

/**
 * Adds to the given Storage Domain the references to the Data Centers it is attached to.
 *
 * @param resource the resource that will be used to run the required queries
 * @param model the model of the Storage Domain where the references will be added
 */
public static void addAttachedDataCenterReferences(BackendResource resource, StorageDomain model) {
    // Note that this implementation is far from efficient, as we are retrieving all the content of the Storage
    // Domains and immediately discarding everything but the identifiers of the Data Centers. It would be better to
    // have a query that returns only the identifiers.
    Guid id = Guid.createGuidFromString(model.getId());
    QueryReturnValue result = resource.runQuery(QueryType.GetStorageDomainListById, new IdQueryParameters(id));
    if (result != null && result.getSucceeded()) {
        List<org.ovirt.engine.core.common.businessentities.StorageDomain> storageDomains = result.getReturnValue();
        if (CollectionUtils.isNotEmpty(storageDomains)) {
            DataCenters dataCenters = new DataCenters();
            for (org.ovirt.engine.core.common.businessentities.StorageDomain storageDomain : storageDomains) {
                DataCenter dataCenter = new DataCenter();
                dataCenter.setId(storageDomain.getStoragePoolId().toString());
                dataCenters.getDataCenters().add(dataCenter);
            }
            model.setDataCenters(dataCenters);
        }
    }
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) StorageDomain(org.ovirt.engine.api.model.StorageDomain) DataCenters(org.ovirt.engine.api.model.DataCenters) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) DataCenter(org.ovirt.engine.api.model.DataCenter)

Example 59 with QueryReturnValue

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

the class BackendHostResourceTest method testIscsiDiscover.

@Test
public void testIscsiDiscover() throws Exception {
    IscsiDetails iscsiDetails = new IscsiDetails();
    iscsiDetails.setAddress(ISCSI_SERVER_ADDRESS);
    iscsiDetails.setPort(ISCSI_PORT_INT);
    iscsiDetails.setUsername(ISCSI_USER_NAME);
    iscsiDetails.setPassword(ISCSI_USER_PASS);
    Action action = new Action();
    action.setIscsi(iscsiDetails);
    QueryReturnValue queryResult = new QueryReturnValue();
    queryResult.setSucceeded(true);
    when(backend.runQuery(eq(QueryType.DiscoverSendTargets), eqParams(DiscoverSendTargetsQueryParameters.class, addSession("VdsId", "Connection.Connection", "Connection.Port", "Connection.UserName", "Connection.Password"), addSession(GUIDS[0], ISCSI_SERVER_ADDRESS, ISCSI_PORT_STRING, ISCSI_USER_NAME, ISCSI_USER_PASS)))).thenReturn(queryResult);
    enqueueInteraction(() -> verify(backend, atLeastOnce()).runQuery(eq(QueryType.DiscoverSendTargets), eqParams(DiscoverSendTargetsQueryParameters.class, addSession("VdsId", "Connection.Connection", "Connection.Port", "Connection.UserName", "Connection.Password"), addSession(GUIDS[0], ISCSI_SERVER_ADDRESS, ISCSI_PORT_STRING, ISCSI_USER_NAME, ISCSI_USER_PASS))));
    resource.iscsiDiscover(action);
}
Also used : Action(org.ovirt.engine.api.model.Action) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IscsiDetails(org.ovirt.engine.api.model.IscsiDetails) DiscoverSendTargetsQueryParameters(org.ovirt.engine.core.common.queries.DiscoverSendTargetsQueryParameters) Test(org.junit.Test)

Example 60 with QueryReturnValue

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

the class BackendMacPoolsResourceTest method setUpMacPoolsQueryExpectations.

private void setUpMacPoolsQueryExpectations(Object failure) {
    QueryReturnValue queryResult = new QueryReturnValue();
    queryResult.setSucceeded(failure == null);
    List<org.ovirt.engine.core.common.businessentities.MacPool> entities = new ArrayList<>();
    if (failure == null) {
        for (int i = 0; i < NAMES.length; i++) {
            entities.add(getEntity(i));
        }
        queryResult.setReturnValue(entities);
    } else {
        if (failure instanceof String) {
            queryResult.setExceptionString((String) failure);
            setUpL10nExpectations((String) failure);
        } else if (failure instanceof Exception) {
            when(backend.runQuery(eq(listQueryType), any())).thenThrow((Exception) failure);
            return;
        }
    }
    when(backend.runQuery(eq(listQueryType), any())).thenReturn(queryResult);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) MacPool(org.ovirt.engine.api.model.MacPool) ArrayList(java.util.ArrayList) WebApplicationException(javax.ws.rs.WebApplicationException)

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