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

/**
 * Function runs Salt states to check infra
 * @param master Salt Connection object or pepperEnv
 * @param extra_tgt Extra target - adds ability to address commands using extra targeting to different clouds, e.g.: salt -C 'I@keystone:server and *ogrudev-deploy-heat-os-ha-ovs-82*' ...
 */
def validateFoundationInfra(master, extra_tgt = '') {
    def salt = new com.mirantis.mk.Salt()

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

def installFoundationInfra(master, staticMgmtNet=false, extra_tgt = '') {
    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 ${extra_tgt}", ['reclass'])

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

    salt.enforceState(master, "I@salt:master ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
    salt.enforceState(master, "I@salt:master ${extra_tgt}", ['salt.minion'])
    salt.fullRefresh(master, "* ${extra_tgt}")
    salt.enforceState(master, "* ${extra_tgt}", ['linux.network.proxy'], true, false, null, false, 60, 2)
    try {
        salt.enforceState(master, "* ${extra_tgt}", ['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.')
    }
    common.retry(2,5){
        salt.enforceState(master, "* ${extra_tgt}", ['linux.system'])
    }
    if (staticMgmtNet) {
        salt.runSaltProcessStep(master, "* ${extra_tgt}", 'cmd.shell', ["salt-call state.sls linux.network; salt-call service.restart salt-minion"], null, true, 60)
    }
    salt.enforceState(master, "I@linux:network:interface ${extra_tgt}", ['linux.network.interface'])
    sleep(5)
    salt.enforceState(master, "I@linux:system ${extra_tgt}", ['linux', 'openssh', 'ntp', 'rsyslog'])
    salt.enforceState(master, "* ${extra_tgt}", ['salt.minion'], true, false, null, false, 60, 2)
    sleep(5)

    salt.fullRefresh(master, "* ${extra_tgt}")
    salt.runSaltProcessStep(master, "* ${extra_tgt}", 'mine.update', [], null, true)
    salt.enforceState(master, "* ${extra_tgt}", ['linux.network.host'])

    // Install and configure iptables
    if (salt.testTarget(master, "I@iptables:service ${extra_tgt}")) {
        salt.enforceState(master, "I@iptables:service ${extra_tgt}", 'iptables')
    }

    // Install and configure logrotate
    if (salt.testTarget(master, "I@logrotate:server ${extra_tgt}")) {
        salt.enforceState(master, "I@logrotate:server ${extra_tgt}", 'logrotate')
    }

    // Install and configure auditd
    if (salt.testTarget(master, "I@auditd:service ${extra_tgt}")) {
        salt.enforceState(master, "I@auditd:service ${extra_tgt}", 'auditd')
    }
}

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

    salt.enforceState(master, "I@salt:master ${extra_tgt}", ['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.')
    }
    common.retry(2,5){
        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'])
    sleep(5)
    salt.enforceState(master, target, ['linux', 'openssh', 'ntp', 'rsyslog'])
    sleep(5)

    salt.fullRefresh(master, target)
    salt.runSaltProcessStep(master, target, 'mine.update', [], null, true)
    salt.enforceState(master, target, ['linux.network.host'])
}

def installInfraKvm(master, extra_tgt = '') {
    def common = new com.mirantis.mk.Common()
    def salt = new com.mirantis.mk.Salt()
    def infra_compound = "I@salt:control ${extra_tgt}"
    def minions = []
    def wait_timeout = 10
    def retries = wait_timeout * 30

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

    common.infoMsg("Building minions list...")
    if (salt.testTarget(master, infra_compound)) {
        // Gathering minions
        for ( infra_node in salt.getMinionsSorted(master, infra_compound) ) {
            def pillar = salt.getPillar(master, infra_node, 'salt:control:cluster')
            if ( !pillar['return'].isEmpty() ) {
                for ( cluster in pillar['return'][0].values() ) {
                    def engine = cluster.values()[0]['engine']
                    def domain = cluster.values()[0]['domain']
                    def node = cluster.values()[0]['node']
                    if ( engine == "virt" ) {
                        def nodes = node.values()
                        if ( !nodes.isEmpty() ) {
                            for ( vm in nodes ) {
                                if ( vm['name'] != null ) {
                                    def vm_fqdn = vm['name'] + '.' + domain
                                    if ( !minions.contains(vm_fqdn) ) {
                                        minions.add(vm_fqdn)
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    def minions_compound = minions.join(' or ')

    common.infoMsg("Waiting for next minions to register within ${wait_timeout} minutes: " + minions_compound)
    timeout(time: wait_timeout, unit: 'MINUTES') {
        salt.minionsPresentFromList(master, "I@salt:master ${extra_tgt}", minions, true, null, true, retries, 1)
    }

    common.infoMsg('Waiting for minions to respond')
    timeout(time: wait_timeout, unit: 'MINUTES') {
        salt.minionsReachable(master, "I@salt:master ${extra_tgt}", minions_compound)
    }

    common.infoMsg("All minions are up.")
    salt.fullRefresh(master, "* and not kvm* ${extra_tgt}")

}

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

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

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

    // Ensure glusterfs clusters is ready
    if (salt.testTarget(master, "I@glusterfs:client ${extra_tgt}")) {
        salt.enforceState(master, "I@glusterfs:client ${extra_tgt}", 'glusterfs.client', true, true, null, false, -1, 2)
    }

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

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

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

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

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

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

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

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

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

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

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


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

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

    // setup keystone service
    if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
        salt.enforceState(master, "I@keystone:server and *01* ${extra_tgt}", 'keystone.server')
        salt.enforceState(master, "I@keystone:server ${extra_tgt}", '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 ${extra_tgt}", 'service.restart', ['apache2'])
        sleep(30)
    }
    if (salt.testTarget(master, "I@keystone:client ${extra_tgt}")) {
        salt.enforceState(master, "I@keystone:client and *01* ${extra_tgt}", 'keystone.client')
        salt.enforceState(master, "I@keystone:client ${extra_tgt}", 'keystone.client')
    }
    if (salt.testTarget(master, "I@keystone:server ${extra_tgt}")) {
        common.retry(3,5){
            salt.cmdRun(master, "I@keystone:server ${extra_tgt}", '. /root/keystonercv3; openstack service list')
        }
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    // Apply gnocchi client state to create gnocchi archive policies, due to possible
    // races, apply on the first node initially
    if (salt.testTarget(master, "I@gnocchi:client ${extra_tgt}")) {
        salt.enforceState(master, "I@gnocchi:client and *01* ${extra_tgt}", 'gnocchi.client')
        salt.enforceState(master, "I@gnocchi:client ${extra_tgt}", 'gnocchi.client')
    }

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

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

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

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


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

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

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

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

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

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

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


def installOpenstackNetwork(master, physical = "false", extra_tgt = '') {
    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 ${extra_tgt}")) {
            salt.enforceState(master, "I@neutron:gateway ${extra_tgt}", '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 ${extra_tgt}")) {
        salt.enforceState(master, "I@neutron:client ${extra_tgt}", 'neutron.client')
    }

    salt.enforceHighstate(master, "I@neutron:gateway ${extra_tgt}")

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


def installOpenstackCompute(master, extra_tgt = '') {
    def salt = new com.mirantis.mk.Salt()
    // Configure compute nodes
    def compute_compound = "I@nova:compute ${extra_tgt}"
    if (salt.testTarget(master, compute_compound)) {
        // In case if infrastructure nodes are used as nova computes too
        def gluster_compound = "I@glusterfs:server ${extra_tgt}"
        def salt_ca_compound = "I@salt:minion:ca:salt_master_ca ${extra_tgt}"
        // Enforce highstate asynchronous only on compute nodes which are not glusterfs and not salt ca servers
        def hightstateTarget = "${compute_compound} and not (${gluster_compound}) and not (${salt_ca_compound})"
        if (salt.testTarget(master, hightstateTarget)) {
            retry(2) {
                salt.enforceHighstateWithExclude(master, hightstateTarget, 'opencontrail.client')
            }
        }
        // Iterate through salt ca 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, salt_ca_compound) ) {
            for ( cmp_target in salt.getMinionsSorted(master, compute_compound) ) {
                if ( target == cmp_target ) {
                    // Enforce highstate one by one on salt ca servers which are compute nodes
                    retry(2) {
                        salt.enforceHighstateWithExclude(master, target, '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')
                    }
                }
            }
        }
    }

    // Run nova:controller to map cmp with cells
    if (salt.testTarget(master, "I@nova:controller ${extra_tgt}")) {
      salt.enforceState(master, "I@nova:controller and *01* ${extra_tgt}", 'nova.controller')
    }
}


def installContrailNetwork(master, extra_tgt = '') {
    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* ${extra_tgt}", 'opencontrail.database')
    salt.enforceState(master, "I@opencontrail:database ${extra_tgt}", 'opencontrail.database')

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

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


def installContrailCompute(master, extra_tgt = '') {
    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 ${extra_tgt}", 'opencontrail.client')
    // Provision opencontrail virtual routers

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

    if (salt.testTarget(master, "I@nova:compute ${extra_tgt}")) {
        salt.cmdRun(master, "I@nova:compute ${extra_tgt}", '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 ${extra_tgt}")) {
        salt.enforceState(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail.client')
        salt.enforceState(master, "I@opencontrail:compute ${extra_tgt}", 'opencontrail')
    }
}


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


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

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

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

    // Run k8s master at *01* to simplify namespaces creation
    salt.enforceStateWithExclude(master, "I@kubernetes:master and *01* ${extra_tgt}", "kubernetes.master", "kubernetes.master.setup")

    // Run k8s without master.setup
    salt.enforceStateWithExclude(master, "I@kubernetes:master ${extra_tgt}", "kubernetes", "kubernetes.master.setup")

    // Run k8s master setup
    salt.enforceState(master, "I@kubernetes:master and *01* ${extra_tgt}", 'kubernetes.master.setup')

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


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

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

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

    // Install docker
    salt.enforceState(master, "I@docker:host ${extra_tgt}", 'docker.host')

    // Install Kubernetes and Calico
    salt.enforceState(master, "I@kubernetes:pool ${extra_tgt}", 'kubernetes.pool')

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


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

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


def installCicd(master, extra_tgt = '') {
    def salt = new com.mirantis.mk.Salt()
    def common = new com.mirantis.mk.Common()
    def gerrit_compound = "I@gerrit:client and ci* ${extra_tgt}"
    def jenkins_compound = "I@jenkins:client and ci* ${extra_tgt}"

    salt.fullRefresh(master, gerrit_compound)
    salt.fullRefresh(master, jenkins_compound)

    salt.enforceState(master, "I@docker:swarm:role:master and I@jenkins:client ${extra_tgt}", 'docker.client', true, true, null, false, -1, 2)

    // API timeout in minutes
    def wait_timeout = 10

    // Gerrit
    def gerrit_master_url = salt.getPillar(master, gerrit_compound, '_param:gerrit_master_url')

    if(!gerrit_master_url['return'].isEmpty()) {
      gerrit_master_url = gerrit_master_url['return'][0].values()[0]
    } else {
      gerrit_master_url = ''
    }

    if (gerrit_master_url != '') {
      common.infoMsg('Gerrit master url "' + gerrit_master_url + '" retrieved at _param:gerrit_master_url')
    } else {

      common.infoMsg('Gerrit master url could not be retrieved at _param:gerrit_master_url. Falling back to gerrit pillar')

      def gerrit_host
      def gerrit_http_port
      def gerrit_http_scheme

      def host_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:host')
      gerrit_host = salt.getReturnValues(host_pillar)

      def port_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:http_port')
      gerrit_http_port = salt.getReturnValues(port_pillar)

      def scheme_pillar = salt.getPillar(master, gerrit_compound, 'gerrit:client:server:protocol')
      gerrit_http_scheme = salt.getReturnValues(scheme_pillar)

      gerrit_master_url = gerrit_http_scheme + '://' + gerrit_host + ':' + gerrit_http_port

    }

    timeout(wait_timeout) {
      common.infoMsg('Waiting for Gerrit to come up..')
      def check_gerrit_cmd = 'while true; do curl -sI -m 3 -o /dev/null -w' + " '" + '%{http_code}' + "' " + gerrit_master_url + '/ | grep 200 && break || sleep 1; done'
      salt.cmdRun(master, gerrit_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_gerrit_cmd + '"')
    }

    // Jenkins
    def jenkins_master_url_pillar = salt.getPillar(master, jenkins_compound, '_param:jenkins_master_url')
    jenkins_master_url = salt.getReturnValues(jenkins_master_url_pillar)

    timeout(wait_timeout) {
      common.infoMsg('Waiting for Jenkins to come up..')
      def check_jenkins_cmd = 'while true; do curl -sI -m 3 -o /dev/null -w' + " '" + '%{http_code}' + "' " + jenkins_master_url + '/whoAmI/ | grep 200 && break || sleep 1; done'
      salt.cmdRun(master, jenkins_compound, 'timeout ' + (wait_timeout*60+3) + ' /bin/sh -c -- ' + '"' + check_jenkins_cmd + '"')
    }

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

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

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


def installStacklight(master, extra_tgt = '') {
    def common = new com.mirantis.mk.Common()
    def salt = new com.mirantis.mk.Salt()
    def retries_wait = 20
    def retries = 15

    // 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 ${extra_tgt}", 'haproxy')
        salt.runSaltProcessStep(master, "I@haproxy:proxy ${extra_tgt}", 'service.status', ['haproxy'])

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

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

    // Install MongoDB for Alerta
    if (salt.testTarget(master, "I@mongodb:server ${extra_tgt}")) {
        salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.server')

        // Initialize mongodb replica set
        common.retry(5,20){
             salt.enforceState(master, "I@mongodb:server ${extra_tgt}", 'mongodb.cluster')
        }
    }

    //Install Telegraf
    salt.enforceState(master, "I@telegraf:agent or I@telegraf:remote_agent ${extra_tgt}", 'telegraf')

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

    //Install Elasticsearch and Kibana
    salt.enforceState(master, "*01* and  I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
    salt.enforceState(master, "I@elasticsearch:server ${extra_tgt}", 'elasticsearch.server')
    salt.enforceState(master, "*01* and I@kibana:server ${extra_tgt}", 'kibana.server')
    salt.enforceState(master, "I@kibana:server ${extra_tgt}", 'kibana.server')

    // Check ES health cluster status
    def pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", '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')
    }
    pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch:client:server:port')
    def elasticsearch_port
    if(!pillar['return'].isEmpty()) {
        elasticsearch_port = pillar['return'][0].values()[0]
    } else {
        common.errorMsg('[ERROR] Elasticsearch VIP port could not be retrieved')
    }
    common.retry(retries,retries_wait) {
        common.infoMsg('Waiting for Elasticsearch to become green..')
        salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", "curl -sf ${elasticsearch_vip}:${elasticsearch_port}/_cat/health | awk '{print \$4}' | grep green")
    }

    common.retry(retries,retries_wait) {
        salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
    }

    common.retry(retries,retries_wait) {
        salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')
    }

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

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

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

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

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

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

    // Configure Prometheus in Docker Swarm
    salt.enforceState(master, "I@docker:swarm and I@prometheus:server ${extra_tgt}", '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 ${extra_tgt}", 'heka.remote_collector', true, false)
    }

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

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

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

    //Configure Grafana
    pillar = salt.getPillar(master, "ctl01* ${extra_tgt}", '_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 ${extra_tgt}", 'grafana.client')
}

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

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

    salt.enforceState(master, "*01* and I@influxdb:server ${extra_tgt}", 'influxdb')
    salt.enforceState(master, "I@influxdb:server ${extra_tgt}", 'influxdb')

    salt.enforceState(master, "*01* and I@kibana:server ${extra_tgt}", 'kibana.server')
    salt.enforceState(master, "I@kibana:server ${extra_tgt}", 'kibana.server')

    salt.enforceState(master, "*01* and I@grafana:server ${extra_tgt}",'grafana.server')
    salt.enforceState(master, "I@grafana:server ${extra_tgt}",'grafana.server')

    def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_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 ${extra_tgt}", 'rabbitmq')
            salt.enforceState(master, "I@redis:cluster:role:master ${extra_tgt}", 'redis')
            salt.enforceState(master, "I@redis:server ${extra_tgt}", 'redis')
            salt.enforceState(master, "I@sensu:server ${extra_tgt}", 'sensu')
        default:
            // Update Nagios
            salt.enforceState(master, "I@nagios:server ${extra_tgt}", '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 ${extra_tgt}", 'service.stop', ['nagios3'], null, true)
    }

    salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client.service')
    salt.enforceState(master, "I@kibana:client ${extra_tgt}", 'kibana.client')

    sleep(10)
}

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

    salt.cmdRun(master, "I@elasticsearch:client ${extra_tgt}", 'salt-call state.sls elasticsearch.client')
    // salt.enforceState(master, "I@elasticsearch:client", 'elasticsearch.client", true)
    salt.cmdRun(master, "I@kibana:client ${extra_tgt}", '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, "* ${extra_tgt}", 'collectd')
    salt.enforceState(master, "* ${extra_tgt}", 'salt.minion')
    salt.enforceState(master, "* ${extra_tgt}", 'heka')

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

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

    sleep(5)

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

    // Update collectd
    salt.enforceState(master, "I@collectd:remote_client:enabled:True ${extra_tgt}", 'collectd')

    def alarming_service_pillar = salt.getPillar(master, "mon*01* ${extra_tgt}", '_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 ${extra_tgt}", 'sensu')
        default:
            break
            // Default is nagios, and was enforced in installStacklightControl()
    }

    salt.cmdRun(master, "I@grafana:client and *01* ${extra_tgt}", '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* ${extra_tgt}", 'grafana.client')
    salt.enforceState(master, "I@grafana:client and *02* ${extra_tgt}", 'grafana.client')
    salt.enforceState(master, "I@grafana:client and *03* ${extra_tgt}", '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* ${extra_tgt}", '_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} ${extra_tgt}", 'service.restart', ['remote_collectd'])
        salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['remote_collector'])
        salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['aggregator'])
        salt.runSaltProcessStep(master, "G@ipv4:${stacklight_vip} ${extra_tgt}", 'service.restart', ['nagios3'])
    } else {
        throw new Exception("Missing stacklight_vip")
    }
}

//
// backups
//

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

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

}

//
// Ceph
//

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

    salt.enforceState(master, "I@ceph:common ${extra_tgt}", 'salt.minion.grains')

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

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

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

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

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

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

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

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

def installOssInfra(master, extra_tgt = '') {
  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 ${extra_tgt}")) {
    salt.enforceState(master, "I@devops_portal:config ${extra_tgt}", 'devops_portal.config')
    salt.enforceState(master, "I@rundeck:client ${extra_tgt}", ['linux.system.user', 'openssh'])
    salt.enforceState(master, "I@rundeck:server ${extra_tgt}", 'rundeck.server')
  }
}

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

  //Get oss VIP address
  def pillar = salt.getPillar(master, "cfg01* ${extra_tgt}", '_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 ${extra_tgt}", '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 ${extra_tgt}", '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 ${extra_tgt}", "while true; do curl -sf ${oss_vip}:8887/apps >/dev/null && break; done")
  }
  salt.enforceState(master, "I@postgresql:client ${extra_tgt}", 'postgresql.client')

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

  // Elasticsearch
  pillar = salt.getPillar(master, "I@elasticsearch:client ${extra_tgt}", '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 ${extra_tgt}", "while true; do curl -sf ${elasticsearch_vip}:9200 >/dev/null && break; done")
  }
  salt.enforceState(master, "I@elasticsearch:client ${extra_tgt}", 'elasticsearch.client')
}
