-
Notifications
You must be signed in to change notification settings - Fork 80
control-service: refactor job cancellation method due to 404 errors #1114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
19f8e63
control-service: refactor job cancellation method due to 404 errors
7af1a04
Google Java Format
27792a5
Merge branch 'main' into person/mzhivkov/fix-job-cancellation-not-found
6662e34
control-service: add integration test
ebc38c0
Google Java Format
ae36332
control-service: fix failing unit tests
04f15ad
Google Java Format
8b785e6
Merge branch 'main' into person/mzhivkov/fix-job-cancellation-not-found
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
200 changes: 200 additions & 0 deletions
200
...ervice/src/integration-test/java/com/vmware/taurus/datajobs/it/DataJobCancellationIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| /* | ||
| * Copyright 2021 VMware, Inc. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package com.vmware.taurus.datajobs.it; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.google.gson.Gson; | ||
| import com.google.gson.internal.LinkedTreeMap; | ||
| import com.vmware.taurus.ControlplaneApplication; | ||
| import com.vmware.taurus.controlplane.model.data.DataJobVersion; | ||
| import com.vmware.taurus.datajobs.it.common.BaseIT; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.apache.commons.io.IOUtils; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.platform.commons.util.StringUtils; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.context.annotation.Import; | ||
| import org.springframework.http.HttpHeaders; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.test.web.servlet.MvcResult; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.UUID; | ||
|
|
||
| import static com.vmware.taurus.datajobs.it.common.WebHookServerMockExtension.TEST_TEAM_NAME; | ||
| import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; | ||
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
|
||
| @Slf4j | ||
| @Import({DataJobDeploymentCrudIT.TaskExecutorConfig.class}) | ||
| @SpringBootTest( | ||
| webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
| classes = ControlplaneApplication.class) | ||
| public class DataJobCancellationIT extends BaseIT { | ||
|
|
||
| private static final String TEST_JOB_NAME = | ||
| "cancellation-test-" + UUID.randomUUID().toString().substring(0, 8); | ||
| private static final Object DEPLOYMENT_ID = "testing-cancellation"; | ||
|
|
||
| @AfterEach | ||
| public void cleanUp() throws Exception { | ||
| // delete job | ||
| mockMvc | ||
| .perform( | ||
| delete( | ||
| String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s/sources", TEST_TEAM_NAME, TEST_JOB_NAME)) | ||
| .with(user("user"))) | ||
| .andExpect(status().isOk()); | ||
|
|
||
| // Execute delete deployment | ||
| mockMvc | ||
| .perform( | ||
| delete( | ||
| String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s/deployments/%s", | ||
| TEST_TEAM_NAME, TEST_JOB_NAME, DEPLOYMENT_ID)) | ||
| .with(user("user")) | ||
| .contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isAccepted()); | ||
| } | ||
|
|
||
| @BeforeEach | ||
| public void setup() throws Exception { | ||
| String dataJobRequestBody = getDataJobRequestBody(TEST_TEAM_NAME, TEST_JOB_NAME); | ||
|
|
||
| // Execute create job | ||
| mockMvc | ||
| .perform( | ||
| post(String.format("/data-jobs/for-team/%s/jobs", TEST_TEAM_NAME)) | ||
| .with(user("user")) | ||
| .content(dataJobRequestBody) | ||
| .contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isCreated()) | ||
| .andExpect( | ||
| header() | ||
| .string( | ||
| HttpHeaders.LOCATION, | ||
| lambdaMatcher( | ||
| s -> | ||
| s.endsWith( | ||
| String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s", | ||
| TEST_TEAM_NAME, TEST_JOB_NAME))))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testJobCancellation_createDeployExecuteAndCancelJob() throws Exception { | ||
| // Take the job zip as byte array | ||
| byte[] jobZipBinary = | ||
| IOUtils.toByteArray( | ||
| getClass().getClassLoader().getResourceAsStream("simple_job_cancel.zip")); | ||
|
|
||
| // Execute job upload with user | ||
| MvcResult jobUploadResult = | ||
| mockMvc | ||
| .perform( | ||
| post(String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s/sources", TEST_TEAM_NAME, TEST_JOB_NAME)) | ||
| .with(user("user")) | ||
| .content(jobZipBinary) | ||
| .contentType(MediaType.APPLICATION_OCTET_STREAM)) | ||
| .andExpect(status().isOk()) | ||
| .andReturn(); | ||
|
|
||
| DataJobVersion testDataJobVersion = | ||
| new ObjectMapper() | ||
| .readValue(jobUploadResult.getResponse().getContentAsString(), DataJobVersion.class); | ||
| Assertions.assertNotNull(testDataJobVersion); | ||
|
|
||
| String testJobVersionSha = testDataJobVersion.getVersionSha(); | ||
| Assertions.assertFalse(StringUtils.isBlank(testJobVersionSha)); | ||
|
|
||
| // Setup | ||
| String dataJobDeploymentRequestBody = getDataJobDeploymentRequestBody(testJobVersionSha); | ||
|
|
||
| // Execute build and deploy job | ||
| mockMvc | ||
| .perform( | ||
| post(String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s/deployments", TEST_TEAM_NAME, TEST_JOB_NAME)) | ||
| .with(user("user")) | ||
| .content(dataJobDeploymentRequestBody) | ||
| .contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isAccepted()) | ||
| .andReturn(); | ||
|
|
||
| // manually start job execution | ||
| mockMvc | ||
| .perform( | ||
| post(String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s/deployments/%s/executions", | ||
| TEST_TEAM_NAME, TEST_JOB_NAME, TEST_JOB_DEPLOYMENT_ID)) | ||
| .with(user("user")) | ||
| .contentType(MediaType.APPLICATION_JSON) | ||
| .content( | ||
| "{\n" | ||
| + " \"args\": {\n" | ||
| + " \"key\": \"value\"\n" | ||
| + " },\n" | ||
| + " \"started_by\": \"schedule/runtime\"\n" | ||
| + "}")) | ||
| .andExpect(status().is(202)) | ||
| .andReturn(); | ||
|
|
||
| // wait for pod to initialize | ||
| Thread.sleep(10000); | ||
|
|
||
| // retrieve running job execution id. | ||
| var exc = | ||
| mockMvc | ||
| .perform( | ||
| get(String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s/deployments/%s/executions", | ||
| TEST_TEAM_NAME, TEST_JOB_NAME, TEST_JOB_DEPLOYMENT_ID)) | ||
| .with(user("user")) | ||
| .contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isOk()) | ||
| .andReturn(); | ||
|
|
||
| var gson = new Gson(); | ||
| ArrayList<LinkedTreeMap> parsed = | ||
| gson.fromJson(exc.getResponse().getContentAsString(), ArrayList.class); | ||
| String executionId = (String) parsed.get(0).get("id"); | ||
|
|
||
| // cancel running execution | ||
| mockMvc | ||
| .perform( | ||
| delete( | ||
| String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s/executions/%s", | ||
| TEST_TEAM_NAME, TEST_JOB_NAME, executionId)) | ||
| .with(user("user")) | ||
| .contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isOk()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testJobCancellation_nonExistingJob() throws Exception { | ||
|
|
||
| mockMvc | ||
| .perform( | ||
| delete( | ||
| String.format( | ||
| "/data-jobs/for-team/%s/jobs/%s/executions/%s", | ||
| TEST_TEAM_NAME, TEST_JOB_NAME, "executionId")) | ||
| .with(user("user")) | ||
| .contentType(MediaType.APPLICATION_JSON)) | ||
| .andExpect(status().isNotFound()); | ||
| } | ||
| } |
Binary file added
BIN
+2.48 KB
...e/projects/pipelines_control_service/src/integration-test/resources/simple_job_cancel.zip
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.