Search in sources :

Example 16 with Server

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

the class ConfigurationParserTest method sameServerWithTwoDifferentQueriesMergesQueries.

@Test
public void sameServerWithTwoDifferentQueriesMergesQueries() throws ValidationException {
    List<Server> existingServers = new ArrayList<Server>();
    existingServers.add(ServerFixtures.createServerWithOneQuery("example.net", "123", "toto:key=val"));
    List<Server> newServers = new ArrayList<Server>();
    newServers.add(ServerFixtures.createServerWithOneQuery("example.net", "123", "tutu:key=val"));
    List<Server> merged = configurationParser.mergeServerLists(existingServers, newServers);
    assertThat(merged).hasSize(1);
    Server mergedServer = merged.get(0);
    assertThat(mergedServer.getQueries()).hasSize(2);
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with Server

use of com.googlecode.jmxtrans.model.Server 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 18 with Server

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

the class ServerJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap map = context.getMergedJobDataMap();
    Server server = (Server) map.get(Server.class.getName());
    log.debug("+++++ Started server job: {}", server);
    try {
        jmxUtils.processServer(server);
    } catch (Exception e) {
        throw new JobExecutionException(e);
    }
    log.debug("+++++ Finished server job: {}", server);
}
Also used : JobDataMap(org.quartz.JobDataMap) JobExecutionException(org.quartz.JobExecutionException) Server(com.googlecode.jmxtrans.model.Server) JobExecutionException(org.quartz.JobExecutionException)

Example 19 with Server

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

the class ConfigurationParserTest method mergeAlreadyExistingServerDoesNotModifyList.

@Test
public void mergeAlreadyExistingServerDoesNotModifyList() throws ValidationException {
    List<Server> existingServers = new ArrayList<Server>();
    existingServers.add(dummyServer());
    List<Server> newServers = new ArrayList<Server>();
    newServers.add(dummyServer());
    List<Server> merged = configurationParser.mergeServerLists(existingServers, newServers);
    assertThat(merged).hasSize(1);
    Server mergedServer = merged.get(0);
    assertThat(mergedServer.getQueries()).hasSize(1);
}
Also used : ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 20 with Server

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

the class ServerListBuilderTest method outputWritersAreReusedOnQueries.

@Test
public void outputWritersAreReusedOnQueries() {
    Query q1 = Query.builder(dummyQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build();
    Query q2 = Query.builder(queryWithAllTypeNames()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build();
    Server server = Server.builder(serverWithNoQuery()).addQuery(q1).addQuery(q2).build();
    ImmutableList<Server> servers = new ServerListBuilder().add(singletonList(server)).build();
    assertThat(servers).hasSize(1);
    Server createdServer = servers.iterator().next();
    assertThat(createdServer.getQueries()).hasSize(2);
    Iterator<Query> queryIterator = createdServer.getQueries().iterator();
    Query query1 = queryIterator.next();
    Query query2 = queryIterator.next();
    assertThat(query1.getOutputWriterInstances()).hasSize(1);
    assertThat(query2.getOutputWriterInstances()).hasSize(1);
    assertThat(query1.getOutputWriterInstances().iterator().next()).isSameAs(query2.getOutputWriterInstances().iterator().next());
}
Also used : QueryFixtures.dummyQuery(com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery) Query(com.googlecode.jmxtrans.model.Query) ServerFixtures.serverWithNoQuery(com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery) ServerFixtures.dummyServer(com.googlecode.jmxtrans.model.ServerFixtures.dummyServer) Server(com.googlecode.jmxtrans.model.Server) Test(org.junit.Test)

Aggregations

Server (com.googlecode.jmxtrans.model.Server)22 Test (org.junit.Test)12 Query (com.googlecode.jmxtrans.model.Query)11 ServerFixtures.dummyServer (com.googlecode.jmxtrans.model.ServerFixtures.dummyServer)8 Result (com.googlecode.jmxtrans.model.Result)5 ArrayList (java.util.ArrayList)5 OutputWriter (com.googlecode.jmxtrans.model.OutputWriter)4 MBeanServer (javax.management.MBeanServer)4 ImmutableList (com.google.common.collect.ImmutableList)3 QueryFixtures.dummyQuery (com.googlecode.jmxtrans.model.QueryFixtures.dummyQuery)3 ServerFixtures.serverWithNoQuery (com.googlecode.jmxtrans.model.ServerFixtures.serverWithNoQuery)3 IOException (java.io.IOException)3 MBeanServerConnection (javax.management.MBeanServerConnection)3 JMXConnector (javax.management.remote.JMXConnector)3 LifecycleException (com.googlecode.jmxtrans.exceptions.LifecycleException)2 JmxProcess (com.googlecode.jmxtrans.model.JmxProcess)2 JobDataMap (org.quartz.JobDataMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Gson (com.google.gson.Gson)1 Injector (com.google.inject.Injector)1