/**
 * Update mirror image
 *
 * Expected parameters:
 *   SALT_MASTER_CREDENTIALS            Credentials to the Salt API.
 *   SALT_MASTER_URL                    Full Salt API address [https://10.10.10.1:8000].
 *   UPDATE_APTLY                       Option to update Aptly
 *   UPDATE_APTLY_MIRRORS               List of mirrors
 *   PUBLISH_APTLY                      Publish aptly snapshots
 *   RECREATE_APTLY_PUBLISHES           Option to recreate Aptly publishes separated by comma
 *   FORCE_OVERWRITE_APTLY_PUBLISHES    Option to force overwrite existing packages while publishing
 *   CLEANUP_APTLY                      Option to cleanup old Aptly snapshots
 *   UPDATE_DOCKER_REGISTRY             Option to update Docker Registry
 *   CLEANUP_DOCKER_CACHE               Option to cleanup locally cached Docker images
 *   UPDATE_PYPI                        Option to update Python Packages
 *   UPDATE_GIT                         Option to update Git repositories
 *   UPDATE_IMAGES                      Option to update VM images
 *
**/

def common = new com.mirantis.mk.Common()
def salt = new com.mirantis.mk.Salt()
def python = new com.mirantis.mk.Python()
def venvPepper = "venvPepper"

node() {
    try {
        python.setupPepperVirtualenv(venvPepper, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)

        if(UPDATE_APTLY.toBoolean()){
            stage('Update Aptly mirrors'){
                def aptlyMirrorArgs = "-s -v"

                salt.enforceState(venvPepper, '*apt*', ['aptly.server'], true)
                sleep(10)

                if(UPDATE_APTLY_MIRRORS != ""){
                    common.infoMsg("Updating List of Aptly mirrors.")
                    UPDATE_APTLY_MIRRORS = UPDATE_APTLY_MIRRORS.replaceAll("\\s","")
                    def mirrors = UPDATE_APTLY_MIRRORS.tokenize(",")
                    for(mirror in mirrors){
                        salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs} -m ${mirror}\"", 'runas=aptly'], null, true)
                    }
                }
                else{
                    common.infoMsg("Updating all Aptly mirrors.")
                    salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=\"${aptlyMirrorArgs}\"", 'runas=aptly'], null, true)
                }
            }
        }
        if(PUBLISH_APTLY.toBoolean()){
            def aptlyPublishArgs = "-av"

            common.infoMsg("Publishing all Aptly snapshots.")

            salt.enforceState(venvPepper, '*apt*', ['aptly.publisher'], true)
            sleep(10)

            if(CLEANUP_APTLY.toBoolean()){
                aptlyPublishArgs += "c"
            }
            if(RECREATE_APTLY_PUBLISHES.toBoolean()){
                aptlyPublishArgs += "r"
            }
            if(FORCE_OVERWRITE_APTLY_PUBLISHES.toBoolean()){
                aptlyPublishArgs += "f"
            }
            salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=\"${aptlyPublishArgs}\"", 'runas=aptly'], null, true)
        }
        if(UPDATE_DOCKER_REGISTRY.toBoolean()){
            stage('Update Docker images'){
                common.infoMsg("Updating Docker images.")
                salt.enforceState(venvPepper, '*apt*', ['docker.client.registry'], true)
                if(CLEANUP_DOCKER_CACHE.toBoolean()){
                    salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.run', ['docker system prune --all --force'], null, true)
                }
            }
        }
        if(UPDATE_PYPI.toBoolean()){
            stage('Update PyPi packages'){
                common.infoMsg("Updating PyPi packages.")
                salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.run', ['pip2pi /srv/pypi_mirror/packages/ -r /srv/pypi_mirror/requirements.txt'], null, true)
            }
        }
        if(UPDATE_GIT.toBoolean()){
            stage('Update Git repositories'){
                common.infoMsg("Updating Git repositories.")
                salt.enforceState(venvPepper, '*apt*', ['git.server'], true)
            }
        }
        if(UPDATE_IMAGES.toBoolean()){
            stage('Update VM images'){
                common.infoMsg("Updating VM images.")
                salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.run', ['/srv/scripts/update-images.sh'], null, true)
            }
        }
    } catch (Throwable e) {
        // If there was an error or exception thrown, the build failed
        currentBuild.result = "FAILURE"
        currentBuild.description = currentBuild.description ? e.message + " " + currentBuild.description : e.message
        throw e
    }
}