use of com.googlecode.jmxtrans.model.Query in project jmxtrans by jmxtrans.
the class BaseOutputWriterTests method booleanValuesAreTransformedToNumber.
@Test
public void booleanValuesAreTransformedToNumber() throws Exception {
final ArrayList<Result> processedResults = Lists.newArrayList();
BaseOutputWriter outputWriter = new BaseOutputWriter(ImmutableList.<String>of(), true, false, Maps.<String, Object>newHashMap()) {
@Override
protected void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception {
processedResults.addAll(results);
}
@Override
public void validateSetup(Server server, Query query) throws ValidationException {
}
};
Result result = new Result(0, "", "", "", "", "", ImmutableMap.<String, Object>of("true", true, "false", false));
outputWriter.doWrite(null, null, ImmutableList.of(result));
assertThat(processedResults).hasSize(1);
Result processedResult = processedResults.get(0);
assertThat(processedResult.getValues().get("true")).isEqualTo(1);
assertThat(processedResult.getValues().get("false")).isEqualTo(0);
}
use of com.googlecode.jmxtrans.model.Query 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.Query 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());
}
use of com.googlecode.jmxtrans.model.Query in project jmxtrans by jmxtrans.
the class ServerListBuilderTest method outputWritersAreReusedOnServersAndQueries.
@Test
public void outputWritersAreReusedOnServersAndQueries() {
Server server = Server.builder(serverWithNoQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).addQuery(Query.builder(dummyQuery()).addOutputWriterFactory(new DummyOutputWriterFactory("output1")).build()).build();
ImmutableList<Server> servers = new ServerListBuilder().add(singletonList(server)).build();
Server createdServer = servers.iterator().next();
Query createdQuery = createdServer.getQueries().iterator().next();
assertThat(createdQuery.getOutputWriterInstances()).hasSize(1);
assertThat(createdServer.getOutputWriters().iterator().next()).isSameAs(createdQuery.getOutputWriterInstances().iterator().next());
}
use of com.googlecode.jmxtrans.model.Query in project jmxtrans by jmxtrans.
the class JmxTransformer method stopWriterAndClearMasterServerList.
/**
* Shut down the output writers and clear the master server list
* Used both during shutdown and when re-reading config files
*/
private void stopWriterAndClearMasterServerList() {
for (Server server : this.masterServersList) {
for (OutputWriter writer : server.getOutputWriters()) {
try {
writer.close();
} catch (LifecycleException ex) {
log.error("Eror stopping writer: {}", writer);
}
}
for (Query query : server.getQueries()) {
for (OutputWriter writer : query.getOutputWriterInstances()) {
try {
writer.close();
log.debug("Stopped writer: {} for query: {}", writer, query);
} catch (LifecycleException ex) {
log.error("Error stopping writer: {} for query: {}", writer, query, ex);
}
}
}
}
this.masterServersList = ImmutableList.of();
}
Aggregations