niumy0701 commented on code in PR #17719:
URL: 
https://github.com/apache/dolphinscheduler/pull/17719#discussion_r2591217862


##########
dolphinscheduler-task-plugin/dolphinscheduler-task-emr/src/main/java/org/apache/dolphinscheduler/plugin/task/emr/EmrAddStepsTask.java:
##########
@@ -187,26 +187,37 @@ private StepStatus getStepStatus() {
 
     @Override
     public void cancelApplication() throws TaskException {
-        log.info("trying cancel emr step, taskId:{}, clusterId:{}, stepId:{}",
-                this.taskExecutionContext.getTaskInstanceId(), clusterId, 
stepId);
-        CancelStepsRequest cancelStepsRequest = new 
CancelStepsRequest().withClusterId(clusterId).withStepIds(stepId);
-        CancelStepsResult cancelStepsResult = 
emrClient.cancelSteps(cancelStepsRequest);
+        try {
+            log.info("trying cancel emr step, taskId:{}, clusterId:{}, 
stepId:{}",
+                    this.taskExecutionContext.getTaskInstanceId(), clusterId, 
stepId);
+            CancelStepsRequest cancelStepsRequest =
+                    new 
CancelStepsRequest().withClusterId(clusterId).withStepIds(stepId);
+            CancelStepsResult cancelStepsResult = 
emrClient.cancelSteps(cancelStepsRequest);
+
+            if (cancelStepsResult == null) {
+                throw new EmrTaskException("cancel emr step failed");
+            }
 
-        if (cancelStepsResult == null) {
-            throw new EmrTaskException("cancel emr step failed");
-        }
+            CancelStepsInfo cancelEmrStepInfo = 
cancelStepsResult.getCancelStepsInfoList()
+                    .stream()
+                    .filter(cancelStepsInfo -> 
cancelStepsInfo.getStepId().equals(stepId))
+                    .findFirst()
+                    .orElseThrow(() -> new EmrTaskException("cancel emr step 
failed"));
 
-        CancelStepsInfo cancelEmrStepInfo = 
cancelStepsResult.getCancelStepsInfoList()
-                .stream()
-                .filter(cancelStepsInfo -> 
cancelStepsInfo.getStepId().equals(stepId))
-                .findFirst()
-                .orElseThrow(() -> new EmrTaskException("cancel emr step 
failed"));
+            if 
(CancelStepsRequestStatus.FAILED.toString().equals(cancelEmrStepInfo.getStatus()))
 {
+                throw new EmrTaskException("cancel emr step failed, message:" 
+ cancelEmrStepInfo.getReason());
+            }
 
-        if 
(CancelStepsRequestStatus.FAILED.toString().equals(cancelEmrStepInfo.getStatus()))
 {
-            throw new EmrTaskException("cancel emr step failed, message:" + 
cancelEmrStepInfo.getReason());
+            log.info("the result of cancel emr step is:{}", cancelStepsResult);
+        } catch (EmrTaskException | SdkBaseException e) {
+            log.error("cancel emr step failed", e);
+            throw new TaskException("cancel emr step failed", e);
+        } finally {
+            // shutdown emrclient
+            if (emrClient != null) {
+                emrClient.shutdown();
+            }

Review Comment:
   done



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