You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by ke...@apache.org on 2017/05/04 13:11:35 UTC

[4/8] beam git commit: Tighten access in sdk.options

Tighten access in sdk.options


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/58298d86
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/58298d86
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/58298d86

Branch: refs/heads/master
Commit: 58298d866fe9d1f4fcaf2ccda3078809f4d55b27
Parents: fe51cc0
Author: Kenneth Knowles <kl...@google.com>
Authored: Wed May 3 10:10:07 2017 -0700
Committer: Kenneth Knowles <kl...@google.com>
Committed: Thu May 4 06:09:32 2017 -0700

----------------------------------------------------------------------
 .../beam/sdk/options/ValueProviderUtils.java    | 60 ---------------
 .../apache/beam/sdk/options/ValueProviders.java | 60 +++++++++++++++
 .../beam/sdk/options/ValueProviderTest.java     |  4 +-
 .../sdk/options/ValueProviderUtilsTest.java     | 78 --------------------
 .../beam/sdk/options/ValueProvidersTest.java    | 78 ++++++++++++++++++++
 5 files changed, 140 insertions(+), 140 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/58298d86/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProviderUtils.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProviderUtils.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProviderUtils.java
deleted file mode 100644
index 14a5f23..0000000
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProviderUtils.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.beam.sdk.options;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-
-import java.io.IOException;
-import java.util.Map;
-
-/**
- * Utilities for working with the {@link ValueProvider} interface.
- */
-public class ValueProviderUtils {
-  private ValueProviderUtils() {}
-
-  /**
-   * Given {@code serializedOptions} as a JSON-serialized {@link PipelineOptions}, updates
-   * the values according to the provided values in {@code runtimeValues}.
-   */
-  public static String updateSerializedOptions(
-      String serializedOptions, Map<String, String> runtimeValues) {
-    ObjectMapper mapper = new ObjectMapper();
-    ObjectNode root, options;
-    try {
-      root = mapper.readValue(serializedOptions, ObjectNode.class);
-      options = (ObjectNode) root.get("options");
-      checkNotNull(options, "Unable to locate 'options' in %s", serializedOptions);
-    } catch (IOException e) {
-      throw new RuntimeException(
-        String.format("Unable to parse %s", serializedOptions), e);
-    }
-
-    for (Map.Entry<String, String> entry : runtimeValues.entrySet()) {
-      options.put(entry.getKey(), entry.getValue());
-    }
-    try {
-      return mapper.writeValueAsString(root);
-    } catch (IOException e) {
-      throw new RuntimeException("Unable to parse re-serialize options", e);
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/beam/blob/58298d86/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProviders.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProviders.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProviders.java
new file mode 100644
index 0000000..d034b81
--- /dev/null
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/options/ValueProviders.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.options;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Utilities for working with the {@link ValueProvider} interface.
+ */
+class ValueProviders {
+  private ValueProviders() {}
+
+  /**
+   * Given {@code serializedOptions} as a JSON-serialized {@link PipelineOptions}, updates
+   * the values according to the provided values in {@code runtimeValues}.
+   */
+  public static String updateSerializedOptions(
+      String serializedOptions, Map<String, String> runtimeValues) {
+    ObjectMapper mapper = new ObjectMapper();
+    ObjectNode root, options;
+    try {
+      root = mapper.readValue(serializedOptions, ObjectNode.class);
+      options = (ObjectNode) root.get("options");
+      checkNotNull(options, "Unable to locate 'options' in %s", serializedOptions);
+    } catch (IOException e) {
+      throw new RuntimeException(
+        String.format("Unable to parse %s", serializedOptions), e);
+    }
+
+    for (Map.Entry<String, String> entry : runtimeValues.entrySet()) {
+      options.put(entry.getKey(), entry.getValue());
+    }
+    try {
+      return mapper.writeValueAsString(root);
+    } catch (IOException e) {
+      throw new RuntimeException("Unable to parse re-serialize options", e);
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/beam/blob/58298d86/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
index 383de53..9369ae6 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderTest.java
@@ -199,7 +199,7 @@ public class ValueProviderTest {
     ObjectMapper mapper = new ObjectMapper();
     String serializedOptions = mapper.writeValueAsString(submitOptions);
 
-    String runnerString = ValueProviderUtils.updateSerializedOptions(
+    String runnerString = ValueProviders.updateSerializedOptions(
       serializedOptions, ImmutableMap.of("foo", "quux"));
     TestOptions runtime = mapper.readValue(runnerString, PipelineOptions.class)
       .as(TestOptions.class);
@@ -218,7 +218,7 @@ public class ValueProviderTest {
     ObjectMapper mapper = new ObjectMapper();
     String serializedOptions = mapper.writeValueAsString(submitOptions);
 
-    String runnerString = ValueProviderUtils.updateSerializedOptions(
+    String runnerString = ValueProviders.updateSerializedOptions(
       serializedOptions, ImmutableMap.of("foo", "quux"));
     TestOptions runtime = mapper.readValue(runnerString, PipelineOptions.class)
       .as(TestOptions.class);

http://git-wip-us.apache.org/repos/asf/beam/blob/58298d86/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderUtilsTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderUtilsTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderUtilsTest.java
deleted file mode 100644
index e09f4ad..0000000
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProviderUtilsTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.beam.sdk.options;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.ImmutableMap;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for {@link ValueProviderUtils}. */
-@RunWith(JUnit4.class)
-public class ValueProviderUtilsTest {
-  /** A test interface. */
-  public interface TestOptions extends PipelineOptions {
-    String getString();
-    void setString(String value);
-
-    String getOtherString();
-    void setOtherString(String value);
-  }
-
-  @Test
-  public void testUpdateSerialize() throws Exception {
-    TestOptions submitOptions = PipelineOptionsFactory.as(TestOptions.class);
-    ObjectMapper mapper = new ObjectMapper();
-    String serializedOptions = mapper.writeValueAsString(submitOptions);
-    String updatedOptions = ValueProviderUtils.updateSerializedOptions(
-      serializedOptions, ImmutableMap.of("string", "bar"));
-    TestOptions runtime = mapper.readValue(updatedOptions, PipelineOptions.class)
-      .as(TestOptions.class);
-    assertEquals("bar", runtime.getString());
-  }
-
-  @Test
-  public void testUpdateSerializeExistingValue() throws Exception {
-    TestOptions submitOptions = PipelineOptionsFactory.fromArgs(
-        "--string=baz", "--otherString=quux").as(TestOptions.class);
-    ObjectMapper mapper = new ObjectMapper();
-    String serializedOptions = mapper.writeValueAsString(submitOptions);
-    String updatedOptions = ValueProviderUtils.updateSerializedOptions(
-      serializedOptions, ImmutableMap.of("string", "bar"));
-    TestOptions runtime = mapper.readValue(updatedOptions, PipelineOptions.class)
-      .as(TestOptions.class);
-    assertEquals("bar", runtime.getString());
-    assertEquals("quux", runtime.getOtherString());
-  }
-
-  @Test
-  public void testUpdateSerializeEmptyUpdate() throws Exception {
-    TestOptions submitOptions = PipelineOptionsFactory.as(TestOptions.class);
-    ObjectMapper mapper = new ObjectMapper();
-    String serializedOptions = mapper.writeValueAsString(submitOptions);
-    String updatedOptions = ValueProviderUtils.updateSerializedOptions(
-      serializedOptions, ImmutableMap.<String, String>of());
-    TestOptions runtime = mapper.readValue(updatedOptions, PipelineOptions.class)
-      .as(TestOptions.class);
-    assertNull(runtime.getString());
-  }
-}

http://git-wip-us.apache.org/repos/asf/beam/blob/58298d86/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProvidersTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProvidersTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProvidersTest.java
new file mode 100644
index 0000000..14f86bc
--- /dev/null
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/options/ValueProvidersTest.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.options;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.ImmutableMap;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link ValueProviders}. */
+@RunWith(JUnit4.class)
+public class ValueProvidersTest {
+  /** A test interface. */
+  public interface TestOptions extends PipelineOptions {
+    String getString();
+    void setString(String value);
+
+    String getOtherString();
+    void setOtherString(String value);
+  }
+
+  @Test
+  public void testUpdateSerialize() throws Exception {
+    TestOptions submitOptions = PipelineOptionsFactory.as(TestOptions.class);
+    ObjectMapper mapper = new ObjectMapper();
+    String serializedOptions = mapper.writeValueAsString(submitOptions);
+    String updatedOptions = ValueProviders.updateSerializedOptions(
+      serializedOptions, ImmutableMap.of("string", "bar"));
+    TestOptions runtime = mapper.readValue(updatedOptions, PipelineOptions.class)
+      .as(TestOptions.class);
+    assertEquals("bar", runtime.getString());
+  }
+
+  @Test
+  public void testUpdateSerializeExistingValue() throws Exception {
+    TestOptions submitOptions = PipelineOptionsFactory.fromArgs(
+        "--string=baz", "--otherString=quux").as(TestOptions.class);
+    ObjectMapper mapper = new ObjectMapper();
+    String serializedOptions = mapper.writeValueAsString(submitOptions);
+    String updatedOptions = ValueProviders.updateSerializedOptions(
+      serializedOptions, ImmutableMap.of("string", "bar"));
+    TestOptions runtime = mapper.readValue(updatedOptions, PipelineOptions.class)
+      .as(TestOptions.class);
+    assertEquals("bar", runtime.getString());
+    assertEquals("quux", runtime.getOtherString());
+  }
+
+  @Test
+  public void testUpdateSerializeEmptyUpdate() throws Exception {
+    TestOptions submitOptions = PipelineOptionsFactory.as(TestOptions.class);
+    ObjectMapper mapper = new ObjectMapper();
+    String serializedOptions = mapper.writeValueAsString(submitOptions);
+    String updatedOptions = ValueProviders.updateSerializedOptions(
+      serializedOptions, ImmutableMap.<String, String>of());
+    TestOptions runtime = mapper.readValue(updatedOptions, PipelineOptions.class)
+      .as(TestOptions.class);
+    assertNull(runtime.getString());
+  }
+}