Search in sources :

Example 1 with DbAccessFactory

use of com.axway.ats.log.autodb.io.DbAccessFactory in project ats-framework by Axway.

the class AbstractClientExecutor method retrieveQueueId.

/**
 * Start performance queue in the database and retrieve its ID
 *
 * @return the started queue ID
 * @throws AgentException
 */
public int retrieveQueueId(int sequence, String hostsList) throws AgentException {
    if (!ActiveDbAppender.isAttached) {
        throw new AgentException("Unable to retrieve queue id from ATS Log database. Db appender is not attached.");
    }
    int queueId;
    try {
        if (dbAccess == null) {
            dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
        }
        queueId = dbAccess.startLoadQueue(queueName, sequence, hostsList, threadingPattern.getPatternDescription(), threadingPattern.getThreadCount(), LOCAL_MACHINE, Calendar.getInstance().getTimeInMillis(), ActiveDbAppender.getCurrentInstance().getTestCaseId(), true);
        log.rememberLoadQueueState(queueName, queueId, threadingPattern.getPatternDescription(), threadingPattern.getThreadCount());
    } catch (DatabaseAccessException e) {
        if (ActiveDbAppender.getCurrentInstance() == null) {
            // The log4j2 DB appender is not attached
            // We assume the user is running a performance test without DB logging
            log.warn("Unable to register a performance queue with name '" + queueName + "' in the loggging database." + " This means the results of running this queue will not be registered in the log DB." + " Check your DB configuration in order to fix this problem.");
            // Return this invalid value will not cause an error on the Test Executor side
            // We also know there will be no error on agent's side as our DB appender will not be present there
            queueId = -1;
        } else {
            throw new AgentException("Unable to register a performance queue with name '" + queueName + "' in the loggging database. This queue will not run at all.", e);
        }
    }
    return queueId;
}
Also used : DbAccessFactory(com.axway.ats.log.autodb.io.DbAccessFactory) AgentException(com.axway.ats.agent.core.exceptions.AgentException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 2 with DbAccessFactory

use of com.axway.ats.log.autodb.io.DbAccessFactory in project ats-framework by Axway.

the class AbstractClientExecutor method populateCheckpointsSummary.

/**
 * Insert checkpoints summaries for each action request
 * @return the checkpoints IDs
 * @throws AgentException
 */
public void populateCheckpointsSummary(int loadQueueId, List<ActionRequest> actionRequests) throws AgentException {
    try {
        if (dbAccess == null) {
            dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
        }
        // If user add same action more than once in same queue,
        // we must not populate it more than once
        Set<String> actionNames = new HashSet<>();
        for (ActionRequest actionRequest : actionRequests) {
            if (actionRequest.getRegisterActionExecution()) {
                String actionName = actionRequest.getActionName();
                if (!actionNames.contains(actionName)) {
                    actionNames.add(actionName);
                    dbAccess.populateCheckpointSummary(loadQueueId, actionName, actionRequest.getTransferUnit(), true);
                }
            }
        }
        dbAccess.populateCheckpointSummary(loadQueueId, AbstractActionTask.ATS_ACTION__QUEUE_EXECUTION_TIME, "", true);
    } catch (DatabaseAccessException e) {
        throw new AgentException("Unable to populate checkpoint summary data for queued actions", e);
    }
}
Also used : DbAccessFactory(com.axway.ats.log.autodb.io.DbAccessFactory) ActionRequest(com.axway.ats.agent.core.action.ActionRequest) AgentException(com.axway.ats.agent.core.exceptions.AgentException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) HashSet(java.util.HashSet)

Example 3 with DbAccessFactory

use of com.axway.ats.log.autodb.io.DbAccessFactory in project ats-framework by Axway.

the class MachineInfoAgent method updateMachineInfo.

/**
 * Retrieves static info about a machine and stores this info into the
 * log DB
 *
 * @param atsAgent the address of the ATS Agent running on the machine of interest
 * @param dbMachineName the name of the machine as it appears in the DB
 * @throws Exception
 */
@PublicAtsApi
public void updateMachineInfo(@Validate(name = "atsAgent", type = ValidationType.STRING_SERVER_WITH_PORT) String atsAgent, @Validate(name = "dbMachineName", type = ValidationType.STRING_NOT_EMPTY) String dbMachineName) throws Exception {
    // validate input parameters
    atsAgent = HostUtils.getAtsAgentIpAndPort(atsAgent);
    new Validator().validateMethodParameters(new Object[] { atsAgent, dbMachineName });
    log.info("Retrieving info about " + dbMachineName + " from " + atsAgent);
    MachineDescriptionOperations mm = new MachineDescriptionOperations(atsAgent);
    String machineDescriptionString = mm.getDescription();
    log.info("Saving retrieved info about " + dbMachineName + " into the Test Explorer database");
    SQLServerDbWriteAccess dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
    dbAccess.updateMachineInfo(dbMachineName, machineDescriptionString, true);
    log.info("Successfully updated the info about " + dbMachineName);
}
Also used : SQLServerDbWriteAccess(com.axway.ats.log.autodb.io.SQLServerDbWriteAccess) DbAccessFactory(com.axway.ats.log.autodb.io.DbAccessFactory) MachineDescriptionOperations(com.axway.ats.agent.components.system.operations.clients.MachineDescriptionOperations) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with DbAccessFactory

use of com.axway.ats.log.autodb.io.DbAccessFactory in project ats-framework by Axway.

the class DatabaseReadingsRepository method updateDatabaseRepository.

/**
 * Populate these reading to the DB, so they have their own DB IDs
 *
 * @param monitoredHost
 * @param readings
 * @param readingIdToDbIdMap
 * @throws DatabaseAccessException
 */
public void updateDatabaseRepository(String monitoredHost, List<ReadingBean> readings) throws DatabaseAccessException {
    Logger log = LogManager.getLogger(DatabaseReadingsRepository.class);
    String caller = ThreadsPerCaller.getCaller();
    if (dbAccess == null) {
        dbAccess = new DbAccessFactory().getNewDbWriteAccessObjectViaPassiveDbAppender(caller);
    }
    String dbConnectionHash = obtainDbConnectionHash(caller);
    Map<String, Integer> knownReadingBeansForCurrentDbConn = knownReadingBeans.get(dbConnectionHash);
    if (knownReadingBeansForCurrentDbConn == null) {
        knownReadingBeansForCurrentDbConn = new HashMap<String, Integer>();
        knownReadingBeans.put(dbConnectionHash, knownReadingBeansForCurrentDbConn);
    }
    for (ReadingBean reading : readings) {
        // check if the current reading already was flagged as known
        int dbId = getDbIdForReading(reading, knownReadingBeansForCurrentDbConn);
        reading.setDbId(dbId);
        if (reading.getDbId() == -1) {
            StringBuilder newReadingParameters = new StringBuilder();
            Map<String, String> readingParameters = reading.getParameters();
            if (readingParameters != null && readingParameters.size() > 0) {
                if (readingParameters.containsKey(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS)) {
                    newReadingParameters.append("'");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS));
                    newReadingParameters.append("'_user pattern is '");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_RECOGNITION_PATTERN));
                    newReadingParameters.append("'_reading=");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_READING_ID));
                    newReadingParameters.append("_started by command '");
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_START_COMMAND));
                    newReadingParameters.append("'");
                } else {
                    newReadingParameters.append(readingParameters.get(SystemMonitorDefinitions.PARAMETER_NAME__CUSTOM_MESSAGE));
                }
            }
            int newReadingDatabaseId;
            if (reading instanceof ParentProcessReadingBean) {
                String thisProcessName = "[process] " + ((ParentProcessReadingBean) reading).getTheNameOfThisParentProcess();
                String thisReadingName = thisProcessName + " - " + reading.getName();
                newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(thisReadingName, reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME), thisProcessName, reading.getUnit(), newReadingParameters.toString());
                log.debug("DB id " + newReadingDatabaseId + " for parent process reading: " + thisReadingName);
            } else {
                String parentName = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
                if (parentName != null) {
                    parentName = "[process] " + parentName;
                }
                newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(reading.getName(), parentName, "", reading.getUnit(), newReadingParameters.toString());
                log.debug("DB id " + newReadingDatabaseId + " for reading: " + reading.getName());
            }
            // remember the DB ID of this reading
            reading.setDbId(newReadingDatabaseId);
            knownReadingBeansForCurrentDbConn.put(reading.getDescription(), reading.getDbId());
        }
    }
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) DbAccessFactory(com.axway.ats.log.autodb.io.DbAccessFactory) Logger(org.apache.logging.log4j.Logger)

Aggregations

DbAccessFactory (com.axway.ats.log.autodb.io.DbAccessFactory)4 AgentException (com.axway.ats.agent.core.exceptions.AgentException)2 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)2 MachineDescriptionOperations (com.axway.ats.agent.components.system.operations.clients.MachineDescriptionOperations)1 ActionRequest (com.axway.ats.agent.core.action.ActionRequest)1 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 ParentProcessReadingBean (com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean)1 ReadingBean (com.axway.ats.common.performance.monitor.beans.ReadingBean)1 Validator (com.axway.ats.core.validation.Validator)1 SQLServerDbWriteAccess (com.axway.ats.log.autodb.io.SQLServerDbWriteAccess)1 HashSet (java.util.HashSet)1 Logger (org.apache.logging.log4j.Logger)1