Optimize reconfigure action for gnocchi

Change-Id: I1b81f46568cf37296b86755b501d167fba849408
Partially-implements: blueprint better-reconfigure
This commit is contained in:
caoyuan 2017-01-20 17:09:23 +08:00
parent 686bf67681
commit cb1a2b4faf
9 changed files with 189 additions and 165 deletions

View File

@ -1,6 +1,38 @@
---
project_name: "gnocchi"
gnocchi_services:
gnocchi-api:
container_name: gnocchi_api
group: gnocchi-api
enabled: true
image: "{{ gnocchi_api_image_full }}"
volumes:
- "{{ node_config_directory }}/gnocchi-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "gnocchi:/var/lib/gnocchi/"
- "kolla_logs:/var/log/kolla/"
gnocchi-metricd:
container_name: gnocchi_metricd
group: gnocchi-metricd
enabled: true
image: "{{ gnocchi_metricd_image_full }}"
volumes:
- "{{ node_config_directory }}/gnocchi-metricd/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "gnocchi:/var/lib/gnocchi/"
- "kolla_logs:/var/log/kolla/"
gnocchi-statsd:
container_name: gnocchi_statsd
group: gnocchi-statsd
enabled: true
image: "{{ gnocchi_statsd_image_full }}"
volumes:
- "{{ node_config_directory }}/gnocchi-statsd/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "gnocchi:/var/lib/gnocchi/"
- "kolla_logs:/var/log/kolla/"
####################
# Ceph

View File

@ -0,0 +1,71 @@
---
- name: Restart gnocchi-api container
vars:
service_name: "gnocchi-api"
service: "{{ gnocchi_services[service_name] }}"
config_json: "{{ gnocchi_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
gnocchi_conf: "{{ gnocchi_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ gnocchi_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
gnocchi_api_container: "{{ check_gnocchi_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 gnocchi_conf.changed | bool
or policy_json.changed | bool
or gnocchi_api_paste_ini.changed | bool
or gnocchi_wsgi_conf.changed | bool
or gnocchi_api_container.changed | bool
- name: Restart gnocchi-metricd container
vars:
service_name: "gnocchi-metricd"
service: "{{ gnocchi_services[service_name] }}"
config_json: "{{ gnocchi_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
gnocchi_conf: "{{ gnocchi_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ gnocchi_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
gnocchi_metricd_container: "{{ check_gnocchi_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 gnocchi_conf.changed | bool
or policy_json.changed | bool
or gnocchi_metricd_container.changed | bool
- name: Restart gnocchi-statsd container
vars:
service_name: "gnocchi-statsd"
service: "{{ gnocchi_services[service_name] }}"
config_json: "{{ gnocchi_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
gnocchi_conf: "{{ gnocchi_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ gnocchi_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
gnocchi_statsd_container: "{{ check_gnocchi_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 gnocchi_conf.changed | bool
or policy_json.changed | bool
or gnocchi_statsd_container.changed | bool

View File

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

View File

@ -1,55 +1,79 @@
---
- name: Ensuring config directories exist
file:
path: "{{ node_config_directory }}/{{ item }}"
path: "{{ node_config_directory }}/{{ item.key }}"
state: "directory"
recurse: yes
with_items:
- "gnocchi-api"
- "gnocchi-statsd"
- "gnocchi-metricd"
when: inventory_hostname in groups[item.value.group]
with_dict: "{{ gnocchi_services }}"
- name: Copying over config.json files for services
template:
src: "{{ item }}.json.j2"
dest: "{{ node_config_directory }}/{{ item }}/config.json"
with_items:
- "gnocchi-api"
- "gnocchi-metricd"
- "gnocchi-statsd"
src: "{{ item.key }}.json.j2"
dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
register: gnocchi_config_jsons
when:
- item.value.enabled | bool
- inventory_hostname in groups[item.value.group]
with_dict: "{{ gnocchi_services }}"
notify:
- Restart gnocchi-api container
- Restart gnocchi-metricd container
- Restart gnocchi-statsd container
- name: Copying over api-paste.ini
vars:
service: "{{ gnocchi_services['gnocchi-api'] }}"
merge_configs:
sources:
- "{{ role_path }}/templates/api-paste.ini.j2"
- "{{ node_custom_config }}/gnocchi/api-paste.ini"
- "{{ node_custom_config }}/gnocchi/{{ inventory_hostname }}/api-paste.ini"
dest: "{{ node_config_directory }}/gnocchi-api/api-paste.ini"
register: gnocchi_api_paste_ini
when:
- inventory_hostname in groups['gnocchi-api']
- service.enabled | bool
notify:
- Restart gnocchi-api container
- name: Copying over gnocchi.conf
merge_configs:
vars:
service_name: "{{ item }}"
service_name: "{{ item.key }}"
sources:
- "{{ role_path }}/templates/gnocchi.conf.j2"
- "{{ node_custom_config }}/global.conf"
- "{{ node_custom_config }}/database.conf"
- "{{ node_custom_config }}/messaging.conf"
- "{{ node_custom_config }}/gnocchi.conf"
- "{{ node_custom_config }}/gnocchi/{{ item }}.conf"
- "{{ node_custom_config }}/gnocchi/{{ item.key }}.conf"
- "{{ node_custom_config }}/gnocchi/{{ inventory_hostname }}/gnocchi.conf"
dest: "{{ node_config_directory }}/{{ item }}/gnocchi.conf"
with_items:
- "gnocchi-api"
- "gnocchi-statsd"
- "gnocchi-metricd"
dest: "{{ node_config_directory }}/{{ item.key }}/gnocchi.conf"
register: gnocchi_confs
when:
- item.value.enabled | bool
- inventory_hostname in groups[item.value.group]
with_dict: "{{ gnocchi_services }}"
notify:
- Restart gnocchi-api container
- Restart gnocchi-metricd container
- Restart gnocchi-statsd container
- name: Copying over wsgi-gnocchi.conf
vars:
service: "{{ gnocchi_services['gnocchi-api'] }}"
template:
src: "wsgi-gnocchi.conf.j2"
dest: "{{ node_config_directory }}/{{ item }}/wsgi-gnocchi.conf"
register: gnocchi_wsgi_conf
when:
- inventory_hostname in groups['gnocchi-api']
- service.enabled | bool
with_items:
- "gnocchi-api"
notify:
- Restart gnocchi-api container
- name: Check if policies shall be overwritten
local_action: stat path="{{ node_custom_config }}/gnocchi/policy.json"
@ -58,10 +82,32 @@
- name: Copying over existing policy.json
template:
src: "{{ node_custom_config }}/gnocchi/policy.json"
dest: "{{ node_config_directory }}/{{ item }}/policy.json"
with_items:
- "gnocchi-api"
- "gnocchi-statsd"
- "gnocchi-metricd"
dest: "{{ node_config_directory }}/{{ item.key }}/policy.json"
register: gnocchi_policy_jsons
when:
gnocchi_policy.stat.exists
- gnocchi_policy.stat.exists
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ gnocchi_services }}"
notify:
- Restart gnocchi-api container
- Restart gnocchi-metricd container
- Restart gnocchi-statsd container
- name: Check gnocchi 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_gnocchi_containers
when:
- action != "config"
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ gnocchi_services }}"
notify:
- Restart gnocchi-api container
- Restart gnocchi-metricd container
- Restart gnocchi-statsd container

View File

@ -20,7 +20,5 @@
- include: bootstrap.yml
when: inventory_hostname in groups['gnocchi-api']
- include: start.yml
when: inventory_hostname in groups['gnocchi-statsd'] or
inventory_hostname in groups['gnocchi-api'] or
inventory_hostname in groups['gnocchi-metricd']
- name: Flush handlers
meta: flush_handlers

View File

@ -1,21 +1,10 @@
---
- name: Pulling gnocchi-api image
- name: Pulling gnocchi images
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ gnocchi_api_image_full }}"
when: inventory_hostname in groups['gnocchi-api']
- name: Pulling gnocchi-metricd image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ gnocchi_metricd_image_full }}"
when: inventory_hostname in groups['gnocchi-metricd']
- name: Pulling gnocchi-statsd image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ gnocchi_statsd_image_full }}"
when: inventory_hostname in groups['gnocchi-statsd']
image: "{{ item.value.image }}"
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ gnocchi_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: gnocchi_api, group: gnocchi-api }
- { name: gnocchi_metricd, group: gnocchi-metricd }
- { name: gnocchi_statsd, group: gnocchi-statsd }
- 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: gnocchi_api, group: gnocchi-api }
- { name: gnocchi_metricd, group: gnocchi-metricd }
- { name: gnocchi_statsd, group: gnocchi-statsd }
# 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: gnocchi_api, group: gnocchi-api }
- { name: gnocchi_metricd, group: gnocchi-metricd }
- { name: gnocchi_statsd, group: gnocchi-statsd }
- 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: gnocchi_api, group: gnocchi-api },
{ name: gnocchi_metricd, group: gnocchi-metricd },
{ name: gnocchi_statsd, group: gnocchi-statsd }]
- "{{ 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: gnocchi_api, group: gnocchi-api },
{ name: gnocchi_metricd, group: gnocchi-metricd },
{ name: gnocchi_statsd, group: gnocchi-statsd }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"
- include: deploy.yml

View File

@ -1,39 +0,0 @@
---
- name: Starting gnocchi-api container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ gnocchi_api_image_full }}"
name: "gnocchi_api"
volumes:
- "{{ node_config_directory }}/gnocchi-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "gnocchi:/var/lib/gnocchi/"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['gnocchi-api']
- name: Starting gnocchi-metricd container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ gnocchi_metricd_image_full }}"
name: "gnocchi_metricd"
volumes:
- "{{ node_config_directory }}/gnocchi-metricd/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "gnocchi:/var/lib/gnocchi/"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['gnocchi-metricd']
- name: Starting gnocchi-statsd container
kolla_docker:
action: "start_container"
common_options: "{{ docker_common_options }}"
image: "{{ gnocchi_statsd_image_full }}"
name: "gnocchi_statsd"
volumes:
- "{{ node_config_directory }}/gnocchi-statsd/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "gnocchi:/var/lib/gnocchi/"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['gnocchi-statsd']

View File

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