Skip to content

Commit

Permalink
[HWKMETRICS-643] Disable the job for deleting expired metrics if the …
Browse files Browse the repository at this point in the history
…run interval configuration is zero or negative.

(cherry picked from commit 9523163)
Signed-off-by: Stefan Negrea <snegrea@redhat.com>
  • Loading branch information
Stefan Negrea committed Apr 11, 2017
1 parent 00e263c commit 81ff6ea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ private void maybeScheduleMetricExpirationJob(List<JobDetails> backgroundJobs) {
if (config.get(jobIdConfigKey) != null) {
Integer configuredJobFrequency = null;
try {
configuredJobFrequency = Integer.parseInt(config.get("jobFrequency"));
configuredJobFrequency = Integer.parseInt(config.get(jobFrequencyKey));
} catch (Exception e) {
//do nothing, the parsing failed which makes the value unknown
}

if (configuredJobFrequency == null || configuredJobFrequency != this.metricExpirationJobFrequencyInDays) {
if (configuredJobFrequency == null || configuredJobFrequency != this.metricExpirationJobFrequencyInDays
|| this.metricExpirationJobFrequencyInDays <= 0 || configuredJobFrequency <= 0) {
scheduler.unscheduleJob(config.get(jobIdConfigKey)).await();
configurationService.delete(configId, jobIdConfigKey).toBlocking();
config.delete(jobIdConfigKey);
Expand All @@ -187,7 +188,7 @@ private void maybeScheduleMetricExpirationJob(List<JobDetails> backgroundJobs) {
}
}

if (config.get(jobIdConfigKey) == null) {
if (config.get(jobIdConfigKey) == null && this.metricExpirationJobFrequencyInDays > 0) {
logger.info("Preparing to create and schedule " + DeleteExpiredMetrics.JOB_NAME + " job");

//Get start of next day
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;

import java.lang.reflect.Method;
import java.util.List;
Expand Down Expand Up @@ -101,16 +102,27 @@ public void initTest(Method method) {
jobScheduler = new TestScheduler(rxSession);
jobScheduler.truncateTables(getKeyspace());

jobsService = new JobsServiceImpl(2, 7);
if (method.getName().equals("testScheduleDeleteExpiredMetricsJobDisabled")) {
jobsService = new JobsServiceImpl(2, -1);
} else {
jobsService = new JobsServiceImpl(2, 7);
}
jobsService.setSession(rxSession);
jobsService.setScheduler(jobScheduler);
jobsService.setMetricsService(metricsService);
jobsService.setConfigurationService(configurationService);

deleteExpiredMetricsJob = jobsService.start().stream()
.filter(details -> details.getJobName().equals(DeleteExpiredMetrics.JOB_NAME))
.findFirst().get();
assertNotNull(deleteExpiredMetricsJob);
if (method.getName().equals("testScheduleDeleteExpiredMetricsJobDisabled")) {
assertEquals(jobsService.start().stream()
.filter(details -> details.getJobName().equals(DeleteExpiredMetrics.JOB_NAME))
.count(), 0);
deleteExpiredMetricsJob = null;
} else {
deleteExpiredMetricsJob = jobsService.start().stream()
.filter(details -> details.getJobName().equals(DeleteExpiredMetrics.JOB_NAME))
.findFirst().get();
assertNotNull(deleteExpiredMetricsJob);
}
}

@AfterMethod(alwaysRun = true)
Expand Down Expand Up @@ -240,6 +252,11 @@ public void testScheduleDeleteExpiredMetricsJob() throws Exception {
assertEquals(metrics.get(0).getId(), "C2");
}

@Test
public void testScheduleDeleteExpiredMetricsJobDisabled() throws Exception {
assertNull(this.deleteExpiredMetricsJob);
}

private void waitForScheduledDeleteExpiredMetricsJob() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
jobScheduler.onJobFinished(jobDetails -> {
Expand Down

0 comments on commit 81ff6ea

Please sign in to comment.