Search in sources :

Example 6 with JsonMapperProvider

use of com.netflix.conductor.common.utils.JsonMapperProvider in project conductor by Netflix.

the class TestElasticSearchDAOV5 method startServer.

@BeforeClass
public static void startServer() throws Exception {
    System.setProperty(ElasticSearchConfiguration.EMBEDDED_PORT_PROPERTY_NAME, "9203");
    System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME, "localhost:9303");
    System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_INDEX_BATCH_SIZE_PROPERTY_NAME, "1");
    configuration = new SystemPropertiesElasticSearchConfiguration();
    String host = configuration.getEmbeddedHost();
    int port = configuration.getEmbeddedPort();
    String clusterName = configuration.getEmbeddedClusterName();
    embeddedElasticSearch = new EmbeddedElasticSearchV5(clusterName, host, port);
    embeddedElasticSearch.start();
    ElasticSearchTransportClientProvider transportClientProvider = new ElasticSearchTransportClientProvider(configuration);
    elasticSearchClient = transportClientProvider.get();
    elasticSearchClient.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().get();
    ObjectMapper objectMapper = new JsonMapperProvider().get();
    indexDAO = new ElasticSearchDAOV5(elasticSearchClient, configuration, objectMapper);
}
Also used : ElasticSearchTransportClientProvider(com.netflix.conductor.elasticsearch.ElasticSearchTransportClientProvider) EmbeddedElasticSearchV5(com.netflix.conductor.elasticsearch.es5.EmbeddedElasticSearchV5) SystemPropertiesElasticSearchConfiguration(com.netflix.conductor.elasticsearch.SystemPropertiesElasticSearchConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) BeforeClass(org.junit.BeforeClass)

Example 7 with JsonMapperProvider

use of com.netflix.conductor.common.utils.JsonMapperProvider in project conductor by Netflix.

the class ElasticSearchBaseDAO method applyIndexPrefixToTemplate.

private String applyIndexPrefixToTemplate(String text) throws JsonProcessingException {
    ObjectMapper mapper = new JsonMapperProvider().get();
    String indexPatternsFieldName = "index_patterns";
    JsonNode root = mapper.readTree(text);
    if (root != null) {
        JsonNode indexPatternsNodeValue = root.get(indexPatternsFieldName);
        if (indexPatternsNodeValue != null && indexPatternsNodeValue.isArray()) {
            ArrayList<String> patternsWithPrefix = new ArrayList<>();
            indexPatternsNodeValue.forEach(v -> {
                String patternText = v.asText();
                StringBuffer sb = new StringBuffer();
                if (patternText.startsWith("*")) {
                    sb.append("*").append(indexPrefix).append("_").append(patternText.substring(1));
                } else {
                    sb.append(indexPrefix).append("_").append(patternText);
                }
                patternsWithPrefix.add(sb.toString());
            });
            ((ObjectNode) root).set(indexPatternsFieldName, mapper.valueToTree(patternsWithPrefix));
            System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root));
            return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
        }
    }
    return text;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider)

Example 8 with JsonMapperProvider

use of com.netflix.conductor.common.utils.JsonMapperProvider in project conductor by Netflix.

the class TestElasticSearchRestDAOV6 method startElasticSearchWithBatchSize.

private void startElasticSearchWithBatchSize(int i) throws Exception {
    System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_INDEX_BATCH_SIZE_PROPERTY_NAME, String.valueOf(i));
    configuration = new SystemPropertiesElasticSearchConfiguration();
    String host = configuration.getEmbeddedHost();
    int port = configuration.getEmbeddedPort();
    String clusterName = configuration.getEmbeddedClusterName();
    embeddedElasticSearch = new EmbeddedElasticSearchV6(clusterName, host, port);
    embeddedElasticSearch.start();
    ElasticSearchRestClientBuilderProvider restClientProvider = new ElasticSearchRestClientBuilderProvider(configuration);
    RestClientBuilder restClientBuilder = restClientProvider.get();
    restClient = restClientBuilder.build();
    Map<String, String> params = new HashMap<>();
    params.put("wait_for_status", "yellow");
    params.put("timeout", "30s");
    restClient.performRequest("GET", "/_cluster/health", params);
    objectMapper = new JsonMapperProvider().get();
    indexDAO = new ElasticSearchRestDAOV6(restClientBuilder, configuration, objectMapper);
}
Also used : EmbeddedElasticSearchV6(com.netflix.conductor.elasticsearch.es6.EmbeddedElasticSearchV6) ElasticSearchRestClientBuilderProvider(com.netflix.conductor.elasticsearch.ElasticSearchRestClientBuilderProvider) HashMap(java.util.HashMap) SystemPropertiesElasticSearchConfiguration(com.netflix.conductor.elasticsearch.SystemPropertiesElasticSearchConfiguration) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider)

Example 9 with JsonMapperProvider

use of com.netflix.conductor.common.utils.JsonMapperProvider in project conductor by Netflix.

the class ExecutionDAOFacadeTest method setUp.

@Before
public void setUp() {
    executionDAO = mock(ExecutionDAO.class);
    queueDAO = mock(QueueDAO.class);
    indexDAO = mock(IndexDAO.class);
    rateLimitingDao = mock(RateLimitingDAO.class);
    pollDataDAO = mock(PollDataDAO.class);
    objectMapper = new JsonMapperProvider().get();
    Configuration configuration = new TestConfiguration();
    executionDAOFacade = new ExecutionDAOFacade(executionDAO, queueDAO, indexDAO, rateLimitingDao, pollDataDAO, objectMapper, configuration);
}
Also used : QueueDAO(com.netflix.conductor.dao.QueueDAO) PollDataDAO(com.netflix.conductor.dao.PollDataDAO) ExecutionDAO(com.netflix.conductor.dao.ExecutionDAO) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) Configuration(com.netflix.conductor.core.config.Configuration) TestConfiguration(com.netflix.conductor.core.execution.TestConfiguration) RateLimitingDAO(com.netflix.conductor.dao.RateLimitingDAO) IndexDAO(com.netflix.conductor.dao.IndexDAO) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Before(org.junit.Before)

Example 10 with JsonMapperProvider

use of com.netflix.conductor.common.utils.JsonMapperProvider in project conductor by Netflix.

the class JsonMapperProviderTest method testWorkflowSerDe.

@Test
public void testWorkflowSerDe() throws IOException {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("testDef");
    workflowDef.setVersion(2);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setWorkflowId("test-workflow-id");
    workflow.setStatus(Workflow.WorkflowStatus.RUNNING);
    workflow.setStartTime(10L);
    workflow.setInput(null);
    Map<String, Object> data = new HashMap<>();
    data.put("someKey", null);
    data.put("someId", "abc123");
    workflow.setOutput(data);
    ObjectMapper objectMapper = new JsonMapperProvider().get();
    String workflowPayload = objectMapper.writeValueAsString(workflow);
    Workflow workflow1 = objectMapper.readValue(workflowPayload, Workflow.class);
    assertTrue(workflow1.getOutput().containsKey("someKey"));
    assertNull(workflow1.getOutput().get("someKey"));
    assertNotNull(workflow1.getInput());
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Test(org.junit.Test)

Aggregations

JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)25 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 SystemPropertiesElasticSearchConfiguration (com.netflix.conductor.elasticsearch.SystemPropertiesElasticSearchConfiguration)10 HashMap (java.util.HashMap)9 Test (org.junit.Test)6 ElasticSearchTransportClientProvider (com.netflix.conductor.elasticsearch.ElasticSearchTransportClientProvider)4 EmbeddedElasticSearchV5 (com.netflix.conductor.elasticsearch.es5.EmbeddedElasticSearchV5)4 Before (org.junit.Before)4 BeforeClass (org.junit.BeforeClass)4 Configuration (com.netflix.conductor.core.config.Configuration)3 TestConfiguration (com.netflix.conductor.core.execution.TestConfiguration)3 ElasticSearchRestClientBuilderProvider (com.netflix.conductor.elasticsearch.ElasticSearchRestClientBuilderProvider)3 EmbeddedElasticSearchV6 (com.netflix.conductor.elasticsearch.es6.EmbeddedElasticSearchV6)3 RestClientBuilder (org.elasticsearch.client.RestClientBuilder)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)2 QueueDAO (com.netflix.conductor.dao.QueueDAO)2 EmbeddedElasticSearchV7 (com.netflix.conductor.elasticsearch.es7.EmbeddedElasticSearchV7)2 Request (org.elasticsearch.client.Request)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1