Skip to content

Commit 034f209

Browse files
committed
control-service: user-initiated deployment notifications
Why Currently, the new deployment mechanism sends notifications every time, lacking the ability to send them only when the user initiates the deployment. What We modified the method to send notifications exclusively when deployments are initiated by the User, by incorporating a check for DeploymentStatus.NONE which represents user-initiated deployments. Testing done: Unit tests. Signed-off-by: Miroslav Ivanov [email protected]
1 parent 0b5a97b commit 034f209

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,11 @@ void synchronizeDataJob(
7979
ActualDataJobDeployment actualDataJobDeployment,
8080
boolean isDeploymentPresentInKubernetes) {
8181
if (desiredDataJobDeployment != null) {
82-
boolean sendNotification =
83-
true; // TODO [miroslavi] sends notification only when the deployment is initiated by the
84-
// user.
8582
deploymentService.updateDeployment(
8683
dataJob,
8784
desiredDataJobDeployment,
8885
actualDataJobDeployment,
89-
isDeploymentPresentInKubernetes,
90-
sendNotification);
86+
isDeploymentPresentInKubernetes);
9187
}
9288
}
9389

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ public class DeploymentServiceV2 {
5757
* @param actualJobDeployment the actual data job deployment has been deployed.
5858
* @param isJobDeploymentPresentInKubernetes if it is true the data job deployment is present in
5959
* Kubernetes.
60-
* @param sendNotification if it is true the method will send a notification to the end user.
6160
*/
6261
@Measurable(includeArg = 0, argName = "data_job")
6362
public void updateDeployment(
6463
DataJob dataJob,
6564
DesiredDataJobDeployment desiredJobDeployment,
6665
ActualDataJobDeployment actualJobDeployment,
67-
boolean isJobDeploymentPresentInKubernetes,
68-
Boolean sendNotification) {
66+
boolean isJobDeploymentPresentInKubernetes) {
6967
if (desiredJobDeployment == null) {
7068
log.warn(
7169
"Skipping the data job [job_name={}] deployment due to the missing deployment data",
@@ -83,6 +81,9 @@ public void updateDeployment(
8381
return;
8482
}
8583

84+
// Sends notification only when the deployment is initiated by the user.
85+
boolean sendNotification = Boolean.TRUE.equals(desiredJobDeployment.getUserInitiated());
86+
8687
try {
8788
log.info("Starting deployment of job {}", desiredJobDeployment.getDataJobName());
8889
deploymentProgress.started(dataJob.getJobConfig(), desiredJobDeployment);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import lombok.Setter;
1111
import lombok.ToString;
1212

13+
import javax.persistence.Column;
1314
import javax.persistence.Entity;
1415

1516
@Getter
@@ -20,4 +21,7 @@
2021
public class DesiredDataJobDeployment extends BaseDataJobDeployment {
2122

2223
private DeploymentStatus status;
24+
25+
@Column(name = "is_user_initiated")
26+
private Boolean userInitiated;
2327
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ private boolean saveDataJobStatus(
107107
actualJobDeploymentRepository.save(actualDataJobDeployment);
108108
}
109109

110-
desiredJobDeploymentRepository.updateDesiredDataJobDeploymentStatusByDataJobName(
111-
dataJobName, deploymentStatus);
110+
desiredJobDeploymentRepository.updateDesiredDataJobDeploymentStatusAndUserInitiatedByDataJobName(
111+
dataJobName, deploymentStatus, false);
112112
return true;
113113
}
114114
log.debug("Data job: {} was deleted or hasn't been created", dataJobName);

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ int updateDesiredDataJobDeploymentEnabledByDataJobName(
4141
@Transactional
4242
@Modifying(clearAutomatically = true)
4343
@Query(
44-
"update DesiredDataJobDeployment d set d.status = :status where d.dataJobName ="
44+
"update DesiredDataJobDeployment d set d.status = :status, d.userInitiated = :userInitiated where d.dataJobName ="
4545
+ " :dataJobName")
46-
int updateDesiredDataJobDeploymentStatusByDataJobName(
46+
int updateDesiredDataJobDeploymentStatusAndUserInitiatedByDataJobName(
4747
@Param(value = "dataJobName") String dataJobName,
48-
@Param(value = "status") DeploymentStatus status);
48+
@Param(value = "status") DeploymentStatus status,
49+
@Param(value = "userInitiated") Boolean userInitiatedDeployment);
4950
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
alter table if exists desired_data_job_deployment
2+
add column if not exists is_user_initiated boolean;

projects/control-service/projects/pipelines_control_service/src/test/java/com/vmware/taurus/service/deploy/DeploymentServiceV2TestIT.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,43 @@ public void updateDeployment_withDesiredDeploymentStatusNone_shouldStartDeployme
4949
updateDeployment(DeploymentStatus.NONE, 1);
5050
}
5151

52+
@Test
53+
public void updateDeployment_withDesiredDeploymentUserInitiatedDeploymentTrue_shouldSendNotification()
54+
throws IOException, InterruptedException, ApiException {
55+
updateDeployment(DeploymentStatus.NONE, 1, true);
56+
57+
Mockito.verify(jobImageBuilder, Mockito.times(1))
58+
.buildImage(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.eq(true));
59+
}
60+
61+
@Test
62+
public void updateDeployment_withDesiredDeploymentUserInitiatedDeploymentFalse_shouldNotSendNotification()
63+
throws IOException, InterruptedException, ApiException {
64+
updateDeployment(DeploymentStatus.NONE, 1, false);
65+
66+
Mockito.verify(jobImageBuilder, Mockito.times(1))
67+
.buildImage(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.eq(false));
68+
}
69+
70+
private void updateDeployment(
71+
DeploymentStatus deploymentStatus, int deploymentProgressStartedInvocations) throws IOException, InterruptedException, ApiException {
72+
updateDeployment(deploymentStatus, deploymentProgressStartedInvocations, true);
73+
}
74+
5275
private void updateDeployment(
53-
DeploymentStatus deploymentStatus, int deploymentProgressStartedInvocations)
76+
DeploymentStatus deploymentStatus, int deploymentProgressStartedInvocations, boolean sendNotification)
5477
throws IOException, InterruptedException, ApiException {
5578
DesiredDataJobDeployment desiredDataJobDeployment = new DesiredDataJobDeployment();
5679
desiredDataJobDeployment.setStatus(deploymentStatus);
80+
desiredDataJobDeployment.setUserInitiated(sendNotification);
5781
DataJob dataJob = new DataJob();
5882
dataJob.setJobConfig(new JobConfig());
5983
Mockito.when(
6084
jobImageBuilder.buildImage(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
6185
.thenReturn(false);
6286

6387
deploymentService.updateDeployment(
64-
dataJob, desiredDataJobDeployment, new ActualDataJobDeployment(), true, true);
88+
dataJob, desiredDataJobDeployment, new ActualDataJobDeployment(), true);
6589

6690
Mockito.verify(deploymentProgress, Mockito.times(deploymentProgressStartedInvocations))
6791
.started(dataJob.getJobConfig(), desiredDataJobDeployment);

0 commit comments

Comments
 (0)