Search in sources :

Example 6 with NotEnoughValidWindowsException

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.");
    }
}
Also used : OperationProgress(com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress) LoadMonitorTaskRunner(com.linkedin.kafka.cruisecontrol.monitor.task.LoadMonitorTaskRunner) KafkaCruiseControlException(com.linkedin.kafka.cruisecontrol.exception.KafkaCruiseControlException) NotEnoughValidWindowsException(com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException) NotEnoughValidWindowsException(com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException) KafkaCruiseControlException(com.linkedin.kafka.cruisecontrol.exception.KafkaCruiseControlException) ClusterModel(com.linkedin.kafka.cruisecontrol.model.ClusterModel) Goal(com.linkedin.kafka.cruisecontrol.analyzer.goals.Goal) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

NotEnoughValidWindowsException (com.linkedin.cruisecontrol.exception.NotEnoughValidWindowsException)6 OperationProgress (com.linkedin.kafka.cruisecontrol.async.progress.OperationProgress)6 ClusterModel (com.linkedin.kafka.cruisecontrol.model.ClusterModel)4 Test (org.junit.Test)4 KafkaMetricSampleAggregator (com.linkedin.kafka.cruisecontrol.monitor.sampling.aggregator.KafkaMetricSampleAggregator)3 ValuesAndExtrapolations (com.linkedin.cruisecontrol.monitor.sampling.aggregator.ValuesAndExtrapolations)1 Goal (com.linkedin.kafka.cruisecontrol.analyzer.goals.Goal)1 MetadataClient (com.linkedin.kafka.cruisecontrol.common.MetadataClient)1 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)1 KafkaCruiseControlException (com.linkedin.kafka.cruisecontrol.exception.KafkaCruiseControlException)1 ModelCompletenessRequirements (com.linkedin.kafka.cruisecontrol.monitor.ModelCompletenessRequirements)1 PartitionEntity (com.linkedin.kafka.cruisecontrol.monitor.sampling.PartitionEntity)1 LoadMonitorTaskRunner (com.linkedin.kafka.cruisecontrol.monitor.task.LoadMonitorTaskRunner)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Metadata (org.apache.kafka.clients.Metadata)1 Cluster (org.apache.kafka.common.Cluster)1