@Override public void execute(IndexTemplate indexTemplate) { try { createClient().admin().indices().putTemplate( new PutIndexTemplateRequest() .name(indexTemplate.getName()) .source(indexTemplate.getSource(), XContentType.JSON) ); } catch (Exception e) { throw new ConfigurationException(e.getMessage(), e); } }
@Override public IndexTemplate build() { if (name == null) { throw new ConfigurationException("No name provided for IndexTemplate"); } if ((path == null && source == null) || (path != null && source != null)) { throw new ConfigurationException("Either path or source have to be provided for IndexTemplate"); } return new IndexTemplate(name, loadSource()); }
public static IndexTemplate.Builder createTestIndexTemplateBuilder() { IndexTemplate.Builder builder = IndexTemplate.newBuilder(); builder.withName(TEST_INDEX_TEMPLATE) .withPath(TEST_PATH); return builder; }
@Override public void execute(IndexTemplate indexTemplate) { try { createClient().admin().indices().putTemplate( new PutIndexTemplateRequest() .name(indexTemplate.getName()) .source(indexTemplate.getSource(), XContentType.JSON) ); } catch (Exception e) { throw new ConfigurationException(e.getMessage(), e); } }
@Override public IndexTemplate build() { if (name == null) { throw new ConfigurationException("No name provided for IndexTemplate"); } if ((path == null && source == null) || (path != null && source != null)) { throw new ConfigurationException("Either path or source have to be provided for IndexTemplate"); } return new IndexTemplate(name, loadSource()); }
public static Builder createTestBatchDeliveryBuilder() { return spy(AsyncBatchDelivery.newBuilder() .withBatchSize(TEST_BATCH_SIZE) .withDeliveryInterval(TEST_DELIVERY_INTERVAL) .withClientObjectFactory(createTestObjectFactoryBuilder().build())) .withFailoverPolicy(new NoopFailoverPolicy()) .withIndexTemplate(new IndexTemplate(TEST_INDEX_TEMPLATE, TEST_PATH)); }
@Override public void execute(IndexTemplate indexTemplate) { TemplateAction templateAction = new PutTemplate.Builder(indexTemplate.getName(), indexTemplate.getSource()).build(); try { JestResult result = createClient().execute(templateAction); if (!result.isSucceeded()) { throw new ConfigurationException("IndexTemplate not added: " + result.getErrorMessage()); } } catch (IOException e) { throw new ConfigurationException("IndexTemplate not added: " + e.getMessage()); } }
@Test public void startsWhenSetupCorrectlyWithNameAndPath() { // given IndexTemplate.Builder builder = createTestIndexTemplateBuilder(); builder.withName(TEST_INDEX_TEMPLATE) .withPath(TEST_PATH); // when IndexTemplate indexTemplate = builder.build(); // then Assert.assertNotNull(indexTemplate); Assert.assertNotNull(indexTemplate.getName()); Assert.assertNotNull(indexTemplate.getSource()); }
@Test public void startsWhenSetupCorrectlyWithNameAndSource() { // given IndexTemplate.Builder builder = createTestIndexTemplateBuilder(); builder.withName(TEST_INDEX_TEMPLATE) .withPath(null) .withSource(TEST_SOURCE); // when IndexTemplate indexTemplate = builder.build(); // then Assert.assertNotNull(indexTemplate); Assert.assertNotNull(indexTemplate.getName()); Assert.assertNotNull(indexTemplate.getSource()); }