Search in sources :

Example 6 with TypeReference

use of io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference 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 7 with TypeReference

use of io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference in project mantis by Netflix.

the class SimpleCachedFileStorageProvider method modifyCompletedJobsForNamedJob.

private void modifyCompletedJobsForNamedJob(String name, Action1<List<NamedJob.CompletedJob>> modifier) throws IOException {
    File completedJobsFile = new File(NAMED_JOBS_DIR + File.separator + name + NAMED_JOBS_COMPLETED_JOBS_FILE_NAME_SUFFIX);
    List<NamedJob.CompletedJob> completedJobs = new LinkedList<>();
    if (completedJobsFile.exists()) {
        try (FileInputStream fis = new FileInputStream(completedJobsFile)) {
            completedJobs.addAll(mapper.readValue(fis, new TypeReference<List<NamedJob.CompletedJob>>() {
            }));
        }
    }
    modifier.call(completedJobs);
    completedJobsFile.delete();
    completedJobsFile.createNewFile();
    try (PrintWriter w = new PrintWriter(completedJobsFile)) {
        mapper.writeValue(w, completedJobs);
    }
}
Also used : TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) File(java.io.File) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) PrintWriter(java.io.PrintWriter)

Example 8 with TypeReference

use of io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference in project mantis by Netflix.

the class AgentClustersRoute method postAgentClustersRoute.

private Route postAgentClustersRoute() {
    logger.info("POST /api/v1/agentClusters called");
    return entity(Jackson.unmarshaller(new TypeReference<List<String>>() {
    }), activeClustersList -> {
        logger.info("POST {} called {}", API_V1_AGENT_CLUSTER, activeClustersList);
        try {
            agentClusterOps.setActiveVMsAttributeValues(activeClustersList);
        } catch (IOException e) {
            HttpRequestMetrics.getInstance().incrementEndpointMetrics(HttpRequestMetrics.Endpoints.AGENT_CLUSTERS, new BasicTag("verb", HttpRequestMetrics.HttpVerb.GET.toString()), new BasicTag("responseCode", String.valueOf(StatusCodes.INTERNAL_SERVER_ERROR.intValue())));
            return complete(StatusCodes.INTERNAL_SERVER_ERROR, "Failed to set active clusters to " + activeClustersList.toString());
        }
        HttpRequestMetrics.getInstance().incrementEndpointMetrics(HttpRequestMetrics.Endpoints.AGENT_CLUSTERS, new BasicTag("verb", HttpRequestMetrics.HttpVerb.GET.toString()), new BasicTag("responseCode", String.valueOf(StatusCodes.OK.intValue())));
        return complete(StatusCodes.OK, "");
    });
}
Also used : BasicTag(com.netflix.spectator.api.BasicTag) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException)

Example 9 with TypeReference

use of io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference in project mantis by Netflix.

the class AdminMasterRouteTest method testMasterConfigAPI.

@Test
public void testMasterConfigAPI() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final CompletionStage<HttpResponse> responseFuture = http.singleRequest(HttpRequest.GET(masterEndpoint("masterConfigs")));
    responseFuture.thenCompose(r -> processRespFut(r, 200)).whenComplete((msg, t) -> {
        try {
            String responseMessage = getResponseMessage(msg, t);
            logger.info("got response {}", responseMessage);
            List<AdminMasterRoute.Configlet> masterconfig = Jackson.fromJSON(responseMessage, new TypeReference<List<AdminMasterRoute.Configlet>>() {
            });
            logger.info("master config ---> {}", masterconfig);
            assertEquals(masterDescRoute.getConfigs(), masterconfig);
        } catch (Exception e) {
            fail("unexpected error " + e.getMessage());
        }
        latch.countDown();
    });
    assertTrue(latch.await(2, TimeUnit.SECONDS));
}
Also used : TestHelpers(com.netflix.mantis.master.scheduler.TestHelpers) MasterDescription(io.mantisrx.server.core.master.MasterDescription) Flow(akka.stream.javadsl.Flow) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) LoggerFactory(org.slf4j.LoggerFactory) Test(org.testng.annotations.Test) Function(java.util.function.Function) ActorMaterializer(akka.stream.ActorMaterializer) JobTestHelper(io.mantisrx.master.jobcluster.job.JobTestHelper) Assert.fail(org.junit.Assert.fail) ServerBinding(akka.http.javadsl.ServerBinding) AfterClass(org.testng.annotations.AfterClass) Logger(org.slf4j.Logger) Http(akka.http.javadsl.Http) Jackson(io.mantisrx.master.api.akka.route.Jackson) HttpRequest(akka.http.javadsl.model.HttpRequest) BeforeClass(org.testng.annotations.BeforeClass) Assert.assertTrue(org.junit.Assert.assertTrue) HttpResponse(akka.http.javadsl.model.HttpResponse) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ConnectHttp(akka.http.javadsl.ConnectHttp) CompletionStage(java.util.concurrent.CompletionStage) NotUsed(akka.NotUsed) Assert.assertEquals(org.junit.Assert.assertEquals) HttpResponse(akka.http.javadsl.model.HttpResponse) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 10 with TypeReference

use of io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference in project mantis by Netflix.

the class AdaptiveAutoScalerTest method shouldPauseScalingWhenWaitingOnWorkersAndResumeAfter.

@Test
public void shouldPauseScalingWhenWaitingOnWorkersAndResumeAfter() throws IOException {
    // Arrange
    Observable<Double> totalRPS = Observable.just(10.0, 20.0, 30.0, 40.0, 50.0, 60.0);
    AdaptiveAutoscalerConfig config = objectMapper.readValue(cfg, new TypeReference<AdaptiveAutoscalerConfig>() {
    });
    JobAutoScaler.StageScaler scaler = mock(JobAutoScaler.StageScaler.class);
    AdaptiveAutoscaler autoScaler = new AdaptiveAutoscaler(config, scaler, 2);
    TestSubscriber<Long> testSubscriber = new TestSubscriber<>();
    // Act
    // This elaborate scheme skips the scaling action at the 40.0 RPS point
    // as we have not received the instances requested at the 30.0 RPS point
    AtomicLong numWorkers = new AtomicLong(2);
    AtomicLong count = new AtomicLong(0);
    totalRPS.doOnNext(x -> {
        if (count.incrementAndGet() == 5) {
            numWorkers.set(3);
        }
    }).map(rps -> new JobAutoScaler.Event(StageScalingPolicy.ScalingReason.CPU, 1, rps / (1.0 * numWorkers.get()), ((Long) numWorkers.get()).intValue(), "message")).compose(autoScaler).map(x -> (Long) x).doOnNext(n -> {
        if (count.get() > 4) {
            numWorkers.set(n);
        }
    }).subscribe(testSubscriber);
    // Assert
    testSubscriber.assertCompleted();
    testSubscriber.assertNoErrors();
    testSubscriber.assertValues(2L, 2L, 3L, 5L, 5L);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) TestSubscriber(rx.observers.TestSubscriber) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) TypeReference(io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference) StageScalingPolicy(io.mantisrx.runtime.descriptor.StageScalingPolicy) JobAutoScaler(io.mantisrx.server.worker.jobmaster.JobAutoScaler) IOException(java.io.IOException) Test(org.junit.Test) Mockito.mock(org.mockito.Mockito.mock) Observable(rx.Observable) JobAutoScaler(io.mantisrx.server.worker.jobmaster.JobAutoScaler) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Aggregations

TypeReference (io.mantisrx.shaded.com.fasterxml.jackson.core.type.TypeReference)15 NotUsed (akka.NotUsed)11 ConnectHttp (akka.http.javadsl.ConnectHttp)11 Http (akka.http.javadsl.Http)11 ServerBinding (akka.http.javadsl.ServerBinding)11 HttpRequest (akka.http.javadsl.model.HttpRequest)11 HttpResponse (akka.http.javadsl.model.HttpResponse)11 ActorMaterializer (akka.stream.ActorMaterializer)11 Flow (akka.stream.javadsl.Flow)11 CompletionStage (java.util.concurrent.CompletionStage)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 TimeUnit (java.util.concurrent.TimeUnit)11 Assert.assertEquals (org.junit.Assert.assertEquals)11 Assert.assertTrue (org.junit.Assert.assertTrue)11 Assert.fail (org.junit.Assert.fail)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 AfterClass (org.testng.annotations.AfterClass)11 BeforeClass (org.testng.annotations.BeforeClass)11 Test (org.testng.annotations.Test)11