You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by "abhishekmjain (via GitHub)" <gi...@apache.org> on 2024/09/03 12:08:10 UTC

[PR] [GOBBLIN-2148] Add temporal workflow cancel support [gobblin]

abhishekmjain opened a new pull request, #4045:
URL: https://github.com/apache/gobblin/pull/4045

   Dear Gobblin maintainers,
   
   Please accept this PR. I understand that it will not be reviewed until I have checked off all the steps below!
   
   
   ### JIRA
   - [ ] My PR addresses the following [Gobblin JIRA](https://issues.apache.org/jira/browse/GOBBLIN-2148) issues and references them in the PR title. For example, "[GOBBLIN-XXX] My Gobblin PR"
       - https://issues.apache.org/jira/browse/GOBBLIN-2148
   
   
   ### Description
   - [ ] Here are some details about my PR, including screenshots (if applicable):
   Currently, when GaaS Temporal job are cancelled, only the Azkaban job is stopped, which stops the subsequent YARN application. However, the Temporal job that is submitted by the YARN application is not stopped.
   As part of this PR, we have implemented the cancel flow which should cancel the Temporal workflow upon cancellation of Azkaban job.
   The support for cancellation is added in base class GobblinTemporalJobLauncher. The workflowId is needed for cancellation, thus some changes are made to initialize the workflowId in submitJob, which can then be used for cancellation.
   
   ### Tests
   - [ ] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:
   - testCancelWorkflowIfFailed
   - testCancelWorkflowIfCompleted
   - testCancelWorkflowIfRunning
   
   ### Commits
   - [ ] My commits all reference JIRA issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
       1. Subject is separated from body by a blank line
       2. Subject is limited to 50 characters
       3. Subject does not end with a period
       4. Subject uses the imperative mood ("add", not "adding")
       5. Body wraps at 72 characters
       6. Body explains "what" and "why", not "how"
   
   


-- 
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: dev-unsubscribe@gobblin.apache.org

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


Re: [PR] [GOBBLIN-2148] Add temporal workflow cancel support [gobblin]

Posted by "abhishekmjain (via GitHub)" <gi...@apache.org>.
abhishekmjain commented on code in PR #4045:
URL: https://github.com/apache/gobblin/pull/4045#discussion_r1743621573


##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/joblauncher/GobblinTemporalJobLauncher.java:
##########
@@ -113,7 +121,37 @@ protected void handleLaunchFinalization() {
 
   @Override
   protected void executeCancellation() {
-    log.info("Cancel temporal workflow");
+    if (this.workflowId == null) {
+      log.info("Cancellation of temporal workflow attempted without submitting it");
+      return;
+    }
+
+    log.info("Cancelling temporal workflow {}", this.workflowId);
+    try {
+      WorkflowStub workflowStub = this.client.newUntypedWorkflowStub(this.workflowId);
+
+      // Describe the workflow execution to get its status
+      DescribeWorkflowExecutionRequest request = DescribeWorkflowExecutionRequest.newBuilder()
+          .setNamespace(this.namespace)
+          .setExecution(workflowStub.getExecution())
+          .build();
+      DescribeWorkflowExecutionResponse response = workflowServiceStubs.blockingStub().describeWorkflowExecution(request);
+
+      // Check if the workflow is not finished
+      WorkflowExecutionStatus status = response.getWorkflowExecutionInfo().getStatus();
+      if (status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_FAILED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CANCELED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TERMINATED) {

Review Comment:
   Since it is one time check I think it is okay we can keep it here. If this gets reused further, we can extract it to a function.



-- 
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: dev-unsubscribe@gobblin.apache.org

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


Re: [PR] [GOBBLIN-2148] Add temporal workflow cancel support [gobblin]

Posted by "abhishekmjain (via GitHub)" <gi...@apache.org>.
abhishekmjain commented on code in PR #4045:
URL: https://github.com/apache/gobblin/pull/4045#discussion_r1743645421


##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/joblauncher/GobblinTemporalJobLauncher.java:
##########
@@ -113,7 +121,37 @@ protected void handleLaunchFinalization() {
 
   @Override
   protected void executeCancellation() {
-    log.info("Cancel temporal workflow");
+    if (this.workflowId == null) {
+      log.info("Cancellation of temporal workflow attempted without submitting it");
+      return;
+    }
+
+    log.info("Cancelling temporal workflow {}", this.workflowId);
+    try {
+      WorkflowStub workflowStub = this.client.newUntypedWorkflowStub(this.workflowId);
+
+      // Describe the workflow execution to get its status
+      DescribeWorkflowExecutionRequest request = DescribeWorkflowExecutionRequest.newBuilder()
+          .setNamespace(this.namespace)
+          .setExecution(workflowStub.getExecution())
+          .build();
+      DescribeWorkflowExecutionResponse response = workflowServiceStubs.blockingStub().describeWorkflowExecution(request);
+
+      // Check if the workflow is not finished
+      WorkflowExecutionStatus status = response.getWorkflowExecutionInfo().getStatus();
+      if (status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_FAILED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CANCELED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TERMINATED) {
+        workflowStub.cancel();
+        log.info("Temporal workflow {} cancelled successfully", this.workflowId);
+      } else {
+        log.info("Workflow {} is already finished with status {}", this.workflowId, status);
+      }
+    }
+    catch (Exception e) {
+      log.error("Exception occurred while cancelling the workflow " + this.workflowId, e);

Review Comment:
   We now have a separate try-catch block for getting the workflow status. For rest, it should be fine since we are anyway logging the exception, we should get the base exception class which is thrown along with any error information.



-- 
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: dev-unsubscribe@gobblin.apache.org

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


Re: [PR] [GOBBLIN-2148] Add temporal workflow cancel support [gobblin]

Posted by "Blazer-007 (via GitHub)" <gi...@apache.org>.
Blazer-007 commented on code in PR #4045:
URL: https://github.com/apache/gobblin/pull/4045#discussion_r1743068501


##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/joblauncher/GobblinTemporalJobLauncher.java:
##########
@@ -113,7 +121,37 @@ protected void handleLaunchFinalization() {
 
   @Override
   protected void executeCancellation() {
-    log.info("Cancel temporal workflow");
+    if (this.workflowId == null) {
+      log.info("Cancellation of temporal workflow attempted without submitting it");
+      return;
+    }
+
+    log.info("Cancelling temporal workflow {}", this.workflowId);
+    try {
+      WorkflowStub workflowStub = this.client.newUntypedWorkflowStub(this.workflowId);
+
+      // Describe the workflow execution to get its status
+      DescribeWorkflowExecutionRequest request = DescribeWorkflowExecutionRequest.newBuilder()
+          .setNamespace(this.namespace)
+          .setExecution(workflowStub.getExecution())
+          .build();
+      DescribeWorkflowExecutionResponse response = workflowServiceStubs.blockingStub().describeWorkflowExecution(request);
+
+      // Check if the workflow is not finished
+      WorkflowExecutionStatus status = response.getWorkflowExecutionInfo().getStatus();
+      if (status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_FAILED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CANCELED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TERMINATED) {

Review Comment:
   It will be better to extract this check in one separate function which return true or false



##########
gobblin-temporal/src/main/java/org/apache/gobblin/temporal/joblauncher/GobblinTemporalJobLauncher.java:
##########
@@ -113,7 +121,37 @@ protected void handleLaunchFinalization() {
 
   @Override
   protected void executeCancellation() {
-    log.info("Cancel temporal workflow");
+    if (this.workflowId == null) {
+      log.info("Cancellation of temporal workflow attempted without submitting it");
+      return;
+    }
+
+    log.info("Cancelling temporal workflow {}", this.workflowId);
+    try {
+      WorkflowStub workflowStub = this.client.newUntypedWorkflowStub(this.workflowId);
+
+      // Describe the workflow execution to get its status
+      DescribeWorkflowExecutionRequest request = DescribeWorkflowExecutionRequest.newBuilder()
+          .setNamespace(this.namespace)
+          .setExecution(workflowStub.getExecution())
+          .build();
+      DescribeWorkflowExecutionResponse response = workflowServiceStubs.blockingStub().describeWorkflowExecution(request);
+
+      // Check if the workflow is not finished
+      WorkflowExecutionStatus status = response.getWorkflowExecutionInfo().getStatus();
+      if (status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_FAILED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CANCELED &&
+          status != WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TERMINATED) {
+        workflowStub.cancel();
+        log.info("Temporal workflow {} cancelled successfully", this.workflowId);
+      } else {
+        log.info("Workflow {} is already finished with status {}", this.workflowId, status);
+      }
+    }
+    catch (Exception e) {
+      log.error("Exception occurred while cancelling the workflow " + this.workflowId, e);

Review Comment:
   Can we add more granular level of exception check instead of wrapping each type in same Exception like workflowStub.cancel() can through :
   [WorkflowNotFoundException](https://www.javadoc.io/static/io.temporal/temporal-sdk/1.25.1/io/temporal/client/WorkflowNotFoundException.html) - if the workflow execution doesn't exist or is already completed
   [WorkflowServiceException](https://www.javadoc.io/static/io.temporal/temporal-sdk/1.25.1/io/temporal/client/WorkflowServiceException.html) - for all other failures including networking and service availability issues
   
   so it will be good to have separate catch blocks of this with more detailed logging.



-- 
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: dev-unsubscribe@gobblin.apache.org

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