Search in sources :

Example 1 with DbAccessFactory

use of com.axway.ats.log.autodb.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");
    DbWriteAccess dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
    dbAccess.updateMachineInfo(dbMachineName, machineDescriptionString, true);
    log.info("Successfully updated the info about " + dbMachineName);
}
Also used : DbAccessFactory(com.axway.ats.log.autodb.DbAccessFactory) MachineDescriptionOperations(com.axway.ats.agent.components.monitoring.operations.clients.MachineDescriptionOperations) DbWriteAccess(com.axway.ats.log.autodb.DbWriteAccess) Validator(com.axway.ats.core.validation.Validator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 2 with DbAccessFactory

use of com.axway.ats.log.autodb.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 {
    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 log4j 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.DbAccessFactory) AgentException(com.axway.ats.agent.core.exceptions.AgentException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 3 with DbAccessFactory

use of com.axway.ats.log.autodb.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<BasicReadingBean> readings, Map<String, Integer> readingIdToDbIdMap) throws DatabaseAccessException {
    Logger log = Logger.getLogger(DatabaseReadingsRepository.class);
    if (dbAccess == null) {
        dbAccess = new DbAccessFactory().getNewDbWriteAccessObject();
    }
    List<BasicReadingBean> repository = repositoryPerHostMap.get(monitoredHost);
    if (repository == null) {
        repository = new ArrayList<BasicReadingBean>();
        repositoryPerHostMap.put(monitoredHost, repository);
    }
    for (BasicReadingBean reading : readings) {
        if (reading instanceof FullReadingBean) {
            FullReadingBean newReading = (FullReadingBean) reading;
            StringBuilder newReadingParameters = new StringBuilder();
            Map<String, String> readingParameters = newReading.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) newReading).getTheNameOfThisParentProcess();
                String thisReadingName = thisProcessName + " - " + newReading.getName();
                newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(thisReadingName, newReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME), thisProcessName, newReading.getUnit(), newReadingParameters.toString());
                log.debug("DB id " + newReadingDatabaseId + " for parent process reading: " + thisReadingName);
            } else {
                String parentName = newReading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
                if (parentName != null) {
                    parentName = "[process] " + parentName;
                }
                newReadingDatabaseId = dbAccess.populateSystemStatisticDefinition(newReading.getName(), parentName, "", newReading.getUnit(), newReadingParameters.toString());
                log.debug("DB id " + newReadingDatabaseId + " for reading: " + newReading.getName());
            }
            // remember the DB ID of this reading, because the monitoring remote service gives us the
            // full reading information only the first time
            newReading.setDbId(newReadingDatabaseId);
            // we maintain this map so can easily find the DB id of each Basic reading(it has reading id only)
            readingIdToDbIdMap.put(newReading.getId(), newReading.getDbId());
        }
    }
}
Also used : ParentProcessReadingBean(com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean) DbAccessFactory(com.axway.ats.log.autodb.DbAccessFactory) BasicReadingBean(com.axway.ats.common.performance.monitor.beans.BasicReadingBean) Logger(org.apache.log4j.Logger) FullReadingBean(com.axway.ats.common.performance.monitor.beans.FullReadingBean)

Aggregations

DbAccessFactory (com.axway.ats.log.autodb.DbAccessFactory)3 MachineDescriptionOperations (com.axway.ats.agent.components.monitoring.operations.clients.MachineDescriptionOperations)1 AgentException (com.axway.ats.agent.core.exceptions.AgentException)1 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 BasicReadingBean (com.axway.ats.common.performance.monitor.beans.BasicReadingBean)1 FullReadingBean (com.axway.ats.common.performance.monitor.beans.FullReadingBean)1 ParentProcessReadingBean (com.axway.ats.common.performance.monitor.beans.ParentProcessReadingBean)1 Validator (com.axway.ats.core.validation.Validator)1 DbWriteAccess (com.axway.ats.log.autodb.DbWriteAccess)1 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)1 Logger (org.apache.log4j.Logger)1