Search in sources :

Example 1 with TaskScheduler

use of com.netflix.fenzo.TaskScheduler in project mantis by Netflix.

the class SchedulingService method setupTaskSchedulerAndAutoScaler.

private TaskScheduler setupTaskSchedulerAndAutoScaler(Observable<String> vmLeaseRescindedObservable, TaskScheduler.Builder schedulerBuilder) {
    int minMinIdle = 4;
    schedulerBuilder = schedulerBuilder.withAutoScaleDownBalancedByAttributeName(ConfigurationProvider.getConfig().getHostZoneAttributeName()).withAutoScalerMapHostnameAttributeName(ConfigurationProvider.getConfig().getAutoScalerMapHostnameAttributeName());
    final AgentClustersAutoScaler agentClustersAutoScaler = AgentClustersAutoScaler.get();
    try {
        if (agentClustersAutoScaler != null) {
            Set<AutoScaleRule> rules = agentClustersAutoScaler.getRules();
            if (rules != null && !rules.isEmpty()) {
                for (AutoScaleRule rule : rules) {
                    schedulerBuilder = schedulerBuilder.withAutoScaleRule(rule);
                    minMinIdle = Math.min(minMinIdle, rule.getMinIdleHostsToKeep());
                }
            } else
                logger.warn("No auto scale rules setup");
        }
    } catch (IllegalStateException e) {
        logger.warn("Ignoring: " + e.getMessage());
    }
    schedulerBuilder = schedulerBuilder.withMaxOffersToReject(Math.max(1, minMinIdle));
    final TaskScheduler scheduler = schedulerBuilder.build();
    vmLeaseRescindedObservable.doOnNext(new Action1<String>() {

        @Override
        public void call(String s) {
            if (s.equals("ALL"))
                scheduler.expireAllLeases();
            else
                scheduler.expireLease(s);
        }
    }).subscribe();
    if (agentClustersAutoScaler != null) {
        final Observer<AutoScaleAction> autoScaleActionObserver = agentClustersAutoScaler.getAutoScaleActionObserver();
        scheduler.setAutoscalerCallback(new com.netflix.fenzo.functions.Action1<AutoScaleAction>() {

            @Override
            public void call(AutoScaleAction action) {
                try {
                    switch(action.getType()) {
                        case Up:
                            numAutoScaleUpActions.increment();
                            break;
                        case Down:
                            numAutoScaleDownActions.increment();
                            break;
                    }
                    autoScaleActionObserver.onNext(action);
                } catch (Exception e) {
                    logger.warn("Will continue after exception calling autoscale action observer: " + e.getMessage(), e);
                }
            }
        });
    }
    return scheduler;
}
Also used : Action1(rx.functions.Action1) AutoScaleRule(com.netflix.fenzo.AutoScaleRule) TaskScheduler(com.netflix.fenzo.TaskScheduler) AutoScaleAction(com.netflix.fenzo.AutoScaleAction) TaskQueueException(com.netflix.fenzo.queues.TaskQueueException)

Aggregations

AutoScaleAction (com.netflix.fenzo.AutoScaleAction)1 AutoScaleRule (com.netflix.fenzo.AutoScaleRule)1 TaskScheduler (com.netflix.fenzo.TaskScheduler)1 TaskQueueException (com.netflix.fenzo.queues.TaskQueueException)1 Action1 (rx.functions.Action1)1