use of com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException in project cruise-control by linkedin.
the class GoalViolationDetector method run.
@Override
public void run() {
long now = _time.milliseconds();
if (_loadMonitor.clusterModelGeneration().equals(_lastCheckedModelGeneration)) {
LOG.debug("Skipping goal violation detection because the model generation hasn't changed. Current model generation {}", _loadMonitor.clusterModelGeneration());
return;
}
AutoCloseable clusterModelSemaphore = null;
try {
LoadMonitorTaskRunner.LoadMonitorTaskRunnerState loadMonitorTaskRunnerState = _loadMonitor.taskRunnerState();
if (!ViolationUtils.isLoadMonitorReady(loadMonitorTaskRunnerState)) {
LOG.info("Skipping goal violation detection because load monitor is in {} state.", loadMonitorTaskRunnerState);
return;
}
GoalViolations goalViolations = new GoalViolations();
boolean newModelNeeded = true;
ClusterModel clusterModel = null;
for (Map.Entry<Integer, Goal> entry : _goals.entrySet()) {
Goal goal = entry.getValue();
if (_loadMonitor.meetCompletenessRequirements(goal.clusterModelCompletenessRequirements())) {
LOG.debug("Detecting if {} is violated.", entry.getValue().name());
// Because the model generation could be slow, We only get new cluster model if needed.
if (newModelNeeded) {
if (clusterModelSemaphore != null) {
clusterModelSemaphore.close();
}
clusterModelSemaphore = _loadMonitor.acquireForModelGeneration(new OperationProgress());
// Make cluster model null before generating a new cluster model so the current one can be GCed.
clusterModel = null;
clusterModel = _loadMonitor.clusterModel(now, goal.clusterModelCompletenessRequirements(), new OperationProgress());
}
int priority = entry.getKey();
newModelNeeded = optimizeForGoal(clusterModel, priority, goal, goalViolations);
} else {
LOG.debug("Skipping goal violation detection for {} because load completeness requirement is not met.", goal);
}
}
if (clusterModel != null) {
_lastCheckedModelGeneration = clusterModel.generation();
}
if (!goalViolations.violations().isEmpty()) {
_anomalies.add(goalViolations);
}
} catch (NotEnoughValidWindowsException nevwe) {
LOG.debug("Skipping goal violation detection because there are not enough valid windows.");
} catch (KafkaCruiseControlException kcce) {
LOG.warn("Goal violation detector received exception", kcce);
} catch (Exception e) {
LOG.error("Unexpected exception", e);
} finally {
if (clusterModelSemaphore != null) {
try {
clusterModelSemaphore.close();
} catch (Exception e) {
LOG.error("Received exception when closing auto closable semaphore", e);
}
}
LOG.debug("Goal violation detection finished.");
}
}
Aggregations