aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main
diff options
context:
space:
mode:
authorDunietz, Irwin <irwin.dunietz@att.com>2019-03-03 12:20:53 -0500
committerTakamune Cho <takamune.cho@att.com>2019-03-07 19:04:44 +0000
commit6a7b6c092c282884cf263315a4a4802242dcb2fc (patch)
tree614f563ee18ff24560d12ac3acf63f5a56306341 /appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main
parent7ba77298cc3e45bc215b236414bc406466b1aeec (diff)
Update appc-dispatcher for >1 ansible servers
Change Transaction record update logic to handle null instance entry. Issue-ID: APPC-1516 Change-Id: Ia87e08fbb61d4d0be38802e3e81b45773b1d9498 Signed-off-by: Dunietz, Irwin <irwin.dunietz@att.com>
Diffstat (limited to 'appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main')
-rw-r--r--appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java6
-rw-r--r--appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java96
2 files changed, 95 insertions, 7 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java
index 17e0e2575..40bd0a71d 100644
--- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java
+++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
@@ -45,10 +45,12 @@ public interface TransactionRecorder {
/**
* This method is called when a particular row in transactions needs to be updated
* @param key This is TransactionId which uniquely identifies the record.
+ * @param requestId
* @param updateColumns Map containing names of updated columns and their values.
* @throws APPCException
*/
- void update(String key, Map<TransactionConstants.TRANSACTION_ATTRIBUTES, String> updateColumns) throws APPCException;
+ void update(String key, String requestId, Map<TransactionConstants.TRANSACTION_ATTRIBUTES, String> updateColumns)
+ throws APPCException;
/**
* Marks all records in Transactions table in non-terminal state as ABORTED. This method is to be called during
diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java
index 5c5d8fc24..12a3457d0 100644
--- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java
+++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP : APPC
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
* ================================================================================
@@ -109,14 +109,29 @@ public class TransactionRecorderImpl implements TransactionRecorder {
}
@Override
- public void update(String key, Map<TransactionConstants.TRANSACTION_ATTRIBUTES, String> updateColumns) throws
- APPCException {
+ public void update(String key,
+ String requestId,
+ Map<TransactionConstants.TRANSACTION_ATTRIBUTES, String> updateColumns) throws APPCException {
+ logger.debug("Inside update in TransactionRecorderImpl");
+
+ if (appcInstanceId != null && checkIfNullInstanceEntryExist(key, requestId)) {
+ updateNullInstanceEntry(key, requestId, updateColumns);
+ } else {
+ updateTransactionEntry(key, updateColumns);
+ }
+ logger.trace("End of Update Transaction table.");
+ }
+
+ private void updateTransactionEntry(String key, Map<TRANSACTION_ATTRIBUTES, String> updateColumns)
+ throws APPCException {
ArrayList<String> values = new ArrayList<>();
+ logger.debug("Inside updateTransactionEntry");
StringBuilder queryBuilder = new StringBuilder("UPDATE TRANSACTIONS SET ");
for (Map.Entry<TransactionConstants.TRANSACTION_ATTRIBUTES, String> entry : updateColumns.entrySet()) {
queryBuilder.append(entry.getKey().getColumnName() + " = ? ,");
values.add(entry.getValue());
+ logger.debug("Value for " + entry.getKey().getColumnName() + " in Transaction table: " + entry.getValue());
}
queryBuilder.deleteCharAt(queryBuilder.lastIndexOf(","));
queryBuilder.append(WHERE + TRANSACTION_ID.getColumnName() + " = ?");
@@ -124,9 +139,16 @@ public class TransactionRecorderImpl implements TransactionRecorder {
String query = queryBuilder.toString();
try {
- dbLibService.writeData(query, values, SCHEMA);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Before updating Transaction table the Query is: " + query);
+ for (String value : values) {
+ logger.debug("Value for Transaction table: " + value);
+ }
+ }
+ Boolean result = dbLibService.writeData(query, values, SCHEMA);
+ logger.debug("Transactions table data update, writeData() result: " + result);
} catch (SQLException e) {
- logger.error("Error in updating records " + e);
+ logger.error("Error in updating records in updateTransactionEntry " + e);
throw new APPCException(ERROR_ACCESSING_DATABASE, e);
}
if (logger.isTraceEnabled()) {
@@ -135,6 +157,70 @@ public class TransactionRecorderImpl implements TransactionRecorder {
}
+ private void updateNullInstanceEntry(String key,
+ String requestId,
+ Map<TRANSACTION_ATTRIBUTES, String> updateColumns) throws APPCException {
+ logger.debug("Inside updateNullInstanceEntry");
+
+ ArrayList<String> values = new ArrayList<>();
+ StringBuilder queryBuilder = new StringBuilder("UPDATE TRANSACTIONS SET ");
+ for (Map.Entry<TransactionConstants.TRANSACTION_ATTRIBUTES, String> entry : updateColumns.entrySet()) {
+ queryBuilder.append(entry.getKey().getColumnName() + " = ? ,");
+ values.add(entry.getValue());
+ }
+ // queryBuilder.deleteCharAt(queryBuilder.lastIndexOf(","));
+ queryBuilder.append(TRANSACTION_ID.getColumnName() + " = ?");
+ queryBuilder.append(WHERE + TRANSACTION_ID.getColumnName() + " = ? AND "
+ + REQUEST_ID.getColumnName() + " = ? ");
+ values.add(appcInstanceId + "~" + key);
+ values.add(null + "~" + key);
+ values.add(requestId);
+ String query = queryBuilder.toString();
+ try {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Before updating Transaction table the Query is: " + query);
+ for (String value : values) {
+ logger.debug("Value for Transaction table: " + value);
+ }
+ }
+ Boolean result = dbLibService.writeData(query, values, SCHEMA);
+ logger.debug("Transactions table data update, writeData() result: " + result);
+
+ } catch (SQLException e) {
+ logger.error("Error in updating records in updateNullInstanceEntry " + e);
+ throw new APPCException(ERROR_ACCESSING_DATABASE, e);
+ }
+
+ }
+
+ private boolean checkIfNullInstanceEntryExist(String key, String requestId) throws APPCException {
+ logger.debug("Entered checkIfNullInstanceEntryExist");
+ String nullInstanceCheckQuery = new String("SELECT COUNT(*) as ROWS FROM " +
+ TransactionConstants.TRANSACTIONS + WHERE +
+ TRANSACTION_ID.getColumnName() + " = ? AND " +
+ REQUEST_ID.getColumnName() + " = ? ");
+
+ ArrayList<String> nullInstanceCheckParams = new ArrayList<>();
+ nullInstanceCheckParams.add(null + "~" + key);
+ nullInstanceCheckParams.add(requestId);
+
+ try{
+ CachedRowSet rowSet = dbLibService.getData(nullInstanceCheckQuery, nullInstanceCheckParams, SCHEMA);
+ int noRows = 0;
+ if (rowSet != null && rowSet.first()) {
+ noRows = rowSet.getInt("ROWS");
+ logger.info("No of Rows in Transactions Table with TRANSACTION_ID: " +
+ null + "~" + key + " and REQUEST_ID " + requestId + " is: " + noRows);
+ }
+ if(noRows > 0)
+ return true;
+ } catch (SQLException e) {
+ logger.error("Error in checkIfNullInstanceEntryExist in the transaction table", e);
+ throw new APPCException(ERROR_ACCESSING_DATABASE, e);
+ }
+ return false;
+ }
+
@Override
public void markTransactionsAborted(String appcInstanceId) {
if (logger.isTraceEnabled()) {