Ignore:
Timestamp:
2011-08-26T00:22:29+12:00 (13 years ago)
Author:
davidb
Message:
Reworking of code that detects existing running instance of Solr/Jetty server. This was due to Windows version of Perl not implementing '' on an open call. Code currently messy and needs a further tidy up.
File:
1 edited

Legend:

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

    r24456 r24483  
    117117        print STDERR "Sections:      $solr_passes_sections\n";
    118118        print STDERR "Build Dir:     $build_dir\n";
    119         print STDERR "Cmd:           $solr_passes_exe $collection text $solr_passes_sections \"$build_dir\" \"dummy\"   $osextra\n";
    120     if (!open($handle, "| $solr_passes_exe $collection text $solr_passes_sections \"$build_dir\" \"dummy\"   $osextra"))
     119        print STDERR "Cmd:           $solr_passes_exe $collection text dummy \"$build_dir\" \"dummy\"   $osextra\n";
     120    if (!open($handle, "| $solr_passes_exe $collection text dummy \"$build_dir\" \"dummy\"   $osextra"))
    121121    {
    122122        print STDERR "<FatalError name='NoRunSolrPasses'/>\n</Stage>\n" if $self->{'gli'};
     
    272272
    273273
    274 sub solr_core_admin
    275 {
    276     my $self = shift (@_);
    277     my ($url) = @_;
    278 
    279     my $cmd = "wget -O - \"$url\" 2>&1";
    280 
    281     my $preamble_output = "";   
    282     my $xml_output = "";
    283     my $error_output = undef;
    284 
    285     my $in_preamble = 1;
    286    
    287     if (open(WIN,"$cmd |")) {
    288 
    289     my $line;
    290     while (defined ($line=<WIN>)) {
    291 
    292         if ($line =~ m/ERROR \d+:/) {
    293         chomp $line;
    294         $error_output = $line;
    295         last;
    296         }
    297         elsif ($in_preamble) {
    298         if ($line =~ m/<.*>/) {
    299             $in_preamble = 0;
    300         }
    301         else {
    302             $preamble_output .= $line;
    303         }
    304         }
    305 
    306         if (!$in_preamble) {
    307         $xml_output .= $line;
    308         }
    309     }
    310     close(WIN);
    311 
    312     }
    313     else {
    314     $error_output = "Error: failed to run $cmd\n";
    315     $error_output .= "  $!\n";
    316     }
    317 
    318     my $output = { 'preamble' => $preamble_output,
    319            'output'   => $xml_output,
    320            'error'    => $error_output };
    321 
    322     return $output;
    323 }
    324 
    325274sub pre_build_indexes
    326275{
     
    415364    # => at most two cores <colname>-Doc and <colname>-Sec
    416365
    417     my $jetty_server_port = $ENV{'SOLR_JETTY_PORT'};
    418     my $base_url = "http://localhost:$jetty_server_port/solr/admin/cores";
    419 
    420366    my $collection = $self->{'collection'};
    421367
     
    427373    my ($pindex) = $level =~ /^(.)/;
    428374   
    429     my $llevel = $mgppbuilder::level_map{$level};
    430     my $core = $collection."-".lc($llevel);
    431    
    432    
    433     # if collect==core not already in solr.xml (check with STATUS)
    434     # => use CREATE API to add to solr.xml
     375##  my $llevel = $mgppbuilder::level_map{$level};
     376##  my $core = $collection."-".lc($llevel);
     377       
     378    my $core = $collection."-".$pindex.$idx;
     379
     380    # if collect==core already in solr.xml (check with STATUS)
     381    # => use RELOAD call to refresh fields now expressed in schema.xml
    435382    #
    436383    # else
    437     # => use RELOAD call to refresh fields now expressed in schema.xml
    438    
    439    
    440     my $check_core_url    = "$base_url?action=STATUS&core=$core";
    441     my $output = $self->solr_core_admin($check_core_url);
    442 
    443     if (defined $output->{'error'}) {
    444 
    445         my $preamble = $output->{'preamble'};
    446         my $error    = $output->{'error'};
    447 
    448         print STDERR "----\n";
    449         print STDERR "Error: Failed to get XML response from:\n";
    450         print STDERR "         $check_core_url\n";
    451         print STDERR "Output was:\n";
    452         print STDERR $preamble if ($preamble ne "");
    453         print STDERR "$error\n";
    454         print STDERR "----\n";
    455 
    456         next;
    457     }
    458    
    459     # If the collection doesn't exist yet, then there will be
    460     # an empty element of the form:
    461     #   <lst name="collect-doc"/>
    462     # where 'collect' is the actual name of the collection,
    463     # such as demo
    464 
    465     my $xml_output = $output->{'output'};
    466    
    467     my $empty_element="<lst\\s+name=\"$core\"\\s*\\/>";
    468    
    469     my $check_core_exists = !($xml_output =~ m/$empty_element/s);
    470    
    471     if ($check_core_exists) {
    472        
    473         my $reload_core_url    = "$base_url?action=RELOAD&core=$core";
    474        
     384    # => use CREATE API to add to solr.xml
     385       
     386    my $check_core_exists = $solr_server->admin_ping_core($core);
     387       
     388    if ($check_core_exists) {       
    475389        print $outhandle "Reloading Solr core: $core\n";
    476         $self->solr_core_admin($reload_core_url);
     390        $solr_server->admin_reload_core($core);
    477391    }
    478392    else {
    479        
    480         my $collect_home = $ENV{'GSDLCOLLECTDIR'};
    481         my $etc_dirname = &util::filename_cat($collect_home,"etc");
    482        
    483         my $build_dir = $self->{'build_dir'};
    484         my $idx_dirname = &util::filename_cat($build_dir,$pindex.$idx);
    485        
    486         my $create_core_url    = "$base_url?action=CREATE&name=$core";
    487         $create_core_url .= "&instanceDir=$etc_dirname";
    488         $create_core_url .= "&dataDir=$idx_dirname";
    489        
    490393        print $outhandle "Creating Solr core: $core\n";
    491         $self->solr_core_admin($create_core_url);
     394        $solr_server->admin_create_core($core);
    492395    }
    493396    }
     
    574477    } else {
    575478    my $collection = $self->{'collection'};
    576 
    577     print STDERR "Cmd: $solr_passes_exe $opt_create_index $collection index $solr_passes_sections \"$build_dir\" \"$indexdir\"   $osextra\n";
    578     if (!open($handle, "| $solr_passes_exe $opt_create_index $collection index $solr_passes_sections \"$build_dir\" \"$indexdir\"   $osextra")) {
     479    my $ds_idx = $self->{'index_mapping'}->{$index};
     480
     481    print STDERR "Cmd: $solr_passes_exe $opt_create_index $collection index $ds_idx \"$build_dir\" \"$indexdir\"   $osextra\n";
     482    if (!open($handle, "| $solr_passes_exe $opt_create_index $collection index $ds_idx \"$build_dir\" \"$indexdir\"   $osextra")) {
    579483        print STDERR "<FatalError name='NoRunSolrPasses'/>\n</Stage>\n" if $self->{'gli'};
    580484        die "solrbuilder::build_index - couldn't run $solr_passes_exe\n!$\n";
Note: See TracChangeset for help on using the changeset viewer.