1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # ParallelInexport.pm -- useful class to support parallel_import.pl
|
---|
4 | # A component of the Greenstone digital library software
|
---|
5 | # from the New Zealand Digital Library Project at the
|
---|
6 | # University of Waikato, New Zealand.
|
---|
7 | #
|
---|
8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or modify
|
---|
11 | # it under the terms of the GNU General Public License as published by
|
---|
12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
13 | # (at your option) any later version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful,
|
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | # GNU General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, write to the Free Software
|
---|
22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | #
|
---|
24 | ###########################################################################
|
---|
25 |
|
---|
26 | package ParallelInexport;
|
---|
27 |
|
---|
28 | use strict;
|
---|
29 |
|
---|
30 |
|
---|
31 | # index the files in parallel using MPI farmer to farm off multiple processes
|
---|
32 | # [hs, 1 july 2010]
|
---|
33 | sub farm_out_processes
|
---|
34 | {
|
---|
35 | my ($jobs, $epoch, $importdir, $block_hash, $collection, $site) = @_;
|
---|
36 |
|
---|
37 | my $tmp_filelist = &util::filename_cat($ENV{'GSDLHOME'}, "tmp", "filelist.txt");
|
---|
38 |
|
---|
39 | # create the list of files to import
|
---|
40 | open (my $filelist, ">$tmp_filelist");
|
---|
41 | foreach my $filename (sort keys %{$block_hash->{'all_files'}})
|
---|
42 | {
|
---|
43 | my $full_filename = &util::filename_cat($importdir,$filename);
|
---|
44 | if ((! exists $block_hash->{'file_blocks'}->{$full_filename})
|
---|
45 | && ($filename !~ m/metadata\.xml$/))
|
---|
46 | {
|
---|
47 | print $filelist "$filename\n";
|
---|
48 | }
|
---|
49 | }
|
---|
50 | close ($filelist);
|
---|
51 |
|
---|
52 | # invoke the farmer to start processing the files
|
---|
53 | $site = "localsite" if ((!defined $site) || ($site eq ""));
|
---|
54 | my $gsdlhome = $ENV{'GSDLHOME'};
|
---|
55 | my $farmer_exe = &util::filename_cat($gsdlhome,"bin",$ENV{'GSDLOS'},"farmer".&util::get_os_exe());
|
---|
56 |
|
---|
57 | my $mpi_cmd = "mpirun -np $jobs $farmer_exe $tmp_filelist $epoch $gsdlhome $site $collection";
|
---|
58 |
|
---|
59 | system ($mpi_cmd);
|
---|
60 | }
|
---|
61 |
|
---|
62 | 1;
|
---|