---
version: '2.0'
name: tripleo.swift_backup.v1
description: TripleO Swift backup container Deployment Workflow v1

workflows:

  create_swift_backup_container_plan:
    description: >
      Ensures the existence of containers for backups, e.g. swift_rings
    input:
      - container
      - queue_name: tripleo
      - container_suffix: "-swift-rings"
      - swift_tar: "swift-rings.tar.gz"
      - get_url_parm: SwiftRingGetTempurl
      - put_url_parm: SwiftRingPutTempurl
      - validate_stack: true
    tags:
      - tripleo-common-managed
    tasks:

      swift_container:
        publish:
          swift_container: "<% $.container %><% $.container_suffix %>"
        on-complete: get_tempurl

      get_tempurl:
        action: tripleo.swift.tempurl
        on-success: put_tempurl
        input:
          container: <% $.swift_container %>
          obj: <% $.swift_tar %>

      put_tempurl:
        action: tripleo.swift.tempurl
        on-success: set_tempurl
        input:
          container: <% $.swift_container %>
          obj: <% $.swift_tar %>
          method: "PUT"

      set_tempurl:
        action: tripleo.parameters.update
        input:
          parameters: <% {$.get_url_parm => task(get_tempurl).result, $.put_url_parm => task(put_tempurl).result} %>
          container: <% $.container %>
          validate: <% $.validate_stack %>
        on-success: set_status_success
        on-error: set_tempurl_failed

      set_status_success:
        on-success: notify_zaqar
        publish:
          status: SUCCESS
          message: 'Temporary Swift GET/PUT URL parameters have successfully been updated.'

      set_tempurl_failed:
        on-success: notify_zaqar
        publish:
          status: FAILED
          message: <% task(set_tempurl).result %>

      notify_zaqar:
        workflow: tripleo.messaging.v1.send
        input:
          queue_name: <% $.queue_name %>
          type: <% execution().name %>
          status: <% $.get('status', 'SUCCESS') %>
          message: <% $.get('message', '') %>
          execution: <% execution() %>
