SAP Commissions – Under the hood of Stage-hooks


Adding Pipeline Stage Hooks

If custom pipeline processing is required before a pipeline stage is run, after a stage
completes, or in the event of any stage exits due to an application exception, stage hooks can
be added to perform the required processing.

so below are the types of pipeline stage hooks, how to create and install them, and provides you a samples of each type of stage hook.

Types of Pipeline Stage Hooks

Pipeline stage hooks can support java class, script file, or stored procedure.

Type Description
Java class A java class. This class must implement an interface, StageHook.
To use a java class stage hook, you must install the java class first.
For a sample java class, including a sample xml descriptor, installation
instructions, and a definition of the StageHook interface,
Script file A batch file or shell script
Stored procedure A stored procedure, compiled into the TCMP/EXT schema

Note: All stage hook messages are logged to the controller.log. For a stage failure
hook, the pipeline exits after the stage failure hook returns

Pipeline stage hooks have three possible run times, as described

Pipeline Stage Hook Run Times

Type Description
pre-stage Pre-stage hooks are executed prior to the specified stage.
For example, a prestage hook for the Allocate stage will execute before the Allocate stage begins.
post-stage Post-stage hooks are executed after the specified stage has completed.
For example, a post-stage hook for the Allocate stage will execute when the
Allocate stage completes
stage failure A stage failure hook is called if any stage exits because there is an exception
during the pipeline run. You can only specify one stage failure hook for the
whole pipeline. If any stage exits due to an exception, the stage failure hook is
called. A common use of the stage failure hook is to call a program to send email to an administrator if there is a pipeline failure

Defining Pipeline Stage Hooks

Stage hooks are defined in a file called StageHookDescriptor.xml. This file needs to be provided to Technical Support team through ticket which will be placed on Pipeline Grid Server in the following location: /pipeline/classpath/properties

Note: Any time that you add stage hooks, support team must restart the application server. A file called StageHookDescriptorTemplate.xml is included in directory. file can be used as a reference to create a StageHookDescriptor.xml file. The tags and attributes of the StageHookDescriptor.xml file


sample StageHookDescriptor.xml

<stagehooks version="1.0">
<script/>
<script/>
<stagehook stagename="AllocateAggregation">
<poststage type="storedproc">
<command><TENANTID>.Yoga_Stagehook.PostAllocateAggregation</command>
<pipelineArgs>
<name>period</name>
<name>calendar</name>
<name>processingUnitSeq</name>
</pipelineArgs>
</poststage>
</stagehook>
<stagehook stagename="Reward">
<poststage type="storedproc">
<command><TENANTID>.Yoga_Stagehook.Stamp_PostReward</command>
<pipelineArgs>
<name>period</name>
<name>calendar</name>
<name>processingUnitSeq</name>
</pipelineArgs>
</poststage>
</stagehook>
<stagehook stagename="Classify">
<prestage type="storedproc">
<command><TENANTID>.Yoga_Stagehook.PreClassify</command>
<pipelineArgs>
<name>period</name>
<name>calendar</name>
<name>processingUnitSeq</name>
</pipelineArgs>
</prestage>
</stagehook>
</stagehooks>

Stored Proc Package

CREATE OR REPLACE PACKAGE <TENANTID>.Yoga_Stagehook
as
PROCEDURE PostAllocateAggregation (
P_PERIODNAME IN CS_PERIOD.NAME%TYPE ,
P_CALENDARNAME IN CS_CALENDAR.NAME%TYPE,
P_PROCESSINUNITSEQ IN CS_PROCESSINGUNIT.PROCESSINGUNITSEQ %TYPE ) ; PROCEDURE PostReward (
P_PERIODNAME IN CS_PERIOD.NAME%TYPE,
P_CALENDARNAME IN CS_CALENDAR.NAME%TYPE,
P_PROCESSINUNITSEQ IN CS_PROCESSINGUNIT.PROCESSINGUNITSEQ%TYPE
); Procedure PreClassify( P_PERIODNAME IN CS_PERIOD.NAME%TYPE, P_CALENDARNAME IN CS_CALENDAR.NAME%TYPE, P_PROCESSINUNITSEQ IN CS_PROCESSINGUNIT.PROCESSINGUNITSEQ%TYPE); end Yoga_Stagehook;
/

Stored Proc Package body

CREATE OR REPLACE PACKAGE BODY <TENANTID>.Yoga_Stagehook AS g_periodname cs_period.name%TYPE; g_periodseq cs_period.periodseq%TYPE;
g_period_startdate cs_period.startdate%TYPE;
g_period_enddate cs_period.enddate%TYPE;
g_processingunitseq cs_processingunit.processingunitseq%TYPE;
g_processingunitname CS_PROCESSINGUNIT.NAME%TYPE;
g_calendarname cs_calendar.name%TYPE;
g_calendarseq cs_calendar.calendarseq%TYPE;
g_eot cs_period.removedate%TYPE := TO_DATE ('1-JAN-2200', 'DD-MON-YYYY');
g_unittypeseq CS_UNITTYPE.UNITTYPESEQ%TYPE; PROCEDURE setGlobals (p_period cs_period.name%TYPE, p_calendar cs_calendar.name%TYPE, p_processingunit cs_processingunit.name%TYPE) AS BEGIN g_calendarname := p_calendar; g_periodname := p_period;
g_processingunitname := p_processingunit; SELECT processingunitseq INTO g_processingunitseq
FROM cs_processingunit
WHERE name = g_processingunitname; DBMS_OUTPUT.put_line ('g_calendarname=' || g_calendarname); SELECT calendarseq INTO g_calendarseq
FROM cs_calendar
WHERE name = g_calendarname AND removedate = g_eot; SELECT periodseq, startdate, enddate INTO g_periodseq, g_period_startdate, g_period_enddate
FROM cs_period
WHERE calendarseq = g_calendarseq AND removedate = g_eot AND name = g_periodname; SELECT UNITTYPESEQ INTO g_unittypeseq
FROM cs_unittype
WHERE name='USD' AND removedate >sysdate; END setGlobals; ---- Start your Procedure ----------------- ---- End your Procedure -----------------
END Yoga_Stagehook;
/

Run the pipeline to check if stagehook is getting Triggered,

Go to Pipeline Logs – Select the Stage where stagehook is placed and download

Understanding through Logs