package com.mirantis.mk
/**
 * Orchestration functions
 *
*/

def validateFoundationInfra(master) {
    def salt = new com.mirantis.mk.Salt()

    salt.cmdRun(master, 'I@salt:master' ,'salt-key')
    salt.runSaltProcessStep(master, 'I@salt:minion', 'test.version')
    salt.cmdRun(master, 'I@salt:master' ,'reclass-salt --top')
    salt.runSaltProcessStep(master, 'I@reclass:storage', 'reclass.inventory')
    salt.runSaltProcessStep(master, 'I@salt:minion', 'state.show_top')
}

def installFoundationInfra(master, staticMgmtNet=false) {
    def salt = new com.mirantis.mk.Salt()
    def common = new com.mirantis.mk.Common()

    // NOTE(vsaienko) Apply reclass first, it may update cluster model
    // apply linux and salt.master salt.minion states afterwards to make sure
    // correct cluster model is used.
    salt.enforceState(master, 'I@salt:master', ['reclass'])

    salt.enforceState(master, 'I@salt:master', ['linux.system'])
    salt.enforceState(master, 'I@salt:master', ['salt.master'], true, false, null, false, 120, 2)
    salt.fullRefresh(master, "*")

    salt.enforceState(master, 'I@salt:master', ['salt.minion'], true, false, null, false, 60, 2)
    salt.enforceState(master, 'I@salt:master', ['salt.minion'])
    salt.fullRefresh(master, "*")
    salt.enforceState(master, '*', ['linux.network.proxy'], true, false, null, false, 60, 2)
    try {
        salt.enforceState(master, '*', ['salt.minion.base'], true, false, null, false, 60, 2)
        sleep(5)
    } catch (Throwable e) {
        common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
    }
    salt.enforceState(master, '*', ['linux.system'])
    if (staticMgmtNet) {
        salt.runSaltProcessStep(master, '*', 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
    }
    salt.enforceState(master, 'I@linux:network:interface', ['linux.network.interface'])
    salt.enforceState(master, 'I@linux:system', ['linux', 'openssh', 'ntp', 'rsyslog'])
    salt.enforceState(master, '*', ['salt.minion'], true, false, null, false, 60, 2)
    sleep(5)
    salt.runSaltProcessStep(master, '*', 'mine.update', [], null, true)
    salt.enforceState(master, '*', ['linux.network.host'])
}

def installFoundationInfraOnTarget(master, target, staticMgmtNet=false) {
    def salt = new com.mirantis.mk.Salt()
    def common = new com.mirantis.mk.Common()

    salt.enforceState(master, 'I@salt:master', ['reclass'], true, false, null, false, 120, 2)
    salt.fullRefresh(master, target)
    salt.enforceState(master, target, ['linux.network.proxy'], true, false, null, false, 60, 2)
    try {
        salt.enforceState(master, target, ['salt.minion.base'], true, false, null, false, 60, 2)
        sleep(5)
    } catch (Throwable e) {
        common.warningMsg('Salt state salt.minion.base is not present in the Salt-formula yet.')
    }
    salt.enforceState(master, target, ['linux.system'])
    if (staticMgmtNet) {
        salt.runSaltProcessStep(master, target, 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
    }
    salt.enforceState(master, target, ['salt.minion'], true, false, null, false, 60, 2)
    salt.enforceState(master, target, ['salt.minion'])
    salt.enforceState(master, target, ['linux.network.interface'])
    salt.enforceState(master, target, ['linux', 'openssh', 'ntp', 'rsyslog'])
    sleep(5)
    salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
    salt.enforceState(master, target, ['linux.network.host'])
}

def installInfraKvm(master) {
    def salt = new com.mirantis.mk.Salt()
    salt.fullRefresh(master, 'I@linux:system')

    salt.enforceState(master, 'I@salt:control', ['salt.minion'], true, false, null, false, 60, 2)
    salt.enforceState(master, 'I@salt:control', ['linux.system', 'linux.network', 'ntp', 'rsyslog'])
    salt.enforceState(master, 'I@salt:control', 'libvirt')
    salt.enforceState(master, 'I@salt:control', 'salt.control')

    sleep(600)

    salt.fullRefresh(master, '* and not kvm*')
}

def installInfra(master) {
    def common = new com.mirantis.mk.Common()
    def salt = new com.mirantis.mk.Salt()

    // Install glusterfs
    if (salt.testTarget(master, 'I@glusterfs:server')) {
        salt.enforceState(master, 'I@glusterfs:server', 'glusterfs.server.service')

        salt.enforceState(master, 'I@glusterfs:server and *01*', 'glusterfs.server.setup', true, true, null, false, -1, 5)
        sleep(10)
        salt.cmdRun(master, 'I@glusterfs:server', "gluster peer status; gluster volume status")
    }

    // Ensure glusterfs clusters is ready
    if (salt.testTarget(master, 'I@glusterfs:client')) {
        salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client')
    }

    // Install galera
    if (salt.testTarget(master, 'I@galera:master') || salt.testTarget(master, 'I@galera:slave')) {
        salt.enforceState(master, 'I@galera:master', 'galera', true, true, null, false, -1, 2)
        salt.enforceState(master, 'I@galera:slave', 'galera', true, true, null, false, -1, 2)

        // Check galera status
        salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
        salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
    // If galera is not enabled check if we need to install mysql:server
    } else if (salt.testTarget(master, 'I@mysql:server')){
        salt.enforceState(master, 'I@mysql:server', 'mysql.server')
        if (salt.testTarget(master, 'I@mysql:client')){
            salt.enforceState(master, 'I@mysql:client', 'mysql.client')
        }
    }
    installBackup(master, 'mysql')

    // Install docker
    if (salt.testTarget(master, 'I@docker:host')) {
        salt.enforceState(master, 'I@docker:host', 'docker.host')
        salt.cmdRun(master, 'I@docker:host', 'docker ps')
    }

    // Install keepalived
    if (salt.testTarget(master, 'I@keepalived:cluster')) {
        salt.enforceState(master, 'I@keepalived:cluster and *01*', 'keepalived')
        salt.enforceState(master, 'I@keepalived:cluster', 'keepalived')
    }

    // Install rabbitmq
    if (salt.testTarget(master, 'I@rabbitmq:server')) {
        salt.enforceState(master, 'I@rabbitmq:server', 'rabbitmq', true, true, null, false, -1, 2)

        // Check the rabbitmq status
        common.retry(3,5){
             salt.cmdRun(master, 'I@rabbitmq:server', 'rabbitmqctl cluster_status')
        }
    }

    // Install haproxy
    if (salt.testTarget(master, 'I@haproxy:proxy')) {
        salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
        salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])
        salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.restart', ['rsyslog'])
    }

    // Install memcached
    if (salt.testTarget(master, 'I@memcached:server')) {
        salt.enforceState(master, 'I@memcached:server', 'memcached')
    }

    // Install etcd
    if (salt.testTarget(master, 'I@etcd:server')) {
        salt.enforceState(master, 'I@etcd:server', 'etcd.server.service')
        common.retry(3,5){
            salt.cmdRun(master, 'I@etcd:server', '. /var/lib/etcd/configenv && etcdctl cluster-health')
        }
    }

    // Install redis
    if (salt.testTarget(master, 'I@redis:server')) {
        if (salt.testTarget(master, 'I@redis:cluster:role:master')) {
            salt.enforceState(master, 'I@redis:cluster:role:master', 'redis')
        }
        salt.enforceState(master, 'I@redis:server', 'redis')
    }
    installBackup(master, 'common')
}

def installOpenstackInfra(master) {
    def common = new com.mirantis.mk.Common()
    common.warningMsg("You calling orchestrate.installOpenstackInfra(). This function is deprecated please use orchestrate.installInfra() directly")
    installInfra(master)
}


def installOpenstackControl(master) {
    def salt = new com.mirantis.mk.Salt()
    def common = new com.mirantis.mk.Common()

    // Install horizon dashboard
    if (salt.testTarget(master, 'I@horizon:server')) {
        salt.enforceState(master, 'I@horizon:server', 'horizon')
    }
    // Install sphinx server
    if (salt.testTarget(master, 'I@sphinx:server')) {
        salt.enforceState(master, 'I@sphinx:server', 'sphinx')
    }
    if (salt.testTarget(master, 'I@nginx:server')) {
        salt.enforceState(master, 'I@nginx:server', 'salt.minion')
        salt.enforceState(master, 'I@nginx:server', 'nginx')
    }

    // setup keystone service
    if (salt.testTarget(master, 'I@keystone:server')) {
        salt.enforceState(master, 'I@keystone:server and *01*', 'keystone.server')
        salt.enforceState(master, 'I@keystone:server', 'keystone.server')
        // populate keystone services/tenants/roles/users

        // keystone:client must be called locally
        //salt.runSaltProcessStep(master, 'I@keystone:client', 'cmd.run', ['salt-call state.sls keystone.client'], null, true)
        salt.runSaltProcessStep(master, 'I@keystone:server', 'service.restart', ['apache2'])
        sleep(30)
    }
    if (salt.testTarget(master, 'I@keystone:client')) {
        salt.enforceState(master, 'I@keystone:client and *01*', 'keystone.client')
        salt.enforceState(master, 'I@keystone:client', 'keystone.client')
    }
    if (salt.testTarget(master, 'I@keystone:server')) {
        common.retry(3,5){
            salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; openstack service list')
        }
    }

    // Install glance
    if (salt.testTarget(master, 'I@glance:server')) {
        //runSaltProcessStep(master, 'I@glance:server', 'state.sls', ['glance.server'], 1)
        salt.enforceState(master, 'I@glance:server and *01*', 'glance.server')
       salt.enforceState(master, 'I@glance:server', 'glance.server')
    }

    // Check glance service
    if (salt.testTarget(master, 'I@glance:server')){
        common.retry(3,5){
            salt.cmdRun(master, 'I@keystone:server','. /root/keystonercv3; glance image-list')
        }
    }

    // Create glance resources
    if (salt.testTarget(master, 'I@glance:client')) {
        salt.enforceState(master, 'I@glance:client', 'glance.client')
    }

    // Install and check nova service
    if (salt.testTarget(master, 'I@nova:controller')) {
        // run on first node first
        salt.enforceState(master, 'I@nova:controller and *01*', 'nova.controller')
        salt.enforceState(master, 'I@nova:controller', 'nova.controller')
        if (salt.testTarget(master, 'I@keystone:server')) {
           common.retry(3,5){
               salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; nova service-list')
           }
        }
    }

    // Create nova resources
    if (salt.testTarget(master, 'I@nova:client')) {
        salt.enforceState(master, 'I@nova:client', 'nova.client')
    }

    // Install and check cinder service
    if (salt.testTarget(master, 'I@cinder:controller')) {
        // run on first node first
        salt.enforceState(master, 'I@cinder:controller and *01*', 'cinder')
        salt.enforceState(master, 'I@cinder:controller', 'cinder')
        if (salt.testTarget(master, 'I@keystone:server')) {
            common.retry(3,5){
                salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; cinder list')
            }
        }
    }

    // Install neutron service
    if (salt.testTarget(master, 'I@neutron:server')) {
        // run on first node first
        salt.enforceState(master, 'I@neutron:server and *01*', 'neutron.server')
        salt.enforceState(master, 'I@neutron:server', 'neutron.server')
        if (salt.testTarget(master, 'I@keystone:server')) {
            common.retry(3,5){
                salt.cmdRun(master, 'I@keystone:server','. /root/keystonercv3; neutron agent-list')
            }
        }
    }

    // Install heat service
    if (salt.testTarget(master, 'I@heat:server')) {
        // run on first node first
        salt.enforceState(master, 'I@heat:server and *01*', 'heat')
        salt.enforceState(master, 'I@heat:server', 'heat')
        if (salt.testTarget(master, 'I@keystone:server')) {
            common.retry(3,5){
                salt.cmdRun(master, 'I@keystone:server', '. /root/keystonercv3; heat resource-type-list')
            }
        }
    }

    // Restart nova api
    if (salt.testTarget(master, 'I@nova:controller')) {
        salt.runSaltProcessStep(master, 'I@nova:controller', 'service.restart', ['nova-api'])
    }

    // Install ironic service
    if (salt.testTarget(master, 'I@ironic:api')) {
        salt.enforceState(master, 'I@ironic:api and *01*', 'ironic.api')
        salt.enforceState(master, 'I@ironic:api', 'ironic.api')
    }

    // Install manila service
    if (salt.testTarget(master, 'I@manila:api')) {
        salt.enforceState(master, 'I@manila:api and *01*', 'manila.api')
        salt.enforceState(master, 'I@manila:api', 'manila.api')
    }
    if (salt.testTarget(master, 'I@manila:scheduler')) {
        salt.enforceState(master, 'I@manila:scheduler', 'manila.scheduler')
    }

    // Install designate services
    if (salt.testTarget(master, 'I@designate:server:enabled')) {
        if (salt.testTarget(master, 'I@designate:server:backend:bind9')) {
            salt.enforceState(master, 'I@bind:server', 'bind.server')
        }
        if (salt.testTarget(master, 'I@designate:server:backend:pdns4')) {
            salt.enforceState(master, 'I@powerdns:server', 'powerdns.server')
        }
        salt.enforceState(master, 'I@designate:server and *01*', 'designate.server')
        salt.enforceState(master, 'I@designate:server', 'designate')
    }

    // Install octavia api service
    if (salt.testTarget(master, 'I@octavia:api')) {
        salt.enforceState(master, 'I@octavia:api and *01*', 'octavia')
        salt.enforceState(master, 'I@octavia:api', 'octavia')
    }

    // Install DogTag server service
    if (salt.testTarget(master, 'I@dogtag:server')) {
        salt.enforceState(master, 'I@dogtag:server and *01*', 'dogtag.server')
        salt.enforceState(master, 'I@dogtag:server', 'dogtag.server')
    }

    // Install barbican server service
    if (salt.testTarget(master, 'I@barbican:server')) {
        salt.enforceState(master, 'I@barbican:server and *01*', 'barbican.server')
        salt.enforceState(master, 'I@barbican:server', 'barbican.server')
    }
    // Install barbican client
    if (salt.testTarget(master, 'I@barbican:client')) {
        salt.enforceState(master, 'I@barbican:client', 'barbican.client')
    }

    // Install gnocchi server
    if (salt.testTarget(master, 'I@gnocchi:server')) {
        salt.enforceState(master, 'I@gnocchi:server and *01*', 'gnocchi.server')
        salt.enforceState(master, 'I@gnocchi:server', 'gnocchi.server')
    }

    // Install gnocchi statsd
    if (salt.testTarget(master, 'I@gnocchi:statsd')) {
        salt.enforceState(master, 'I@gnocchi:statsd and *01*', 'gnocchi.statsd')
        salt.enforceState(master, 'I@gnocchi:statsd', 'gnocchi.statsd')
    }

    // Install panko server
    if (salt.testTarget(master, 'I@panko:server')) {
        salt.enforceState(master, 'I@panko:server and *01*', 'panko')
        salt.enforceState(master, 'I@panko:server', 'panko')
    }

    // Install ceilometer server
    if (salt.testTarget(master, 'I@ceilometer:server')) {
        salt.enforceState(master, 'I@ceilometer:server and *01*', 'ceilometer')
        salt.enforceState(master, 'I@ceilometer:server', 'ceilometer')
    }

    // Install aodh server
    if (salt.testTarget(master, 'I@aodh:server')) {
        salt.enforceState(master, 'I@aodh:server and *01*', 'aodh')
        salt.enforceState(master, 'I@aodh:server', 'aodh')
    }
}


def installIronicConductor(master){
    def salt = new com.mirantis.mk.Salt()

    if (salt.testTarget(master, 'I@ironic:conductor')) {
        salt.enforceState(master, 'I@ironic:conductor', 'ironic.conductor')
        salt.enforceState(master, 'I@ironic:conductor', 'apache')
    }
    if (salt.testTarget(master, 'I@tftpd_hpa:server')) {
        salt.enforceState(master, 'I@tftpd_hpa:server', 'tftpd_hpa')
    }

    if (salt.testTarget(master, 'I@nova:compute')) {
        salt.runSaltProcessStep(master, 'I@nova:compute', 'service.restart', ['nova-compute'])
    }

    if (salt.testTarget(master, 'I@baremetal_simulator:enabled')) {
        salt.enforceState(master, 'I@baremetal_simulator:enabled', 'baremetal_simulator')
    }
    if (salt.testTarget(master, 'I@ironic:client')) {
        salt.enforceState(master, 'I@ironic:client', 'ironic.client')
    }
}

def installManilaShare(master){
    def salt = new com.mirantis.mk.Salt()

    if (salt.testTarget(master, 'I@manila:share')) {
        salt.enforceState(master, 'I@manila:share', 'manila.share')
    }
    if (salt.testTarget(master, 'I@manila:data')) {
        salt.enforceState(master, 'I@manila:data', 'manila.data')
    }

    if (salt.testTarget(master, 'I@manila:client')) {
        salt.enforceState(master, 'I@manila:client', 'manila.client')
    }
}


def installOpenstackNetwork(master, physical = "false") {
    def salt = new com.mirantis.mk.Salt()
    //run full neutron state on neutron.gateway - this will install
    //neutron agents in addition to neutron server. Once neutron agents
    //are up neutron resources can be created without hitting the situation when neutron resources are created
    //prior to neutron agents which results in creating ports in non-usable state
    if (salt.testTarget(master, 'I@neutron:gateway')) {
            salt.enforceState(master, 'I@neutron:gateway', 'neutron')
    }

    // Create neutron resources - this step was moved here to ensure that
    //neutron resources are created after neutron agens are up. In this case neutron ports will be in
    //usable state. More information: https://bugs.launchpad.net/neutron/+bug/1399249
    if (salt.testTarget(master, 'I@neutron:client')) {
        salt.enforceState(master, 'I@neutron:client', 'neutron.client')
    }

    salt.enforceHighstate(master, 'I@neutron:gateway')

    // install octavia manager services
    if (salt.testTarget(master, 'I@octavia:manager')) {
        salt.runSaltProcessStep(master, 'I@salt:master', 'mine.update', ['*'])
        salt.enforceState(master, 'I@octavia:manager', 'octavia')
        salt.enforceState(master, 'I@octavia:manager', 'salt.minion.ca')
        salt.enforceState(master, 'I@octavia:manager', 'salt.minion.cert')
    }
}


def installOpenstackCompute(master) {
    def salt = new com.mirantis.mk.Salt()
    // Configure compute nodes
    def compute_compound = 'I@nova:compute'
    if (salt.testTarget(master, compute_compound)) {
        // In case if infrastructure nodes are used as nova computes too
        def gluster_compound = 'I@glusterfs:server'
        // Enforce highstate asynchronous only on compute nodes which are not glusterfs servers
        retry(2) {
            salt.enforceHighstateWithExclude(master, compute_compound + ' and not ' + gluster_compound, 'opencontrail.client')
        }
        // Iterate through glusterfs servers and check if they have compute role
        // TODO: switch to batch once salt 2017.7+ would be used
        for ( target in salt.getMinionsSorted(master, gluster_compound) ) {
            for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
                if ( target == cmp_target ) {
                    // Enforce highstate one by one on glusterfs servers which are compute nodes
                    retry(2) {
                        salt.enforceHighstateWithExclude(master, target, 'opencontrail.client')
                    }
                }
            }
        }
    }
}


def installContrailNetwork(master) {
    def common = new com.mirantis.mk.Common()
    def salt = new com.mirantis.mk.Salt()


    // Install opencontrail database services
    salt.enforceState(master, 'I@opencontrail:database and *01*', 'opencontrail.database')
    salt.enforceState(master, 'I@opencontrail:database', 'opencontrail.database')

    // Install opencontrail control services
    salt.enforceStateWithExclude(master, "I@opencontrail:control and *01*", "opencontrail", "opencontrail.client")
    salt.enforceStateWithExclude(master, "I@opencontrail:control", "opencontrail", "opencontrail.client")
    salt.enforceStateWithExclude(master, "I@opencontrail:collector and *01*", "opencontrail", "opencontrail.client")

    if (salt.testTarget(master, 'I@docker:client and I@opencontrail:control')) {
        salt.enforceState(master, 'I@opencontrail:control or I@opencontrail:collector', 'docker.client')
    }
    installBackup(master, 'contrail')
}


def installContrailCompute(master) {
    def salt = new com.mirantis.mk.Salt()
    def common = new com.mirantis.mk.Common()
    // Configure compute nodes
    // Provision opencontrail control services
    salt.enforceState(master, 'I@opencontrail:database:id:1', 'opencontrail.client')
    // Provision opencontrail virtual routers

    // Generate script /usr/lib/contrail/if-vhost0 for up vhost0
    if (salt.testTarget(master, 'I@opencontrail:compute')) {
        salt.enforceStateWithExclude(master, "I@opencontrail:compute", "opencontrail", "opencontrail.client")
    }

    if (salt.testTarget(master, 'I@nova:compute')) {
        salt.cmdRun(master, 'I@nova:compute', 'exec 0>&-; exec 1>&-; exec 2>&-; nohup bash -c "ip link | grep vhost && echo no_reboot || sleep 5 && reboot & "', false)
    }

    sleep(300)
    if (salt.testTarget(master, 'I@opencontrail:compute')) {
        salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail.client')
        salt.enforceState(master, 'I@opencontrail:compute', 'opencontrail')
    }
}


def installKubernetesInfra(master) {
    def common = new com.mirantis.mk.Common()
    common.warningMsg("You calling orchestrate.installKubernetesInfra(). This function is deprecated please use orchestrate.installInfra() directly")
    installInfra(master)
}


def installKubernetesControl(master) {
    def salt = new com.mirantis.mk.Salt()

    // Install Kubernetes pool and Calico
    salt.enforceState(master, 'I@kubernetes:master', 'kubernetes.master.kube-addons')
    salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')

    if (salt.testTarget(master, 'I@etcd:server:setup')) {
        // Setup etcd server
        salt.enforceState(master, 'I@kubernetes:master and *01*', 'etcd.server.setup')
    }

    // Run k8s without master.setup
    salt.enforceStateWithExclude(master, 'I@kubernetes:master', "kubernetes", "kubernetes.master.setup")

    // Run k8s master setup
    salt.enforceState(master, 'I@kubernetes:master and *01*', 'kubernetes.master.setup')

    // Restart kubelet
    salt.runSaltProcessStep(master, 'I@kubernetes:pool', 'service.restart', ['kubelet'])
}


def installKubernetesCompute(master) {
    def salt = new com.mirantis.mk.Salt()
    salt.fullRefresh(master, "*")

    // Bootstrap all nodes
    salt.enforceState(master, 'I@kubernetes:pool', 'linux')
    salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion')
    salt.enforceState(master, 'I@kubernetes:pool', ['openssh', 'ntp'])

    // Create and distribute SSL certificates for services using salt state
    salt.enforceState(master, 'I@kubernetes:pool', 'salt.minion.cert')

    // Install docker
    salt.enforceState(master, 'I@docker:host', 'docker.host')

    // Install Kubernetes and Calico
    salt.enforceState(master, 'I@kubernetes:pool', 'kubernetes.pool')

    // Install Tiller and all configured releases
    if (salt.testTarget(master, 'I@helm:client')) {
        salt.enforceState(master, 'I@helm:client', 'helm')
    }
}


def installDockerSwarm(master) {
    def salt = new com.mirantis.mk.Salt()

    //Install and Configure Docker
    salt.enforceState(master, 'I@docker:swarm', 'docker.host')
    salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm')
    salt.enforceState(master, 'I@docker:swarm', 'salt.minion.grains')
    salt.runSaltProcessStep(master, 'I@docker:swarm', 'mine.update')
    salt.runSaltProcessStep(master, 'I@docker:swarm', 'saltutil.refresh_modules')
    sleep(5)
    salt.enforceState(master, 'I@docker:swarm:role:master', 'docker.swarm')
    salt.enforceState(master, 'I@docker:swarm:role:manager', 'docker.swarm')
    sleep(10)
    salt.cmdRun(master, 'I@docker:swarm:role:master', 'docker node ls')
}


def installCicd(master) {
    def salt = new com.mirantis.mk.Salt()
    salt.fullRefresh(master, 'I@jenkins:client or I@gerrit:client')

    if (salt.testTarget(master, 'I@aptly:publisher')) {
        salt.enforceState(master, 'I@aptly:publisher', 'aptly.publisher',true, null, false, -1, 2)
    }

    salt.enforceState(master, 'I@docker:swarm:role:master and I@jenkins:client', 'docker.client', true, true, null, false, -1, 2)
    sleep(500)

    if (salt.testTarget(master, 'I@aptly:server')) {
        salt.enforceState(master, 'I@aptly:server', 'aptly', true, true, null, false, -1, 2)
    }

    if (salt.testTarget(master, 'I@openldap:client')) {
        salt.enforceState(master, 'I@openldap:client', 'openldap', true, true, null, false, -1, 2)
    }

    if (salt.testTarget(master, 'I@python:environment')) {
        salt.enforceState(master, 'I@python:environment', 'python')
    }

    withEnv(['ASK_ON_ERROR=false']){
        retry(2){
            try{
                salt.enforceState(master, 'I@gerrit:client', 'gerrit')
            }catch(e){
                salt.fullRefresh(master, 'I@gerrit:client')
                throw e //rethrow for retry handler
            }
        }
        retry(2){
            try{
                salt.enforceState(master, 'I@jenkins:client', 'jenkins')
            }catch(e){
                salt.fullRefresh(master, 'I@jenkins:client')
                throw e //rethrow for retry handler
            }
        }
    }
}


def installStacklight(master) {
    def common = new com.mirantis.mk.Common()
    def salt = new com.mirantis.mk.Salt()

    // Install core services for K8S environments:
    // HAProxy, Nginx and lusterFS clients
    // In case of OpenStack, those are already installed
    if (common.checkContains('STACK_INSTALL', 'k8s')) {
        salt.enforceState(master, 'I@haproxy:proxy', 'haproxy')
        salt.runSaltProcessStep(master, 'I@haproxy:proxy', 'service.status', ['haproxy'])

        if (salt.testTarget(master, 'I@nginx:server')) {
            salt.enforceState(master, 'I@nginx:server', 'nginx')
        }

        if (salt.testTarget(master, 'I@glusterfs:client')) {
            salt.enforceState(master, 'I@glusterfs:client', 'glusterfs.client')
        }
    }

    // Launch containers
    salt.enforceState(master, 'I@docker:swarm:role:master and I@prometheus:server', 'docker.client')
    salt.runSaltProcessStep(master, 'I@docker:swarm and I@prometheus:server', 'dockerng.ps')

    //Install Telegraf
    salt.enforceState(master, 'I@telegraf:agent or I@telegraf:remote_agent', 'telegraf')

    // Install Prometheus exporters
    if (salt.testTarget(master, 'I@prometheus:exporters')) {
        salt.enforceState(master, 'I@prometheus:exporters', 'prometheus')
    }

    //Install Elasticsearch and Kibana
    salt.enforceState(master, '*01* and  I@elasticsearch:server', 'elasticsearch.server')
    salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server')
    salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server')
    salt.enforceState(master, 'I@kibana:server', 'kibana.server')
    salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client')
    salt.enforceState(master, 'I@kibana:client', 'kibana.client')

    //Install InfluxDB
    if (salt.testTarget(master, 'I@influxdb:server')) {
        salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb')
        salt.enforceState(master, 'I@influxdb:server', 'influxdb')
    }

    //Install Prometheus LTS
    if (salt.testTarget(master, 'I@prometheus:relay')) {
        salt.enforceState(master, 'I@prometheus:relay', 'prometheus')
    }

    // Install service for the log collection
    if (salt.testTarget(master, 'I@fluentd:agent')) {
        salt.enforceState(master, 'I@fluentd:agent', 'fluentd')
    } else {
        salt.enforceState(master, 'I@heka:log_collector', 'heka.log_collector')
    }

    // Install heka ceilometer collector
    if (salt.testTarget(master, 'I@heka:ceilometer_collector:enabled')) {
        salt.enforceState(master, 'I@heka:ceilometer_collector:enabled', 'heka.ceilometer_collector')
        salt.runSaltProcessStep(master, 'I@heka:ceilometer_collector:enabled', 'service.restart', ['ceilometer_collector'], null, true)
    }

    // Install galera
    if (common.checkContains('STACK_INSTALL', 'k8s')) {
        salt.enforceState(master, 'I@galera:master', 'galera', true, true, null, false, -1, 2)
        salt.enforceState(master, 'I@galera:slave', 'galera', true, true, null, false, -1, 2)

        // Check galera status
        salt.runSaltProcessStep(master, 'I@galera:master', 'mysql.status')
        salt.runSaltProcessStep(master, 'I@galera:slave', 'mysql.status')
    }

    //Collect Grains
    salt.enforceState(master, 'I@salt:minion', 'salt.minion.grains')
    salt.runSaltProcessStep(master, 'I@salt:minion', 'saltutil.refresh_modules')
    salt.runSaltProcessStep(master, 'I@salt:minion', 'mine.update')
    sleep(5)

    // Configure Prometheus in Docker Swarm
    salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', 'prometheus')

    //Configure Remote Collector in Docker Swarm for Openstack deployments
    if (!common.checkContains('STACK_INSTALL', 'k8s')) {
        salt.enforceState(master, 'I@docker:swarm and I@prometheus:server', 'heka.remote_collector', true, false)
    }

    // Install sphinx server
    if (salt.testTarget(master, 'I@sphinx:server')) {
        salt.enforceState(master, 'I@sphinx:server', 'sphinx')
    }

    //Configure Grafana
    def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
    common.prettyPrint(pillar)

    def stacklight_vip
    if(!pillar['return'].isEmpty()) {
        stacklight_vip = pillar['return'][0].values()[0]
    } else {
        common.errorMsg('[ERROR] Stacklight VIP address could not be retrieved')
    }

    common.infoMsg("Waiting for service on http://${stacklight_vip}:15013/ to start")
    sleep(120)
    salt.enforceState(master, 'I@grafana:client', 'grafana.client')
}

def installStacklightv1Control(master) {
    def salt = new com.mirantis.mk.Salt()

    // infra install
    // Install the StackLight backends
    salt.enforceState(master, '*01* and  I@elasticsearch:server', 'elasticsearch.server')
    salt.enforceState(master, 'I@elasticsearch:server', 'elasticsearch.server')

    salt.enforceState(master, '*01* and I@influxdb:server', 'influxdb')
    salt.enforceState(master, 'I@influxdb:server', 'influxdb')

    salt.enforceState(master, '*01* and I@kibana:server', 'kibana.server')
    salt.enforceState(master, 'I@kibana:server', 'kibana.server')

    salt.enforceState(master, '*01* and I@grafana:server','grafana.server')
    salt.enforceState(master, 'I@grafana:server','grafana.server')

    def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
    def alarming_service = alarming_service_pillar['return'][0].values()[0]

    switch (alarming_service) {
        case 'sensu':
            // Update Sensu
            salt.enforceState(master, 'I@sensu:server and I@rabbitmq:server', 'rabbitmq')
            salt.enforceState(master, 'I@redis:cluster:role:master', 'redis')
            salt.enforceState(master, 'I@redis:server', 'redis')
            salt.enforceState(master, 'I@sensu:server', 'sensu')
        default:
            // Update Nagios
            salt.enforceState(master, 'I@nagios:server', 'nagios.server')
            // Stop the Nagios service because the package starts it by default and it will
            // started later only on the node holding the VIP address
            salt.runSaltProcessStep(master, 'I@nagios:server', 'service.stop', ['nagios3'], null, true)
    }

    salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client.service')
    salt.enforceState(master, 'I@kibana:client', 'kibana.client')

    sleep(10)
}

def installStacklightv1Client(master) {
    def salt = new com.mirantis.mk.Salt()
    def common = new com.mirantis.mk.Common()

    salt.cmdRun(master, 'I@elasticsearch:client', 'salt-call state.sls elasticsearch.client')
    // salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client', true)
    salt.cmdRun(master, 'I@kibana:client', 'salt-call state.sls kibana.client')
    // salt.enforceState(master, 'I@kibana:client', 'kibana.client', true)

    // Install collectd, heka and sensu services on the nodes, this will also
    // generate the metadata that goes into the grains and eventually into Salt Mine
    salt.enforceState(master, '*', 'collectd')
    salt.enforceState(master, '*', 'salt.minion')
    salt.enforceState(master, '*', 'heka')

    // Gather the Grafana metadata as grains
    salt.enforceState(master, 'I@grafana:collector', 'grafana.collector', true)

    // Update Salt Mine
    salt.enforceState(master, '*', 'salt.minion.grains')
    salt.runSaltProcessStep(master, '*', 'saltutil.refresh_modules')
    salt.runSaltProcessStep(master, '*', 'mine.update')

    sleep(5)

    // Update Heka
    salt.enforceState(master, 'I@heka:aggregator:enabled:True or I@heka:remote_collector:enabled:True', 'heka')

    // Update collectd
    salt.enforceState(master, 'I@collectd:remote_client:enabled:True', 'collectd')

    def alarming_service_pillar = salt.getPillar(master, 'mon*01*', '_param:alarming_service')
    def alarming_service = alarming_service_pillar['return'][0].values()[0]

    switch (alarming_service) {
        case 'sensu':
            // Update Sensu
            // TODO for stacklight team, should be fixed in model
            salt.enforceState(master, 'I@sensu:client', 'sensu')
        default:
            break
            // Default is nagios, and was enforced in installStacklightControl()
    }

    salt.cmdRun(master, 'I@grafana:client and *01*', 'salt-call state.sls grafana.client')
    // salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client', true)

    // Finalize the configuration of Grafana (add the dashboards...)
    salt.enforceState(master, 'I@grafana:client and *01*', 'grafana.client')
    salt.enforceState(master, 'I@grafana:client and *02*', 'grafana.client')
    salt.enforceState(master, 'I@grafana:client and *03*', 'grafana.client')
    // nw salt -C 'I@grafana:client' --async service.restart salt-minion; sleep 10

    // Get the StackLight monitoring VIP addres
    //vip=$(salt-call pillar.data _param:stacklight_monitor_address --out key|grep _param: |awk '{print $2}')
    //vip=${vip:=172.16.10.253}
    def pillar = salt.getPillar(master, 'ctl01*', '_param:stacklight_monitor_address')
    common.prettyPrint(pillar)
    def stacklight_vip = pillar['return'][0].values()[0]

    if (stacklight_vip) {
        // (re)Start manually the services that are bound to the monitoring VIP
        common.infoMsg("restart services on node with IP: ${stacklight_vip}")
        salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collectd'])
        salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['remote_collector'])
        salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['aggregator'])
        salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip}", 'service.restart', ['nagios3'])
    } else {
        throw new Exception("Missing stacklight_vip")
    }
}

//
// backups
//

def installBackup(master, component='common') {
    def salt = new com.mirantis.mk.Salt()
    if (component == 'common') {
        // Install Backupninja
        if (salt.testTarget(master, 'I@backupninja:client')) {
            salt.enforceState(master, 'I@backupninja:client', 'salt.minion.grains')
            salt.runSaltProcessStep(master, 'I@backupninja:client', 'saltutil.sync_grains')
            salt.runSaltProcessStep(master, 'I@backupninja:client', 'mine.flush')
            salt.runSaltProcessStep(master, 'I@backupninja:client', 'mine.update')
            salt.enforceState(master, 'I@backupninja:client', 'backupninja')
        }
        if (salt.testTarget(master, 'I@backupninja:server')) {
            salt.enforceState(master, 'I@backupninja:server', 'salt.minion.grains')
            salt.enforceState(master, 'I@backupninja:server', 'backupninja')
        }
    } else if (component == 'mysql') {
        // Install Xtrabackup
        if (salt.testTarget(master, 'I@xtrabackup:client')) {
            salt.enforceState(master, 'I@xtrabackup:client', 'salt.minion.grains')
            salt.runSaltProcessStep(master, 'I@xtrabackup:client', 'saltutil.sync_grains')
            salt.runSaltProcessStep(master, 'I@xtrabackup:client', 'mine.flush')
            salt.runSaltProcessStep(master, 'I@xtrabackup:client', 'mine.update')
            salt.enforceState(master, 'I@xtrabackup:client', 'xtrabackup')
        }
        if (salt.testTarget(master, 'I@xtrabackup:server')) {
            salt.enforceState(master, 'I@xtrabackup:server', 'xtrabackup')
        }
    } else if (component == 'contrail') {

        // Install Cassandra backup
        if (salt.testTarget(master, 'I@cassandra:backup:client')) {
            salt.enforceState(master, 'I@cassandra:backup:client', 'salt.minion.grains')
            salt.runSaltProcessStep(master, 'I@cassandra:backup:client', 'saltutil.sync_grains')
            salt.runSaltProcessStep(master, 'I@cassandra:backup:client', 'mine.flush')
            salt.runSaltProcessStep(master, 'I@cassandra:backup:client', 'mine.update')
            salt.enforceState(master, 'I@cassandra:backup:client', 'cassandra.backup')
        }
        if (salt.testTarget(master, 'I@cassandra:backup:server')) {
            salt.enforceState(master, 'I@cassandra:backup:server', 'cassandra.backup')
        }
        // Install Zookeeper backup
        if (salt.testTarget(master, 'I@zookeeper:backup:client')) {
            salt.enforceState(master, 'I@zookeeper:backup:client', 'salt.minion.grains')
            salt.runSaltProcessStep(master, 'I@zookeeper:backup:client', 'saltutil.sync_grains')
            salt.runSaltProcessStep(master, 'I@zookeeper:backup:client', 'mine.flush')
            salt.runSaltProcessStep(master, 'I@zookeeper:backup:client', 'mine.update')
            salt.enforceState(master, 'I@zookeeper:backup:client', 'zookeeper.backup')
        }
        if (salt.testTarget(master, 'I@zookeeper:backup:server')) {
            salt.enforceState(master, 'I@zookeeper:backup:server', 'zookeeper.backup')
        }
    } else if (component == 'ceph') {
        // Install Ceph backup
        if (salt.testTarget(master, 'I@ceph:backup:client')) {
            salt.enforceState(master, 'I@ceph:backup:client', 'salt.minion.grains')
            salt.runSaltProcessStep(master, 'I@ceph:backup:client', 'saltutil.sync_grains')
            salt.runSaltProcessStep(master, 'I@ceph:backup:client', 'mine.flush')
            salt.runSaltProcessStep(master, 'I@ceph:backup:client', 'mine.update')
            salt.enforceState(master, 'I@ceph:backup:client', 'ceph.backup')
        }
        if (salt.testTarget(master, 'I@ceph:backup:server')) {
            salt.enforceState(master, 'I@ceph:backup:server', 'ceph.backup')
        }
    }

}

//
// Ceph
//

def installCephMon(master, target='I@ceph:mon') {
    def salt = new com.mirantis.mk.Salt()

    salt.enforceState(master, 'I@ceph:common', 'salt.minion.grains')

    // generate keyrings
    if (salt.testTarget(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin')) {
        salt.enforceState(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin', 'ceph.mon')
        salt.runSaltProcessStep(master, 'I@ceph:mon', 'saltutil.sync_grains')
        salt.runSaltProcessStep(master, 'I@ceph:mon:keyring:mon or I@ceph:common:keyring:admin', 'mine.update')
        sleep(5)
    }
    // install Ceph Mons
    salt.enforceState(master, target, 'ceph.mon')
    if (salt.testTarget(master, 'I@ceph:mgr')) {
        salt.enforceState(master, 'I@ceph:mgr', 'ceph.mgr')
    }
}

def installCephOsd(master, target='I@ceph:osd', setup=true) {
    def salt = new com.mirantis.mk.Salt()

    // install Ceph OSDs
    salt.enforceState(master, target, 'ceph.osd')
    salt.runSaltProcessStep(master, 'I@ceph:osd', 'saltutil.sync_grains')
    salt.enforceState(master, target, 'ceph.osd.custom')
    salt.runSaltProcessStep(master, 'I@ceph:osd', 'saltutil.sync_grains')
    salt.runSaltProcessStep(master, 'I@ceph:osd', 'mine.update')
    installBackup(master, 'ceph')

    // setup pools, keyrings and maybe crush
    if (salt.testTarget(master, 'I@ceph:setup') && setup) {
        sleep(5)
        salt.enforceState(master, 'I@ceph:setup', 'ceph.setup')
    }
}

def installCephClient(master) {
    def salt = new com.mirantis.mk.Salt()

    // install Ceph Radosgw
    if (salt.testTarget(master, 'I@ceph:radosgw')) {
        salt.runSaltProcessStep(master, 'I@ceph:radosgw', 'saltutil.sync_grains')
        salt.enforceState(master, 'I@ceph:radosgw', 'ceph.radosgw')
    }
    // setup Keystone service and endpoints for swift or / and S3
    if (salt.testTarget(master, 'I@keystone:client')) {
        salt.enforceState(master, 'I@keystone:client', 'keystone.client')
    }
}

def connectCeph(master) {
    def salt = new com.mirantis.mk.Salt()

    // connect Ceph to the env
    if (salt.testTarget(master, 'I@ceph:common and I@glance:server')) {
        salt.enforceState(master, 'I@ceph:common and I@glance:server', ['ceph.common', 'ceph.setup.keyring', 'glance'])
        salt.runSaltProcessStep(master, 'I@ceph:common and I@glance:server', 'service.restart', ['glance-api', 'glance-glare', 'glance-registry'])
    }
    if (salt.testTarget(master, 'I@ceph:common and I@cinder:controller')) {
        salt.enforceState(master, 'I@ceph:common and I@cinder:controller', ['ceph.common', 'ceph.setup.keyring', 'cinder'])
    }
    if (salt.testTarget(master, 'I@ceph:common and I@nova:compute')) {
        salt.enforceState(master, 'I@ceph:common and I@nova:compute', ['ceph.common', 'ceph.setup.keyring'])
        salt.runSaltProcessStep(master, 'I@ceph:common and I@nova:compute', 'saltutil.sync_grains')
        salt.enforceState(master, 'I@ceph:common and I@nova:compute', ['nova'])
    }
}

def installOssInfra(master) {
  def common = new com.mirantis.mk.Common()
  def salt = new com.mirantis.mk.Salt()

  if (!common.checkContains('STACK_INSTALL', 'k8s') || !common.checkContains('STACK_INSTALL', 'openstack')) {
    def orchestrate = new com.mirantis.mk.Orchestrate()
    orchestrate.installInfra(master)
  }

  if (salt.testTarget(master, 'I@devops_portal:config')) {
    salt.enforceState(master, 'I@devops_portal:config', 'devops_portal.config')
    salt.enforceState(master, 'I@rundeck:client', ['linux.system.user', 'openssh'])
    salt.enforceState(master, 'I@rundeck:server', 'rundeck.server')
  }
}

def installOss(master) {
  def common = new com.mirantis.mk.Common()
  def salt = new com.mirantis.mk.Salt()

  //Get oss VIP address
  def pillar = salt.getPillar(master, 'cfg01*', '_param:stacklight_monitor_address')
  common.prettyPrint(pillar)

  def oss_vip
  if(!pillar['return'].isEmpty()) {
      oss_vip = pillar['return'][0].values()[0]
  } else {
      common.errorMsg('[ERROR] Oss VIP address could not be retrieved')
  }

  // Postgres client - initialize OSS services databases
  timeout(120){
    common.infoMsg("Waiting for postgresql database to come up..")
    salt.cmdRun(master, 'I@postgresql:client', 'while true; do if docker service logs postgresql_postgresql-db 2>&1 | grep "ready to accept"; then break; else sleep 5; fi; done')
  }
  // XXX: first run usually fails on some inserts, but we need to create databases at first
  salt.enforceState(master, 'I@postgresql:client', 'postgresql.client', true, false)

  // Setup postgres database with integration between
  // Pushkin notification service and Security Monkey security audit service
  timeout(10) {
    common.infoMsg("Waiting for Pushkin to come up..")
    salt.cmdRun(master, 'I@postgresql:client', "while true; do curl -sf ${oss_vip}:8887/apps >/dev/null && break; done")
  }
  salt.enforceState(master, 'I@postgresql:client', 'postgresql.client')

  // Rundeck
  timeout(10) {
    common.infoMsg("Waiting for Rundeck to come up..")
    salt.cmdRun(master, 'I@rundeck:client', "while true; do curl -sf ${oss_vip}:4440 >/dev/null && break; done")
  }
  salt.enforceState(master, 'I@rundeck:client', 'rundeck.client')

  // Elasticsearch
  pillar = salt.getPillar(master, 'I@elasticsearch:client', 'elasticsearch:client:server:host')
  def elasticsearch_vip
  if(!pillar['return'].isEmpty()) {
    elasticsearch_vip = pillar['return'][0].values()[0]
  } else {
    common.errorMsg('[ERROR] Elasticsearch VIP address could not be retrieved')
  }

  timeout(10) {
    common.infoMsg('Waiting for Elasticsearch to come up..')
    salt.cmdRun(master, 'I@elasticsearch:client', "while true; do curl -sf ${elasticsearch_vip}:9200 >/dev/null && break; done")
  }
  salt.enforceState(master, 'I@elasticsearch:client', 'elasticsearch.client')
}
