Search in sources :

Example 1 with AutoScaleRule

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));
}
Also used : TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) LoggerFactory(org.slf4j.LoggerFactory) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.testng.annotations.Test) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) JobClustersManagerActor(io.mantisrx.master.JobClustersManagerActor) AgentClustersAutoScaler(io.mantisrx.server.master.AgentClustersAutoScaler) ActorMaterializer(akka.stream.ActorMaterializer) ActorRef(akka.actor.ActorRef) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) SimpleCachedFileStorageProvider(io.mantisrx.server.master.persistence.SimpleCachedFileStorageProvider) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) ServerBinding(akka.http.javadsl.ServerBinding) JobMessageRouterImpl(io.mantisrx.master.scheduler.JobMessageRouterImpl) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) BeforeClass(org.testng.annotations.BeforeClass) Observer(rx.Observer) DeserializationFeature(io.mantisrx.shaded.com.fasterxml.jackson.databind.DeserializationFeature) CountDownLatch(java.util.concurrent.CountDownLatch) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) AgentClusterPayloads(io.mantisrx.master.api.akka.payloads.AgentClusterPayloads) IMantisStorageProvider(io.mantisrx.server.master.persistence.IMantisStorageProvider) Flow(akka.stream.javadsl.Flow) Function(java.util.function.Function) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) HashSet(java.util.HashSet) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) AutoScaleRule(com.netflix.fenzo.AutoScaleRule) AgentClusterOperationsImpl(io.mantisrx.master.vm.AgentClusterOperationsImpl) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ContentTypes(akka.http.javadsl.model.ContentTypes) HttpEntities(akka.http.javadsl.model.HttpEntities) HttpResponse(akka.http.javadsl.model.HttpResponse) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) ConnectHttp(akka.http.javadsl.ConnectHttp) AutoScaleAction(com.netflix.fenzo.AutoScaleAction) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) HttpResponse(akka.http.javadsl.model.HttpResponse) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) Test(org.testng.annotations.Test)

Example 2 with AutoScaleRule

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));
}
Also used : ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) LoggerFactory(org.slf4j.LoggerFactory) MantisJobStore(io.mantisrx.server.master.persistence.MantisJobStore) Test(org.testng.annotations.Test) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) JobClustersManagerActor(io.mantisrx.master.JobClustersManagerActor) AgentClustersAutoScaler(io.mantisrx.server.master.AgentClustersAutoScaler) ActorMaterializer(akka.stream.ActorMaterializer) ActorRef(akka.actor.ActorRef) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) SimpleCachedFileStorageProvider(io.mantisrx.server.master.persistence.SimpleCachedFileStorageProvider) StatusEventSubscriberLoggingImpl(io.mantisrx.master.events.StatusEventSubscriberLoggingImpl) ServerBinding(akka.http.javadsl.ServerBinding) JobMessageRouterImpl(io.mantisrx.master.scheduler.JobMessageRouterImpl) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) WorkerEventSubscriberLoggingImpl(io.mantisrx.master.events.WorkerEventSubscriberLoggingImpl) BeforeClass(org.testng.annotations.BeforeClass) Observer(rx.Observer) DeserializationFeature(io.mantisrx.shaded.com.fasterxml.jackson.databind.DeserializationFeature) CountDownLatch(java.util.concurrent.CountDownLatch) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) AgentClusterPayloads(io.mantisrx.master.api.akka.payloads.AgentClusterPayloads) ActorSystem(akka.actor.ActorSystem) IMantisStorageProvider(io.mantisrx.server.master.persistence.IMantisStorageProvider) Flow(akka.stream.javadsl.Flow) Function(java.util.function.Function) AuditEventSubscriberLoggingImpl(io.mantisrx.master.events.AuditEventSubscriberLoggingImpl) HashSet(java.util.HashSet) LifecycleEventPublisherImpl(io.mantisrx.master.events.LifecycleEventPublisherImpl) ByteString(akka.util.ByteString) HttpEntity(akka.http.javadsl.model.HttpEntity) AutoScaleRule(com.netflix.fenzo.AutoScaleRule) AgentClusterOperationsImpl(io.mantisrx.master.vm.AgentClusterOperationsImpl) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) Http(akka.http.javadsl.Http) HttpRequest(akka.http.javadsl.model.HttpRequest) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) HttpResponse(akka.http.javadsl.model.HttpResponse) FakeMantisScheduler(io.mantisrx.master.scheduler.FakeMantisScheduler) TimeUnit(java.util.concurrent.TimeUnit) JobClusterManagerProto(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto) ConnectHttp(akka.http.javadsl.ConnectHttp) AutoScaleAction(com.netflix.fenzo.AutoScaleAction) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) LifecycleEventPublisher(io.mantisrx.master.events.LifecycleEventPublisher) HttpResponse(akka.http.javadsl.model.HttpResponse) ByteString(akka.util.ByteString) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) AgentClusterOperations(io.mantisrx.master.vm.AgentClusterOperations) Test(org.testng.annotations.Test)

Example 3 with AutoScaleRule

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);
}
Also used : ScheduleRequest(io.mantisrx.server.master.scheduler.ScheduleRequest) WorkerLaunched(io.mantisrx.server.master.scheduler.WorkerLaunched) LoggerFactory(org.slf4j.LoggerFactory) GaugeCallback(io.mantisrx.common.metrics.spectator.GaugeCallback) SynchronizedHistogram(org.HdrHistogram.SynchronizedHistogram) MantisScheduler(io.mantisrx.server.master.scheduler.MantisScheduler) Action1(rx.functions.Action1) BaseService(io.mantisrx.server.core.BaseService) VirtualMachineCurrentState(com.netflix.fenzo.VirtualMachineCurrentState) WorkerRegistry(io.mantisrx.server.master.scheduler.WorkerRegistry) WorkerPorts(io.mantisrx.common.WorkerPorts) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) Metrics(io.mantisrx.common.metrics.Metrics) VirtualMachineLease(com.netflix.fenzo.VirtualMachineLease) Collection(java.util.Collection) Set(java.util.Set) Sets(io.mantisrx.shaded.com.google.common.collect.Sets) Observer(rx.Observer) Collectors(java.util.stream.Collectors) TaskQueue(com.netflix.fenzo.queues.TaskQueue) WorkerId(io.mantisrx.server.core.domain.WorkerId) List(java.util.List) SchedulingStateManager(io.mantisrx.server.master.scheduler.SchedulingStateManager) SchedulingResult(com.netflix.fenzo.SchedulingResult) Gauge(io.mantisrx.common.metrics.Gauge) ConfigurationProvider(io.mantisrx.server.master.config.ConfigurationProvider) WorkerLaunchFailed(io.mantisrx.server.master.scheduler.WorkerLaunchFailed) Optional(java.util.Optional) TaskScheduler(com.netflix.fenzo.TaskScheduler) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) TaskSchedulingService(com.netflix.fenzo.TaskSchedulingService) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Observable(rx.Observable) TaskRequest(com.netflix.fenzo.TaskRequest) HashSet(java.util.HashSet) LaunchTaskRequest(io.mantisrx.server.master.scheduler.LaunchTaskRequest) WorkerUnscheduleable(io.mantisrx.server.master.scheduler.WorkerUnscheduleable) TieredQueue(com.netflix.fenzo.queues.tiered.TieredQueue) DEFAULT_Q_ATTRIBUTES(io.mantisrx.server.master.scheduler.ScheduleRequest.DEFAULT_Q_ATTRIBUTES) TaskAssignmentResult(com.netflix.fenzo.TaskAssignmentResult) AutoScaleRule(com.netflix.fenzo.AutoScaleRule) Counter(io.mantisrx.common.metrics.Counter) Logger(org.slf4j.Logger) DateTime(org.joda.time.DateTime) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) TaskQueueException(com.netflix.fenzo.queues.TaskQueueException) AutoScaleAction(com.netflix.fenzo.AutoScaleAction) JobMessageRouter(io.mantisrx.server.master.scheduler.JobMessageRouter) SpectatorRegistryFactory(io.mantisrx.common.metrics.spectator.SpectatorRegistryFactory) MetricId(io.mantisrx.common.metrics.spectator.MetricId) VMAssignmentResult(com.netflix.fenzo.VMAssignmentResult) MetricGroupId(io.mantisrx.common.metrics.spectator.MetricGroupId) AutoScaleRule(com.netflix.fenzo.AutoScaleRule) Supplier(java.util.function.Supplier) TaskQueueException(com.netflix.fenzo.queues.TaskQueueException) HashSet(java.util.HashSet)

Example 4 with AutoScaleRule

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;
}
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 5 with AutoScaleRule

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;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AutoScaleRule(com.netflix.fenzo.AutoScaleRule)

Aggregations

AutoScaleRule (com.netflix.fenzo.AutoScaleRule)7 AutoScaleAction (com.netflix.fenzo.AutoScaleAction)6 VirtualMachineLease (com.netflix.fenzo.VirtualMachineLease)5 MantisScheduler (io.mantisrx.server.master.scheduler.MantisScheduler)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 TimeUnit (java.util.concurrent.TimeUnit)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Observer (rx.Observer)3 NotUsed (akka.NotUsed)2 ActorRef (akka.actor.ActorRef)2 ConnectHttp (akka.http.javadsl.ConnectHttp)2 Http (akka.http.javadsl.Http)2 ServerBinding (akka.http.javadsl.ServerBinding)2 HttpRequest (akka.http.javadsl.model.HttpRequest)2 HttpResponse (akka.http.javadsl.model.HttpResponse)2 ActorMaterializer (akka.stream.ActorMaterializer)2 Flow (akka.stream.javadsl.Flow)2 TaskScheduler (com.netflix.fenzo.TaskScheduler)2