private static <K, RT extends RecordTemplate> Response<RT> unbatchResponse(BatchGetEntityRequest<K, RT> request, Response<BatchKVResponse<K, EntityResponse<RT>>> batchResponse, Object id) throws RemoteInvocationException { final BatchKVResponse<K, EntityResponse<RT>> batchEntity = batchResponse.getEntity(); final ErrorResponse errorResponse = batchEntity.getErrors().get(id); if (errorResponse != null) { throw new RestLiResponseException(errorResponse); } final EntityResponse<RT> entityResponse = batchEntity.getResults().get(id); if (entityResponse != null) { final RT entityResult = entityResponse.getEntity(); if (entityResult != null) { return new ResponseImpl<>(batchResponse, entityResult); } } LOGGER.debug("No result or error for base URI : {}, id: {}. Verify that the batchGet endpoint returns response keys that match batchGet request IDs.", request.getBaseUriTemplate(), id); throw NOT_FOUND_EXCEPTION; }
/** * Get a collection of {@link JobExecutionQueryResult}s for a collection of {@link JobExecutionQuery}s. * * <p> * The order of {@link JobExecutionQueryResult}s may not match the order of {@link JobExecutionQuery}s. * </p> * * @param queries a collection of {@link JobExecutionQuery}s * @return a collection of {@link JobExecutionQueryResult}s * @throws RemoteInvocationException */ public Collection<JobExecutionQueryResult> batchGet(Collection<JobExecutionQuery> queries) throws RemoteInvocationException { Set<ComplexResourceKey<JobExecutionQuery, EmptyRecord>> ids = Sets.newHashSet(); for (JobExecutionQuery query : queries) { ids.add(new ComplexResourceKey<JobExecutionQuery, EmptyRecord>(query, new EmptyRecord())); } BatchGetKVRequest<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> batchGetRequest = new JobExecutionsBuilders().batchGet().ids(ids).buildKV(); BatchKVResponse<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> response = this.restClient.sendRequest(batchGetRequest, ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS) .getResponseEntity(); return response.getResults().values(); }
/** * Extract the get response for this resource out of an auto-batched batch response. * This is pure rest.li logic, and it complements the auto-batching logic in BatchGetRequestBuilder. * @throws com.linkedin.r2.RemoteInvocationException if the server returned an error response for this resource, * or if it returned neither a result nor an error. */ public static <K, V extends RecordTemplate> Response<V> unbatchKVResponse(Request<BatchKVResponse<K, V>> request, Response<BatchKVResponse<K, V>> batchResponse, K id) throws RemoteInvocationException { final BatchKVResponse<K, V> batchEntity = batchResponse.getEntity(); final ErrorResponse errorResponse = batchEntity.getErrors().get(id); if (errorResponse != null) { throw new RestLiResponseException(errorResponse); } final V entityResult = batchEntity.getResults().get(id); if (entityResult == null) { throw new RestLiDecodingException("No result or error for base URI " + request.getBaseUriTemplate() + ", id " + id + ". Verify that the batchGet endpoint returns response keys that match batchGet request IDs.", null); } return new ResponseImpl<V>(batchResponse, entityResult); }
/** * Get a collection of {@link JobExecutionQueryResult}s for a collection of {@link JobExecutionQuery}s. * * <p> * The order of {@link JobExecutionQueryResult}s may not match the order of {@link JobExecutionQuery}s. * </p> * * @param queries a collection of {@link JobExecutionQuery}s * @return a collection of {@link JobExecutionQueryResult}s * @throws RemoteInvocationException */ public Collection<JobExecutionQueryResult> batchGet(Collection<JobExecutionQuery> queries) throws RemoteInvocationException { Set<ComplexResourceKey<JobExecutionQuery, EmptyRecord>> ids = Sets.newHashSet(); for (JobExecutionQuery query : queries) { ids.add(new ComplexResourceKey<JobExecutionQuery, EmptyRecord>(query, new EmptyRecord())); } BatchGetKVRequest<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> batchGetRequest = new JobExecutionsBuilders().batchGet().ids(ids).buildKV(); BatchKVResponse<ComplexResourceKey<JobExecutionQuery, EmptyRecord>, JobExecutionQueryResult> response = this.restClient.sendRequest(batchGetRequest, ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS) .getResponseEntity(); return response.getResults().values(); }