Optimize reconfigure action for trove

Co-Authored-By: Mauricio Lima <mauriciolimab@gmail.com>
Change-Id: Icbf70b0cb242dbd705e8794369b7f8d32a43c25f
Partially-implements: blueprint better-reconfigure
This commit is contained in:
caoyuan 2017-01-23 16:47:05 +08:00
parent 83d99ecf0c
commit 1210720a95
9 changed files with 167 additions and 163 deletions

View File

@ -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
####################

View File

@ -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

View File

@ -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] }}"

View File

@ -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"

View File

@ -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

View File

@ -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 }}"

View File

@ -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

View File

@ -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']

View File

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