Changeset 25888

Show
Ignore:
Timestamp:
28.06.2012 18:54:11 (7 years ago)
Author:
ak19
Message:

First working version of activate.pl modified for handling solr collections. It needs to update solr cores when moving building to index.

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/perllib/solrserver.pm

    r24643 r25888  
    204204} 
    205205 
    206  
     206# Some of the Solr CoreAdmin API calls available.  
     207# See http://wiki.apache.org/solr/CoreAdmin 
    207208sub admin_reload_core 
    208209{ 
     
    215216} 
    216217 
     218sub admin_rename_core 
     219{ 
     220    my $self = shift @_; 
     221    my ($oldcore, $newcore) = @_; 
     222 
     223    my $cgi_get_args = "action=RENAME&core=$oldcore&other=$newcore"; 
     224 
     225    $self->_admin_service($cgi_get_args); 
     226} 
     227 
     228sub admin_swap_core 
     229{ 
     230    my $self = shift @_; 
     231    my ($oldcore, $newcore) = @_; 
     232 
     233    my $cgi_get_args = "action=SWAP&core=$oldcore&other=$newcore"; 
     234 
     235    $self->_admin_service($cgi_get_args); 
     236} 
     237 
     238# The ALIAS action is not supported in our version of solr (despite it 
     239# being marked as experimental in the documentation for Core Admin) 
     240sub admin_alias_core 
     241{ 
     242    my $self = shift @_; 
     243    my ($oldcore, $newcore) = @_; 
     244 
     245    my $cgi_get_args = "action=ALIAS&core=$oldcore&other=$newcore"; 
     246 
     247    $self->_admin_service($cgi_get_args); 
     248} 
    217249 
    218250sub admin_create_core 
    219251{ 
    220252    my $self = shift @_; 
    221     my ($core,$removeold) = @_; 
     253    my ($core, $data_parent_dir) = @_; # data_parent_dir is optional, can be index_dir. Defaults to builddir if not provided 
    222254 
    223255    my ($ds_idx) = ($core =~ m/^.*-(.*?)$/); 
     
    227259    my $collect_home = $ENV{'GSDLCOLLECTDIR'}; 
    228260    my $etc_dirname = &util::filename_cat($collect_home,"etc"); 
    229          
    230     my $build_dir = $self->{'build_dir'}; 
    231     my $idx_dirname = &util::filename_cat($build_dir,$ds_idx); 
     261 
     262    if(!defined $data_parent_dir) { 
     263    $data_parent_dir = $self->{'build_dir'}; 
     264    }  
     265     
     266    my $idx_dirname = &util::filename_cat($data_parent_dir,$ds_idx); # "dataDir"   
    232267         
    233268    $cgi_get_args .= "&instanceDir=$etc_dirname"; 
     
    237272} 
    238273 
    239  
     274# removes (unloads) core from th eext/solr/sorl.xml config file 
     275sub admin_unload_core 
     276{ 
     277    my $self = shift @_; 
     278    my ($core) = @_; 
     279 
     280    my $cgi_get_args = "action=UNLOAD&core=$core"; # &deleteIndex=true from Solr3.3 
     281 
     282    $self->_admin_service($cgi_get_args); 
     283} 
     284 
     285sub copy_solrxml_to_web 
     286{ 
     287    my $self = shift @_; 
     288 
     289    my $ext_solrxml = &util::filename_cat($ENV{'GEXT_SOLR'}, "solr.xml"); 
     290    my $web_solrxml = &util::filename_cat($ENV{'GSDL3HOME'}, "ext", "solr", "solr.xml"); 
     291 
     292    #print STDERR "@@@@ Copying $ext_solrxml to $web_solrxml...\n"; 
     293 
     294    &util::cp($ext_solrxml, $web_solrxml); 
     295} 
    240296 
    241297sub start 
  • main/trunk/greenstone2/bin/script/activate.pl

    r25887 r25888  
    520520    $buildtype = "mg"; #mg is the default 
    521521    } 
     522 
     523    my $solr_server; 
     524    my @corenames = (); 
     525    if($buildtype eq "solr") { # start up the jetty server   
     526    my $solr_ext = $ENV{'GEXT_SOLR'}; # from solr_passes.pl 
     527    unshift (@INC, "$solr_ext/perllib"); 
     528    require solrserver; 
     529 
     530    # Solr cores are named without taking the collection-group name into account, since solr 
     531    # is used for GS3 and GS3 doesn't use collection groups but has the site concept instead 
     532    my ($colname, $colgroup) = &util::get_collection_parts($qualified_collection); 
     533 
     534    # See solrbuilder.pm to get the indexing levels (document, section) from the collectcfg file 
     535    # Used to generate core names from them and remove cores by name 
     536    foreach my $level ( @{$collectcfg->{'levels'}} ){ 
     537        my ($pindex) = $level =~ /^(.)/; 
     538        my $indexname = $pindex."idx"; 
     539        push(@corenames, "$site-$colname-$indexname"); #"$site-$colname-didx", "$site-$colname-sidx" 
     540        } 
     541     
     542    # If the Solr/Jetty server is not already running, the following starts 
     543    # it up, and only returns when the server is "reading and listening"     
     544    $solr_server = new solrserver($build_dir); 
     545    $solr_server->start(); 
     546 
     547    # We'll be moving building to index. For solr collection, there's further  
     548    # special processing to make a corresponding change to the solr.xml 
     549    # by removing the temporary building cores and (re)creating the index cores 
     550    } 
    522551     
    523552    # Now the logic in GLI's CollectionManager.java (processComplete()  
     
    572601     
    573602    if($removeold) { 
     603 
     604        if ($buildtype eq "solr") { 
     605        # if solr, remove any cores using the index_dir before deleting this dir 
     606        foreach my $corename (@corenames) { 
     607            $solr_server->admin_unload_core($corename); 
     608        } 
     609        }    
    574610         
    575611        if(&util::dir_exists($index_dir)) { 
     
    596632    } 
    597633    elsif ($keepold) { 
     634            if ($buildtype eq "solr") {  
     635            # if solr, remove any cores using the index_dir before deleting this dir 
     636            foreach my $corename (@corenames) {          
     637            $solr_server->admin_unload_core($corename); 
     638            } 
     639        } 
     640         
    598641        # Copy just the contents of building dir into the index dir, overwriting  
    599642        # existing files, but don't replace index with building. 
     
    602645    } 
    603646     
     647    if ($buildtype eq "solr") { 
     648    # Call CREATE action to get the old cores pointing to the index folder 
     649    foreach my $corename (@corenames) { 
     650        $solr_server->admin_create_core($corename, $index_dir); 
     651    } 
     652 
     653    # copy the just updated ext/solr/solr.xml to web/ext/solr/solr.xml 
     654    $solr_server->copy_solrxml_to_web(); 
     655    } 
     656 
    604657    # 4. Ping the library URL, and if it's a persistent server and running, activate the collection again    
    605658     
     
    643696 
    644697    &print_msg("\n"); 
     698 
     699    if($buildtype eq "solr") { 
     700    if ($solr_server->explicitly_started()) { 
     701        $solr_server->stop(); 
     702    } 
     703    } 
    645704} 
    646705