/**
 *
 * Build mirror image pipeline
 *
 * Expected parameters:
 * CLUSTER_MODEL - An URL to the Reclass model for the mirror VM.
 * CLUSTER_MODEL_REF - Branch or tag to use for cluster model
 * CLUSTER_NAME - Cluster name used in the above model.
 * IMAGE_NAME - Name of the result image.
 * OS_CREDENTIALS_ID - ID of credentials for OpenStack API stored in Jenkins.
 * OS_PROJECT - Project in OpenStack under the VM will be spawned.
 * OS_URL - Keystone auth endpoint of the OpenStack.
 * OS_VERSION - OpenStack version
 * SCRIPTS_REF - ref on the github to get the scripts from.
 * SALT_MASTER_CREDENTIALS - ID of credentials to be used to connect to the Salt API of the VM
 * UPLOAD_URL - URL of an WebDAV used to upload the image after creating.
 * VM_AVAILABILITY_ZONE - Availability zone in OpenStack in the VM will be spawned.
 * VM_CONNECT_RETRIES - Number of retries for SSH connection to the VM after it’s spawned after 8 minutes.
 * VM_CONNECT_DELAY - Delay between connect retries above.
 * VM_FLAVOR - Flavor to be used for VM in OpenStack.
 * VM_FLOATING_IP_POOL - Floating IP pool to be used to assign floating IP to the VM.
 * VM_IMAGE - Name of the image to be used for VM in OpenStack.
 * VM_IP - Static IP that is assigned to the VM which belongs to the network used.
 * VM_IP_RETRIES - Number of retries between tries to assign the floating IP to the VM.
 * VM_IP_DELAY - Delay between floating IP assign retries above.
 * VM_NETWORK_ID - ID of the network that VM connects to.
 *
 */

// Load shared libs
def salt = new com.mirantis.mk.Salt()
def common = new com.mirantis.mk.Common()
def python = new com.mirantis.mk.Python()
def openstack = new com.mirantis.mk.Openstack()
def date = new Date()
def dateTime = date.format("ddMMyyyy-HHmmss")
def venvPepper = "venvPepper"
def privateKey = ""
def floatingIP = ""
def openstackServer = ""
def rcFile = ""
def openstackEnv = ""
def serverStatus = ""
def uploadImageStatus = ""
def uploadMd5Status = ""

def retry(int times = 5, int delay = 0, Closure body) {
    int retries = 0
    def exceptions = []
    while(retries++ < times) {
        try {
            return body.call()
        } catch(e) {
            sleep(delay)
        }
    }
    currentBuild.result = "FAILURE"
    throw new Exception("Failed after $times retries")
}

timeout(time: 12, unit: 'HOURS') {
    node("python&&disk-xl") {
        try {
            def workspace = common.getWorkspace()
            rcFile = openstack.createOpenstackEnv(OS_URL, OS_CREDENTIALS_ID, OS_PROJECT, "default", "", "default", "2", "")
            openstackEnv = String.format("%s/venv", workspace)
            def openstackVersion = OS_VERSION

            VM_IP_DELAY = VM_IP_DELAY as Integer
            VM_IP_RETRIES = VM_IP_RETRIES as Integer
            VM_CONNECT_DELAY = VM_CONNECT_DELAY as Integer
            VM_CONNECT_RETRIES = VM_CONNECT_RETRIES as Integer

            stage("Get templates"){

                if (!fileExists("${workspace}/tmp")) {
                    sh "mkdir -p ${workspace}/tmp"
                }

                sh "wget https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${SCRIPTS_REF}/mirror-image/salt-bootstrap.sh"
                openstack.setupOpenstackVirtualenv(openstackEnv, openstackVersion)
            }

            stage("Spawn Instance"){
                privateKey = openstack.runOpenstackCommand("openstack keypair create mcp-offline-keypair-${dateTime}", rcFile, openstackEnv)

                common.infoMsg(privateKey)
                sh "echo '${privateKey}' > id_rsa;chmod 600 id_rsa"

                floatingIP = openstack.runOpenstackCommand("openstack ip floating create --format value -c floating_ip_address ${VM_FLOATING_IP_POOL}", rcFile, openstackEnv)

                withEnv(["CLUSTER_NAME=${CLUSTER_NAME}", "CLUSTER_MODEL=${CLUSTER_MODEL}", "CLUSTER_MODEL_REF=${CLUSTER_MODEL_REF}", "MCP_VERSION=${MCP_VERSION}"]) {
                    sh "envsubst < salt-bootstrap.sh > salt-bootstrap.sh.temp;mv salt-bootstrap.sh.temp salt-bootstrap.sh; cat salt-bootstrap.sh"
                }

                openstackServer = openstack.runOpenstackCommand("openstack server create --key-name mcp-offline-keypair-${dateTime} --availability-zone ${VM_AVAILABILITY_ZONE} --image ${VM_IMAGE} --flavor ${VM_FLAVOR} --nic net-id=${VM_NETWORK_ID},v4-fixed-ip=${VM_IP} --user-data salt-bootstrap.sh mcp-offline-mirror-${dateTime}", rcFile, openstackEnv)
                sleep(60)

                retry(VM_IP_RETRIES, VM_IP_DELAY){
                    openstack.runOpenstackCommand("openstack ip floating add ${floatingIP} mcp-offline-mirror-${dateTime}", rcFile, openstackEnv)
                }

                sleep(500)

                retry(VM_CONNECT_RETRIES, VM_CONNECT_DELAY){
                    sh "scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i id_rsa root@${floatingIP}:/srv/initComplete ./"
                }

                python.setupPepperVirtualenv(venvPepper, "http://${floatingIP}:6969", SALT_MASTER_CREDENTIALS)
            }
            stage("Prepare instance"){
                salt.runSaltProcessStep(venvPepper, '*apt*', 'saltutil.refresh_pillar', [], null, true)
                salt.runSaltProcessStep(venvPepper, '*apt*', 'saltutil.sync_all', [], null, true)
                salt.enforceState(venvPepper, '*apt*', ['salt'], true, false, null, false, -1, 2)
                salt.enforceState(venvPepper, '*apt*', ['linux'], true, false, null, false, -1, 2)
                salt.enforceState(venvPepper, '*apt*', ['nginx'], true, false, null, false, -1, 2)
            }

            stage("Create Docker Registry"){
                common.infoMsg("Creating Docker Registry")
                salt.enforceState(venvPepper, '*apt*', ["docker.host"], true, false, null, false, -1, 2)
                salt.cmdRun(venvPepper, '*apt*', "docker run --restart always -d -p 5000:5000 --name registry registry:2")
                salt.enforceState(venvPepper, '*apt*', ["docker.client.registry"], true, false, null, false, -1, 2)
                salt.cmdRun(venvPepper, '*apt*', "docker system prune --all --force")
                salt.cmdRun(venvPepper, '*apt*', "wget https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${SCRIPTS_REF}/mirror-image/config/interfaces -O /root/interfaces")
                salt.cmdRun(venvPepper, '*apt*', "wget https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${SCRIPTS_REF}/mirror-image/config/minion.conf -O /root/minion.conf")
            }

            stage("Create Aptly"){
                common.infoMsg("Creating Aptly")
                salt.enforceState(venvPepper, '*apt*', ['aptly'], true, false, null, false, -1, 2)
                //TODO: Do it new way
                salt.cmdRun(venvPepper, '*apt*', "aptly_mirror_update.sh -s -v", true, null, true, ["runas=aptly"])
                salt.cmdRun(venvPepper, '*apt*', "nohup aptly api serve --no-lock > /dev/null 2>&1 </dev/null &", true, null, true, ["runas=aptly"])
                salt.cmdRun(venvPepper, '*apt*', "aptly-publisher --timeout=1200 publish -v -c /etc/aptly-publisher.yaml --architectures amd64 --url http://127.0.0.1:8080 --recreate --force-overwrite", true, null, true, ["runas=aptly"])
                salt.cmdRun(venvPepper, '*apt*', "aptly db cleanup", true, null, true, ["runas=aptly"])
                //NEW way
                //salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_mirror_update.sh', "args=-sv", "runas=aptly"], null, true)
                //salt.runSaltProcessStep(venvPepper, '*apt*', 'cmd.script', ['salt://aptly/files/aptly_publish_update.sh', "args=-acrfv", "runas=aptly"], null, true)
                salt.cmdRun(venvPepper, '*apt*', "wget https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${SCRIPTS_REF}/mirror-image/aptly/aptly-update.sh -O /srv/scripts/aptly-update.sh")
                salt.cmdRun(venvPepper, '*apt*', "chmod +x /srv/scripts/aptly-update.sh")
            }

            stage("Create Debmirrors"){
                common.infoMsg("Creating Debmirrors")
                salt.cmdRun(venvPepper, '*apt*', "wget https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${SCRIPTS_REF}/mirror-image/debmirror.sh -O /srv/scripts/debmirror.sh")
                salt.cmdRun(venvPepper, '*apt*', "chmod +x /srv/scripts/debmirror.sh")
                salt.cmdRun(venvPepper, '*apt*', "export HOME='/root';export MCP_VERSION='${MCP_VERSION}';/srv/scripts/debmirror.sh")
            }

            stage("Create Git mirror"){
                common.infoMsg("Creating Git mirror")
                salt.enforceState(venvPepper, '*apt*', ['git.server'], true, false, null, false, -1, 2)
            }

            stage("Create PyPi mirror"){
                common.infoMsg("Creating PyPi mirror")
                salt.cmdRun(venvPepper, '*apt*', "pip install pip2pi")
                salt.cmdRun(venvPepper, '*apt*', "wget https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${SCRIPTS_REF}/mirror-image/pypi_mirror/requirements.txt -O /srv/pypi_mirror/requirements.txt")
                salt.cmdRun(venvPepper, '*apt*', "pip2pi /srv/pypi_mirror/packages/ -r /srv/pypi_mirror/requirements.txt")
            }

            stage("Create mirror of images"){
                common.infoMsg("Creating mirror of images")
                salt.cmdRun(venvPepper, '*apt*', "wget https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${SCRIPTS_REF}/mirror-image/images_mirror/images.txt -O /srv/images.txt")
                salt.cmdRun(venvPepper, '*apt*', "wget https://raw.githubusercontent.com/Mirantis/mcp-common-scripts/${SCRIPTS_REF}/mirror-image/images_mirror/update-images.sh -O /srv/scripts/update-images.sh")
                salt.cmdRun(venvPepper, '*apt*', "chmod +x /srv/scripts/update-images.sh")
                salt.cmdRun(venvPepper, '*apt*', "/srv/scripts/update-images.sh -u http://ci.mcp.mirantis.net:8085/images")
            }

            stage("Create instance snapshot"){
                salt.cmdRun(venvPepper, '*apt*', "rm -rf /var/lib/cloud/sem/* /var/lib/cloud/instance /var/lib/cloud/instances/*")
                salt.cmdRun(venvPepper, '*apt*', "cloud-init init")

                retry(3, 5){
                    openstack.runOpenstackCommand("openstack server stop mcp-offline-mirror-${dateTime}", rcFile, openstackEnv)
                }

                retry(6, 30){
                    serverStatus = openstack.runOpenstackCommand("openstack server show --format value -c status mcp-offline-mirror-${dateTime}", rcFile, openstackEnv)
                    if(serverStatus != "SHUTOFF"){
                        throw new ResourceException("Instance is not ready for image create.")
                    }
                }
                retry(3, 5){
                    openstack.runOpenstackCommand("openstack server image create --name ${IMAGE_NAME}-${dateTime} --wait mcp-offline-mirror-${dateTime}", rcFile, openstackEnv)
                }
            }

            stage("Publish image"){
                common.infoMsg("Saving image ${IMAGE_NAME}-${dateTime}")
                retry(3, 5){
                    openstack.runOpenstackCommand("openstack image save --file ${IMAGE_NAME}-${dateTime}.qcow2 ${IMAGE_NAME}-${dateTime}", rcFile, openstackEnv)
                }
                sh "md5sum ${IMAGE_NAME}-${dateTime}.qcow2 > ${IMAGE_NAME}-${dateTime}.qcow2.md5"

                common.infoMsg("Uploading image ${IMAGE_NAME}-${dateTime}")
                retry(3, 5){
                    uploadImageStatus = sh(script: "curl -f -T ${IMAGE_NAME}-${dateTime}.qcow2 ${UPLOAD_URL}", returnStatus: true)
                    if(uploadImageStatus!=0){
                        throw new Exception("Image upload failed")
                    }
                }
                retry(3, 5){
                    uploadMd5Status = sh(script: "curl -f -T ${IMAGE_NAME}-${dateTime}.qcow2.md5 ${UPLOAD_URL}", returnStatus: true)
                    if(uploadMd5Status != 0){
                        throw new Exception("MD5 sum upload failed")
                    }
                }
                currentBuild.description = "<a href='http://ci.mcp.mirantis.net:8085/images/${IMAGE_NAME}-${dateTime}.qcow2'>${IMAGE_NAME}-${dateTime}.qcow2</a>"
            }

        } catch (Throwable e) {
            // If there was an error or exception thrown, the build failed
            currentBuild.result = "FAILURE"
            throw e
        } finally {
            stage("Cleanup"){
                if(openstackServer != ""){
                    openstack.runOpenstackCommand("openstack ip floating remove ${floatingIP} mcp-offline-mirror-${dateTime}", rcFile, openstackEnv)
                    openstack.runOpenstackCommand("openstack server delete mcp-offline-mirror-${dateTime}", rcFile, openstackEnv)
                }
                if(privateKey != ""){
                    openstack.runOpenstackCommand("openstack keypair delete mcp-offline-keypair-${dateTime}", rcFile, openstackEnv)
                }
                sh "rm -rf ./*"
            }
        }
    }
}