use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Splitter in project beam by apache.
the class ResourceHints method fromOptions.
/**
* Creates a {@link ResourceHints} instance with hints supplied in options.
*/
public static ResourceHints fromOptions(PipelineOptions options) {
ResourceHintsOptions resourceHintsOptions = options.as(ResourceHintsOptions.class);
ResourceHints result = create();
List<String> hints = resourceHintsOptions.getResourceHints();
Splitter splitter = Splitter.on('=').limit(2);
for (String hint : hints) {
List<String> parts = splitter.splitToList(hint);
if (parts.size() != 2) {
throw new IllegalArgumentException("Unparsable resource hint: " + hint);
}
String nameOrUrn = parts.get(0);
String stringValue = parts.get(1);
String urn;
if (hintNameToUrn.containsKey(nameOrUrn)) {
urn = hintNameToUrn.get(nameOrUrn);
} else if (!nameOrUrn.startsWith("beam:resources:")) {
// Allow unknown hints to be passed, but validate a little bit to prevent typos.
throw new IllegalArgumentException("Unknown resource hint: " + hint);
} else {
urn = nameOrUrn;
}
ResourceHint value = parsers.getOrDefault(urn, s -> new StringHint(s)).apply(stringValue);
result = result.withHint(urn, value);
}
return result;
}
Aggregations