aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/sa/searchdbabstraction
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openecomp/sa/searchdbabstraction')
-rw-r--r--src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java10
-rw-r--r--src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java44
2 files changed, 48 insertions, 6 deletions
diff --git a/src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java b/src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java
index a396516..e8dc384 100644
--- a/src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java
+++ b/src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/DocumentStoreInterface.java
@@ -39,11 +39,13 @@ public interface DocumentStoreInterface {
public OperationResult deleteIndex(String indexName) throws DocumentStoreOperationException;
- public DocumentOperationResult createDocument(String indexName, DocumentStoreDataEntity document)
- throws DocumentStoreOperationException;
+ public DocumentOperationResult createDocument(String indexName,
+ DocumentStoreDataEntity document,
+ boolean allowImplicitIndexCreation) throws DocumentStoreOperationException;
- public DocumentOperationResult updateDocument(String indexName, DocumentStoreDataEntity document)
- throws DocumentStoreOperationException;
+ public DocumentOperationResult updateDocument(String indexName,
+ DocumentStoreDataEntity document,
+ boolean allowImplicitIndexCreation) throws DocumentStoreOperationException;
public DocumentOperationResult deleteDocument(String indexName, DocumentStoreDataEntity document)
throws DocumentStoreOperationException;
diff --git a/src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java b/src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java
index 0e9ff8b..371a483 100644
--- a/src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java
+++ b/src/main/java/org/openecomp/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java
@@ -365,8 +365,28 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
}
@Override
- public DocumentOperationResult createDocument(String indexName, DocumentStoreDataEntity document)
+ public DocumentOperationResult createDocument(String indexName,
+ DocumentStoreDataEntity document,
+ boolean allowImplicitIndexCreation)
throws DocumentStoreOperationException {
+
+ if(!allowImplicitIndexCreation) {
+
+ // Before we do anything, make sure that the specified index actually exists in the
+ // document store - we don't want to rely on ElasticSearch to fail the document
+ // create because it could be configured to implicitly create a non-existent index,
+ // which can lead to hard-to-debug behaviour with queries down the road.
+ OperationResult indexExistsResult = checkIndexExistence(indexName);
+ if ((indexExistsResult.getResultCode() < 200) || (indexExistsResult.getResultCode() >= 300)) {
+
+ DocumentOperationResult opResult = new DocumentOperationResult();
+ opResult.setResultCode(Status.NOT_FOUND.getStatusCode());
+ opResult.setResult("Document Index '" + indexName + "' does not exist.");
+ opResult.setFailureCause("Document Index '" + indexName + "' does not exist.");
+ return opResult;
+ }
+ }
+
if (document.getId() == null || document.getId().isEmpty()) {
return createDocumentWithoutId(indexName, document);
} else {
@@ -531,8 +551,28 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
}
@Override
- public DocumentOperationResult updateDocument(String indexName, DocumentStoreDataEntity document)
+ public DocumentOperationResult updateDocument(String indexName,
+ DocumentStoreDataEntity document,
+ boolean allowImplicitIndexCreation)
throws DocumentStoreOperationException {
+
+ if(!allowImplicitIndexCreation) {
+
+ // Before we do anything, make sure that the specified index actually exists in the
+ // document store - we don't want to rely on ElasticSearch to fail the document
+ // create because it could be configured to implicitly create a non-existent index,
+ // which can lead to hard-to-debug behaviour with queries down the road.
+ OperationResult indexExistsResult = checkIndexExistence(indexName);
+ if ((indexExistsResult.getResultCode() < 200) || (indexExistsResult.getResultCode() >= 300)) {
+
+ DocumentOperationResult opResult = new DocumentOperationResult();
+ opResult.setResultCode(Status.NOT_FOUND.getStatusCode());
+ opResult.setResult("Document Index '" + indexName + "' does not exist.");
+ opResult.setFailureCause("Document Index '" + indexName + "' does not exist.");
+ return opResult;
+ }
+ }
+
DocumentOperationResult opResult = new DocumentOperationResult();
// Initialize operation result with a failure codes / fault string