ITOPSENG-164 Save the binary to shared home adding a locking mechanism to avoid potential race condition. This also allows downloading of old binaries once no longer available to download

This commit is contained in:
Glenn Stewart
2019-10-10 16:12:06 +11:00
parent 6bd58d54f5
commit 054e171da3
3 changed files with 74 additions and 11 deletions

View File

@@ -116,6 +116,7 @@
- "{{ atl_product_home }}"
- "{{ atl_product_installation_versioned }}"
- "{{ atl_product_version_cache_dir }}"
- "{{ atl_product_home_shared_download_dir }}"
changed_when: false # For Molecule idempotence check
# At this point atl_product_version should be set, cache if necessary.
@@ -125,17 +126,75 @@
dest: "{{ atl_product_version_cache }}"
force: true
# For the first run a temp binary should be downloaded but moved to shared home to ensure all subsequent nodes have access
# to the same specific version binary.
# To prevent a race condition with multiple downloads at the same time a directory is used as a lockfile (atomic operation).
# Note: We don't the cache binary in the shared drive to the complexity
# around download race-conditions if multiple nodes are starting at
# the same time. When downloading from product-downloads.atlassian.com
# (which is a CDN) takes seconds anyway.
- name: Fetch product installer
get_url:
url: "{{ atl_product_download_url }}"
dest: "{{ atl_product_download }}"
mode: 0755
force: false
- name: Assume temp binary should be downloaded
set_fact:
download_binary: yes
# Check for product installer in home_shared and lockdir to determine if it needs to be downloaded again.
- name: Check download lock directory exists
stat:
path: "{{ atl_product_home_shared_download_lockdir }}"
register: download_lockdir
- name: Check for presence of product installer in home_shared
stat:
path: "{{ atl_product_home_shared_download }}"
register: home_shared_downloaded
# If binary exists and lockdir exists use this binary instead
- name: Check Lock Directory and binary exists on shared_home
set_fact:
download_binary: no
when:
- home_shared_downloaded.stat.exists
- download_lockdir.stat.isdir is defined
- download_lockdir.stat.isdir
# If the binary was never installed, download it
- name: "Download product installer and move to shared directory"
block:
- name: Fetch product installer
get_url:
url: "{{ atl_product_download_url }}"
dest: "{{ atl_product_download }}"
mode: 0755
force: false
register: atl_product_downloaded
- name: Remove lockdir to prevent nodes relying on binary when copying
file:
path: "{{ atl_product_home_shared_download_lockdir }}"
state: absent
when: atl_product_downloaded is succeeded
register: lockdir_removed
- name: Copy temp installer to home_shared
copy:
src: "{{ atl_product_download }}"
dest: "{{ atl_product_home_shared_download }}"
remote_src: yes
when: lockdir_removed is succeeded
register: copied
- name: Delete old temp installer
file:
path: "{{ atl_product_download }}"
state: absent
when: copied is succeeded
register: temp_deleted
- name: Create lockdir once product installer downloaded and moved
file:
path: "{{ atl_product_home_shared_download_lockdir }}"
state: directory
when: temp_deleted is succeeded
when: download_binary
- name: Unpack the downloaded application depending on format
include_tasks: "unpack_{{ atl_download_format }}.yml"