void run()

in src/com/epam/digital/data/platform/pipelines/stages/impl/dataplatform/cronCleanupOfVersionCandidateDatabases.groovy [27:53]


    void run() {
        ArrayList<String> versionCandidateIdArray = new ArrayList<String>()
        ArrayList<String> crunchyDBsArray = new ArrayList<String>()
        ArrayList<String> versionCandidateTemporaryDBsArray = new ArrayList<String>()

        context.logger.info("Running cleanup for the version candidate databases")
        context.script.sshagent(["${context.gitServer.credentialsId}"]) {
            versionCandidateIdArray = context.script.sh(script: "ssh -oStrictHostKeyChecking=no -p ${context.gitServer.sshPort} " +
                    "${context.gitServer.autouser}@${context.gitServer.host} gerrit query --format=JSON status:open project:registry-regulations " +
                    "| sed -e 's/[{}]/''/g' | sed s/\\\"//g | awk -v RS=',' -F: '\$1==\"number\"{print \$2}'", returnStdout: true).tokenize('\n')
            crunchyDBsArray = context.postgres.psqlCommand(context.postgres.masterPod, "select datname from pg_database",
                    "postgres", context.postgres.operational_pg_user).tokenize('\n')
            crunchyDBsArray.each {
                it.contains("registry_dev") ? versionCandidateTemporaryDBsArray.add(it.split("registry_dev_")[1]) : false
            }
        }
        versionCandidateTemporaryDBsArray.each {
            if (versionCandidateIdArray.contains(it))
                true
            else {
                context.logger.info("Removing temporary version candidate DBs")
                context.postgres.psqlCommand(context.postgres.masterPod,
                        "drop database if exists registry_dev_${it} with(force)",
                        "postgres", context.postgres.operational_pg_user)
            }
        }
    }