From b82f5cc9f005e38705e075cf9c74266caa670c34 Mon Sep 17 00:00:00 2001
From: caowei <cao.wei@99cloud.net>
Date: Wed, 6 Dec 2017 15:14:38 +0800
Subject: [PATCH] Implement designate-producer service

Depends-On: Ia22128e5ce4a717612af658d63258e78e52176ad
Implements: blueprint designate-producer

Change-Id: I98b5e99e8fcfe18fde442b317348ec261f4d2f99
---
 ansible/inventory/all-in-one                  |  3 +++
 ansible/inventory/multinode                   |  3 +++
 ansible/roles/designate/defaults/main.yml     | 13 ++++++++++
 ansible/roles/designate/handlers/main.yml     | 23 +++++++++++++++++
 ansible/roles/designate/tasks/config.yml      |  4 +++
 ansible/roles/designate/tasks/deploy.yml      |  1 +
 .../templates/designate-producer.json.j2      | 25 +++++++++++++++++++
 .../designate/templates/designate.conf.j2     |  6 +++++
 ansible/site.yml                              |  1 +
 ...d-designate-producer-b6e94153ff9bc45c.yaml |  3 +++
 10 files changed, 82 insertions(+)
 create mode 100644 ansible/roles/designate/templates/designate-producer.json.j2
 create mode 100644 releasenotes/notes/add-designate-producer-b6e94153ff9bc45c.yaml

diff --git a/ansible/inventory/all-in-one b/ansible/inventory/all-in-one
index 16d04f679..c78a4f9d8 100644
--- a/ansible/inventory/all-in-one
+++ b/ansible/inventory/all-in-one
@@ -556,6 +556,9 @@ designate
 [designate-central:children]
 designate
 
+[designate-producer:children]
+designate
+
 [designate-mdns:children]
 network
 
diff --git a/ansible/inventory/multinode b/ansible/inventory/multinode
index 9dd45d6bc..1812e0f99 100644
--- a/ansible/inventory/multinode
+++ b/ansible/inventory/multinode
@@ -574,6 +574,9 @@ designate
 [designate-central:children]
 designate
 
+[designate-producer:children]
+designate
+
 [designate-mdns:children]
 network
 
diff --git a/ansible/roles/designate/defaults/main.yml b/ansible/roles/designate/defaults/main.yml
index 50bfb1ec0..0b84ccddc 100644
--- a/ansible/roles/designate/defaults/main.yml
+++ b/ansible/roles/designate/defaults/main.yml
@@ -39,6 +39,15 @@ designate_services:
       - "{{ node_config_directory }}/designate-mdns/:{{ container_config_directory }}/:ro"
       - "/etc/localtime:/etc/localtime:ro"
       - "kolla_logs:/var/log/kolla/"
+  designate-producer:
+    container_name: designate_producer
+    group: designate-producer
+    enabled: true
+    image: "{{ designate_producer_image_full }}"
+    volumes:
+      - "{{ node_config_directory }}/designate-producer/:{{ container_config_directory }}/:ro"
+      - "/etc/localtime:/etc/localtime:ro"
+      - "kolla_logs:/var/log/kolla/"
   designate-worker:
     container_name: designate_worker
     group: designate-worker
@@ -81,6 +90,10 @@ designate_central_image: "{{ docker_registry ~ '/' if docker_registry else '' }}
 designate_central_tag: "{{ designate_tag }}"
 designate_central_image_full: "{{ designate_central_image }}:{{ designate_central_tag }}"
 
+designate_producer_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ designate_install_type }}-designate-producer"
+designate_producer_tag: "{{ designate_tag }}"
+designate_producer_image_full: "{{ designate_central_image }}:{{ designate_central_tag }}"
+
 designate_api_image: "{{ docker_registry ~ '/' if docker_registry else '' }}{{ docker_namespace }}/{{ kolla_base_distro }}-{{ designate_install_type }}-designate-api"
 designate_api_tag: "{{ designate_tag }}"
 designate_api_image_full: "{{ designate_api_image }}:{{ designate_api_tag }}"
diff --git a/ansible/roles/designate/handlers/main.yml b/ansible/roles/designate/handlers/main.yml
index f49d9e315..39d995617 100644
--- a/ansible/roles/designate/handlers/main.yml
+++ b/ansible/roles/designate/handlers/main.yml
@@ -67,6 +67,29 @@
       or policy_json.changed | bool
       or designate_central_container.changed | bool
 
+- name: Restart designate-producer container
+  vars:
+    service_name: "designate-producer"
+    service: "{{ designate_services[service_name] }}"
+    config_json: "{{ designate_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
+    designate_conf: "{{ designate_confs.results|selectattr('item.key', 'equalto', service_name)|first }}"
+    policy_json: "{{ designate_policy_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
+    designate_producer_container: "{{ check_designate_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 designate_conf.changed | bool
+      or policy_json.changed | bool
+      or designate_producer_container.changed | bool
+
 - name: Restart designate-mdns container
   vars:
     service_name: "designate-mdns"
diff --git a/ansible/roles/designate/tasks/config.yml b/ansible/roles/designate/tasks/config.yml
index 6f5b3bf69..f0cd63926 100644
--- a/ansible/roles/designate/tasks/config.yml
+++ b/ansible/roles/designate/tasks/config.yml
@@ -21,6 +21,7 @@
   notify:
     - Restart designate-api container
     - Restart designate-central container
+    - Restart designate-producer container
     - Restart designate-mdns container
     - Restart designate-sink container
     - Restart designate-backend-bind9 container
@@ -45,6 +46,7 @@
   notify:
     - Restart designate-api container
     - Restart designate-central container
+    - Restart designate-producer container
     - Restart designate-mdns container
     - Restart designate-sink container
     - Restart designate-worker container
@@ -135,6 +137,7 @@
   notify:
     - Restart designate-api container
     - Restart designate-central container
+    - Restart designate-producer container
     - Restart designate-mdns container
     - Restart designate-sink container
     - Restart designate-worker container
@@ -155,6 +158,7 @@
   notify:
     - Restart designate-api container
     - Restart designate-central container
+    - Restart designate-producer container
     - Restart designate-mdns container
     - Restart designate-sink container
     - Restart designate-backend-bind9 container
diff --git a/ansible/roles/designate/tasks/deploy.yml b/ansible/roles/designate/tasks/deploy.yml
index 21541774c..35cf6a371 100644
--- a/ansible/roles/designate/tasks/deploy.yml
+++ b/ansible/roles/designate/tasks/deploy.yml
@@ -5,6 +5,7 @@
 - include: config.yml
   when: inventory_hostname in groups['designate-api'] or
         inventory_hostname in groups['designate-central'] or
+        inventory_hostname in groups['designate-producer'] or
         inventory_hostname in groups['designate-mdns'] or
         inventory_hostname in groups['designate-worker'] or
         inventory_hostname in groups['designate-sink'] or
diff --git a/ansible/roles/designate/templates/designate-producer.json.j2 b/ansible/roles/designate/templates/designate-producer.json.j2
new file mode 100644
index 000000000..442766cd5
--- /dev/null
+++ b/ansible/roles/designate/templates/designate-producer.json.j2
@@ -0,0 +1,25 @@
+{
+    "command": "designate-producer --config-file /etc/designate/designate.conf",
+    "config_files": [
+        {
+            "source": "{{ container_config_directory }}/designate.conf",
+            "dest": "/etc/designate/designate.conf",
+            "owner": "designate",
+            "perm": "0600"
+        },
+        {
+            "source": "{{ container_config_directory }}/policy.json",
+            "dest": "/etc/designate/policy.json",
+            "owner": "designate",
+            "perm": "0600",
+            "optional": true
+        }
+    ],
+    "permissions": [
+        {
+            "path": "/var/log/kolla/designate",
+            "owner": "designate:designate",
+            "recurse": true
+        }
+    ]
+}
diff --git a/ansible/roles/designate/templates/designate.conf.j2 b/ansible/roles/designate/templates/designate.conf.j2
index 11762fc3c..425275455 100644
--- a/ansible/roles/designate/templates/designate.conf.j2
+++ b/ansible/roles/designate/templates/designate.conf.j2
@@ -49,6 +49,12 @@ enabled = True
 notify = True
 workers = {{ openstack_service_workers }}
 
+[service:producer]
+workers = {{ openstack_service_workers }}
+threads = 1000
+enabled_tasks = None
+export_synchronous = True
+
 [service:pool_manager]
 cache_driver = sqlalchemy
 pool_id = {{ designate_pool_id }}
diff --git a/ansible/site.yml b/ansible/site.yml
index 47a365d27..815761091 100644
--- a/ansible/site.yml
+++ b/ansible/site.yml
@@ -566,6 +566,7 @@
   hosts:
     - designate-api
     - designate-central
+    - designate-producer
     - designate-mdns
     - designate-worker
     - designate-sink
diff --git a/releasenotes/notes/add-designate-producer-b6e94153ff9bc45c.yaml b/releasenotes/notes/add-designate-producer-b6e94153ff9bc45c.yaml
new file mode 100644
index 000000000..27e899759
--- /dev/null
+++ b/releasenotes/notes/add-designate-producer-b6e94153ff9bc45c.yaml
@@ -0,0 +1,3 @@
+---
+features:
+  -  Add designate-producer ansible role. Orchestrates periodic tasks that are run by designate.
-- 
GitLab