Page History
...
JS7 - Job Resources are a means to carry of carrying variables and to make making them available to jobs.
- A Job Resource can hold any number of variables. Such variables are available for JVM Jobs from arguments and for Shell Jobs from environment variables.
- A Job Resource environment variable is automatically available as a local environment variable to a Shell Job.
If a Workflow is assigned the Job Resource then
any Shell Jobs in the workflow are propagatedthe environment variables of the Job Resource will be propagated to all the Shell Jobs in the workflow.
- If a Job is assigned the Job Resource then this job can use the propagated environment variables of the Job Resource.
- As a result you users can add a variable such as
BusinessDate
to an existing or to a new Job Resource and . Users can then assign the Job Resource to a Workflow to make it available to all jobs or assign limit its scope by assigning it to an individual Job to limit the scope.
Download ? (.json upload): pdBusinessDate.jobresource.json
...
- An argument with the name
businessDate
is introduced that holds a business date value that will later on will be updated automatically.
...
Job for Unix
Download for Unix (.json upload): pduVariableBusinessDateGet.workflow.json
The job is assigned the Job Resource with the given name. In the job script the environment variable $BUSINESS_DATE
is used that which is available from the Job Resource.
...
Job for Windows
Download for Windows (.json upload): pdwVariableBusinessDateGet.workflow.json
The job is assigned the Job Resource with the given name. In the job script the environment variable %BUSINESS_DATE%
is used that which is available from the Job Resource.
...
Updating the Business Date
The final task includes to update updating the business date at a regular basis. This is achieved by use of the JS7 - REST Web Service API.
- The JS7 REST Web Service API is available for any scripting languages and programming languages that implement a REST client.
- This allows to set the business date from to be set by an individual application that triggers triggering the date change.
- This allows to set the business date to be set automatically from a JS7 job.
...
- Users can create a workflow with a single job that updates the
businessDate
variable. - The workflow is triggered by an order from JS7 - Schedules to switch the business date for date, for example, at midnight in the respective relevant time zone and for specific days.
Job for Unix using Shell
Download (.json upload): pduVariableBusinessDateSetpduVariableBusinessDateSetShell.workflow.json
The job example for updating a business date uses the shell script explained with the JS7 - How to update a Job Resource using Unix Shell article.
Users have to download the shell script, make it executable and available in a directory that can be accessed by the Agent.
Download: JS7 - Download (Section: Utilities, Unix: js7.encryption.tar.gz
, Windows: js7.encryption.zip
)
The job performs the following operations:
- connect to the JOC Cockpit with the indicated user account.
- reading the Job Resource.
- updating the
businessDate
variable to the current date and specifying the desired date format. - storing the updated
businessDate
variable in the Job Resource. - deploying the updated Job Resource.
- disconnecting from JS7.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/bin/sh
$HOME/js7_set_job_resource.sh \
--url=http://joc-2-0-primary:7446 \
--controller-id=testsuite \
--user=root:root \
--job-resource=/ProductDemo/Variables/pdBusinessDate \
--key=businessDate \
--value=$(date +'%Y-%m-%d') |
Job for Unix using PowerShell
Download (.json upload): pduVariableBusinessDateSet.workflow.json
The job example for updating a business date uses business date makes use of a PowerShell job script and the JS7 - PowerShell Module.
- The JS7 PowerShell Module is a wrapper for the JS7 - REST Web Service API.
- To install the JS7 PowerShell Module see see the PowerShell Command Line Interface 2.0 - Introduction article.
- Consider Note the use of the shebang
#!/usr/bin/env pwsh
in first line of the job script that which assigns PowerShell as the shell for the job script.
- The JS7 REST Web Service API can be used with any scripting language such as Perl, Python, Ruby etc.
- The PowerShell cmdlets are available from source code, see https://github.com/sos-berlin/js7-cli-powershell, and can be used to identify the parameterization of REST requests.
- The PowerShell cmdlets are available from source code, see https://github.com/sos-berlin/js7-cli-powershell, and can be used to identify the parameterization of REST requests.
...
The job performs the following operations:
- connect to the JOC Cockpit by use of using the Connect-JS7 cmdlet.
- read reading the Job Resource by use of with the Get-JS7InventoryItem cmdlet.
- update updating the
businessDate
variable to the current date and specify specifying the desired date format. - using the Set-JS7InventoryItem cmdlet to store the updated
businessDate
variable to in the Job Resource by use of the Set-JS7InventoryItem cmdlet.. - using the Publish-JS7DeployableItem cmdlet to deploy the updated Job Resource by use of the Publish-JS7DeployableItem cmdlet.
- disconnect from JS7 by use of using the Disconnect-JS7 cmdlet to disconnect from JS7.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#!/usr/bin/env pwsh # Adjust the path to your Job Resource $jobResourcePath = '/ProductDemo/Variables/pdBusinessDate' # Consider to use the appropriate URL that matches host and port of the JOC Cockpit instance $url = "http://joc-2-0-primary:4446" # Consider to store credentials with a PowerShell profile or with a credential store or to use certificate based authentication as an alternative to user/password $credentials = ( New-Object -typename System.Management.Automation.PSCredential -ArgumentList "root", ( "root" | ConvertTo-SecureString -AsPlainText -Force) ) Import-Module JS7 Connect-JS7 -Url $url -id $env:CONTROLLER_ID -Credentials $credentials $jobResource = Get-JS7InventoryItem -Path $jobResourcePath -Type JOBRESOURCE if ( $jobResource.arguments.BusinessDate ) { # update the business date $jobResource.arguments.BusinessDate = (Get-Date -Format "yyyy-MM-dd") } else { # add a business date variable to the Job Resource $jobResource.arguments | Add-Member -Membertype NoteProperty -Name BusinessDate -Value (Get-Date -Format "yyyy-MM-dd") } # Update and deploy the Job Resource Set-JS7InventoryItem -Path $jobResourcePath -Type JOBRESOURCE -Object $jobResource Publish-JS7DeployableItem -Path $jobResourcePath -Type JOBRESOURCE -ControllerID $env:CONTROLLER_ID Disconnect-JS7 |
Job for Windows using PowerShell
Download (.json upload): pdwVariableBusinessDateSet.workflow.json
The job includes the same PowerShell script code and performs the same operations as the above Unix job example described above.
The only difference of with the Windows job is the use of a shebang that which is specific for this OS.
- Consider use of the following shebang in the first line of the job script:
@@setlocal enabledelayedexpansion & @@findstr/v "^@@f^@@[fs].*&" "%~f0" | pwshpowershell.exe -NonInteractive -Command - & goto:eofexit !errorlevel!/b&
- The PowerShell executable
pwsh.exe
is available starting from PowerShell 6.0. PowerShell releases 5.x use the executablepowershell.exe
that can be used accordingly with the shebang. - For details about the PowerShell shebang see see the JS7 - How to run PowerShell scripts from jobs article.
Schedule for automated job execution
To automate the execution of the JS7 workflow in order to update the business date users Users can create JS7 - Schedules that which generate orders for execution that are executed at a given point in time. These can be used to automate the execution of the JS7 workflow and update the business date.
Download (.json upload): pdsVariableBusinessDateSet.schedule.json
...
- The schedule references the workflow to be executed.
- The schedule is specified to be planned and to be submitted automatically to the JS7 - Daily Plan.
To specify the point in time of workflow execution the schedule is added at which the workflow is executed, a run-time setting is added to the schedule like this:
- A calendar is assigned that specifies the days for on which the workflow is executed.
- A period is assigned that which specifies the hour, minute and second for start of when the workflow is to be started.