[MOBY-guts] biomoby commit
Enrique de Andres Saiz
deandres at dev.open-bio.org
Thu Mar 15 09:50:50 UTC 2007
deandres
Thu Mar 15 05:50:50 EDT 2007
Update of /home/repository/moby/moby-live/Perl/MOBY/Async
In directory dev.open-bio.org:/tmp/cvs-serv24918
Modified Files:
Service.pm
Log Message:
Added enumerated_execute and enumerated_submit methods
moby-live/Perl/MOBY/Async Service.pm,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Async/Service.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Perl/MOBY/Async/Service.pm 2007/03/13 15:50:58 1.3
+++ /home/repository/moby/moby-live/Perl/MOBY/Async/Service.pm 2007/03/15 09:50:50 1.4
@@ -53,6 +53,23 @@
Comment : for more information about arguments look up execute
method at MOBY::Client::Service.
+=head2 enumerated_execute
+
+ Name : enumerated_execute
+ Function : execute the asynchronous MOBY service using self-enumerated
+ inputs; this method invoke internally to the enumerated_submit,
+ poll and result methods. It calculates polling time according
+ to the status messages received from the provider. If from
+ that messages is not possible to infer the polling time, it
+ calculates a pseudo-random polling time, whoose value increases
+ until is up to around 1 hour.
+ Usage : $result = $Service->execute(%args)
+ Args : Input => \%data
+ Returns : a MOBY message containing whatever the service provides
+ as output.
+ Comment : for more information about arguments look up enumerated_execute
+ method at MOBY::Client::Service.
+
=head2 submit
Name : submit
@@ -63,6 +80,17 @@
Comment : for more information about arguments look up execute
method at MOBY::Client::Service.
+=head2 enumerated_submit
+
+ Name : enumerated_submit
+ Function : submit the asynchronous MOBY service using self-enumerated
+ inputs.
+ Usage : ($EPR, @queryIDs) = $Service->submit(%args)
+ Args : XMLinputlist => \%data
+ Returns : WSRF::WS_Address object with an EPR and the input queryIDs.
+ Comment : for more information about arguments look up enumerated_execute
+ method at MOBY::Client::Service.
+
=head2 poll
Name : poll
@@ -245,6 +273,130 @@
return ($EPR, @queryIDs);
}
+sub enumerated_execute {
+ my ($self, %args) = @_;
+
+ print "Creating WS-Resource...\n\n" unless ($self->{silent});
+
+ my $start = time;
+ my ($EPR, @queryIDs) = $self->enumerated_submit(%args);
+
+ print XML::LibXML->new->parse_string($EPR->XML)->getDocumentElement()->toString."\n\n" unless ($self->{silent});
+
+ my $pollingTime;
+ my ($i, $j) = (0, 1);
+ my @status;
+ while ( $pollingTime = &_getPollingTime($i, $j, $start, @status) ) {
+ ($i, $j) = ($j, $i+$j);
+
+ print "Next polling in $pollingTime seconds...\n\n" unless ($self->{silent});
+
+ sleep $pollingTime;
+ @status = $self->poll($EPR, @queryIDs);
+
+ unless ($self->{silent}) {
+ foreach my $st (@status) {
+ print $st->XML."\n";
+ }
+ print "\n";
+ }
+ }
+
+ print "Retrieving results and destroying WS-Resource...\n\n" unless ($self->{silent});
+
+ my @responses = $self->result($EPR, @queryIDs);
+ $self->destroy($EPR);
+ my $response = &_composeResponse(@responses);
+
+ print "Finished.\n" unless ($self->{silent});
+
+ return $response;
+}
+
+sub enumerated_submit {
+ my ($self, %args) = @_;
+
+ # Compose the moby message (part of this block is copied from MOBY::Client::Service)
+ die "ERROR: expected Input to be a HASH ref" unless ( ref( $args{Input} ) eq 'HASH' );
+ my %inputs = %{$args{Input}};
+ my @queryIDs = keys %inputs;
+ my $data;
+ foreach my $qID ( @queryIDs ) {
+
+ die "ERROR: expected hashref {articleName => XML} for each queryID" unless ( ref($inputs{$qID}) eq 'HASH' );
+ my %articles = %{$inputs{$qID}};
+ $data .= "<moby:mobyData queryID='$qID'>";
+
+ foreach my $articleName(keys %articles){
+
+ my $XML = $articles{$articleName};
+ if ( ref( $XML ) ne 'ARRAY' ) {
+
+ $XML ||= "";
+ if ( $XML =~ /\<(moby\:|)Value\>/ ){
+ $data .= "<moby:Parameter moby:articleName='$articleName'>$XML</moby:Parameter>";
+ } else {
+ $data .= "<moby:Simple moby:articleName='$articleName'>\n$XML\n</moby:Simple>\n";
+ }
+
+ } elsif ( ref( $XML ) eq 'ARRAY' ) {
+
+ my @objs = @{$XML};
+ $data .= "<moby:Collection moby:articleName='$articleName'>\n";
+ foreach ( @objs ) {
+ $data .= "<moby:Simple>$_</moby:Simple>\n";
+ }
+ $data .= "</moby:Collection>\n";
+ }
+ }
+ $data .= "</moby:mobyData>\n";
+ }
+ my $version = $self->{smessageVersion};
+ $data = "<?xml version='1.0' encoding='UTF-8'?>
+ <moby:MOBY xmlns:moby='http://www.biomoby.org/moby' moby:smessageVersion='$version'>
+ <moby:mobyContent>
+ $data
+ </moby:mobyContent>
+ </moby:MOBY>";
+
+ # Create the resource and submit the batch-call
+ my $func = $self->{serviceName}.'_submit';
+ my $ans = WSRF::Lite
+ -> proxy(&_getServiceEndpoint($self->{service}))
+ -> uri($WSRF::Constants::MOBY)
+ -> $func(SOAP::Data->value($data)->type('string'));
+ die "ERROR: ".$ans->faultstring if ($ans->fault);
+
+ # Get address from the returned Endpoint Reference
+ my $address = $ans->match("//Body//{$WSRF::Constants::WSA}Address") ?
+ $ans->valueof("//Body//{$WSRF::Constants::WSA}Address") :
+ die "ERROR: no EndpointReference returned";
+ die "ERROR: no address into returned EndpointReference" unless ($address);
+
+ # Get resource identifier from the returned Endpoint Reference
+ my $identifier;
+ if ($ans->dataof('//Body//ReferenceParameters/*')) {
+ foreach my $a ($ans->dataof('//Body//ReferenceParameters/*')) {
+ my $name = $a->name();
+ my $uri = $a->uri();
+ my $value = $a->value();
+ if ($name eq "ServiceInvocationId") {
+ $identifier = $value;
+ last;
+ }
+ }
+ }
+ die "ERROR: no identifier into returned EndpointReference" unless ($identifier);
+
+ # Compose the Endpoint Reference
+ my $EPR = WSRF::WS_Address->new();
+ $EPR->Address($address);
+ $EPR->ReferenceParameters('<moby:ServiceInvocationId xmlns:moby="'.$WSRF::Constants::MOBY.'">'.$identifier.'</moby:ServiceInvocationId>');
+
+ # Return Endpoint Reference and the queryIDs
+ return ($EPR, @queryIDs);
+}
+
sub poll {
my ($self, $EPR, @queryIDs) = @_;
More information about the MOBY-guts
mailing list