Search in sources :

Example 1 with JmxTransServer

use of io.strimzi.operator.cluster.model.components.JmxTransServer 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;
}
Also used : ArrayList(java.util.ArrayList) JmxTransServer(io.strimzi.operator.cluster.model.components.JmxTransServer) JmxTransOutputDefinitionTemplate(io.strimzi.api.kafka.model.template.JmxTransOutputDefinitionTemplate) JmxTransOutputWriter(io.strimzi.operator.cluster.model.components.JmxTransOutputWriter) JmxTransQueries(io.strimzi.operator.cluster.model.components.JmxTransQueries) JmxTransQueryTemplate(io.strimzi.api.kafka.model.template.JmxTransQueryTemplate)

Example 2 with JmxTransServer

use of io.strimzi.operator.cluster.model.components.JmxTransServer 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);
    }
}
Also used : ArrayList(java.util.ArrayList) JmxTransServers(io.strimzi.operator.cluster.model.components.JmxTransServers) JmxTransServer(io.strimzi.operator.cluster.model.components.JmxTransServer) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) JmxTransQueries(io.strimzi.operator.cluster.model.components.JmxTransQueries) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with JmxTransServer

use of io.strimzi.operator.cluster.model.components.JmxTransServer in project strimzi by strimzi.

the class JmxTrans method jmxTransServer.

/**
 * Generates the server configuration for given Kafka broker
 *
 * @param queries           List of Queries which should be used for this broker
 * @param brokerServiceName Address of the service where to connect to the broker
 *
 * @return  JMX Trans server instance for given Kafka broker
 */
private JmxTransServer jmxTransServer(List<JmxTransQueries> queries, String brokerServiceName) {
    JmxTransServer server = new JmxTransServer();
    server.setHost(brokerServiceName);
    server.setPort(AbstractModel.JMX_PORT);
    server.setQueries(queries);
    if (isJmxAuthenticated) {
        server.setUsername("${kafka.username}");
        server.setPassword("${kafka.password}");
    }
    return server;
}
Also used : JmxTransServer(io.strimzi.operator.cluster.model.components.JmxTransServer)

Example 4 with JmxTransServer

use of io.strimzi.operator.cluster.model.components.JmxTransServer 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);
    }
}
Also used : ArrayList(java.util.ArrayList) JmxTransServers(io.strimzi.operator.cluster.model.components.JmxTransServers) JmxTransServer(io.strimzi.operator.cluster.model.components.JmxTransServer) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) JmxTransQueries(io.strimzi.operator.cluster.model.components.JmxTransQueries) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with JmxTransServer

use of io.strimzi.operator.cluster.model.components.JmxTransServer in project strimzi-kafka-operator by strimzi.

the class JmxTrans method jmxTransServer.

/**
 * Generates the server configuration for given Kafka broker
 *
 * @param queries           List of Queries which should be used for this broker
 * @param brokerServiceName Address of the service where to connect to the broker
 *
 * @return  JMX Trans server instance for given Kafka broker
 */
private JmxTransServer jmxTransServer(List<JmxTransQueries> queries, String brokerServiceName) {
    JmxTransServer server = new JmxTransServer();
    server.setHost(brokerServiceName);
    server.setPort(AbstractModel.JMX_PORT);
    server.setQueries(queries);
    if (isJmxAuthenticated) {
        server.setUsername("${kafka.username}");
        server.setPassword("${kafka.password}");
    }
    return server;
}
Also used : JmxTransServer(io.strimzi.operator.cluster.model.components.JmxTransServer)

Aggregations

JmxTransServer (io.strimzi.operator.cluster.model.components.JmxTransServer)8 JmxTransQueries (io.strimzi.operator.cluster.model.components.JmxTransQueries)4 ArrayList (java.util.ArrayList)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 JmxTransOutputDefinitionTemplate (io.strimzi.api.kafka.model.template.JmxTransOutputDefinitionTemplate)2 JmxTransQueryTemplate (io.strimzi.api.kafka.model.template.JmxTransQueryTemplate)2 JmxTransOutputWriter (io.strimzi.operator.cluster.model.components.JmxTransOutputWriter)2 JmxTransServers (io.strimzi.operator.cluster.model.components.JmxTransServers)2 ParallelTest (io.strimzi.test.annotations.ParallelTest)2 JsonObject (io.vertx.core.json.JsonObject)2