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();
}
}
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();
}
}
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;
}
Aggregations