Ignore:
Timestamp:
2011-08-23T14:23:40+12:00 (13 years ago)
Author:
davidb
Message:

Tidy up of code. Better structuring of classes

File:
1 edited

Legend:

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

    r24447 r24453  
    3131
    3232use lucenebuilder;
     33use solrserver;
    3334use Config; # for getting the perlpath in the recommended way
    3435
     
    271272
    272273
     274sub solr_core_admin
     275{
     276    my $self = shift (@_);
     277    my ($url) = @_;
     278
     279    my $cmd = "wget -q -O - \"$url\"";
     280
     281    my $status = undef;
     282
     283    if (open(WIN,"$cmd |")) {
     284
     285    my $xml_output = "";
     286    my $line;
     287    while (defined ($line=<WIN>)) {
     288
     289        $xml_output .= $line;
     290    }
     291    close(WIN);
     292
     293##  print $xml_output;
     294
     295    ($status) = ($xml_output =~ m!<int name="status">(\d+)</int>!s);
     296   
     297    }
     298    else {
     299    print STDERR "Warning: failed to run $cmd\n";
     300    print STDERR "  $!\n";
     301    }
     302
     303    return $status;
     304
     305}
     306
    273307sub pre_build_indexes
    274308{
     
    277311    my $outhandle = $self->{'outhandle'};
    278312
    279     # read in build.cfg if in incremental mode???
     313    # If the Solr/Jetty server is not already running, the following starts
     314    # it up, and only returns when the server is "reading and listening"
     315 
     316    my $solr_server = new solrserver();
     317    $solr_server->start();
     318    $self->{'solr_server'} = $solr_server;
    280319
    281320    my $indexes = [];
     
    350389    }
    351390
    352     # write out solr 'schema.xml' (and related) file
     391    # Write out solr 'schema.xml' (and related) file
     392    #
    353393    $self->make_final_field_list();
    354394    $self->premake_solr_auxiliary_files();
    355395
    356     # if collect==core not already in solr.xml (check with STATUS)
    357     # => use CREATE API to add to solr.xml
    358     #
    359     # else
    360     # => use RELOAD call to refresh fields now expressed in schema.xml
     396    # Now update the solr-core information in solr.xml
     397    # => at most two cores <colname>-Doc and <colname>-Sec
     398
     399    my $jetty_server_port = $ENV{'SOLR_JETTY_PORT'};
     400    my $base_url = "http://localhost:$jetty_server_port/solr/admin/cores";
     401
     402    my $collection = $self->{'collection'};
     403
     404    foreach my $level (keys %{$self->{'levels'}}) {
     405
     406    my $llevel = $mgppbuilder::level_map{$level};
     407
     408    my $core = $collection."-".lc($llevel);
     409    my $check_core_url = "$base_url?action=STATUS&core=$core";
     410
     411    my $check_status = $self->solr_core_admin($check_core_url);
     412   
     413    print STDERR "*** check status = $check_status\n";
     414
     415
     416    # if collect==core not already in solr.xml (check with STATUS)
     417    # => use CREATE API to add to solr.xml
     418    #
     419    # else
     420    # => use RELOAD call to refresh fields now expressed in schema.xml
     421    }
    361422
    362423}
     
    499560    #  $self->make_final_field_list()
    500561    # as this has been done in our pre_build_indexes() phase for solr
     562
     563
     564    # Also need to stop the Solr/jetty server if it was explicitly started
     565    # in pre_build_indexes()
    501566   
     567    my $solr_server = $self->{'solr_server'};
     568
     569    if ($solr_server->explicitly_started()) {
     570    $solr_server->stop();
     571    }
     572
     573    $self->{'solr_server'} = undef;
     574
    502575}   
    503576
Note: See TracChangeset for help on using the changeset viewer.