Search in sources :

Example 1 with SessionData

use of com.axway.ats.agent.webapp.restservice.model.SessionData 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)

Example 2 with SessionData

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

the class MonitoringServiceImpl method scheduleCustomJvmMonitoring.

@POST
@Path("scheduleCustomJvmMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleCustomJvmMonitoring(@Context HttpServletRequest request, ScheduleCustomJvmMonitoringPojo monitoringPojo) {
    final String caller = getCaller(request, monitoringPojo, false);
    ThreadsPerCaller.registerThread(caller);
    try {
        SessionData sd = getSessionData(request, monitoringPojo);
        RestSystemMonitor restSystemMonitor = sd.getSystemMonitor();
        String agent = request.getLocalAddr() + ":" + request.getLocalPort();
        Set<ReadingBean> readings = restSystemMonitor.scheduleCustomJvmMonitoring(agent, monitoringPojo.getJmxPort(), monitoringPojo.getAlias(), monitoringPojo.getMbeanName(), monitoringPojo.getUnit(), monitoringPojo.getMbeanAttributes());
        restSystemMonitor.setScheduledReadingTypes(readings);
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
    String statusMessage = "{\"status \": \"scheduled custom JVM monitoring with parameters '" + monitoringPojo.toString() + "'\"}";
    return Response.ok(statusMessage).build();
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) ErrorPojo(com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo) SessionData(com.axway.ats.agent.webapp.restservice.model.SessionData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with SessionData

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

the class MonitoringServiceImpl method stopMonitoring.

@POST
@Path("stopMonitoring")
@Produces(MediaType.APPLICATION_JSON)
public Response stopMonitoring(@Context HttpServletRequest request, BasePojo basePojo) {
    final String caller = getCaller(request, basePojo, false);
    ThreadsPerCaller.registerThread(caller);
    try {
        SessionData sd = getSessionData(request, basePojo);
        RestSystemMonitor restSystemMonitor = sd.getSystemMonitor();
        String agent = request.getLocalAddr() + ":" + request.getLocalPort();
        restSystemMonitor.stopMonitoring(agent);
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
    return Response.ok("{\"status\":\"monitoring stopped.\"}").build();
}
Also used : ErrorPojo(com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo) SessionData(com.axway.ats.agent.webapp.restservice.model.SessionData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 4 with SessionData

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

the class MonitoringServiceImpl method initializeMonitoring.

/**
 * Initialize Monitoring context Must be called before calling any
 * scheduleXYZMonitoring REST method
 */
@POST
@Path("initializeMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response initializeMonitoring(@Context HttpServletRequest request, BasePojo basePojo) {
    final String caller = getCaller(request, basePojo, false);
    ThreadsPerCaller.registerThread(caller);
    try {
        SessionData sd = getSessionData(request, basePojo);
        RestSystemMonitor restSystemMonitor = sd.getSystemMonitor();
        String agent = request.getLocalAddr() + ":" + request.getLocalPort();
        restSystemMonitor.initializeMonitoringContext(agent);
        return Response.ok("{\"status\":\"monitoring context initialized.\"}").build();
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
}
Also used : ErrorPojo(com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo) SessionData(com.axway.ats.agent.webapp.restservice.model.SessionData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 5 with SessionData

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

the class MonitoringServiceImpl method scheduleProcessMonitoring.

@POST
@Path("scheduleProcessMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleProcessMonitoring(@Context HttpServletRequest request, ScheduleProcessMonitoringPojo monitoringPojo) {
    final String caller = getCaller(request, monitoringPojo, false);
    ThreadsPerCaller.registerThread(caller);
    try {
        SessionData sd = getSessionData(request, monitoringPojo);
        RestSystemMonitor restSystemMonitor = sd.getSystemMonitor();
        String agent = request.getLocalAddr() + ":" + request.getLocalPort();
        Set<ReadingBean> readings = restSystemMonitor.scheduleProcessMonitoring(agent, monitoringPojo.getProcessPattern(), monitoringPojo.getProcessAlias(), monitoringPojo.getProcessUsername(), monitoringPojo.getProcessReadingTypes());
        restSystemMonitor.setScheduledReadingTypes(readings);
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
    String statusMessage = "{\"status \": \"scheduled process monitoring with parameters '" + monitoringPojo.toString() + "'\"}";
    return Response.ok(statusMessage).build();
}
Also used : ReadingBean(com.axway.ats.common.performance.monitor.beans.ReadingBean) ErrorPojo(com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo) SessionData(com.axway.ats.agent.webapp.restservice.model.SessionData) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

SessionData (com.axway.ats.agent.webapp.restservice.model.SessionData)13 ErrorPojo (com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo)11 POST (javax.ws.rs.POST)11 Path (javax.ws.rs.Path)11 Produces (javax.ws.rs.Produces)11 Consumes (javax.ws.rs.Consumes)10 ReadingBean (com.axway.ats.common.performance.monitor.beans.ReadingBean)6 TestCaseState (com.axway.ats.log.autodb.TestCaseState)2 RestSystemMonitor (com.axway.ats.agent.webapp.restservice.RestSystemMonitor)1 SessionNotFoundException (com.axway.ats.agent.webapp.restservice.exceptions.SessionNotFoundException)1 WebMethod (javax.jws.WebMethod)1