Job log from Multi Instance jobs

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
sankarsadasivan
Premium Member
Premium Member
Posts: 39
Joined: Tue Dec 23, 2003 3:47 am
Location: India

Job log from Multi Instance jobs

Post by sankarsadasivan »

Hi

I am trying to get the job logs of Multi instance server jobs and trying to wirte it in an OS file.

I am trying to use the following function

DSGetLogSummary(JobHandle, EventType, StartTime, EndTime, MaxNumber)

This function returns a dynamic array.

I am not sure how to declare and access dynamic arrays..
Can anybody throw some light how to use dynamic arrays and/or using this DSGetLogSummary function?.

Any other better alternative to get logs from multi instance jobs are also welcome.

Thanks in advance

Cheers
Sankar
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Sankar,

a dynamic array is just a string where the elements (in this case, separate lines of output) are separated by special characters. The mnemonic code @FM (field mark) is used in this case. If you wanted to write this out to a file you can do something along the lines of:

Code: Select all

SummaryArray = DSGetLogSummary(JobHandle, EventType, StartTime, EndTime, MaxNumber) 
ArrayLines = DCOUNT(SummaryArray,@FM) ;** count number of lines
OPENSEQ '/tmp/TextLogFile' TO SeqOutFilePtr ON ERROR CALL DSLogFatal('unable to open file','')
FOR Counter = 1 TO ArrayLines
   WRITESEQ FIELD(SummaryArray,@FM,Counter) ON SeqOutFilePtr ELSE CALL DSLogFatal('unable to write to file','')
NEXT Counter
WEOFSEQ SeqOutFilePtr ELSE CALL DSLogFatal('unable to write EOF to file','')
CLOSESEQ SeqOutFilePtr
** Note "SummaryArray<Counter>" can be used instead of the FIELD function
sankarsadasivan
Premium Member
Premium Member
Posts: 39
Joined: Tue Dec 23, 2003 3:47 am
Location: India

Job log from Multi Instance jobs

Post by sankarsadasivan »

Thanks ArndW.
That was quite useful, I enhanced the framework suggested by you to suit multi instant jobs and following is the code...Might be useful for some...

Thanks again for your help

Rgds
Sankar



************************************************************** Attaching the job handle of the job, whose log has to be written -
* I.JobName and I.LogFile are parameters
*************************************************************

hJob1 = DSAttachJob(I.JobName, DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed":JobName, "JobControl")
Abort
End

************************************************************** Calculating the job start time and the current time - the window for *getting the log and the invocation id of the job
*************************************************************

JobStartTime = DSGetJobInfo (hJob1, DSJ.JOBSTARTTIMESTAMP)
CurrentTime = Oconv(Date(),"D-YMD[4,2,2]"):' ':Field(TimeDate(), " ", 1, 1)
JobInvocationId = DSGetJobInfo (hJob1, DSJ.JOBINVOCATIONID)

Call DSLogInfo("Job Start time":JobStartTime,"JobControl")
Call DSLogInfo("Current time":CurrentTime,"JobControl")


************************************************************** Fetching the job log info using DSGetLogSummary in to the dynamic
* array LOGANY - Indicates all sort of log info
* 0 indicates unlimited records of log
*************************************************************

SummaryArray = DSGetLogSummary(hJob1, DSJ.LOGANY ,JobStartTime,CurrentTime,0)


*************************************************************
* Computing the number of lines of log, filtering the log based on
* invocation id and writting into the log file
*************************************************************

ArrayLines = DCOUNT(SummaryArray,@FM) ;** count number of lines

OpenSeq I.LogFile To SeqOutFilePtr Then
WeofSeq SeqOutFilePtr ;* write end-of-file mark immediately
End

FOR Counter = 1 TO ArrayLines
TempLine = FIELD(SummaryArray,@FM,Counter)
If FIELD(TempLine,'\',4) = JobInvocationId
Then

WriteSeq TempLine To SeqOutFilePtr
On Error
Call DSLogFatal("Error from status=":Status(),"JobControl")
End
Else
Call DSLogInfo ("Unable to Write to ","JobControl")
End

End
NEXT Counter

CloseSeq SeqOutFilePtr

*************************************************************
*End
*************************************************************
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Sankar,

good job; I love it when I post a rough framework and let whomever (in this case yourself) flesh out the basic idea and make it implementable! I'm glad it's working out for you.

(Hope nobody reading/posting the 2 concurrent CREATE threads looks at my code snippet - I did it again :roll: )
Titto
Participant
Posts: 148
Joined: Tue Jun 21, 2005 7:49 am

Re: Job log from Multi Instance jobs

Post by Titto »

Where do we code the following code is it in JobControl or create it as a After/Before job routine.

Any help is appreciated!!
sankarsadasivan wrote:Thanks ArndW.
That was quite useful, I enhanced the framework suggested by you to suit multi instant jobs and following is the code...Might be useful for some...

Thanks again for your help

Rgds
Sankar



************************************************************** Attaching the job handle of the job, whose log has to be written -
* I.JobName and I.LogFile are parameters
*************************************************************

hJob1 = DSAttachJob(I.JobName, DSJ.ERRFATAL)
If NOT(hJob1) Then
Call DSLogFatal("Job Attach Failed":JobName, "JobControl")
Abort
End

************************************************************** Calculating the job start time and the current time - the window for *getting the log and the invocation id of the job
*************************************************************

JobStartTime = DSGetJobInfo (hJob1, DSJ.JOBSTARTTIMESTAMP)
CurrentTime = Oconv(Date(),"D-YMD[4,2,2]"):' ':Field(TimeDate(), " ", 1, 1)
JobInvocationId = DSGetJobInfo (hJob1, DSJ.JOBINVOCATIONID)

Call DSLogInfo("Job Start time":JobStartTime,"JobControl")
Call DSLogInfo("Current time":CurrentTime,"JobControl")


************************************************************** Fetching the job log info using DSGetLogSummary in to the dynamic
* array LOGANY - Indicates all sort of log info
* 0 indicates unlimited records of log
*************************************************************

SummaryArray = DSGetLogSummary(hJob1, DSJ.LOGANY ,JobStartTime,CurrentTime,0)


*************************************************************
* Computing the number of lines of log, filtering the log based on
* invocation id and writting into the log file
*************************************************************

ArrayLines = DCOUNT(SummaryArray,@FM) ;** count number of lines

OpenSeq I.LogFile To SeqOutFilePtr Then
WeofSeq SeqOutFilePtr ;* write end-of-file mark immediately
End

FOR Counter = 1 TO ArrayLines
TempLine = FIELD(SummaryArray,@FM,Counter)
If FIELD(TempLine,'\',4) = JobInvocationId
Then

WriteSeq TempLine To SeqOutFilePtr
On Error
Call DSLogFatal("Error from status=":Status(),"JobControl")
End
Else
Call DSLogInfo ("Unable to Write to ","JobControl")
End

End
NEXT Counter

CloseSeq SeqOutFilePtr

*************************************************************
*End
*************************************************************
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You can write/execute the code discussed in this thread either in a Job Control section or in a before/after subroutine or even in a normal routine and call it from wherever you can call routines. Important is that the code never gets called with the jobname and instance of the calling process, due to a bug in DSAttachJob() the process will hang for 30 minutes and then return an error in attach.
Post Reply