From 1210720a9542dcbb1f0d9c901b8fb71ddd58f9a5 Mon Sep 17 00:00:00 2001 From: caoyuan Date: Mon, 23 Jan 2017 16:47:05 +0800 Subject: [PATCH] Optimize reconfigure action for trove Co-Authored-By: Mauricio Lima Change-Id: Icbf70b0cb242dbd705e8794369b7f8d32a43c25f Partially-implements: blueprint better-reconfigure --- ansible/roles/trove/defaults/main.yml | 33 +++++++++ ansible/roles/trove/handlers/main.yml | 67 +++++++++++++++++ .../roles/trove/tasks/bootstrap_service.yml | 12 ++- ansible/roles/trove/tasks/config.yml | 74 +++++++++++++------ ansible/roles/trove/tasks/deploy.yml | 6 +- ansible/roles/trove/tasks/pull.yml | 23 ++---- ansible/roles/trove/tasks/reconfigure.yml | 74 +------------------ ansible/roles/trove/tasks/start.yml | 38 ---------- ansible/roles/trove/tasks/upgrade.yml | 3 +- 9 files changed, 167 insertions(+), 163 deletions(-) create mode 100644 ansible/roles/trove/handlers/main.yml delete mode 100644 ansible/roles/trove/tasks/start.yml diff --git a/ansible/roles/trove/defaults/main.yml b/ansible/roles/trove/defaults/main.yml index 8d96aed43f..24e6887a9a 100644 --- a/ansible/roles/trove/defaults/main.yml +++ b/ansible/roles/trove/defaults/main.yml @@ -1,6 +1,39 @@ --- project_name: "trove" +trove_services: + trove-api: + container_name: trove_api + group: trove-api + enabled: true + image: "{{ trove_api_image_full }}" + volumes: + - "{{ node_config_directory }}/trove-api/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + - "trove:/var/lib/trove/" + trove-conductor: + container_name: trove_conductor + group: trove-conductor + enabled: true + image: "{{ trove_conductor_image_full }}" + volumes: + - "{{ node_config_directory }}/trove-conductor/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + - "trove:/var/lib/trove/" + trove-taskmanager: + container_name: trove_taskmanager + group: trove-taskmanager + enabled: true + image: "{{ trove_taskmanager_image_full }}" + volumes: + - "{{ node_config_directory }}/trove-taskmanager/:{{ container_config_directory }}/:ro" + - "/etc/localtime:/etc/localtime:ro" + - "kolla_logs:/var/log/kolla/" + - "trove:/var/lib/trove/" + + #################### # Database #################### diff --git a/ansible/roles/trove/handlers/main.yml b/ansible/roles/trove/handlers/main.yml new file mode 100644 index 0000000000..ca6ff60310 --- /dev/null +++ b/ansible/roles/trove/handlers/main.yml @@ -0,0 +1,67 @@ +--- +- name: Restart trove-api container + vars: + service_name: "trove-api" + service: "{{ trove_services[service_name] }}" + config_json: "{{ trove_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + trove_conf: "{{ trove_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + trove_api_container: "{{ check_trove_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 trove_conf.changed | bool + or trove_api_container.changed | bool + +- name: Restart trove-conductor container + vars: + service_name: "trove-conductor" + service: "{{ trove_services[service_name] }}" + config_json: "{{ trove_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + conf_file: "{{ trove_conf_file.results|selectattr('item.key', 'equalto', service_name)|first }}" + trove_conf: "{{ trove_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + trove_conductor_container: "{{ check_trove_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 conf_file.changed | bool + or trove_conf.changed | bool + or trove_conductor_container.changed | bool + +- name: Restart trove-taskmanager container + vars: + service_name: "trove-taskmanager" + service: "{{ trove_services[service_name] }}" + config_json: "{{ trove_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}" + conf_file: "{{ trove_conf_file.results|selectattr('item.key', 'equalto', service_name)|first }}" + trove_conf: "{{ trove_confs.results|selectattr('item.key', 'equalto', service_name)|first }}" + trove_taskmanager_container: "{{ check_trove_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 conf_file.changed | bool + or trove_conf.changed | bool + or trove_taskmanager_container.changed | bool diff --git a/ansible/roles/trove/tasks/bootstrap_service.yml b/ansible/roles/trove/tasks/bootstrap_service.yml index 9136554fc2..786bb73724 100644 --- a/ansible/roles/trove/tasks/bootstrap_service.yml +++ b/ansible/roles/trove/tasks/bootstrap_service.yml @@ -1,5 +1,7 @@ --- - name: Running trove bootstrap container + vars: + trove_api: "{{ trove_services['trove-api'] }}" kolla_docker: action: "start_container" common_options: "{{ docker_common_options }}" @@ -7,15 +9,11 @@ environment: KOLLA_BOOTSTRAP: KOLLA_CONFIG_STRATEGY: "{{ config_strategy }}" - image: "{{ trove_api_image_full }}" + image: "{{ trove_api.image }}" labels: BOOTSTRAP: name: "bootstrap_trove" restart_policy: "never" - volumes: - - "{{ node_config_directory }}/trove-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - - "trove:/var/lib/trove/" + volumes: "{{ trove_api.volumes }}" run_once: True - delegate_to: "{{ groups['trove-api'][0] }}" + delegate_to: "{{ groups[trove_api.group][0] }}" diff --git a/ansible/roles/trove/tasks/config.yml b/ansible/roles/trove/tasks/config.yml index b2481a0fdc..5359b5ff48 100644 --- a/ansible/roles/trove/tasks/config.yml +++ b/ansible/roles/trove/tasks/config.yml @@ -1,45 +1,73 @@ --- - name: Ensuring config directories exist file: - path: "{{ node_config_directory }}/{{ item }}" + path: "{{ node_config_directory }}/{{ item.key }}" state: "directory" recurse: yes - with_items: - - "trove-conductor" - - "trove-api" - - "trove-taskmanager" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ trove_services }}" - name: Copying over config.json files for services template: - src: "{{ item }}.json.j2" - dest: "{{ node_config_directory }}/{{ item }}/config.json" - with_items: - - "trove-conductor" - - "trove-api" - - "trove-taskmanager" + src: "{{ item.key }}.json.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/config.json" + register: trove_config_jsons + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ trove_services }}" + notify: + - "Restart {{ item.key }} container" - name: Copying over trove conf files template: - src: "{{ item }}.conf.j2" - dest: "{{ node_config_directory }}/{{ item }}/{{ item }}.conf" - with_items: - - "trove-conductor" - - "trove-taskmanager" + src: "{{ item.key }}.conf.j2" + dest: "{{ node_config_directory }}/{{ item.key }}/{{ item.key }}.conf" + register: trove_conf_file + when: + - item.key in [ "trove-conductor", "trove-taskmanager" ] + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ trove_services }}" + notify: + - Restart trove-conductor container + - Restart trove-taskmanager container - name: Copying over trove.conf merge_configs: vars: - service_name: "{{ item }}" + service_name: "{{ item.key }}" sources: - "{{ role_path }}/templates/trove.conf.j2" - "{{ node_custom_config }}/global.conf" - "{{ node_custom_config }}/database.conf" - "{{ node_custom_config }}/messaging.conf" - "{{ node_custom_config }}/trove.conf" - - "{{ node_custom_config }}/trove/{{ item }}.conf" + - "{{ node_custom_config }}/trove/{{ item.key }}.conf" - "{{ node_custom_config }}/trove/{{ inventory_hostname }}/trove.conf" - dest: "{{ node_config_directory }}/{{ item }}/trove.conf" - with_items: - - "trove-conductor" - - "trove-api" - - "trove-taskmanager" + dest: "{{ node_config_directory }}/{{ item.key }}/trove.conf" + register: trove_confs + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ trove_services }}" + notify: + - "Restart {{ item.key }} container" + +- name: Check trove 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_trove_containers + when: + - action != "config" + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ trove_services }}" + notify: + - "Restart {{ item.key }} container" diff --git a/ansible/roles/trove/tasks/deploy.yml b/ansible/roles/trove/tasks/deploy.yml index 833d0a36ba..80a1326be2 100644 --- a/ansible/roles/trove/tasks/deploy.yml +++ b/ansible/roles/trove/tasks/deploy.yml @@ -10,7 +10,5 @@ - include: bootstrap.yml when: inventory_hostname in groups['trove-api'] -- include: start.yml - when: inventory_hostname in groups['trove-api'] or - inventory_hostname in groups['trove-conductor'] or - inventory_hostname in groups['trove-taskmanager'] +- name: Flush handlers + meta: flush_handlers diff --git a/ansible/roles/trove/tasks/pull.yml b/ansible/roles/trove/tasks/pull.yml index 9aaf50b0a3..84a449f474 100644 --- a/ansible/roles/trove/tasks/pull.yml +++ b/ansible/roles/trove/tasks/pull.yml @@ -1,21 +1,10 @@ --- -- name: Pulling trove-api image +- name: Pulling trove images kolla_docker: action: "pull_image" common_options: "{{ docker_common_options }}" - image: "{{ trove_api_image_full }}" - when: inventory_hostname in groups['trove-api'] - -- name: Pulling trove-conductor image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ trove_conductor_image_full }}" - when: inventory_hostname in groups['trove-conductor'] - -- name: Pulling trove-taskmanager image - kolla_docker: - action: "pull_image" - common_options: "{{ docker_common_options }}" - image: "{{ trove_taskmanager_image_full }}" - when: inventory_hostname in groups['trove-taskmanager'] + image: "{{ item.value.image }}" + when: + - inventory_hostname in groups[item.value.group] + - item.value.enabled | bool + with_dict: "{{ trove_services }}" diff --git a/ansible/roles/trove/tasks/reconfigure.yml b/ansible/roles/trove/tasks/reconfigure.yml index 227aff576e..e078ef1318 100644 --- a/ansible/roles/trove/tasks/reconfigure.yml +++ b/ansible/roles/trove/tasks/reconfigure.yml @@ -1,74 +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: trove_api, group: trove-api } - - { name: trove_conductor, group: trove-conductor } - - { name: trove_taskmanager, group: trove-taskmanager } - -- 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: trove_api, group: trove-api } - - { name: trove_conductor, group: trove-conductor } - - { name: trove_taskmanager, group: trove-taskmanager } - -# 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: trove_api, group: trove-api } - - { name: trove_conductor, group: trove-conductor } - - { name: trove_taskmanager, group: trove-taskmanager } - -- 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: trove_api, group: trove-api }, - { name: trove_conductor, group: trove-conductor }, - { name: trove_taskmanager, group: trove-taskmanager }] - - "{{ 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: trove_api, group: trove-api }, - { name: trove_conductor, group: trove-conductor }, - { name: trove_taskmanager, group: trove-taskmanager }] - - "{{ container_envs.results }}" - - "{{ check_results.results }}" +- include: deploy.yml diff --git a/ansible/roles/trove/tasks/start.yml b/ansible/roles/trove/tasks/start.yml deleted file mode 100644 index 34a767a40d..0000000000 --- a/ansible/roles/trove/tasks/start.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -- name: Starting trove-api container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ trove_api_image_full }}" - name: "trove_api" - volumes: - - "{{ node_config_directory }}/trove-api/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - when: inventory_hostname in groups['trove-api'] - -- name: Starting trove-conductor container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ trove_conductor_image_full }}" - name: "trove_conductor" - volumes: - - "{{ node_config_directory }}/trove-conductor/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - - "trove:/var/lib/trove/" - when: inventory_hostname in groups['trove-conductor'] - -- name: Starting trove-taskmanager container - kolla_docker: - action: "start_container" - common_options: "{{ docker_common_options }}" - image: "{{ trove_taskmanager_image_full }}" - name: "trove_taskmanager" - volumes: - - "{{ node_config_directory }}/trove-taskmanager/:{{ container_config_directory }}/:ro" - - "/etc/localtime:/etc/localtime:ro" - - "kolla_logs:/var/log/kolla/" - - "trove:/var/lib/trove/" - when: inventory_hostname in groups['trove-taskmanager'] diff --git a/ansible/roles/trove/tasks/upgrade.yml b/ansible/roles/trove/tasks/upgrade.yml index 308053080c..c38db1adf4 100644 --- a/ansible/roles/trove/tasks/upgrade.yml +++ b/ansible/roles/trove/tasks/upgrade.yml @@ -3,4 +3,5 @@ - include: bootstrap_service.yml -- include: start.yml +- name: Flush handlers + meta: flush_handlers