From cd17016f58689694ca15cd8fadd7b24d20c7db51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Garc=C3=ADa?= Date: Wed, 6 Dec 2023 11:08:17 +0100 Subject: [PATCH] Elasticsearch index creation - log the exception when a parsing error of the index configuration file occurs --- .../geonet/kernel/search/EsSearchManager.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/fao/geonet/kernel/search/EsSearchManager.java b/core/src/main/java/org/fao/geonet/kernel/search/EsSearchManager.java index 43017e4112f..d009c08291b 100644 --- a/core/src/main/java/org/fao/geonet/kernel/search/EsSearchManager.java +++ b/core/src/main/java/org/fao/geonet/kernel/search/EsSearchManager.java @@ -35,6 +35,7 @@ import jeeves.server.context.ServiceContext; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; +import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.bulk.BulkRequest; @@ -271,11 +272,11 @@ private void createIndex(String indexId, String indexName, boolean dropIndexFirs DeleteIndexRequest request = new DeleteIndexRequest(indexName); AcknowledgedResponse deleteIndexResponse = client.getClient().indices().delete(request, RequestOptions.DEFAULT); if (deleteIndexResponse.isAcknowledged()) { - LOGGER.debug("Index '{}' removed.", new Object[]{indexName}); + LOGGER.debug("Index '{}' removed.", indexName); } } catch (Exception e) { // index does not exist ? - LOGGER.debug("Error during index '{}' removal. Error is: {}", new Object[]{indexName, e.getMessage()}); + LOGGER.debug("Error during index '{}' removal. Error is: {}", indexName, e.getMessage()); } } @@ -304,7 +305,7 @@ private void createIndex(String indexId, String indexName, boolean dropIndexFirs CreateIndexResponse createIndexResponse = client.getClient().indices().create(createIndexRequest, RequestOptions.DEFAULT); if (createIndexResponse.isAcknowledged()) { - LOGGER.debug("Index '{}' created", new Object[]{indexName}); + LOGGER.debug("Index '{}' created", indexName); } else { final String message = String.format("Index '%s' was not created. Error is: %s", indexName, createIndexResponse.toString()); LOGGER.error(message); @@ -317,10 +318,13 @@ private void createIndex(String indexId, String indexName, boolean dropIndexFirs indexName)); } } + } catch (ElasticsearchParseException ex) { + LOGGER.error(ex.getMessage(), ex); + throw new IOException(ex.getMessage()); } catch (Exception cnce) { final String message = String.format("Could not connect to index '%s'. Error is %s. Is the index server up and running?", defaultIndex, cnce.getMessage()); - LOGGER.error(message); + LOGGER.error(message, cnce); throw new IOException(message); } } @@ -444,7 +448,7 @@ private void sendDocumentsToIndex() { } catch (Exception e) { LOGGER.error( "An error occurred while indexing {} documents in current indexing list. Error is {}.", - new Object[]{listOfDocumentsToIndex.size(), e.getMessage()}); + listOfDocumentsToIndex.size(), e.getMessage()); } finally { // TODO: Trigger this async ? documents.keySet().forEach(uuid -> overviewFieldUpdater.process(uuid)); @@ -489,14 +493,14 @@ private void checkIndexResponse(BulkResponse bulkItemResponses, // TODO: Report the JSON which was causing the error ? LOGGER.error("Document with error #{}: {}.", - new Object[]{e.getId(), e.getFailureMessage()}); + e.getId(), e.getFailureMessage()); LOGGER.error(failureDoc); try { listErrorOfDocumentsToIndex.put(e.getId(), mapper.writeValueAsString(docWithErrorInfo)); } catch (JsonProcessingException e1) { LOGGER.error("Generated document for the index is not properly formatted. Check document #{}: {}.", - new Object[]{e.getId(), e1.getMessage()}); + e.getId(), e1.getMessage()); } } }); @@ -505,7 +509,7 @@ private void checkIndexResponse(BulkResponse bulkItemResponses, BulkResponse response = client.bulkRequest(defaultIndex, listErrorOfDocumentsToIndex); if (response.status().getStatus() != 201) { LOGGER.error("Failed to save error documents {}.", - new Object[]{Arrays.toString(errorDocumentIds.toArray())}); + Arrays.toString(errorDocumentIds.toArray())); } } } @@ -638,7 +642,7 @@ public ObjectNode documentToJson(Element xml) { mapper.readTree(node.getText())); } catch (IOException e) { LOGGER.error("Parsing invalid JSON node {} for property {}. Error is: {}", - new Object[]{node.getTextNormalize(), propertyName, e.getMessage()}); + node.getTextNormalize(), propertyName, e.getMessage()); } } else { arrayNode.add( @@ -657,7 +661,7 @@ public ObjectNode documentToJson(Element xml) { doc.set("geom", mapper.readTree(nodeElements.get(0).getTextNormalize())); } catch (IOException e) { LOGGER.error("Parsing invalid geometry for JSON node {}. Error is: {}", - new Object[]{nodeElements.get(0).getTextNormalize(), e.getMessage()}); + nodeElements.get(0).getTextNormalize(), e.getMessage()); } continue; } @@ -670,7 +674,7 @@ public ObjectNode documentToJson(Element xml) { )); } catch (IOException e) { LOGGER.error("Parsing invalid JSON node {} for property {}. Error is: {}", - new Object[]{nodeElements.get(0).getTextNormalize(), propertyName, e.getMessage()}); + nodeElements.get(0).getTextNormalize(), propertyName, e.getMessage()); } } else { doc.put(propertyName,