Changeset 25892


Ignore:
Timestamp:
2012-07-03T19:53:05+12:00 (12 years ago)
Author:
ak19
Message:

First commit for allowing a SOLR collection to be activated without having to run ant restart to get Greenstone to allow searching the updated solr index.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java

    r25886 r25892  
    7474
    7575                String solr_home_str = GSFile.extHome(gsdl3_home, solr_ext_name);
    76                 File solr_home = new File(solr_home_str);
    77                 File solr_xml = new File(solr_home, "solr.xml");
    78 
    79                 all_solr_cores = new CoreContainer(solr_home_str, solr_xml);
     76
     77                all_solr_cores = new CoreContainer(solr_home_str);
    8078            }
    8179            catch (Exception e)
     
    9189    public boolean configure(Element info, Element extra_info)
    9290    {
    93         if (!super.configure(info, extra_info))
    94         {
    95             return false;
    96         }
    97 
     91        boolean success = super.configure(info, extra_info);
     92
     93        // 1. Make the CoreContainer reload solr.xml
     94        // This is particularly needed for when activate.pl is executed during
     95        // a running GS3 server. At that point, the solr collection is reactivated and
     96        // we need to tell Greenstone that the solr index has changed. This requires
     97        // the CoreContainer to reload the solr.xml file, and it all works again.
     98
     99        solr_core_cache.clear(); // clear the map of existing solr cores
     100       
     101        // Reload the updated solr.xml into the CoreContainer
     102        // (Doing an all_solr_cores.shutdown() first doesn't seem to be required)
     103        try {   
     104            String solr_home_str = all_solr_cores.getSolrHome();
     105            File solr_home = new File(solr_home_str);
     106            File solr_xml = new File( solr_home,"solr.xml" );
     107           
     108            all_solr_cores.load(solr_home_str,solr_xml);
     109        } catch (Exception e) {
     110            logger.error("Exception in GS2SolrSearch.configure(): " + e.getMessage());
     111            e.printStackTrace();
     112            return false;
     113        }
     114       
     115        if(!success) {
     116            return false;
     117        }
     118       
     119        // 2. Setting up facets
    98120        Element searchElem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
    99121        NodeList configIndexElems = searchElem.getElementsByTagName(GSXML.INDEX_ELEM);
  • main/trunk/greenstone2/bin/script/activate.pl

    r25889 r25892  
    430430    my $build_dir = undef;
    431431    my $index_dir = undef;
    432     my $site = undef;
     432    my $site = undef;
    433433   
    434434    my $removeold = 0;
    435435    my $keepold = 0;
    436    
     436    my $incremental = 0; # used by solr
     437
    437438    my $library_url = undef; # to be specified on the cmdline if not using a GS-included web server
    438439   
     
    455456        elsif ($arg eq "-keepold") {
    456457            $keepold = 1;
     458        }
     459        elsif ($arg eq "-incremental") {
     460            $incremental = 1;
    457461        }
    458462        elsif ($arg eq "-library_url") {
     
    595599    # If keepold: move building's contents into index, where only duplicates will get deleted.
    596600    # removeold and keepold can't both be on at the same time
    597     ($removeold, $keepold) = &scriptutil::check_removeold_and_keepold($removeold, $keepold,
    598                            0, # incremental is irrelevant to what activate.pl does, setting this = 0
     601        # incremental becomes relevant for solr, though it was irrelevant to what activate.pl does (moving building to index)
     602    my $incremental_mode;
     603    ($removeold, $keepold, $incremental, $incremental_mode) = &scriptutil::check_removeold_and_keepold($removeold, $keepold,
     604                           $incremental,
    599605                           $build_dir, # checkdir. Usually archives or export to be deleted. activate.pl deletes building
    600606                           $collectcfg);
     
    639645        }
    640646    }
    641     elsif ($keepold) {
    642             if ($buildtype eq "solr") { ### no building- prefix for keepold incremental case?
     647    elsif ($keepold || $incremental) {
     648            if ($buildtype eq "solr") {
    643649            # if solr, remove any cores that may be using the building_dir before moving this dir onto index
    644650            foreach my $corename (@corenames) {         
     
    652658        &util::mv_dir_contents($build_dir, $index_dir);
    653659    }
    654    
     660
    655661    if ($buildtype eq "solr") {
    656     # Call CREATE action to get all cores pointing to the index folder, since building is now index
    657     ### Should already be using the index_dir directory for $keepold (incremental) case? Then call RELOAD CORE
     662    # Call CREATE action to get the old cores pointing to the index folder
    658663    foreach my $corename (@corenames) {
    659664        if($removeold) {
     665        # Call CREATE action to get all cores pointing to the index folder, since building is now index
    660666        $solr_server->admin_create_core($corename, $index_dir);
    661         } elsif ($keepold) {
    662         $solr_server->admin_reload_core($corename);
     667       
     668        } elsif ($keepold || $incremental) {
     669        # Call RELOAD core. Should already be using the index_dir directory for $keepold and $incremental case
     670       
     671        # Ping to see if corename exists, if it does, reload, else create
     672        if ($solr_server->admin_ping_core($corename)) {
     673            $solr_server->admin_reload_core($corename);
     674        } else {
     675            $solr_server->admin_create_core($corename, $index_dir);
     676        }
    663677        }
    664678    }
Note: See TracChangeset for help on using the changeset viewer.