Search in sources :

Example 1 with GetEntitiesWithPermittedActionParameters

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

the class AsyncDataProvider method getClustersWithPermittedAction.

public void getClustersWithPermittedAction(AsyncQuery<List<Cluster>> aQuery, ActionGroup actionGroup, final boolean supportsVirtService, final boolean supportsGlusterService) {
    aQuery.converterCallback = source -> {
        if (source != null) {
            ArrayList<Cluster> list = (ArrayList<Cluster>) source;
            return getClusterByServiceList(list, supportsVirtService, supportsGlusterService);
        }
        return new ArrayList<>();
    };
    GetEntitiesWithPermittedActionParameters getEntitiesWithPermittedActionParameters = new GetEntitiesWithPermittedActionParameters();
    getEntitiesWithPermittedActionParameters.setActionGroup(actionGroup);
    Frontend.getInstance().runQuery(QueryType.GetClustersWithPermittedAction, getEntitiesWithPermittedActionParameters, aQuery);
}
Also used : GetEntitiesWithPermittedActionParameters(org.ovirt.engine.core.common.queries.GetEntitiesWithPermittedActionParameters) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster)

Example 2 with GetEntitiesWithPermittedActionParameters

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

the class VMConsoleProxyServlet method availableConsoles.

private List<Map<String, String>> availableConsoles(String userIdAsString) {
    List<Map<String, String>> jsonVms = new ArrayList<>();
    Guid userGuid = null;
    try {
        if (StringUtils.isNotEmpty(userIdAsString)) {
            userGuid = Guid.createGuidFromString(userIdAsString);
        }
    } catch (IllegalArgumentException e) {
        log.debug("Could not read User GUID");
    }
    if (userGuid != null) {
        ActionReturnValue loginResult = backend.runInternalAction(ActionType.LoginOnBehalf, new LoginOnBehalfParameters(userGuid));
        if (!loginResult.getSucceeded()) {
            throw new RuntimeException("Unable to create session using LoginOnBehalf");
        }
        String engineSessionId = loginResult.getActionReturnValue();
        try {
            QueryReturnValue retVms = backend.runInternalQuery(QueryType.GetAllVmsForUserAndActionGroup, new GetEntitiesWithPermittedActionParameters(ActionGroup.CONNECT_TO_SERIAL_CONSOLE), new EngineContext().withSessionId(engineSessionId));
            if (retVms != null) {
                List<VM> vmsList = retVms.getReturnValue();
                for (VM vm : vmsList) {
                    Map<String, String> jsonVm = new HashMap<>();
                    if (vm.getRunOnVds() != null) {
                        // TODO: avoid one query per loop. Bulk query?
                        QueryReturnValue retValue = backend.runInternalQuery(QueryType.GetVdsByVdsId, new IdQueryParameters(vm.getRunOnVds()));
                        if (retValue != null && retValue.getReturnValue() != null) {
                            VDS vds = retValue.getReturnValue();
                            jsonVm.put("vmid", vm.getId().toString());
                            jsonVm.put("vmname", vm.getName());
                            jsonVm.put("host", vds.getHostName());
                            /* there is only one serial console, no need and no way to distinguish them */
                            jsonVm.put("console", "default");
                            jsonVms.add(jsonVm);
                        }
                    }
                }
            }
        } finally {
            backend.runInternalAction(ActionType.LogoutSession, new ActionParametersBase(engineSessionId));
        }
    }
    return jsonVms;
}
Also used : GetEntitiesWithPermittedActionParameters(org.ovirt.engine.core.common.queries.GetEntitiesWithPermittedActionParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) LoginOnBehalfParameters(org.ovirt.engine.core.common.action.LoginOnBehalfParameters) VM(org.ovirt.engine.core.common.businessentities.VM) EngineContext(org.ovirt.engine.core.bll.context.EngineContext) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)2 GetEntitiesWithPermittedActionParameters (org.ovirt.engine.core.common.queries.GetEntitiesWithPermittedActionParameters)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 EngineContext (org.ovirt.engine.core.bll.context.EngineContext)1 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 LoginOnBehalfParameters (org.ovirt.engine.core.common.action.LoginOnBehalfParameters)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 VM (org.ovirt.engine.core.common.businessentities.VM)1 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)1 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)1 Guid (org.ovirt.engine.core.compat.Guid)1