Search in sources :

Example 6 with ErrorPojo

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

the class MonitoringServiceImpl method scheduleChildProcessMonitoring.

@POST
@Path("scheduleChildProcessMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleChildProcessMonitoring(@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.scheduleChildProcessMonitoring(agent, monitoringPojo.getParentProcess(), 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 child 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)

Example 7 with ErrorPojo

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

the class AgentConfigurationServiceImpl method joinTestcase.

/**
 * Tell the DbEventRequestProcess which run and test must receive the DB
 * messages/data
 */
@POST
@Path("joinTestcase")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response joinTestcase(@Context HttpServletRequest request, JoinTestcasePojo testCaseStatePojo) {
    final String caller = getCaller(request, testCaseStatePojo, false);
    ThreadsPerCaller.registerThread(caller);
    try {
        SessionData sd = getSessionData(request, testCaseStatePojo);
        RestSystemMonitor restSystemMonitor = sd.getSystemMonitor();
        // cancel all action tasks, that are started on an agent, located on
        // the current caller host.
        // current caller and the agent must have the same IP, in order for
        // the queue to be cancelled
        dbLog.debug("Cancelling all action task on the agent, that were started form the current caller.");
        MultiThreadedActionHandler.cancellAllQueuesFromAgent(ThreadsPerCaller.getCaller());
        // cancel all running system monitoring tasks on the agent
        dbLog.debug("Cancelling all running system monitoring tasks on the agent, that were started form the current caller.");
        String agent = request.getLocalAddr() + ":" + request.getLocalPort();
        restSystemMonitor.stopMonitoring(agent);
        TestCaseState newTestCaseState = new TestCaseState();
        newTestCaseState.setRunId(testCaseStatePojo.getRunId());
        newTestCaseState.setTestcaseId(testCaseStatePojo.getTestcaseId());
        newTestCaseState.setLastExecutedTestcaseId(testCaseStatePojo.getLastExecutedTestcaseId());
        // get the current state on the agent
        TestCaseState currentState = dbLog.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(newTestCaseState)) {
                dbLog.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.");
                dbLog.leaveTestCase();
            } else {
                joinToNewTescase = false;
            }
        }
        if (joinToNewTescase) {
            /* previous RestSystemMonitor instance is still in the sessionData for that caller 
                 * so we create new RestSystemMonitor for this caller
                 * */
            restSystemMonitor = new RestSystemMonitor();
            sd.setSystemMonitor(restSystemMonitor);
            dbLog.joinTestCase(newTestCaseState);
            logClassPath(newTestCaseState);
            return Response.ok("{\"status\": \"testcase joined.\"}").build();
        } else {
            return Response.ok("{\"status\": \"testcase already joined.\"}").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) TestCaseState(com.axway.ats.log.autodb.TestCaseState) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 8 with ErrorPojo

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

the class AgentConfigurationServiceImpl method initializeDbConnection.

/**
 * This method must be called, in order a connection to the desired DB to be
 * initialized. If there are any previous initialized DB connections from
 * the same caller, they will be discarded.
 */
@POST
@Path("initializeDbConnection")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response initializeDbConnection(@Context HttpServletRequest request, DbConnectionPojo dbConnectionPojo) {
    // we do some cleanup here, it is not be very resource consuming
    cleanupExpiredSessions(dbConnectionPojo);
    final String caller = getCaller(request, dbConnectionPojo, true);
    ThreadsPerCaller.registerThread(caller);
    try {
        // we have to create a new session,
        // so we call getSessionData() only for that
        getSessionData(request, dbConnectionPojo);
        // create DbAppenderConfiguration
        DbAppenderConfiguration newAppenderConfiguration = new DbAppenderConfiguration();
        newAppenderConfiguration.setHost(dbConnectionPojo.getDbHost());
        newAppenderConfiguration.setPort(dbConnectionPojo.getDbPort());
        newAppenderConfiguration.setDatabase(dbConnectionPojo.getDbName());
        newAppenderConfiguration.setUser(dbConnectionPojo.getDbUser());
        newAppenderConfiguration.setPassword(dbConnectionPojo.getDbPass());
        newAppenderConfiguration.setMode(dbConnectionPojo.getMode());
        newAppenderConfiguration.setLoggingThreshold(SystemLogLevel.toLevel(dbConnectionPojo.getLoggingThreshold()));
        newAppenderConfiguration.setMaxNumberLogEvents(dbConnectionPojo.getMaxNumberLogEvents());
        PassiveDbAppender alreadyExistingAppender = PassiveDbAppender.getCurrentInstance(caller);
        // check whether PassiveDbAppender for this caller is already registered
        if (alreadyExistingAppender != null) {
            // check if the already registered PassiveDbAppender's apenderConfiguration is NOT the same and the new one
            if (!alreadyExistingAppender.getAppenderConfig().equals(newAppenderConfiguration)) {
                /* we have a request for different DB configuration, 
                     * so remove the previous appender and append new one with the desired appender configuration
                     */
                dbLog.debug("Remove previously attached PassiveDbAppender for caller '" + caller + "'.");
                PassiveDbAppender appender = PassiveDbAppender.getCurrentInstance(caller);
                appender.stop();
                Log4j2Utils.removeAppenderFromLogger(Log4j2Utils.getRootLogger().getName(), appender.getName());
                attachPassiveDbAppender(newAppenderConfiguration, dbConnectionPojo.getTimestamp());
                dbLog.debug("Successfully attached new PassiveDbAppender for caller '" + caller + "'.");
            }
        } else {
            attachPassiveDbAppender(newAppenderConfiguration, dbConnectionPojo.getTimestamp());
        }
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
    String uid = dbConnectionPojo.getUid();
    String agentVersion = AtsVersion.getAtsVersion();
    return Response.ok("{\"" + ApplicationContext.ATS_UID_SESSION_TOKEN + "\": " + "\"" + uid + "\",\"" + "agent_version" + "\": " + "\"" + agentVersion + "\"}").build();
}
Also used : ErrorPojo(com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo) DbAppenderConfiguration(com.axway.ats.log.autodb.DbAppenderConfiguration) PassiveDbAppender(com.axway.ats.log.appenders.PassiveDbAppender) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 9 with ErrorPojo

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

the class MonitoringServiceImpl method startMonitoring.

@POST
@Path("startMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response startMonitoring(@Context HttpServletRequest request, StartMonitoringPojo 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();
        // calculate the time offset between the agent and the test executor
        long timeOffset = System.currentTimeMillis() - monitoringPojo.getStartTimestamp();
        restSystemMonitor.startMonitoring(agent, monitoringPojo.getStartTimestamp(), monitoringPojo.getPollingInterval(), timeOffset);
        return Response.ok("{\"status\":\"monitoring started on every " + monitoringPojo.getPollingInterval() + " seconds.\"}").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 10 with ErrorPojo

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

the class MonitoringServiceImpl method scheduleJvmMonitoring.

@POST
@Path("scheduleJvmMonitoring")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response scheduleJvmMonitoring(@Context HttpServletRequest request, ScheduleJvmMonitoringPojo 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.scheduleJvmMonitoring(agent, monitoringPojo.getJvmPort(), (monitoringPojo.getAlias() == null) ? "" : monitoringPojo.getAlias(), monitoringPojo.getJvmReadingTypes());
        restSystemMonitor.setScheduledReadingTypes(readings);
    } catch (Exception e) {
        return Response.serverError().entity(new ErrorPojo(e)).build();
    } finally {
        ThreadsPerCaller.unregisterThread();
    }
    String statusMessage = "{\"status \": \"scheduled 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)

Aggregations

ErrorPojo (com.axway.ats.agent.webapp.restservice.model.pojo.ErrorPojo)12 POST (javax.ws.rs.POST)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 SessionData (com.axway.ats.agent.webapp.restservice.model.SessionData)11 Consumes (javax.ws.rs.Consumes)11 ReadingBean (com.axway.ats.common.performance.monitor.beans.ReadingBean)6 PassiveDbAppender (com.axway.ats.log.appenders.PassiveDbAppender)1 DbAppenderConfiguration (com.axway.ats.log.autodb.DbAppenderConfiguration)1 TestCaseState (com.axway.ats.log.autodb.TestCaseState)1