Skip to content
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

control-service: user-initiated deployment notifications #2757

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,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,9 @@ 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 ="
+ " :dataJobName")
int updateDesiredDataJobDeploymentStatusByDataJobName(
"update DesiredDataJobDeployment d set d.status = :status, d.userInitiated = :userInitiated"
+ " where d.dataJobName = :dataJobName")
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,48 @@ 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,
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