org.apache.solr.client.solrj.SolrServerException Java Examples

The following examples show how to use org.apache.solr.client.solrj.SolrServerException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SolrReducer.java    From examples with Apache License 2.0 6 votes vote down vote up
@Override
protected void setup(Context context) throws IOException, InterruptedException {
  verifyPartitionAssignment(context);    
  SolrRecordWriter.addReducerContext(context);

  /*
   * Note that ReflectionUtils.newInstance() above also implicitly calls
   * resolver.configure(context.getConfiguration()) if the resolver
   * implements org.apache.hadoop.conf.Configurable
   */

  this.exceptionHandler = new FaultTolerance(
      context.getConfiguration().getBoolean(FaultTolerance.IS_PRODUCTION_MODE, false), 
      context.getConfiguration().getBoolean(FaultTolerance.IS_IGNORING_RECOVERABLE_EXCEPTIONS, false),
      context.getConfiguration().get(FaultTolerance.RECOVERABLE_EXCEPTION_CLASSES, SolrServerException.class.getName()));
  
  this.heartBeater = new HeartBeater(context);
}
 
Example #2
Source File: ShrinkerJob.java    From thoth with BSD 3-Clause Clear License 6 votes vote down vote up
public void createDocumentShrinkers() throws SolrServerException, InterruptedException, ExecutionException {
  ExecutorService service = Executors.newFixedThreadPool(threadPoolSize);
  CompletionService<String> completionService = new ExecutorCompletionService<String>(service);
  HttpSolrServer thothServer = new HttpSolrServer(thothIndexUrl + realTimeCore);
  HttpSolrServer thothShrankServer = new HttpSolrServer(thothIndexUrl + shrankCore);
  ArrayList<ServerDetail> listOfServers = new ThothServers().getList(thothServer);

  for (ServerDetail serverDetail: listOfServers){
    LOG.info("Shrinking docs for server("+serverDetail.getName()+"):("+serverDetail.getPort()+") ");
    completionService.submit(new DocumentShrinker(serverDetail, nowMinusTimeToShrink, thothServer, thothShrankServer));
  }

  // Wait for all the executors to finish
  for(int i = 0; i < listOfServers.size(); i++){
    completionService.take().get();
  }
  LOG.info("Done Shrinking.");
}
 
Example #3
Source File: AutocompleteUpdateRequestProcessor.java    From solr-autocomplete with Apache License 2.0 6 votes vote down vote up
private SolrInputDocument fetchExistingOrCreateNewSolrDoc(String id) throws SolrServerException, IOException {
  Map<String, String> p = new HashMap<String, String>();
  p.put("q", PHRASE + ":\"" + ClientUtils.escapeQueryChars(id) + "\"");
  
  SolrParams params = new MapSolrParams(p);
  
  QueryResponse res = solrAC.query(params);
  
  if (res.getResults().size() == 0) {
    return new SolrInputDocument();
  } else if (res.getResults().size() == 1) {
    SolrDocument doc = res.getResults().get(0);
    SolrInputDocument tmp = new SolrInputDocument();
    
    for (String fieldName : doc.getFieldNames()) {
      tmp.addField(fieldName, doc.getFieldValue(fieldName));
    }
    return tmp;
  } else {
    throw new IllegalStateException("Query with params : " + p + " returned more than 1 hit!");
  }
}
 
Example #4
Source File: SolrColumnMetadataDao.java    From metron with Apache License 2.0 6 votes vote down vote up
protected List<Map<String, Object>> getIndexFields(String index)
    throws IOException, SolrServerException {
  List<Map<String, Object>> indexFields = new ArrayList<>();

  // Get all the fields in use, including dynamic fields
  LukeRequest lukeRequest = new LukeRequest();
  LukeResponse lukeResponse = lukeRequest.process(client, index);
  for (Entry<String, LukeResponse.FieldInfo> field : lukeResponse.getFieldInfo().entrySet()) {
    Map<String, Object> fieldData = new HashMap<>();
    fieldData.put("name", field.getValue().getName());
    fieldData.put("type", field.getValue().getType());
    indexFields.add(fieldData);

  }

  // Get all the schema fields
  SchemaRepresentation schemaRepresentation = new SchemaRequest().process(client, index)
      .getSchemaRepresentation();
  indexFields.addAll(schemaRepresentation.getFields());

  return indexFields;
}
 
Example #5
Source File: SolrSearchServerTest.java    From vind with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws IOException, SolrServerException {
    MockitoAnnotations.initMocks(this);
    when(solrClient.ping()).thenReturn(solrPingResponse);
    when(solrPingResponse.getStatus()).thenReturn(0);
    when(solrPingResponse.getQTime()).thenReturn(10);

    when(solrClient.query(any(), any(SolrRequest.METHOD.class))).thenReturn(response);
    when(response.getResults()).thenReturn(new SolrDocumentList());
    when(response.getResponse()).thenReturn(responseObject);
    when(responseObject.get("responseHeader")).thenReturn(responseObject);
    when(responseObject.get("params")).thenReturn(responseObject);
    when(responseObject.get("suggestion.field")).thenReturn("category");

    when(solrClient.add(org.mockito.Matchers.<Collection<SolrInputDocument>>any())).thenReturn(iResponse);
    when(solrClient.add(any(SolrInputDocument.class))).thenReturn(iResponse);
    when(iResponse.getQTime()).thenReturn(10);
    when(iResponse.getElapsedTime()).thenReturn(15l);

    //we use the protected constructor to avoid schema checking
    server = new SolrSearchServerTestClass(solrClient);
}
 
Example #6
Source File: SolrRecordWriter.java    From examples with Apache License 2.0 6 votes vote down vote up
/**
 * Write a record. This method accumulates records in to a batch, and when
 * {@link #batchSize} items are present flushes it to the indexer. The writes
 * can take a substantial amount of time, depending on {@link #batchSize}. If
 * there is heavy disk contention the writes may take more than the 600 second
 * default timeout.
 */
@Override
public void write(K key, V value) throws IOException {
  heartBeater.needHeartBeat();
  try {
    try {
      SolrInputDocumentWritable sidw = (SolrInputDocumentWritable) value;
      batch.add(sidw.getSolrInputDocument());
      if (batch.size() >= batchSize) {
        batchWriter.queueBatch(batch);
        numDocsWritten += batch.size();
        if (System.nanoTime() >= nextLogTime) {
          LOG.info("docsWritten: {}", numDocsWritten);
          nextLogTime += TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
        }
        batch.clear();
      }
    } catch (SolrServerException e) {
      throw new IOException(e);
    }
  } finally {
    heartBeater.cancelHeartBeat();
  }

}
 
Example #7
Source File: TestRealTimeGet.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  while (!finished) {
    if (rand.nextBoolean()) {
      doc.setField(authField, authFieldValue0);
    } else {
      doc.setField(authField, authFieldValue1);
    }
    try {
      server.add(doc);
    } catch (SolrServerException sse) {
      throw new RuntimeException(sse);
    } catch (IOException ioe) {
      throw new RuntimeException(ioe);
    }
  }
}
 
Example #8
Source File: BasicHttpSolrClientTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testRedirect() throws Exception {
  final String clientUrl = jetty.getBaseUrl().toString() + "/redirect/foo";
  try (HttpSolrClient client = getHttpSolrClient(clientUrl)) {
    SolrQuery q = new SolrQuery("*:*");
    // default = false
    SolrServerException e = expectThrows(SolrServerException.class, () -> client.query(q));
    assertTrue(e.getMessage().contains("redirect"));

    client.setFollowRedirects(true);
    client.query(q);

    //And back again:
    client.setFollowRedirects(false);
    e = expectThrows(SolrServerException.class, () -> client.query(q));
    assertTrue(e.getMessage().contains("redirect"));
  }

}
 
Example #9
Source File: MigrateRouteKeyTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private boolean waitForRuleToExpire(String collection, String shard, String splitKey, long finishTime) throws KeeperException, InterruptedException, SolrServerException, IOException {
  DocCollection state;
  Slice slice;
  boolean ruleRemoved = false;
  long expiryTime = finishTime + TimeUnit.NANOSECONDS.convert(60, TimeUnit.SECONDS);
  while (System.nanoTime() < expiryTime) {
    cluster.getSolrClient().getZkStateReader().forceUpdateCollection(collection);
    state = getCollectionState(collection);
    slice = state.getSlice(shard);
    Map<String,RoutingRule> routingRules = slice.getRoutingRules();
    if (routingRules == null || routingRules.isEmpty() || !routingRules.containsKey(splitKey)) {
      ruleRemoved = true;
      break;
    }
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", splitKey + random().nextInt());
    cluster.getSolrClient().add(collection, doc);
    Thread.sleep(1000);
  }
  return ruleRemoved;
}
 
Example #10
Source File: SolrOntologySearch.java    From BioSolr with Apache License 2.0 6 votes vote down vote up
@Override
public OntologyEntryBean findOntologyEntryByUri(String uri) throws SearchEngineException {
	OntologyEntryBean retVal = null;
	
	try {
		SolrQuery query = new SolrQuery(uri);
		query.setRequestHandler(config.getOntologyNodeRequestHandler());
		
		QueryResponse response = server.query(query);
		List<OntologyEntryBean> annotations = response.getBeans(OntologyEntryBean.class);
		if (annotations.size() > 0) {
			retVal = annotations.get(0);
		}
	} catch (SolrServerException e) {
		throw new SearchEngineException(e);
	}
	
	return retVal;
}
 
Example #11
Source File: SolrStreamingService.java    From chronix.spark with Apache License 2.0 6 votes vote down vote up
private void initialStream(SolrQuery query, SolrClient connection) {
    try {
        SolrQuery solrQuery = query.getCopy();
        solrQuery.setRows(nrOfTimeSeriesPerBatch);
        solrQuery.setStart(currentDocumentCount);

        solrStreamingHandler.init(nrOfTimeSeriesPerBatch, currentDocumentCount);
        QueryResponse response = connection.queryAndStreamResponse(solrQuery, solrStreamingHandler);

        nrOfAvailableTimeSeries = response.getResults().getNumFound();
        queryStart = 0;//(long) response.getResponseHeader().get(ChronixSolrStorageConstants.QUERY_START_LONG);
        queryEnd = Long.MAX_VALUE;//(long) response.getResponseHeader().get(ChronixSolrStorageConstants.QUERY_END_LONG);

        needStream = false;
    } catch (SolrServerException | IOException e) {
        LOGGER.error("SolrServerException occurred while querying server.", e);
    }
}
 
Example #12
Source File: App.java    From jate with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void indexJATEDocuments(Path file, EmbeddedSolrServer solrServer, JATEProperties jateProp, boolean commit) throws JATEException {
    if (file == null) {
        return;
    }

    try {
        JATEDocument jateDocument = JATEUtil.loadJATEDocument(file);

        if (isNotEmpty(jateDocument))
            JATEUtil.addNewDoc(solrServer, jateDocument.getId(),
                    jateDocument.getId(), jateDocument.getContent(), jateProp, commit);
    } catch (FileNotFoundException ffe) {
        throw new JATEException(ffe.toString());
    } catch (IOException ioe) {
        throw new JATEException(String.format("failed to index [%s]", file.toString()) + ioe.toString());
    } catch (SolrServerException sse) {
        throw new JATEException(String.format("failed to index [%s] ", file.toString()) + sse.toString());
    }
}
 
Example #13
Source File: MCROAISolrSearcher.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerException, IOException {
    SolrQuery query = getBaseQuery(CommonParams.Q);

    // set support
    if (this.set != null) {
        String setId = this.set.getSetId();
        MCROAISetConfiguration<SolrQuery, SolrDocument, String> setConfig = getSetManager().getConfig(setId);
        setConfig.getHandler().apply(this.set, query);
    }
    // from & until
    if (this.from != null || this.until != null) {
        String fromUntilCondition = buildFromUntilCondition(this.from, this.until);
        query.add(CommonParams.FQ, fromUntilCondition);
    }

    // cursor
    query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor.orElse(CursorMarkParams.CURSOR_MARK_START));
    query.set(CommonParams.ROWS, String.valueOf(getPartitionSize()));
    query.set(CommonParams.SORT, "id asc");

    // do the query
    SolrClient solrClient = MCRSolrClientFactory.getMainSolrClient();
    QueryResponse response = solrClient.query(query);
    Collection<MCROAISetResolver<String, SolrDocument>> setResolver = getSetResolver(response.getResults());
    return new MCROAISolrResult(response, d -> toHeader(d, setResolver));
}
 
Example #14
Source File: AppATEGENIATest.java    From jate with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Test
public void validate_indexing() {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("q", "*:*");

    try {
        QueryResponse qResp = server.query(params);
        SolrDocumentList docList = qResp.getResults();

        assert (docList.getNumFound() == 2000);
    } catch (SolrServerException e) {
        e.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
 
Example #15
Source File: DirectSolrInputDocumentWriter.java    From hbase-indexer with Apache License 2.0 6 votes vote down vote up
/**
 * Has the same behavior as {@link SolrClient#deleteByQuery(String)}.
 * 
 * @param deleteQuery delete query to be executed
 */
@Override
public void deleteByQuery(String deleteQuery) throws SolrServerException, IOException {
    try {
        solrServer.deleteByQuery(deleteQuery);
    } catch (SolrException e) {
        if (isDocumentIssue(e)) {
            documentDeleteErrorMeter.mark(1);
        } else {
            solrDeleteErrorMeter.mark(1);
            throw e;
        }
    } catch (SolrServerException sse) {
        solrDeleteErrorMeter.mark(1);
        throw sse;
    }
}
 
Example #16
Source File: EmbeddedSolrNoSerializeTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void doTestAssertTagStreaming(BiFunction<ModifiableSolrParams,String,QueryRequest> newQueryRequest) throws IOException, SolrServerException {
  ModifiableSolrParams params = params();
  String input = "foo boston bar";//just one tag;
  QueryRequest req = newQueryRequest.apply(params, input);
  req.setPath("/tag");

  final AtomicReference<SolrDocument> refDoc = new AtomicReference<>();
  req.setStreamingResponseCallback(new StreamingResponseCallback() {
    @Override
    public void streamSolrDocument(SolrDocument doc) {
      refDoc.set(doc);
    }

    @Override
    public void streamDocListInfo(long numFound, long start, Float maxScore) {

    }
  });
  QueryResponse rsp = req.process(solrServer);
  assertNotNull(rsp.getResponse().get("tags"));
  assertNotNull(refDoc.get());
  assertEquals("Boston", ((Field)refDoc.get().getFieldValue("name")).stringValue());
}
 
Example #17
Source File: MarcSolrClient.java    From metadata-qa-marc with GNU General Public License v3.0 6 votes vote down vote up
public void indexMap(String id, Map<String, List<String>> objectMap)
    throws IOException, SolrServerException {
  SolrInputDocument document = new SolrInputDocument();
  document.addField("id", (trimId ? id.trim() : id));
  for (Map.Entry<String, List<String>> entry : objectMap.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
    if (value != null) {
      if (!key.endsWith("_sni") && !key.endsWith("_ss"))
        key += "_ss";
      document.addField(key, value);
    }
  }

  try {
    UpdateResponse response = solr.add(document);
  } catch (HttpSolrClient.RemoteSolrException ex) {
    System.err.printf("document: %s", document);
    System.err.printf("Commit exception: %s%n", ex.getMessage());
  }
}
 
Example #18
Source File: SolrTemplate.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
public UpdateResponse delete(SolrDataQuery query) {
	Assert.notNull(query, "Query must not be 'null'.");

	final String queryString = this.queryParsers.getForClass(query.getClass()).getQueryString(query);

	return execute(new SolrCallback<UpdateResponse>() {
		@Override
		public UpdateResponse doInSolr(SolrClient solrClient) throws SolrServerException, IOException {
			return solrClient.deleteByQuery(queryString);
		}
	});
}
 
Example #19
Source File: SolrTemplate.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Override
public void rollback() {
	execute(new SolrCallback<UpdateResponse>() {
		@Override
		public UpdateResponse doInSolr(SolrClient solrClient) throws SolrServerException, IOException {
			return solrClient.rollback();
		}
	});
}
 
Example #20
Source File: SolrLookingBlurServerTest.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
private SolrServer createServerAndTableWithSimpleTestDoc(String table) throws BlurException, TException, IOException,
    SolrServerException {
  createTable(table);
  SolrServer server = new SolrLookingBlurServer(miniCluster.getControllerConnectionStr(), table);
  SolrInputDocument doc;

  doc = createSimpleTestDoc();

  server.add(doc);
  return server;
}
 
Example #21
Source File: SolrMachineProducer.java    From extract with MIT License 5 votes vote down vote up
private long fetch() throws IOException, SolrServerException {
	final SolrQuery query = new SolrQuery(filter);

	query.setRows(rows);
	query.setStart((int) start);

	// Only request the fields to be copied and the ID.
	query.setFields(idField);

	if (null != fields) {
		fields.forEach(query::addField);
	}

	logger.info(String.format("Fetching up to %d documents, skipping %d.", rows, start));
	client.queryAndStreamResponse(query, this);

	final long fetched = this.fetched;

	// Stop if there are no more results.
	// Instruct transformers to stop by sending a poison pill.
	if (fetched < rows) {
		stopped = true;
	}

	// Reset for the next run.
	this.fetched = 0;
	return fetched;
}
 
Example #22
Source File: V2ApiIntegrationTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetPropertyValidationOfCluster() throws IOException, SolrServerException {
  @SuppressWarnings({"rawtypes"})
  NamedList resp = cluster.getSolrClient().request(
    new V2Request.Builder("/cluster").withMethod(SolrRequest.METHOD.POST).withPayload("{set-property: {name: autoAddReplicas, val:false}}").build());
  assertTrue(resp.toString().contains("status=0"));
  resp = cluster.getSolrClient().request(
      new V2Request.Builder("/cluster").withMethod(SolrRequest.METHOD.POST).withPayload("{set-property: {name: autoAddReplicas, val:null}}").build());
  assertTrue(resp.toString().contains("status=0"));
}
 
Example #23
Source File: ShowFileRequestHandlerTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testGetRawFile() throws SolrServerException, IOException {
  SolrClient client = getSolrClient();
  //assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
  QueryRequest request = new QueryRequest(params("file", "managed-schema"));
  request.setPath("/admin/file");
  final AtomicBoolean readFile = new AtomicBoolean();
  request.setResponseParser(new ResponseParser() {
    @Override
    public String getWriterType() {
      return "mock";//unfortunately this gets put onto params wt=mock but it apparently has no effect
    }

    @Override
    public NamedList<Object> processResponse(InputStream body, String encoding) {
      try {
        if (body.read() >= 0)
          readFile.set(true);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
      return null;
    }

    @Override
    public NamedList<Object> processResponse(Reader reader) {
      throw new UnsupportedOperationException("TODO unimplemented");//TODO
    }
  });

  client.request(request);//runs request
  //request.process(client); but we don't have a NamedList response
  assertTrue(readFile.get());
}
 
Example #24
Source File: SaveToSolrActionExecutionFunction.java    From Decision with Apache License 2.0 5 votes vote down vote up
private SolrClient getClient(StratioStreamingMessage message) throws IOException, SolrServerException, URISyntaxException, TransformerException, SAXException, ParserConfigurationException {
    String core = message.getStreamName();
    if (solrClients.containsKey(core)) {
        //we have a client for this core
        return solrClients.get(core);
    } else {
        SolrClient solrClient = getSolrclient(core);
        solrClients.put(core, solrClient);
        return solrClient;
    }
}
 
Example #25
Source File: SolrCloudTestCase.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Get the {@link CoreStatus} data for a {@link Replica}
 * <p>
 * This assumes that the replica is hosted on a live node.
 */
protected static CoreStatus getCoreStatus(Replica replica) throws IOException, SolrServerException {
  JettySolrRunner jetty = cluster.getReplicaJetty(replica);
  try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString(), cluster.getSolrClient().getHttpClient())) {
    return CoreAdminRequest.getCoreStatus(replica.getCoreName(), client);
  }
}
 
Example #26
Source File: DistributedTermsComponentTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link NamedList} containing server
 * response deserialization is based on the {@code responseParser}
 */
private NamedList<Object> queryClient(SolrClient solrClient, final ModifiableSolrParams params,
                                      ResponseParser responseParser) throws SolrServerException, IOException {
  QueryRequest queryRequest = new QueryRequest(params);
  queryRequest.setResponseParser(responseParser);
  return solrClient.request(queryRequest);
}
 
Example #27
Source File: FullTaxonIntegrationRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
@Ignore("This test requires a missing resource.")
public void testLoadFullTaxon() throws Exception {
	ParserWrapper pw = new ParserWrapper();
	final OWLGraphWrapper g = pw.parseToOWLGraph(taxonFile);
	
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	GafSolrDocumentLoaderIntegrationRunner.gc();
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	
	ConfigManager configManager = new ConfigManager();
	configManager.add("src/test/resources/test-ont-config.yaml");
	FlexCollection c = new FlexCollection(configManager, g);
	
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	GafSolrDocumentLoaderIntegrationRunner.gc();
	GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
	
	FlexSolrDocumentLoader loader = new FlexSolrDocumentLoader((SolrServer)null, c) {

		@Override
		protected void addToServer(Collection<SolrInputDocument> docs)
				throws SolrServerException, IOException {
			solrCounter += docs.size();
			GafSolrDocumentLoaderIntegrationRunner.printMemoryStats();
			System.out.println("Cache size: "+g.getCurrentEdgesAdvancedCacheSize());
		}
		
	};
	loader.load();
	assertTrue(solrCounter > 0);
}
 
Example #28
Source File: Solr6Index.java    From atlas with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #29
Source File: TestConfigSetsAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void scriptRequest(String collection) throws SolrServerException, IOException {
  SolrClient client = solrCluster.getSolrClient();
  SolrInputDocument doc = sdoc("id", "4055", "subject", "Solr");
  client.add(collection, doc);
  client.commit(collection);

  assertEquals("42", client.query(collection, params("q", "*:*")).getResults().get(0).get("script_added_i"));
}
 
Example #30
Source File: AbstractAlfrescoDistributedIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected static QueryResponse queryRandomShard(ModifiableSolrParams params) throws SolrServerException, IOException
{
    Random r = SOLR_RANDOM_SUPPLIER.getRandomGenerator();
    int which = r.nextInt(clientShards.size());
    SolrClient client = clientShards.get(which);
    return client.query(params);
}