zhoulii commented on code in PR #2592:
URL: 
https://github.com/apache/incubator-streampark/pull/2592#discussion_r1190741209


##########
streampark-console/streampark-console-service/src/test/java/org/apache/streampark/console/core/service/SavePointServiceTest.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.streampark.console.core.service;
+
+import org.apache.streampark.common.enums.ApplicationType;
+import org.apache.streampark.common.enums.DevelopmentMode;
+import org.apache.streampark.common.enums.ExecutionMode;
+import org.apache.streampark.common.util.DeflaterUtils;
+import org.apache.streampark.console.SpringTestBase;
+import org.apache.streampark.console.core.entity.Application;
+import org.apache.streampark.console.core.entity.ApplicationConfig;
+import org.apache.streampark.console.core.entity.Effective;
+import org.apache.streampark.console.core.entity.FlinkEnv;
+import org.apache.streampark.console.core.enums.ConfigFileType;
+import org.apache.streampark.console.core.enums.EffectiveType;
+import org.apache.streampark.console.core.service.impl.SavePointServiceImpl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import static 
org.apache.flink.configuration.CheckpointingOptions.SAVEPOINT_DIRECTORY;
+import static 
org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions.CHECKPOINTING_INTERVAL;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * Test class for the implementation {@link
+ * org.apache.streampark.console.core.service.impl.SavePointServiceImpl} of 
{@link
+ * SavePointService}.
+ */
+class SavePointServiceTest extends SpringTestBase {
+
+  @Autowired private SavePointService savePointService;
+
+  @Autowired private ApplicationConfigService configService;
+
+  @Autowired private EffectiveService effectiveService;
+
+  @Autowired private FlinkEnvService flinkEnvService;
+  @Autowired private FlinkClusterService flinkClusterService;
+  @Autowired ApplicationService applicationService;
+
+  @AfterEach
+  void cleanTestRecordsInDatabase() {
+    savePointService.remove(new QueryWrapper<>());
+    configService.remove(new QueryWrapper<>());
+    effectiveService.remove(new QueryWrapper<>());
+    flinkEnvService.remove(new QueryWrapper<>());
+    flinkClusterService.remove(new QueryWrapper<>());
+    applicationService.remove(new QueryWrapper<>());
+  }
+
+  /**
+   * This part will be migrated into the corresponding test cases about
+   * PropertiesUtils.extractDynamicPropertiesAsJava.
+   */
+  @Test
+  void testGetSavepointFromDynamicProps() {
+    String propsWithEmptyTargetValue = "-Dstate.savepoints.dir=";
+    String props = "-Dstate.savepoints.dir=hdfs:///test";
+    SavePointServiceImpl savePointServiceImpl = (SavePointServiceImpl) 
savePointService;
+
+    
assertThat(savePointServiceImpl.getSavepointFromDynamicProps(null)).isNull();
+    
assertThat(savePointServiceImpl.getSavepointFromDynamicProps(props)).isEqualTo("hdfs:///test");
+    
assertThat(savePointServiceImpl.getSavepointFromDynamicProps(propsWithEmptyTargetValue))
+        .isEmpty();
+  }
+
+  @Test
+  void testGetSavepointFromAppCfgIfStreamParkOrSQLJob() {
+    SavePointServiceImpl savePointServiceImpl = (SavePointServiceImpl) 
savePointService;
+    Application app = new Application();
+    Long appId = 1L;
+    Long appCfgId = 1L;
+    app.setId(appId);
+
+    // Test for non-(StreamPark job Or FlinkSQL job)
+    app.setAppType(ApplicationType.APACHE_FLINK.getType());
+    
assertThat(savePointServiceImpl.getSavepointFromAppCfgIfStreamParkOrSQLJob(app)).isNull();
+    app.setAppType(ApplicationType.STREAMPARK_FLINK.getType());
+    app.setJobType(DevelopmentMode.CUSTOM_CODE.getValue());
+    
assertThat(savePointServiceImpl.getSavepointFromAppCfgIfStreamParkOrSQLJob(app)).isNull();
+
+    // Test for (StreamPark job Or FlinkSQL job) without application config.
+    app.setAppType(ApplicationType.STREAMPARK_FLINK.getType());
+    
assertThat(savePointServiceImpl.getSavepointFromAppCfgIfStreamParkOrSQLJob(app)).isNull();
+    app.setAppType(ApplicationType.STREAMPARK_FLINK.getType());
+    app.setJobType(DevelopmentMode.CUSTOM_CODE.getValue());
+    
assertThat(savePointServiceImpl.getSavepointFromAppCfgIfStreamParkOrSQLJob(app)).isNull();
+
+    // Test for (StreamPark job Or FlinkSQL job) with application config just 
disabled checkpoint.
+    ApplicationConfig appCfg = new ApplicationConfig();
+    appCfg.setId(appCfgId);
+    appCfg.setAppId(appId);
+    appCfg.setContent("state.savepoints.dir=hdfs:///test");
+    appCfg.setFormat(ConfigFileType.PROPERTIES.getValue());
+    configService.save(appCfg);
+    
assertThat(savePointServiceImpl.getSavepointFromAppCfgIfStreamParkOrSQLJob(app)).isNull();
+
+    // Test for (StreamPark job Or FlinkSQL job) with application config and 
enabled checkpoint and
+    // configured value.
+
+    // Test for non-value for CHECKPOINTING_INTERVAL
+    
assertThat(savePointServiceImpl.getSavepointFromAppCfgIfStreamParkOrSQLJob(app)).isNull();

Review Comment:
   These two lines are duplicated.



##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/SavePointServiceImpl.java:
##########
@@ -299,29 +186,58 @@ public void trigger(Long appId, @Nullable String 
savepointPath) {
     FlinkEnv flinkEnv = flinkEnvService.getById(application.getVersionId());
 
     // infer savepoint
-    String customSavepoint = this.getFinalSavepointDir(savepointPath, 
application);
-
-    FlinkCluster cluster = 
flinkClusterService.getById(application.getFlinkClusterId());
-    String clusterId = getClusterId(application, cluster);
-
-    Map<String, Object> properties = this.tryGetRestProps(application, 
cluster);
-
     TriggerSavepointRequest request =
-        new TriggerSavepointRequest(
-            flinkEnv.getFlinkVersion(),
-            application.getExecutionModeEnum(),
-            properties,
-            clusterId,
-            application.getJobId(),
-            customSavepoint,
-            application.getK8sNamespace());
+        renderTriggerSavepointRequest(savepointPath, application, flinkEnv);
 
     CompletableFuture<SavepointResponse> savepointFuture =
         CompletableFuture.supplyAsync(() -> 
FlinkClient.triggerSavepoint(request), executorService);
 
     handleSavepointResponseFuture(application, applicationLog, 
savepointFuture);
   }
 
+  @Override
+  @Transactional(rollbackFor = Exception.class)
+  public Boolean delete(Long id, Application application) throws 
InternalException {
+    SavePoint savePoint = getById(id);
+    try {
+      if (CommonUtils.notEmpty(savePoint.getPath())) {
+        application.getFsOperator().delete(savePoint.getPath());
+      }
+      removeById(id);
+      return true;

Review Comment:
   ```suggestion
         return removeById(id);
   ```



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