use of com.netflix.fenzo.AutoScaleRule in project mantis by Netflix.
the class AgentClustersRouteTest method testGetAutoScalePolicy.
@Test(dependsOnMethods = { "testGetJobsOnAgentClusters" })
public void testGetAutoScalePolicy() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(SERVER_ENDPOINT + "/autoScalePolicy"));
responseFuture.thenCompose(r -> processRespFut(r, 200)).whenComplete((msg, t) -> {
String responseMessage = getResponseMessage(msg, t);
logger.info("got response {}", responseMessage);
try {
Map<String, AgentClusterOperations.AgentClusterAutoScaleRule> agentClusterAutoScaleRule = mapper.readValue(responseMessage, new TypeReference<Map<String, AgentClusterOperations.AgentClusterAutoScaleRule>>() {
});
agentClusterAutoScaleRule.values().forEach(autoScaleRule -> {
assertEquals("test", autoScaleRule.getName());
assertEquals(300, autoScaleRule.getCooldownSecs());
assertEquals(1, autoScaleRule.getMinIdle());
assertEquals(10, autoScaleRule.getMaxIdle());
assertEquals(1, autoScaleRule.getMinSize());
assertEquals(100, autoScaleRule.getMaxSize());
});
} catch (IOException e) {
logger.error("caught error", e);
fail("failed to deserialize response");
}
latch.countDown();
});
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of com.netflix.fenzo.AutoScaleRule in project mantis by Netflix.
the class AgentClusterRouteTest method testGetAgentClustersList.
@Test(dependsOnMethods = { "testGetJobsOnVMs" })
public void testGetAgentClustersList() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(agentClusterEndpoint(AgentClusterRoute.LISTAGENTCLUSTERS)));
responseFuture.thenCompose(r -> processRespFut(r, 200)).whenComplete((msg, t) -> {
String responseMessage = getResponseMessage(msg, t);
logger.info("got response {}", responseMessage);
try {
Map<String, AgentClusterOperations.AgentClusterAutoScaleRule> agentClusterAutoScaleRule = mapper.readValue(responseMessage, new TypeReference<Map<String, AgentClusterOperations.AgentClusterAutoScaleRule>>() {
});
agentClusterAutoScaleRule.values().forEach(autoScaleRule -> {
assertEquals("test", autoScaleRule.getName());
assertEquals(300, autoScaleRule.getCooldownSecs());
assertEquals(1, autoScaleRule.getMinIdle());
assertEquals(10, autoScaleRule.getMaxIdle());
assertEquals(1, autoScaleRule.getMinSize());
assertEquals(100, autoScaleRule.getMaxSize());
});
} catch (IOException e) {
logger.error("caught error", e);
fail("failed to deserialize response");
}
// assertEquals("{}", responseMessage);
latch.countDown();
});
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of com.netflix.fenzo.AutoScaleRule in project mantis by Netflix.
the class SchedulingService method setupAutoscaleRulesDynamicUpdater.
private void setupAutoscaleRulesDynamicUpdater() {
final Set<String> emptyHashSet = new HashSet<>();
Schedulers.computation().createWorker().schedulePeriodically(() -> {
try {
logger.debug("Updating cluster autoscale rules");
final AgentClustersAutoScaler agentClustersAutoScaler = AgentClustersAutoScaler.get();
if (agentClustersAutoScaler == null) {
logger.warn("No agent cluster autoscaler defined, not setting up Fenzo autoscaler rules");
return;
}
final Set<AutoScaleRule> newRules = agentClustersAutoScaler.getRules();
final Collection<AutoScaleRule> currRules = taskScheduler.getAutoScaleRules();
final Set<String> currRulesNames = currRules == null || currRules.isEmpty() ? emptyHashSet : currRules.stream().collect((Supplier<Set<String>>) HashSet::new, (strings, autoScaleRule) -> strings.add(autoScaleRule.getRuleName()), Set::addAll);
if (newRules != null && !newRules.isEmpty()) {
for (AutoScaleRule r : newRules) {
logger.debug("Setting up autoscale rule: " + r);
taskScheduler.addOrReplaceAutoScaleRule(r);
currRulesNames.remove(r.getRuleName());
}
}
if (!currRulesNames.isEmpty()) {
for (String ruleName : currRulesNames) {
logger.info("Removing autoscale rule " + ruleName);
taskScheduler.removeAutoScaleRule(ruleName);
}
}
} catch (Exception e) {
logger.warn("Unexpected error updating cluster autoscale rules: " + e.getMessage());
}
}, 1, 1, TimeUnit.MINUTES);
}
use of com.netflix.fenzo.AutoScaleRule 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;
}
use of com.netflix.fenzo.AutoScaleRule in project mantis by Netflix.
the class AgentClusterOperationsImpl method getAgentClusterAutoScaleRules.
@Override
public Map<String, AgentClusterAutoScaleRule> getAgentClusterAutoScaleRules() {
final Set<AutoScaleRule> agentAutoscaleRules = agentClustersAutoScaler.getRules();
final Map<String, AgentClusterAutoScaleRule> result = new HashMap<>();
if (agentAutoscaleRules != null && !agentAutoscaleRules.isEmpty()) {
for (AutoScaleRule r : agentAutoscaleRules) {
result.put(r.getRuleName(), new AgentClusterOperations.AgentClusterAutoScaleRule(r.getRuleName(), r.getCoolDownSecs(), r.getMinIdleHostsToKeep(), r.getMaxIdleHostsToKeep(), r.getMinSize(), r.getMaxSize()));
}
}
return result;
}
Aggregations