use of io.strimzi.operator.cluster.model.components.JmxTransQueries in project strimzi by strimzi.
the class JmxTrans method convertSpecToServers.
private JmxTransServer convertSpecToServers(JmxTransSpec spec, String brokerServiceName) {
JmxTransServer server = new JmxTransServer();
server.setHost(brokerServiceName);
server.setPort(AbstractModel.JMX_PORT);
if (isJmxAuthenticated()) {
server.setUsername("${kafka.username}");
server.setPassword("${kafka.password}");
}
List<JmxTransQueries> queries = new ArrayList<>();
for (JmxTransQueryTemplate queryTemplate : spec.getKafkaQueries()) {
JmxTransQueries query = new JmxTransQueries();
query.setObj(queryTemplate.getTargetMBean());
query.setAttr(queryTemplate.getAttributes());
query.setOutputWriters(new ArrayList<>());
for (JmxTransOutputDefinitionTemplate outputDefinitionTemplate : spec.getOutputDefinitions()) {
if (queryTemplate.getOutputs().contains(outputDefinitionTemplate.getName())) {
JmxTransOutputWriter outputWriter = new JmxTransOutputWriter();
outputWriter.setAtClass(outputDefinitionTemplate.getOutputType());
if (outputDefinitionTemplate.getHost() != null) {
outputWriter.setHost(outputDefinitionTemplate.getHost());
}
if (outputDefinitionTemplate.getPort() != null) {
outputWriter.setPort(outputDefinitionTemplate.getPort());
}
if (outputDefinitionTemplate.getFlushDelayInSeconds() != null) {
outputWriter.setFlushDelayInSeconds(outputDefinitionTemplate.getFlushDelayInSeconds());
}
outputWriter.setTypeNames(outputDefinitionTemplate.getTypeNames());
query.getOutputWriters().add(outputWriter);
}
}
queries.add(query);
}
server.setQueries(queries);
return server;
}
use of io.strimzi.operator.cluster.model.components.JmxTransQueries in project strimzi by strimzi.
the class JmxTrans method generateJMXConfig.
/**
* Generates the string'd config that the JmxTrans deployment needs to run. It is configured by the user in the yaml
* and this method will convert that into the config the JmxTrans understands.
*
* @return the jmx trans config file that targets each broker
*/
private String generateJMXConfig() {
List<JmxTransQueries> queries = jmxTransQueries();
List<JmxTransServer> servers = new ArrayList<>(numberOfBrokers);
String headlessService = KafkaResources.brokersServiceName(cluster);
for (int brokerNumber = 0; brokerNumber < numberOfBrokers; brokerNumber++) {
String brokerServiceName = KafkaResources.kafkaStatefulSetName(cluster) + "-" + brokerNumber + "." + headlessService;
servers.add(jmxTransServer(queries, brokerServiceName));
}
JmxTransServers jmxTransConfiguration = new JmxTransServers();
jmxTransConfiguration.setServers(servers);
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(jmxTransConfiguration);
} catch (JsonProcessingException e) {
LOGGER.errorCr(reconciliation, "Failed to convert JMX Trans configuration to JSON", e);
throw new RuntimeException("Failed to convert JMX Trans configuration to JSON", e);
}
}
use of io.strimzi.operator.cluster.model.components.JmxTransQueries in project strimzi-kafka-operator by strimzi.
the class JmxTrans method generateJMXConfig.
/**
* Generates the string'd config that the JmxTrans deployment needs to run. It is configured by the user in the yaml
* and this method will convert that into the config the JmxTrans understands.
*
* @return the jmx trans config file that targets each broker
*/
private String generateJMXConfig() {
List<JmxTransQueries> queries = jmxTransQueries();
List<JmxTransServer> servers = new ArrayList<>(numberOfBrokers);
String headlessService = KafkaResources.brokersServiceName(cluster);
for (int brokerNumber = 0; brokerNumber < numberOfBrokers; brokerNumber++) {
String brokerServiceName = KafkaResources.kafkaStatefulSetName(cluster) + "-" + brokerNumber + "." + headlessService;
servers.add(jmxTransServer(queries, brokerServiceName));
}
JmxTransServers jmxTransConfiguration = new JmxTransServers();
jmxTransConfiguration.setServers(servers);
try {
ObjectMapper mapper = new ObjectMapper();
return mapper.writeValueAsString(jmxTransConfiguration);
} catch (JsonProcessingException e) {
LOGGER.errorCr(reconciliation, "Failed to convert JMX Trans configuration to JSON", e);
throw new RuntimeException("Failed to convert JMX Trans configuration to JSON", e);
}
}
use of io.strimzi.operator.cluster.model.components.JmxTransQueries in project strimzi-kafka-operator by strimzi.
the class JmxTrans method jmxTransQueries.
/**
* Generates the queries for the JMX Trans configuration
*
* @return List with JMX Trans queries
*/
private List<JmxTransQueries> jmxTransQueries() {
List<JmxTransQueries> queries = new ArrayList<>(kafkaQueries.size());
for (JmxTransQueryTemplate queryTemplate : kafkaQueries) {
JmxTransQueries query = new JmxTransQueries();
query.setObj(queryTemplate.getTargetMBean());
query.setAttr(queryTemplate.getAttributes());
query.setOutputWriters(new ArrayList<>());
for (JmxTransOutputDefinitionTemplate outputDefinitionTemplate : outputDefinitions) {
if (queryTemplate.getOutputs().contains(outputDefinitionTemplate.getName())) {
JmxTransOutputWriter outputWriter = new JmxTransOutputWriter();
outputWriter.setAtClass(outputDefinitionTemplate.getOutputType());
if (outputDefinitionTemplate.getHost() != null) {
outputWriter.setHost(outputDefinitionTemplate.getHost());
}
if (outputDefinitionTemplate.getPort() != null) {
outputWriter.setPort(outputDefinitionTemplate.getPort());
}
if (outputDefinitionTemplate.getFlushDelayInSeconds() != null) {
outputWriter.setFlushDelayInSeconds(outputDefinitionTemplate.getFlushDelayInSeconds());
}
outputWriter.setTypeNames(outputDefinitionTemplate.getTypeNames());
query.getOutputWriters().add(outputWriter);
}
}
queries.add(query);
}
return queries;
}
use of io.strimzi.operator.cluster.model.components.JmxTransQueries in project strimzi-kafka-operator by strimzi.
the class JmxTransTest method testQueriesDeserialization.
@ParallelTest
public void testQueriesDeserialization() {
JmxTransOutputWriter outputWriter = new JmxTransOutputWriter();
outputWriter.setAtClass("class");
outputWriter.setHost("host");
outputWriter.setPort(9999);
outputWriter.setFlushDelayInSeconds(1);
outputWriter.setTypeNames(Collections.singletonList("SingleType"));
JmxTransQueries queries = new JmxTransQueries();
queries.setObj("object");
queries.setAttr(Collections.singletonList("attribute"));
queries.setOutputWriters(Collections.singletonList(outputWriter));
JsonObject targetJson = JsonObject.mapFrom(queries);
JsonObject outputWriterJson = targetJson.getJsonArray("outputWriters").getJsonObject(0);
assertThat(targetJson.getString("obj"), is("object"));
assertThat(targetJson.getJsonArray("attr").size(), is(1));
assertThat(targetJson.getJsonArray("attr").getString(0), is("attribute"));
assertThat(outputWriterJson.getString("host"), is("host"));
assertThat(outputWriterJson.getString("@class"), is("class"));
assertThat(outputWriterJson.getInteger("port"), is(9999));
assertThat(outputWriterJson.getInteger("flushDelayInSeconds"), is(1));
assertThat(outputWriterJson.getJsonArray("typeNames").size(), is(1));
assertThat(outputWriterJson.getJsonArray("typeNames").getList().get(0), is("SingleType"));
}
Aggregations