[Bio] / FigKernelPackages / ServerThing.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/ServerThing.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.45, Fri Mar 19 18:27:07 2010 UTC revision 1.51, Wed Apr 28 15:46:38 2010 UTC
# Line 5  Line 5 
5      use strict;      use strict;
6      use Tracer;      use Tracer;
7      use YAML;      use YAML;
8        use JSON::Any;
9      use ERDB;      use ERDB;
10      use TestUtils;      use TestUtils;
11      use Time::HiRes;      use Time::HiRes;
# Line 14  Line 15 
15      no warnings qw(once);      no warnings qw(once);
16    
17      # Maximum number of requests to run per invocation.      # Maximum number of requests to run per invocation.
18      use constant MAX_REQUESTS => 5000;      use constant MAX_REQUESTS => 50;
19    
20  =head1 General Server Helper  =head1 General Server Helper
21    
# Line 519  Line 520 
520          ($genomeA, $genomeB) = ($genome1, $genome2);          ($genomeA, $genomeB) = ($genome1, $genome2);
521      }      }
522      # Insure the source organism has a subdirectory in the organism cache.      # Insure the source organism has a subdirectory in the organism cache.
523      my $orgDir = "$FIG_Config::orgCache/$genomeA";      my $orgDir = ComputeCorrespondenceDirectory($genomeA);
     Tracer::Insure($orgDir, 0777);  
524      # Compute the name of the correspondence file for the appropriate target genome.      # Compute the name of the correspondence file for the appropriate target genome.
525      $fileName = "$orgDir/$genomeB";      $fileName = "$orgDir/$genomeB";
526      # Return the results.      # Return the results.
# Line 528  Line 528 
528  }  }
529    
530    
531    =head3 ComputeCorresopndenceDirectory
532    
533        my $dirName = ServerThing::ComputeCorrespondenceDirectory($genome);
534    
535    Return the name of the directory that would contain the correspondence files
536    for the specified genome.
537    
538    =over 4
539    
540    =item genome
541    
542    ID of the genome whose correspondence file directory is desired.
543    
544    =item RETURN
545    
546    Returns the name of the directory of interest.
547    
548    =back
549    
550    =cut
551    
552    sub ComputeCorrespondenceDirectory {
553        # Get the parameters.
554        my ($genome) = @_;
555        # Insure the source organism has a subdirectory in the organism cache.
556        my $retVal = "$FIG_Config::orgCache/$genome";
557        Tracer::Insure($retVal, 0777);
558        # Return it.
559        return $retVal;
560    }
561    
562    
563  =head3 CreateGeneCorrespondenceFile  =head3 CreateGeneCorrespondenceFile
564    
565      my ($fileName, $converse) = ServerThing::CheckForGeneCorrespondenceFile($genome1, $genome2);      my ($fileName, $converse) = ServerThing::CheckForGeneCorrespondenceFile($genome1, $genome2);
# Line 837  Line 869 
869    
870  =item cgi  =item cgi
871    
872  CGI query object containing the parameters from the web service request.  CGI query object containing the parameters from the web service request. The
873    significant parameters are as follows.
874    
875    =over 8
876    
877    =item function
878    
879    Name of the function to run.
880    
881    =item args
882    
883    Parameters for the function.
884    
885    =item encoding
886    
887    Encoding scheme for the function parameters, either C<yaml> (the default) or C<json> (used
888    by the Java interface).
889    
890    =back
891    
892    Certain unusual requests can come in outside of the standard function interface.
893    These are indicated by special parameters that override all the others.
894    
895    =over 8
896    
897    =item pod
898    
899    Display a POD documentation module.
900    
901    =item code
902    
903    Display an example code file.
904    
905    =item file
906    
907    Transfer a file (not implemented).
908    
909    =back
910    
911  =item serverThing  =item serverThing
912    
# Line 878  Line 947 
947          # Insure the function name is valid.          # Insure the function name is valid.
948          Die("Invalid function name.")          Die("Invalid function name.")
949              if $function =~ /\W/;              if $function =~ /\W/;
950            # Determing the encoding scheme. The default is YAML.
951            my $encoding = $cgi->param('encoding') || 'yaml';
952          # The parameter structure will go in here.          # The parameter structure will go in here.
953          my $args;          my $args;
954          # Start the timer.          # Start the timer.
# Line 888  Line 959 
959          my $sapling;          my $sapling;
960          # Protect from errors.          # Protect from errors.
961          eval {          eval {
962              # Parse the arguments.              # Here we parse the arguments. This is affected by the encoding parameter.
963              $args = YAML::Load($cgi->param('args'));              # Get the argument string.
964                my $argString = $cgi->param('args');
965                if ($encoding eq 'yaml') {
966                    # Parse the arguments using YAML.
967                    $args = YAML::Load($argString);
968                } elsif ($encoding eq 'json') {
969                    # Parse the arguments using JSON.
970                    Trace("Incoming string is:\n$argString") if T(3);
971                    $args = JSON::Any->jsonToObj($argString);
972                } else {
973                    Die("Invalid encoding type $encoding.");
974                }
975          };          };
976          # Check to make sure we got everything.          # Check to make sure we got everything.
977          if ($@) {          if ($@) {
# Line 903  Line 985 
985                  SendError($@, "Error detected by service.");                  SendError($@, "Error detected by service.");
986                  Trace("Error encountered by service: $@") if T(0);                  Trace("Error encountered by service: $@") if T(0);
987              } else {              } else {
988                  # No error, so we output the result.                  # No error, so we output the result. Start with an HTML header.
989                  print $cgi->header(-type => 'text/plain');                  print $cgi->header(-type => 'text/plain');
990                  my $string = YAML::Dump($document);                  # The nature of the output depends on the encoding type.
991                    my $string;
992                    if ($encoding eq 'yaml') {
993                        $string = YAML::Dump($document);
994                    } else {
995                        $string = JSON::Any->objToJson($document);
996                    }
997                  print $string;                  print $string;
998                  MemTrace(length($string) . " bytes returned from $function by task $$.") if T(Memory => 3);                  MemTrace(length($string) . " bytes returned from $function by task $$.") if T(Memory => 3);
999              }              }
# Line 1076  Line 1164 
1164      my ($module) = @_;      my ($module) = @_;
1165      # Start the output page.      # Start the output page.
1166      print CGI::header();      print CGI::header();
1167      print CGI::start_html(-title => 'Documentation Page',      print CGI::start_html(-title => "$module Documentation Page",
1168                            -style => { src => "http://servers.nmpdr.org/sapling/Html/css/ERDB.css" });                            -style => { src => "http://servers.nmpdr.org/sapling/Html/css/ERDB.css" });
1169      # Protect from errors.      # Protect from errors.
1170      eval {      eval {

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.51

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3