Delphix Products

 View Only
  • 1.  How to Invoke script after masking job in automated way

    Posted 07-17-2019 11:29:00 AM
    Hi,

    I have need to invoke some script before  & after masking job. The before masking job can be added it as hook in clone or post refresh stage where VDB is virtualized and masking job is attached to it. 

    However, I am wondering where is a place holder to invoke SQL update query or some script after masking job execution. The refresh control is given to project team, so want to make sure that query will be executed as a part of automated refresh. 

    Any suggestions?

    ------------------------------
    Santosh

    ------------------------------


  • 2.  RE: How to Invoke script after masking job in automated way
    Best Answer

    Posted 07-17-2019 01:20:00 PM
    Edited by Marcin Kwasninski 07-18-2019 03:48:28 AM
    Hi Santosh,

    You can Simply use Post Script in your masking JOB definition


    Or you need to go out from GUI and go to API/CLI methods, and build simple Python/shell script which will run:
    1. Run PRE masking operations, like dropping indexes, PKs, FKs, etc
    2. Authenticate in Masking Engine
    3. Execute Masking JOB or JOBs
    4. Run POST masking operations like dropping indexes, PKs, FKs, or whether you want :)


    Example of script:

    ### Configuration section

    # Masking Engine IP address

    ME_IP="10.10.105.11"

    # Masking Engine user login

    ME_USER="apijob_runner"

    # Masking Engine user password

    ME_PASS="[password]"

    # JOB List

    JOBLIST="55 36"

    # Authentication

    get_token()

    {

    AUTH_TOKEN=$(curl -s -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d "{ \"username\": \"$ME_USER\", \"password\": \"$ME_PASS\" }" http://${ME_IP}:8282/masking/api/login | cut -d ":" -f 2 |sed -E 's/["}]//g')

    }


    timestamp()

    {

    TS="$(date +'%Y-%m-%d %H:%M:%S')"

    }

    # In case of error of running Masking JOB

    exit_error()

    {

    timestamp

    echo ""

    echo "$TS - Last JOB finish with error..."

    exit

    }

    SQL_PRE_AS_USER()

    {

    timestamp

    echo "$TS - PRE Script as USER"

    sqlplus user/[password]@TNSALIAS @SQL_PRE.sql

    timestamp

    echo "$TS - End of executing PRE Scripts"

    }

    POST_script()

    {

    timestamp


    echo "$TS - POST script"

    sqlplus user/pass @POST_script.sql

    timestamp

    echo "$TS - POST script"

    }

    ### Executive section

    timestamp

    echo "-----------------------------------------------"

    echo "$TS - Masking JOBs start"

    echo "-----------------------------------------------"

    # Running PRE scripts

    SQL_PRE_AS_USER

    # Authorization

    get_token

    # Running masking JOBs using JOBLIST

    for jobID in ${JOBLIST}

    do

    timestamp

    echo "---------------------------------------"

    echo "$TS - Start: job $jobID"

    echo "---------------------------------------"

    curl -X POST --header 'Content-Type: application/json' --header 'Accept: applicaion/json' --header "Authorization: $AUTH_TOKEN" -d "{\"jobId\": $jobID}" "http://${ME_IP}:8282/masking/api/executions"

    # Waiting for Masking Engine

    sleep 30

    # JOB Status check

    JOB_STATUS=`curl -s -X GET --header 'Accept: applcation/json' --header "Authorization: $AUTH_TOKEN" "http://${ME_IP}:8282/masking/api/executions" | sed -n "s/.*:${jobID},\"status\":\"\([A-Z]*)\".*/\1/p"`

    echo "Job status: $JOB_STATUS"

    echo "There are running JOBs, please wait..."

    # Checking masking JOB status every ??? seconds

    i=0

    while [ "$JOB_STATUS" == "RUNNING" ]

    do

    sleep 15

    let "i+=1"

    # Refreshing auth token every 75 secs

    let "m=$i % 5"

    [ "$m" -eq 0 ] && echo "$(date +'%Y-%m-%d %H:%M:%S - keep alive')" && get_token

    JOB_STATUS=`curl -s -X GET --header 'Accept: application/json' --header "Authorization: $AUTH_TOKEN" "http://${ME_IP}:8282/masking/api/executions" | sed -n "s/.*:${jobID},\"status\":\"\([A-Z]*\)".*/\1/p"`

    done

    timestamp

    echo "------------------------------------------------------------------------------"

    echo "$TS - End: job $jobID end with status $JOB_STATUS"

    echo "------------------------------------------------------------------------------"

    echo ""

    # exit if job failed

    [ "$JOB_STATUS" != "SUCCEEDED" ] && exit_error

    done 

    # POST Scripts execution

    POST_script

    timestamp

    echo "----------------------------------------------------------"

    echo "$TS - End"

    echo "----------------------------------------------------------"



    Regards
    Marcin


    ------------------------------
    Marcin Kwasninski
    Technical Principal
    Spica Solutions
    ------------------------------



  • 3.  RE: How to Invoke script after masking job in automated way

    Posted 07-17-2019 03:19:00 PM
    Thanks Marcin. Its my bad, i overlooked this option. Using this product quite long time, did API automation and created more than 100+ jobs, but over looked this option :-). 

    Thank you again !!

    ------------------------------
    Santosh Saidapur
    Testing Engineer
    American Family Mutual Insurance Company
    ------------------------------