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));
}
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);
}
}
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, "");
});
}
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));
}
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);
}
Aggregations