Search in sources :

Example 11 with SessionData

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

the class MonitoringServiceImpl method scheduleSystemMonitoring.

@POST
@Path("scheduleSystemMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleSystemMonitoring(@Context HttpServletRequest request, ScheduleSystemMonitoringPojo 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.scheduleSystemMonitoring(agent, monitoringPojo.getReadings());
        restSystemMonitor.setScheduledReadingTypes(readings);
        return Response.ok("{\"status\":\"scheduled system monitoring for readings '" + Arrays.toString(monitoringPojo.getReadings()) + "'\"}").build();
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
}
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 12 with SessionData

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

the class MonitoringServiceImpl method scheduleMonitoring.

@POST
@Path("scheduleMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleMonitoring(@Context HttpServletRequest request, ScheduleMonitoringPojo 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.scheduleMonitoring(agent, monitoringPojo.getReading(), monitoringPojo.getReadingParametersAsMap());
        restSystemMonitor.setScheduledReadingTypes(readings);
        String readingParametersAsString = entrySetAsString(monitoringPojo.getReadingParametersAsMap());
        return Response.ok("{\"status\":\"scheduled monitoring for reading '" + monitoringPojo.getReading() + "' and readingParameters '" + readingParametersAsString + "'\"}").build();
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
}
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 13 with SessionData

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

the class BaseRestServiceImpl method getSessionData.

protected SessionData getSessionData(HttpServletRequest request, BasePojo basePojo) throws Exception {
    String uid = null;
    SessionData sd = null;
    uid = getUid(request, basePojo, false);
    sd = sessions.get(uid);
    if (sd == null) {
        /*
             * new Session (SessionData) is created when:
             * <ul>
             * <li>initializeDbConnection is called - this is done, when monitoring is requested by REST API</li>
             * <li>initializeMonitoring is called - this is done when the ATS Framework is sending a system monitoring operation</li> 
             * </ul>
             *  
             * */
        if (request.getRequestURI().contains("initializeDbConnection") || request.getRequestURI().contains("initializeMonitoring")) {
            // create new session
            sd = new SessionData();
            sessions.put(uid, sd);
        } else {
            throw new SessionNotFoundException("Could not obtain session with uid '" + uid + "'. It is possible that the agent had been restarted so no sessions are available");
        }
    }
    sd.updateLastUsedFlag();
    return sd;
}
Also used : SessionData(com.axway.ats.agent.webapp.restservice.model.SessionData) SessionNotFoundException(com.axway.ats.agent.webapp.restservice.exceptions.SessionNotFoundException)

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