From 5fad922ff2240502b1f7e0ad7f38664ad8f39d6b Mon Sep 17 00:00:00 2001 From: Joseph Vazhappilly Date: Sun, 20 Jun 2021 02:32:16 -0400 Subject: [PATCH] Add support for delfin containarized deployment --- ansible/group_vars/delfin.yml | 8 ++- ansible/roles/cleaner/scenarios/delfin.yml | 9 +++ .../delfin-installer/scenarios/container.yml | 23 +++++++ .../scenarios/source-code.yml | 65 +++++++++++-------- ansible/roles/delfin-installer/tasks/main.yml | 5 +- 5 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 ansible/roles/delfin-installer/scenarios/container.yml diff --git a/ansible/group_vars/delfin.yml b/ansible/group_vars/delfin.yml index 9d9fb11b2..1e60916b3 100644 --- a/ansible/group_vars/delfin.yml +++ b/ansible/group_vars/delfin.yml @@ -36,6 +36,12 @@ venv: "{{ delfin_work_dir }}/venv" delfin_redis_ip: 127.0.0.1 delfin_redis_port: 26379 +delfin_rabbitmq_user: delfinuser +delfin_rabbitmq_pass: delfinpass + +# Configurable Perf collection interval in seconds +performance_collection_interval: 900 + # Exporter configurations for Kafka, Prometheus & Alert Manager # Uncomment exporters to enable performance_exporters: #PerformanceExporterPrometheus, PerformanceExporterKafka @@ -49,7 +55,7 @@ delfin_exporter_kafka_topic: 'delfin-kafka' # Exporter configurations for Prometheus delfin_exporter_prometheus_ip: 0.0.0.0 delfin_exporter_prometheus_port: 8195 -delfin_exporter_prometheus_cache_file: '/var/lib/delfin/delfin_exporter.txt' +delfin_exporter_prometheus_metrics_dir: '/var/lib/delfin/metrics' # Exporter configurations for Alert Manager delfin_exporter_alertmanager_host: 'localhost' diff --git a/ansible/roles/cleaner/scenarios/delfin.yml b/ansible/roles/cleaner/scenarios/delfin.yml index 5ddd627f7..e0e1ef60d 100644 --- a/ansible/roles/cleaner/scenarios/delfin.yml +++ b/ansible/roles/cleaner/scenarios/delfin.yml @@ -13,6 +13,15 @@ # limitations under the License. --- +- name: Stop delfin containers, if started + shell: "{{ item }}" + with_items: + - docker-compose down + become: yes + ignore_errors: yes + args: + chdir: "{{ delfin_work_dir }}" + - name: Get running delfin processes shell: "ps -ef | grep -v grep | grep -i 'python3 /opt/delfin-linux-amd64/delfin/' | awk '{print $2}'" register: running_processes diff --git a/ansible/roles/delfin-installer/scenarios/container.yml b/ansible/roles/delfin-installer/scenarios/container.yml new file mode 100644 index 000000000..6893c22be --- /dev/null +++ b/ansible/roles/delfin-installer/scenarios/container.yml @@ -0,0 +1,23 @@ +# Copyright 2021 The OpenSDS Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +- name: build and install delfin using containerized deployment + shell: "{{ item }}" + with_items: + - docker build -t sodafoundation/delfin . + - DELFIN_METRICS_DIR={{ delfin_exporter_prometheus_metrics_dir }} DELFIN_HOST_IP={{ host_ip }} DELFIN_RABBITMQ_USER={{ delfin_rabbitmq_user }} DELFIN_RABBITMQ_PASS={{ delfin_rabbitmq_pass }} docker-compose up -d + become: yes + args: + chdir: "{{ delfin_work_dir }}" diff --git a/ansible/roles/delfin-installer/scenarios/source-code.yml b/ansible/roles/delfin-installer/scenarios/source-code.yml index 59b87355b..326e77d3b 100644 --- a/ansible/roles/delfin-installer/scenarios/source-code.yml +++ b/ansible/roles/delfin-installer/scenarios/source-code.yml @@ -25,7 +25,7 @@ dest: "{{ delfin_work_dir }}" version: "{{ delfin_repo_branch }}" when: - - delfin_installation_type == "repository" + - delfin_installation_type != "release" - delfinexisted.stat.exists is undefined or delfinexisted.stat.exists == false - name: ensure delfin directory exists @@ -56,38 +56,32 @@ - delfin_installation_type == "release" - delfinexisted.stat.exists is undefined or delfinexisted.stat.exists == false -- name: Create delfin config dir in host - file: - path: "{{ delfin_config_dir }}" - state: directory - mode: 0755 - become: yes - -- name: copy delfin configs to host - copy: - src: "{{ delfin_work_dir }}/etc/delfin/{{ item }}" - dest: "{{ delfin_config_dir }}/{{ item }}" - mode: 0755 - become: yes - with_items: - - delfin.conf - - api-paste.ini - - name: Update redis ip & port configuration ini_file: create: no - path: "{{ delfin_config_dir }}/delfin.conf" + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" section: coordination option: backend_server value: "{{ delfin_redis_ip }}:{{ delfin_redis_port }}" become: yes + when: delfin_installation_type != "container" + +# Telemetry option for perf collection interval +- name: Update Performance collection interval + ini_file: + create: no + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" + section: TELEMETRY + option: performance_collection_interval + value: "{{ performance_collection_interval }}" + become: yes # Performance Export Configurations - name: Check and remove performance exporters configs ini_file: create: no state: absent - path: "{{ delfin_config_dir }}/delfin.conf" + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" section: DEFAULT option: performance_exporters value: "" @@ -98,7 +92,7 @@ - name: Enable Performance Exporter configuration ini_file: create: no - path: "{{ delfin_config_dir }}/delfin.conf" + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" section: DEFAULT option: "{{ item.option }}" value: "{{ item.value }}" @@ -112,7 +106,7 @@ - name: Update Kafka Exporter configuration ini_file: create: no - path: "{{ delfin_config_dir }}/delfin.conf" + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" section: KAFKA_EXPORTER option: "{{ item.option }}" value: "{{ item.value }}" @@ -129,14 +123,14 @@ - name: Update Prometheus Exporter configuration ini_file: create: no - path: "{{ delfin_config_dir }}/delfin.conf" + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" section: PROMETHEUS_EXPORTER option: "{{ item.option }}" value: "{{ item.value }}" with_items: - { option: metric_server_ip, value: "{{ delfin_exporter_prometheus_ip }}" } - { option: metric_server_port, value: "{{ delfin_exporter_prometheus_port }}" } - - { option: metric_server_file, value: "{{ delfin_exporter_prometheus_cache_file }}" } + - { option: metrics_dir, value: "{{ delfin_exporter_prometheus_metrics_dir }}" } become: yes when: - performance_exporters != None @@ -147,7 +141,7 @@ ini_file: create: no state: absent - path: "{{ delfin_config_dir }}/delfin.conf" + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" section: DEFAULT option: alert_exporters value: "" @@ -158,7 +152,7 @@ - name: Enable AlertManager Exporter configuration ini_file: create: no - path: "{{ delfin_config_dir }}/delfin.conf" + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" section: DEFAULT option: "{{ item.option }}" value: "{{ item.value }}" @@ -171,7 +165,7 @@ - name: Update AlertManager Exporter configuration ini_file: create: no - path: "{{ delfin_config_dir }}/delfin.conf" + path: "{{ delfin_work_dir }}/etc/delfin/delfin.conf" section: PROMETHEUS_ALERT_MANAGER_EXPORTER option: "{{ item.option }}" value: "{{ item.value }}" @@ -182,3 +176,20 @@ when: - alert_exporters != None - "'AlertExporterPrometheus' in alert_exporters" + +- name: Create delfin config dir in host + file: + path: "{{ delfin_config_dir }}" + state: directory + mode: 0755 + become: yes + +- name: copy delfin configs to host + copy: + src: "{{ delfin_work_dir }}/etc/delfin/{{ item }}" + dest: "{{ delfin_config_dir }}/{{ item }}" + mode: 0755 + become: yes + with_items: + - delfin.conf + - api-paste.ini diff --git a/ansible/roles/delfin-installer/tasks/main.yml b/ansible/roles/delfin-installer/tasks/main.yml index c472fc464..f7b2b1eb1 100644 --- a/ansible/roles/delfin-installer/tasks/main.yml +++ b/ansible/roles/delfin-installer/tasks/main.yml @@ -22,8 +22,11 @@ - name: Get delfin source code include_tasks: scenarios/source-code.yml - when: delfin_installation_type != "container" - name: Start delfin processes include_tasks: scenarios/start-delfin.yml when: delfin_installation_type != "container" + +- name: containerized delfin deployment + include_tasks: scenarios/container.yml + when: delfin_installation_type == "container"