Newer
Older
The *Task* entities defined in a *Processor* definition can be implemented as dedicated native java plugins or as scripts written in *Perl*, *Python* or *Shell* scripting languages.
Dedicated native java plugins can be developed by implementing the GenericTaskInterface process method defined in the DES library
**GenericTaskInterface Interface**
```java
public interface GenericTaskInterface {
/**
*
* @param basepath Basepath as configured in DistributionServer.ini
* @param aoi_name AOI name contained in the $processor.processor_config.xml
* @param processor_name Processor name related to the $processor.processor_config.xml
* @param entity_name Name of executing entity (Task, Consumer, etc.)
* @param parameters Parameters as defined by <Parameter>
* @param args List of arguments of the Task (String or Hashtables, to be checked by the plugin)
* @param files List of files of the Task IFF <FileType>regexp</FileType> is defined, else null
* @return ExitCodes
*/
public int process(String basepath, String aoi_name,
String processor_name, String entity_name, Hashtable parameters, Object[] args, String[] files);
}
```
The implemented plugin should be packaged as a jar file and placed in the DES ./plugins directory where it is automatically loaded at Runtime.
The plugin can be executed in a given *Processor* *Task* with the following definition:
Example:
```xml
<Task name="renameFiles" type="class" active="yes" priority="NORM">
<Command>class</Command>
<FileType>SAMPLE.*.AA.txt</FileType>
<Parameter>edu.eurac.distributionserver.tasks.generic.FileRename</Parameter>
<FilePrefix>RENAME</FilePrefix>
</Task>
```
The parameters can be passed to the *Task* plugin with one of the following options:
- By using a custom keyword tag eg. *FilePrefix* in the *Task* definition and then accessing the parameter with the Hashtable parameters in the Interface
- By using the *Parameter* tag in the *Task* definition and than referencing the parameter with the Object[] args type in the Interface
If a given *Task* is implemented with a scripting language (*Perl*, *Python*, *Shell*), the script must consider the following input parameters:
[BASE_PATH] [AOI] [PROCESSOR] [Parameter_1] [Parameter_N] ... [$FILE*]
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
IFF a *FileType* filtering is defined for the *Task*, the last parameter, defined above as $FILE, is the filename of the 1st file filtered by the Task execution.
In this case the script will be executed N times, for each file filtered by the FileType regular expression.
Example:
```perl
#!/usr/bin/perl -w
# This script is part of a Task collection available for the DES (Data Exchange Server)
# usage: testPerl.pl [base_path] [aoi] [procesosr_name] [CWD]
#main
print "running testPerl.pl\n";
my $base_path = "null";
my $aoi = "null";
my $processor_name = "null";
my $working_dir = "null";
print scalar(@ARGV);
print " ";
print "Parameters: @ARGV\n";
if(scalar(@ARGV) < 4){
print "missing arguments!\n";
print "usage: testPerl.pl [base_path] [aoi] [procesosr_name] [CWD]\n";
exit -1;
}else{
$base_path = $ARGV[0];
$aoi = $ARGV[1];
$processor_name = $ARGV[2];
$working_dir = $ARGV[3];
print "base_path: $base_path, aoi: $aoi, processor_name: $processor_name, CWD: $working_dir\n";
exit 0;
}
```
The *Task* definition for the script above is:
```xml
<Task name="testExitCode" type="cmd" active="yes" priority="NORM">
<EMail>mail@host.yourdomain</EMail>
<NotifyEmail>false</NotifyEmail>
<Command>perl</Command>
<Parameter>./test_data/scripts/testPerlExitCode.pl</Parameter>
<Parameter>0</Parameter>
</Task>
```