Search in sources :

Example 1 with ValidationException

use of com.googlecode.jmxtrans.model.ValidationException in project jmxtrans by jmxtrans.

the class JmxTransformer method processServersIntoJobs.

/**
	 * Processes all the Servers into Job's
	 * <p/>
	 * Needs to be called after processFiles()
	 */
private void processServersIntoJobs() throws LifecycleException {
    for (Server server : this.masterServersList) {
        try {
            // need to inject the poolMap
            for (Query query : server.getQueries()) {
                for (OutputWriter writer : query.getOutputWriterInstances()) {
                    writer.start();
                }
            }
            // Now validate the setup of each of the OutputWriter's per
            // query.
            this.validateSetup(server, server.getQueries());
            // Now schedule the jobs for execution.
            this.scheduleJob(server);
        } catch (ParseException ex) {
            throw new LifecycleException("Error parsing cron expression: " + server.getCronExpression(), ex);
        } catch (SchedulerException ex) {
            throw new LifecycleException("Error scheduling job for server: " + server, ex);
        } catch (ValidationException ex) {
            throw new LifecycleException("Error validating json setup for query", ex);
        }
    }
}
Also used : LifecycleException(com.googlecode.jmxtrans.exceptions.LifecycleException) SchedulerException(org.quartz.SchedulerException) ValidationException(com.googlecode.jmxtrans.model.ValidationException) MBeanServer(javax.management.MBeanServer) Server(com.googlecode.jmxtrans.model.Server) Query(com.googlecode.jmxtrans.model.Query) ParseException(java.text.ParseException) OutputWriter(com.googlecode.jmxtrans.model.OutputWriter)

Example 2 with ValidationException

use of com.googlecode.jmxtrans.model.ValidationException in project jmxtrans by jmxtrans.

the class KeyOutWriter method validateSetup.

/**
	 * Creates the logging
	 */
@Override
public void validateSetup(Server server, Query query) throws ValidationException {
    // Check if we've already created a logger for this file. If so, use it.
    if (loggers.containsKey(outputFile)) {
        logger = loggers.get(outputFile);
        return;
    }
    // need to create a logger
    try {
        logger = initLogger(outputFile);
        loggers.put(outputFile, logger);
    } catch (IOException e) {
        throw new ValidationException("Failed to setup log4j", query, e);
    }
}
Also used : ValidationException(com.googlecode.jmxtrans.model.ValidationException) IOException(java.io.IOException)

Example 3 with ValidationException

use of com.googlecode.jmxtrans.model.ValidationException in project jmxtrans by jmxtrans.

the class NagiosWriter method checkFile.

/**
	 * Creates the logging. Nagios doesn't start if the external command pipe
	 * exists, so we write to /dev/null until we have it available.
	 * From the official documentation:
	 * <blockquote>
	 * The external command file is implemented as a named pipe (FIFO),
	 * which is created when Nagios starts and removed when it shuts down.
	 * If the file exists when Nagios starts,
	 * the Nagios process will terminate with an error message.
	 * http://nagios.sourceforge.net/docs/3_0/configmain.html#command_file
	 * </blockquote>
	 */
public void checkFile(Query query) throws ValidationException {
    if (!outputFile.exists()) {
        if (loggers.containsKey("/dev/null")) {
            logger = loggers.get("/dev/null");
        } else {
            try {
                logger = initLogger("/dev/null");
                loggers.put("/dev/null", logger);
            } catch (IOException e) {
                throw new ValidationException("Failed to setup log4j", query, e);
            }
        }
        if (loggers.containsKey(outputFile.getAbsolutePath())) {
            loggers.remove(outputFile.getAbsolutePath());
        }
        return;
    } else if (loggers.containsKey(outputFile.getAbsolutePath())) {
        logger = loggers.get(outputFile.getAbsolutePath());
        return;
    }
    try {
        logger = initLogger(outputFile.getAbsolutePath());
        loggers.put(outputFile.getAbsolutePath(), logger);
    } catch (IOException e) {
        throw new ValidationException("Failed to setup log4j", query, e);
    }
}
Also used : ValidationException(com.googlecode.jmxtrans.model.ValidationException) IOException(java.io.IOException)

Aggregations

ValidationException (com.googlecode.jmxtrans.model.ValidationException)3 IOException (java.io.IOException)2 LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)1 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)1 Query (com.googlecode.jmxtrans.model.Query)1 Server (com.googlecode.jmxtrans.model.Server)1 ParseException (java.text.ParseException)1 MBeanServer (javax.management.MBeanServer)1 SchedulerException (org.quartz.SchedulerException)1