Optimize reconfiguration for mistral

Change-Id: Ieec58fe3759c8ce430a187357ca8282b0f81b7eb
Partially-implements: blueprint better-reconfigure
This commit is contained in:
caoyuan 2017-01-22 17:05:11 +08:00
parent 686bf67681
commit 7148b818e0
9 changed files with 161 additions and 158 deletions

View File

@ -1,6 +1,36 @@
--- ---
project_name: "mistral" project_name: "mistral"
mistral_services:
mistral-api:
container_name: mistral_api
group: mistral-api
enabled: true
image: "{{ mistral_api_image_full }}"
volumes:
- "{{ node_config_directory }}/mistral-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
mistral-engine:
container_name: mistral_engine
group: mistral-engine
enabled: true
image: "{{ mistral_engine_image_full }}"
volumes:
- "{{ node_config_directory }}/mistral-engine/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
mistral-executor:
container_name: mistral_executor
group: mistral-executor
enabled: true
image: "{{ mistral_executor_image_full }}"
volumes:
- "{{ node_config_directory }}/mistral-executor/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
#################### ####################
# Database # Database
#################### ####################

View File

@ -0,0 +1,69 @@
---
- name: Restart mistral-api container
vars:
service_name: "mistral-api"
service: "{{ mistral_services[service_name] }}"
config_json: "{{ mistral_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
mistral_conf: "{{ mistral_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ mistral_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
mistral_api_container: "{{ check_mistral_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 mistral_conf.changed | bool
or policy_json.changed | bool
or mistral_api_container.changed | bool
- name: Restart mistral-engine container
vars:
service_name: "mistral-engine"
service: "{{ mistral_services[service_name] }}"
config_json: "{{ mistral_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
mistral_conf: "{{ mistral_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ mistral_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
mistral_engine_container: "{{ check_mistral_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 mistral_conf.changed | bool
or policy_json.changed | bool
or mistral_engine_container.changed | bool
- name: Restart mistral-executor container
vars:
service_name: "mistral-executor"
service: "{{ mistral_services[service_name] }}"
config_json: "{{ mistral_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
mistral_conf: "{{ mistral_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
policy_json: "{{ mistral_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
mistral_executor_container: "{{ check_mistral_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 mistral_conf.changed | bool
or policy_json.changed | bool
or mistral_executor_container.changed | bool

View File

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

View File

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

View File

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

View File

@ -1,21 +1,10 @@
--- ---
- name: Pulling mistral-api image - name: Pulling mistral images
kolla_docker: kolla_docker:
action: "pull_image" action: "pull_image"
common_options: "{{ docker_common_options }}" common_options: "{{ docker_common_options }}"
image: "{{ mistral_api_image_full }}" image: "{{ item.value.image }}"
when: inventory_hostname in groups['mistral-api'] with_dict: "{{ mistral_services }}"
when:
- name: Pulling mistral-engine image - inventory_hostname in groups[item.value.group]
kolla_docker: - item.value.enabled | bool
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ mistral_engine_image_full }}"
when: inventory_hostname in groups['mistral-engine']
- name: Pulling mistral-executor image
kolla_docker:
action: "pull_image"
common_options: "{{ docker_common_options }}"
image: "{{ mistral_executor_image_full }}"
when: inventory_hostname in groups['mistral-executor']

View File

@ -1,71 +1,2 @@
--- ---
- name: Ensuring the containers up - include: deploy.yml
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: mistral_api, group: mistral-api }
- { name: mistral_engine, group: mistral-engine }
- { name: mistral_executor, group: mistral-executor }
- 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: mistral_api, group: mistral-api }
- { name: mistral_engine, group: mistral-engine }
- { name: mistral_executor, group: mistral-executor }
- 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: mistral_api, group: mistral-api }
- { name: mistral_engine, group: mistral-engine }
- { name: mistral_executor, group: mistral-executor }
- 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: mistral_api, group: mistral-api },
{ name: mistral_engine, group: mistral-engine },
{ name: mistral_executor, group: mistral-executor }]
- "{{ 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: mistral_api, group: mistral-api },
{ name: mistral_engine, group: mistral-engine },
{ name: mistral_executor, group: mistral-executor }]
- "{{ container_envs.results }}"
- "{{ check_results.results }}"

View File

@ -1,36 +0,0 @@
---
- name: Starting mistral-engine container
kolla_docker:
action: "start_container"
name: "mistral_engine"
common_options: "{{ docker_common_options }}"
image: "{{ mistral_engine_image_full }}"
volumes:
- "{{ node_config_directory }}/mistral-engine/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['mistral-engine']
- name: Starting mistral-executor container
kolla_docker:
action: "start_container"
name: "mistral_executor"
common_options: "{{ docker_common_options }}"
image: "{{ mistral_executor_image_full }}"
volumes:
- "{{ node_config_directory }}/mistral-executor/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['mistral-executor']
- name: Starting mistral-api container
kolla_docker:
action: "start_container"
name: "mistral_api"
common_options: "{{ docker_common_options }}"
image: "{{ mistral_api_image_full }}"
volumes:
- "{{ node_config_directory }}/mistral-api/:{{ container_config_directory }}/:ro"
- "/etc/localtime:/etc/localtime:ro"
- "kolla_logs:/var/log/kolla/"
when: inventory_hostname in groups['mistral-api']

View File

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