private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection) throws IOException, SolrServerException, KeeperException, InterruptedException { if (!checkIfCollectionExists(client, collection)) { Integer numShards = config.get(NUM_SHARDS); Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE); Integer replicationFactor = config.get(REPLICATION_FACTOR); // Ideally this property used so a new configset is not uploaded for every single // index (collection) created in solr. // if a generic configSet is not set, make the configset name the same as the collection. // This was the default behavior before a default configSet could be specified String genericConfigSet = config.has(SOLR_DEFAULT_CONFIG) ? config.get(SOLR_DEFAULT_CONFIG):collection; CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create(); createRequest.setConfigName(genericConfigSet); createRequest.setCollectionName(collection); createRequest.setNumShards(numShards); createRequest.setMaxShardsPerNode(maxShardsPerNode); createRequest.setReplicationFactor(replicationFactor); CollectionAdminResponse createResponse = createRequest.process(client); if (createResponse.isSuccess()) { logger.trace("Collection {} successfully created.", collection); } else { throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages())); } } waitForRecoveriesToFinish(client, collection); }
public SolrServer getSolrServer() throws SolrServerException { if (solrServer != null) { if (isSolrServerLive()) { return solrServer; } else { throw new SolrServerException("Solr server not available"); } } solrServer = new HttpSolrServer(solrUrl) { private static final long serialVersionUID = 1L; @Override public org.apache.solr.client.solrj.beans.DocumentObjectBinder getBinder() { if (documentObjectBinder == null) { return new DocumentObjectBinder(); } return documentObjectBinder; } }; if (!isSolrServerLive()) { throw new SolrServerException("Solr server not available"); } return solrServer; }
@Override public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException { try { SolrClient server = getServer(request); return server.request(request); } catch (Exception e) { throw new SolrServerException(e); } }
@Override public NamedList<Object> request(SolrRequest request, String collection) throws SolrServerException, IOException { try { SolrClient server = getServer(request); return server.request(request); } catch (Exception e) { throw new SolrServerException(e); } }
@Override public QueryResponse process( SolrServer server ) throws SolrServerException { try { long startTime = System.currentTimeMillis(); QueryResponse res = new QueryResponse( server.request( this ), server ); res.setElapsedTime( System.currentTimeMillis()-startTime ); return res; } catch (SolrServerException e){ throw e; } catch (Exception e) { throw new SolrServerException("Error executing query", e); } } }
private CoreContainer createCoreContainer(String solrHome) throws SolrServerException { CoreContainer coreContainer = new CoreContainer(solrHome); coreContainer.load(); if (coreContainer.getCores().size() == 0) { throw new SolrServerException("Failed to initialize the Solr core. " + "Please check the configuration and log messages."); } else if (coreContainer.getCores().size() > 1) { this.logger.warn("Multiple Solr cores detected: [{}]. Using the first one.", StringUtils.join(coreContainer.getCoreNames(), ", ")); } return coreContainer; }
private static void checkAllZnodesThere(SolrZkClient zkClient, String src, String dst) throws KeeperException, InterruptedException, SolrServerException { for (String node : zkClient.getChildren(src, null, true)) { if (zkClient.exists(dst + "/" + node, true) == false) { throw new SolrServerException("mv command did not move node " + dst + "/" + node + " source left intact"); } checkAllZnodesThere(zkClient, src + "/" + node, dst + "/" + node); } }
@Override public GetResult execute(RealTimeGet search, DocumentFactory assets) { SolrQuery query = buildSolrQuery(search, assets); try { log.debug(">>> query({})", query.toString()); QueryResponse response = solrClient.query(query, REQUEST_METHOD); if(response!=null){ return SolrUtils.Result.buildRealTimeGetResult(response, search, assets); }else { log.error("Null result from SolrClient"); throw new SolrServerException("Null result from SolrClient"); } } catch (SolrServerException | IOException e) { log.error("Cannot execute realTime get query"); throw new SearchServerException("Cannot execute realTime get query", e); } }
@Override public Request call() { Request req = new Request(); req.url = url; req.isLeader = urls.indexOf(url) == 0; req.shard = shard; LOG.info("Live merge " + dir.getPath() + " into " + mergeUrl); try (final HttpSolrClient client = new HttpSolrClient.Builder(mergeUrl).build()) { CoreAdminRequest.MergeIndexes mergeRequest = new CoreAdminRequest.MergeIndexes(); mergeRequest.setCoreName(name); mergeRequest.setIndexDirs(Arrays.asList(dir.getPath().toString() + "/data/index")); if (!req.isLeader && System.getProperty(INJECT_FOLLOWER_MERGE_FAILURES) != null) { throw new SolrServerException(INJECT_FOLLOWER_MERGE_FAILURES); } mergeRequest.process(client); req.success = true; } catch (SolrServerException | IOException e) { req.e = e; } return req; } };
@Override public SuggestionResult execute(ExecutableSuggestionSearch search, DocumentFactory assets,DocumentFactory childFactory) { SolrQuery query = buildSolrQuery(search, assets, childFactory); try { log.debug(">>> query({})", query.toString()); QueryResponse response = solrClient.query(query, REQUEST_METHOD); if(response!=null){ return SolrUtils.Result.buildSuggestionResult(response, assets, childFactory, search.getSearchContext()); }else { log.error("Null result from SolrClient"); throw new SolrServerException("Null result from SolrClient"); } } catch (SolrServerException | IOException e) { log.error("Cannot execute suggestion query"); throw new SearchServerException("Cannot execute suggestion query", e); } }
/** * Constructor. Prepares solr connection. * * @param solrDir * The directory of the solr instance. * @param dataDir * The directory of the solr index data. */ public static SolrServer newEmbeddedInstance(File solrDir, File dataDir) throws SolrServerException { try { final CoreContainer cc = new CoreContainer(solrDir.getAbsolutePath()); SolrConfig config = new OpencastSolrConfig(solrDir.getAbsolutePath(), SolrConfig.DEFAULT_CONF_FILE, null); IndexSchema schema = new IndexSchema(config, solrDir + "/conf/schema.xml", null); SolrCore core0 = new SolrCore(null, dataDir.getAbsolutePath(), config, schema, null); cc.register("core0", core0, false); return new EmbeddedSolrServerWrapper(cc, "core0"); } catch (Exception e) { throw new SolrServerException(e); } }
/** * Process this request asynchronously, using a specified request id * @param asyncId the request id * @param client a Solr client * @return the request id */ public String processAsync(String asyncId, SolrClient client) throws IOException, SolrServerException { this.asyncId = asyncId; NamedList<Object> resp = client.request(this); if (resp.get("error") != null) { throw new SolrServerException((String)resp.get("error")); } return (String) resp.get("requestid"); }
throw new SolrServerException(e); } catch (InterruptedException e1) { throw new SolrServerException("Impossible to retry connection to solr server", e);
throw new SolrServerException(e);
private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection) throws IOException, SolrServerException, KeeperException, InterruptedException { if (!checkIfCollectionExists(client, collection)) { final Integer numShards = config.get(NUM_SHARDS); final Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE); final Integer replicationFactor = config.get(REPLICATION_FACTOR); // Ideally this property used so a new configset is not uploaded for every single // index (collection) created in solr. // if a generic configSet is not set, make the configset name the same as the collection. // This was the default behavior before a default configSet could be specified final String genericConfigSet = config.has(SOLR_DEFAULT_CONFIG) ? config.get(SOLR_DEFAULT_CONFIG):collection; final CollectionAdminRequest.Create createRequest = CollectionAdminRequest.createCollection(collection, genericConfigSet, numShards, replicationFactor); createRequest.setMaxShardsPerNode(maxShardsPerNode); final CollectionAdminResponse createResponse = createRequest.process(client); if (createResponse.isSuccess()) { logger.trace("Collection {} successfully created.", collection); } else { throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages())); } } waitForRecoveriesToFinish(client, collection); }
private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection) throws IOException, SolrServerException, KeeperException, InterruptedException { if (!checkIfCollectionExists(client, collection)) { Integer numShards = config.get(NUM_SHARDS); Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE); Integer replicationFactor = config.get(REPLICATION_FACTOR); CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create(); createRequest.setConfigName(collection); createRequest.setCollectionName(collection); createRequest.setNumShards(numShards); createRequest.setMaxShardsPerNode(maxShardsPerNode); createRequest.setReplicationFactor(replicationFactor); CollectionAdminResponse createResponse = createRequest.process(client); if (createResponse.isSuccess()) { logger.trace("Collection {} successfully created.", collection); } else { throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages())); } } waitForRecoveriesToFinish(client, collection); }
private static void createCollectionIfNotExists(CloudSolrClient client, Configuration config, String collection) throws IOException, SolrServerException, KeeperException, InterruptedException { if (!checkIfCollectionExists(client, collection)) { Integer numShards = config.get(NUM_SHARDS); Integer maxShardsPerNode = config.get(MAX_SHARDS_PER_NODE); Integer replicationFactor = config.get(REPLICATION_FACTOR); CollectionAdminRequest.Create createRequest = new CollectionAdminRequest.Create(); createRequest.setConfigName(collection); createRequest.setCollectionName(collection); createRequest.setNumShards(numShards); createRequest.setMaxShardsPerNode(maxShardsPerNode); createRequest.setReplicationFactor(replicationFactor); CollectionAdminResponse createResponse = createRequest.process(client); if (createResponse.isSuccess()) { logger.trace("Collection {} successfully created.", collection); } else { throw new SolrServerException(Joiner.on("\n").join(createResponse.getErrorMessages())); } } waitForRecoveriesToFinish(client, collection); }
@Override public SearchResult execute(FulltextSearch search, DocumentFactory factory) { final SolrQuery query = buildSolrQuery(search, factory); //query try { solrClientLogger.debug(">>> query({})", query.toString()); final QueryResponse response = solrClient.query(query, REQUEST_METHOD); if(response!=null){ final Map<String,Integer> childCounts = SolrUtils.getChildCounts(response); final List<Document> documents = SolrUtils.Result.buildResultList(response.getResults(), childCounts, factory, search.getSearchContext()); final FacetResults facetResults = SolrUtils.Result.buildFacetResult(response, factory, search.getChildrenFactory(), search.getFacets(),search.getSearchContext()); switch(search.getResultSet().getType()) { case page:{ return new PageResult(response.getResults().getNumFound(), response.getQTime(), documents, search, facetResults, this, factory).setElapsedTime(response.getElapsedTime()); } case slice: { return new SliceResult(response.getResults().getNumFound(), response.getQTime(), documents, search, facetResults, this, factory).setElapsedTime(response.getElapsedTime()); } default: return new PageResult(response.getResults().getNumFound(), response.getQTime(), documents, search, facetResults, this, factory).setElapsedTime(response.getElapsedTime()); } }else { throw new SolrServerException("Null result from SolrClient"); } } catch (SolrServerException | IOException e) { throw new SearchServerException("Cannot issue query", e); } }
public void testDefaultRetryPredicate() { assertTrue(DEFAULT_RETRY_PREDICATE.test(new IOException("test"))); assertTrue(DEFAULT_RETRY_PREDICATE.test(new SolrServerException("test")));