@Override public PathValidator create(PipelineOptions options) { GcsOptions gcsOptions = options.as(GcsOptions.class); return InstanceBuilder.ofType(PathValidator.class) .fromClass(gcsOptions.getPathValidatorClass()) .fromFactoryMethod("fromOptions") .withArg(PipelineOptions.class, options) .build(); } }
@Override public T fromCloudObject(CloudObject cloudObject) { return InstanceBuilder.ofType(coderClass).fromFactoryMethod("of").build(); }
@Override public PTransformReplacement<PCollection<InputT>, PValue> getReplacementTransform( final AppliedPTransform< PCollection<InputT>, PValue, PTransform<PCollection<InputT>, PValue>> transform) { PTransform<PCollection<InputT>, PValue> rep = InstanceBuilder.ofType(replacement) .withArg(DataflowRunner.class, runner) .withArg(CreatePCollectionView.class, findCreatePCollectionView(transform)) .build(); return PTransformReplacement.of( PTransformReplacements.getSingletonMainInput(transform), (PTransform) rep); }
S3FileSystem(S3Options options) { this.options = checkNotNull(options, "options"); if (Strings.isNullOrEmpty(options.getAwsRegion())) { LOG.info( "The AWS S3 Beam extension was included in this build, but the awsRegion flag " + "was not specified. If you don't plan to use S3, then ignore this message."); } this.amazonS3 = InstanceBuilder.ofType(S3ClientBuilderFactory.class) .fromClass(options.getS3ClientFactoryClass()) .build() .createBuilder(options) .build(); checkNotNull(options.getS3StorageClass(), "storageClass"); checkArgument(options.getS3ThreadPoolSize() > 0, "threadPoolSize"); executorService = MoreExecutors.listeningDecorator( Executors.newFixedThreadPool( options.getS3ThreadPoolSize(), new ThreadFactoryBuilder().setDaemon(true).build())); }
@Test public void testWrongType() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage(Matchers.containsString("must be assignable to TupleTag")); InstanceBuilder.ofType(TupleTag.class) .fromClassName(InstanceBuilderTest.class.getName()) .build(); } }
@Override public PTransformReplacement<PCollection<InputT>, PCollection<OutputT>> getReplacementTransform( AppliedPTransform<PCollection<InputT>, PCollection<OutputT>, TransformT> transform) { PTransform<PCollection<InputT>, PCollection<OutputT>> rep = InstanceBuilder.ofType(replacement) .withArg(DataflowRunner.class, runner) .withArg( (Class<TransformT>) transform.getTransform().getClass(), transform.getTransform()) .build(); return PTransformReplacement.of(PTransformReplacements.getSingletonMainInput(transform), rep); } }
public static <T extends Coder> CloudObjectTranslator<T> atomic(final Class<T> coderClass) { // Make sure that the instance will be instantiable from the class. InstanceBuilder.ofType(coderClass).fromFactoryMethod("of").build(); return new CloudObjectTranslator<T>() { @Override public CloudObject toCloudObject(T target, SdkComponents sdkComponents) { return CloudObject.forClass(coderClass); } @Override public T fromCloudObject(CloudObject cloudObject) { return InstanceBuilder.ofType(coderClass).fromFactoryMethod("of").build(); } @Override public Class<? extends T> getSupportedClass() { return coderClass; } @Override public String cloudObjectClassName() { return CloudObject.forClass(coderClass).getClassName(); } }; }
@Override public Stager create(PipelineOptions options) { DataflowPipelineDebugOptions debugOptions = options.as(DataflowPipelineDebugOptions.class); return InstanceBuilder.ofType(Stager.class) .fromClass(debugOptions.getStagerClass()) .fromFactoryMethod("fromOptions") .withArg(PipelineOptions.class, options) .build(); } }
for (Class<? extends Coder> atomicCoder : DefaultCoderCloudObjectTranslatorRegistrar.KNOWN_ATOMIC_CODERS) { dataBuilder.add(InstanceBuilder.ofType(atomicCoder).fromFactoryMethod("of").build());
@Override public IterableLikeCoder<?, ?> fromCloudObject(CloudObject cloudObject) { List<Coder<?>> elemCoderList = getComponents(cloudObject); checkArgument( elemCoderList.size() == 1, "Expected 1 component for %s, got %s", cloudObject.getClassName(), elemCoderList.size()); return InstanceBuilder.ofType(clazz) .fromFactoryMethod("of") .withArg(Coder.class, elemCoderList.get(0)) .build(); }
public MetricsPusher( MetricsContainerStepMap metricsContainerStepMap, PipelineOptions pipelineOptions, PipelineResult pipelineResult) { this.metricsContainerStepMap = metricsContainerStepMap; this.pipelineResult = pipelineResult; period = pipelineOptions.getMetricsPushPeriod(); // calls the constructor of MetricsSink implementation specified in // pipelineOptions.getMetricsSink() passing the pipelineOptions metricsSink = InstanceBuilder.ofType(MetricsSink.class) .fromClass(pipelineOptions.getMetricsSink()) .withArg(PipelineOptions.class, pipelineOptions) .build(); }
@Override public Credentials create(PipelineOptions options) { GcpOptions gcpOptions = options.as(GcpOptions.class); try { CredentialFactory factory = InstanceBuilder.ofType(CredentialFactory.class) .fromClass(gcpOptions.getCredentialFactoryClass()) .fromFactoryMethod("fromOptions") .withArg(PipelineOptions.class, options) .build(); return factory.getCredential(); } catch (IOException | GeneralSecurityException e) { throw new RuntimeException("Unable to obtain credential", e); } } }
/** * Constructs a runner from the provided {@link PipelineOptions}. * * @return The newly created runner. */ public static PipelineRunner<? extends PipelineResult> fromOptions(PipelineOptions options) { checkNotNull(options); PipelineOptionsValidator.validate(PipelineOptions.class, options); // (Re-)register standard FileSystems. Clobbers any prior credentials. FileSystems.setDefaultPipelineOptions(options); @SuppressWarnings("unchecked") PipelineRunner<? extends PipelineResult> result = InstanceBuilder.ofType(PipelineRunner.class) .fromClass(options.getRunner()) .fromFactoryMethod("fromOptions") .withArg(PipelineOptions.class, options) .build(); return result; }
@Test public void testBadMethod() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage(Matchers.containsString("Unable to find factory method")); InstanceBuilder.ofType(String.class) .fromClassName(InstanceBuilderTest.class.getName()) .fromFactoryMethod("nonexistantFactoryMethod") .withArg(String.class, "hello") .withArg(String.class, " world!") .build(); }
@Test public void testBadArgs() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage(Matchers.containsString("Unable to find factory method")); InstanceBuilder.ofType(TupleTag.class) .fromClassName(InstanceBuilderTest.class.getName()) .fromFactoryMethod("createTag") .withArg(String.class, "hello") .withArg(Integer.class, 42) .build(); }
@Test public void testFullNameLookup() throws Exception { TupleTag tag = InstanceBuilder.ofType(TupleTag.class) .fromClassName(InstanceBuilderTest.class.getName()) .fromFactoryMethod("createTag") .withArg(String.class, "hello world!") .build(); Assert.assertEquals("hello world!", tag.getId()); }