|
16 | 16 | */ |
17 | 17 | package feast.core.job.dataflow; |
18 | 18 |
|
19 | | -import java.lang.reflect.Field; |
20 | | -import java.util.Map; |
21 | | -import java.util.Set; |
| 19 | +import feast.core.job.option.RunnerConfig; |
| 20 | +import feast.proto.core.RunnerProto.DataflowRunnerConfigOptions; |
| 21 | +import java.util.*; |
22 | 22 | import javax.validation.*; |
23 | 23 | import javax.validation.constraints.NotBlank; |
24 | 24 | import lombok.Getter; |
|
27 | 27 | /** DataflowRunnerConfig contains configuration fields for the Dataflow job runner. */ |
28 | 28 | @Getter |
29 | 29 | @Setter |
30 | | -public class DataflowRunnerConfig { |
31 | | - |
32 | | - public DataflowRunnerConfig(Map<String, String> runnerConfigOptions) { |
33 | | - |
34 | | - // Try to find all fields in DataflowRunnerConfig inside the runnerConfigOptions and map it into |
35 | | - // this object |
36 | | - for (Field field : DataflowRunnerConfig.class.getFields()) { |
37 | | - String fieldName = field.getName(); |
38 | | - try { |
39 | | - if (!runnerConfigOptions.containsKey(fieldName)) { |
40 | | - continue; |
41 | | - } |
42 | | - String value = runnerConfigOptions.get(fieldName); |
43 | | - |
44 | | - if (Boolean.class.equals(field.getType())) { |
45 | | - field.set(this, Boolean.valueOf(value)); |
46 | | - continue; |
47 | | - } |
48 | | - if (field.getType() == Integer.class) { |
49 | | - field.set(this, Integer.valueOf(value)); |
50 | | - continue; |
51 | | - } |
52 | | - field.set(this, value); |
53 | | - } catch (IllegalAccessException e) { |
54 | | - throw new RuntimeException( |
55 | | - String.format( |
56 | | - "Could not successfully convert DataflowRunnerConfig for key: %s", fieldName), |
57 | | - e); |
58 | | - } |
59 | | - } |
| 30 | +public class DataflowRunnerConfig extends RunnerConfig { |
| 31 | + |
| 32 | + public DataflowRunnerConfig(DataflowRunnerConfigOptions runnerConfigOptions) { |
| 33 | + this.project = runnerConfigOptions.getProject(); |
| 34 | + this.region = runnerConfigOptions.getRegion(); |
| 35 | + this.zone = runnerConfigOptions.getZone(); |
| 36 | + this.serviceAccount = runnerConfigOptions.getServiceAccount(); |
| 37 | + this.network = runnerConfigOptions.getNetwork(); |
| 38 | + this.subnetwork = runnerConfigOptions.getSubnetwork(); |
| 39 | + this.workerMachineType = runnerConfigOptions.getWorkerMachineType(); |
| 40 | + this.autoscalingAlgorithm = runnerConfigOptions.getAutoscalingAlgorithm(); |
| 41 | + this.usePublicIps = runnerConfigOptions.getUsePublicIps(); |
| 42 | + this.tempLocation = runnerConfigOptions.getTempLocation(); |
| 43 | + this.maxNumWorkers = runnerConfigOptions.getMaxNumWorkers(); |
| 44 | + this.deadLetterTableSpec = runnerConfigOptions.getDeadLetterTableSpec(); |
| 45 | + this.labels = runnerConfigOptions.getLabelsMap(); |
60 | 46 | validate(); |
61 | 47 | } |
62 | 48 |
|
63 | 49 | /* Project id to use when launching jobs. */ |
64 | | - @NotBlank public String project; |
| 50 | + @NotBlank String project; |
65 | 51 |
|
66 | 52 | /* The Google Compute Engine region for creating Dataflow jobs. */ |
67 | | - @NotBlank public String region; |
| 53 | + @NotBlank String region; |
68 | 54 |
|
69 | 55 | /* GCP availability zone for operations. */ |
70 | | - @NotBlank public String zone; |
| 56 | + @NotBlank String zone; |
71 | 57 |
|
72 | 58 | /* Run the job as a specific service account, instead of the default GCE robot. */ |
73 | | - public String serviceAccount; |
| 59 | + String serviceAccount; |
74 | 60 |
|
75 | 61 | /* GCE network for launching workers. */ |
76 | | - @NotBlank public String network; |
| 62 | + @NotBlank String network; |
77 | 63 |
|
78 | 64 | /* GCE subnetwork for launching workers. */ |
79 | | - @NotBlank public String subnetwork; |
| 65 | + @NotBlank String subnetwork; |
80 | 66 |
|
81 | 67 | /* Machine type to create Dataflow worker VMs as. */ |
82 | | - public String workerMachineType; |
| 68 | + String workerMachineType; |
83 | 69 |
|
84 | 70 | /* The autoscaling algorithm to use for the workerpool. */ |
85 | | - public String autoscalingAlgorithm; |
| 71 | + String autoscalingAlgorithm; |
86 | 72 |
|
87 | 73 | /* Specifies whether worker pools should be started with public IP addresses. */ |
88 | | - public Boolean usePublicIps; |
| 74 | + Boolean usePublicIps; |
89 | 75 |
|
90 | 76 | /** |
91 | 77 | * A pipeline level default location for storing temporary files. Support Google Cloud Storage |
92 | 78 | * locations, e.g. gs://bucket/object |
93 | 79 | */ |
94 | | - @NotBlank public String tempLocation; |
| 80 | + @NotBlank String tempLocation; |
95 | 81 |
|
96 | 82 | /* The maximum number of workers to use for the workerpool. */ |
97 | | - public Integer maxNumWorkers; |
| 83 | + Integer maxNumWorkers; |
98 | 84 |
|
99 | 85 | /* BigQuery table specification, e.g. PROJECT_ID:DATASET_ID.PROJECT_ID */ |
100 | | - public String deadLetterTableSpec; |
| 86 | + String deadLetterTableSpec; |
| 87 | + |
| 88 | + Map<String, String> labels; |
101 | 89 |
|
102 | 90 | /** Validates Dataflow runner configuration options */ |
103 | 91 | public void validate() { |
|
0 commit comments