Search in sources :

Example 1 with CustomSources

use of org.apache.beam.runners.dataflow.internal.CustomSources in project beam by apache.

the class WorkerCustomSources method serializeSplitToCloudSource.

/**
 * Version of {@link CustomSources#serializeToCloudSource(Source, PipelineOptions)} intended for
 * use on splits of {@link BoundedSource}.
 */
private static com.google.api.services.dataflow.model.Source serializeSplitToCloudSource(BoundedSource<?> source) throws Exception {
    com.google.api.services.dataflow.model.Source cloudSource = new com.google.api.services.dataflow.model.Source();
    cloudSource.setSpec(CloudObject.forClass(CustomSources.class));
    addString(cloudSource.getSpec(), SERIALIZED_SOURCE, encodeBase64String(serializeToByteArray(source)));
    SourceMetadata metadata = new SourceMetadata();
    // Size estimation is best effort so we continue even if it fails here.
    try {
        long estimatedSize = source.getEstimatedSizeBytes(PipelineOptionsFactory.create());
        if (estimatedSize >= 0) {
            metadata.setEstimatedSizeBytes(estimatedSize);
        } else {
            LOG.warn("Ignoring negative estimated size {} produced by source {}", estimatedSize, source);
        }
    } catch (Exception e) {
        LOG.warn("Size estimation of the source failed: " + source, e);
    }
    cloudSource.setMetadata(metadata);
    return cloudSource;
}
Also used : SourceMetadata(com.google.api.services.dataflow.model.SourceMetadata) CustomSources(org.apache.beam.runners.dataflow.internal.CustomSources) UnboundedSource(org.apache.beam.sdk.io.UnboundedSource) Source(org.apache.beam.sdk.io.Source) DerivedSource(com.google.api.services.dataflow.model.DerivedSource) BoundedSource(org.apache.beam.sdk.io.BoundedSource) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Aggregations

DerivedSource (com.google.api.services.dataflow.model.DerivedSource)1 SourceMetadata (com.google.api.services.dataflow.model.SourceMetadata)1 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 CustomSources (org.apache.beam.runners.dataflow.internal.CustomSources)1 BoundedSource (org.apache.beam.sdk.io.BoundedSource)1 Source (org.apache.beam.sdk.io.Source)1 UnboundedSource (org.apache.beam.sdk.io.UnboundedSource)1