MOSES-MOBY
view release on metacpan or search on metacpan
lib/MOSES/MOBY/Generators/templates/service.tt view on Meta::CPAN
[%- END %]
# EDIT: PUT REAL VALUES INTO THE RESPONSE
# fill the response
[%- FOREACH output IN base.outputs %]
[%- IF is_simple(output) %]
[%- unique_output_name = unique (output.name) %]
my $[% unique_output_name %] = new [% output.datatype.module_name %]
(
[%- children = get_children (output.datatype.name) %]
[%- IF children.size == 0 %]
[% no_children (output.datatype.name) %]
[%- ELSE %]
[%- FOREACH child IN children %]
[%- set_child (child, 2) %]
[%- END %]
[%- END %]
);
$response->[% output.name %] ($[% unique_output_name %]);
[%- ELSE %]
foreach my $elem (0..2) {
my $[% output.name %] = new [% output.elements.0.datatype.module_name %]
(
[%- children = get_children (output.elements.0.datatype.name) %]
[%- IF children.size == 0 %]
[% no_children (output.elements.0.datatype.name) %]
[%- ELSE %]
[%- FOREACH child IN children %]
[%- set_child (child, 6 '$elem') %]
[%- END %]
[%- END %]
);
$response->add_[% output.name %] ($[% output.name %]);
}
[%- END %]
[%- END %]
# fill service notes (if you wish)
$context->serviceNotes
('Response created at ' . gmtime() . ' (GMT), by the service \'[% base.name %]\'.');
# this is how to fill (record) exceptions
# $response->record_info ('This is an info');
# $response->record_warning ('This is a warning');
# $response->record_error ('This is an error');
# $response->record_error ( { code => INPUTS_INVALID,
# msg => 'This is an error with a code' } );
}
[%- IF is_async(base.category) -%]
#-----------------------------------------------------------------
# update_state_event
# This method is used to update the state of your
# LSAE_STATE_CHANGED_EVENT event.
#
# Parameters:
# $request - $request from process_it()
# $state - one of (created, running, completed, terminated_by_request, terminated_by_error)
# $msg - a message to provide regarding the state of our event
#-----------------------------------------------------------------
sub update_state_event {
my ( $self, $request, $state, $msg ) = @_;
my %valid_states = ('created'=>1,'running'=>1,'completed'=>1,'termintated_by_request'=>1,'terminated_by_error'=>1,);
$msg = '' unless defined $msg;
$state = 'running' unless defined $state;
# validate the state of the event ...
$state = 'running' unless $valid_states{$state};
unless ( defined $ENV{ID} ) {
# hmm, local testing of service?
$ENV{ID} = WSRF::GSutil::CalGSH_ID();
WSRF::File::toFile($ENV{ID});
}
# our service invocation id
my $ID = $ENV{ID};
# our job id
my $jid = $request->jid;
# some variables we need to access/store our event information
my $property_pid = "pid_$jid";
my $property_input = "input_$jid";
my $property_status = "status_$jid";
my $property_result = "result_$jid";
# construct an LSAE object based on the old event block
my $old_status = LSAE::AnalysisEventBlock->new(
$WSRF::WSRP::ResourceProperties{$property_status}
);
# construct a new state changed event
my $status = LSAE::AnalysisEventBlock->new();
$status->type(LSAE_STATE_CHANGED_EVENT);
# set the previous state
$status->previous_state( $old_status->new_state() ) if defined ($old_status->type) and $old_status->type == LSAE_STATE_CHANGED_EVENT;
$status->previous_state( 'created') unless $status->previous_state;
# set the new state
$status->new_state($state);
$status->message($msg);
# set our job id for this event
$status->id($jid);
# create a file based resource that we will store our event information
my $lock = WSRF::MobyFile->new( undef, $ID );
$WSRF::WSRP::ResourceProperties{$property_status} = $status->XML();
# here we leave the result empty since the service is still running
$WSRF::WSRP::ResourceProperties{$property_result} = '';
# save the event so that our clients can access the information
$lock->toFile();
return;
}
#-----------------------------------------------------------------
# update_percentage_event
# This method is used to update the state of your
# LSAE_PERCENT_PROGRESS_EVENT event.
#
# Parameters:
# $request - $request from process_it()
# $percentrage - an integer between 0-100
# $msg - a message to provide regarding the state of our event
#-----------------------------------------------------------------
sub update_percentage_event {
my ( $self, $request, $percentage, $msg ) = @_;
$msg = '' unless defined $msg;
$percentage = 1 unless defined $percentage;
# validate the state of the event ...
$percentage = 1 unless $percentage >= 0 and $percentage <=100;
unless ( defined $ENV{ID} ) {
# hmm, local testing of service?
$ENV{ID} = WSRF::GSutil::CalGSH_ID();
WSRF::File::toFile($ENV{ID});
}
# our service invocation id
my $ID = $ENV{ID};
# our job id
my $jid = $request->jid;
# some variables we need to access/store our event information
my $property_pid = "pid_$jid";
my $property_input = "input_$jid";
my $property_status = "status_$jid";
my $property_result = "result_$jid";
# construct an LSAE object based on the old event block
my $old_status = LSAE::AnalysisEventBlock->new(
$WSRF::WSRP::ResourceProperties{$property_status}
);
# construct a new state changed event
my $status = LSAE::AnalysisEventBlock->new();
$status->type(LSAE_PERCENT_PROGRESS_EVENT);
# set the new state
$status->percentage($percentage);
$status->message($msg);
# set our job id for this event
$status->id($jid);
# create a file based resource that we will store our event information
my $lock = WSRF::MobyFile->new( undef, $ID );
$WSRF::WSRP::ResourceProperties{$property_status} = $status->XML();
# here we leave the result empty since the service is still running
$WSRF::WSRP::ResourceProperties{$property_result} = '';
# save the event so that our clients can access the information
$lock->toFile();
return;
}
#-----------------------------------------------------------------
# update_step_event
# This method is used to update the state of your
# LSAE_STEP_PROGRESS_EVENT event.
#
# Parameters:
# $request - $request from process_it()
# $total_steps - integer representing total steps until completion
# $steps_completed - integer representing steps completed
# $msg - a message to provide regarding the state of our event
#-----------------------------------------------------------------
sub update_step_event {
my ( $self, $request, $total_steps, $steps_completed, $msg ) = @_;
$msg = '' unless defined $msg;
$total_steps = 1 unless defined $total_steps;
$steps_completed = 0 unless defined $steps_completed;
# validate the state of the event ...
$steps_completed = $total_steps if $steps_completed > $total_steps;
unless ( defined $ENV{ID} ) {
# hmm, local testing of service?
$ENV{ID} = WSRF::GSutil::CalGSH_ID();
WSRF::File::toFile($ENV{ID});
}
# our service invocation id
my $ID = $ENV{ID};
# our job id
my $jid = $request->jid;
# some variables we need to access/store our event information
my $property_pid = "pid_$jid";
my $property_input = "input_$jid";
my $property_status = "status_$jid";
my $property_result = "result_$jid";
# construct an LSAE object based on the old event block
my $old_status = LSAE::AnalysisEventBlock->new(
$WSRF::WSRP::ResourceProperties{$property_status}
);
# construct a new state changed event
my $status = LSAE::AnalysisEventBlock->new();
$status->type(LSAE_STEP_PROGRESS_EVENT);
# set the new state
$status->steps_completed($steps_completed);
$status->total_steps($total_steps);
$status->message($msg);
# set our job id for this event
$status->id($jid);
# create a file based resource that we will store our event information
my $lock = WSRF::MobyFile->new( undef, $ID );
$WSRF::WSRP::ResourceProperties{$property_status} = $status->XML();
# here we leave the result empty since the service is still running
$WSRF::WSRP::ResourceProperties{$property_result} = '';
# save the event so that our clients can access the information
$lock->toFile();
return;
}
#-----------------------------------------------------------------
# update_time_event
# This method is used to update the state of your
# LSAE_TIME_PROGRESS_EVENT event.
#
# Parameters:
# $request - $request from process_it()
# $remaining - integer representing seconds until completion
# $msg - a message to provide regarding the state of our event
#-----------------------------------------------------------------
sub update_time_event {
my ( $self, $request, $remaining, $msg ) = @_;
$msg = '' unless defined $msg;
$remaining = 0 unless defined $remaining;
# validate the state of the event ...
$remaining = 0 unless $remaining >= 0 ;
unless ( defined $ENV{ID} ) {
# hmm, local testing of service?
$ENV{ID} = WSRF::GSutil::CalGSH_ID();
WSRF::File::toFile($ENV{ID});
}
# our service invocation id
my $ID = $ENV{ID};
# our job id
my $jid = $request->jid;
# some variables we need to access/store our event information
my $property_pid = "pid_$jid";
my $property_input = "input_$jid";
my $property_status = "status_$jid";
my $property_result = "result_$jid";
# construct an LSAE object based on the old event block
my $old_status = LSAE::AnalysisEventBlock->new(
$WSRF::WSRP::ResourceProperties{$property_status}
);
# construct a new state changed event
my $status = LSAE::AnalysisEventBlock->new();
$status->type(LSAE_TIME_PROGRESS_EVENT);
# set the new state
$status->remaining($remaining);
$status->message($msg);
# set our job id for this event
$status->id($jid);
# create a file based resource that we will store our event information
my $lock = WSRF::MobyFile->new( undef, $ID );
$WSRF::WSRP::ResourceProperties{$property_status} = $status->XML();
# here we leave the result empty since the service is still running
$WSRF::WSRP::ResourceProperties{$property_result} = '';
# save the event so that our clients can access the information
$lock->toFile();
return;
}
[%- END -%]
1;
__END__
=head1 NAME
[% impl.package %] - a BioMoby service
( run in 1.821 second using v1.01-cache-2.11-cpan-39bf76dae61 )