-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
control-service: deployment controller reads from db (#2800)
what: DataJobDeploymentController now has the functionality to read from the DB. why: Part of the persistence VEP which can be found here - https://github.com/vmware/versatile-data-kit/tree/main/specs/vep-2272-complete-data-job-configuration-persistence This PR will reduce the overhead on K8S when making API calls to the control-service. testing: added unit tests. --------- Signed-off-by: mrMoZ1 <[email protected]> Co-authored-by: github-actions <>
- Loading branch information
Momchil Z
authored
Oct 18, 2023
1 parent
286f5e7
commit e9af4fa
Showing
4 changed files
with
270 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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
73 changes: 73 additions & 0 deletions
73
...lines_control_service/src/test/java/com/vmware/taurus/datajobs/ModelApiConverterTest.java
This file contains 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,73 @@ | ||
/* | ||
* Copyright 2021-2023 VMware, Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.vmware.taurus.datajobs; | ||
|
||
import com.vmware.taurus.service.model.ActualDataJobDeployment; | ||
import com.vmware.taurus.service.model.DataJob; | ||
import com.vmware.taurus.service.model.DataJobDeploymentResources; | ||
import com.vmware.taurus.service.model.JobConfig; | ||
import java.time.OffsetDateTime; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ModelApiConverterTest { | ||
|
||
@Test | ||
public void testToJobDeploymentStatus() { | ||
var job = createTestJob("name", "team"); | ||
var deployment = createActualJobDeployment(job); | ||
var status = DeploymentModelConverter.toJobDeploymentStatus(deployment, job); | ||
|
||
Assertions.assertEquals("test-sha", status.getJobVersion()); | ||
Assertions.assertEquals("3.9-secure", status.getPythonVersion()); | ||
Assertions.assertEquals("name", status.getId()); | ||
Assertions.assertEquals(true, status.getEnabled()); | ||
Assertions.assertEquals("user", status.getLastDeployedBy()); | ||
Assertions.assertEquals(OffsetDateTime.MIN.toString(), status.getLastDeployedDate()); | ||
Assertions.assertEquals("[email protected]", status.getContacts().getNotifiedOnJobDeploy().get(0)); | ||
Assertions.assertEquals(1, status.getResources().getMemoryLimit()); | ||
Assertions.assertEquals(1, status.getResources().getMemoryRequest()); | ||
Assertions.assertEquals(1f, status.getResources().getCpuLimit()); | ||
Assertions.assertEquals(1f, status.getResources().getCpuRequest()); | ||
} | ||
|
||
@Test | ||
public void testToJobDeploymentStatus_emptyValues_expectNoExceptions() { | ||
var job = new DataJob(); | ||
var deployment = new ActualDataJobDeployment(); | ||
DeploymentModelConverter.toJobDeploymentStatus(deployment, job); | ||
} | ||
|
||
private DataJob createTestJob(String jobName, String teamName) { | ||
var dataJob = ToModelApiConverter.toDataJob(TestUtils.getDataJob(teamName, jobName)); | ||
var jobConfig = new JobConfig(); | ||
jobConfig.setTeam(teamName); | ||
jobConfig.setNotifiedOnJobDeploy(List.of("[email protected]")); | ||
dataJob.setJobConfig(jobConfig); | ||
return dataJob; | ||
} | ||
|
||
private ActualDataJobDeployment createActualJobDeployment(DataJob dataJob) { | ||
var deployment = new ActualDataJobDeployment(); | ||
deployment.setGitCommitSha("actualSha"); | ||
deployment.setDataJob(dataJob); | ||
deployment.setDataJobName(dataJob.getName()); | ||
deployment.setPythonVersion("3.9-secure"); | ||
deployment.setEnabled(true); | ||
deployment.setLastDeployedBy("user"); | ||
deployment.setSchedule("sched"); | ||
deployment.setDeploymentVersionSha("test-sha"); | ||
deployment.setLastDeployedDate(OffsetDateTime.MIN); | ||
var resources = new DataJobDeploymentResources(); | ||
resources.setMemoryLimitMi(1); | ||
resources.setMemoryRequestMi(1); | ||
resources.setCpuLimitCores(1f); | ||
resources.setCpuRequestCores(1f); | ||
deployment.setResources(resources); | ||
return deployment; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...e/src/test/java/com/vmware/taurus/service/deploy/DataJobDeploymentControllerReadTest.java
This file contains 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,105 @@ | ||
/* | ||
* Copyright 2021-2023 VMware, Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.vmware.taurus.service.deploy; | ||
|
||
import com.vmware.taurus.ControlplaneApplication; | ||
import com.vmware.taurus.controlplane.model.data.DataJobMode; | ||
import com.vmware.taurus.datajobs.DataJobsDeploymentController; | ||
import com.vmware.taurus.datajobs.TestUtils; | ||
import com.vmware.taurus.datajobs.ToModelApiConverter; | ||
import com.vmware.taurus.service.model.ActualDataJobDeployment; | ||
import com.vmware.taurus.service.model.DataJob; | ||
import com.vmware.taurus.service.model.DataJobDeploymentResources; | ||
import com.vmware.taurus.service.model.JobConfig; | ||
import com.vmware.taurus.service.repository.ActualJobDeploymentRepository; | ||
import com.vmware.taurus.service.repository.JobsRepository; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
@SpringBootTest(classes = ControlplaneApplication.class) | ||
@TestPropertySource( | ||
properties = {"datajobs.deployment.configuration.persistence.readDataSource=DB"}) | ||
public class DataJobDeploymentControllerReadTest { | ||
|
||
@Autowired JobsRepository jobsRepository; | ||
@Autowired DataJobsDeploymentController dataJobsDeploymentController; | ||
@Autowired ActualJobDeploymentRepository actualJobDeploymentRepository; | ||
|
||
@WithMockUser | ||
@Test | ||
public void testReadJob_expectResponse() { | ||
var job = createTestJob("test-job", "team"); | ||
createActualJobDeployment(job); | ||
var retrievedDeployment = dataJobsDeploymentController.deploymentRead("team", "test-job", ""); | ||
Assertions.assertEquals(200, retrievedDeployment.getStatusCodeValue()); | ||
Assertions.assertEquals("test-job", retrievedDeployment.getBody().getId()); | ||
} | ||
|
||
@WithMockUser | ||
@Test | ||
public void testReadJob_expectNoResponse() { | ||
var retrievedDeployment = dataJobsDeploymentController.deploymentRead("team", "test-job", ""); | ||
Assertions.assertEquals(404, retrievedDeployment.getStatusCodeValue()); | ||
} | ||
|
||
@WithMockUser | ||
@Test | ||
public void testReadJob_asList_expectResponse() { | ||
var job = createTestJob("test-job", "team"); | ||
createActualJobDeployment(job); | ||
var retrievedDeploymentList = | ||
dataJobsDeploymentController.deploymentList("team", "test-job", "", DataJobMode.RELEASE); | ||
Assertions.assertEquals(200, retrievedDeploymentList.getStatusCodeValue()); | ||
Assertions.assertEquals("test-job", retrievedDeploymentList.getBody().get(0).getId()); | ||
} | ||
|
||
@WithMockUser | ||
@Test | ||
public void testReadJob_asList_expectNoResponse() { | ||
var retrievedDeploymentList = | ||
dataJobsDeploymentController.deploymentList("team", "test-job", "", DataJobMode.RELEASE); | ||
Assertions.assertEquals(404, retrievedDeploymentList.getStatusCodeValue()); | ||
} | ||
|
||
@AfterEach | ||
public void cleanup() { | ||
jobsRepository.deleteAll(); | ||
actualJobDeploymentRepository.deleteAll(); | ||
} | ||
|
||
private DataJob createTestJob(String jobName, String teamName) { | ||
var dataJob = ToModelApiConverter.toDataJob(TestUtils.getDataJob(teamName, jobName)); | ||
var jobConfig = new JobConfig(); | ||
jobConfig.setTeam(teamName); | ||
dataJob.setJobConfig(jobConfig); | ||
jobsRepository.save(dataJob); | ||
return dataJob; | ||
} | ||
|
||
private ActualDataJobDeployment createActualJobDeployment(DataJob dataJob) { | ||
var deployment = new ActualDataJobDeployment(); | ||
deployment.setGitCommitSha("actualSha"); | ||
deployment.setDataJob(dataJob); | ||
deployment.setDataJobName(dataJob.getName()); | ||
deployment.setPythonVersion("3.9-secure"); | ||
deployment.setEnabled(true); | ||
deployment.setLastDeployedBy("user"); | ||
deployment.setSchedule("sched"); | ||
var resources = new DataJobDeploymentResources(); | ||
resources.setMemoryLimitMi(1); | ||
resources.setMemoryRequestMi(1); | ||
resources.setCpuLimitCores(1f); | ||
resources.setCpuRequestCores(1f); | ||
deployment.setResources(resources); | ||
actualJobDeploymentRepository.save(deployment); | ||
return deployment; | ||
} | ||
} |