Search in sources :

Example 6 with ObjectMapper

use of io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper in project mantis by Netflix.

the class JobsRouteTest method validateJobsListResponse.

private void validateJobsListResponse(String resp, int expectedJobsCount, boolean isCompact) {
    try {
        assert !Strings.isNullOrEmpty(resp);
        ObjectMapper mapper = new ObjectMapper();
        JsonNode responseObj = mapper.readTree(resp).get("list");
        assert responseObj.size() == expectedJobsCount;
        for (int i = 0; i < expectedJobsCount; i++) {
            validateJobsListItem(responseObj.get(i), isCompact);
        }
    } catch (IOException ex) {
        logger.error("Failed to validate job response: " + ex.getMessage());
        assert false;
    }
}
Also used : JsonNode(io.mantisrx.shaded.com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with ObjectMapper

use of io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper in project mantis by Netflix.

the class JobsRouteTest method validateJobDetails.

private void validateJobDetails(String resp) {
    try {
        assert !Strings.isNullOrEmpty(resp);
        ObjectMapper mapper = new ObjectMapper();
        JsonNode responseObj = mapper.readTree(resp);
        validateJobsListItem(responseObj, false);
    } catch (IOException ex) {
        logger.error("Failed to validate job details response: " + ex.getMessage());
        assert false;
    }
}
Also used : JsonNode(io.mantisrx.shaded.com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with ObjectMapper

use of io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper in project mantis by Netflix.

the class AppJobClustersMapTest method testDeSerFromString.

@Test
public void testDeSerFromString() throws IOException {
    final ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    final String mapping = "{\"version\":\"1\",\"timestamp\":2,\"mappings\":{\"testApp\":{\"__default__\":\"SharedMrePublishEventSource\"}}}";
    AppJobClustersMap appJobClustersMap = mapper.readValue(mapping, AppJobClustersMap.class);
    assertEquals(2, appJobClustersMap.getTimestamp());
    assertEquals("testApp", appJobClustersMap.getStreamJobClusterMap("testApp").getAppName());
    assertEquals("SharedMrePublishEventSource", appJobClustersMap.getStreamJobClusterMap("testApp").getJobCluster("testStream"));
}
Also used : ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 9 with ObjectMapper

use of io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper in project mantis by Netflix.

the class AppJobClustersMapTest method testSerDe.

@Test
public void testSerDe() throws IOException {
    Map<String, Object> mappings = new HashMap<>();
    Map<String, Object> defaultAppMappings = new HashMap<>();
    defaultAppMappings.put(StreamJobClusterMap.DEFAULT_STREAM_KEY, "SharedPushEventSource");
    defaultAppMappings.put("testEventStream", "TestPushEventSource");
    mappings.put(AppJobClustersMap.DEFAULT_APP_KEY, defaultAppMappings);
    Map<String, Object> customAppMappings = new HashMap<>();
    customAppMappings.put("customEventStream", "CustomPushEventSource");
    customAppMappings.put(StreamJobClusterMap.DEFAULT_STREAM_KEY, "CustomDefaultPushEventSource");
    mappings.put("custom", customAppMappings);
    AppJobClustersMap mapV1 = new AppJobClustersMap(AppJobClustersMap.VERSION_1, System.currentTimeMillis(), mappings);
    assertEquals("SharedPushEventSource", mapV1.getStreamJobClusterMap(AppJobClustersMap.DEFAULT_APP_KEY).getJobCluster(StreamJobClusterMap.DEFAULT_STREAM_KEY));
    assertEquals("SharedPushEventSource", mapV1.getStreamJobClusterMap(AppJobClustersMap.DEFAULT_APP_KEY).getJobCluster("AnyRandomStream"));
    assertEquals("TestPushEventSource", mapV1.getStreamJobClusterMap(AppJobClustersMap.DEFAULT_APP_KEY).getJobCluster("testEventStream"));
    StreamJobClusterMap customStreamJCMap = mapV1.getStreamJobClusterMap("custom");
    System.out.println("custom app mapping: " + customStreamJCMap);
    assertTrue(customStreamJCMap.getStreamJobClusterMap().size() == 2);
    assertTrue(customStreamJCMap.getStreamJobClusterMap().containsKey(StreamJobClusterMap.DEFAULT_STREAM_KEY));
    assertFalse(customStreamJCMap.getStreamJobClusterMap().containsKey("testEventStream"));
    assertTrue(customStreamJCMap.getStreamJobClusterMap().containsKey("customEventStream"));
    assertEquals("CustomDefaultPushEventSource", customStreamJCMap.getJobCluster(StreamJobClusterMap.DEFAULT_STREAM_KEY));
    assertEquals("CustomDefaultPushEventSource", customStreamJCMap.getJobCluster("AnyRandomStreamName"));
    assertEquals("CustomDefaultPushEventSource", customStreamJCMap.getJobCluster("testEventStream"));
    assertEquals("CustomPushEventSource", customStreamJCMap.getJobCluster("customEventStream"));
    ObjectMapper mapper = new ObjectMapper();
    String mappingStr = mapper.writeValueAsString(mapV1);
    System.out.println("input mappings " + mappingStr);
    AppJobClustersMap appJobClustersMap = mapper.readValue(mappingStr, AppJobClustersMap.class);
    System.out.println("parsed mappings " + appJobClustersMap);
    assertEquals(mapV1, appJobClustersMap);
}
Also used : HashMap(java.util.HashMap) ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with ObjectMapper

use of io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper in project mantis by Netflix.

the class AdaptiveAutoscalerConfig method main.

public static void main(String[] args) throws IOException {
    ObjectMapper objectMapper = new ObjectMapper();
    String cfg = "{\"metric\": \"KafkaProcessed\", \"setPoint\": 1, \"invert\": true, \"rope\": 0, \"kp\": 0.1, \"ki\": 0.00, \"kd\": 0.00, \"minScale\": 1, \"maxScale\": 5}\n";
    AdaptiveAutoscalerConfig config = objectMapper.readValue(cfg, new TypeReference<AdaptiveAutoscalerConfig>() {
    });
    System.out.println(config.toString());
}
Also used : ObjectMapper(io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (io.mantisrx.shaded.com.fasterxml.jackson.databind.ObjectMapper)17 IOException (java.io.IOException)10 Test (org.junit.Test)7 JsonNode (io.mantisrx.shaded.com.fasterxml.jackson.databind.JsonNode)5 JsonProcessingException (io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException)3 MachineDefinition (io.mantisrx.runtime.MachineDefinition)2 MantisWorkerMetadataWritable (io.mantisrx.server.master.store.MantisWorkerMetadataWritable)2 HashMap (java.util.HashMap)2 ActorRef (akka.actor.ActorRef)1 ActorSystem (akka.actor.ActorSystem)1 TestKit (akka.testkit.javadsl.TestKit)1 TestHelpers (com.netflix.mantis.master.scheduler.TestHelpers)1 Label (io.mantisrx.common.Label)1 WorkerPorts (io.mantisrx.common.WorkerPorts)1 OffsetAndMetadataDeserializer (io.mantisrx.connector.kafka.source.serde.OffsetAndMetadataDeserializer)1 OffsetAndMetadataSerializer (io.mantisrx.connector.kafka.source.serde.OffsetAndMetadataSerializer)1 AuditEventSubscriberLoggingImpl (io.mantisrx.master.events.AuditEventSubscriberLoggingImpl)1 LifecycleEventPublisher (io.mantisrx.master.events.LifecycleEventPublisher)1 LifecycleEventPublisherImpl (io.mantisrx.master.events.LifecycleEventPublisherImpl)1 StatusEventSubscriberLoggingImpl (io.mantisrx.master.events.StatusEventSubscriberLoggingImpl)1