From 618cdcdd6334f621886613f38e767873e38bf1f5 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Fri, 19 Dec 2014 11:05:28 -0800 Subject: [PATCH] Cell Support Yagi-workers are now created per cell. One rabbit per cell. Also renamed the common role to stv3-common to prevent conflicts with other playbooks. Take note of ansible/roles/stv3-workers/defaults/main.yaml to see an example of the expected format of the calling facts file. Each entry in this list-of-dictionaries represents a rabbit server and Swift container for that cell. Also, multiple pipeline_workers are created based on the value of num_pipeline_workers (defaults to 2). This is so a machine can better utilize multi-core architectures. Change-Id: I09c4d364878493546d6e23e019f01f5f4f38c37c --- ansible/api.yaml | 2 +- .../defaults/main.yaml | 0 .../files/distiller.conf | 0 .../files/event_definitions.yaml | 0 .../files/pipelines.yaml | 0 .../files/triggers.yaml | 0 .../{common => stv3-common}/tasks/main.yaml | 0 .../templates/logging.conf.j2 | 0 .../templates/winchester.yaml.j2 | 0 ansible/roles/stv3-workers/defaults/main.yaml | 33 ++++++++++++++----- ansible/roles/stv3-workers/handlers/main.yaml | 6 ++-- ansible/roles/stv3-workers/tasks/main.yaml | 11 ++++--- .../pipeline-worker.debian.init.d.j2} | 13 ++++---- .../yagi-event.debian.init.d.j2} | 15 +++++---- .../roles/stv3-workers/templates/yagi.conf.j2 | 18 +++++----- ansible/workers.yaml | 2 +- 16 files changed, 61 insertions(+), 39 deletions(-) rename ansible/roles/{common => stv3-common}/defaults/main.yaml (100%) rename ansible/roles/{common => stv3-common}/files/distiller.conf (100%) rename ansible/roles/{common => stv3-common}/files/event_definitions.yaml (100%) rename ansible/roles/{common => stv3-common}/files/pipelines.yaml (100%) rename ansible/roles/{common => stv3-common}/files/triggers.yaml (100%) rename ansible/roles/{common => stv3-common}/tasks/main.yaml (100%) rename ansible/roles/{common => stv3-common}/templates/logging.conf.j2 (100%) rename ansible/roles/{common => stv3-common}/templates/winchester.yaml.j2 (100%) rename ansible/roles/stv3-workers/{files/pipeline-worker.debian.init.d => templates/pipeline-worker.debian.init.d.j2} (86%) rename ansible/roles/stv3-workers/{files/yagi-event.debian.init.d => templates/yagi-event.debian.init.d.j2} (84%) diff --git a/ansible/api.yaml b/ansible/api.yaml index 8a0f43f..34c3d43 100644 --- a/ansible/api.yaml +++ b/ansible/api.yaml @@ -17,5 +17,5 @@ - ["vars/local_settings.yaml"] roles: - - common + - stv3-common - stv3-api diff --git a/ansible/roles/common/defaults/main.yaml b/ansible/roles/stv3-common/defaults/main.yaml similarity index 100% rename from ansible/roles/common/defaults/main.yaml rename to ansible/roles/stv3-common/defaults/main.yaml diff --git a/ansible/roles/common/files/distiller.conf b/ansible/roles/stv3-common/files/distiller.conf similarity index 100% rename from ansible/roles/common/files/distiller.conf rename to ansible/roles/stv3-common/files/distiller.conf diff --git a/ansible/roles/common/files/event_definitions.yaml b/ansible/roles/stv3-common/files/event_definitions.yaml similarity index 100% rename from ansible/roles/common/files/event_definitions.yaml rename to ansible/roles/stv3-common/files/event_definitions.yaml diff --git a/ansible/roles/common/files/pipelines.yaml b/ansible/roles/stv3-common/files/pipelines.yaml similarity index 100% rename from ansible/roles/common/files/pipelines.yaml rename to ansible/roles/stv3-common/files/pipelines.yaml diff --git a/ansible/roles/common/files/triggers.yaml b/ansible/roles/stv3-common/files/triggers.yaml similarity index 100% rename from ansible/roles/common/files/triggers.yaml rename to ansible/roles/stv3-common/files/triggers.yaml diff --git a/ansible/roles/common/tasks/main.yaml b/ansible/roles/stv3-common/tasks/main.yaml similarity index 100% rename from ansible/roles/common/tasks/main.yaml rename to ansible/roles/stv3-common/tasks/main.yaml diff --git a/ansible/roles/common/templates/logging.conf.j2 b/ansible/roles/stv3-common/templates/logging.conf.j2 similarity index 100% rename from ansible/roles/common/templates/logging.conf.j2 rename to ansible/roles/stv3-common/templates/logging.conf.j2 diff --git a/ansible/roles/common/templates/winchester.yaml.j2 b/ansible/roles/stv3-common/templates/winchester.yaml.j2 similarity index 100% rename from ansible/roles/common/templates/winchester.yaml.j2 rename to ansible/roles/stv3-common/templates/winchester.yaml.j2 diff --git a/ansible/roles/stv3-workers/defaults/main.yaml b/ansible/roles/stv3-workers/defaults/main.yaml index 302a9c7..cd9bf2f 100644 --- a/ansible/roles/stv3-workers/defaults/main.yaml +++ b/ansible/roles/stv3-workers/defaults/main.yaml @@ -1,14 +1,29 @@ ## Lowest level config defaults for the stv3-worker role -# used in yagi.conf -rabbit_host: localhost -rabbit_user: guest -rabbit_password: password -rabbit_port: 5672 -rabbit_vhost: / -rabbit_exchange: nova - # shoebox credentials ... -swift_region: DFW swift_username: my_username rax_api_key: my_api_key + +num_pipeline_workers: 2 + +# Each dictionary results in a separate yagi_{{cell}}.conf +cells: + - cell: cell-1 + rabbit_host: localhost + rabbit_user: guest + rabbit_password: password + rabbit_port: 5672 + rabbit_vhost: / + rabbit_exchange: nova + + swift_region: DFW-cell-1 + + - cell: cell-2 + rabbit_host: localhost + rabbit_user: guest + rabbit_password: password + rabbit_port: 5672 + rabbit_vhost: / + rabbit_exchange: nova + + swift_region: DFW-cell-2 diff --git a/ansible/roles/stv3-workers/handlers/main.yaml b/ansible/roles/stv3-workers/handlers/main.yaml index e41ad1c..6e5c08a 100644 --- a/ansible/roles/stv3-workers/handlers/main.yaml +++ b/ansible/roles/stv3-workers/handlers/main.yaml @@ -1,7 +1,9 @@ # Only restart stv3-worker if we didn't already go from stopped # to started by the stv3 worker process task - name: restart yagi-event - service: name=yagi-event state=restarted + service: name=yagi-event-{{item.cell}} state=restarted + with_items: cells - name: restart pipeline-worker - service: name=pipeline_worker state=restarted + service: name=pipeline_worker_{{item}} state=restarted + with_sequence: count={{num_pipeline_workers}} diff --git a/ansible/roles/stv3-workers/tasks/main.yaml b/ansible/roles/stv3-workers/tasks/main.yaml index 16d0f45..f72a015 100644 --- a/ansible/roles/stv3-workers/tasks/main.yaml +++ b/ansible/roles/stv3-workers/tasks/main.yaml @@ -4,8 +4,9 @@ --- - name: yagi.conf - template: src=yagi.conf.j2 dest=/etc/stv3/yagi.conf + template: src=yagi.conf.j2 dest=/etc/stv3/yagi-{{item.cell}}.conf owner=stv3 group=stv3 mode=0644 + with_items: cells notify: - restart yagi-event @@ -16,13 +17,15 @@ - restart yagi-event - name: yagi-event-initd - copy: src=yagi-event.debian.init.d dest=/etc/init.d/yagi-event + template: src=yagi-event.debian.init.d.j2 dest=/etc/init.d/yagi-event-{{item.cell}} owner=stv3 group=stv3 mode=0755 + with_items: cells - name: pipeline-worker-initd - copy: src=pipeline-worker.debian.init.d - dest=/etc/init.d/pipeline_worker + template: src=pipeline-worker.debian.init.d.j2 + dest=/etc/init.d/pipeline_worker_{{item}} owner=stv3 group=stv3 mode=0755 + with_sequence: count={{num_pipeline_workers}} - name: yagi-event debug: msg="Starting yagi-event" diff --git a/ansible/roles/stv3-workers/files/pipeline-worker.debian.init.d b/ansible/roles/stv3-workers/templates/pipeline-worker.debian.init.d.j2 similarity index 86% rename from ansible/roles/stv3-workers/files/pipeline-worker.debian.init.d rename to ansible/roles/stv3-workers/templates/pipeline-worker.debian.init.d.j2 index f7cdbdf..9651cc1 100644 --- a/ansible/roles/stv3-workers/files/pipeline-worker.debian.init.d +++ b/ansible/roles/stv3-workers/templates/pipeline-worker.debian.init.d.j2 @@ -17,10 +17,11 @@ PATH=/opt/stv3/bin:/sbin:/usr/sbin:/bin:/usr/bin DESC="Winchester pipeline worker control" NAME=pipeline_worker +CORENAME=pipeline_worker_{{item}} DAEMON=/opt/stv3/bin/$NAME DAEMON_ARGS="--config /etc/stv3/winchester.yaml" -PIDFILE=/var/run/stv3/$NAME.pid -SCRIPTNAME=/etc/init.d/$NAME +PIDFILE=/var/run/stv3/$CORENAME.pid +SCRIPTNAME=/etc/init.d/$CORENAME USER=stv3 GROUP=stv3 @@ -66,7 +67,7 @@ do_stop() case "$1" in start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$CORENAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; @@ -74,7 +75,7 @@ case "$1" in esac ;; stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$CORENAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; @@ -82,10 +83,10 @@ case "$1" in esac ;; status) - status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + status_of_proc "$DAEMON" "$CORENAME" && exit 0 || exit $? ;; restart|force-reload) - log_daemon_msg "Restarting $DESC" "$NAME" + log_daemon_msg "Restarting $DESC" "$CORENAME" do_stop do_start ;; diff --git a/ansible/roles/stv3-workers/files/yagi-event.debian.init.d b/ansible/roles/stv3-workers/templates/yagi-event.debian.init.d.j2 similarity index 84% rename from ansible/roles/stv3-workers/files/yagi-event.debian.init.d rename to ansible/roles/stv3-workers/templates/yagi-event.debian.init.d.j2 index 921bff1..70ee016 100644 --- a/ansible/roles/stv3-workers/files/yagi-event.debian.init.d +++ b/ansible/roles/stv3-workers/templates/yagi-event.debian.init.d.j2 @@ -17,10 +17,11 @@ PATH=/opt/stv3/bin:/sbin:/usr/sbin:/bin:/usr/bin DESC="YAGI worker control" NAME=yagi-event +CELLNAME=yagi-event-{{item.cell}} DAEMON=/opt/stv3/bin/$NAME DAEMON_ARGS="--config /etc/stv3/yagi.conf" -PIDFILE=/var/run/stv3/$NAME.pid -SCRIPTNAME=/etc/init.d/$NAME +PIDFILE=/var/run/stv3/$CELLNAME.pid +SCRIPTNAME=/etc/init.d/$CELLNAME USER=stv3 GROUP=stv3 @@ -28,7 +29,7 @@ GROUP=stv3 [ -x "$DAEMON" ] || exit 0 # Read configuration variable file if it is present -[ -r /etc/default/$NAME ] && . /etc/default/$NAME +[ -r /etc/default/$CELLNAME ] && . /etc/default/$CELLNAME # Load the VERBOSE setting and other rcS variables . /lib/init/vars.sh @@ -66,7 +67,7 @@ do_stop() case "$1" in start) - [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$CELLNAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; @@ -74,7 +75,7 @@ case "$1" in esac ;; stop) - [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$CELLNAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; @@ -82,10 +83,10 @@ case "$1" in esac ;; status) - status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + status_of_proc "$DAEMON" "$CELLNAME" && exit 0 || exit $? ;; restart|force-reload) - log_daemon_msg "Restarting $DESC" "$NAME" + log_daemon_msg "Restarting $DESC" "$CELLNAME" do_stop do_start ;; diff --git a/ansible/roles/stv3-workers/templates/yagi.conf.j2 b/ansible/roles/stv3-workers/templates/yagi.conf.j2 index 87bd805..9dddce3 100644 --- a/ansible/roles/stv3-workers/templates/yagi.conf.j2 +++ b/ansible/roles/stv3-workers/templates/yagi.conf.j2 @@ -4,21 +4,21 @@ debug = True update_timer = 10 [event_worker] -pidfile = yagi_event_worker.pid +pidfile = yagi_{{item.cell}}_event_worker.pid daemonize = False event_driver = yagi.broker.rabbit.Broker [rabbit_broker] -host = {{ rabbit_host }} -user = {{ rabbit_user }} -password = {{ rabbit_password }} -port = {{ rabbit_port }} -vhost = {{ rabbit_vhost }} +host = {{ item.rabbit_host }} +user = {{ item.rabbit_user }} +password = {{ item.rabbit_password }} +port = {{ item.rabbit_port }} +vhost = {{ item.rabbit_vhost }} poll_delay = 1 -exchange_name = "{{ rabbit_exchange }}" +exchange_name = "{{ item.rabbit_exchange }}" [logging] -logfile = /var/log/stv3/yagi.log +logfile = /var/log/stv3/yagi-{{item.cell}}.log default_level = {{ yagi_log_level }} #config_file = /etc/stv3/logging.conf @@ -67,7 +67,7 @@ callback_list=shoebox.handlers:MoveFileCallback, shoebox.handlers:SwiftUploadCal container=sandbox credentials_file=swift_credentials.conf auth_method=rackspace -region={{ swift_region }} +region={{ item.swift_region }} # If you don't want Swift support, comment the above callback= # entry and uncomment this one: diff --git a/ansible/workers.yaml b/ansible/workers.yaml index 8d2562d..1b5be12 100644 --- a/ansible/workers.yaml +++ b/ansible/workers.yaml @@ -17,5 +17,5 @@ - ["vars/local_settings.yaml"] roles: - - common + - stv3-common - stv3-workers