public static RuntimeException wrapIf(boolean condition, Throwable t) { if (condition) { return wrap(t); } if (t instanceof RuntimeException) { return (RuntimeException) t; } return new RuntimeException(t); }
private UserCodeException wrap(Throwable t) { throw UserCodeException.wrap(t); }
public SerializableArrayViaCoder(Coder<T> elementCoder, T[] value) { this.coder = ListCoder.of(elementCoder); this.value = value; try { this.encodedValue = CoderUtils.encodeToByteArray(coder, Arrays.asList(value)); } catch (CoderException exc) { throw UserCodeException.wrap(exc); } }
@Override public PipelineResult run(Pipeline pipeline) { Throwable t = new IllegalStateException("user code exception"); throw UserCodeException.wrap(t); } }
@Override public void beforeElement(WindowedValue<T> element) { try { mutationElements.put( element, MutationDetectors.forValueWithCoder(element.getValue(), coder)); } catch (CoderException e) { throw UserCodeException.wrap(e); } }
@Override public void processElement(WindowedValue<InputT> element) { try { Iterable<WindowedValue<InputT>> unprocessed = fnRunner.processElementInReadyWindows(element); unprocessedElements.addAll(unprocessed); } catch (Exception e) { throw UserCodeException.wrap(e); } }
private ParDoEvaluator( PushbackSideInputDoFnRunner<InputT, ?> fnRunner, AppliedPTransform<?, ?, ?> transform, BundleOutputManager outputManager, DirectStepContext stepContext) { this.fnRunner = fnRunner; this.transform = transform; this.outputManager = outputManager; this.stepContext = stepContext; this.unprocessedElements = ImmutableList.builder(); try { fnRunner.startBundle(); } catch (Exception e) { throw UserCodeException.wrap(e); } }
private void throwUserCodeException() { try { userCode(); } catch (Exception ex) { throw UserCodeException.wrap(ex); } }
public void onTimer(TimerData timer, BoundedWindow window) { try { fnRunner.onTimer(timer.getTimerId(), window, timer.getTimestamp(), timer.getDomain()); } catch (Exception e) { throw UserCodeException.wrap(e); } }
@Override public UncommittedBundle<T> add(WindowedValue<T> element) { try { // Use the cloned value to ensure that if the coder behaves poorly (e.g. a NoOpCoder that // does not expect to be used) that is reflected in the values given to downstream // transforms WindowedValue<T> clone = element.withValue(CoderUtils.clone(coder, element.getValue())); underlying.add(clone); } catch (CoderException e) { throw UserCodeException.wrap(e); } return this; }
@Test public void robustAgainstEmptyStackTrace() { RuntimeException runtimeException = new RuntimeException("empty stack"); runtimeException.setStackTrace(new StackTraceElement[0]); RuntimeException wrapped = UserCodeException.wrap(runtimeException); assertEquals(runtimeException, wrapped.getCause()); }
pending.addAll(initialInputs); } catch (Exception e) { throw UserCodeException.wrap(e);
@Override public void processElement(WindowedValue<KV<K, Iterable<AccumT>>> element) throws Exception { checkState( element.getWindows().size() == 1, "Expected inputs to %s to be in exactly one window. Got %s", MergeAccumulatorsAndExtractOutputEvaluator.class.getSimpleName(), element.getWindows().size()); Iterable<AccumT> inputAccumulators = element.getValue().getValue(); try { AccumT first = combineFn.createAccumulator(); AccumT merged = combineFn.mergeAccumulators( Iterables.concat( Collections.singleton(first), inputAccumulators, Collections.singleton(combineFn.createAccumulator()))); OutputT extracted = combineFn.extractOutput(merged); output.add(element.withValue(KV.of(element.getValue().getKey(), extracted))); } catch (Exception e) { throw UserCodeException.wrap(e); } }
pending.addAll(initialInputs); } catch (Exception e) { throw UserCodeException.wrap(e);
@Override public TransformResult<InputT> finishBundle() { try { fnRunner.finishBundle(); } catch (Exception e) { throw UserCodeException.wrap(e); } StepTransformResult.Builder<InputT> resultBuilder; CopyOnAccessInMemoryStateInternals state = stepContext.commitState(); if (state != null) { resultBuilder = StepTransformResult.<InputT>withHold(transform, state.getEarliestWatermarkHold()) .withState(state); } else { resultBuilder = StepTransformResult.withoutHold(transform); } return resultBuilder .addOutput(outputManager.bundles.values()) .withTimerUpdate(stepContext.getTimerUpdate()) .addUnprocessedElements(unprocessedElements.build()) .build(); }
@Override public void processElement(WindowedValue<BoundedSourceShard<OutputT>> element) throws Exception { BoundedSource<OutputT> source = element.getValue().getSource(); try (final BoundedReader<OutputT> reader = source.createReader(options)) { boolean contentsRemaining = reader.start(); Future<BoundedSource<OutputT>> residualFuture = startDynamicSplitThread(source, reader); UncommittedBundle<OutputT> output = evaluationContext.createBundle(outputPCollection); while (contentsRemaining) { output.add( WindowedValue.timestampedValueInGlobalWindow( reader.getCurrent(), reader.getCurrentTimestamp())); contentsRemaining = reader.advance(); } resultBuilder.addOutput(output); try { BoundedSource<OutputT> residual = residualFuture.get(); if (residual != null) { resultBuilder.addUnprocessedElements( element.withValue(BoundedSourceShard.of(residual))); } } catch (ExecutionException exex) { // Un-and-rewrap the exception thrown by attempting to split throw UserCodeException.wrap(exex.getCause()); } } }