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