Update appc-dispatcher for >1 ansible servers 72/79572/10
authorDunietz, Irwin <irwin.dunietz@att.com>
Sun, 3 Mar 2019 17:20:53 +0000 (12:20 -0500)
committerTakamune Cho <takamune.cho@att.com>
Thu, 7 Mar 2019 19:04:44 +0000 (19:04 +0000)
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>
14 files changed:
appc-dispatcher/appc-command-executor/appc-command-executor-api/pom.xml
appc-dispatcher/appc-command-executor/appc-command-executor-core/pom.xml
appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/pom.xml
appc-dispatcher/appc-dispatcher-common/execution-queue-management-lib/pom.xml
appc-dispatcher/appc-dispatcher-common/transaction-recorder/pom.xml
appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java
appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java
appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java
appc-dispatcher/appc-request-handler/appc-request-handler-api/pom.xml
appc-dispatcher/appc-request-handler/appc-request-handler-core/pom.xml
appc-dispatcher/appc-request-handler/appc-request-handler-core/src/main/java/org/onap/appc/requesthandler/impl/AbstractRequestHandlerImpl.java
appc-dispatcher/appc-workflow-management/appc-workflow-management-api/pom.xml
appc-dispatcher/appc-workflow-management/appc-workflow-management-core/pom.xml
appc-dispatcher/pom.xml

index 210fd04..1d03434 100644 (file)
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-       <parent>
-               <groupId>org.onap.appc.parent</groupId>
-               <artifactId>binding-parent</artifactId>
-               <version>1.5.0-SNAPSHOT</version>
-                <relativePath />
-       </parent>
+    <parent>
+        <groupId>org.onap.appc.parent</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>1.5.0-SNAPSHOT</version>
+        <relativePath />
+    </parent>
 
     <artifactId>appc-command-executor-api</artifactId>
     <packaging>bundle</packaging>
index 4ffa0b8..40cbb3e 100644 (file)
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-       <parent>
-               <groupId>org.onap.appc.parent</groupId>
-               <artifactId>binding-parent</artifactId>
-               <version>1.5.0-SNAPSHOT</version>
-                <relativePath />
-       </parent>
+    <parent>
+        <groupId>org.onap.appc.parent</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>1.5.0-SNAPSHOT</version>
+        <relativePath />
+    </parent>
 
     <artifactId>appc-command-executor-core</artifactId>
     <packaging>bundle</packaging>
             <artifactId>appc-lifecycle-management-api</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.onap.ccsdk.sli.adaptors</groupId>
             <artifactId>aai-service-provider</artifactId>
index 5d1861d..60352e4 100644 (file)
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
-  
+
        http://www.apache.org/licenses/LICENSE-2.0
-  
+
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-  
+
   ============LICENSE_END=========================================================
- -->   
+ -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
             <artifactId>commons-dbcp2</artifactId>
             <version>${apache.common.dbcp2.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
         </dependency>
-       <dependency>
-               <groupId>org.mariadb.jdbc</groupId>
-               <artifactId>mariadb-java-client</artifactId>
-       </dependency>
+        <dependency>
+            <groupId>com.att.eelf</groupId>
+            <artifactId>eelf-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mariadb.jdbc</groupId>
+            <artifactId>mariadb-java-client</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.onap.appc</groupId>
             <artifactId>appc-test-dependencies</artifactId>
index 93da4fe..9b96a53 100644 (file)
             <groupId>com.att.eelf</groupId>
             <artifactId>eelf-core</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
index ca1bfc6..6747c58 100644 (file)
             <scope>test</scope>
             <type>pom</type>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
 
     </dependencies>
 
index 17e0e25..40bd0a7 100644 (file)
@@ -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
index 5c5d8fc..12a3457 100644 (file)
@@ -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()) {
index 8d30ef3..36cf26b 100644 (file)
@@ -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
  * ================================================================================
@@ -145,7 +145,7 @@ public class TransactionRecorderImplTest {
     }
 
     /**
-     * Verify the transactionRecorderImpl.sore() store the TransactionRecord correctly in the database.
+     * Verify the transactionRecorderImpl.store() store the TransactionRecord correctly in the database.
      */
     @Test
     public void testStore() throws Exception {
@@ -274,9 +274,13 @@ public class TransactionRecorderImplTest {
         insertRecord(input);
         Map<TransactionConstants.TRANSACTION_ATTRIBUTES, String> updateColumns = new HashMap<>();
         updateColumns.put(TransactionConstants.TRANSACTION_ATTRIBUTES.TARGET_TYPE, "Firewall");
+        Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation ->
+                returnResult(invocation.getArguments()));
         Mockito.when(dbLibService.writeData(anyString(), anyObject(), anyString())).thenAnswer(invocation ->
                 testUpdateInMemory(invocation.getArguments()));
-        transactionRecorderImpl.update(input.getTransactionId(), updateColumns);
+        transactionRecorderImpl.update(input.getTransactionId(), input.getRequestId(), updateColumns);
+        Mockito.verify(dbLibService).getData(anyString(), anyObject(), anyString());
+        Mockito.verify(dbLibService).writeData(anyString(), anyObject(), anyString());
     }
 
     @Test
@@ -289,7 +293,97 @@ public class TransactionRecorderImplTest {
         expectedEx.expect(APPCException.class);
         expectedEx.expectMessage(TransactionConstants.ERROR_ACCESSING_DATABASE);
         expectedEx.expectCause(isA(SQLException.class));
-        transactionRecorderImpl.update(input.getTransactionId(), updateColumns);
+        transactionRecorderImpl.update(input.getTransactionId(), input.getRequestId(), updateColumns);
+    }
+
+    @Test
+    public void testUpdatewithNullInstance() throws APPCException, SQLException {
+        TransactionRecord input = prepareTransactionsInput();
+        Map<TransactionConstants.TRANSACTION_ATTRIBUTES, String> updateColumns = new HashMap<>();
+        updateColumns.put(TransactionConstants.TRANSACTION_ATTRIBUTES.TARGET_TYPE, "Firewall");
+        Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation ->
+                returnPositiveResult(invocation.getArguments()));
+        Mockito.when(dbLibService.writeData(anyString(), anyObject(), anyString())).thenAnswer(invocation ->
+                testUpdateInMemory(invocation.getArguments()));
+
+        transactionRecorderImpl.update(input.getTransactionId(), input.getRequestId(), updateColumns);
+        Mockito.verify(dbLibService).getData(anyString(), anyObject(), anyString());
+        Mockito.verify(dbLibService).writeData(anyString(), anyObject(), anyString());
+    }
+
+    private Object returnPositiveResult(Object[] obj) throws Exception {
+        String query = (String) obj[0];
+        ArrayList<String> args = (ArrayList<String>) obj[1];
+        System.out.println("returnPositiveResult: Query: " + query + "\nArgs: " + args);
+
+        insertNullInstanceData(args.get(0));
+
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps_second = con.prepareStatement(query)
+             ) {
+            for (int i = 1; i <= args.size(); i++) {
+                ps_second.setString(i, args.get(i - 1));
+            }
+            CachedRowSet rowSet = new CachedRowSetImpl();
+            rowSet.populate(ps_second.executeQuery());
+            return rowSet;
+        }
+    }
+
+    private void insertNullInstanceData(String transactionId) throws Exception {
+        final String nullInstanceQuery = (TransactionConstants.INSERT_INTO + TransactionConstants.TRANSACTIONS +
+                                          " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement(nullInstanceQuery)
+             ) {
+            ArrayList<String> input = new ArrayList<String>();
+            input.add(transactionId);
+            input.add(dateToStringConverterMillis(Instant.parse("2017-09-12T00:00:01.00Z")));
+            input.add("REQUEST_ID");
+            input.add("SUB_REQUEST_ID");
+            input.add("ORIGINATOR_ID");
+            input.add(dateToStringConverterMillis(Instant.parse("2018-09-12T00:00:02.00Z")));
+            input.add(dateToStringConverterMillis(Instant.parse("2018-09-12T20:00:02.00Z")));
+            input.add("TARGET_ID");
+            input.add("TARGET_TYPE");
+            input.add("Audit");
+            input.add(String.valueOf(200));
+            input.add("SERVICE_INSTANCE_ID");
+            input.add("ACCEPTED");
+            input.add("DESCRIPTION");
+            input.add("test");
+            input.add("test");
+            input.add("test");
+            input.add("EXCLUSIVE");
+
+            for (int i = 1; i <= input.size(); i++) {
+                ps.setString(i, input.get(i-1));
+            }
+            ps.execute();
+
+            if (checkIfRowIsPresent(input.get(0))) {
+                System.out.println("RECORD INSERTED " + input.get(0));
+            }
+        }
+    }
+
+    private ResultSet returnResult(Object[] obj) throws Exception {
+        String query = (String) obj[0];
+        ArrayList<String> args = (ArrayList<String>) obj[1];
+        System.out.println("Query: " + query + "\nArgs: " + args);
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement(query)
+             ) {
+            for (int i = 1; i <= args.size(); i++) {
+                ps.setString(i, args.get(i - 1));
+            }
+            CachedRowSet rowSet = new CachedRowSetImpl();
+            rowSet.populate(ps.executeQuery());
+            return rowSet;
+        }
     }
 
     @Test
@@ -334,74 +428,94 @@ public class TransactionRecorderImplTest {
     private ResultSet inMemoryExecutionWithResultSet(Object[] obj) throws Exception {
         String query = (String) obj[0];
         ArrayList<String> args = (ArrayList<String>) obj[1];
-        Connection con = dbConnectionPool.getConnection();
-        PreparedStatement ps = con.prepareStatement(query);
-        for (int i = 1; i <= args.size(); i++) {
-            ps.setString(i, args.get(i - 1));
+        // System.out.println("Query: " + query + "\nArgs: " + args);
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement(query)
+             ) {
+            for (int i = 1; i <= args.size(); i++) {
+                ps.setString(i, args.get(i - 1));
+            }
+            CachedRowSet rowSet = new CachedRowSetImpl();
+            rowSet.populate(ps.executeQuery());
+            return rowSet;
         }
-        CachedRowSet rowSet = new CachedRowSetImpl();
-        rowSet.populate(ps.executeQuery());
-        return rowSet;
     }
 
     private boolean testMarkAbortedInMemory(Object[] obj) throws Exception {
         String query = (String) obj[0];
         ArrayList<String> args = (ArrayList<String>) obj[1];
-        Connection con = dbConnectionPool.getConnection();
-        PreparedStatement ps = con.prepareStatement(query);
-        for (int i = 1; i <= args.size(); i++) {
-            ps.setString(i, args.get(i - 1));
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement(query)
+             ) {
+            for (int i = 1; i <= args.size(); i++) {
+                ps.setString(i, args.get(i - 1));
+            }
+            ps.execute();
+            return isTransactionAborted();
         }
-        ps.execute();
-        return isTransactionAborted();
     }
 
     private boolean isTransactionAborted() throws Exception {
         String query = "SELECT COUNT(*) FROM  TRANSACTIONS WHERE STATE = ?";
-        Connection con = dbConnectionPool.getConnection();
-        PreparedStatement ps = con.prepareStatement(query);
-        ps.setString(1, RequestStatus.ABORTED.toString());
-        ResultSet rs = ps.executeQuery();
-        while (rs.next()) {
-            int value = rs.getInt(1);
-            if (value == 1) {
-                System.out.println("Non terminal Transactions are aborted");
-                return true;
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement(query)
+             ) {
+            ps.setString(1, RequestStatus.ABORTED.toString());
+            try (
+                 ResultSet rs = ps.executeQuery()
+                 ) {
+                while (rs.next()) {
+                    int value = rs.getInt(1);
+                    if (value == 1) {
+                        System.out.println("Non terminal Transactions are aborted");
+                        return true;
+                    }
+                }
+                throw new Exception("Transactions are not aborted");
             }
         }
-        throw new Exception("Transactions are not aborted");
     }
 
     private boolean testUpdateInMemory(Object[] obj) throws Exception {
         String query = (String) obj[0];
         ArrayList<String> args = (ArrayList<String>) obj[1];
-        Connection con = dbConnectionPool.getConnection();
-        PreparedStatement ps = con.prepareStatement(query);
-        for (int i = 1; i <= args.size(); i++) {
-            ps.setString(i, args.get(i - 1));
-        }
-        ps.execute();
-        String updatedValue = checkIfValueIsUpdated(args.get(1));
-        System.out.println("updated Value is " + updatedValue);
-        if (updatedValue.equals("Firewall")) {
-            return true;
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement(query)
+             ) {
+            for (int i = 1; i <= args.size(); i++) {
+                System.out.println("Value at " + i + ": " + args.get(i - 1));
+                ps.setString(i, args.get(i - 1));
+            }
+            ps.execute();
+            String updatedValue = checkIfValueIsUpdated(args.get(1));
+            System.out.println("updated Value is " + updatedValue);
+            if (updatedValue.equals("Firewall")) {
+                return true;
+            }
+            throw new Exception("Not Updated");
         }
-        throw new Exception("Not Updated");
     }
 
     private boolean testStoreInMemory(Object[] obj) throws Exception {
         String query = (String) obj[0];
         ArrayList<String> args = (ArrayList<String>) obj[1];
-        Connection con = dbConnectionPool.getConnection();
-        PreparedStatement ps = con.prepareStatement(query);
-        for (int i = 1; i <= args.size(); i++) {
-            ps.setString(i, args.get(i - 1));
-        }
-        ps.execute();
-        if (checkIfRowIsPresent(args.get(0))) {
-            return true;
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement(query)
+             ) {
+            for (int i = 1; i <= args.size(); i++) {
+                ps.setString(i, args.get(i - 1));
+            }
+            ps.execute();
+            if (checkIfRowIsPresent(args.get(0))) {
+                return true;
+            }
+            throw new Exception("Failed to update");
         }
-        throw new Exception("Failed to update");
     }
 
     private TransactionRecord prepareTransactionsInput() {
@@ -426,19 +540,21 @@ public class TransactionRecorderImplTest {
     private void insertRecord(TransactionRecord input) throws SQLException {
         final String STORE_DATE_QUERY = TransactionConstants.INSERT_INTO + TransactionConstants.TRANSACTIONS +
                 " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
-        Connection con = dbConnectionPool.getConnection();
-        PreparedStatement ps = con.prepareStatement(STORE_DATE_QUERY);
-        ArrayList<String> args = prepareArguments(input);
-        args.remove(0);
-        args.add(0, "123~" + input.getTransactionId());
-        for (int i = 1; i <= 18; i++) {
-            ps.setString(i, args.get(i - 1));
-        }
-        ps.execute();
-        if (checkIfRowIsPresent(args.get(0))) {
-            System.out.println("RECORD INSERTED " + args.get(0));
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement(STORE_DATE_QUERY)
+             ) {
+            ArrayList<String> args = prepareArguments(input);
+            args.remove(0);
+            args.add(0, "123~" + input.getTransactionId());
+            for (int i = 1; i <= 18; i++) {
+                ps.setString(i, args.get(i - 1));
+            }
+            ps.execute();
+            if (checkIfRowIsPresent(args.get(0))) {
+                System.out.println("RECORD INSERTED " + args.get(0));
+            }
         }
-
     }
 
     private ArrayList<String> prepareArguments(TransactionRecord input) {
@@ -498,15 +614,24 @@ public class TransactionRecorderImplTest {
     }
 
     private String checkIfValueIsUpdated(String key) throws Exception {
-        Connection con = dbConnectionPool.getConnection();
-        PreparedStatement ps = con.prepareStatement("SELECT TARGET_TYPE FROM  TRANSACTIONS WHERE TRANSACTION_ID = ?");
-        ps.setString(1, key);
-        ResultSet rs = ps.executeQuery();
-        while (rs.next()) {
-            String value = rs.getString("TARGET_TYPE");
-            return value;
+        try (
+             Connection con = dbConnectionPool.getConnection();
+             PreparedStatement ps = con.prepareStatement("SELECT TARGET_TYPE,TRANSACTION_ID FROM TRANSACTIONS" +
+                                                         " WHERE TRANSACTION_ID = ?")
+             ) {
+            ps.setString(1, key);
+            try (
+                 ResultSet rs = ps.executeQuery()
+                 ) {
+               while (rs.next()) {
+                   String value = rs.getString("TARGET_TYPE");
+                   String transactionId = rs.getString("TRANSACTION_ID");
+                   System.out.println("Updated data: TRANSACTION_ID: " + transactionId + " TARGET_TYPE: " + value);
+                   return value;
+               }
+               throw new Exception("Value not found");
+            }
         }
-        throw new Exception("Value not found");
     }
 
 
index c13e6c4..15229dd 100644 (file)
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-       <parent>
-               <groupId>org.onap.appc.parent</groupId>
-               <artifactId>binding-parent</artifactId>
-               <version>1.5.0-SNAPSHOT</version>
-                <relativePath />
-       </parent>
+    <parent>
+        <groupId>org.onap.appc.parent</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>1.5.0-SNAPSHOT</version>
+        <relativePath />
+    </parent>
 
     <artifactId>appc-request-handler-api</artifactId>
     <packaging>bundle</packaging>
index 87aad83..f31ef0f 100644 (file)
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
     <modelVersion>4.0.0</modelVersion>
-       <parent>
-               <groupId>org.onap.appc.parent</groupId>
-               <artifactId>binding-parent</artifactId>
-               <version>1.5.0-SNAPSHOT</version>
-                <relativePath />
-       </parent>
+    <parent>
+        <groupId>org.onap.appc.parent</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>1.5.0-SNAPSHOT</version>
+        <relativePath />
+    </parent>
 
     <artifactId>appc-request-handler-core</artifactId>
     <packaging>bundle</packaging>
             <version>${equinox.osgi.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
index 73c98e9..aa9b42a 100644 (file)
@@ -2,22 +2,22 @@
  * ============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
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * 
+ *
  * ============LICENSE_END=========================================================
  */
 
@@ -233,7 +233,7 @@ public abstract class AbstractRequestHandlerImpl implements RequestHandler {
                     dateToStringConverterMillis(endTime));
         }
         try {
-            transactionRecorder.update(record.getTransactionId(), updateColumns);
+            transactionRecorder.update(record.getTransactionId(), record.getRequestId(), updateColumns);
         } catch (APPCException e) {
             logger.error("Error accessing database", e);
         }
index 856c135..2f19fe6 100644 (file)
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-       <parent>
-               <groupId>org.onap.appc.parent</groupId>
-               <artifactId>binding-parent</artifactId>
-               <version>1.5.0-SNAPSHOT</version>
-                <relativePath />
-       </parent>
+    <parent>
+        <groupId>org.onap.appc.parent</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>1.5.0-SNAPSHOT</version>
+        <relativePath />
+    </parent>
 
     <artifactId>appc-workflow-management-api</artifactId>
     <name>APPC Workflow Management API</name>
index 12e99c2..c9c0871 100644 (file)
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-       <parent>
-               <groupId>org.onap.appc.parent</groupId>
-               <artifactId>binding-parent</artifactId>
-               <version>1.5.0-SNAPSHOT</version>
-                <relativePath />
-       </parent>
+    <parent>
+        <groupId>org.onap.appc.parent</groupId>
+        <artifactId>binding-parent</artifactId>
+        <version>1.5.0-SNAPSHOT</version>
+        <relativePath />
+    </parent>
 
     <artifactId>appc-workflow-management-core</artifactId>
     <packaging>bundle</packaging>
             <artifactId>appc-ranking-framework-lib</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.onap.appc</groupId>
             <artifactId>transaction-recorder</artifactId>
index dc62232..be396ee 100644 (file)
             <artifactId>mockito-core</artifactId>
             <scope>test</scope>
         </dependency>
-            <dependency>
+        <dependency>
             <groupId>org.powermock</groupId>
             <artifactId>powermock-api-mockito</artifactId>
-         </dependency>
-         <dependency>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.powermock</groupId>
             <artifactId>powermock-module-junit4</artifactId>
             <version>1.6.2</version>
     </modules>
 
     <dependencyManagement>
-       <dependencies>
-           <dependency>
-            <groupId>org.powermock</groupId>
-            <artifactId>powermock-api-mockito</artifactId>
-            <version>1.6.4</version>
-         </dependency>
-       </dependencies>
+        <dependencies>
+            <dependency>
+                <groupId>org.powermock</groupId>
+                <artifactId>powermock-api-mockito</artifactId>
+                <version>1.6.4</version>
+            </dependency>
+        </dependencies>
     </dependencyManagement>
 </project>