Search in sources :

Example 1 with AutoScaleAction

use of com.netflix.fenzo.AutoScaleAction 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)

Example 2 with AutoScaleAction

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

the class MantisMasterAPI method setupDummyAgentClusterAutoScaler.

private static void setupDummyAgentClusterAutoScaler() {
    final AutoScaleRule dummyAutoScaleRule = new AutoScaleRule() {

        @Override
        public String getRuleName() {
            return "test";
        }

        @Override
        public int getMinIdleHostsToKeep() {
            return 1;
        }

        @Override
        public int getMaxIdleHostsToKeep() {
            return 10;
        }

        @Override
        public long getCoolDownSecs() {
            return 300;
        }

        @Override
        public boolean idleMachineTooSmall(VirtualMachineLease lease) {
            return false;
        }
    };
    AgentClustersAutoScaler.initialize(() -> new HashSet<>(Collections.singletonList(dummyAutoScaleRule)), new Observer<AutoScaleAction>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onNext(AutoScaleAction autoScaleAction) {
        }
    });
}
Also used : AutoScaleRule(com.netflix.fenzo.AutoScaleRule) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) AutoScaleAction(com.netflix.fenzo.AutoScaleAction)

Example 3 with AutoScaleAction

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

the class MasterMain method setupDummyAgentClusterAutoScaler.

private static void setupDummyAgentClusterAutoScaler() {
    final AutoScaleRule dummyAutoScaleRule = new AutoScaleRule() {

        @Override
        public String getRuleName() {
            return "test";
        }

        @Override
        public int getMinIdleHostsToKeep() {
            return 1;
        }

        @Override
        public int getMaxIdleHostsToKeep() {
            return 10;
        }

        @Override
        public long getCoolDownSecs() {
            return 300;
        }

        @Override
        public boolean idleMachineTooSmall(VirtualMachineLease lease) {
            return false;
        }
    };
    AgentClustersAutoScaler.initialize(() -> new HashSet<>(Collections.singletonList(dummyAutoScaleRule)), new Observer<AutoScaleAction>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onNext(AutoScaleAction autoScaleAction) {
        }
    });
}
Also used : AutoScaleRule(com.netflix.fenzo.AutoScaleRule) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) AutoScaleAction(com.netflix.fenzo.AutoScaleAction)

Aggregations

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