This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1136751 - drift detection interval for individual drift definitio…
…n is *always* ignored and value from agent config is used Fix issues with previous commit. Prevent the DriftDetector from running in infinite loop: * when the queue is full of disabled schedules * when a previous snapshot file exists (cherry picked from commit 487cc7c) Signed-off-by: Thomas Segismont <tsegismo@redhat.com>
- Loading branch information
1 parent
dfee834
commit 5467553
Showing
4 changed files
with
162 additions
and
19 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...-container/src/main/java/org/rhq/core/pc/drift/DriftDetectionScheduleQueueComparator.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,41 @@ | ||
/* | ||
* RHQ Management Platform | ||
* Copyright (C) 2005-2014 Red Hat, Inc. | ||
* All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | ||
*/ | ||
|
||
package org.rhq.core.pc.drift; | ||
|
||
/** | ||
* Comparator for a {@link java.util.PriorityQueue} of {@link DriftDetectionSchedule} instances. Disabled schedules go | ||
* at the end of the queue, enabled schedules are ordered by nextScan property. | ||
* | ||
* @author Thomas Segismont | ||
*/ | ||
class DriftDetectionScheduleQueueComparator implements java.util.Comparator<DriftDetectionSchedule> { | ||
@Override | ||
public int compare(DriftDetectionSchedule schedule1, DriftDetectionSchedule schedule2) { | ||
boolean enabled1 = schedule1.getDriftDefinition().isEnabled(); | ||
boolean enabled2 = schedule2.getDriftDefinition().isEnabled(); | ||
int diff = (enabled1 == enabled2) ? 0 : (enabled2 ? 1 : -1); | ||
if (diff == 0) { | ||
long nextScan1 = schedule1.getNextScan(); | ||
long nextScan2 = schedule2.getNextScan(); | ||
diff = (nextScan1 == nextScan2) ? 0 : (nextScan2 > nextScan1 ? 1 : -1); | ||
} | ||
return diff; | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
...tainer/src/test/java/org/rhq/core/pc/drift/DriftDetectionScheduleQueueComparatorTest.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,87 @@ | ||
/* | ||
* RHQ Management Platform | ||
* Copyright (C) 2005-2014 Red Hat, Inc. | ||
* All rights reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation version 2 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | ||
*/ | ||
|
||
package org.rhq.core.pc.drift; | ||
|
||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertTrue; | ||
import static org.testng.Assert.fail; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.PriorityQueue; | ||
import java.util.Random; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import org.rhq.core.domain.configuration.Configuration; | ||
import org.rhq.core.domain.drift.DriftDefinition; | ||
|
||
public class DriftDetectionScheduleQueueComparatorTest { | ||
private static final int DISABLED_COUNT = 100; | ||
private static final int TOTAL = DISABLED_COUNT * 20; | ||
|
||
@Test | ||
public void testPriority() { | ||
Collection<DriftDetectionSchedule> sampleSchedules = createSampleSchedules(); | ||
|
||
PriorityQueue<DriftDetectionSchedule> priorityQueue = new PriorityQueue<DriftDetectionSchedule>( | ||
sampleSchedules.size(), new DriftDetectionScheduleQueueComparator()); | ||
priorityQueue.addAll(sampleSchedules); | ||
|
||
DriftDetectionSchedule previousSchedule = priorityQueue.poll(); | ||
assertNotNull(previousSchedule); | ||
|
||
DriftDetectionSchedule schedule; | ||
boolean foundDisabled = !previousSchedule.getDriftDefinition().isEnabled(); | ||
while ((schedule = priorityQueue.poll()) != null) { | ||
boolean enabled = schedule.getDriftDefinition().isEnabled(); | ||
if (foundDisabled && enabled) { | ||
fail("All disabled schedule should be at the end of queue"); | ||
} | ||
foundDisabled = !enabled; | ||
if (!foundDisabled) { | ||
assertTrue(schedule.getNextScan() < previousSchedule.getNextScan(), "getNextScan priority failure"); | ||
} | ||
previousSchedule = schedule; | ||
} | ||
} | ||
|
||
private static Collection<DriftDetectionSchedule> createSampleSchedules() { | ||
Random random = new Random(); | ||
List<DriftDetectionSchedule> schedules = new ArrayList<DriftDetectionSchedule>(TOTAL); | ||
for (int i = 0; i < TOTAL; i++) { | ||
schedules.add(newScheduleInstance(random.nextLong(), i > DISABLED_COUNT)); | ||
} | ||
Collections.shuffle(schedules); | ||
return schedules; | ||
} | ||
|
||
private static DriftDetectionSchedule newScheduleInstance(long interval, boolean enabled) { | ||
DriftDefinition definition = new DriftDefinition(new Configuration()); | ||
definition.setEnabled(enabled); | ||
definition.setInterval(interval); | ||
DriftDetectionSchedule driftDetectionSchedule = new DriftDetectionSchedule(-1, definition); | ||
driftDetectionSchedule.updateShedule(); | ||
return driftDetectionSchedule; | ||
} | ||
|
||
} |