Code Review
/
aai
/
search-data-service.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Fix to not remove whitespaces in the payload to ES
[aai/search-data-service.git]
/
src
/
main
/
java
/
org
/
onap
/
aai
/
sa
/
searchdbabstraction
/
elasticsearch
/
dao
/
ElasticSearchHttpController.java
diff --git
a/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java
b/src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java
index
ad32129
..
98a254c
100644
(file)
--- a/
src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java
+++ b/
src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java
@@
-26,7
+26,6
@@
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import edu.emory.mathcs.backport.java.util.Arrays;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@
-49,6
+48,7
@@
import org.onap.aai.sa.searchdbabstraction.entity.SearchOperationResult;
import org.onap.aai.sa.searchdbabstraction.logging.SearchDbMsgs;
import org.onap.aai.sa.searchdbabstraction.util.AggregationParsingUtil;
import org.onap.aai.sa.searchdbabstraction.util.DocumentSchemaUtil;
import org.onap.aai.sa.searchdbabstraction.logging.SearchDbMsgs;
import org.onap.aai.sa.searchdbabstraction.util.AggregationParsingUtil;
import org.onap.aai.sa.searchdbabstraction.util.DocumentSchemaUtil;
+import org.onap.aai.sa.searchdbabstraction.util.ElasticSearchPayloadTranslator;
import org.onap.aai.sa.searchdbabstraction.util.SearchDbConstants;
import org.onap.aai.cl.api.LogFields;
import org.onap.aai.cl.api.LogLine;
import org.onap.aai.sa.searchdbabstraction.util.SearchDbConstants;
import org.onap.aai.cl.api.LogFields;
import org.onap.aai.cl.api.LogLine;
@@
-76,10
+76,13
@@
import java.net.ProtocolException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.ws.rs.core.Response.Status;
+
+import org.springframework.http.HttpStatus;
+
/**
/**
@@
-177,7
+180,7
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
//result.setResult("{\"index\": \"" + index + ", \"type\": \"" + DEFAULT_TYPE + "\"}");
}
//result.setResult("{\"index\": \"" + index + ", \"type\": \"" + DEFAULT_TYPE + "\"}");
}
- } catch (DocumentStoreOperationException e) {
+ } catch (DocumentStoreOperationException
| IOException
e) {
result.setFailureCause("Document store operation failure. Cause: " + e.getMessage());
}
result.setFailureCause("Document store operation failure. Cause: " + e.getMessage());
}
@@
-348,6
+351,7
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
try {
conn.setRequestMethod("PUT");
try {
conn.setRequestMethod("PUT");
+ conn.setRequestProperty("Content-Type", "application/json");
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
@@
-363,7
+367,12
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
sb.append(indexMappings);
sb.append("}}");
sb.append(indexMappings);
sb.append("}}");
- attachContent(conn, sb.toString());
+ try {
+ attachContent(conn, ElasticSearchPayloadTranslator.translateESPayload(sb.toString()));
+ } catch(IOException e) {
+ logger.error(SearchDbMsgs.INDEX_CREATE_FAILURE, e);
+ throw new DocumentStoreOperationException(e.getMessage(), e);
+ }
logger.debug("\ncreateTable(), Sending 'PUT' request to URL : " + conn.getURL());
logger.debug("Request content: " + sb.toString());
logger.debug("\ncreateTable(), Sending 'PUT' request to URL : " + conn.getURL());
logger.debug("Request content: " + sb.toString());
@@
-405,12
+414,18
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
try {
conn.setRequestMethod("PUT");
try {
conn.setRequestMethod("PUT");
+ conn.setRequestProperty("Content-Type", "application/json");
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
}
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
}
- attachContent(conn, settingsAndMappings);
+ try {
+ attachContent(conn, ElasticSearchPayloadTranslator.translateESPayload(settingsAndMappings));
+ } catch(IOException e) {
+ logger.error(SearchDbMsgs.INDEX_CREATE_FAILURE, e);
+ throw new DocumentStoreOperationException(e.getMessage());
+ }
handleResponse(conn, result);
// Generate a metrics log so we can track how long the operation took.
handleResponse(conn, result);
// Generate a metrics log so we can track how long the operation took.
@@
-440,7
+455,7
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
if ((indexExistsResult.getResultCode() < 200) || (indexExistsResult.getResultCode() >= 300)) {
DocumentOperationResult opResult = new DocumentOperationResult();
if ((indexExistsResult.getResultCode() < 200) || (indexExistsResult.getResultCode() >= 300)) {
DocumentOperationResult opResult = new DocumentOperationResult();
- opResult.setResultCode(
Status.NOT_FOUND.getStatusCod
e());
+ opResult.setResultCode(
HttpStatus.NOT_FOUND.valu
e());
opResult.setResult("Document Index '" + indexName + "' does not exist.");
opResult.setFailureCause("Document Index '" + indexName + "' does not exist.");
return opResult;
opResult.setResult("Document Index '" + indexName + "' does not exist.");
opResult.setFailureCause("Document Index '" + indexName + "' does not exist.");
return opResult;
@@
-461,13
+476,13
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
DocumentOperationResult opResult = checkDocumentExistence(indexName, document.getId());
DocumentOperationResult opResult = checkDocumentExistence(indexName, document.getId());
- if (opResult.getResultCode() !=
Status.NOT_FOUND.getStatusCod
e()) {
- if (opResult.getResultCode() ==
Status.OK.getStatusCod
e()) {
+ if (opResult.getResultCode() !=
HttpStatus.NOT_FOUND.valu
e()) {
+ if (opResult.getResultCode() ==
HttpStatus.CONFLICT.valu
e()) {
opResult.setFailureCause("A document with the same id already exists.");
} else {
opResult.setFailureCause("Failed to verify a document with the specified id does not already exist.");
}
opResult.setFailureCause("A document with the same id already exists.");
} else {
opResult.setFailureCause("Failed to verify a document with the specified id does not already exist.");
}
- opResult.setResultCode(
Status.CONFLICT.getStatusCod
e());
+ opResult.setResultCode(
HttpStatus.CONFLICT.valu
e());
return opResult;
}
return opResult;
}
@@
-555,9
+570,9
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
private void attachDocument(HttpURLConnection conn, DocumentStoreDataEntity doc)
throws DocumentStoreOperationException {
private void attachDocument(HttpURLConnection conn, DocumentStoreDataEntity doc)
throws DocumentStoreOperationException {
- conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+// conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+ conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Connection", "Close");
conn.setRequestProperty("Connection", "Close");
-
attachContent(conn, doc.getContentInJson());
}
attachContent(conn, doc.getContentInJson());
}
@@
-626,7
+641,7
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
if ((indexExistsResult.getResultCode() < 200) || (indexExistsResult.getResultCode() >= 300)) {
DocumentOperationResult opResult = new DocumentOperationResult();
if ((indexExistsResult.getResultCode() < 200) || (indexExistsResult.getResultCode() >= 300)) {
DocumentOperationResult opResult = new DocumentOperationResult();
- opResult.setResultCode(
Status.NOT_FOUND.getStatusCod
e());
+ opResult.setResultCode(
HttpStatus.NOT_FOUND.valu
e());
opResult.setResult("Document Index '" + indexName + "' does not exist.");
opResult.setFailureCause("Document Index '" + indexName + "' does not exist.");
return opResult;
opResult.setResult("Document Index '" + indexName + "' does not exist.");
opResult.setFailureCause("Document Index '" + indexName + "' does not exist.");
return opResult;
@@
-648,6
+663,7
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
try {
conn.setRequestMethod("PUT");
try {
conn.setRequestMethod("PUT");
+ conn.setRequestProperty("Content-Type", "application/json");
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
@@
-821,6
+837,7
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
try {
conn.setRequestMethod("POST");
try {
conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-Type", "application/json");
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to POST.", e);
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to POST.", e);
@@
-870,6
+887,7
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
try {
conn.setRequestMethod("POST");
try {
conn.setRequestMethod("POST");
+ conn.setRequestProperty("Content-Type", "application/json");
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to POST.", e);
} catch (ProtocolException e) {
shutdownConnection(conn);
throw new DocumentStoreOperationException("Failed to set HTTP request method to POST.", e);
@@
-979,8
+997,8
@@
public class ElasticSearchHttpController implements DocumentStoreInterface {
throw new DocumentStoreOperationException("Failed getting the response body payload.", e);
}
throw new DocumentStoreOperationException("Failed getting the response body payload.", e);
}
- if (resultCode ==
Status.CONFLICT.getStatusCod
e()) {
- opResult.setResultCode(
Status.PRECONDITION_FAILED.getStatusCod
e());
+ if (resultCode ==
HttpStatus.CONFLICT.valu
e()) {
+ opResult.setResultCode(
HttpStatus.PRECONDITION_FAILED.valu
e());
} else {
opResult.setResultCode(resultCode);
}
} else {
opResult.setResultCode(resultCode);
}