345 lines
8.7 KiB
Plaintext
345 lines
8.7 KiB
Plaintext
<%@ jet
|
|
package="org.talend.designer.codegen.translators"
|
|
imports="
|
|
org.talend.core.model.process.IProcess
|
|
org.talend.core.model.process.INode
|
|
org.talend.core.model.process.IConnection
|
|
org.talend.core.model.process.EConnectionType
|
|
org.talend.core.model.process.ElementParameterParser
|
|
org.talend.designer.codegen.config.CodeGeneratorArgument
|
|
org.talend.designer.runprocess.CodeGeneratorRoutine
|
|
org.talend.designer.codegen.i18n.Messages
|
|
org.talend.core.ui.branding.IBrandingService
|
|
org.talend.core.ui.branding.AbstractBrandingService
|
|
org.talend.core.GlobalServiceRegister
|
|
java.util.List
|
|
java.util.Vector
|
|
java.util.Map
|
|
"
|
|
class="Header"
|
|
%>
|
|
<%
|
|
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
|
Vector v = (Vector) codeGenArgument.getArgument();
|
|
IProcess process = (IProcess)v.get(0);
|
|
String version = (String)v.get(1);
|
|
|
|
List< ? extends INode> processNodes = (List< ? extends INode>)process.getGeneratingNodes();
|
|
boolean stats = codeGenArgument.isStatistics();
|
|
boolean trace = codeGenArgument.isTrace();
|
|
%>
|
|
#!/usr/bin/perl
|
|
|
|
=head1 <%=ElementParameterParser.getValue(process, "__NAME__") %>
|
|
Job <%=ElementParameterParser.getValue(process, "__NAME__") %>, version <%=ElementParameterParser.getValue(process, "__VERSION__") %>, status <%=ElementParameterParser.getValue(process, "__STATUS__") %>.
|
|
Author: <%=ElementParameterParser.getValue(process, "__AUTHOR__") %>
|
|
Purpose: <%=ElementParameterParser.getValue(process, "__PURPOSE__") %>
|
|
<%=ElementParameterParser.getValue(process, "__DESCRIPTION__") %>
|
|
=cut
|
|
|
|
<%
|
|
if (stats) {
|
|
%>
|
|
use talend::runstat;
|
|
<%
|
|
}
|
|
%>
|
|
<%
|
|
if (trace) {
|
|
%>
|
|
use talend::trace;
|
|
<%
|
|
}
|
|
|
|
for (INode node : process.getNodesOfType("tLibraryLoad")) {
|
|
List<Map<String, String>> libraries =
|
|
(List<Map<String,String>>)ElementParameterParser.getObjectValue(
|
|
node,
|
|
"__LIBRARIES__"
|
|
);
|
|
|
|
for (Map<String, String> library : libraries) {
|
|
%>
|
|
use <%=library.get("LIBRARY")%>;
|
|
<%
|
|
}
|
|
|
|
}
|
|
|
|
for (String routine : CodeGeneratorRoutine.getRequiredRoutineName(process)) {
|
|
%>
|
|
use <%=routine%>;
|
|
<%
|
|
}
|
|
%>
|
|
|
|
my $_licence = <<'END_OF_LICENCE';
|
|
<%
|
|
IBrandingService service=(IBrandingService)GlobalServiceRegister.getDefault().getService(IBrandingService.class);
|
|
if(service instanceof AbstractBrandingService){
|
|
%>
|
|
<%=((AbstractBrandingService) service).getJobLicenseHeader(version).replace("//", "#").replace("#www", "//www") %>
|
|
<%}%>
|
|
END_OF_LICENCE
|
|
|
|
# print $_licence;
|
|
|
|
use Getopt::Long;
|
|
use Time::HiRes qw/gettimeofday tv_interval time/;
|
|
my %opt = ();
|
|
GetOptions(
|
|
\%opt,
|
|
(
|
|
'context=s',
|
|
'stat_port=i',
|
|
'trace_port=i',
|
|
'client_host=s',
|
|
'watch',
|
|
'pid=s',
|
|
'father_pid=s',
|
|
'root_pid=s',
|
|
'context_param=s%',
|
|
'context_param_encoding=s',
|
|
)
|
|
);
|
|
|
|
$defaultClientHost = "127.0.0.1";
|
|
$clientHost = $opt{client_host} ? $opt{client_host} : $defaultClientHost;
|
|
|
|
<%
|
|
if (trace) {
|
|
%>
|
|
StartTrace($opt{trace_port}, $clientHost) if defined $opt{trace_port};
|
|
<%
|
|
}
|
|
%>
|
|
|
|
our %_context;
|
|
our %_globals;
|
|
|
|
$_globals{pid} = defined $opt{pid}
|
|
? $opt{pid}
|
|
: getRandomString(6, ['a'..'z', 'A'..'Z', 0..9])
|
|
;
|
|
|
|
$_globals{father_pid} = defined $opt{father_pid}
|
|
? $opt{father_pid}
|
|
: $_globals{pid}
|
|
;
|
|
|
|
$_globals{root_pid} = defined $opt{root_pid}
|
|
? $opt{root_pid}
|
|
: $_globals{pid}
|
|
;
|
|
|
|
$_globals{job_name} = '<%=codeGenArgument.getJobName() %>';
|
|
$_globals{job_repository_id} = '<%=process.getId() %>';
|
|
$_globals{job_version} = '<%=process.getVersion() %>';
|
|
$_globals{system_pid} = $$;
|
|
$_globals{project_name} = '<%=codeGenArgument.getCurrentProjectName() %>';
|
|
$_globals{start} = [gettimeofday];
|
|
$_globals{job_execution_datetime} = getDate('CCYY-MM-DD hh:mm:ss');
|
|
|
|
if (defined $opt{context}) {
|
|
my $context_filename =
|
|
$_globals{project_name}
|
|
.'.job_'.$_globals{job_name}
|
|
.'_'.$_globals{job_version}
|
|
.'_'.$opt{context}
|
|
.'.pl'
|
|
;
|
|
|
|
use FindBin;
|
|
use lib $FindBin::Bin;
|
|
require $context_filename;
|
|
}
|
|
|
|
if (defined $opt{context_param}) {
|
|
my $cb = undef;
|
|
|
|
if (defined $opt{context_param_encoding}) {
|
|
require Convert::BaseN;
|
|
$cb = Convert::BaseN->new(base => $opt{context_param_encoding});
|
|
}
|
|
|
|
foreach my $key (keys %{ $opt{context_param} }) {
|
|
my $raw_value = $opt{context_param}{$key};
|
|
$_context{$key} = defined $cb ? $cb->decode($raw_value) : $raw_value;
|
|
}
|
|
}
|
|
|
|
<% // Constants for RUN IF OK links %>
|
|
use constant true => 1;
|
|
use constant false => 0;
|
|
use constant null => undef;
|
|
|
|
<% // Constants for RUN IF Error links %>
|
|
$SIG{__DIE__} = \&global_die_catcher;
|
|
$current_component = undef;
|
|
|
|
<%
|
|
for (INode statCatcher : process.getNodesOfType("tStatCatcher")) {
|
|
%>
|
|
<%=statCatcher.getUniqueName()%>_subprocess(
|
|
message_type => 'begin',
|
|
);
|
|
|
|
<%
|
|
}
|
|
%>
|
|
|
|
$current_component = undef;
|
|
|
|
sub global_die_catcher {
|
|
# go away if we are inside an eval
|
|
return if $^S;
|
|
|
|
our $_globals;
|
|
$_globals{job_failure} = 1;
|
|
|
|
if (defined $current_component) {
|
|
my $dying_component = $current_component;
|
|
|
|
my $exception = $_[0];
|
|
chomp($exception);
|
|
|
|
$_globals{$dying_component}{ERROR_MESSAGE} = $exception;
|
|
|
|
<%
|
|
for (INode logCatcher : process.getNodesOfType("tLogCatcher")) {
|
|
%>
|
|
<%=logCatcher.getUniqueName()%>_subprocess(
|
|
type => 'Perl die',
|
|
origin => $dying_component,
|
|
priority => 6,
|
|
message => $_globals{$dying_component}{ERROR_MESSAGE},
|
|
);
|
|
<%
|
|
}
|
|
for (INode statCatcher : process.getNodesOfType("tStatCatcher")) {
|
|
%>
|
|
if (exists $_globals{$dying_component}{start}) {
|
|
<%=statCatcher.getUniqueName()%>_subprocess(
|
|
message_type => 'end',
|
|
message => 'failure',
|
|
duration => int(
|
|
tv_interval(
|
|
$_globals{$dying_component}{start},
|
|
[gettimeofday]
|
|
)
|
|
* 1000
|
|
),
|
|
origin => $dying_component,
|
|
);
|
|
}
|
|
|
|
<%
|
|
}
|
|
for (INode assertCatcher : process.getNodesOfType("tAssertCatcher")) {
|
|
%>
|
|
<%=assertCatcher.getUniqueName()%>_subprocess(
|
|
origin => $dying_component,
|
|
description => $_globals{$dying_component}{ERROR_MESSAGE},
|
|
status => 'Failed',
|
|
substatus => 'Job execution error',
|
|
);
|
|
<%
|
|
}
|
|
%>
|
|
no strict 'refs';
|
|
&{$dying_component.'_error'}();
|
|
}
|
|
|
|
<%
|
|
// there should be 0 or 1 tPostJob
|
|
for (INode postjob : process.getNodesOfType("tPostjob")) {
|
|
%>
|
|
<%=postjob.getUniqueName()%>_subprocess();
|
|
<%
|
|
}
|
|
%>
|
|
|
|
|
|
<%
|
|
for (INode statCatcher : process.getNodesOfType("tStatCatcher")) {
|
|
%>
|
|
$_globals{stop} = [gettimeofday];
|
|
|
|
$_globals{duration} = int(
|
|
tv_interval(
|
|
$_globals{start},
|
|
$_globals{stop}
|
|
)
|
|
* 1000
|
|
);
|
|
|
|
<%=statCatcher.getUniqueName()%>_subprocess(
|
|
message_type => 'end',
|
|
message => $_globals{job_failure} ? 'failure' : 'success',
|
|
duration => $_globals{duration},
|
|
);
|
|
<%
|
|
}
|
|
%>
|
|
# if the error was catched, we say to the father job that everything is OK
|
|
if ($_globals{job_failure} == 0) {
|
|
exit(0);
|
|
}
|
|
}
|
|
<% // Methods for RUN IF Error links %>
|
|
|
|
# OnComponentError dedicated subs for all components of the job design
|
|
<%
|
|
for (INode node : processNodes) {
|
|
if (node.isActivate()) {
|
|
%>
|
|
sub <%=node.getUniqueName() %>_error() {
|
|
<%
|
|
List< ? extends IConnection> conns =
|
|
node.getOutgoingConnections();
|
|
|
|
for (IConnection conn : conns) {
|
|
if (conn.getLineStyle().equals(EConnectionType.ON_COMPONENT_ERROR)){
|
|
%>
|
|
<%=conn.getTarget().getUniqueName() %>_subprocess();
|
|
$_globals{job_failure} = 0;
|
|
<%
|
|
}
|
|
}
|
|
INode subProcessStartNode = node.getDesignSubjobStartNode();
|
|
%>
|
|
|
|
# even if the error was "catched" in an OnComponentError, we call the
|
|
# corresponding OnSubjobError sub
|
|
<%=subProcessStartNode.getUniqueName()%>_onSubjobError();
|
|
}
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
|
|
# OnSubjobError dedicated subs for all components responsible (starting) a
|
|
# subjob
|
|
<%
|
|
for (INode node : processNodes) {
|
|
if (node.isActivate() && node.isDesignSubjobStartNode()) {
|
|
%>
|
|
sub <%=node.getUniqueName()%>_onSubjobError() {
|
|
<%
|
|
List< ? extends IConnection> conns = node.getOutgoingConnections();
|
|
for (IConnection conn : conns) {
|
|
EConnectionType connType = conn.getLineStyle();
|
|
if (connType.equals(EConnectionType.ON_SUBJOB_ERROR)) {
|
|
%>
|
|
<%=conn.getTarget().getUniqueName() %>_subprocess();
|
|
$_globals{job_failure} = 0;
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
}
|
|
<%
|
|
}
|
|
}
|
|
%>
|