Optimize reconfiguration for aodh

Co-Authored-By: Mauricio Lima <mauriciolimab@gmail.com>
Change-Id: Ib54136f9d4313db05f3711fc1c8d7a07d2186d6b
Partially-implements: blueprint better-reconfigure
This commit is contained in:
caoyuan 2017-01-21 23:48:18 +08:00 committed by Mauricio Lima
parent 2d32083a27
commit ec8f05587e
9 changed files with 217 additions and 194 deletions

View File

@ -1,6 +1,45 @@
--- ---
project_name: "aodh" project_name: "aodh"
aodh_services:
aodh-api:
container_name: aodh_api
group: aodh-api
enabled: true
image: "{{ aodh_api_image_full }}"
volumes:
- "{{ node_config_directory }}/aodh-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "aodh:/var/lib/aodh/"
- "kolla_logs:/var/log/kolla/"
aodh-evaluator:
container_name: aodh_evaluator
group: aodh-evaluator
enabled: true
image: "{{ aodh_evaluator_image_full }}"
volumes:
- "{{ node_config_directory }}/aodh-evaluator/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
aodh-listener:
container_name: aodh_listener
group: aodh-listener
enabled: true
image: "{{ aodh_listener_image_full }}"
volumes:
- "{{ node_config_directory }}/aodh-listener/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
aodh-notifier:
container_name: aodh_notifier
group: aodh-notifier
enabled: true
image: "{{ aodh_notifier_image_full }}"
volumes:
- "{{ node_config_directory }}/aodh-notifier/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
#################### ####################
# Database # Database

View File

@ -0,0 +1,93 @@
---
- name: Restart aodh-api container
vars:
service_name: "aodh-api"
service: "{{ aodh_services[service_name] }}"
config_json: "{{ aodh_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
aodh_conf: "{{ aodh_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ aodh_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
aodh_api_container: "{{ check_aodh_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 aodh_conf.changed | bool
or policy_json.changed | bool
or aodh_conf_wsgi.changed | bool
or aodh_api_container.changed | bool
- name: Restart aodh-evaluator container
vars:
service_name: "aodh-evaluator"
service: "{{ aodh_services[service_name] }}"
config_json: "{{ aodh_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
aodh_conf: "{{ aodh_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ aodh_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
aodh_evaluator_container: "{{ check_aodh_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 aodh_conf.changed | bool
or policy_json.changed | bool
or aodh_evaluator_container.changed | bool
- name: Restart aodh-listener container
vars:
service_name: "aodh-listener"
service: "{{ aodh_services[service_name] }}"
config_json: "{{ aodh_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
aodh_conf: "{{ aodh_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ aodh_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
aodh_listener_container: "{{ check_aodh_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 aodh_conf.changed | bool
or policy_json.changed | bool
or aodh_listener_container.changed | bool
- name: Restart aodh-notifier container
vars:
service_name: "aodh-notifier"
service: "{{ aodh_services[service_name] }}"
config_json: "{{ aodh_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
aodh_conf: "{{ aodh_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ aodh_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
aodh_notifier_container: "{{ check_aodh_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 aodh_conf.changed | bool
or policy_json.changed | bool
or aodh_notifier_container.changed | bool

View File

@ -1,5 +1,7 @@
--- ---
- name: Running aodh bootstrap container - name: Running aodh bootstrap container
vars:
aodh_api: "{{ aodh_services['aodh-api'] }}"
kolla_docker: kolla_docker:
action: "start_container" action: "start_container"
common_options: "{{ docker_common_options }}" common_options: "{{ docker_common_options }}"
@ -7,15 +9,11 @@
environment: environment:
KOLLA_BOOTSTRAP: KOLLA_BOOTSTRAP:
KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}"
image: "{{ aodh_api_image_full }}" image: "{{ aodh_api.image }}"
labels: labels:
BOOTSTRAP: BOOTSTRAP:
name: "bootstrap_aodh" name: "bootstrap_aodh"
restart_policy: "never" restart_policy: "never"
volumes: volumes: "{{ aodh_api.volumes }}"
- "{{ node_config_directory }}/aodh-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "aodh:/var/lib/aodh/"
- "kolla_logs:/var/log/kolla/"
run_once: True run_once: True
delegate_to: "{{ groups['aodh-api'][0] }}" delegate_to: "{{ groups[aodh_api.group][0] }}"

View File

@ -1,50 +1,65 @@
--- ---
- name: Ensuring config directories exist - name: Ensuring config directories exist
file: file:
path: "{{ node_config_directory }}/{{ item }}" path: "{{ node_config_directory }}/{{ item.key }}"
state: "directory" state: "directory"
recurse: yes recurse: yes
with_items: when:
- "aodh-api" - item.value.enabled | bool
- "aodh-evaluator" - inventory_hostname in groups[item.value.group]
- "aodh-listener" with_dict: "{{ aodh_services }}"
- "aodh-notifier"
- name: Copying over config.json files for services - name: Copying over config.json files for services
template: template:
src: "{{ item }}.json.j2" src: "{{ item.key }}.json.j2"
dest: "{{ node_config_directory }}/{{ item }}/config.json" dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
with_items: register: aodh_config_jsons
- "aodh-api" when:
- "aodh-listener" - item.value.enabled | bool
- "aodh-evaluator" - inventory_hostname in groups[item.value.group]
- "aodh-notifier" with_dict: "{{ aodh_services }}"
notify:
- Restart aodh-api container
- Restart aodh-evaluator container
- Restart aodh-listener container
- Restart aodh-notifier container
- name: Copying over aodh.conf - name: Copying over aodh.conf
merge_configs: merge_configs:
vars: vars:
service_name: "{{ item }}" service_name: "{{ item.key }}"
sources: sources:
- "{{ role_path }}/templates/aodh.conf.j2" - "{{ role_path }}/templates/aodh.conf.j2"
- "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/global.conf"
- "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/database.conf"
- "{{ node_custom_config }}/messaging.conf" - "{{ node_custom_config }}/messaging.conf"
- "{{ node_custom_config }}/aodh.conf" - "{{ node_custom_config }}/aodh.conf"
- "{{ node_custom_config }}/aodh/{{ item }}.conf" - "{{ node_custom_config }}/aodh/{{ item.key }}.conf"
- "{{ node_custom_config }}/aodh/{{ inventory_hostname }}/aodh.conf" - "{{ node_custom_config }}/aodh/{{ inventory_hostname }}/aodh.conf"
dest: "{{ node_config_directory }}/{{ item }}/aodh.conf" dest: "{{ node_config_directory }}/{{ item.key }}/aodh.conf"
with_items: register: aodh_confs
- "aodh-api" when:
- "aodh-evaluator" - item.value.enabled | bool
- "aodh-listener" - inventory_hostname in groups[item.value.group]
- "aodh-notifier" with_dict: "{{ aodh_services }}"
notify:
- Restart aodh-api container
- Restart aodh-evaluator container
- Restart aodh-listener container
- Restart aodh-notifier container
- name: Copying over wsgi-aodh files for services - name: Copying over wsgi-aodh files for services
vars:
service: "{{ aodh_services['aodh-api'] }}"
template: template:
src: "wsgi-aodh.conf.j2" src: "wsgi-aodh.conf.j2"
dest: "{{ node_config_directory }}/{{ item }}/wsgi-aodh.conf" dest: "{{ node_config_directory }}/aodh-api/wsgi-aodh.conf"
with_items: register: aodh_conf_wsgi
- "aodh-api" when:
- inventory_hostname in groups[service.group]
- service.enabled | bool
notify:
- Restart aodh-api container
- name: Check if policies shall be overwritten - name: Check if policies shall be overwritten
local_action: stat path="{{ node_custom_config }}/aodh/policy.json" local_action: stat path="{{ node_custom_config }}/aodh/policy.json"
@ -53,11 +68,34 @@
- name: Copying over existing policy.json - name: Copying over existing policy.json
template: template:
src: "{{ node_custom_config }}/aodh/policy.json" src: "{{ node_custom_config }}/aodh/policy.json"
dest: "{{ node_config_directory }}/{{ item }}/policy.json" dest: "{{ node_config_directory }}/{{ item.key }}/policy.json"
with_items: register: aodh_policy_jsons
- "aodh-api"
- "aodh-evaluator"
- "aodh-listener"
- "aodh-notifier"
when: when:
aodh_policy.stat.exists - aodh_policy.stat.exists
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ aodh_services }}"
notify:
- Restart aodh-api container
- Restart aodh-evaluator container
- Restart aodh-listener container
- Restart aodh-notifier container
- name: Check aodh 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_aodh_containers
when:
- action != "config"
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ aodh_services }}"
notify:
- Restart aodh-api container
- Restart aodh-evaluator container
- Restart aodh-listener container
- Restart aodh-notifier container

View File

@ -11,8 +11,5 @@
- include: bootstrap.yml - include: bootstrap.yml
when: inventory_hostname in groups['aodh-api'] when: inventory_hostname in groups['aodh-api']
- include: start.yml - name: Flush handlers
when: inventory_hostname in groups['aodh-api'] or meta: flush_handlers
inventory_hostname in groups['aodh-evaluator'] or
inventory_hostname in groups['aodh-listener'] or
inventory_hostname in groups['aodh-notifier']

View File

@ -1,28 +1,10 @@
--- ---
- name: Pulling aodh-api image - name: Pulling aodh images
kolla_docker: kolla_docker:
action: "pull_image" action: "pull_image"
common_options: "{{ docker_common_options }}" common_options: "{{ docker_common_options }}"
image: "{{ aodh_api_image_full }}" image: "{{ item.value.image }}"
when: inventory_hostname in groups['aodh-api'] when:
- inventory_hostname in groups[item.value.group]
- name: Pulling aodh-listener image - item.value.enabled | bool
kolla_docker: with_dict: "{{ aodh_services }}"
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ aodh_listener_image_full }}"
when: inventory_hostname in groups['aodh-listener']
- name: Pulling aodh-evaluator image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ aodh_evaluator_image_full }}"
when: inventory_hostname in groups['aodh-evaluator']
- name: Pulling aodh-notifier image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ aodh_notifier_image_full }}"
when: inventory_hostname in groups['aodh-notifier']

View File

@ -1,79 +1,2 @@
--- ---
- name: Ensuring the containers up - include: deploy.yml
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: aodh_api, group: aodh-api }
- { name: aodh_listener, group: aodh-listener }
- { name: aodh_evaluator, group: aodh-evaluator }
- { name: aodh_notifier, group: aodh-notifier }
- 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: aodh_api, group: aodh-api }
- { name: aodh_listener, group: aodh-listener }
- { name: aodh_evaluator, group: aodh-evaluator }
- { name: aodh_notifier, group: aodh-notifier }
# NOTE(jeffrey4l): when config_strategy == 'COPY_ALWAYS'
# and container env['KOLLA_CONFIG_STRATEGY'] == 'COPY_ONCE',
# just remove the container and start again
- 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: aodh_api, group: aodh-api }
- { name: aodh_listener, group: aodh-listener }
- { name: aodh_evaluator, group: aodh-evaluator }
- { name: aodh_notifier, group: aodh-notifier }
- 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: aodh_api, group: aodh-api },
{ name: aodh_listener, group: aodh-listener },
{ name: aodh_evaluator, group: aodh-evaluator },
{ name: aodh_notifier, group: aodh-notifier }]
- "{{ 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:
- inventory_hostname in groups[item[0]['group']]
- config_strategy == 'COPY_ALWAYS'
- item[1]['KOLLA_CONFIG_STRATEGY'] != 'COPY_ONCE'
- item[2]['rc'] == 1
with_together:
- [{ name: aodh_api, group: aodh-api },
{ name: aodh_listener, group: aodh-listener },
{ name: aodh_evaluator, group: aodh-evaluator },
{ name: aodh_notifier, group: aodh-notifier }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"

View File

@ -1,48 +0,0 @@
---
- name: Starting aodh-api container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ aodh_api_image_full }}"
name: "aodh_api"
volumes:
- "{{ node_config_directory }}/aodh-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['aodh-api']
- name: Starting aodh-evaluator container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ aodh_evaluator_image_full }}"
name: "aodh_evaluator"
volumes:
- "{{ node_config_directory }}/aodh-evaluator/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['aodh-evaluator']
- name: Starting aodh-listener container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ aodh_listener_image_full }}"
name: "aodh_listener"
volumes:
- "{{ node_config_directory }}/aodh-listener/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['aodh-listener']
- name: Starting aodh-notifier container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ aodh_notifier_image_full }}"
name: "aodh_notifier"
volumes:
- "{{ node_config_directory }}/aodh-notifier/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['aodh-notifier']

View File

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