use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class MultiThreadedOCPTest method testLongAndShortRunningParallelApiCalls.
private void testLongAndShortRunningParallelApiCalls() throws InterruptedException, IOException, SolrServerException {
Thread indexThread = new Thread() {
@Override
public void run() {
Random random = random();
int max = atLeast(random, 200);
for (int id = 101; id < max; id++) {
try {
doAddDoc(String.valueOf(id));
} catch (Exception e) {
log.error("Exception while adding docs", e);
}
}
}
};
indexThread.start();
try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
SplitShard splitShardRequest = CollectionAdminRequest.splitShard("collection1").setShardName(SHARD1);
splitShardRequest.processAsync("2000", client);
RequestStatusState state = getRequestState("2000", client);
while (state == RequestStatusState.SUBMITTED) {
state = getRequestState("2000", client);
Thread.sleep(10);
}
assertSame("SplitShard task [2000] was supposed to be in [running] but isn't. It is [" + state + "]", RequestStatusState.RUNNING, state);
// CLUSTERSTATE is always mutually exclusive, it should return with a response before the split completes
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", "collection1");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
client.request(request);
state = getRequestState("2000", client);
assertSame("After invoking OVERSEERSTATUS, SplitShard task [2000] was still supposed to be in [running] but " + "isn't. It is [" + state + "]", RequestStatusState.RUNNING, state);
} finally {
try {
indexThread.join();
} catch (InterruptedException e) {
log.warn("Indexing thread interrupted.");
}
}
}
use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class MultiThreadedOCPTest method testDeduplicationOfSubmittedTasks.
private void testDeduplicationOfSubmittedTasks() throws IOException, SolrServerException {
try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
CollectionAdminRequest.createCollection("ocptest_shardsplit2", "conf1", 4, 1).processAsync("3000", client);
SplitShard splitShardRequest = CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD1);
splitShardRequest.processAsync("3001", client);
splitShardRequest = CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD2);
splitShardRequest.processAsync("3002", client);
// Now submit another task with the same id. At this time, hopefully the previous 3002 should still be in the queue.
expectThrows(SolrServerException.class, () -> {
CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD1).processAsync("3002", client);
// more helpful assertion failure
fail("Duplicate request was supposed to exist but wasn't found. De-duplication of submitted task failed.");
});
for (int i = 3001; i <= 3002; i++) {
final RequestStatusState state = getRequestStateAfterCompletion(i + "", REQUEST_STATUS_TIMEOUT, client);
assertSame("Task " + i + " did not complete, final state: " + state, RequestStatusState.COMPLETED, state);
}
}
}
use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class TestRequestStatusCollectionAPI method sendStatusRequestWithRetry.
/**
* Helper method to send a status request with specific retry limit and return
* the message/null from the success response.
*/
private String sendStatusRequestWithRetry(ModifiableSolrParams params, int maxCounter) throws SolrServerException, IOException {
String message = null;
while (maxCounter-- > 0) {
final NamedList r = sendRequest(params);
final NamedList status = (NamedList) r.get("status");
final RequestStatusState state = RequestStatusState.fromKey((String) status.get("state"));
message = (String) status.get("msg");
if (state == RequestStatusState.COMPLETED || state == RequestStatusState.FAILED) {
return message;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
// Return last state?
return message;
}
use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class CollectionsAPIAsyncDistributedZkTest method testAsyncRequests.
@Test
public void testAsyncRequests() throws Exception {
final String collection = "testAsyncOperations";
final CloudSolrClient client = cluster.getSolrClient();
RequestStatusState state = CollectionAdminRequest.createCollection(collection, "conf1", 1, 1).setRouterName("implicit").setShards("shard1").processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("CreateCollection task did not complete!", RequestStatusState.COMPLETED, state);
//Add a few documents to shard1
int numDocs = TestUtil.nextInt(random(), 10, 100);
List<SolrInputDocument> docs = new ArrayList<>(numDocs);
for (int i = 0; i < numDocs; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
doc.addField("_route_", "shard1");
docs.add(doc);
}
client.add(collection, docs);
client.commit(collection);
SolrQuery query = new SolrQuery("*:*");
query.set("shards", "shard1");
assertEquals(numDocs, client.query(collection, query).getResults().getNumFound());
state = CollectionAdminRequest.reloadCollection(collection).processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("ReloadCollection did not complete", RequestStatusState.COMPLETED, state);
state = CollectionAdminRequest.createShard(collection, "shard2").processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("CreateShard did not complete", RequestStatusState.COMPLETED, state);
//Add a doc to shard2 to make sure shard2 was created properly
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", numDocs + 1);
doc.addField("_route_", "shard2");
client.add(collection, doc);
client.commit(collection);
query = new SolrQuery("*:*");
query.set("shards", "shard2");
assertEquals(1, client.query(collection, query).getResults().getNumFound());
state = CollectionAdminRequest.deleteShard(collection, "shard2").processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("DeleteShard did not complete", RequestStatusState.COMPLETED, state);
state = CollectionAdminRequest.addReplicaToShard(collection, "shard1").processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("AddReplica did not complete", RequestStatusState.COMPLETED, state);
//cloudClient watch might take a couple of seconds to reflect it
Slice shard1 = client.getZkStateReader().getClusterState().getSlice(collection, "shard1");
int count = 0;
while (shard1.getReplicas().size() != 2) {
if (count++ > 1000) {
fail("2nd Replica not reflecting in the cluster state");
}
Thread.sleep(100);
}
state = CollectionAdminRequest.createAlias("myalias", collection).processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("CreateAlias did not complete", RequestStatusState.COMPLETED, state);
query = new SolrQuery("*:*");
query.set("shards", "shard1");
assertEquals(numDocs, client.query("myalias", query).getResults().getNumFound());
state = CollectionAdminRequest.deleteAlias("myalias").processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("DeleteAlias did not complete", RequestStatusState.COMPLETED, state);
try {
client.query("myalias", query);
fail("Alias should not exist");
} catch (SolrException e) {
//expected
}
Replica replica = shard1.getReplicas().iterator().next();
for (String liveNode : client.getZkStateReader().getClusterState().getLiveNodes()) {
if (!replica.getNodeName().equals(liveNode)) {
state = new CollectionAdminRequest.MoveReplica(collection, replica.getName(), liveNode).processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("MoveReplica did not complete", RequestStatusState.COMPLETED, state);
break;
}
}
shard1 = client.getZkStateReader().getClusterState().getSlice(collection, "shard1");
String replicaName = shard1.getReplicas().iterator().next().getName();
state = CollectionAdminRequest.deleteReplica(collection, "shard1", replicaName).processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("DeleteReplica did not complete", RequestStatusState.COMPLETED, state);
state = CollectionAdminRequest.deleteCollection(collection).processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("DeleteCollection did not complete", RequestStatusState.COMPLETED, state);
}
use of org.apache.solr.client.solrj.response.RequestStatusState in project ddf by codice.
the class BackupCommand method getBackupStatus.
private void getBackupStatus(SolrClient client, String requestId) {
try {
CollectionAdminRequest.RequestStatusResponse requestStatusResponse = CollectionAdminRequest.requestStatus(requestId).process(client);
RequestStatusState requestStatus = requestStatusResponse.getRequestStatus();
printInfoMessage(String.format("Backup status for request Id [%s] is [%s].", asyncBackupReqId, requestStatus.getKey()));
LOGGER.debug("Async backup request status: {}", requestStatus.getKey());
if (requestStatus == RequestStatusState.FAILED) {
printErrorMessage("Backup status failed. ");
printResponseErrorMessages(requestStatusResponse);
}
} catch (Exception e) {
String message = e.getMessage() != null ? e.getMessage() : "Unable to get status of backup.";
printErrorMessage(String.format("Backup status failed. %s", message));
}
}
Aggregations