EricJoy2048 commented on code in PR #3191:
URL: 
https://github.com/apache/incubator-seatunnel/pull/3191#discussion_r1010115679


##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/master/JobHistorySevice.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.seatunnel.engine.server.master;
+
+import org.apache.seatunnel.engine.core.job.JobStatus;
+import org.apache.seatunnel.engine.core.job.PipelineStatus;
+import org.apache.seatunnel.engine.server.dag.physical.PipelineLocation;
+import org.apache.seatunnel.engine.server.execution.ExecutionState;
+import org.apache.seatunnel.engine.server.execution.TaskGroupLocation;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.hazelcast.logging.ILogger;
+import com.hazelcast.map.IMap;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+public class JobHistorySevice {
+    /**
+     * IMap key is one of jobId {@link 
org.apache.seatunnel.engine.server.dag.physical.PipelineLocation} and
+     * {@link org.apache.seatunnel.engine.server.execution.TaskGroupLocation}
+     * <p>
+     * The value of IMap is one of {@link JobStatus} {@link PipelineStatus}
+     * {@link org.apache.seatunnel.engine.server.execution.ExecutionState}
+     * <p>
+     * This IMap is used to recovery runningJobStateIMap in JobMaster when a 
new master node active
+     */
+    private final IMap<Object, Object> runningJobStateIMap;
+
+    private final ILogger logger;
+
+    /**
+     * key: job id;
+     * <br> value: job master;
+     */
+    private final Map<Long, JobMaster> runningJobMasterMap;
+
+    /**
+     * finishedJobStateImap key is jobId and value is jobState(json)
+     * JobStateMapper Indicates the status of the job, pipeline, and task
+     */
+    //TODO need to limit the amount of storage
+    private final IMap<Long, JobStateMapper> finishedJobStateImap;
+
+    public JobHistorySevice(
+        IMap<Object, Object> runningJobStateIMap,
+        ILogger logger,
+        Map<Long, JobMaster> runningJobMasterMap,
+        IMap<Long, JobStateMapper> finishedJobStateImap
+    ) {
+        this.runningJobStateIMap = runningJobStateIMap;
+        this.logger = logger;
+        this.runningJobMasterMap = runningJobMasterMap;
+        this.finishedJobStateImap = finishedJobStateImap;
+    }
+
+    // Gets the status of a running and completed job
+    public String listAllJob() {
+        ObjectMapper objectMapper = new ObjectMapper();
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, 
false);
+        ArrayNode jobs = objectNode.putArray("jobs");
+
+        
Stream.concat(runningJobMasterMap.values().stream().map(this::toJobStateMapper),
+                finishedJobStateImap.values().stream())
+            .forEach(jobStateMapper -> {
+                JobStatusMapper jobStatusMapper = new 
JobStatusMapper(jobStateMapper.jobId, jobStateMapper.jobStatus);
+                JsonNode jsonNode = objectMapper.valueToTree(jobStatusMapper);
+                jobs.add(jsonNode);
+            });
+        return jobs.toString();
+    }
+
+    // Get detailed status of a single job
+    public JobStateMapper getJobStatus(Long jobId) {
+        return runningJobMasterMap.containsKey(jobId) ? 
toJobStateMapper(runningJobMasterMap.get(jobId)) :
+            finishedJobStateImap.getOrDefault(jobId, null);
+    }
+
+    // Get detailed status of a single job as json
+    public String getJobStatusAsString(Long jobId) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        JobStateMapper jobStatus = getJobStatus(jobId);
+        if (null != jobStatus) {
+            try {
+                return objectMapper.writeValueAsString(jobStatus);
+            } catch (JsonProcessingException e) {
+                logger.severe("serialize jobStateMapper err", e);
+                ObjectNode objectNode = objectMapper.createObjectNode();
+                objectNode.put("err", "serialize jobStateMapper err");
+                return objectNode.toString();
+            }
+        } else {

Review Comment:
   `else` is not needed.



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/operation/ListJobStatusOperation.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * 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.seatunnel.engine.server.operation;
+
+import org.apache.seatunnel.engine.server.SeaTunnelServer;
+
+import com.hazelcast.spi.impl.AllowedDuringPassiveState;
+import com.hazelcast.spi.impl.operationservice.Operation;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+public class ListJobStatusOperation extends Operation implements 
AllowedDuringPassiveState {
+
+    private String response;
+
+    public ListJobStatusOperation() {
+    }
+
+    @Override
+    public void run() {
+        SeaTunnelServer service = getService();
+        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> 
{
+            return 
service.getCoordinatorService().jobHistorySevice.listAllJob();
+        });
+
+        try {
+            response = future.get();
+        } catch (InterruptedException | ExecutionException e) {
+            throw new RuntimeException(e);

Review Comment:
   same as above.



##########
seatunnel-core/seatunnel-starter/src/main/java/org/apache/seatunnel/core/starter/seatunnel/command/ClientExecuteCommand.java:
##########
@@ -66,10 +64,22 @@ public void execute() throws CommandExecuteException {
             ClientConfig clientConfig = 
ConfigProvider.locateAndGetClientConfig();
             clientConfig.setClusterName(clusterName);
             engineClient = new SeaTunnelClient(clientConfig);
-            JobExecutionEnvironment jobExecutionEnv = 
engineClient.createExecutionContext(configFile.toString(), jobConfig);
+            if (clientCommandArgs.isListJob()) {
+                String jobstatus = engineClient.listJobStatus();
+                log.info(jobstatus);

Review Comment:
   I think the command result use `System.out.print()` is better.



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/operation/GetJobStateOperation.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.seatunnel.engine.server.operation;
+
+import org.apache.seatunnel.engine.server.SeaTunnelServer;
+import 
org.apache.seatunnel.engine.server.serializable.OperationDataSerializerHook;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
+import com.hazelcast.spi.impl.AllowedDuringPassiveState;
+import com.hazelcast.spi.impl.operationservice.Operation;
+
+import java.io.IOException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+public class GetJobStateOperation extends Operation implements 
IdentifiedDataSerializable, AllowedDuringPassiveState {
+    private Long jobId;
+
+    private String response;
+
+    public GetJobStateOperation() {
+    }
+
+    public GetJobStateOperation(Long jobId) {
+        this.jobId = jobId;
+    }
+
+    @Override
+    public final int getFactoryId() {
+        return OperationDataSerializerHook.FACTORY_ID;
+    }
+
+    @Override
+    public int getClassId() {
+        return OperationDataSerializerHook.PRINT_MESSAGE_OPERATOR;
+    }
+
+    @Override
+    protected void writeInternal(ObjectDataOutput out) throws IOException {
+        super.writeInternal(out);
+        out.writeLong(jobId);
+    }
+
+    @Override
+    protected void readInternal(ObjectDataInput in) throws IOException {
+        super.readInternal(in);
+        jobId = in.readLong();
+    }
+
+    @Override
+    public void run() {
+        SeaTunnelServer service = getService();
+        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> 
{
+            return 
service.getCoordinatorService().jobHistorySevice.getJobStatusAsString(jobId);

Review Comment:
   `getJobHistoryService` is better.



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/operation/GetJobStateOperation.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.seatunnel.engine.server.operation;
+
+import org.apache.seatunnel.engine.server.SeaTunnelServer;
+import 
org.apache.seatunnel.engine.server.serializable.OperationDataSerializerHook;
+
+import com.hazelcast.nio.ObjectDataInput;
+import com.hazelcast.nio.ObjectDataOutput;
+import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
+import com.hazelcast.spi.impl.AllowedDuringPassiveState;
+import com.hazelcast.spi.impl.operationservice.Operation;
+
+import java.io.IOException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+
+public class GetJobStateOperation extends Operation implements 
IdentifiedDataSerializable, AllowedDuringPassiveState {
+    private Long jobId;
+
+    private String response;
+
+    public GetJobStateOperation() {
+    }
+
+    public GetJobStateOperation(Long jobId) {
+        this.jobId = jobId;
+    }
+
+    @Override
+    public final int getFactoryId() {
+        return OperationDataSerializerHook.FACTORY_ID;
+    }
+
+    @Override
+    public int getClassId() {
+        return OperationDataSerializerHook.PRINT_MESSAGE_OPERATOR;
+    }
+
+    @Override
+    protected void writeInternal(ObjectDataOutput out) throws IOException {
+        super.writeInternal(out);
+        out.writeLong(jobId);
+    }
+
+    @Override
+    protected void readInternal(ObjectDataInput in) throws IOException {
+        super.readInternal(in);
+        jobId = in.readLong();
+    }
+
+    @Override
+    public void run() {
+        SeaTunnelServer service = getService();
+        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> 
{
+            return 
service.getCoordinatorService().jobHistorySevice.getJobStatusAsString(jobId);
+        });
+
+        try {
+            response = future.get();
+        } catch (InterruptedException | ExecutionException e) {
+            throw new RuntimeException(e);

Review Comment:
   Use `SeaTunnelEngineException` is better.



##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/master/JobHistorySevice.java:
##########
@@ -0,0 +1,178 @@
+/*
+ * 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.seatunnel.engine.server.master;
+
+import org.apache.seatunnel.engine.core.job.JobStatus;
+import org.apache.seatunnel.engine.core.job.PipelineStatus;
+import org.apache.seatunnel.engine.server.dag.physical.PipelineLocation;
+import org.apache.seatunnel.engine.server.execution.ExecutionState;
+import org.apache.seatunnel.engine.server.execution.TaskGroupLocation;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.hazelcast.logging.ILogger;
+import com.hazelcast.map.IMap;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+public class JobHistorySevice {
+    /**
+     * IMap key is one of jobId {@link 
org.apache.seatunnel.engine.server.dag.physical.PipelineLocation} and
+     * {@link org.apache.seatunnel.engine.server.execution.TaskGroupLocation}
+     * <p>
+     * The value of IMap is one of {@link JobStatus} {@link PipelineStatus}
+     * {@link org.apache.seatunnel.engine.server.execution.ExecutionState}
+     * <p>
+     * This IMap is used to recovery runningJobStateIMap in JobMaster when a 
new master node active
+     */
+    private final IMap<Object, Object> runningJobStateIMap;
+
+    private final ILogger logger;
+
+    /**
+     * key: job id;
+     * <br> value: job master;
+     */
+    private final Map<Long, JobMaster> runningJobMasterMap;
+
+    /**
+     * finishedJobStateImap key is jobId and value is jobState(json)
+     * JobStateMapper Indicates the status of the job, pipeline, and task
+     */
+    //TODO need to limit the amount of storage
+    private final IMap<Long, JobStateMapper> finishedJobStateImap;
+
+    public JobHistorySevice(
+        IMap<Object, Object> runningJobStateIMap,
+        ILogger logger,
+        Map<Long, JobMaster> runningJobMasterMap,
+        IMap<Long, JobStateMapper> finishedJobStateImap
+    ) {
+        this.runningJobStateIMap = runningJobStateIMap;
+        this.logger = logger;
+        this.runningJobMasterMap = runningJobMasterMap;
+        this.finishedJobStateImap = finishedJobStateImap;
+    }
+
+    // Gets the status of a running and completed job
+    public String listAllJob() {
+        ObjectMapper objectMapper = new ObjectMapper();
+        ObjectNode objectNode = objectMapper.createObjectNode();
+        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, 
false);
+        ArrayNode jobs = objectNode.putArray("jobs");
+
+        
Stream.concat(runningJobMasterMap.values().stream().map(this::toJobStateMapper),
+                finishedJobStateImap.values().stream())
+            .forEach(jobStateMapper -> {
+                JobStatusMapper jobStatusMapper = new 
JobStatusMapper(jobStateMapper.jobId, jobStateMapper.jobStatus);
+                JsonNode jsonNode = objectMapper.valueToTree(jobStatusMapper);
+                jobs.add(jsonNode);
+            });
+        return jobs.toString();
+    }
+
+    // Get detailed status of a single job
+    public JobStateMapper getJobStatus(Long jobId) {
+        return runningJobMasterMap.containsKey(jobId) ? 
toJobStateMapper(runningJobMasterMap.get(jobId)) :
+            finishedJobStateImap.getOrDefault(jobId, null);
+    }
+
+    // Get detailed status of a single job as json
+    public String getJobStatusAsString(Long jobId) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        JobStateMapper jobStatus = getJobStatus(jobId);
+        if (null != jobStatus) {
+            try {
+                return objectMapper.writeValueAsString(jobStatus);
+            } catch (JsonProcessingException e) {
+                logger.severe("serialize jobStateMapper err", e);
+                ObjectNode objectNode = objectMapper.createObjectNode();
+                objectNode.put("err", "serialize jobStateMapper err");
+                return objectNode.toString();
+            }
+        } else {
+            ObjectNode objectNode = objectMapper.createObjectNode();
+            objectNode.put("err", String.format("jobId : %s not found", 
jobId));
+            return objectNode.toString();
+        }
+    }
+
+    @SuppressWarnings("checkstyle:MagicNumber")
+    public void storeFinishedJobState(JobMaster jobMaster) {
+        JobStateMapper jobStateMapper = toJobStateMapper(jobMaster);
+        finishedJobStateImap.put(jobStateMapper.jobId, jobStateMapper, 90, 
TimeUnit.DAYS);

Review Comment:
   90 day is too long, Please make it configurable.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to