[
https://issues.apache.org/jira/browse/BEAM-4176?focusedWorklogId=150951&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-150951
]
ASF GitHub Bot logged work on BEAM-4176:
----------------------------------------
Author: ASF GitHub Bot
Created on: 03/Oct/18 22:05
Start Date: 03/Oct/18 22:05
Worklog Time Spent: 10m
Work Description: tweise closed pull request #6550: [BEAM-4176] Correctly
deserialize pipeline options on Fn harness
URL: https://github.com/apache/beam/pull/6550
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PipelineOptionsTranslation.java
b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PipelineOptionsTranslation.java
index b47a40a55b7..6a8988e76fa 100644
---
a/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PipelineOptionsTranslation.java
+++
b/runners/core-construction-java/src/main/java/org/apache/beam/runners/core/construction/PipelineOptionsTranslation.java
@@ -88,4 +88,16 @@ public static PipelineOptions fromProto(Struct protoOptions)
throws IOException
MAPPER.writeValueAsString(ImmutableMap.of("options", mapWithoutUrns)),
PipelineOptions.class);
}
+
+ /** Converts the provided Json{@link String} into {@link PipelineOptions}. */
+ public static PipelineOptions fromJson(String optionsJson) throws
IOException {
+ Struct.Builder builder = Struct.newBuilder();
+ JsonFormat.parser().merge(optionsJson, builder);
+ return fromProto(builder.build());
+ }
+
+ /** Converts the provided {@link PipelineOptions} into Json{@link String}. */
+ public static String toJson(PipelineOptions options) throws IOException {
+ return JsonFormat.printer().print(toProto(options));
+ }
}
diff --git
a/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/PipelineOptionsTranslationTest.java
b/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/PipelineOptionsTranslationTest.java
index 4d832390fda..aef82d245bf 100644
---
a/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/PipelineOptionsTranslationTest.java
+++
b/runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/PipelineOptionsTranslationTest.java
@@ -82,6 +82,17 @@ public void testToFromProto() throws Exception {
Struct reserializedStruct =
PipelineOptionsTranslation.toProto(deserializedStruct);
assertThat(reserializedStruct.getFieldsMap(),
equalTo(originalStruct.getFieldsMap()));
}
+
+ @Test
+ public void testToFromJson() throws Exception {
+ options.getOptionsId();
+ Struct originalStruct = PipelineOptionsTranslation.toProto(options);
+ String json = PipelineOptionsTranslation.toJson(options);
+
+ PipelineOptions deserializedOptions =
PipelineOptionsTranslation.fromJson(json);
+ Struct reserializedStruct =
PipelineOptionsTranslation.toProto(deserializedOptions);
+ assertThat(reserializedStruct.getFieldsMap(),
equalTo(originalStruct.getFieldsMap()));
+ }
}
/** Tests that translations contain the correct contents. */
diff --git
a/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnHarness.java
b/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnHarness.java
index 6ba55bca900..d1eb02d0538 100644
--- a/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnHarness.java
+++ b/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/FnHarness.java
@@ -18,7 +18,6 @@
package org.apache.beam.fn.harness;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import java.util.EnumMap;
import java.util.List;
@@ -34,6 +33,7 @@
import org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionRequest;
import
org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionResponse.Builder;
import org.apache.beam.model.pipeline.v1.Endpoints;
+import org.apache.beam.runners.core.construction.PipelineOptionsTranslation;
import org.apache.beam.sdk.extensions.gcp.options.GcsOptions;
import org.apache.beam.sdk.fn.IdGenerator;
import org.apache.beam.sdk.fn.IdGenerators;
@@ -43,7 +43,6 @@
import org.apache.beam.sdk.io.FileSystems;
import org.apache.beam.sdk.options.ExperimentalOptions;
import org.apache.beam.sdk.options.PipelineOptions;
-import org.apache.beam.sdk.util.common.ReflectHelpers;
import org.apache.beam.vendor.protobuf.v3.com.google.protobuf.TextFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -88,11 +87,7 @@ public static void main(String[] args) throws Exception {
System.out.format("Pipeline options %s%n",
System.getenv(PIPELINE_OPTIONS));
String id = System.getenv(HARNESS_ID);
- ObjectMapper objectMapper =
- new ObjectMapper()
-
.registerModules(ObjectMapper.findModules(ReflectHelpers.findClassLoader()));
- PipelineOptions options =
- objectMapper.readValue(System.getenv(PIPELINE_OPTIONS),
PipelineOptions.class);
+ PipelineOptions options =
PipelineOptionsTranslation.fromJson(System.getenv(PIPELINE_OPTIONS));
Endpoints.ApiServiceDescriptor loggingApiServiceDescriptor =
getApiServiceDescriptor(LOGGING_API_SERVICE_DESCRIPTOR);
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 150951)
Time Spent: 26h 50m (was: 26h 40m)
> Java: Portable batch runner passes all ValidatesRunner tests that
> non-portable runner passes
> --------------------------------------------------------------------------------------------
>
> Key: BEAM-4176
> URL: https://issues.apache.org/jira/browse/BEAM-4176
> Project: Beam
> Issue Type: Bug
> Components: runner-flink
> Reporter: Ben Sidhom
> Assignee: Ankur Goenka
> Priority: Major
> Attachments: 81VxNWtFtke.png, Screen Shot 2018-08-14 at 4.18.31
> PM.png, Screen Shot 2018-09-03 at 11.07.38 AM.png
>
> Time Spent: 26h 50m
> Remaining Estimate: 0h
>
> We need this as a sanity check that runner execution is correct.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)