private static RuntimeException beamExceptionFrom(final Throwable e) { // Scala doesn't declare checked exceptions in the bytecode, and the Java compiler // won't let you catch something that is not declared, so we can't catch // SparkException directly, instead we do an instanceof check. if (e instanceof SparkException) { if (e.getCause() != null && e.getCause() instanceof UserCodeException) { UserCodeException userException = (UserCodeException) e.getCause(); return new Pipeline.PipelineExecutionException(userException.getCause()); } else if (e.getCause() != null) { return new Pipeline.PipelineExecutionException(e.getCause()); } } return runtimeExceptionFrom(e); }
/** * Converts any datum to an {@link IndexedRecord} representation as if it were passed in the transformation. This * might be an expensive call, so it should only be used for sampling data (not in a processing-intensive loop). * * @param datum the datum to convert. * @return its representation as an Avro {@link IndexedRecord}. */ public static <DatumT> IndexedRecord convertToAvro(DatumT datum) { IndexedRecordConverter<DatumT, IndexedRecord> c = getConverter(datum); if (c == null) { throw new Pipeline.PipelineExecutionException( new RuntimeException("Cannot convert " + datum.getClass() + " to IndexedRecord.")); } return (IndexedRecord) c.convertToAvro(datum); }
/** * Converts any datum to an {@link IndexedRecord} representation as if it were passed in the transformation. This * might be an expensive call, so it should only be used for sampling data (not in a processing-intensive loop). * * @param datum the datum to convert. * @return its representation as an Avro {@link IndexedRecord}. */ public static <DatumT> IndexedRecord convertToAvro(DatumT datum) { IndexedRecordConverter<DatumT, IndexedRecord> c = getConverter(datum); if (c == null) { throw new Pipeline.PipelineExecutionException( new RuntimeException("Cannot convert " + datum.getClass() + " to IndexedRecord.")); } return (IndexedRecord) c.convertToAvro(datum); }
result.waitUntilFinish(); } catch (UserCodeException userException) { throw new PipelineExecutionException(userException.getCause()); } catch (Throwable t) { if (t instanceof RuntimeException) {
throw new Pipeline.PipelineExecutionException(uce.getCause()); } catch (Exception e) { if (e instanceof InterruptedException) {
@Override public PipelineResult run(Pipeline pipeline) { try { return delegate.run(pipeline); } catch (Throwable t) { // Special case hack to pull out assertion errors from PAssert; instead there should // probably be a better story along the lines of UserCodeException. UserCodeException innermostUserCodeException = null; Throwable current = t; for (; current.getCause() != null; current = current.getCause()) { if (current instanceof UserCodeException) { innermostUserCodeException = (UserCodeException) current; } } if (innermostUserCodeException != null) { current = innermostUserCodeException.getCause(); } if (current instanceof AssertionError) { throw (AssertionError) current; } throw new PipelineExecutionException(current); } }
@Override public PipelineResult run(Pipeline pipeline) { try { return delegate.run(pipeline); } catch (Throwable t) { // Special case hack to pull out assertion errors from PAssert; instead there should // probably be a better story along the lines of UserCodeException. UserCodeException innermostUserCodeException = null; Throwable current = t; for (; current.getCause() != null; current = current.getCause()) { if (current instanceof UserCodeException) { innermostUserCodeException = (UserCodeException) current; } } if (innermostUserCodeException != null) { current = innermostUserCodeException.getCause(); } if (current instanceof AssertionError) { throw (AssertionError) current; } throw new PipelineExecutionException(current); } }
@Override public PipelineResult run(Pipeline pipeline) { try { return delegate.run(pipeline); } catch (Throwable t) { // Special case hack to pull out assertion errors from PAssert; instead there should // probably be a better story along the lines of UserCodeException. UserCodeException innermostUserCodeException = null; Throwable current = t; for (; current.getCause() != null; current = current.getCause()) { if (current instanceof UserCodeException) { innermostUserCodeException = ((UserCodeException) current); } } if (innermostUserCodeException != null) { current = innermostUserCodeException.getCause(); } if (current instanceof AssertionError) { throw (AssertionError) current; } throw new PipelineExecutionException(current); } }
/** * Return a converter that can any datum to an {@link IndexedRecord} representation as if it were passed in the * transformation. This might be an expensive call, so the converter should be cached if possible. * * @param datum the datum to convert. * @return a converter that can turn it into an Avro {@link IndexedRecord}. */ public static <DatumT> IndexedRecordConverter<DatumT, IndexedRecord> getConverter(DatumT datum) { @SuppressWarnings("unchecked") IndexedRecordConverter<DatumT, IndexedRecord> converter = (IndexedRecordConverter<DatumT, IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); if (datum instanceof IndexedRecord) { converter.setSchema(((IndexedRecord) datum).getSchema()); } if (converter == null) { throw new Pipeline.PipelineExecutionException( new RuntimeException("Cannot convert " + datum.getClass() + " to IndexedRecord.")); } return converter; }
/** * Runs this {@link Pipeline} using the given {@link PipelineOptions}, using the runner specified * by the options. */ public PipelineResult run(PipelineOptions options) { PipelineRunner<? extends PipelineResult> runner = PipelineRunner.fromOptions(options); // Ensure all of the nodes are fully specified before a PipelineRunner gets access to the // pipeline. LOG.debug("Running {} via {}", this, runner); try { validate(options); return runner.run(this); } catch (UserCodeException e) { // This serves to replace the stack with one that ends here and // is caused by the caught UserCodeException, thereby splicing // out all the stack frames in between the PipelineRunner itself // and where the worker calls into the user's code. throw new PipelineExecutionException(e.getCause()); } }
@Override public final boolean advance() throws IOException { try { return source.doAs.doAs(new PrivilegedExceptionAction<Boolean>() { @Override public Boolean run() throws IOException { return doAsAdvance(); } }); } catch (RuntimeException e) { throw e; } catch (IOException e) { throw e; } catch (Exception e) { // This should never occur, since it can't be thrown by the privileged action. throw new Pipeline.PipelineExecutionException(e); } }
@Override public final boolean advance() throws IOException { try { return source.doAs.doAs(new PrivilegedExceptionAction<Boolean>() { @Override public Boolean run() throws IOException { return doAsAdvance(); } }); } catch (RuntimeException e) { throw e; } catch (IOException e) { throw e; } catch (Exception e) { // This should never occur, since it can't be thrown by the privileged action. throw new Pipeline.PipelineExecutionException(e); } }
/** * Return a converter that can any datum to an {@link IndexedRecord} representation as if it were passed in the * transformation. This might be an expensive call, so the converter should be cached if possible. * * @param datum the datum to convert. * @return a converter that can turn it into an Avro {@link IndexedRecord}. */ public static <DatumT> IndexedRecordConverter<DatumT, IndexedRecord> getConverter(DatumT datum) { @SuppressWarnings("unchecked") IndexedRecordConverter<DatumT, IndexedRecord> converter = (IndexedRecordConverter<DatumT, IndexedRecord>) new AvroRegistry() .createIndexedRecordConverter(datum.getClass()); if (datum instanceof IndexedRecord) { converter.setSchema(((IndexedRecord) datum).getSchema()); } if (converter == null) { throw new Pipeline.PipelineExecutionException( new RuntimeException("Cannot convert " + datum.getClass() + " to IndexedRecord.")); } return converter; }
public static PipelineResult waitUntilDone(PipelineResult result) { PipelineResult.State state = result.waitUntilFinish(); if (!state.equals(PipelineResult.State.DONE)) { throw new Pipeline.PipelineExecutionException( new Exception("Job finished with state " + state.toString())); } return result; }
protected Schema getSchema() { Schema schema = avroSchemaHolder.get(); if (schema == null) { // This should not occur, since the encode must be called before the schema is available. If it happens, it // is an unrecoverable error. throw new Pipeline.PipelineExecutionException( new NoSuchElementException("No schema found for " + avroSchemaHolder.getAvroSchemaId())); } return schema; }
protected Schema getSchema() { Schema schema = avroSchemaHolder.get(); if (schema == null) { // This should not occur, since the encode must be called before the schema is available. If it happens, it // is an unrecoverable error. throw new Pipeline.PipelineExecutionException( new NoSuchElementException("No schema found for " + avroSchemaHolder.getAvroSchemaId())); } return schema; }