@Override public BatchResult<Integer> execute(ClusterState currentState, List<Integer> tasks) throws Exception { this.tasks.addAll(tasks); return BatchResult.<Integer>builder() .successes(tasks) .build(ClusterState.builder(currentState).build()); }
public BatchResult getBatchResult(String jobId, String batchId) throws AsyncApiException { try { InputStream stream = doHttpGet(buildBatchResultURL(jobId, batchId)); XmlInputStream xin = new XmlInputStream(); xin.setInput(stream, "UTF-8"); BatchResult result = new BatchResult(); result.load(xin, typeMapper); return result; } catch (PullParserException e) { throw new AsyncApiException( "Failed to parse result ", AsyncExceptionCode.ClientInputError, e); } catch (IOException e) { throw new AsyncApiException("Failed to get result ", AsyncExceptionCode.ClientInputError, e); } catch (ConnectionException e) { throw new AsyncApiException("Failed to get result ", AsyncExceptionCode.ClientInputError, e); } }
@Override public BatchResult<String> execute(ClusterState currentState, List<String> tasks) throws Exception { executionOrder.addAll( tasks); // do this first, so startedProcessing can be used as a notification that this // is done. startedProcessing.release(tasks.size()); allowProcessing.acquire(tasks.size()); return BatchResult.<String>builder() .successes(tasks) .build(ClusterState.builder(currentState).build()); }
/** * Batch execution method that returns all the information the driver has to offer. * * @return a List of BatchResult objects * @throws BatchException (an SQLException sub class) if any nested batch fails * @throws SQLException if a database access error occurs, or the drive does not support batch * statements * @throws BatchException if the driver throws BatchUpdateException */ public List executeBatchDetailed() throws SQLException, BatchException { List answer = new ArrayList(); for (int i = 0, n = statementList.size(); i < n; i++) { BatchResult br = (BatchResult) batchResultList.get(i); PreparedStatement ps = (PreparedStatement) statementList.get(i); try { br.setUpdateCounts(ps.executeBatch()); } catch (BatchUpdateException e) { StringBuffer message = new StringBuffer(); message.append("Sub batch number "); message.append(i + 1); message.append(" failed."); if (i > 0) { message.append(" "); message.append(i); message.append(" prior sub batch(s) completed successfully, but will be rolled back."); } throw new BatchException(message.toString(), e, answer, br.getStatementId(), br.getSql()); } answer.add(br); } return answer; }
@Override public BatchResult<ClusterChangedEvent> execute( ClusterState currentState, List<ClusterChangedEvent> tasks) throws Exception { ClusterState accumulator = ClusterState.builder(currentState).build(); BatchResult.Builder<ClusterChangedEvent> builder = BatchResult.builder(); try { // we only need to apply the latest cluster state update accumulator = applyUpdate(accumulator, tasks.get(tasks.size() - 1)); builder.successes(tasks); } catch (Throwable t) { builder.failures(tasks, t); } return builder.build(accumulator); }
@Override public BatchResult<Task> execute(ClusterState currentState, List<Task> tasks) throws Exception { for (Set<Task> expectedSet : taskGroups) { long count = tasks.stream().filter(expectedSet::contains).count(); assertThat( "batched set should be executed together or not at all. Expected " + expectedSet + "s. Executing " + tasks, count, anyOf(equalTo(0L), equalTo((long) expectedSet.size()))); } tasks.forEach(Task::execute); counter.addAndGet(tasks.size()); ClusterState maybeUpdatedClusterState = currentState; if (randomBoolean()) { maybeUpdatedClusterState = ClusterState.builder(currentState).build(); batches.incrementAndGet(); semaphore.acquire(); } return BatchResult.<Task>builder().successes(tasks).build(maybeUpdatedClusterState); }