use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.
the class ShardSplitTest method splitShard.
protected void splitShard(String collection, String shardId, List<DocRouter.Range> subRanges, String splitKey) throws SolrServerException, IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.SPLITSHARD.toString());
params.set("collection", collection);
if (shardId != null) {
params.set("shard", shardId);
}
if (subRanges != null) {
StringBuilder ranges = new StringBuilder();
for (int i = 0; i < subRanges.size(); i++) {
DocRouter.Range subRange = subRanges.get(i);
ranges.append(subRange.toString());
if (i < subRanges.size() - 1)
ranges.append(",");
}
params.set("ranges", ranges.toString());
}
if (splitKey != null) {
params.set("split.key", splitKey);
}
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
String baseUrl = ((HttpSolrClient) shardToJetty.get(SHARD1).get(0).client.solrClient).getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
try (HttpSolrClient baseServer = getHttpSolrClient(baseUrl)) {
baseServer.setConnectionTimeout(30000);
baseServer.setSoTimeout(60000 * 5);
baseServer.request(request);
}
}
use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.
the class SyncSliceTest method test.
@Test
public void test() throws Exception {
handle.clear();
handle.put("timestamp", SKIPVAL);
waitForThingsToLevelOut(30);
del("*:*");
List<CloudJettyRunner> skipServers = new ArrayList<>();
int docId = 0;
indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "old haven was blue.");
skipServers.add(shardToJetty.get("shard1").get(1));
indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "but the song was fancy.");
skipServers.add(shardToJetty.get("shard1").get(2));
indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "under the moon and over the lake");
commit();
waitForRecoveriesToFinish(false);
// shard should be inconsistent
String shardFailMessage = checkShardConsistency("shard1", true, false);
assertNotNull(shardFailMessage);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionAction.SYNCSHARD.toString());
params.set("collection", "collection1");
params.set("shard", "shard1");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
String baseUrl = ((HttpSolrClient) shardToJetty.get("shard1").get(2).client.solrClient).getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
try (HttpSolrClient baseClient = getHttpSolrClient(baseUrl)) {
// we only set the connect timeout, not so timeout
baseClient.setConnectionTimeout(30000);
baseClient.request(request);
}
waitForThingsToLevelOut(15);
checkShardConsistency(false, true);
long cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
assertEquals(4, cloudClientDocs);
// kill the leader - new leader could have all the docs or be missing one
CloudJettyRunner leaderJetty = shardToLeaderJetty.get("shard1");
// but not the leader
skipServers = getRandomOtherJetty(leaderJetty, null);
// this doc won't be on one node
indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
Set<CloudJettyRunner> jetties = new HashSet<>();
jetties.addAll(shardToJetty.get("shard1"));
jetties.remove(leaderJetty);
assertEquals(getShardCount() - 1, jetties.size());
chaosMonkey.killJetty(leaderJetty);
Thread.sleep(3000);
waitForNoShardInconsistency();
Thread.sleep(1000);
checkShardConsistency(false, true);
cloudClientDocs = cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound();
assertEquals(5, cloudClientDocs);
CloudJettyRunner deadJetty = leaderJetty;
// let's get the latest leader
while (deadJetty == leaderJetty) {
updateMappingsFromZk(this.jettys, this.clients);
leaderJetty = shardToLeaderJetty.get("shard1");
}
// bring back dead node
// he is not the leader anymore
ChaosMonkey.start(deadJetty.jetty);
waitTillAllNodesActive();
skipServers = getRandomOtherJetty(leaderJetty, deadJetty);
skipServers.addAll(getRandomOtherJetty(leaderJetty, deadJetty));
// skip list should be
// System.out.println("leader:" + leaderJetty.url);
// System.out.println("dead:" + deadJetty.url);
// System.out.println("skip list:" + skipServers);
// we are skipping 2 nodes
assertEquals(2, skipServers.size());
// more docs than can peer sync
for (int i = 0; i < 300; i++) {
indexDoc(skipServers, id, docId++, i1, 50, tlong, 50, t1, "to come to the aid of their country.");
}
commit();
Thread.sleep(1000);
waitForRecoveriesToFinish(false);
// shard should be inconsistent
shardFailMessage = waitTillInconsistent();
assertNotNull("Test Setup Failure: shard1 should have just been set up to be inconsistent - but it's still consistent. Leader:" + leaderJetty.url + " Dead Guy:" + deadJetty.url + "skip list:" + skipServers, shardFailMessage);
// good place to test compareResults
boolean shouldFail = CloudInspectUtil.compareResults(controlClient, cloudClient);
assertTrue("A test that compareResults is working correctly failed", shouldFail);
jetties = new HashSet<>();
jetties.addAll(shardToJetty.get("shard1"));
jetties.remove(leaderJetty);
assertEquals(getShardCount() - 1, jetties.size());
// kill the current leader
chaosMonkey.killJetty(leaderJetty);
waitForNoShardInconsistency();
checkShardConsistency(true, true);
success = true;
}
use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.
the class TestRebalanceLeaders method listCollection.
private void listCollection() throws IOException, SolrServerException {
//CloudSolrServer client = createCloudClient(null);
try {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.LIST.toString());
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = cloudClient.request(request);
List<String> collections = (List<String>) rsp.get("collections");
assertTrue("control_collection was not found in list", collections.contains("control_collection"));
assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION));
assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME));
} finally {
//remove collections
//client.shutdown();
}
}
use of org.apache.solr.client.solrj.SolrRequest in project lucene-solr by apache.
the class TestRebalanceLeaders method issuePreferred.
void issuePreferred(String slice, Replica rep) throws IOException, SolrServerException, InterruptedException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.ADDREPLICAPROP.toString());
// Insure we get error returns when omitting required parameters
params.set("collection", COLLECTION_NAME);
params.set("shard", slice);
params.set("replica", rep.getName());
params.set("property", "preferredLeader");
params.set("property.value", "true");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
cloudClient.request(request);
}
use of org.apache.solr.client.solrj.SolrRequest in project storm by apache.
the class SolrState method updateState.
public void updateState(List<TridentTuple> tuples) {
try {
SolrRequest solrRequest = solrMapper.toSolrRequest(tuples);
solrClient.request(solrRequest, solrMapper.getCollection());
solrClient.commit(solrMapper.getCollection());
} catch (Exception e) {
final String msg = String.format("%s", tuples);
logger.warn(msg);
throw new FailedException(msg, e);
}
}
Aggregations