Search in sources :

Example 1 with RestSystemMonitor

use of com.axway.ats.agent.webapp.restservice.RestSystemMonitor in project ats-framework by Axway.

the class AgentWsImpl method onTestStart.

/**
 * Web method for starting a testcase
 *
 * @param testCaseState contains the id of the test case in the logging system (if passive logging is to be used, otherwise pass null)
 * @throws AgentException if any error occurs
 */
/* TODO: 
     * add possibility for the user to set whether all queues from this agent have to be stopped 
     * each time a new run, from a different caller to the same agent are started
     */
@WebMethod
public void onTestStart(@WebParam(name = "testCaseState") TestCaseState testCaseState) throws AgentException {
    if (testCaseState == null) {
        // the user has not initialized our DB appender on the Test Executor side
        return;
    }
    final String caller = getCaller();
    ThreadsPerCaller.registerThread(caller);
    try {
        // cancel all action tasks, that are started on an agent, locate on the current caller host.
        // current caller and the agent must have the same IP, in order for queue to be cancelled
        MultiThreadedActionHandler.cancellAllQueuesFromAgent(caller);
        // cancel all monitoring, started previously by the current caller
        SessionData sd = BaseRestServiceImpl.sessions.get(caller);
        if (sd != null) {
            RestSystemMonitor sysMon = sd.getSystemMonitor();
            if (sysMon != null) {
                log.info("Stopping previously started monitoring from caller '" + caller + "' ...");
                sysMon.stopMonitoring(getAgentHostAddress());
            }
        }
        // get the current state on the remote machine
        TestCaseState currentState = log.getCurrentTestCaseState();
        boolean joinToNewTescase = true;
        if (currentState != null && currentState.isInitialized()) {
            /* This agent is already configured.
                 *
                 * Now check if the state is the same as the new one, this would mean we are trying to
                 * configure this agent for second time.
                 * This is normal as we get here when Test Executor or another agent calls this agent for first time.
                 *
                 * If the state is different, we hit an error which means this agent did not get On Test End event
                 * for the previous test case.
                 */
            if (!currentState.equals(testCaseState)) {
                log.error("This test appears to be aborted by the user on the test executor side, but it kept running on the agent side." + " Now we cancel any further logging from the agent.");
                log.leaveTestCase();
            } else {
                joinToNewTescase = false;
            }
        }
        if (joinToNewTescase) {
            // connect to the new test case
            log.joinTestCase(testCaseState);
            // take care of chained ATS agents(if there are any)
            TestcaseStateEventsDispacher.getInstance().onTestStart();
        }
        logClassPath(testCaseState);
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
}
Also used : RestSystemMonitor(com.axway.ats.agent.webapp.restservice.RestSystemMonitor) SessionData(com.axway.ats.agent.webapp.restservice.model.SessionData) TestCaseState(com.axway.ats.log.autodb.TestCaseState) WebMethod(javax.jws.WebMethod)

Aggregations

RestSystemMonitor (com.axway.ats.agent.webapp.restservice.RestSystemMonitor)1 SessionData (com.axway.ats.agent.webapp.restservice.model.SessionData)1 TestCaseState (com.axway.ats.log.autodb.TestCaseState)1 WebMethod (javax.jws.WebMethod)1