@Test public void createIndexReturnsFalse_whenCreationFails() throws Exception { mockServerClient.when(request().withPath("/" + INDEX_NAME).withMethod(HttpPut.METHOD_NAME)) .respond(response().withBody("{\"acknowledged\":false,\"shards_acknowledged\":false,\"index\":\"rre\"}", MediaType.JSON_UTF_8)); assertThat(connector.createIndex(INDEX_NAME)).isFalse(); mockServerClient.verify( request() .withMethod(HttpPut.METHOD_NAME) .withPath("/" + INDEX_NAME)); }
@Override public boolean createIndex(String index) throws IOException { final boolean ret; final String configJson = ConnectorUtils.readConfig( ConnectorUtils.getStreamForMappingsFile(MAPPINGS_FILE) .orElseThrow(() -> new IOException("Configuration file " + MAPPINGS_FILE + " not available!"))); CreateIndexRequest request = new CreateIndexRequest(index) .source(configJson, XContentType.JSON); try { ret = client.indices().create(request, RequestOptions.DEFAULT).isAcknowledged(); } catch (ElasticsearchException e) { LOGGER.error("Caught ElasticsearchException creating index {} :: {}", index, e.getDetailedMessage()); throw new IOException(e); } return ret; }
IndexOnlyElasticsearchConnector implements ElasticsearchConnector { @Override public boolean createIndex(String index) throws IOException { final boolean ret; final String configJson = ConnectorUtils.readConfig( ConnectorUtils.getStreamForMappingsFile(MAPPINGS_FILE) .orElseThrow(() -> new IOException("Configuration file " + MAPPINGS_FILE + " not available!"))); CreateIndexRequest request = new CreateIndexRequest(index) .source(configJson, XContentType.JSON); try { ret = client.indices().create(request, RequestOptions.DEFAULT).isAcknowledged(); } catch (ElasticsearchException e) { LOGGER.error("Caught ElasticsearchException creating index {} :: {}", index, e.getDetailedMessage()); throw new IOException(e); } return ret; } }
IndexOnlyElasticsearchConnector implements ElasticsearchConnector { @Override public boolean createIndex(String index) throws IOException { final boolean ret; final String configJson = ConnectorUtils.readConfig( ConnectorUtils.getStreamForMappingsFile(MAPPINGS_FILE) .orElseThrow(() -> new IOException("Configuration file " + MAPPINGS_FILE + " not available!"))); CreateIndexRequest request = new CreateIndexRequest(index) .source(configJson, XContentType.JSON); try { ret = client.indices().create(request, RequestOptions.DEFAULT).isAcknowledged(); } catch (ElasticsearchException e) { LOGGER.error("Caught ElasticsearchException creating index {} :: {}", index, e.getDetailedMessage()); throw new IOException(e); } return ret; } IndexOnlyElasticsearchConnector(RestHighLevelClient client); }
IndexOnlyElasticsearchConnector implements ElasticsearchConnector { @Override public boolean createIndex(String index) throws IOException { final boolean ret; final String configJson = ConnectorUtils.readConfig( ConnectorUtils.getStreamForMappingsFile(MAPPINGS_FILE) .orElseThrow(() -> new IOException("Configuration file " + MAPPINGS_FILE + " not available!"))); CreateIndexRequest request = new CreateIndexRequest(index) .source(configJson, XContentType.JSON); try { ret = client.indices().create(request, RequestOptions.DEFAULT).isAcknowledged(); } catch (ElasticsearchException e) { LOGGER.error("Caught ElasticsearchException creating index {} :: {}", index, e.getDetailedMessage()); throw new IOException(e); } return ret; } IndexOnlyElasticsearchConnector(RestHighLevelClient client); @Override boolean isAvailable(); @Override boolean indexExists(String index); @Override boolean createIndex(String index); @Override void storeItems(String index, Collection<QueryVersionReport> reports); @Override void close(); }
IndexOnlyElasticsearchConnector implements ElasticsearchConnector { @Override public boolean createIndex(String index) throws IOException { final boolean ret; final String configJson = ConnectorUtils.readConfig( ConnectorUtils.getStreamForMappingsFile(MAPPINGS_FILE) .orElseThrow(() -> new IOException("Configuration file " + MAPPINGS_FILE + " not available!"))); CreateIndexRequest request = new CreateIndexRequest(index) .source(configJson, XContentType.JSON); try { ret = client.indices().create(request, RequestOptions.DEFAULT).isAcknowledged(); } catch (ElasticsearchException e) { LOGGER.error("Caught ElasticsearchException creating index {} :: {}", index, e.getDetailedMessage()); throw new IOException(e); } return ret; } IndexOnlyElasticsearchConnector(RestHighLevelClient client); @Override boolean isAvailable(); @Override boolean indexExists(String index); @Override boolean createIndex(String index); @Override void storeItems(String index, Collection<QueryVersionReport> reports); @Override void close();  }