JunRuiLee commented on code in PR #25798:
URL: https://github.com/apache/flink/pull/25798#discussion_r1894906328


##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/DefaultStreamGraphContext.java:
##########
@@ -69,16 +69,33 @@ public class DefaultStreamGraphContext implements 
StreamGraphContext {
     // as they reuse some attributes.
     private final Map<Integer, Map<StreamEdge, NonChainedOutput>> 
opIntermediateOutputsCaches;
 
+    private final StreamGraphUpdateListener streamGraphUpdateListener;
+
     public DefaultStreamGraphContext(

Review Comment:
   @VisibleForTesting



##########
flink-runtime/src/test/java/org/apache/flink/runtime/jobgraph/jsonplan/JsonGeneratorTest.java:
##########
@@ -151,4 +160,55 @@ private void checkVertexExists(String vertexId, JobGraph 
graph) {
         }
         fail("could not find vertex with id " + vertexId + " in JobGraph");
     }
+
+    @Test
+    public void testGenerateStreamGraphJson() throws JsonProcessingException {
+        StreamExecutionEnvironment env = new StreamExecutionEnvironment();

Review Comment:
   StreamExecutionEnvironment.getExecutionEnvironment();



##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/JobDetailHandlerTest.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * 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.flink.runtime.rest.handler.job;
+
+import org.apache.flink.api.common.ArchivedExecutionConfig;
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.MetricOptions;
+import org.apache.flink.runtime.executiongraph.AccessExecutionGraph;
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.handler.HandlerRequestException;
+import org.apache.flink.runtime.rest.handler.RestHandlerConfiguration;
+import org.apache.flink.runtime.rest.handler.RestHandlerException;
+import org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcherImpl;
+import 
org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionConfigBuilder;
+import 
org.apache.flink.runtime.rest.handler.legacy.utils.ArchivedExecutionGraphBuilder;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.JobIDPathParameter;
+import org.apache.flink.runtime.rest.messages.JobPlanInfo;
+import org.apache.flink.runtime.rest.messages.job.JobDetailsHeaders;
+import org.apache.flink.runtime.rest.messages.job.JobDetailsInfo;
+import 
org.apache.flink.runtime.rest.messages.taskmanager.TaskManagerMessageParameters;
+import org.apache.flink.runtime.webmonitor.RestfulGateway;
+import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever;
+import org.apache.flink.testutils.TestingUtils;
+import org.apache.flink.util.concurrent.Executors;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class JobDetailHandlerTest {

Review Comment:
   no need to be public for junit5 test.



##########
flink-runtime/src/main/java/org/apache/flink/streaming/api/graph/DefaultStreamGraphContext.java:
##########
@@ -69,16 +69,33 @@ public class DefaultStreamGraphContext implements 
StreamGraphContext {
     // as they reuse some attributes.
     private final Map<Integer, Map<StreamEdge, NonChainedOutput>> 
opIntermediateOutputsCaches;
 
+    private final StreamGraphUpdateListener streamGraphUpdateListener;

Review Comment:
   @Nullable



##########
flink-runtime/src/test/java/org/apache/flink/runtime/jobgraph/jsonplan/JsonGeneratorTest.java:
##########
@@ -151,4 +160,55 @@ private void checkVertexExists(String vertexId, JobGraph 
graph) {
         }
         fail("could not find vertex with id " + vertexId + " in JobGraph");
     }
+
+    @Test
+    public void testGenerateStreamGraphJson() throws JsonProcessingException {
+        StreamExecutionEnvironment env = new StreamExecutionEnvironment();
+        env.fromSequence(0L, 1L).disableChaining().print();
+        StreamGraph streamGraph = env.getStreamGraph();
+        Map<Integer, JobVertexID> jobVertexIdMap = new HashMap<>();
+        String streamGraphJson =
+                JsonPlanGenerator.generateStreamGraphJson(streamGraph, 
jobVertexIdMap);
+
+        ObjectMapper mapper = JacksonMapperFactory.createObjectMapper();
+        StreamGraphJsonSchema parsedStreamGraph =
+                mapper.readValue(streamGraphJson, StreamGraphJsonSchema.class);
+
+        List<String> expectedJobVertexIds = new ArrayList<>();
+        expectedJobVertexIds.add(null);
+        expectedJobVertexIds.add(null);
+        validateStreamGraph(streamGraph, parsedStreamGraph, 
expectedJobVertexIds);
+
+        jobVertexIdMap.put(1, new JobVertexID());
+        jobVertexIdMap.put(2, new JobVertexID());
+        streamGraphJson = 
JsonPlanGenerator.generateStreamGraphJson(streamGraph, jobVertexIdMap);
+
+        parsedStreamGraph = mapper.readValue(streamGraphJson, 
StreamGraphJsonSchema.class);
+        validateStreamGraph(
+                streamGraph,
+                parsedStreamGraph,
+                jobVertexIdMap.values().stream()
+                        .map(JobVertexID::toString)
+                        .collect(Collectors.toList()));
+    }
+
+    public static void validateStreamGraph(
+            StreamGraph streamGraph,
+            StreamGraphJsonSchema parsedStreamGraph,
+            List<String> expectedJobVertexIds) {
+        List<String> realJobVertexIds = new ArrayList<>();
+        parsedStreamGraph
+                .getNodes()
+                .forEach(
+                        node -> {

Review Comment:
   It seems that some attributes of `JsonStreamNodeSchema`, such as 
`Description` and `Inputs`, have not been checked. Can we include these 
attributes?



##########
flink-runtime/src/test/java/org/apache/flink/runtime/jobgraph/jsonplan/StreamGraphJsonSchema.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * 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.flink.runtime.jobgraph.jsonplan;
+
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnore;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+import java.util.Objects;
+
+public class StreamGraphJsonSchema {

Review Comment:
   add some class java doc.



##########
flink-runtime/src/test/java/org/apache/flink/runtime/jobgraph/jsonplan/StreamGraphJsonSchema.java:
##########
@@ -0,0 +1,227 @@
+/*
+ * 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.flink.runtime.jobgraph.jsonplan;
+
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonCreator;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonIgnore;
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+import java.util.Objects;
+
+public class StreamGraphJsonSchema {
+    public static final String FIELD_NAME_NODES = "nodes";
+
+    @JsonProperty(FIELD_NAME_NODES)
+    private List<JsonStreamNodeSchema> nodes;

Review Comment:
   maybe final?



##########
flink-runtime/src/test/java/org/apache/flink/runtime/jobgraph/jsonplan/JsonGeneratorTest.java:
##########
@@ -151,4 +160,55 @@ private void checkVertexExists(String vertexId, JobGraph 
graph) {
         }
         fail("could not find vertex with id " + vertexId + " in JobGraph");
     }
+
+    @Test
+    public void testGenerateStreamGraphJson() throws JsonProcessingException {
+        StreamExecutionEnvironment env = new StreamExecutionEnvironment();
+        env.fromSequence(0L, 1L).disableChaining().print();
+        StreamGraph streamGraph = env.getStreamGraph();
+        Map<Integer, JobVertexID> jobVertexIdMap = new HashMap<>();
+        String streamGraphJson =
+                JsonPlanGenerator.generateStreamGraphJson(streamGraph, 
jobVertexIdMap);
+
+        ObjectMapper mapper = JacksonMapperFactory.createObjectMapper();
+        StreamGraphJsonSchema parsedStreamGraph =
+                mapper.readValue(streamGraphJson, StreamGraphJsonSchema.class);
+
+        List<String> expectedJobVertexIds = new ArrayList<>();
+        expectedJobVertexIds.add(null);
+        expectedJobVertexIds.add(null);
+        validateStreamGraph(streamGraph, parsedStreamGraph, 
expectedJobVertexIds);
+
+        jobVertexIdMap.put(1, new JobVertexID());
+        jobVertexIdMap.put(2, new JobVertexID());
+        streamGraphJson = 
JsonPlanGenerator.generateStreamGraphJson(streamGraph, jobVertexIdMap);
+
+        parsedStreamGraph = mapper.readValue(streamGraphJson, 
StreamGraphJsonSchema.class);
+        validateStreamGraph(
+                streamGraph,
+                parsedStreamGraph,
+                jobVertexIdMap.values().stream()
+                        .map(JobVertexID::toString)
+                        .collect(Collectors.toList()));
+    }
+
+    public static void validateStreamGraph(

Review Comment:
   private



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to