[Bio] / FigWebServices / cluster_stage.cgi Repository:
ViewVC logotype

Annotation of /FigWebServices/cluster_stage.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (view) (download)

1 : olson 1.4 #
2 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 : olson 1.1 use strict;
19 :    
20 :     #use Common::Errors;
21 :    
22 :     =head1 Cluster Staging Interface
23 :    
24 :     This module provides a CGI interface for retrieving staged input files via HTTP.
25 :    
26 :     The client must provide the job id and work id for the staging work that we
27 :     are retrieving.
28 :    
29 :     =cut
30 :    
31 :     use strict;
32 :     use FIG;
33 :     use CGI;
34 :    
35 :     use Cluster;
36 :    
37 :     my $cgi = new CGI;
38 :    
39 :     sub fail($)
40 :     {
41 :     my($mesg) = @_;
42 :    
43 :     print $cgi->header(-type => "text/html",
44 :     -status => "500 error");
45 :     print "Staging failed: $mesg\n";
46 :     exit;
47 :     }
48 :    
49 : olson 1.3 if (0)
50 :     {
51 : olson 1.2 warn "Environment:\n";
52 :     for my $k (sort keys(%ENV))
53 :     {
54 :     warn "$k=$ENV{$k}\n";
55 :     }
56 :    
57 :     warn "Params:\n";
58 :     for my $k ($cgi->param())
59 :     {
60 :     warn "$k=" . $cgi->param($k) . "\n";
61 :     }
62 : olson 1.3 }
63 : olson 1.1
64 :     my $fig = new FIG;
65 :     my $job_id = $cgi->param("job_id");
66 :     my $work_id = $cgi->param("work_id");
67 : olson 1.2 my $filename = $cgi->param("file");
68 : olson 1.1
69 :     $job_id =~ /^\d+/ or fail "Invalid job_id\n";
70 :     $work_id =~ /^\d+/ or fail "Invalid work_id\n";
71 :    
72 : olson 1.2 #
73 :     # If filename has been give, we're uploading. Otherwise
74 :     # this is a download.
75 :    
76 : olson 1.1 my $c = new Cluster::Broker($fig);
77 :    
78 : olson 1.2 if ($filename ne "")
79 :     {
80 :     warn "Doing upload\n";
81 :     eval {
82 :     do_upload($c, $fig, $job_id, $work_id, $filename);
83 :     };
84 :     if ($@)
85 :     {
86 :     fail "upload failed: $@";
87 :     }
88 :     }
89 :     else
90 :     {
91 :     warn "Doing download\n";
92 :     do_download($c, $fig, $job_id, $work_id);
93 :     }
94 :    
95 :     sub do_upload
96 :     {
97 :     my($c, $fig, $job_id, $work_id, $filename) = @_;
98 : olson 1.1
99 : olson 1.2 warn " UPLOAD: jobid=$job_id work_id=$work_id filename=$filename\n";
100 : olson 1.1
101 : olson 1.2 #
102 :     # Determine location of output file.
103 :     #
104 :    
105 :     my $output_fh = $c->open_output_file($job_id, $work_id, $filename);
106 :    
107 :     #
108 :     # File is passed as the cgi parameter named "file".
109 :     #
110 :     my $fh = $cgi->upload('file');
111 :     warn "Got fh $fh\n";
112 :    
113 :     my($n, $buf);
114 :     while ($n = read($fh, $buf, 4096))
115 :     {
116 :     print $output_fh $buf;
117 :     }
118 :     close($fh);
119 :     close($output_fh);
120 : olson 1.1
121 : olson 1.2 print $cgi->header(-type => "text/plain");
122 :     print "File uploaded OK\n";
123 :     }
124 : olson 1.1
125 : olson 1.2 sub do_download
126 : olson 1.1 {
127 : olson 1.2 my($c, $fig, $job_id, $work_id) = @_;
128 :    
129 :     my ($fh, $size, $basename);
130 :    
131 :     my $ok = eval {
132 :     ($fh, $size, $basename) = $c->open_staging_file($job_id, $work_id);
133 :     };
134 :    
135 :     $ok or fail "$@";
136 :     $fh or fail "Cannot find staging file";
137 :    
138 :     print $cgi->header(-type => "application/octet-stream",
139 :     -Content_Length => $size,
140 :     -Content_Disposition => "attachment;filename=\"$basename\"",
141 :     );
142 :    
143 :     my $buf;
144 :     while (my $n = read($fh, $buf, 4096))
145 :     {
146 :     print $buf;
147 :     }
148 :    
149 :     close($fh);
150 : olson 1.1 }
151 :    
152 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3