From 7cf409f03b535f41ee6ea6e4cb04443f3591c93a Mon Sep 17 00:00:00 2001 From: "Maharajh, Robby (rx2202)" Date: Tue, 5 Dec 2017 09:56:30 -0500 Subject: Add limit override for bulk api's Issue-ID: AAI-535 Change-Id: Ie248a85541f77b786973be54a7791f6e4e7dff16 Signed-off-by: Maharajh, Robby (rx2202) --- .../etc/appprops/aaiconfig.properties | 4 ++ .../main/java/org/onap/aai/rest/BulkConsumer.java | 43 ++++++++++++---------- .../org/onap/aai/rest/BulkProcessConsumerTest.java | 1 - 3 files changed, 28 insertions(+), 20 deletions(-) (limited to 'aai-resources') diff --git a/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties b/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties index 27a744c..dda9b46 100644 --- a/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties +++ b/aai-resources/bundleconfig-local/etc/appprops/aaiconfig.properties @@ -151,3 +151,7 @@ aai.jms.enable=false #limit set for bulk consumer APIS aai.bulkconsumer.payloadlimit=30 + +#uncomment and use header X-OverrideLimit with the value to override the bulk api limit +#aai.bulkconsumer.payloadoverride=E6F04B93462CB5B0EDF41C05A9DDF5C3FE59748F +aai.bulkconsumer.payloadoverride=false diff --git a/aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java b/aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java index 5ff0e35..1267792 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/BulkConsumer.java @@ -134,7 +134,7 @@ public abstract class BulkConsumer extends RESTAPI { try { DBConnectionType type = this.determineConnectionType(sourceOfTruth, realTime); - JsonArray transactions = getTransactions(content); + JsonArray transactions = getTransactions(content, headers); for (int i = 0; i < transactions.size(); i++){ HttpEntry httpEntry = new HttpEntry(version, introspectorFactoryType, queryStyle, type); @@ -240,7 +240,7 @@ public abstract class BulkConsumer extends RESTAPI { * @throws JsonSyntaxException Parses and breaks the single payload into an array of individual transaction * bodies to be processed. */ - private JsonArray getTransactions(String content) throws AAIException, JsonSyntaxException { + private JsonArray getTransactions(String content, HttpHeaders headers) throws AAIException, JsonSyntaxException { JsonParser parser = new JsonParser(); JsonObject input = parser.parse(content).getAsJsonObject(); @@ -255,7 +255,7 @@ public abstract class BulkConsumer extends RESTAPI { throw new AAIException("AAI_6111", String.format("input payload does not follow %s interface", module)); } JsonArray transactions = transactionsObj.getAsJsonArray(); - validateRequest(transactions); + validateRequest(transactions, headers); return transactions; } @@ -546,30 +546,35 @@ public abstract class BulkConsumer extends RESTAPI { * @param transactions - a JsonArray of all the transactions in the request payload * @throws AAIException */ - private void validateRequest(JsonArray transactions) throws AAIException{ + private void validateRequest(JsonArray transactions, HttpHeaders headers) throws AAIException{ + String overrideLimit = headers.getRequestHeaders().getFirst("X-OverrideLimit"); + boolean isOverride = overrideLimit != null && !AAIConfig.get(AAIConstants.AAI_BULKCONSUMER_OVERRIDE_LIMIT).equals("false") + && overrideLimit.equals(AAIConfig.get(AAIConstants.AAI_BULKCONSUMER_OVERRIDE_LIMIT)); if (transactions.size() == 0) { //case where user sends a validly formatted transactions object but //which has no actual things in it for A&AI to do anything with //assuming we should count this as a user error throw new AAIException("AAI_6118", "payload had no objects to operate on"); - }else if(transactions.size() > getPayLoadLimit()) { + }else if(!isOverride && transactions.size() > getPayLoadLimit()) { throw new AAIException("AAI_6147", String.format("Payload limit of %s reached, please reduce payload.", getPayLoadLimit())); } - int operationCount = 0; - int payLoadLimit = getPayLoadLimit(); - for(int i = 0; i < transactions.size(); i++){ - Set> entrySet = transactions.get(i).getAsJsonObject().entrySet(); - Iterator> it = entrySet.iterator(); - while(it.hasNext()){ - Map.Entry element = it.next(); - if(element.getValue() instanceof JsonArray) { - operationCount += ((JsonArray) element.getValue()).size(); - }else{ - operationCount++; + if(!isOverride) { + int operationCount = 0; + int payLoadLimit = getPayLoadLimit(); + for (int i = 0; i < transactions.size(); i++) { + Set> entrySet = transactions.get(i).getAsJsonObject().entrySet(); + Iterator> it = entrySet.iterator(); + while (it.hasNext()) { + Map.Entry element = it.next(); + if (element.getValue() instanceof JsonArray) { + operationCount += ((JsonArray) element.getValue()).size(); + } else { + operationCount++; + } + } + if (operationCount > payLoadLimit) { + throw new AAIException("AAI_6147", String.format("Payload limit of %s reached, please reduce payload.", payLoadLimit)); } - } - if(operationCount > payLoadLimit){ - throw new AAIException("AAI_6147", String.format("Payload limit of %s reached, please reduce payload.", payLoadLimit)); } } } diff --git a/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessConsumerTest.java index 1e3a4e4..5a5c4c0 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessConsumerTest.java @@ -255,7 +255,6 @@ public class BulkProcessConsumerTest extends BulkProcessorTestAbstraction { Response response = executeRequest(payload); assertEquals("Created", Response.Status.CREATED.getStatusCode(), response.getStatus()); - //assertEquals("Contains error code", true, response.getEntity().toString().contains("ERR.5.4.6147")); assertEquals("Contains 30 {\"201\":null}", 30, StringUtils.countMatches(response.getEntity().toString(), "{\"201\":null}")); } -- cgit 1.2.3-korg