Optimize reconfigure action for congress

Co-Authored-By: Mauricio Lima <mauriciolimab@gmail.com>
Change-Id: I568ebe2e5160982aaf5a82b6d73a753cbadc0c49
Partially-implements: blueprint better-reconfigure
This commit is contained in:
caoyuan 2017-01-19 23:16:48 +08:00
parent d7bc9a01ad
commit e527707056
9 changed files with 161 additions and 161 deletions

View File

@ -1,6 +1,36 @@
---
project_name: "congress"
congress_services:
congress-api:
container_name: congress_api
group: congress-api
enabled: true
image: "{{ congress_api_image_full }}"
volumes:
- "{{ node_config_directory }}/congress-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
congress-policy-engine:
container_name: congress_policy_engine
group: congress-policy-engine
enabled: true
image: "{{ congress_policy_engine_image_full }}"
volumes:
- "{{ node_config_directory }}/congress-policy-engine/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
congress-datasource:
container_name: congress_datasource
group: congress-datasource
enabled: true
image: "{{ congress_datasource_image_full }}"
volumes:
- "{{ node_config_directory }}/congress-datasource/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
####################
# Database
####################

View File

@ -0,0 +1,69 @@
---
- name: Restart congress-api container
vars:
service_name: "congress-api"
service: "{{ congress_services[service_name] }}"
config_json: "{{ congress_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
congress_conf: "{{ congress_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ congress_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
congress_api_container: "{{ check_congress_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 congress_conf.changed | bool
or policy_json.changed | bool
or congress_api_container.changed | bool
- name: Restart congress-policy-engine container
vars:
service_name: "congress-policy-engine"
service: "{{ congress_services[service_name] }}"
config_json: "{{ congress_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
congress_conf: "{{ congress_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ congress_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
congress_policy_engin_container: "{{ check_congress_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 congress_conf.changed | bool
or policy_json.changed | bool
or congress_policy_engin_container.changed | bool
- name: Restart congress-datasource container
vars:
service_name: "congress-datasource"
service: "{{ congress_services[service_name] }}"
config_json: "{{ congress_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
congress_conf: "{{ congress_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ congress_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
congress_datasource_container: "{{ check_congress_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 congress_conf.changed | bool
or policy_json.changed | bool
or congress_datasource_container.changed | bool

View File

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

View File

@ -1,40 +1,44 @@
---
- name: Ensuring config directories exist
file:
path: "{{ node_config_directory }}/{{ item }}"
path: "{{ node_config_directory }}/{{ item.key }}"
state: "directory"
recurse: yes
with_items:
- "congress-api"
- "congress-policy-engine"
- "congress-datasource"
when: inventory_hostname in groups[item.value.group]
with_dict: "{{ congress_services }}"
- name: Copying over config.json files for services
template:
src: "{{ item }}.json.j2"
dest: "{{ node_config_directory }}/{{ item }}/config.json"
with_items:
- "congress-api"
- "congress-policy-engine"
- "congress-datasource"
src: "{{ item.key }}.json.j2"
dest: "{{ node_config_directory }}/{{ item.key }}/config.json"
register: congress_config_jsons
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ congress_services }}"
notify:
- "Restart {{ item.key }} container"
- name: Copying over congress.conf
merge_configs:
vars:
service_name: "{{ item }}"
service_name: "{{ item.key }}"
sources:
- "{{ role_path }}/templates/congress.conf.j2"
- "{{ node_custom_config }}/global.conf"
- "{{ node_custom_config }}/database.conf"
- "{{ node_custom_config }}/messaging.conf"
- "{{ node_custom_config }}/congress.conf"
- "{{ node_custom_config }}/congress/{{ item }}.conf"
- "{{ node_custom_config }}/congress/{{ item.key }}.conf"
- "{{ node_custom_config }}/congress/{{ inventory_hostname }}/congress.conf"
dest: "{{ node_config_directory }}/{{ item }}/congress.conf"
with_items:
- "congress-api"
- "congress-policy-engine"
- "congress-datasource"
dest: "{{ node_config_directory }}/{{ item.key }}/congress.conf"
register: congress_confs
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ congress_services }}"
notify:
- "Restart {{ item.key }} container"
- name: Check if policies shall be overwritten
local_action: stat path="{{ node_custom_config }}/congress/policy.json"
@ -43,10 +47,28 @@
- name: Copying over existing policy.json
template:
src: "{{ node_custom_config }}/congress/policy.json"
dest: "{{ node_config_directory }}/{{ item }}/policy.json"
with_items:
- "congress-api"
- "congress-policy-engine"
- "congress-datasource"
dest: "{{ node_config_directory }}/{{ item.key }}/policy.json"
register: congress_policy_jsons
when:
congress_policy.stat.exists
- congress_policy.stat.exists
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ congress_services }}"
notify:
- "Restart {{ item.key }} container"
- name: Check congress 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_congress_containers
when:
- action != "config"
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ congress_services }}"
notify:
- "Restart {{ item.key }} container"

View File

@ -10,7 +10,5 @@
- include: bootstrap.yml
when: inventory_hostname in groups['congress-api']
- include: start.yml
when: inventory_hostname in groups['congress-api'] or
inventory_hostname in groups['congress-policy-engine'] or
inventory_hostname in groups['congress-datasource']
- name: Flush handlers
meta: flush_handlers

View File

@ -1,21 +1,10 @@
---
- name: Pulling congress-api image
- name: Pulling congress images
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ congress_api_image_full }}"
when: inventory_hostname in groups['congress-api']
- name: Pulling congress-policy-engine image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ congress_policy_engine_image_full }}"
when: inventory_hostname in groups['congress-policy-engine']
- name: Pulling congress-datasource image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ congress_datasource_image_full }}"
when: inventory_hostname in groups['congress-datasource']
image: "{{ item.value.image }}"
when:
- inventory_hostname in groups[item.value.group]
- item.value.enabled | bool
with_dict: "{{ congress_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: congress_api, group: congress-api }
- { name: congress_datasource, group: congress-datasource }
- { name: congress_policy_engine, group: congress-policy-engine }
- 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: congress_api, group: congress-api }
- { name: congress_datasource, group: congress-datasource }
- { name: congress_policy_engine, group: congress-policy-engine }
# 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: congress_api, group: congress-api }
- { name: congress_datasource, group: congress-datasource }
- { name: congress_policy_engine, group: congress-policy-engine }
- 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: congress_api, group: congress-api },
{ name: congress_datasource, group: congress-datasource },
{ name: congress_policy_engine, group: congress-policy-engine }]
- "{{ 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: congress_api, group: congress-api },
{ name: congress_datasource, group: congress-datasource },
{ name: congress_policy_engine, group: congress-policy-engine }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"
- include: deploy.yml

View File

@ -1,36 +0,0 @@
---
- name: Starting congress-policy-engine container
kolla_docker:
action: "start_container"
name: "congress_policy_engine"
common_options: "{{ docker_common_options }}"
image: "{{ congress_policy_engine_image_full }}"
volumes:
- "{{ node_config_directory }}/congress-policy-engine/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['congress-policy-engine']
- name: Starting congress-datasource container
kolla_docker:
action: "start_container"
name: "congress_datasource"
common_options: "{{ docker_common_options }}"
image: "{{ congress_datasource_image_full }}"
volumes:
- "{{ node_config_directory }}/congress-datasource/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['congress-datasource']
- name: Starting congress-api container
kolla_docker:
action: "start_container"
name: "congress_api"
common_options: "{{ docker_common_options }}"
image: "{{ congress_api_image_full }}"
volumes:
- "{{ node_config_directory }}/congress-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['congress-api']

View File

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