Merge "Optimize reconfiguration for watcher"

This commit is contained in:
Jenkins 2017-01-25 11:38:36 +00:00 committed by Gerrit Code Review
commit c667eabe4c
9 changed files with 169 additions and 158 deletions

View File

@ -1,6 +1,36 @@
---
project_name: "watcher"
watcher_services:
watcher-api:
container_name: watcher_api
group: watcher-api
enabled: true
image: "{{ watcher_api_image_full }}"
volumes:
- "{{ node_config_directory }}/watcher-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
watcher-applier:
container_name: watcher_applier
group: watcher-applier
enabled: true
image: "{{ watcher_applier_image_full }}"
volumes:
- "{{ node_config_directory }}/watcher-applier/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
watcher-engine:
container_name: watcher_engine
group: watcher-engine
enabled: true
image: "{{ watcher_engine_image_full }}"
volumes:
- "{{ node_config_directory }}/watcher-engine/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
####################
# Database
####################

View File

@ -0,0 +1,69 @@
---
- name: Restart watcher-applier container
vars:
service_name: "watcher-applier"
service: "{{ watcher_services[service_name] }}"
config_json: "{{ watcher_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
watcher_conf: "{{ watcher_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ watcher_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
watcher_applier_container: "{{ check_watcher_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 }}"
volumes: "{{ service.volumes }}"
when:
- action != "config"
- inventory_hostname in groups[service.group]
- service.enabled | bool
- config_json.changed | bool
or watcher_conf.changed | bool
or policy_json.changed | bool
or watcher_applier_container.changed | bool
- name: Restart watcher-engine container
vars:
service_name: "watcher-engine"
service: "{{ watcher_services[service_name] }}"
config_json: "{{ watcher_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
watcher_conf: "{{ watcher_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ watcher_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
watcher_engine_container: "{{ check_watcher_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 }}"
volumes: "{{ service.volumes }}"
when:
- action != "config"
- inventory_hostname in groups[service.group]
- service.enabled | bool
- config_json.changed | bool
or watcher_conf.changed | bool
or policy_json.changed | bool
or watcher_engine_container.changed | bool
- name: Restart watcher-api container
vars:
service_name: "watcher-api"
service: "{{ watcher_services[service_name] }}"
config_json: "{{ watcher_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
watcher_conf: "{{ watcher_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ watcher_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
watcher_api_container: "{{ check_watcher_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 }}"
volumes: "{{ service.volumes }}"
when:
- action != "config"
- inventory_hostname in groups[service.group]
- service.enabled | bool
- config_json.changed | bool
or watcher_conf.changed | bool
or policy_json.changed | bool
or watcher_api_container.changed | bool

View File

@ -1,5 +1,7 @@
---
- name: Running Watcher bootstrap container
vars:
watcher_api: "{{ watcher_services['watcher-api'] }}"
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
@ -7,14 +9,11 @@
environment:
KOLLA_BOOTSTRAP:
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
image: "{{ watcher_api_image_full }}"
image: "{{ watcher_api.image }}"
labels:
BOOTSTRAP:
name: "bootstrap_watcher"
restart_policy: "never"
volumes:
- "{{ node_config_directory }}/watcher-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
volumes: "{{ watcher_api.volumes }}"
run_once: True
delegate_to: "{{ groups['watcher-api'][0] }}"
delegate_to: "{{ groups[watcher_api.group][0] }}"

View File

@ -1,40 +1,48 @@
---
- name: Ensuring config directories exist
file:
path: "{{ node_config_directory }}/{{ item }}"
path: "{{ node_config_directory }}/{{ item.key }}"
state: "directory"
recurse: yes
with_items:
- "watcher-api"
- "watcher-engine"
- "watcher-applier"
when: inventory_hostname in groups[item.value.group]
with_dict: "{{ watcher_services }}"
- name: Copying over config.json files for services
template:
src: "{{ item }}.json.j2"
dest: "{{ node_config_directory }}/{{ item }}/config.json"
with_items:
- "watcher-api"
- "watcher-engine"
- "watcher-applier"
src: "{{ item.key }}.json.j2"
dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
register: watcher_config_jsons
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ watcher_services }}"
notify:
- Restart watcher-api container
- Restart watcher-engine container
- Restart watcher-applier container
- name: Copying over watcher.conf
merge_configs:
vars:
service_name: "{{ item }}"
service_name: "{{ item.key }}"
sources:
- "{{ role_path }}/templates/watcher.conf.j2"
- "{{ node_config_directory }}/config/global.conf"
- "{{ node_config_directory }}/config/database.conf"
- "{{ node_config_directory }}/config/messaging.conf"
- "{{ node_config_directory }}/config/watcher.conf"
- "{{ node_config_directory }}/config/watcher/{{ item }}.conf"
- "{{ node_config_directory }}/config/watcher/{{ item.key }}.conf"
- "{{ node_config_directory }}/config/watcher/{{ inventory_hostname }}/watcher.conf"
dest: "{{ node_config_directory }}/{{ item }}/watcher.conf"
with_items:
- "watcher-api"
- "watcher-engine"
- "watcher-applier"
dest: "{{ node_config_directory }}/{{ item.key }}/watcher.conf"
register: watcher_confs
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ watcher_services }}"
notify:
- Restart watcher-api container
- Restart watcher-engine container
- Restart watcher-applier container
- name: Check if policies shall be overwritten
local_action: stat path="{{ node_custom_config }}/watcher/policy.json"
@ -43,10 +51,32 @@
- name: Copying over existing policy.json
template:
src: "{{ node_custom_config }}/watcher/policy.json"
dest: "{{ node_config_directory }}/{{ item }}/policy.json"
with_items:
- "watcher-api"
- "watcher-engine"
- "watcher-applier"
dest: "{{ node_config_directory }}/{{ item.key }}/policy.json"
register: watcher_policy_jsons
when:
watcher_policy.stat.exists
- watcher_policy.stat.exists
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ watcher_services }}"
notify:
- Restart watcher-api container
- Restart watcher-applier container
- Restart watcher-engine container
- name: Check watcher containers
kolla_docker:
action: "compare_container"
common_options: "{{ docker_common_options }}"
name: "{{ item.value.container_name }}"
image: "{{ item.value.image }}"
volumes: "{{ item.value.volumes }}"
register: check_watcher_containers
when:
- action != "config"
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ watcher_services }}"
notify:
- Restart watcher-api container
- Restart watcher-applier container
- Restart watcher-engine container

View File

@ -10,7 +10,5 @@
- include: bootstrap.yml
when: inventory_hostname in groups['watcher-api']
- include: start.yml
when: inventory_hostname in groups['watcher-api'] or
inventory_hostname in groups['watcher-engine'] or
inventory_hostname in groups['watcher-applier']
- name: Flush handlers
meta: flush_handlers

View File

@ -1,21 +1,10 @@
---
- name: Pulling watcher-api image
- name: Pulling watcher images
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ watcher_api_image_full }}"
when: inventory_hostname in groups['watcher-api']
- name: Pulling watcher-engine image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ watcher_engine_image_full }}"
when: inventory_hostname in groups['watcher-engine']
- name: Pulling watcher-applier image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ watcher_applier_image_full }}"
when: inventory_hostname in groups['watcher-applier']
image: "{{ item.value.image }}"
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ watcher_services }}"

View File

@ -1,71 +1,2 @@
---
- name: Ensuring the containers up
kolla_docker:
name: "{{ item.name }}"
action: "get_container_state"
register: container_state
failed_when: container_state.Running == false
when: inventory_hostname in groups[item.group]
with_items:
- { name: watcher_api, group: watcher-api }
- { name: watcher_engine, group: watcher-engine }
- { name: watcher_applier, group: watcher-applier }
- include: config.yml
- name: Check the configs
command: docker exec {{ item.name }} /usr/local/bin/kolla_set_configs --check
changed_when: false
failed_when: false
register: check_results
when: inventory_hostname in groups[item.group]
with_items:
- { name: watcher_api, group: watcher-api }
- { name: watcher_engine, group: watcher-engine }
- { name: watcher_applier, group: watcher-applier }
- name: Containers config strategy
kolla_docker:
name: "{{ item.name }}"
action: "get_container_env"
register: container_envs
when: inventory_hostname in groups[item.group]
with_items:
- { name: watcher_api, group: watcher-api }
- { name: watcher_engine, group: watcher-engine }
- { name: watcher_applier, group: watcher-applier }
- name: Remove the containers
kolla_docker:
name: "{{ item[0]['name'] }}"
action: "remove_container"
register: remove_containers
when:
- inventory_hostname in groups[item[0]['group']]
- config_strategy == "COPY_ONCE" or item[1]['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE'
- item[2]['rc'] == 1
with_together:
- [{ name: watcher_api, group: watcher-api },
{ name: watcher_engine, group: watcher-engine },
{ name: watcher_applier, group: watcher-applier }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"
- include: start.yml
when: remove_containers.changed
- name: Restart containers
kolla_docker:
name: "{{ item[0]['name'] }}"
action: "restart_container"
when:
- config_strategy == 'COPY_ALWAYS'
- item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
- item[2]['rc'] == 1
- inventory_hostname in groups[item[0]['group']]
with_together:
- [{ name: watcher_api, group: watcher-api },
{ name: watcher_engine, group: watcher-engine },
{ name: watcher_applier, group: watcher-applier }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"
- include: deploy.yml

View File

@ -1,36 +0,0 @@
---
- name: Starting watcher-applier container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ watcher_applier_image_full }}"
name: "watcher_applier"
volumes:
- "{{ node_config_directory }}/watcher-applier/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['watcher-applier']
- name: Starting watcher-engine container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ watcher_engine_image_full }}"
name: "watcher_engine"
volumes:
- "{{ node_config_directory }}/watcher-engine/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['watcher-engine']
- name: Starting watcher-api container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ watcher_api_image_full }}"
name: "watcher_api"
volumes:
- "{{ node_config_directory }}/watcher-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['watcher-api']

View File

@ -3,4 +3,5 @@
- include: bootstrap_service.yml
- include: start.yml
- name: Flush handlers
meta: flush_handlers