[ 
https://issues.apache.org/jira/browse/BEAM-3702?focusedWorklogId=81293&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-81293
 ]

ASF GitHub Bot logged work on BEAM-3702:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 16/Mar/18 17:56
            Start Date: 16/Mar/18 17:56
    Worklog Time Spent: 10m 
      Work Description: lukecwik commented on a change in pull request #4683: 
[BEAM-3702] adding fromJvm to create pipelineoptions from the system properties
URL: https://github.com/apache/beam/pull/4683#discussion_r175167532
 
 

 ##########
 File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/options/PipelineOptionsFactory.java
 ##########
 @@ -1792,4 +1804,82 @@ private synchronized void register(Class<? extends 
PipelineOptions> iface) {
       return combinedCache.get(interfaces).getPropertyDescriptors();
     }
   }
+
+  /**
+   * @param prefix a prefix filter on the map keys.
+   * @param options the options to convert to a pipeline options.
+   * @return a pipeline options instance based on the specified configuration.
+   */
+  @Experimental
+  public static PipelineOptions fromMap(final String prefix, final Map<String, 
String> options) {
+    checkArgument(prefix != null, "prefix should not be null.");
+    checkArgument(options != null, "options should not be null.");
+    final Map<String, String> filtered = options.entrySet()
+                                        .stream()
+                                        .filter(e -> e.getKey()
+                                                      .startsWith(prefix))
+                                        .collect(toMap(Map.Entry::getKey, 
Map.Entry::getValue));
+    return fromMap(filtered);
+  }
+
+  /**
+   * @param options the options to convert to a pipeline options.
+   * @return a pipeline options instance based on the specified configuration.
+   */
+  public static PipelineOptions fromMap(final Map<String, String> options) {
+    checkArgument(options != null, "options should not be null.");
+    return new Builder().fromMap(options).create();
+  }
+
+  /**
+   * @param properties the properties to use to create the pipeline options 
instance.
+   * @return a pipeline options instance based on the specified properties.
+   */
+  @Experimental
+  public static PipelineOptions fromProperties(final Properties properties) {
+    checkArgument(properties != null, "properties should not be null.");
+    return fromMap(properties.stringPropertyNames()
+                    .stream()
+                    .collect(toMap(identity(), properties::getProperty)));
+  }
+
+  /**
+   * @param prefix the prefix filter applied on system properties keys.
+   * @param properties the properties to use to create the pipeline options 
instance.
+   * @return a pipeline options instance based on the specified properties
+   * filtered with the specified prefix.
+   */
+  @Experimental
+  public static PipelineOptions fromProperties(final String prefix, final 
Properties properties) {
+    checkArgument(prefix != null, "prefix should not be null.");
+    checkArgument(properties != null, "properties should not be null.");
+    final Properties instantiationProperties = properties.stringPropertyNames()
+      .stream()
+      .filter(k -> k.startsWith(prefix))
+      .collect(
+        Properties::new,
+        (p, k) -> p.setProperty(k.substring(prefix.length()), 
properties.getProperty(k)),
+        Hashtable::putAll);
+    return fromProperties(instantiationProperties);
+  }
+
+  /**
+   * @param prefix the prefix filter applied on system properties keys.
+   * @return a pipeline options instance based on system properties key/values
 
 Review comment:
   Please improve/explain what is the contract for this method.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 81293)

> Support system properties source for pipeline options
> -----------------------------------------------------
>
>                 Key: BEAM-3702
>                 URL: https://issues.apache.org/jira/browse/BEAM-3702
>             Project: Beam
>          Issue Type: Task
>          Components: sdk-java-core
>            Reporter: Romain Manni-Bucau
>            Assignee: Romain Manni-Bucau
>            Priority: Major
>             Fix For: 2.5.0
>
>          Time Spent: 9h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to