Skip to content

Commit

Permalink
control-service: user-initiated deployment notifications
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
mivanov1988 committed Oct 5, 2023
1 parent 0b5a97b commit 034f209
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,11 @@ void synchronizeDataJob(
ActualDataJobDeployment actualDataJobDeployment,
boolean isDeploymentPresentInKubernetes) {
if (desiredDataJobDeployment != null) {
boolean sendNotification =
true; // TODO [miroslavi] sends notification only when the deployment is initiated by the
// user.
deploymentService.updateDeployment(
dataJob,
desiredDataJobDeployment,
actualDataJobDeployment,
isDeploymentPresentInKubernetes,
sendNotification);
isDeploymentPresentInKubernetes);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ public class DeploymentServiceV2 {
* @param actualJobDeployment the actual data job deployment has been deployed.
* @param isJobDeploymentPresentInKubernetes if it is true the data job deployment is present in
* Kubernetes.
* @param sendNotification if it is true the method will send a notification to the end user.
*/
@Measurable(includeArg = 0, argName = "data_job")
public void updateDeployment(
DataJob dataJob,
DesiredDataJobDeployment desiredJobDeployment,
ActualDataJobDeployment actualJobDeployment,
boolean isJobDeploymentPresentInKubernetes,
Boolean sendNotification) {
boolean isJobDeploymentPresentInKubernetes) {
if (desiredJobDeployment == null) {
log.warn(
"Skipping the data job [job_name={}] deployment due to the missing deployment data",
Expand All @@ -83,6 +81,9 @@ public void updateDeployment(
return;
}

// Sends notification only when the deployment is initiated by the user.
boolean sendNotification = Boolean.TRUE.equals(desiredJobDeployment.getUserInitiated());

try {
log.info("Starting deployment of job {}", desiredJobDeployment.getDataJobName());
deploymentProgress.started(dataJob.getJobConfig(), desiredJobDeployment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.Setter;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Entity;

@Getter
Expand All @@ -20,4 +21,7 @@
public class DesiredDataJobDeployment extends BaseDataJobDeployment {

private DeploymentStatus status;

@Column(name = "is_user_initiated")
private Boolean userInitiated;
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ private boolean saveDataJobStatus(
actualJobDeploymentRepository.save(actualDataJobDeployment);
}

desiredJobDeploymentRepository.updateDesiredDataJobDeploymentStatusByDataJobName(
dataJobName, deploymentStatus);
desiredJobDeploymentRepository.updateDesiredDataJobDeploymentStatusAndUserInitiatedByDataJobName(
dataJobName, deploymentStatus, false);
return true;
}
log.debug("Data job: {} was deleted or hasn't been created", dataJobName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ int updateDesiredDataJobDeploymentEnabledByDataJobName(
@Transactional
@Modifying(clearAutomatically = true)
@Query(
"update DesiredDataJobDeployment d set d.status = :status where d.dataJobName ="
"update DesiredDataJobDeployment d set d.status = :status, d.userInitiated = :userInitiated where d.dataJobName ="
+ " :dataJobName")
int updateDesiredDataJobDeploymentStatusByDataJobName(
int updateDesiredDataJobDeploymentStatusAndUserInitiatedByDataJobName(
@Param(value = "dataJobName") String dataJobName,
@Param(value = "status") DeploymentStatus status);
@Param(value = "status") DeploymentStatus status,
@Param(value = "userInitiated") Boolean userInitiatedDeployment);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table if exists desired_data_job_deployment
add column if not exists is_user_initiated boolean;
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,43 @@ public void updateDeployment_withDesiredDeploymentStatusNone_shouldStartDeployme
updateDeployment(DeploymentStatus.NONE, 1);
}

@Test
public void updateDeployment_withDesiredDeploymentUserInitiatedDeploymentTrue_shouldSendNotification()
throws IOException, InterruptedException, ApiException {
updateDeployment(DeploymentStatus.NONE, 1, true);

Mockito.verify(jobImageBuilder, Mockito.times(1))
.buildImage(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.eq(true));
}

@Test
public void updateDeployment_withDesiredDeploymentUserInitiatedDeploymentFalse_shouldNotSendNotification()
throws IOException, InterruptedException, ApiException {
updateDeployment(DeploymentStatus.NONE, 1, false);

Mockito.verify(jobImageBuilder, Mockito.times(1))
.buildImage(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.eq(false));
}

private void updateDeployment(
DeploymentStatus deploymentStatus, int deploymentProgressStartedInvocations) throws IOException, InterruptedException, ApiException {
updateDeployment(deploymentStatus, deploymentProgressStartedInvocations, true);
}

private void updateDeployment(
DeploymentStatus deploymentStatus, int deploymentProgressStartedInvocations)
DeploymentStatus deploymentStatus, int deploymentProgressStartedInvocations, boolean sendNotification)
throws IOException, InterruptedException, ApiException {
DesiredDataJobDeployment desiredDataJobDeployment = new DesiredDataJobDeployment();
desiredDataJobDeployment.setStatus(deploymentStatus);
desiredDataJobDeployment.setUserInitiated(sendNotification);
DataJob dataJob = new DataJob();
dataJob.setJobConfig(new JobConfig());
Mockito.when(
jobImageBuilder.buildImage(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn(false);

deploymentService.updateDeployment(
dataJob, desiredDataJobDeployment, new ActualDataJobDeployment(), true, true);
dataJob, desiredDataJobDeployment, new ActualDataJobDeployment(), true);

Mockito.verify(deploymentProgress, Mockito.times(deploymentProgressStartedInvocations))
.started(dataJob.getJobConfig(), desiredDataJobDeployment);
Expand Down

0 comments on commit 034f209

Please sign in to comment.