link3280 commented on code in PR #21292:
URL: https://github.com/apache/flink/pull/21292#discussion_r1050321324


##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/operation/OperationExecutor.java:
##########
@@ -405,4 +425,107 @@ private Set<TableInfo> listViews(String catalogName, 
String databaseName) {
                                                 TableKind.VIEW))
                         .collect(Collectors.toSet()));
     }
+
+    public ResultFetcher callStopJobOperation(
+            OperationHandle operationHandle, StopJobOperation stopJobOperation)
+            throws SqlExecutionException {
+        String jobId = stopJobOperation.getJobId();
+        boolean isWithSavepoint = stopJobOperation.isWithSavepoint();
+        boolean isWithDrain = stopJobOperation.isWithDrain();
+        Duration clientTimeout =
+                Configuration.fromMap(sessionContext.getConfigMap())
+                        .get(ClientOptions.CLIENT_TIMEOUT);
+        Optional<String> savepoint;
+        try {
+            savepoint =
+                    runClusterAction(
+                            operationHandle,
+                            clusterClient -> {
+                                if (isWithSavepoint) {
+                                    // blocking get savepoint path
+                                    try {
+                                        return Optional.of(
+                                                clusterClient
+                                                        .stopWithSavepoint(
+                                                                
JobID.fromHexString(jobId),
+                                                                isWithDrain,
+                                                                
executionConfig.get(
+                                                                        
CheckpointingOptions
+                                                                               
 .SAVEPOINT_DIRECTORY),
+                                                                
SavepointFormatType.DEFAULT)
+                                                        .get(
+                                                                
clientTimeout.toMillis(),
+                                                                
TimeUnit.MILLISECONDS));
+                                    } catch (Exception e) {
+                                        throw new FlinkException(
+                                                "Could not stop job "
+                                                        + stopJobOperation
+                                                        + " in session "
+                                                        + 
operationHandle.getIdentifier()
+                                                        + ".",
+                                                e);
+                                    }
+                                } else {
+                                    
clusterClient.cancel(JobID.fromHexString(jobId));
+                                    return Optional.empty();
+                                }
+                            });
+        } catch (Exception e) {
+            throw new SqlExecutionException(
+                    "Could not stop job " + jobId + " for operation " + 
operationHandle + ".", e);
+        }
+        return new ResultFetcher(
+                operationHandle,
+                ResolvedSchema.of(Column.physical(JOB_ID, DataTypes.STRING())),
+                Collections.singletonList(
+                        
GenericRowData.of(StringData.fromString(savepoint.orElse("")))));

Review Comment:
   Oops. It looks like something goes wrong in the rebase process.



-- 
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