8000 control-service: Fix JsonSyntaxException when cancelling execution (#… · vmware/versatile-data-kit@803942c · GitHub
[go: up one dir, main page]

Skip to content

Commit 803942c

Browse files
author
Momchil Z
authored
control-service: Fix JsonSyntaxException when cancelling execution (#192)
Why: During testing of the new feature - cancelling a running or submitted data job execution I stumbled upon an error in the K8S api. A sucessfull call would throw a JsonSyntaxException. This is a known issue on the K8S API - kubernetes-client/java#86 . We already handle this in other methods. What: Mimicked the way we handle this exception in our codebase and modified the cancelRunningCronJob method to handle JsonSyntaxExceptions. Type: Bug fix. Testing: ci/cd and ran tests concerning Execution cancellation locally. Signed-off-by: mrMoZ1 <mzhivkov@vmware.com>
1 parent 8f54d55 commit 803942c

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/KubernetesService.java

+19-10
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,25 @@ public void startNewCronJobExecution(String cronJobName, String executionId, Map
475475

476476
public void cancelRunningCronJob(String teamName, String jobName, String executionId) throws ApiException {
477477
log.info("K8S deleting job for team: {} data job name: {} execution: {}", teamName, jobName, executionId);
478-
var operationResponse = new BatchV1Api(client).deleteNamespacedJob(executionId, namespace, null,
479-
null, null,
480-
null,
481-
null,
482-
"Foreground");
483-
484-
//Status of the operation. One of: "Success" or "Failure"
485-
if (operationResponse.getStatus().equals("Failure")) {
486-
log.warn("Failed to delete K8S job. Reason: {} Details: {}", operationResponse.getReason(), operationResponse.getDetails().toString());
487-
throw new ApiException(operationResponse.getCode(), operationResponse.getMessage());
478+
try {
479+
var operationResponse = new BatchV1Api(client).deleteNamespacedJob(executionId, namespace, null,
480+
null, null,
481+
null,
482+
null,
483+
"Foreground");
484+
//Status of the operation. One of: "Success" or "Failure"
485+
if (operationResponse.getStatus().equals("Failure")) {
486+
log.warn("Failed to delete K8S job. Reason: {} Details: {}", operationResponse.getReason(), operationResponse.getDetails().toString());
487+
throw new ApiException(operationResponse.getCode(), operationResponse.getMessage());
488+
}
489+
490+
} catch (JsonSyntaxException e) {
491+
if (e.getCause() instanceof IllegalStateException) {
492+
IllegalStateException ise = (IllegalStateException) e.getCause();
493+
if (ise.getMessage() != null && ise.getMessage().contains("Expected a string but was BEGIN_OBJECT"))
494+
log.debug("Catching exception because of issue https://github.com/kubernetes-client/java/issues/86", e);
495+
else throw e;
496+
} else throw e;
488497
}
489498
}
490499

projects/control-service/projects/pipelines_control_service/src/main/java/com/vmware/taurus/service/execution/JobExecutionService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package com.vmware.taurus.service.execution;
77

8+
import com.google.gson.JsonSyntaxException;
89
import com.vmware.taurus.controlplane.model.data.DataJobExecution;
910
import com.vmware.taurus.controlplane.model.data.DataJobExecutionRequest;
1011
import com.vmware.taurus.datajobs.ToApiModelConverter;
@@ -138,7 +139,7 @@ public void cancelDataJobExecution(String teamName, String jobName, String execu
138139
jobExecutionRepository.save(jobExecution);
139140
log.info("Cancelled data job execution {} successfully.", executionId);
140141

141-
} catch (ApiException e) {
142+
} catch (ApiException | JsonSyntaxException e) {
142143
throw new KubernetesException(String.format("Cannot cancel a Data Job '%s' execution with execution id '%s'", jobName, executionId), e);
143144
}
144145
}

0 commit comments

Comments
 (0)
0