Use triggers

Triggers are automatic actions that will take place whenever an entry gets modified in the file catalogue.

Thee are two steps in order to have triggers in the catalogue: first, you have to define the action that will take place, and then, you have to assign the

action to a directory.

 

Defining trigger actions

The action for a trigger can be any shell script that you want. The only thing that has to be done is to register the file under /<org name>/triggers, or

under your $HOME/triggers in the catalogue. Whenever the trigger has to be executed, the script will be called, passing as the first argument the

name of the file.

For example, imagine that we want to send an email every time that a file gets registered. The script would be something like:

 

[pcitgd26] /home/psaiz > cat /tmp/mail.sh
#!/bin/bash
mail -s 'Hello file $1' pablo.saiz@cern.ch < /dev/null

[pcitgd26] /home/psaiz > alien
Oct 22 09:44:41 info Hello ALICE::CERN::SE
Warning: No valid proxy. Trying SSH key...
Oct 22 09:44:42 info We will talk to the PackMan
[aliendb06c.cern.ch:3307] /alice/cern.ch/user/p/psaiz/ > mkdir triggers
[aliendb06c.cern.ch:3307] /alice/cern.ch/user/p/psaiz/ > cd triggers
[aliendb06c.cern.ch:3307] /alice/cern.ch/user/p/psaiz/triggers/ > add mail /tmp/mail.sh
Oct 22 09:44:57 info The pfn '/tmp/mail.sh' does not look like a pfn... let's hope that it refers to
'file://pcitgd26.cern.ch/tmp/mail.sh'
<skipped>
Oct 22 09:47:52 info OK. Added the file /alice/cern.ch/user/p/psaiz/triggers/mail on 2 SEs as specified. Superb!
[aliendb06c.cern.ch:3307] /alice/cern.ch/user/p/psaiz/triggers/ >
 

And now we have a trigger called 'mail'.

 

Associating trigger actions with directories

There are three commands in AliEn for this action: addTrigger, showTrigger, and deleteTrigger. As their names suggest, the first one adds a trigger

to a directory, the second one displays the current triggers in a directory, and the last one deletes ones of the defined triggers from a directory. The

manual page explains the arguments that you need to call them

 

[aliendb06c.cern.ch:3307] /alice/cern.ch/user/p/psaiz/triggers/ > man addTrigger
AddTrigger - creates a Trigger on a table
Syntax:
addTriger <directory> <triggerName> [%lt;action> [%lt;fileName>]]

<action> can be: insert, update or delete

%lt;triggerName> has to be the name of a file defined in /triggers, /%lt;vo>/triggers or ~/triggers

%lt;fileName> will be the name of the entries that will activate the trigger (if not defined, all the entries will
 activate the trigger)

When the specified action happens in the directory, the script '%lt;triggerName>' will be called, and it will receive
the name of the file that has triggered the event.
 

 

* Warning * Triggers are defined on the underlying database tables. If you want to have the trigger only on a subdirectory, you should move the directory to

another table. See the commands 'showStructure' and 'moveDirectory' for a more detailed description.

 

 

A trigger example

As an example of a more elaborated trigger, this is what ALICE does when a new file from rawData gets registered in the catalogue. The trigger checks if it is

a root file, and if so, it adds the file to a collection. The trigger also used to replicate the file in another location with the 'mirror' command. However, that is not

used anymore because the file is already copied in several places once it is created.

 

 

[aliendb06c.cern.ch:3307] /alice/cern.ch/user/p/psaiz/triggers/ > cat /alice/triggers/rawData
#!/bin/sh
FILE=$1

echo "The file $1 has been inserted in the catalogue"

FILENAME=`echo $1 |awk -F \/ {'print \$NF'}`

echo "The filename is $FILENAME"

rawfile=0
rootfile=0
case $FILENAME in
*tag.root) echo "This is a tag file. Ignoring it";;
*.root) rootfile=1; echo got a root file;;
esac

case $FILE in
/alice/data/2007/LHC07w*) echo This is the right path;;
/alice/data/2008/*) echo "Data for 2008";;
/alice/data/2009/*) echo "Data for 2009";;
*) echo "Wrong path";rootfile=0;;
esac
 

my (\$type)=\$catalogue->execute("type", \$collection);
if (\$type !~ /^col/){
print "The collection doesn't exist ($type)\n";
\$catalogue->execute("createCollection", \$collection);
}
\$catalogue->execute("addFileToCollection", \$file, \$collection);
#\$catalogue->execute("mirror","-t", \$file,\$site);

 

EOF

$ALIEN_ROOT/bin/alien -x $TMPFILE
rm $TMPFILE

fi