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;
}
Aggregations