use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class BaseOutputWriterTests method booleanValuesAreNotTransformedToNumber.
@Test
public void booleanValuesAreNotTransformedToNumber() throws Exception {
final ArrayList<Result> processedResults = Lists.newArrayList();
BaseOutputWriter outputWriter = new BaseOutputWriter(ImmutableList.<String>of(), false, 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(true);
assertThat(processedResult.getValues().get("false")).isEqualTo(false);
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class JsonUtilsTest method loadFromFile.
private void loadFromFile(String file) throws URISyntaxException, IOException, MalformedObjectNameException {
File input = new File(JsonUtilsTest.class.getResource("/" + file).toURI());
JmxProcess process = jsonUtils.parseProcess(input);
assertThat(process.getName()).isEqualTo(file);
Server server = process.getServers().get(0);
assertThat(server.getPort()).isEqualTo("1099");
assertThat(server.getNumQueryThreads()).isEqualTo(2);
Optional<Query> queryOptional = from(server.getQueries()).firstMatch(new ByObj("java.lang:type=Memory"));
assertThat(queryOptional.isPresent()).isTrue();
assertThat(queryOptional.get().getAttr().get(0)).isEqualTo("HeapMemoryUsage");
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class JmxTransformer method scheduleJob.
private void scheduleJob(Server server) throws ParseException, SchedulerException {
String name = server.getHost() + ":" + server.getPort() + "-" + System.currentTimeMillis() + "-" + RandomStringUtils.randomNumeric(10);
JobDetail jd = new JobDetail(name, "ServerJob", ServerJob.class);
JobDataMap map = new JobDataMap();
map.put(Server.class.getName(), server);
jd.setJobDataMap(map);
Trigger trigger;
if ((server.getCronExpression() != null) && CronExpression.isValidExpression(server.getCronExpression())) {
trigger = new CronTrigger();
((CronTrigger) trigger).setCronExpression(server.getCronExpression());
trigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
trigger.setStartTime(computeSpreadStartDate(configuration.getRunPeriod()));
} else {
int runPeriod = configuration.getRunPeriod();
if (server.getRunPeriodSeconds() != null)
runPeriod = server.getRunPeriodSeconds();
Trigger minuteTrigger = TriggerUtils.makeSecondlyTrigger(runPeriod);
minuteTrigger.setName(server.getHost() + ":" + server.getPort() + "-" + Long.toString(System.currentTimeMillis()));
minuteTrigger.setStartTime(computeSpreadStartDate(runPeriod));
trigger = minuteTrigger;
// TODO replace Quartz with a ScheduledExecutorService
}
serverScheduler.scheduleJob(jd, trigger);
if (log.isDebugEnabled()) {
log.debug("Scheduled job: " + jd.getName() + " for server: " + server);
}
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class ConfigurationParser method mergeServerLists.
/**
* Merges two lists of servers (and their queries). Based on the equality of
* both sets of objects. Public for testing purposes.
* @param secondList
* @param firstList
*/
// FIXME: the params for this method should be Set<Server> as there are multiple assumptions that they are unique
@CheckReturnValue
@VisibleForTesting
ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) {
ImmutableList.Builder<Server> results = ImmutableList.builder();
List<Server> toProcess = new ArrayList<>(secondList);
for (Server firstServer : firstList) {
if (toProcess.contains(firstServer)) {
Server found = toProcess.get(secondList.indexOf(firstServer));
results.add(merge(firstServer, found));
// remove server as it is already merged
toProcess.remove(found);
} else {
results.add(firstServer);
}
}
// add servers from the second list that are not in the first one
results.addAll(toProcess);
return results.build();
}
use of com.googlecode.jmxtrans.model.Server in project jmxtrans by jmxtrans.
the class ServerSchedulerTest method testScheduleWhenRunFails.
@Test
public void testScheduleWhenRunFails() throws InterruptedException {
// Given
Server server = Server.builder().setRunPeriodSeconds(2).setPid("2").setPool(mock(KeyedObjectPool.class)).addQueries(sampleQueries()).build();
ThreadPoolExecutor executor = queryExecutorRepository.initExecutor(server);
when(executor.submit(any(Runnable.class))).thenThrow(new IllegalStateException("Command failed"));
// When
serverScheduler.schedule(server);
// Then
verify(executor, timeout(6000L).atLeast(2)).submit(any(Runnable.class));
}
Aggregations