Search in sources :

Example 1 with Checkpoint

use of com.axway.ats.log.autodb.entities.Checkpoint in project ats-framework by Axway.

the class DbReadAccess method getCheckpointStatistics.

public List<Statistic> getCheckpointStatistics(float timeOffset, String testcaseIds, String actionNames, Set<String> expectedSingleActionUIDs, Set<String> expectedCombinedActionUIDs) throws DatabaseAccessException {
    List<Statistic> allStatistics = new ArrayList<Statistic>();
    String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset)).add("testcase ids", testcaseIds).add("checkpoint names", actionNames).format();
    Map<String, Integer> fakeStatisticIds = new HashMap<String, Integer>();
    /*
         * The DB does not contain combined statistics, so we must create them.
         *
         * All statistics with same name are combined in one statistic(no matter how many queues are).
         * In cases when there are more than one hits at same timestamp, we do not sum the values, but we
         * pass the same number of statistics for this timestamp - users see balloon marker on Test Explorer
         */
    Map<String, Statistic> combinedStatistics = new HashMap<String, Statistic>();
    Map<String, Integer> combinedStatisticHitsAtSameTimestamp = new HashMap<String, Integer>();
    Connection connection = getConnection();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_checkpoint_statistics(?, ?, ?) }");
        callableStatement.setString(1, formatDateFromEpoch(timeOffset));
        callableStatement.setString(2, testcaseIds);
        callableStatement.setString(3, actionNames);
        int numberRecords = 0;
        rs = callableStatement.executeQuery();
        while (rs.next()) {
            // add new statistic
            Statistic statistic = new Statistic();
            statistic.name = rs.getString("statsName");
            statistic.parentName = rs.getString("queueName");
            statistic.unit = "ms";
            statistic.value = rs.getFloat("value");
            statistic.timestamp = rs.getLong("statsAxisTimestamp");
            // Checkpoints will be collected and displayed for testcase
            statistic.machineId = 0;
            statistic.testcaseId = rs.getInt("testcaseId");
            statistic.statisticTypeId = getStatisticFakeId(START_FAKE_ID_VALUE_FOR_CHECKPOINTS, fakeStatisticIds, statistic);
            // add to single statistics
            if (expectedSingleActionUIDs.contains(statistic.getUid())) {
                allStatistics.add(statistic);
            }
            // add to combined statistics
            if (expectedCombinedActionUIDs.contains(statistic.getCombinedStatisticUid())) {
                String statisticKey = statistic.timestamp + "->" + statistic.name;
                Integer timesHaveThisStatisticAtThisTimestamp = combinedStatisticHitsAtSameTimestamp.get(statisticKey);
                Statistic combinedStatistic;
                if (timesHaveThisStatisticAtThisTimestamp == null) {
                    // create a new combined statistic
                    combinedStatistic = new Statistic();
                    combinedStatistic.name = statistic.name;
                    combinedStatistic.parentName = Statistic.COMBINED_STATISTICS_CONTAINER;
                    combinedStatistic.unit = statistic.unit;
                    combinedStatistic.timestamp = statistic.timestamp;
                    combinedStatistic.machineId = statistic.machineId;
                    combinedStatistic.testcaseId = statistic.testcaseId;
                    // this is the first such statistic at this timestamp
                    timesHaveThisStatisticAtThisTimestamp = 1;
                } else {
                    // create another copy of this statistic
                    combinedStatistic = combinedStatistics.get(statisticKey + "->" + timesHaveThisStatisticAtThisTimestamp).newInstance();
                    // we already had such statistic at this timestamp
                    timesHaveThisStatisticAtThisTimestamp++;
                }
                combinedStatistic.value = statistic.value;
                combinedStatistic.statisticTypeId = getStatisticFakeId(START_FAKE_ID_VALUE_FOR_CHECKPOINTS, fakeStatisticIds, combinedStatistic);
                // remember how many times we got same statistic at same timestamp
                combinedStatisticHitsAtSameTimestamp.put(statisticKey, timesHaveThisStatisticAtThisTimestamp);
                // Remember this statistic in the list
                // The way we create the map key assures the proper time ordering
                combinedStatistics.put(statisticKey + "->" + timesHaveThisStatisticAtThisTimestamp, combinedStatistic);
            }
            numberRecords++;
        }
        if (combinedStatistics.size() > 0) {
            // sort the combined statistics by their timestamps
            List<Statistic> sortedStatistics = new ArrayList<Statistic>(combinedStatistics.values());
            Collections.sort(sortedStatistics, new Comparator<Statistic>() {

                @Override
                public int compare(Statistic stat1, Statistic stat2) {
                    return (int) (stat1.timestamp - stat2.timestamp);
                }
            });
            // add the combined statistics to the others
            allStatistics.addAll(sortedStatistics);
        }
        logQuerySuccess(sqlLog, "action response statistics", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return allStatistics;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) Statistic(com.axway.ats.log.autodb.entities.Statistic) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 2 with Checkpoint

use of com.axway.ats.log.autodb.entities.Checkpoint in project ats-framework by Axway.

the class DbReadAccess method getCheckpointStatisticDescriptions.

public List<StatisticDescription> getCheckpointStatisticDescriptions(float timeOffset, String testcaseIds, Map<String, String> testcaseAliases) throws DatabaseAccessException {
    List<StatisticDescription> statisticDescriptions = new ArrayList<StatisticDescription>();
    String sqlLog = new SqlRequestFormatter().add("fdate", formatDateFromEpoch(timeOffset)).add("testcase ids", testcaseIds).format();
    Connection connection = getConnection();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_checkpoint_statistic_descriptions(?, ?) }");
        callableStatement.setString(1, formatDateFromEpoch(timeOffset));
        callableStatement.setString(2, testcaseIds);
        rs = callableStatement.executeQuery();
        int numberRecords = 0;
        while (rs.next()) {
            StatisticDescription statisticDescription = new StatisticDescription();
            statisticDescription.testcaseId = rs.getInt("testcaseId");
            // if user has provided testcase alias - use it instead the original testcase name
            if (testcaseAliases != null) {
                statisticDescription.testcaseName = testcaseAliases.get(String.valueOf(statisticDescription.testcaseId));
            }
            if (statisticDescription.testcaseName == null) {
                statisticDescription.testcaseName = rs.getString("testcaseName");
            }
            statisticDescription.testcaseStarttime = rs.getInt("testcaseStarttime");
            // Checkpoints will be collected and displayed for testcase
            statisticDescription.machineId = 0;
            statisticDescription.machineName = MACHINE_NAME_FOR_ATS_AGENTS;
            statisticDescription.queueName = rs.getString("queueName");
            statisticDescription.numberMeasurements = rs.getInt("statsNumberMeasurements");
            statisticDescription.statisticName = rs.getString("name");
            // "statsUnit" field is null for checkpoint statistics, because the action response times are always measured in "ms"
            statisticDescription.unit = "ms";
            statisticDescriptions.add(statisticDescription);
            numberRecords++;
        }
        logQuerySuccess(sqlLog, "system statistic descriptions", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return statisticDescriptions;
}
Also used : StatisticDescription(com.axway.ats.log.autodb.entities.StatisticDescription) CallableStatement(java.sql.CallableStatement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) ResultSet(java.sql.ResultSet) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 3 with Checkpoint

use of com.axway.ats.log.autodb.entities.Checkpoint in project ats-framework by Axway.

the class DbReadAccess method getCheckpointAggregatedStatistics.

public List<Statistic> getCheckpointAggregatedStatistics(float timeOffset, String testcaseIds, String actionNames, Set<String> expectedSingleActionUIDs, Set<String> expectedCombinedActionUIDs, int interval, int mode) throws DatabaseAccessException {
    List<Statistic> allStatistics = new ArrayList<Statistic>();
    String sqlLog = new SqlRequestFormatter().add("testcase ids", testcaseIds).add("fdate", formatDateFromEpoch(timeOffset)).add("checkpoint names", actionNames).add("inverval (seconds)", interval).add("mode (AVG-0001,SUM-0010,TOTALS-0100,COUNT-1000)", mode).format();
    Map<String, Integer> fakeStatisticIds = new HashMap<String, Integer>();
    /*
         * The DB does not contain combined statistics, so we must create them.
         * All values of statistic with same name and timestamp are summed into 1 statistic
         */
    Map<String, Statistic> combinedStatistics = new HashMap<String, Statistic>();
    Connection connection = getConnection();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_checkpoint_aggregated_statistics(?, ?, ?, ?, ?) }");
        callableStatement.setString(1, formatDateFromEpoch(timeOffset));
        callableStatement.setString(2, testcaseIds);
        callableStatement.setString(3, actionNames);
        callableStatement.setInt(4, interval);
        callableStatement.setInt(5, mode);
        int numberRecords = 0;
        Map<String, Float> totalSumValues = new HashMap<String, Float>();
        rs = callableStatement.executeQuery();
        while (rs.next()) {
            Statistic statistic = new Statistic();
            statistic.name = rs.getString("statsName");
            statistic.parentName = rs.getString("queueName");
            // "statsUnit" field is null for checkpoint statistics, because the action response times are always measured in "ms"
            statistic.unit = "ms";
            statistic.avgValue = rs.getFloat("avgValue");
            statistic.sumValue = rs.getFloat("sumValue");
            statistic.countValue = rs.getFloat("countValue");
            if (StatisticAggregatedType.isTotals(mode)) {
                // total sum value
                float totalSumValue = statistic.sumValue;
                if (totalSumValues.containsKey(statistic.name)) {
                    totalSumValue += totalSumValues.get(statistic.name);
                }
                totalSumValues.put(statistic.name, totalSumValue);
                statistic.totalValue = totalSumValue;
            }
            statistic.timestamp = rs.getLong("timestamp");
            // Checkpoints will be collected and displayed for testcase
            statistic.machineId = 0;
            statistic.testcaseId = rs.getInt("testcaseId");
            statistic.statisticTypeId = getStatisticFakeId(START_FAKE_ID_VALUE_FOR_AGGREGATED_CHECKPOINTS, fakeStatisticIds, statistic);
            // add to single statistics
            if (expectedSingleActionUIDs.contains(statistic.getUid())) {
                allStatistics.add(statistic);
            }
            // add to combined statistics
            if (expectedCombinedActionUIDs.contains(statistic.getCombinedStatisticUid())) {
                String statisticTempKey = statistic.timestamp + "->" + statistic.name;
                Statistic combinedStatistic = combinedStatistics.get(statisticTempKey);
                if (combinedStatistic == null) {
                    // create a new combined statistic
                    combinedStatistic = new Statistic();
                    combinedStatistic.name = statistic.name;
                    combinedStatistic.parentName = Statistic.COMBINED_STATISTICS_CONTAINER;
                    combinedStatistic.unit = statistic.unit;
                    combinedStatistic.timestamp = statistic.timestamp;
                    combinedStatistic.machineId = statistic.machineId;
                    combinedStatistic.testcaseId = statistic.testcaseId;
                    combinedStatistic.statisticTypeId = getStatisticFakeId(START_FAKE_ID_VALUE_FOR_AGGREGATED_CHECKPOINTS, fakeStatisticIds, combinedStatistic);
                    combinedStatistics.put(statisticTempKey, combinedStatistic);
                }
                // calculate the combined value
                combinedStatistic.avgValue = combinedStatistic.avgValue + statistic.avgValue;
                combinedStatistic.sumValue = combinedStatistic.sumValue + statistic.sumValue;
                combinedStatistic.countValue = combinedStatistic.countValue + statistic.countValue;
                combinedStatistic.totalValue = combinedStatistic.totalValue + statistic.totalValue;
            }
            numberRecords++;
        }
        if (combinedStatistics.size() > 0) {
            // sort the combined statistics by their timestamps
            List<Statistic> sortedStatistics = new ArrayList<Statistic>(combinedStatistics.values());
            Collections.sort(sortedStatistics, new Comparator<Statistic>() {

                @Override
                public int compare(Statistic stat1, Statistic stat2) {
                    return (int) (stat1.timestamp - stat2.timestamp);
                }
            });
            // add the combined statistics to the others
            allStatistics.addAll(sortedStatistics);
        }
        logQuerySuccess(sqlLog, "checkpoint aggregated statistics", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return allStatistics;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) Statistic(com.axway.ats.log.autodb.entities.Statistic) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 4 with Checkpoint

use of com.axway.ats.log.autodb.entities.Checkpoint in project ats-framework by Axway.

the class DbReadAccess method getCheckpoints.

public List<Checkpoint> getCheckpoints(String testcaseId, String checkpointName) throws DatabaseAccessException {
    List<Checkpoint> checkpoints = new ArrayList<Checkpoint>();
    String sqlLog = new SqlRequestFormatter().add("testcase id", testcaseId).add("checkpoint name", checkpointName).format();
    Connection connection = getConnection();
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        statement = connection.prepareStatement("SELECT ch.checkpointId, ch.responseTime, ch.transferRate, ch.transferRateUnit, ch.result," + " DATEDIFF(second, CONVERT( datetime, '1970-01-01 00:00:00', 20), ch.endTime) as endTime " + "FROM tCheckpoints ch" + " INNER JOIN tCheckpointsSummary chs on (chs.checkpointSummaryId = ch.checkpointSummaryId)" + " INNER JOIN tLoadQueues c on (c.loadQueueId = chs.loadQueueId)" + " INNER JOIN tTestcases tt on (tt.testcaseId = c.testcaseId) " + "WHERE tt.testcaseId = ? AND ch.name = ?");
        statement.setString(1, testcaseId);
        statement.setString(2, checkpointName);
        rs = statement.executeQuery();
        while (rs.next()) {
            Checkpoint checkpoint = new Checkpoint();
            checkpoint.checkpointId = rs.getInt("checkpointId");
            checkpoint.name = checkpointName;
            checkpoint.responseTime = rs.getInt("responseTime");
            checkpoint.transferRate = rs.getFloat("transferRate");
            checkpoint.transferRateUnit = rs.getString("transferRateUnit");
            checkpoint.result = rs.getInt("result");
            checkpoint.endTime = rs.getLong("endTime");
            checkpoints.add(checkpoint);
        }
        logQuerySuccess(sqlLog, "checkpoints", checkpoints.size());
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, statement);
    }
    return checkpoints;
}
Also used : Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Aggregations

DbConnection (com.axway.ats.core.dbaccess.DbConnection)4 Checkpoint (com.axway.ats.log.autodb.entities.Checkpoint)4 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)4 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 ArrayList (java.util.ArrayList)4 CallableStatement (java.sql.CallableStatement)3 Statistic (com.axway.ats.log.autodb.entities.Statistic)2 HashMap (java.util.HashMap)2 StatisticDescription (com.axway.ats.log.autodb.entities.StatisticDescription)1 PreparedStatement (java.sql.PreparedStatement)1