Search in sources :

Example 1 with UpdateRunEvent

use of com.axway.ats.log.autodb.events.UpdateRunEvent in project ats-framework by Axway.

the class DbEventRequestProcessor method constructUpdateRunEvent.

private void constructUpdateRunEvent() {
    try {
        if (userProvidedUpdateRunEvent != null) {
            // get current run info from database
            Run run = getLatestRun();
            // replace the missing fields, received by the latest UpdateRunEvent with the one from the DB
            String runName = (userProvidedUpdateRunEvent.getRunName() != null) ? userProvidedUpdateRunEvent.getRunName() : run.runName;
            String osName = (userProvidedUpdateRunEvent.getOsName() != null) ? userProvidedUpdateRunEvent.getOsName() : run.os;
            String productName = (userProvidedUpdateRunEvent.getProductName() != null) ? userProvidedUpdateRunEvent.getProductName() : run.productName;
            String versionName = (userProvidedUpdateRunEvent.getVersionName() != null) ? userProvidedUpdateRunEvent.getVersionName() : run.versionName;
            String buildName = (userProvidedUpdateRunEvent.getBuildName() != null) ? userProvidedUpdateRunEvent.getBuildName() : run.buildName;
            String userNote = (userProvidedUpdateRunEvent.getUserNote() != null) ? userProvidedUpdateRunEvent.getUserNote() : run.userNote;
            String hostName = (userProvidedUpdateRunEvent.getHostName() != null) ? userProvidedUpdateRunEvent.getHostName() : run.hostName;
            // construct the new pending UpdateRunEvent
            actualUpdateRunEvent = new UpdateRunEvent(userProvidedUpdateRunEvent.getLoggerFqcn(), (Logger) userProvidedUpdateRunEvent.getLogger(), runName, osName, productName, versionName, buildName, userNote, hostName);
        }
    } catch (SQLException e) {
        /*  
             * Could not obtain run info from database.
             * The exception will be logged to the console only, because the event processor is busy handling the UpdateRunEvent
             * and will not be able to handle the log message event as well
            */
        new AtsConsoleLogger(getClass()).error("Unable to update run with ID '" + eventProcessorState.getRunId() + "'", e);
    }
}
Also used : UpdateRunEvent(com.axway.ats.log.autodb.events.UpdateRunEvent) SQLException(java.sql.SQLException) Run(com.axway.ats.log.autodb.entities.Run) Logger(org.apache.logging.log4j.Logger) AtsConsoleLogger(com.axway.ats.core.log.AtsConsoleLogger) AtsConsoleLogger(com.axway.ats.core.log.AtsConsoleLogger)

Example 2 with UpdateRunEvent

use of com.axway.ats.log.autodb.events.UpdateRunEvent in project ats-framework by Axway.

the class DbEventRequestProcessor method processEventRequest.

public void processEventRequest(LogEventRequest eventRequest) throws LoggingException {
    if (testcaseToDelete > 0) {
        /* Pause for a moment processing the current event.
             * This is (delete testcase)event is not coming from the FIFO queue, as we want to process it as
             * soon as possible, so any events related to this testcase are directly skipped.
             */
        deleteRequestedTestcase();
    // now resume the processing of the current event that came from the queue
    }
    if (isBatchMode && eventRequest == null) {
        // timeout waiting for next event - flush the current cache
        dbAccess.flushCache();
        return;
    }
    LogEvent event = eventRequest.getEvent();
    if (event instanceof AbstractLoggingEvent) {
        AbstractLoggingEvent dbAppenderEvent = (AbstractLoggingEvent) event;
        if (dbAppenderEvent instanceof UpdateSuiteEvent) {
            try {
                dbAppenderEvent.checkIfCanBeProcessed(eventProcessorState);
            } catch (IncorrectProcessorStateException e) {
                /* Suite not started yet, 
                     * so save the current event as pending 
                     * and fired it right after StartSuiteEvent is received
                    */
                pendingUpdateSuiteEvent = (UpdateSuiteEvent) dbAppenderEvent;
                return;
            }
        } else if (dbAppenderEvent instanceof UpdateRunEvent) {
            try {
                /* Run not started yet.
                     * We will fire the event after StartRunEvent is received
                    */
                userProvidedUpdateRunEvent = (UpdateRunEvent) dbAppenderEvent;
                dbAppenderEvent.checkIfCanBeProcessed(eventProcessorState);
            } catch (IncorrectProcessorStateException e) {
                /*
                     * If we get an exception, do no process the event any further.
                     * We will fire it after StartRunEvent is received.
                     * */
                return;
            }
        } else if (dbAppenderEvent instanceof AddTestcaseMetainfoEvent) {
            try {
                dbAppenderEvent.checkIfCanBeProcessed(eventProcessorState);
            } catch (Exception e) {
                AddTestcaseMetainfoEvent atmie = ((AddTestcaseMetainfoEvent) dbAppenderEvent);
                boolean throwException = false;
                if (atmie.getTestcaseId() == -1) {
                    if (eventProcessorState.getTestCaseId() == -1 && eventProcessorState.getLastExecutedTestCaseId() == -1) {
                        // No testcase was either running or previously finished.
                        // ATS needs to throw an Exception
                        throwException = true;
                    }
                } else {
                    // Testcase ID was specified with the event, but still an error occurred. ATS needs to throw an Exception
                    throwException = true;
                }
                if (throwException) {
                    String errorMessage = constructEventProcessingErrorMessage(dbAppenderEvent);
                    log.error(errorMessage);
                    throw e;
                }
            }
        } else {
            // first check if we can process the event at all
            try {
                dbAppenderEvent.checkIfCanBeProcessed(eventProcessorState);
            } catch (LoggingException e) {
                String errorMessage = constructEventProcessingErrorMessage(dbAppenderEvent);
                log.error(errorMessage);
                throw e;
            }
        }
        if (isBatchMode && !(event instanceof CacheableEvent) && eventProcessorState.getLifeCycleState() == LifeCycleState.TEST_CASE_STARTED) {
            // this event can not be cached - flush the current cache
            dbAccess.flushCache();
        }
        switch(dbAppenderEvent.getEventType()) {
            case START_RUN:
                startRun((StartRunEvent) event, eventRequest.getTimestamp());
                if (userProvidedUpdateRunEvent != null) {
                    constructUpdateRunEvent();
                    updateRun(actualUpdateRunEvent);
                }
                break;
            case END_RUN:
                endRun(eventRequest.getTimestamp());
                break;
            case UPDATE_RUN:
                /*
                     * By using data from the latest UpdateRunEvent and the current run info,
                     * construct a pending UpdateRunEvent
                     * */
                constructUpdateRunEvent();
                updateRun(actualUpdateRunEvent);
                break;
            case START_AFTER_SUITE:
                afterSuiteMode = true;
                break;
            case END_AFTER_SUITE:
                afterSuiteMode = false;
                break;
            case ADD_RUN_METAINFO:
                addRunMetainfo((AddRunMetainfoEvent) event);
                break;
            case START_SUITE:
                startSuite((StartSuiteEvent) event, eventRequest.getTimestamp());
                if (pendingUpdateSuiteEvent != null) {
                    updateSuite(pendingUpdateSuiteEvent);
                    pendingUpdateSuiteEvent = null;
                }
                break;
            case END_SUITE:
                endSuite(eventRequest.getTimestamp());
                break;
            case UPDATE_SUITE:
                updateSuite((UpdateSuiteEvent) event);
                break;
            case START_AFTER_CLASS:
                afterClassMode = true;
                break;
            case END_AFTER_CLASS:
                afterClassMode = false;
                break;
            case CLEAR_SCENARIO_METAINFO:
                clearScenarioMetainfo();
                break;
            case ADD_SCENARIO_METAINFO:
                addScenarioMetainfo((AddScenarioMetainfoEvent) event);
                break;
            case UPDATE_TEST_CASE:
                updateTestcase((UpdateTestcaseEvent) event, eventRequest.getTimestamp());
                break;
            case END_TEST_CASE:
                endTestCase((EndTestCaseEvent) event, eventRequest.getTimestamp());
                break;
            case START_TEST_CASE:
                startTestCase((StartTestCaseEvent) event, eventRequest.getTimestamp());
                break;
            case JOIN_TEST_CASE:
                joinTestCase((JoinTestCaseEvent) event);
                break;
            case LEAVE_TEST_CASE:
                leaveTestCase();
                break;
            case ADD_TESTCASE_METAINFO:
                addTestcaseMetainfo((AddTestcaseMetainfoEvent) event);
                break;
            case START_AFTER_METHOD:
                afterMethodMode = true;
                break;
            case END_AFTER_METHOD:
                afterMethodMode = false;
                break;
            case REMEMBER_LOADQUEUE_STATE:
                rememberLoadQueueState((RememberLoadQueueStateEvent) event);
                break;
            case CLEANUP_LOADQUEUE_STATE:
                cleanupLoadQueueState((CleanupLoadQueueStateEvent) event);
                break;
            case END_LOADQUEUE:
                endLoadQueue((EndLoadQueueEvent) event, eventRequest.getTimestamp());
                break;
            case REGISTER_THREAD_WITH_LOADQUEUE:
                registerThreadWithLoadQueue((RegisterThreadWithLoadQueueEvent) event);
                break;
            case START_CHECKPOINT:
                startCheckpoint((StartCheckpointEvent) event);
                break;
            case END_CHECKPOINT:
                endCheckpoint((EndCheckpointEvent) event);
                break;
            case INSERT_CHECKPOINT:
                insertCheckpoint((InsertCheckpointEvent) event);
                break;
            case INSERT_SYSTEM_STAT:
                insertSystemStatistics((InsertSystemStatisticEvent) event);
                break;
            case INSERT_USER_ACTIVITY_STAT:
                insertUserActivityStatistics((InsertUserActivityStatisticEvent) event);
                break;
            case INSERT_MESSAGE:
                InsertMessageEvent insertMessageEvent = (InsertMessageEvent) event;
                insertMessage(eventRequest, insertMessageEvent.isEscapeHtml(), insertMessageEvent.isRunMessage());
                break;
            default:
                throw new LoggingException("Unsupported logging event of type: " + dbAppenderEvent.getEventType());
        }
    } else {
        insertMessage(eventRequest, false, false);
    }
}
Also used : AddTestcaseMetainfoEvent(com.axway.ats.log.autodb.events.AddTestcaseMetainfoEvent) AbstractLoggingEvent(com.axway.ats.log.autodb.model.AbstractLoggingEvent) IncorrectProcessorStateException(com.axway.ats.log.autodb.exceptions.IncorrectProcessorStateException) UpdateRunEvent(com.axway.ats.log.autodb.events.UpdateRunEvent) LoggingException(com.axway.ats.log.autodb.exceptions.LoggingException) LogEvent(org.apache.logging.log4j.core.LogEvent) InsertMessageEvent(com.axway.ats.log.autodb.events.InsertMessageEvent) UpdateSuiteEvent(com.axway.ats.log.autodb.events.UpdateSuiteEvent) CacheableEvent(com.axway.ats.log.autodb.model.CacheableEvent) LoggingException(com.axway.ats.log.autodb.exceptions.LoggingException) LoadQueueAlreadyStartedException(com.axway.ats.log.autodb.exceptions.LoadQueueAlreadyStartedException) ThreadAlreadyRegisteredWithLoadQueueException(com.axway.ats.log.autodb.exceptions.ThreadAlreadyRegisteredWithLoadQueueException) NoSuchLoadQueueException(com.axway.ats.log.autodb.exceptions.NoSuchLoadQueueException) SQLException(java.sql.SQLException) IncorrectProcessorStateException(com.axway.ats.log.autodb.exceptions.IncorrectProcessorStateException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) UnknownHostException(java.net.UnknownHostException)

Aggregations

UpdateRunEvent (com.axway.ats.log.autodb.events.UpdateRunEvent)2 SQLException (java.sql.SQLException)2 AtsConsoleLogger (com.axway.ats.core.log.AtsConsoleLogger)1 Run (com.axway.ats.log.autodb.entities.Run)1 AddTestcaseMetainfoEvent (com.axway.ats.log.autodb.events.AddTestcaseMetainfoEvent)1 InsertMessageEvent (com.axway.ats.log.autodb.events.InsertMessageEvent)1 UpdateSuiteEvent (com.axway.ats.log.autodb.events.UpdateSuiteEvent)1 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)1 IncorrectProcessorStateException (com.axway.ats.log.autodb.exceptions.IncorrectProcessorStateException)1 LoadQueueAlreadyStartedException (com.axway.ats.log.autodb.exceptions.LoadQueueAlreadyStartedException)1 LoggingException (com.axway.ats.log.autodb.exceptions.LoggingException)1 NoSuchLoadQueueException (com.axway.ats.log.autodb.exceptions.NoSuchLoadQueueException)1 ThreadAlreadyRegisteredWithLoadQueueException (com.axway.ats.log.autodb.exceptions.ThreadAlreadyRegisteredWithLoadQueueException)1 AbstractLoggingEvent (com.axway.ats.log.autodb.model.AbstractLoggingEvent)1 CacheableEvent (com.axway.ats.log.autodb.model.CacheableEvent)1 UnknownHostException (java.net.UnknownHostException)1 Logger (org.apache.logging.log4j.Logger)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1