Changeset 30563

Show
Ignore:
Timestamp:
04.06.2016 22:56:37 (4 years ago)
Author:
litvinovg
Message:

Undoing solr cores initialization commit to move code in solr extension repo

Location:
main/trunk/greenstone3
Files:
1 removed
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/Collection.java

    r30550 r30563  
    3232import org.apache.commons.lang3.StringUtils; 
    3333import org.apache.log4j.Logger; 
    34 import org.apache.solr.client.solrj.SolrServerException; 
    35 import org.apache.solr.client.solrj.impl.HttpSolrServer; 
    36 import org.apache.solr.client.solrj.impl.HttpSolrServer.RemoteSolrException; 
    37 import org.apache.solr.client.solrj.request.CoreAdminRequest; 
    38 import org.apache.solr.client.solrj.response.CoreAdminResponse; 
    39 import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction; 
    40 import org.apache.solr.common.util.NamedList; 
    4134import org.greenstone.gsdl3.core.ModuleInterface; 
    4235import org.greenstone.gsdl3.util.GSFile; 
     
    144137        { 
    145138            col_type = search.getAttribute(GSXML.TYPE_ATT); 
    146             //If use Solr check if cores loaded 
    147             if (col_type.equals("solr")) 
    148             { 
    149                 if (!loadSolrCores()) { 
    150                     logger.error("Collection: couldn't configure collection: " + this.cluster_name + ", " + "Couldn't activate Solr cores"); 
    151                     return false; 
    152                 } 
    153             } 
    154         } 
    155          
     139        } 
     140 
    156141        Element browse = (Element) GSXML.getChildByTagName(coll_config_xml, GSXML.INFODB_ELEM); 
    157142        if (browse != null) 
     
    924909        return response; 
    925910    } 
    926  
    927     private boolean loadSolrCores() { 
    928  
    929         // Solr servlet url 
    930         String solrUrl = "http://localhost:8383/solr/"; 
    931         HttpSolrServer solrServer = new HttpSolrServer(solrUrl); 
    932         // Max retries 
    933         solrServer.setMaxRetries(1); 
    934         // Connection Timeout 
    935         solrServer.setConnectionTimeout(3000); 
    936         //Cores 
    937         String coreSecName = this.router.getSiteName() + "-" + cluster_name + "-sidx"; 
    938         String coreDocName = this.router.getSiteName() + "-" + cluster_name + "-didx"; 
    939  
    940         if (!checkSolrCore(coreSecName, solrServer)){ 
    941             if (!activateSolrCore(coreSecName, solrServer)){ 
    942                 logger.error("Couldn't activate Solr core " + coreSecName + " for collection " + cluster_name); 
    943                 return false; 
    944             } 
    945         } 
    946         if (!checkSolrCore(coreDocName, solrServer)){ 
    947             if (!activateSolrCore(coreDocName, solrServer)){ 
    948                 logger.error("Couldn't activate Solr core " + coreDocName + " for collection " + cluster_name); 
    949                 return false; 
    950             } 
    951         } 
    952         return true; 
    953     } 
    954  
    955     private boolean checkSolrCore(String coreName, HttpSolrServer solrServer) { 
    956  
    957         CoreAdminRequest adminRequest = new CoreAdminRequest(); 
    958         adminRequest.setAction(CoreAdminAction.STATUS); 
    959         adminRequest.setCoreName(coreName); 
    960  
    961         try { 
    962             CoreAdminResponse adminResponse = adminRequest.process(solrServer); 
    963             NamedList<NamedList<Object>> coreStatus = adminResponse.getCoreStatus(); 
    964             NamedList<Object> coreList = coreStatus.getVal(0); 
    965             if (coreList != null) { 
    966                 if (coreList.get("name") == null) { 
    967                     logger.warn("Solr core " + coreName + " for collection " + cluster_name + " not exists."); 
    968                     return false; 
    969                 }  
    970             } 
    971              
    972         } catch (SolrServerException e) { 
    973             e.printStackTrace(); 
    974             return false; 
    975         } catch (IOException e) { 
    976             e.printStackTrace(); 
    977             return false; 
    978         } catch (RemoteSolrException e1){ 
    979             e1.printStackTrace(); 
    980             return false; 
    981         } 
    982         return true; 
    983     } 
    984      
    985     private boolean activateSolrCore(String coreName, HttpSolrServer solrServer) { 
    986          
    987         String dataDir = GSFile.collectionIndexDir(site_home, cluster_name) + File.separator + coreName.substring(coreName.length() - 4); 
    988         String instanceDir = GSFile.collectionEtcDir(site_home, cluster_name); 
    989      
    990         try { 
    991             CoreAdminRequest.createCore(coreName, instanceDir, solrServer, "", "", dataDir, ""); 
    992             logger.warn("Solr core " + coreName + " for collection " + cluster_name + " activated."); 
    993         } catch (SolrServerException e1) { 
    994             e1.printStackTrace(); 
    995             return false; 
    996         } catch (IOException e1) { 
    997             e1.printStackTrace(); 
    998             return false; 
    999         } catch (RemoteSolrException e1){ 
    1000             logger.error("Activation solr core " + coreName + " for collection " + cluster_name + "failed."); 
    1001             e1.printStackTrace(); 
    1002             return false; 
    1003         } 
    1004  
    1005         return true; 
    1006     } 
    1007  
    1008911} 
    1009