HCL Workload Automation, Version 9.4

Examples for IBM Workload Scheduler for z/OS

Provides an overview of the examples available of using the Java™ API for IBM Workload Scheduler for z/OS.

The following examples help you to understand how the beans are used in the IBM Workload Scheduler for z/OS environment:

Example 1: Adding a workstation to the database

// Create the connection to the server
TWSZConn connection = new TWSZConn();
// Get an instance of the interface ZConnModel
final ZConnModel model = connection.getModelBean();

// Define the workstation properties
String wksName = "CPU1";
String wksDescription = "Added by API";
String wksPrintoutRouting = "SYSOUT";
Workstation wks = new Workstation();
wks.setName(wksName);
wks.setDescription(wksDescription);
wks.setType(WorkstationType.COMPUTER);
wks.setReportingAttribute(WorkstationReportingAttribute.AUTOMATIC);
WorkstationZOSAttributes wksAttr = new WorkstationZOSAttributes();
wksAttr.setDefaultTransportTime(3600);
wksAttr.setDefaultJobDuration(60);
wksAttr.setPrintoutRouting(wksPrintoutRouting);
wksAttr.setStartedTaskSupported(true);
wks.setZosAttributes(wksAttr);

try {
	Context context = new Context();
	// Add the workstation to the database
	model.addTWSObject(wks, context);
}
catch (ConnException e) {
	// Do something to recover
}

Example 2: Adding a job stream (application) to the database

// Create the connection to the server
TWSZConn connection = new TWSZConn();
// Get an instance of the interface ZConnModel
final ZConnModel model = connection.getModelBean();

final static Date TODAY =
new Date((System.currentTimeMillis()/86400000L) * 86400000L);

// Define the job stream properties
String jsName = "APPL";
String jsOwnerName = "API";
JobStream js = new JobStream();
js.setName(jsName);
js.setOwnerName(jsOwnerName);
js.setValidFrom(TODAY);
js.setPriority(5);
// Define a JCL job to add to the job stream
String jobName = "1";
String wksName = "CPU1";
String jclName = "MYJCL";
Job jclJob = new Job();
jclJob.setName(jobName);
jclJob.setEstimatedDuration(1000);
jclJob.setPriority(-1);
ZOSJobDefinition jobDef = new ZOSJobDefinition();
jobDef.setFlowTargetKey(new FlowTargetKey(wksName));
jobDef.setTaskType(TaskTypes.ZOS_JOB_TASK);
jobDef.setJclName(jclName);
jclJob.setJobDefinition(jobDef);
// Add the JCL job to the job stream
js.getJobs().add(jclJob);
// Define a Printer job to add to the job stream
jobName = "2";
wksName = "PRNT";
Job printerJob = new Job();
printerJob.setName(jobName);
printerJob.setEstimatedDuration(1000);
printerJob.setPriority(-1);
jobDef = new ZOSJobDefinition();
jobDef.setFlowTargetKey(new FlowTargetKey(wksName));
jobDef.setTaskType(TaskTypes.ZOS_ PRINTER_TASK);
jobDef.setJclName(jclName);
jobDef.setLimitForFeedback(102);
printerJob.setJobDefinition(jobDef);
// Add to the Printer job the dependency from the JCL job
List printerJobDeps = printerJob.getInternalDependencies();
InternalDependency depFromJclJob =
new InternalDependency(null, (JobKey)jclJob.getKey());
printerJobDeps.add(depFromJclJob);
// Add the Printer job to the job stream
js.getJobs().add(printerJob);

try {
	Context context = new Context();
	// Add the job stream to the database

Example 3: Modifying a job stream (application) in the database

// Create the connection to the server
TWSZConn connection = new TWSZConn();
// Get an instance of the interface ZConnModel
final ZConnModel model = connection.getModelBean();

final static Date TODAY =
new Date((System.currentTimeMillis()/86400000L) * 86400000L);

final static Date TOMORROW = 
new Date(((System.currentTimeMillis()/86400000L) * 86400000L) + 86400000L);

final static long HOUR = 3600000;

// Make the job stream key
String jsName = "APPL";
JobStreamKey jsKey = new JobStreamKey(jsName, TODAY, false, false);

try {
	Context context = new Context();
	// Get the job stream by its key
	JobStream js = 
         (JobStream)model.getTWSObject(JobStream.class, jsKey, false, context);

	// Define a run cycle to add to the job stream
  String rcName = "RCRULE";
  String rcDescription = "Added by API";
  RunCycle rcRule = new RunCycle();
  rcRule.setName(rcName);
  rcRule.setDescription(rcDescription);
  rcRule.setType(RunCycleType.RULE);
  rcRule.setValidFrom(TODAY);
  rcRule.setValidTo(TOMORROW);
  rcRule.getTimeRestrictions().setStartOffset(10*HOUR);
  rcRule.getTimeRestrictions().setDeadlineOffset(12*HOUR + 24* HOUR);
  rcRule.setFreeDaysRule(FreeDaysRule.DO_NOT_SELECT);
  rcRule.setICalendar("ADRULE ONLY(001 003) LAST(001 002) DAY(DAY 
MONDAY THURSDAY) MONTH(FEBRUARY APRIL JUNE SEPTEMBER NOVEMBER) YEAR  ");
      
  // Add the run cycle to the job stream
  js.getRunCycles().add(rcRule);
  // Modify the job stream in the database
  Identifier jsId = model.setTWSObject(js, true, true, context);
}
catch (ConnException e) {
	// Do something to recover
}

Example 4: Adding a special resource in the database

// Create the connection to the server
TWSZConn connection = new TWSZConn();
// Get an instance of the interface ZConnModel
final ZConnModel model = connection.getModelBean();

final static long HOUR = 3600000;

// Define the resource properties
String resName = "RES";
String resDescription = "Added by API";
String wksName1 = "CPU1";
String wksName2 = "CPU2";
Resource res = new Resource();
res.setName(resName);
res.setDescription(resDescription);
FlowTargetKey wksKey1 = new FlowTargetKey(wksName1);
FlowTargetKey wksKey2 = new FlowTargetKey(wksName2);
res.getConnectedWorkstationLinks().add(new WorkstationLink(wksKey1));
res.getConnectedWorkstationLinks().add(new WorkstationLink(wksKey2));
ResourceBaseConstraints resCon = new ResourceBaseConstraints();
resCon.setQuantity(30);
resCon.setUsedFor(ResourceUsage.CONTROL);
resCon.setActionOnError(ResourceActionOnError.KEEP);
resCon.setAvailable(YesNoDefaultOption.NO);
res.setDefaultConstraints(resCon);
ResourceAvailabilityInterval resInt =
new ResourceAvailabilityInterval();
resInt.setIntervalValidityDayOfWeek(Calendar.MONDAY);
resInt.setIntervalStartTime(10*HOUR);
resInt.setIntervalEndTime(21*HOUR);
resInt.setQuantity(20);
resInt.setAvailable(YesNoDefaultOption.YES);
res.getResourceAvailabilityIntervals().add(resInt);

try {
	Context context = new Context();
	// Add the resource to the database
	model.addTWSObject(res, context);
}
catch (ConnException e) {
	// Do something to recover
}