aboutsummaryrefslogtreecommitdiffstats
path: root/aai-resources/src/main/java
diff options
context:
space:
mode:
authorKajur, Harish (vk250x) <vk250x@att.com>2019-02-18 00:45:57 -0500
committerKajur, Harish (vk250x) <vk250x@att.com>2019-02-18 20:32:29 -0500
commitb7c8d78c9e715fdc849277d14235d6b64f4d5b9e (patch)
treeb528ef2f53fd9de5da9ca18781f147f6fbbb3696 /aai-resources/src/main/java
parentd2e095c4a1639691b065278f01bf56d6a81c3565 (diff)
Update the bulk single transaction code
to fix the memory leak due to not properly rolling back when there is an exception in the code Issue-ID: AAI-2168 Change-Id: Iaea6b1942547ae9da94b70cf29bc7a405ddabbea Signed-off-by: Kajur, Harish (vk250x) <vk250x@att.com>
Diffstat (limited to 'aai-resources/src/main/java')
-rw-r--r--aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java34
1 files changed, 23 insertions, 11 deletions
diff --git a/aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java b/aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java
index 674c1b4..b06abaa 100644
--- a/aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java
+++ b/aai-resources/src/main/java/org/onap/aai/rest/bulk/BulkSingleTransactionConsumer.java
@@ -19,6 +19,8 @@
*/
package org.onap.aai.rest.bulk;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.javatuples.Pair;
@@ -58,7 +60,8 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
private static final String TARGET_ENTITY = "aai-resources";
private static final Set<String> validOperations = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("put", "patch", "delete")));
private int allowedOperationCount = 30;
- private TransactionalGraphEngine dbEngine = null;
+
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(BulkSingleTransactionConsumer.class);
@POST
@Consumes(value = javax.ws.rs.core.MediaType.APPLICATION_JSON)
@@ -72,6 +75,11 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
DBConnectionType type;
initLogging(req, transId, sourceOfTruth);
+ boolean success = true;
+
+ TransactionalGraphEngine dbEngine = null;
+ TransactionResponse transactionResponse;
+ Response response;
try {
if(AAIConfig.get("aai.use.realtime", "true").equals("true")){
@@ -101,7 +109,7 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
HttpEntry resourceHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class);
resourceHttpEntry.setHttpEntryProperties(version, type);
Loader loader = resourceHttpEntry.getLoader();
- TransactionalGraphEngine dbEngine = resourceHttpEntry.getDbEngine();
+ dbEngine = resourceHttpEntry.getDbEngine();
//populate uri query
populateUriQuery(bulkOperations, dbEngine);
@@ -116,28 +124,32 @@ public class BulkSingleTransactionConsumer extends RESTAPI {
Pair<Boolean, List<Pair<URI, Response>>> results = resourceHttpEntry.process(dbRequests, sourceOfTruth, this.enableResourceVersion());
//process result of db requests
- TransactionResponse transactionResponse = buildTransactionResponse(transaction, results.getValue1());
+ transactionResponse = buildTransactionResponse(transaction, results.getValue1());
//commit/rollback based on results
- if (results.getValue0()) { //everything was processed without error
- dbEngine.commit();
- } else { //something failed
- dbEngine.rollback();
- }
+ success = results.getValue0();
- return Response
+ response = Response
.status(Response.Status.CREATED)
.entity(new GsonBuilder().serializeNulls().create().toJson(transactionResponse))
.build();
} catch (AAIException e) {
- return consumerExceptionResponseGenerator(headers, info, javax.ws.rs.HttpMethod.POST, e);
+ response = consumerExceptionResponseGenerator(headers, info, javax.ws.rs.HttpMethod.POST, e);
+ success = false;
} finally {
if (dbEngine != null) {
- dbEngine.rollback();
+ if(success){
+ dbEngine.commit();
+ LOGGER.info("Successfully committed the transaction to the database");
+ } else {
+ dbEngine.rollback();
+ LOGGER.info("Rolled back the transaction due to failure");
+ }
}
}
+ return response;
}