saagie / gradle-saagie-dataops-plugin

Saagie Gradle Plugin for the new version (2.0) of Saagie Dataops Orchestrator
Apache License 2.0
2 stars 0 forks source link

Support Environment Variables - Export V1 / Import V2 #286

Open medamineziraoui opened 4 years ago

medamineziraoui commented 4 years ago

Export v1 / Import (V2) tasks should support ability to export environment variables and import them back.

Refer to https://github.com/saagie/gradle-saagie-dataops-plugin/wiki/projectsExportV1

medamineziraoui commented 4 years ago

How to test :

Version to test : 2.1.4

The Export phase:

Create a build file: Example of build.projectsExportV1.gradle:

plugins {
  id "io.saagie.gradle-saagie-dataops-plugin" version "2.1.4"
}
saagie {
    server {
        url = "REPLACE_SAAGIEURL"
        login = "REPLACE_SAAGIELOGIN"
    password = "REPLACE_SAAGIEPASSWORD"
        environment = "REPLACE_SAAGIE"
    jwt = true
    }

    env {
        include_all_var = true
        scope = 'global'
    }

    exportArtifacts {
          export_file = "./variable/export_v1_all_global.zip" // <=== url "./variable/" should exist  
          overwrite=true
      temporary_directory='./tmp'    // <=== temporary_directory ./tmp'  should exist        
    }
}

Export variables using this commande : The command line : gradle -b build.projectsExportV1.gradle projectsExportV1 This should export all variable from v1 with scope global for every variable.

Test all variable as project from v1: https://drive.google.com/file/d/1xoFTdZEjs9lQoYlwGn--IKyof5na6U56/view?usp=sharing

Other use cases :

Case global by name from v1:

In every use case we need to change the env variable section.

 env {
        include_all_var = false
        scope = 'global'
        name = ['WEBHDFS_URI', 'TRIFACTA_ADAPTER_URL']
    }

Test variable as global with name from v1: https://drive.google.com/file/d/1DTDmERFJDQ0DEKW8GYadtFMW35D1cA7T/view?usp=sharing

Result:

> Task :projectsExport
Directory created successfully
{"status":"success","exportfile":"path/exported/zip/file.zip"}

BUILD SUCCESSFUL in 3s

Case project by name from v1:

 env {
        include_all_var = false
        scope = 'project'
        name = ['SAAGIE_BOT_URL', 'STREAM_DATA_PATH']
    }

https://drive.google.com/file/d/1o7f_1-2Q7Ig-Kr3mKQjoIE76PsOBmdcn/view?usp=sharing

Result:

> Task :projectsExport
Directory created successfully
{"status":"success","exportfile":"path/exported/zip/file.zip"}

BUILD SUCCESSFUL in 3s

Case all variables of scope project from v1:

 env {
        include_all_var = true
        scope = 'project'
    }

https://drive.google.com/file/d/1Of_9I2M2P1kEquEzZIll0WBz7hvM2vsl/view?usp=sharing

Result:

> Task :projectsExport
Directory created successfully
{"status":"success","exportfile":"path/exported/zip/file.zip"}

BUILD SUCCESSFUL in 3s

Case variable's name is not found when exporting project scope:

 env {
        include_all_var = false
        name  = ['NAME_DOENST_EXIST']
        scope = 'project'
    }

test: https://drive.google.com/file/d/17hFGjGYGfi8UTe1JasTwg7BlALOG4Cnb/view?usp=sharing

Result: `Didn't find variable name : NAME_DOENST_EXIST in the required environment

Case variable's name is not found when exporting global scope:

 env {
        include_all_var = false
        name  = ['NAME_DOENST_EXIST']
        scope = 'global'
    }

test: https://drive.google.com/file/d/1DTDmERFJDQ0DEKW8GYadtFMW35D1cA7T/view?usp=sharing

Result: `Didn't find variable name : NAME_DOENST_EXIST in the required environment

Case export gloal variable with include_all_var = true and name defined

 env {
        include_all_var = true
       name = ['SAAGIE_BOT_URL', 'STREAM_DATA_PATH']
        scope = 'global'
    }

test: https://drive.google.com/file/d/1DTDmERFJDQ0DEKW8GYadtFMW35D1cA7T/view?usp=sharing

Result:

> Task :projectsExport
Directory created successfully
{"status":"success","exportfile":"path/exported/zip/file.zip"}

BUILD SUCCESSFUL in 3s

Zip file will contain all variables of the global scope in the v2 platform, or will import all variable from v1 and define it s scope as global

The import phase:

Create a new build file: Example : build.projectsImport.gradle:

plugins {
    id 'groovy'
    id 'io.saagie.gradle-saagie-dataops-plugin' version '2.1.4'
}

saagie {
    server {
        url = "REPLACE_SAAGIEURL"
        login = "REPLACE_SAAGIELOGIN"
    password = "REPLACE_SAAGIEPASSWORD"
        environment = "REPLACE_SAAGIE"
    jwt = true
        acceptSelfSigned = true
    }
    project {
        id = "REPLACE_SAAGIE_PROJECT_ID"
    }
    importArtifacts {
        import_file = "./variable/export_v2_variables_and_import_them.zip" // <===== export.zip must exist
        temporary_directory='./tmp'
    }
}

Then use this command line: The command line : gradle -b build.projectsImport.gradle projectsImport

Note that no variable with name TRIFACTA_ADAPTER_URL_1 or WEBHDFS_URI_1 should exist in global scope v2

Expected behvio for zip filer:
export_v1_global_by_name_var: export_v1_global_by_name_var.zip test: https://drive.google.com/file/d/1xtK3hjRk6t0cO1wLoZ9rEQDgby6Rucm6/view?usp=sharing

Result:

{status=success, job=[], pipeline=[], variable=[{id=cd0bb64f-7f84-45ca-8dca-988cb1ef36c6, name=TRIFACTA_ADAPTER_URL_1}, {id=2547d7d5-5778-41a6-bdc3-b5005f9fc024, name=WEBHDFS_URI_1}]}

BUILD SUCCESSFUL in 5s
1 actionable task: 1 executed

Other use cases :

Import project scope variable from v1. Zip file : export_v1_project_by_name_var.zip

Note that no variable with name SAAGIE_BOT_URL or STREAM_DATA_PATH should exist in global scope v2

Test : https://drive.google.com/file/d/1IQqYBa3_lfhNdteFwmGDB2lTIrzqnAJJ/view?usp=sharing

Result:

> Task :projectsImport
Directory created successfully
{status=success, job=[], pipeline=[], variable=[{id=ed115284-fc4a-4648-bd72-d774dd1bd927, name=STREAM_DATA_PATH}, {id=ae8c1894-287d-4c66-a227-cc5dce0ee2a3, name=SAAGIE_BOT_URL}]}

BUILD SUCCESSFUL in 4s
1 actionable task: 1 executed

Import project scope variable from v1.