AutoSys Workload Automation

 View Only
  • 1.  CAWA DE array to build servername variable

    Posted Aug 12, 2019 02:50 PM
    Edited by Kenneth Chrapczynski Aug 12, 2019 03:21 PM
    Does anyone have a cookbook suggestion on how I can trigger jobs into CAWA DE from an array, looping through the line items creating servername variables for each line item in the text file?

    Basically from the data below I want to create a variable %(APPL.servername), then pass it into a command line JOB with %(APPL.servername) in the path.

    ie.. \\%(APPL.servername)\c:\path


    This is the format of the raw csv file:
    Server=00101111SR01,Concept=xx,Corpcode=001,TZ=EASTERN
    Server=00102222SR01,Concept=xx,Corpcode=001,TZ=EASTERN
    Server=00103333SR01,Concept=xx,Corpcode=001,TZ=EASTERN


    Here is a text file with servername stripped out:
    00101111SR01
    00102222SR01
    00103333SR01

    If you want to really show-off your java scripting skills I know the raw csv file can be used where you select the substr of (7,11) to create the servername variable. My java scripting skills aren't there yet, but I know it can be done. Anyway, I wrote a powershell script to extract the items in the text file if anyone is interested in that I can share. My struggle is turning this information into job's. The max number of lines in the files will only be around 30 servers, nothing too crazy. Thanks for any input.

    I found File-Level Function file_read and file_readlines, but I haven't found any good examples of what I'm trying to do.

    ------------------------------
    Ken Ski
    ------------------------------


  • 2.  RE: CAWA DE array to build servername variable

    Posted Aug 12, 2019 07:00 PM
    Edited by Andy Reimer Aug 12, 2019 07:02 PM
    I do something similar.  This may give you a direction to explore.

    We have a list of SQL servers in a text file, and I want trigger one DE application many times, passing the SQL server name into the "Runtime name" as well as into the "Job Qualifier" and the "Command to run".  The goal is to run a script from each server that backs up the SQL databases.

    I do this with two applications.  One is called SQL_Backup_Trigger and the other is called SQL_Backup.
    SQL_Backup_Trigger is scheduled to trigger at 8PM when I want the backups to start.  It has a single job which runs the following PowerShell:

    # Get the content of the text file
    $SQL_Servers = get-content "D:\Backups\SQLServerBackups.txt"
    
    # Submit a job for each server listed in the text file
    Foreach ($server in $SQL_Servers) {
    if (-not $server.StartsWith('#')) {
    & 'C:\Program Files\CA\WorkloadAutomation\bin\cli.bat' DESERVER 7500 CLIUSER CLIPASSWORD triggeradd event`("PRDESP.SQL_BACKUP"`) u1`("$server"`)
    start-sleep -s 2 }
    }
    
    # Error checking
    If ($Error.Count -eq 0) {$exitcode= 0; Write-Host " Code:$exitcode - All jobs successfully submitted"} #everything worked
    elseif ($Error.Count -ne 0) {$exitcode = 1; Write-Host " Code:$exitcode - Powershell encountred $Error.Count errors."} #powershell error
    
    # Send the completion code back to DE
    $Host.SetShouldExit($exitcode)

    This Powershell loops through the file and for each server that isn't commented out (ie. does not start with #) it executes the cli.bat telling it to trigger SQL_BACKUP, passing the server name as User Parameter 1.

    In the SQL_Backup application I can use the %APPL._user1 variable in all the places I want the SQL Server name.
    Runtime name: SQL_BACKUP_%APPL._user1
    Job Qualifier: %APPL._user1
    Command to run: \\%APPL._user1\d$\cybexec\sql_backup.cmd

    Note: this does result in multiple generations of the same application, each with a unique name. If you wanted one application with different jobs getting different variables you would have to take a different approach.



    ------------------------------
    Andy Reimer
    ------------------------------



  • 3.  RE: CAWA DE array to build servername variable

    Posted Aug 13, 2019 11:40 AM
    Edited by Kenneth Chrapczynski Aug 13, 2019 11:41 AM
    Hi Andy, Thanks for the info. I believe we are thinking along the same lines, where you are using powershell to execute cli.bat, I was envisioning javascript can handle the reading the file. The fun thing with computers is there are many ways to do the same thing. 

    My workflow thought is to have an EVENT File monitor job detect the file, once detected trigger a link that has the java code leveraging APPL._filename to create the APPL.servername variables. 

    Something like this:
    var SRVFILE = APPL._filename;
    var SRV=new java.util.Properties();
    SRV.load(new java.io.FileInputStream(SRVFILE));
    APPL.RESTSERVER=SRV.getProperty('Server');

    I have this part reading the whole line, I just need to figure out how to pull out just server name. I'm not 100% sure if my references to "Properties" is correct.


  • 4.  RE: CAWA DE array to build servername variable
    Best Answer

    Broadcom Employee
    Posted Aug 14, 2019 06:32 AM
    Hi,

    I have used the example listed below in the docops and came up with the javascript below.

    https://docops.ca.com/ca-workload-automation-de/12-2/en/scheduling/using-javascript/built-in-functions/file-level-javascript-functions#File-levelJavascriptFunctions-file_readLines

    Example is listed there - Example: Reading the Content of a File Line by Line




    ----------------------Javascript -------------------------------------
    APPL.MyFile = new Array();

    APPL.MyFile = file_readLines('C:/Users/kirku01/Desktop/ch.csv', 1);
    var i= 0;
    var server= new Array();
    for (i in APPL.MyFile)
    {
    var tmp =APPL.MyFile[i].split(',');
    var ser=tmp[0].split('=');
    server[i]=ser[1];

    }

    server[0] server[1] server[2] array elements should have the server names

    Hope it helps!
    Ravi Kiran