HCL Workload Automation, Version 9.4

Working with objects in the database

Provides examples of using the Java™ API to work with objects in the database.

The following examples indicate how you use the classes to work with objects in the database:

Example 1: Adding a workstation to the database

//Object definition
String wksName = "MYWS";
Workstation wks = new Workstation();
wks.setName(wksName);
wks.setType(WorkstationType.FTA);
wks.setOs(OperatingSystem.UNIX);
wks.setAutoLink(true);
wks.setNodeName("node.abc.com");
wks.setSecurityLevel(SecurityLevel.NONE);
		 		 

ConnModel myModel;
//Get an instance of ConnModel interface...
...
		 		 
//Add the object
try 
{    
		 myModel.addTWSObject(wks, null);
}
catch (ConnException e) 
{
		 //Do something to recover...
}

Example 2: Retrieving a workstation from the database

Workstation wksRead = new Workstation();
//Get the same workstation from the DB
try 
{
wksRead = (Workstation) myModel.getTWSObject(Workstation.class, 
						new FlowTargetKey(wksName), false, null);
}
catch (ConnException e) 
{
		 //Do something to recover...
 }

Example 3: Removing a workstation from the database

//Remove a workstation from the DB
 try 
{
		 myModel.removeTWSObject(Workstation.class, wksRead.getId(), null);
}
catch (ConnException exc)
{
		 //Do something to recover...
}

Example 4: Defining a native job definition

//Job Definition creation

jobOk = new DistJobDefinition();
jobOk.setDescription("All values provided");
jobOk.setFlowTargetKey(wks);
jobOk.setName("JOB1");
jobOk.setTaskType("UNIX");
jobOk.setTaskString("ls");
jobOk.setUserLogin("tws_user");
jobOk.setRecoveryOption(RecoveryOption.STOP);

Example 5: Defining a job definition by using Jsdl

//Job Definition creation with Jsdl

jobPred4 = new DistJobDefinition();
jobPred4.setDescription("All values provided");
jobPred4.setFlowTargetKey(wksAgt);
jobPred4.setName("JSDLJOB");
jobPred4.setDefinedByJsdl(true);
jobPred4.setTaskString("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "
  <jsdl:jobDefinition xmlns:jsdl=\"http://www.abc.com/xmlns/prod/scheduling
  /1.0/jsdl\" " + "xmlns:jsdle=\"http://www.abc.com/xmlns/prod/scheduling/1.0/
  jsdle\">" + "<jsdl:application name=\"executable\">" + 
"<jsdle:executable interactive=
  \"false\">" + "<jsdle:script>hostname</jsdle:script>" + "</jsdle:executable>" 
  + "</jsdl:application>" + "</jsdl:jobDefinition>");
jobPred4.setRecoveryOption(RecoveryOption.STOP);  

Example 6: Adding a job stream definition with dependencies, jobs, and runcycle:

//Job Stream creation

JobStream js = null;
String jsName = "SBSCDBF1_1S";
String alias = "SBSCDBF1_1S";
js = new JobStream();
js.setName(jsName);
js.setFlowTargetKey(wks);
List<Job> joblist = js.getJobs();

//Jobs creation

Job jobPredecessor = new Job();
jobPredecessor.setName(jobPredName);
jobPredecessor.setJobDefinition(jobPred4);
jobPredecessor.setJobStreamKey((JobStreamKey) js.getKey());
Job jobSuccessor1 = new Job();
jobSuccessor1.setName(jobSucc1Name);
jobSuccessor1.setJobDefinition(jobOk);
jobSuccessor1.setJobStreamKey((JobStreamKey) js.getKey());

//Add Jobs into Job Stream

joblist.add(jobPredecessor);
joblist.add(jobSuccessor1);

//Add Dependencies to jobSuccessor1 from jobPredecessor

InternalDependency depend = new InternalDependency();
depend.setJobKey(new JobKey(jobOkName,(JobStreamKey) js.getKey()));
jobSuccessor1.getInternalDependencies().add(depend);

//Add a run cycle

RunCycle rcy = new RunCycle();
rcy.setCalendarKey(null);
rcy.setDescription("runCycleDescription");
rcy.setFreeDaysRule(FreeDaysRule.NEAREST_AFTER);
rcy.setICalendar("iCalendar");
rcy.setInclusive(false);
rcy.setName("runCycleName");
rcy.setOffsetType(null);
rcy.setOffsetValue(0);
rcy.getTimeRestrictions().setTimeDependent(true);
rcy.getTimeRestrictions().setStartOffset(43200000L);
rcy.getTimeRestrictions().setDeadlineOffset(14400000L);
rcy.getTimeRestrictions().setLatestStartOffset(3600000L);
rcy.getTimeRestrictions().setLatestStartAction(LateAction.CONTINUE);
rcy.setType(RunCycleType.SIMPLE);
rcy.setValidFrom(new Date(time - 86400000L));
rcy.setValidTo(new Date(time + 86400000L));
js.getRunCycles().add(rcy);