Puppet Class: confluent::kafka::broker

Inherits:
confluent::params
Defined in:
manifests/kafka/broker.pp

Overview

Class is used to install and configure an Apache Kafka Broker using the Confluent installation packages.

Examples:

Installation through class.

class{'confluent::kafka::broker':
  broker_id => '1',
  config => {
    'zookeeper.connect' => {
      'value' => 'zookeeper-01.custenborder.com:2181,zookeeper-02.custenborder.com:2181,zookeeper-03.custenborder.com:2181'
    },
  },
  environment_settings => {
    'KAFKA_HEAP_OPTS' => {
      'value' => '-Xmx4000M'
    }
  }
}

Hiera based installation

include ::confluent::kafka::broker

confluent::kafka::broker::broker_id: '1'
confluent::kafka::broker::config:
  zookeeper.connect:
    value: 'zookeeper-01.example.com:2181,zookeeper-02.example.com:2181,zookeeper-03.example.com:2181'
  log.dirs:
    value: /var/lib/kafka
  advertised.listeners:
    value: "PLAINTEXT://%{::fqdn}:9092"
  delete.topic.enable:
    value: true
  auto.create.topics.enable:
    value: false
confluent::kafka::broker::environment_settings:
  KAFKA_HEAP_OPTS:
    value: -Xmx1024M

Parameters:

  • broker_id (Any)

    broker.id of the Kafka broker.

  • config (Any) (defaults to: { })

    Hash of configuration values.

  • environment_settings (Any) (defaults to: { })

    Hash of environment variables to set for the Kafka scripts.

  • config_path (Any) (defaults to: $::confluent::params::kafka_config_path)

    Location of the server.properties file for the Kafka broker.

  • environment_file (Any) (defaults to: $::confluent::params::kafka_environment_path)

    Location of the environment file used to pass environment variables to the Kafka broker.

  • data_path (Any) (defaults to: $::confluent::params::kafka_data_path)

    Location to store the data on disk.

  • log_path (Any) (defaults to: $::confluent::params::kafka_log_path)

    Location to write the log files to.

  • user (Any) (defaults to: $::confluent::params::kafka_user)

    User to run the kafka service as.

  • service_name (Any) (defaults to: $::confluent::params::kafka_service)

    Name of the kafka service.

  • manage_service (Any) (defaults to: $::confluent::params::kafka_manage_service)

    Flag to determine if the service should be managed by puppet.

  • service_ensure (Any) (defaults to: $::confluent::params::kafka_service_ensure)

    Ensure setting to pass to service resource.

  • service_enable (Any) (defaults to: $::confluent::params::kafka_service_enable)

    Enable setting to pass to service resource.

  • file_limit (Any) (defaults to: $::confluent::params::kafka_file_limit)

    File limit to set for the Kafka service (SystemD) only.

  • stop_timeout_secs (Any) (defaults to: $::confluent::params::kafka_stop_timeout_secs)
  • manage_repository (Any) (defaults to: $::confluent::params::manage_repository)
  • heap_size (Any) (defaults to: $::confluent::params::kafka_heap_size)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'manifests/kafka/broker.pp', line 50

class confluent::kafka::broker (
  $broker_id,
  $config               = { },
  $environment_settings = { },
  $config_path          = $::confluent::params::kafka_config_path,
  $environment_file     = $::confluent::params::kafka_environment_path,
  $data_path            = $::confluent::params::kafka_data_path,
  $log_path             = $::confluent::params::kafka_log_path,
  $user                 = $::confluent::params::kafka_user,
  $service_name         = $::confluent::params::kafka_service,
  $manage_service       = $::confluent::params::kafka_manage_service,
  $service_ensure       = $::confluent::params::kafka_service_ensure,
  $service_enable       = $::confluent::params::kafka_service_enable,
  $file_limit           = $::confluent::params::kafka_file_limit,
  $stop_timeout_secs    = $::confluent::params::kafka_stop_timeout_secs,
  $manage_repository    = $::confluent::params::manage_repository,
  $heap_size            = $::confluent::params::kafka_heap_size,
) inherits confluent::params {
  include ::confluent
  include ::confluent::kafka

  if($manage_repository) {
    include ::confluent::repository
  }

  validate_hash($config)
  validate_hash($environment_settings)
  validate_integer($broker_id)
  validate_absolute_path($config_path)
  validate_absolute_path($environment_file)
  validate_absolute_path($log_path)
  validate_absolute_path($data_path)


  $kafka_default_settings = {
    'broker.id' => {
      'value' => $broker_id
    },
    'log.dirs' => {
      'value' => join(any2array($data_path), ',')
    }
  }

  $java_default_settings = {
    'KAFKA_HEAP_OPTS' => {
      'value' => "-Xmx${heap_size}"
    },
    'KAFKA_OPTS'      => {
      'value' => '-Djava.net.preferIPv4Stack=true'
    },
    'GC_LOG_ENABLED'  => {
      'value' => true
    },
    'LOG_DIR'         => {
      'value' => $log_path
    }
  }

  $actual_kafka_settings = merge($kafka_default_settings, $config)
  $actual_java_settings = merge($java_default_settings, $environment_settings)

  user { $user:
    ensure => present
  } ->
    file { [$log_path, $data_path]:
      ensure  => directory,
      owner   => $user,
      group   => $user,
      recurse => true
    }

  $ensure_kafka_settings_defaults = {
    'ensure'      => 'present',
    'path'        => $config_path,
    'application' => 'kafka'
  }

  ensure_resources('confluent::java_property', $actual_kafka_settings, $ensure_kafka_settings_defaults)

  $ensure_java_settings_defaults = {
    'path'        => $environment_file,
    'application' => 'kafka'
  }

  ensure_resources('confluent::kafka_environment_variable', $actual_java_settings, $ensure_java_settings_defaults)

  $unit_ini_setting_defaults = {
    'ensure' => 'present'
  }

  $unit_ini_settings = {
    "${service_name}/Unit/Description"        => { 'value' => 'Apache Kafka by Confluent', },
    "${service_name}/Unit/Wants"              => { 'value' => 'basic.target', },
    "${service_name}/Unit/After"              => { 'value' => 'basic.target network.target', },
    "${service_name}/Service/User"            => { 'value' => $user, },
    "${service_name}/Service/EnvironmentFile" => { 'value' => $environment_file, },
    "${service_name}/Service/ExecStart"       => { 'value' => "/usr/bin/kafka-server-start ${config_path}", },
    "${service_name}/Service/ExecStop"        => { 'value' => '/usr/bin/kafka-server-stop', },
    "${service_name}/Service/LimitNOFILE"     => { 'value' => $file_limit, },
    "${service_name}/Service/KillMode"        => { 'value' => 'process', },
    "${service_name}/Service/RestartSec"      => { 'value' => 5, },
    "${service_name}/Service/TimeoutStopSec"  => { 'value' => $stop_timeout_secs, },
    "${service_name}/Service/Type"            => { 'value' => 'simple', },
    "${service_name}/Install/WantedBy"        => { 'value' => 'multi-user.target', },
  }

  ensure_resources('confluent::systemd::unit_ini_setting', $unit_ini_settings, $unit_ini_setting_defaults)

  if($manage_service) {
    service { $service_name:
      ensure => $service_ensure,
      enable => $service_enable
    }
  }
}