From ec8f05587ebe54487d981fa886aa2a14f21ca5a0 Mon Sep 17 00:00:00 2001 From: caoyuan Date: Sat, 21 Jan 2017 23:48:18 +0800 Subject: [PATCH] Optimize reconfiguration for aodh Co-Authored-By: Mauricio Lima Change-Id: Ib54136f9d4313db05f3711fc1c8d7a07d2186d6b Partially-implements: blueprint better-reconfigure --- ansible/roles/aodh/defaults/main.yml | 39 +++++++ ansible/roles/aodh/handlers/main.yml | 93 ++++++++++++++++ .../roles/aodh/tasks/bootstrap_service.yml | 12 +-- ansible/roles/aodh/tasks/config.yml | 100 ++++++++++++------ ansible/roles/aodh/tasks/deploy.yml | 7 +- ansible/roles/aodh/tasks/pull.yml | 30 ++---- ansible/roles/aodh/tasks/reconfigure.yml | 79 +------------- ansible/roles/aodh/tasks/start.yml | 48 --------- ansible/roles/aodh/tasks/upgrade.yml | 3 +- 9 files changed, 217 insertions(+), 194 deletions(-) create mode 100644 ansible/roles/aodh/handlers/main.yml delete mode 100644 ansible/roles/aodh/tasks/start.yml diff --git a/ansible/roles/aodh/defaults/main.yml b/ansible/roles/aodh/defaults/main.yml index 66e2b94590..eb08a8fe6d 100644 --- a/ansible/roles/aodh/defaults/main.yml +++ b/ansible/roles/aodh/defaults/main.yml @@ -1,6 +1,45 @@ --- 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 diff --git a/ansible/roles/aodh/handlers/main.yml b/ansible/roles/aodh/handlers/main.yml new file mode 100644 index 0000000000..9cce8c6ba8 --- /dev/null +++ b/ansible/roles/aodh/handlers/main.yml @@ -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 diff --git a/ansible/roles/aodh/tasks/bootstrap_service.yml b/ansible/roles/aodh/tasks/bootstrap_service.yml index 5b3f0585c9..5ad824cfb4 100644 --- a/ansible/roles/aodh/tasks/bootstrap_service.yml +++ b/ansible/roles/aodh/tasks/bootstrap_service.yml @@ -1,5 +1,7 @@ --- - name: Running aodh bootstrap container + vars: + aodh_api: "{{ aodh_services['aodh-api'] }}" kolla_docker: action: "start_container" common_options: "{{ docker_common_options }}" @@ -7,15 +9,11 @@ environment: KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - image: "{{ aodh_api_image_full }}" + image: "{{ aodh_api.image }}" labels: BOOTSTRAP: name: "bootstrap_aodh" restart_policy: "never" - volumes: - - "{{ node_config_directory }}/aodh-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "aodh:/var/lib/aodh/" - - "kolla_logs:/var/log/kolla/" + volumes: "{{ aodh_api.volumes }}" run_once: True - delegate_to: "{{ groups['aodh-api'][0] }}" + delegate_to: "{{ groups[aodh_api.group][0] }}" diff --git a/ansible/roles/aodh/tasks/config.yml b/ansible/roles/aodh/tasks/config.yml index 7bc6ee5db5..b6720ba575 100644 --- a/ansible/roles/aodh/tasks/config.yml +++ b/ansible/roles/aodh/tasks/config.yml @@ -1,50 +1,65 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "aodh-api" - - "aodh-evaluator" - - "aodh-listener" - - "aodh-notifier" + when: + - item.value.enabled | bool + - inventory_hostname in groups[item.value.group] + with_dict: "{{ aodh_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "aodh-api" - - "aodh-listener" - - "aodh-evaluator" - - "aodh-notifier" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: aodh_config_jsons + when: + - item.value.enabled | bool + - inventory_hostname in groups[item.value.group] + 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 merge_configs: vars: - service_name: "{{ item }}" + service_name: "{{ item.key }}" sources: - "{{ role_path }}/templates/aodh.conf.j2" - "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/messaging.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" - dest: "{{ node_config_directory }}/{{ item }}/aodh.conf" - with_items: - - "aodh-api" - - "aodh-evaluator" - - "aodh-listener" - - "aodh-notifier" + dest: "{{ node_config_directory }}/{{ item.key }}/aodh.conf" + register: aodh_confs + when: + - item.value.enabled | bool + - inventory_hostname in groups[item.value.group] + 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 + vars: + service: "{{ aodh_services['aodh-api'] }}" template: src: "wsgi-aodh.conf.j2" - dest: "{{ node_config_directory }}/{{ item }}/wsgi-aodh.conf" - with_items: - - "aodh-api" + dest: "{{ node_config_directory }}/aodh-api/wsgi-aodh.conf" + register: aodh_conf_wsgi + when: + - inventory_hostname in groups[service.group] + - service.enabled | bool + notify: + - Restart aodh-api container - name: Check if policies shall be overwritten local_action: stat path="{{ node_custom_config }}/aodh/policy.json" @@ -53,11 +68,34 @@ - name: Copying over existing policy.json template: src: "{{ node_custom_config }}/aodh/policy.json" - dest: "{{ node_config_directory }}/{{ item }}/policy.json" - with_items: - - "aodh-api" - - "aodh-evaluator" - - "aodh-listener" - - "aodh-notifier" + dest: "{{ node_config_directory }}/{{ item.key }}/policy.json" + register: aodh_policy_jsons 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 diff --git a/ansible/roles/aodh/tasks/deploy.yml b/ansible/roles/aodh/tasks/deploy.yml index bb4533fa0d..7e6598017b 100644 --- a/ansible/roles/aodh/tasks/deploy.yml +++ b/ansible/roles/aodh/tasks/deploy.yml @@ -11,8 +11,5 @@ - include: bootstrap.yml when: inventory_hostname in groups['aodh-api'] -- include: start.yml - when: inventory_hostname in groups['aodh-api'] or - inventory_hostname in groups['aodh-evaluator'] or - inventory_hostname in groups['aodh-listener'] or - inventory_hostname in groups['aodh-notifier'] +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/aodh/tasks/pull.yml b/ansible/roles/aodh/tasks/pull.yml index dae4426a5e..ce85ce93c8 100644 --- a/ansible/roles/aodh/tasks/pull.yml +++ b/ansible/roles/aodh/tasks/pull.yml @@ -1,28 +1,10 @@ --- -- name: Pulling aodh-api image +- name: Pulling aodh images kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ aodh_api_image_full }}" - when: inventory_hostname in groups['aodh-api'] - -- name: Pulling aodh-listener image - kolla_docker: - 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'] + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ aodh_services }}" diff --git a/ansible/roles/aodh/tasks/reconfigure.yml b/ansible/roles/aodh/tasks/reconfigure.yml index c915b500d1..e078ef1318 100644 --- a/ansible/roles/aodh/tasks/reconfigure.yml +++ b/ansible/roles/aodh/tasks/reconfigure.yml @@ -1,79 +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: 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 }}" +- include: deploy.yml diff --git a/ansible/roles/aodh/tasks/start.yml b/ansible/roles/aodh/tasks/start.yml deleted file mode 100644 index a20197d363..0000000000 --- a/ansible/roles/aodh/tasks/start.yml +++ /dev/null @@ -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'] diff --git a/ansible/roles/aodh/tasks/upgrade.yml b/ansible/roles/aodh/tasks/upgrade.yml index 308053080c..c38db1adf4 100644 --- a/ansible/roles/aodh/tasks/upgrade.yml +++ b/ansible/roles/aodh/tasks/upgrade.yml @@ -3,4 +3,5 @@ - include: bootstrap_service.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers