Add support for deploying ZooKeeper

This picks up the abandoned review:
https://review.openstack.org/#/c/412423

Co-Authored-By: Sam Yaple <sam@yaple.net>
Partially-Implements: blueprint monasca-roles
Change-Id: Idc01afcb125271181ee5e15d327d0929f07b49e9
This commit is contained in:
Doug Szumski 2018-02-23 17:36:27 +00:00
parent d32c708290
commit f87b238db5
26 changed files with 275 additions and 0 deletions

View File

@ -303,6 +303,10 @@ trove_api_port: "8779"
watcher_api_port: "9322"
zookeeper_client_port: "2181"
zookeeper_peer_port: "2888"
zookeeper_quorum_port: "3888"
zun_api_port: "9517"
opendaylight_clustering_port: "2550"
@ -477,6 +481,7 @@ enable_trove: "no"
enable_vitrage: "no"
enable_vmtp: "no"
enable_watcher: "no"
enable_zookeeper: "no"
enable_zun: "no"
ovs_datapath: "{{ 'netdev' if enable_ovs_dpdk | bool else 'system' }}"

View File

@ -222,6 +222,9 @@ control
[bifrost:children]
deployment
[zookeeper:children]
control
[zun:children]
control

View File

@ -241,6 +241,9 @@ control
[bifrost:children]
deployment
[zookeeper:children]
control
[zun:children]
control

View File

@ -51,6 +51,7 @@
- "03-rabbitmq"
- "04-openstack-wsgi"
- "05-libvirt"
- "06-zookeeper"
notify:
- Restart fluentd container
@ -217,6 +218,7 @@
- { name: "trove", enabled: "{{ enable_trove }}" }
- { name: "vitrage", enabled: "{{ enable_vitrage }}" }
- { name: "watcher", enabled: "{{ enable_watcher }}" }
- { name: "zookeeper", enabled: "{{ enable_zookeeper }}" }
- { name: "zun", enabled: "{{ enable_zun }}" }
notify:
- Restart cron container

View File

@ -7,6 +7,13 @@
</record>
</filter>
<filter infra.var.log.kolla.*.*.log>
@type record_transformer
<record>
Logger ${tag_parts[4]}
</record>
</filter>
<filter infra.*>
@type record_transformer
<record>

View File

@ -0,0 +1,11 @@
{% set fluentd_dir = 'td-agent' if kolla_base_distro in ['ubuntu', 'debian'] else 'fluentd' %}
<source>
@type tail
path /var/log/kolla/zookeeper/zookeeper.log
pos_file /var/run/{{ fluentd_dir }}/zookeeper.pos
tag infra.*
format multiline
format_firstline /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} \S+ \S+ \S+ .*$/
format1 /^(?<Timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) \[(?<server_id>\S+)\] \S+ (?<log_level>\S+) (?<Payload>.*)$/
time_key Timestamp
</source>

View File

@ -0,0 +1,3 @@
"/var/log/kolla/zookeeper/*.log"
{
}

View File

@ -53,6 +53,7 @@
( 'trove', enable_trove ),
( 'vitrage', enable_vitrage ),
( 'watcher', enable_watcher ),
( 'zookeeper', enable_zookeeper ),
( 'zun', enable_zun )
] %}
{

View File

@ -47,6 +47,12 @@
"owner": "{{ fluentd_user }}",
"perm": "0600"
},
{
"source": "{{ container_config_directory }}/input/06-zookeeper.conf",
"dest": "{{ fluentd_dir }}/input/06-zookeeper.conf",
"owner": "{{ fluentd_user }}",
"perm": "0600"
},
{# Copy all configuration files in filter/ directory to include #}
{# custom filter configs. #}
{

View File

@ -0,0 +1,28 @@
---
zookeeper_services:
zookeeper:
container_name: zookeeper
group: zookeeper
enabled: true
image: "{{ zookeeper_image_full }}"
environment:
ZOO_LOG_DIR: /var/log/kolla/zookeeper
ZOO_LOG4J_PROP: "{{ zookeeper_log_settings }}"
volumes:
- "{{ node_config_directory }}/zookeeper/:{{ container_config_directory }}/"
- "/etc/localtime:/etc/localtime:ro"
- "zookeeper:/var/lib/zookeeper/data"
- "kolla_logs:/var/log/kolla/"
####################
# Zookeeper
####################
zookeeper_log_settings: 'INFO,ROLLINGFILE'
####################
# Docker
####################
zookeeper_install_type: "{{ kolla_install_type }}"
zookeeper_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ zookeeper_install_type }}-zookeeper"
zookeeper_tag: "{{ openstack_release }}"
zookeeper_image_full: "{{ zookeeper_image }}:{{ zookeeper_tag }}"

View File

@ -0,0 +1,24 @@
---
- name: Restart zookeeper container
vars:
service_name: "zookeeper"
service: "{{ zookeeper_services[service_name] }}"
config_json: "{{ zookeeper_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
zookeeper_conf: "{{ zookeeper_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
zookeeper_instance_id: "{{ zookeeper_instance_id.results|selectattr('item.key', 'equalto', service_name)|first }}"
zookeeper_container: "{{ check_zookeeper_containers.results|selectattr('item.key', 'equalto', service_name)|first }}"
kolla_docker:
action: "recreate_or_restart_container"
common_options: "{{ docker_common_options }}"
name: "{{ service.container_name }}"
image: "{{ service.image }}"
environment: "{{ service.environment }}"
volumes: "{{ service.volumes }}"
when:
- action != "config"
- inventory_hostname in groups[service.group]
- service.enabled | bool
- config_json.changed | bool
or zookeeper_conf.changed | bool
or zookeeper_instance_id.changed | bool
or zookeeper_container.changed | bool

View File

@ -0,0 +1,3 @@
---
dependencies:
- { role: common }

View File

@ -0,0 +1 @@
---

View File

@ -0,0 +1,76 @@
---
- name: Ensuring config directories exist
file:
path: "{{ node_config_directory }}/{{ item.key }}"
state: "directory"
owner: "{{ config_owner_user }}"
group: "{{ config_owner_group }}"
mode: "0770"
recurse: yes
become: true
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ zookeeper_services }}"
- name: Copying over config.json files for services
template:
src: "{{ item.key }}.json.j2"
dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
mode: "0660"
become: true
register: zookeeper_config_jsons
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ zookeeper_services }}"
notify:
- Restart zookeeper container
- name: Copying over zookeeper configuration
merge_configs:
sources:
- "{{ role_path }}/templates/{{ item.key }}.cfg.j2"
- "{{ node_custom_config }}/{{ item.key }}.cfg"
- "{{ node_custom_config }}/{{ item.key }}/{{ inventory_hostname }}/{{ item.key }}.cfg"
dest: "{{ node_config_directory }}/{{ item.key }}/{{ item.key }}.cfg"
mode: "0660"
become: true
register: zookeeper_confs
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ zookeeper_services }}"
notify:
- Restart zookeeper container
- name: Copying over zookeeper instance id
template:
src: "myid.j2"
dest: "{{ node_config_directory }}/{{ item.key }}/myid"
mode: "0660"
become: true
register: zookeeper_instance_id
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ zookeeper_services }}"
notify:
- Restart zookeeper container
- name: Check zookeeper containers
kolla_docker:
action: "compare_container"
common_options: "{{ docker_common_options }}"
name: "{{ item.value.container_name }}"
image: "{{ item.value.image }}"
volumes: "{{ item.value.volumes }}"
environment: "{{ item.value.environment }}"
register: check_zookeeper_containers
when:
- action != "config"
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ zookeeper_services }}"
notify:
- Restart zookeeper container

View File

@ -0,0 +1,5 @@
---
- include: config.yml
- name: Flush handlers
meta: flush_handlers

View File

@ -0,0 +1,2 @@
---
- include: "{{ action }}.yml"

View File

@ -0,0 +1,21 @@
---
- name: Get container facts
kolla_container_facts:
name:
- zookeeper
register: container_facts
- name: Checking zookeeper ports are available
wait_for:
host: "{{ api_interface_address }}"
port: "{{ item }}"
connect_timeout: 1
timeout: 1
state: stopped
with_items:
- "{{ zookeeper_client_port }}"
- "{{ zookeeper_peer_port }}"
- "{{ zookeeper_quorum_port }}"
when:
- container_facts['zookeeper'] is not defined
- inventory_hostname in groups['zookeeper']

View File

@ -0,0 +1,10 @@
---
- name: Pulling zookeeper images
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ item.value.image }}"
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ zookeeper_services }}"

View File

@ -0,0 +1,2 @@
---
- include: deploy.yml

View File

@ -0,0 +1,5 @@
---
- include: config.yml
- name: Flush handlers
meta: flush_handlers

View File

@ -0,0 +1,5 @@
{% for host in groups['zookeeper'] -%}
{% if hostvars[host]['ansible_hostname'] == ansible_hostname -%}
{{ loop.index }}
{%- endif %}
{%- endfor %}

View File

@ -0,0 +1,8 @@
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/var/lib/zookeeper/data
clientPort={{ zookeeper_client_port }}
{% for host in groups['zookeeper'] %}
server.{{ loop.index }}={{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }}:{{ zookeeper_peer_port }}:{{ zookeeper_quorum_port }}
{% endfor %}

View File

@ -0,0 +1,29 @@
{
"command": "/opt/zookeeper/bin/zkServer.sh start-foreground /etc/zookeeper/conf/zoo.cfg",
"config_files": [
{
"source": "{{ container_config_directory }}/myid",
"dest": "/var/lib/zookeeper/data/myid",
"owner": "zookeeper",
"perm": "0600"
},
{
"source": "{{ container_config_directory }}/zookeeper.cfg",
"dest": "/etc/zookeeper/conf/zoo.cfg",
"owner": "zookeeper",
"perm": "0600"
}
],
"permissions": [
{
"path": "/var/lib/zookeeper",
"owner": "zookeeper:zookeeper",
"recurse": true
},
{
"path": "/var/log/kolla/zookeeper",
"owner": "zookeeper:zookeeper",
"recurse": true
}
]
}

View File

@ -75,6 +75,15 @@
tags: collectd,
when: enable_collectd | bool }
- name: Apply role zookeeper
gather_facts: false
hosts: zookeeper
serial: '{{ serial|default("0") }}'
roles:
- { role: zookeeper,
tags: zookeeper,
when: enable_zookeeper | bool }
- name: Apply role elasticsearch
gather_facts: false
hosts: elasticsearch

View File

@ -234,6 +234,7 @@ kolla_internal_vip_address: "10.10.10.254"
#enable_vitrage: "no"
#enable_vmtp: "no"
#enable_watcher: "no"
#enable_zookeeper: "no"
#enable_zun: "no"
##############

View File

@ -0,0 +1,5 @@
---
features:
- Add a role for deploying Apache Zookeeper for the purpose of
supporting Apache Kafka. See https://zookeeper.apache.org/
for more details.