public static void serialize(SerializationStreamWriter streamWriter, QueryReturnValue instance) throws SerializationException { streamWriter.writeBoolean(instance.getSucceeded()); streamWriter.writeString(instance.getExceptionString()); ObjectSerializer.serialize(streamWriter, instance.getReturnValue()); }
private QueryReturnValue generateDescriptorResponse() throws Exception { org.ovirt.engine.core.common.businessentities.GraphicsType graphicsType = BackendGraphicsConsoleHelper.asGraphicsType(consoleId); ConsoleOptions consoleOptions = new ConsoleOptions(graphicsType); consoleOptions.setVmId(guid); QueryReturnValue configuredOptionsReturnValue = runQuery( QueryType.ConfigureConsoleOptions, new ConfigureConsoleOptionsParams(consoleOptions, true) ); if (!configuredOptionsReturnValue.getSucceeded()) { QueryReturnValue returnValue = new QueryReturnValue(); returnValue.setSucceeded(false); returnValue.setExceptionString(configuredOptionsReturnValue.getExceptionString()); return returnValue; } return runQuery( QueryType.GetConsoleDescriptorFile, new ConsoleOptionsParams(configuredOptionsReturnValue.getReturnValue()) ); }
void stubGetUserBySessionIdQuery() { QueryReturnValue returnValue = new QueryReturnValue(); returnValue.setSucceeded(true); returnValue.setReturnValue(mockUser); when(mockBackend.runQuery( eq(QueryType.GetUserBySessionId), isA(QueryParametersBase.class) )).thenReturn(returnValue); }
public static void deserialize(SerializationStreamReader streamReader, QueryReturnValue instance) throws SerializationException { instance.setSucceeded(streamReader.readBoolean()); instance.setExceptionString(streamReader.readString()); instance.setReturnValue(ObjectSerializer.deserialize(streamReader)); }
private void checkResultAndThrowExceptionIfFailed(QueryReturnValue result){ if (!result.getSucceeded()) { try { backendFailure(result.getExceptionString()); } catch (BackendFailureException e){ handleError(e, false); } } } }
@SuppressWarnings("unchecked") protected <T> T getConfigurationValueDefault(ConfigValues config) { QueryReturnValue result = runQuery( QueryType.GetConfigurationValue, new GetConfigurationValueParameters(config, ConfigCommon.defaultConfigurationVersion) ); if (result.getSucceeded()) { return (T) result.getReturnValue(); } return null; }
private void setUpCpuProfilesQueryExpectations(Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<org.ovirt.engine.core.common.businessentities.profiles.CpuProfile> 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); }
void reportNetworkOperationInProgress(Host host, VDS entity) { QueryReturnValue queryReturnValue = runQuery(QueryType.IsHostLockedOnNetworkOperation, new IdQueryParameters(entity.getId())); boolean inProgress = queryReturnValue != null && Boolean.TRUE.equals(queryReturnValue.getReturnValue()); host.setNetworkOperationInProgress(inProgress); } }
private void runQuery(Guid guid) { AsyncQuery<QueryReturnValue> asyncQuery = new AsyncQuery<>(returnValue -> { if (returnValue.getSucceeded()) { ErrataData errataData = returnValue.getReturnValue(); unfilteredResultList = errataData.getErrata(); // manual client-side filter // TODO: Use filtering and pagination options by GetErrataCountsParameters.setErrataFilter(filter) setItems(filter(unfilteredResultList)); } else { setMessage(constants.katelloProblemRetrievingErrata() + " " + returnValue.getExceptionMessage()); //$NON-NLS-1$ } }); asyncQuery.setHandleFailure(true); Frontend.getInstance().runQuery(getQueryType(), new GetErrataCountsParameters(guid), asyncQuery); }
@Override public void onSuccess(final VdcOperation<QueryType, QueryParametersBase> operation, final QueryReturnValue result) { try { if (!result.getSucceeded()) { // translate error enums to text result.setExceptionMessage(getAppErrorsTranslator().translateErrorTextSingle(result.getExceptionString())); logger.log(Level.WARNING, "Failure while invoking runQuery [" + result.getExceptionString() + ", " + result.getExceptionMessage() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (getEventsHandler() != null) { handleNotLoggedInEvent(result.getExceptionString()); } if (callback.isHandleFailure()) { callback.getAsyncCallback().onSuccess(result); } } else { if (callback.getConverter() != null) { callback.getAsyncCallback().onSuccess( callback.getConverter().convert(result.getReturnValue())); } else { callback.getAsyncCallback().onSuccess(result); } } } finally { fireAsyncQuerySucceededEvent(callback.getModel()); } }
/** * Run the following test case. * <ol> * <li>Run a search query, with *win* as the parameter, searching for VMs</li> * <li>The callback is NOT marked to handle failures</li> * <li>The failure is NOT, a-not-logged in failure</li> * <li>Return success, but the success status is !succeeded (business logic failure/not logged in)</li> * <li>Check to make sure the appropriate query start and query complete events are fired</li> * </ol> */ @Test public void testrunQuery_success_not_succeeded_noeventshandler_nocallbackhandler() { QueryParametersBase testParameters = new SearchParameters("*win*", SearchType.VM); //$NON-NLS-1$ frontend.runQuery(QueryType.Search, testParameters, mockAsyncQuery, false); verify(mockService).runQuery(eq(QueryType.Search), eq(testParameters), callback.capture()); QueryReturnValue mockReturnValue = new QueryReturnValue(); mockReturnValue.setExceptionString("Fake failure for test"); //$NON-NLS-1$ // Return value set to failure mockReturnValue.setSucceeded(false); callback.getValue().onSuccess(mockReturnValue); // Make sure the not logged in event is never called, as the failure is not a USER_IS_NOT_LOGGED_IN verify(mockFrontendNotLoggedInEvent, never()).raise(Frontend.class, EventArgs.EMPTY); verifyAsyncQuerySucceeded(); }
result.add(new QueryReturnValue()); result.get(0).setSucceeded(false); result.add(new QueryReturnValue()); result.get(1).setSucceeded(true); ArgumentCaptor<FrontendMultipleQueryAsyncResult> multipleResultCaptor = ArgumentCaptor.forClass(FrontendMultipleQueryAsyncResult.class);
public ShowErrorAsyncQuery(final AsyncCallback<QueryReturnValue> onRealSuccessCallback) { super(returnValue -> { if (!returnValue.getSucceeded()) { final ErrorPopupManager popupManager = (ErrorPopupManager) TypeResolver.getInstance().resolve(ErrorPopupManager.class); popupManager.show(returnValue.getExceptionMessage()); return; } onRealSuccessCallback.onSuccess(returnValue); }); setHandleFailure(true); } }
public static QueryReturnValue instantiate(SerializationStreamReader streamReader) throws SerializationException { return new QueryReturnValue(); }
public static String formatQueryReturnValues(List<QueryReturnValue> values) { StringBuilder msg = new StringBuilder(); for (QueryReturnValue val : values) { msg.append(val.getExceptionString()); } return msg.toString(); }
private void setAsyncTaskStatusExpectations(ArrayList<Guid> asyncTasks, ArrayList<AsyncTaskStatus> asyncStatuses, QueryReturnValue monitorResult, ActionReturnValue result) { if (asyncTasks != null) { result.setVdsmTaskIdList(asyncTasks); monitorResult.setReturnValue(asyncStatuses); when(backend.runQuery(eq(QueryType.GetTasksStatusesByTasksIDs), eqParams(GetTasksStatusesByTasksIDsParameters.class, addSession(), addSession(new Object[] {})))).thenReturn(monitorResult); } }
/** * Executes a backend {@linkplain BackendLocal#runPublicQuery public query} and returns its result value if * successful. * <p> * Returns {@code null} otherwise. */ protected Object runPublicQuery(QueryType queryType, QueryParametersBase queryParams, String sessionId) { initQueryParams(queryParams, sessionId); QueryReturnValue result = backend.runPublicQuery(queryType, queryParams); return result != null && result.getSucceeded() ? result.getReturnValue() : null; }
private void setUpDiskProfilesQueryExpectations(Object failure) { QueryReturnValue queryResult = new QueryReturnValue(); queryResult.setSucceeded(failure == null); List<org.ovirt.engine.core.common.businessentities.profiles.DiskProfile> 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); }
@Override public void onSuccess(QueryReturnValue returnValue) { Pair<List<GlusterVolumeSnapshotConfig>, List<GlusterVolumeSnapshotConfig>> configs = returnValue.getReturnValue(); if (configs != null) { List<GlusterVolumeSnapshotConfig> clusterConfigOptions = configs.getFirst(); Collections.sort(clusterConfigOptions, Comparator.comparing(GlusterVolumeSnapshotConfig::getParamName)); setModelItems(getClusterConfigOptions(), clusterConfigOptions, existingClusterConfigs); } else { getClusterConfigOptions().setItems(null); } }
public void runQuery(Guid guid) { startProgress("getCount"); //$NON-NLS-1$ AsyncQuery<QueryReturnValue> asyncQuery = new AsyncQuery<>(returnValue -> { stopProgress(); ErrataCounts resultEntity = returnValue.getReturnValue(); //Set message to null to make sure the actual setMessage creates an event. setMessage(null); if (resultEntity != null && returnValue.getSucceeded()) { setErrataCounts(resultEntity); } else { setMessage( constants.katelloProblemRetrievingErrata() + " " + returnValue.getExceptionMessage()); //$NON-NLS-1$ } }); asyncQuery.setHandleFailure(true); Frontend.getInstance().runQuery(getQueryType(), new GetErrataCountsParameters(guid), asyncQuery); }