Java Code Examples for org.apache.solr.client.solrj.request.CollectionAdminRequest#requestStatus()
The following examples show how to use
org.apache.solr.client.solrj.request.CollectionAdminRequest#requestStatus() .
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: CollectionAdminRequestRequiredParamsTest.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testRequestStatus() { final CollectionAdminRequest.RequestStatus request = CollectionAdminRequest.requestStatus("request"); assertContainsParams(request.getParams(), ACTION, REQUESTID); }
Example 2
Source File: AsyncCallRequestStatusResponseTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") @Test public void testAsyncCallStatusResponse() throws Exception { int numShards = 4; int numReplicas = 1; Create createCollection = CollectionAdminRequest.createCollection("asynccall", "conf", numShards, numReplicas); createCollection.setMaxShardsPerNode(100); String asyncId = createCollection.processAsync(cluster.getSolrClient()); waitForState("Expected collection 'asynccall' to have "+numShards+" shards and "+ numShards*numReplicas+" replica", "asynccall", clusterShape(numShards, numShards*numReplicas)); RequestStatusState state = AbstractFullDistribZkTestBase.getRequestStateAfterCompletion(asyncId, 30, cluster.getSolrClient()); assertEquals("Unexpected request status: " + state, "completed", state.getKey()); CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus(asyncId); CollectionAdminResponse rsp = requestStatus.process(cluster.getSolrClient()); NamedList<?> r = rsp.getResponse(); if (OverseerCollectionMessageHandler.INCLUDE_TOP_LEVEL_RESPONSE) { final int actualNumOfElems = 3+(numShards*numReplicas); // responseHeader, success, status, + old responses per every replica assertEquals("Expected "+actualNumOfElems+" elements in the response" + r.jsonStr(), actualNumOfElems, r.size()); } else { // responseHeader, success, status assertEquals("Expected 3 elements in the response" + r.jsonStr(), 3, r.size()); } assertNotNull("Expected 'responseHeader' response" + r, r.get("responseHeader")); assertNotNull("Expected 'status' response" + r, r.get("status")); { final NamedList<?> success = (NamedList<?>)r.get("success"); assertNotNull("Expected 'success' response" + r, success); final int actualSuccessElems = 2*(numShards*numReplicas); // every replica responds once on submit and once on complete assertEquals("Expected "+actualSuccessElems+ " elements in the success element" + success.jsonStr(), actualSuccessElems, success.size()); } }
Example 3
Source File: MoveReplicaTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 17-Mar-2018 This JIRA is fixed, but this test still fails //17-Aug-2018 commented @LuceneTestCase.BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 2-Aug-2018 // commented out on: 17-Feb-2019 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // annotated on: 24-Dec-2018 public void testFailedMove() throws Exception { String coll = getTestClass().getSimpleName() + "_failed_coll_" + inPlaceMove; int REPLICATION = 2; CloudSolrClient cloudClient = cluster.getSolrClient(); // random create tlog or pull type replicas with nrt boolean isTlog = random().nextBoolean(); CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(coll, "conf1", 2, 1, isTlog ? 1 : 0, !isTlog ? 1 : 0); create.setAutoAddReplicas(false); cloudClient.request(create); addDocs(coll, 100); NamedList<Object> overSeerStatus = cluster.getSolrClient().request(CollectionAdminRequest.getOverseerStatus()); String overseerLeader = (String) overSeerStatus.get("leader"); // don't kill overseer in this test Replica replica; int count = 10; do { replica = getRandomReplica(coll, cloudClient); } while (!replica.getNodeName().equals(overseerLeader) && count-- > 0); assertNotNull("could not find non-overseer replica???", replica); Set<String> liveNodes = cloudClient.getZkStateReader().getClusterState().getLiveNodes(); ArrayList<String> l = new ArrayList<>(liveNodes); Collections.shuffle(l, random()); String targetNode = null; for (String node : liveNodes) { if (!replica.getNodeName().equals(node) && !overseerLeader.equals(node)) { targetNode = node; break; } } assertNotNull(targetNode); CollectionAdminRequest.MoveReplica moveReplica = createMoveReplicaRequest(coll, replica, targetNode); moveReplica.setInPlaceMove(inPlaceMove); // start moving String asyncId = IdUtils.randomId(); moveReplica.processAsync(asyncId, cloudClient); // shut down target node for (int i = 0; i < cluster.getJettySolrRunners().size(); i++) { if (cluster.getJettySolrRunner(i).getNodeName().equals(targetNode)) { JettySolrRunner j = cluster.stopJettySolrRunner(i); cluster.waitForJettyToStop(j); break; } } CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus(asyncId); // wait for async request success boolean success = true; for (int i = 0; i < 200; i++) { CollectionAdminRequest.RequestStatusResponse rsp = requestStatus.process(cloudClient); assertNotSame(rsp.getRequestStatus().toString(), rsp.getRequestStatus(), RequestStatusState.COMPLETED); if (rsp.getRequestStatus() == RequestStatusState.FAILED) { success = false; break; } Thread.sleep(500); } assertFalse(success); if (log.isInfoEnabled()) { log.info("--- current collection state: {}", cloudClient.getZkStateReader().getClusterState().getCollection(coll)); } assertEquals(100, cluster.getSolrClient().query(coll, new SolrQuery("*:*")).getResults().getNumFound()); }
Example 4
Source File: DeleteNodeTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { CloudSolrClient cloudClient = cluster.getSolrClient(); String coll = "deletenodetest_coll"; ClusterState state = cloudClient.getZkStateReader().getClusterState(); Set<String> liveNodes = state.getLiveNodes(); ArrayList<String> l = new ArrayList<>(liveNodes); Collections.shuffle(l, random()); CollectionAdminRequest.Create create = pickRandom( CollectionAdminRequest.createCollection(coll, "conf1", 5, 2, 0, 0), CollectionAdminRequest.createCollection(coll, "conf1", 5, 1, 1, 0), CollectionAdminRequest.createCollection(coll, "conf1", 5, 0, 1, 1), // check RF=1 CollectionAdminRequest.createCollection(coll, "conf1", 5, 1, 0, 0), CollectionAdminRequest.createCollection(coll, "conf1", 5, 0, 1, 0) ); create.setCreateNodeSet(StrUtils.join(l, ',')).setMaxShardsPerNode(3); cloudClient.request(create); state = cloudClient.getZkStateReader().getClusterState(); String node2bdecommissioned = l.get(0); // check what replicas are on the node, and whether the call should fail boolean shouldFail = false; DocCollection docColl = state.getCollection(coll); log.info("#### DocCollection: {}", docColl); List<Replica> replicas = docColl.getReplicas(node2bdecommissioned); if (replicas != null) { for (Replica replica : replicas) { String shard = docColl.getShardId(node2bdecommissioned, replica.getStr(ZkStateReader.CORE_NAME_PROP)); Slice slice = docColl.getSlice(shard); boolean hasOtherNonPullReplicas = false; for (Replica r: slice.getReplicas()) { if (!r.getName().equals(replica.getName()) && !r.getNodeName().equals(node2bdecommissioned) && r.getType() != Replica.Type.PULL) { hasOtherNonPullReplicas = true; break; } } if (!hasOtherNonPullReplicas) { shouldFail = true; break; } } } new CollectionAdminRequest.DeleteNode(node2bdecommissioned).processAsync("003", cloudClient); CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus("003"); CollectionAdminRequest.RequestStatusResponse rsp = null; for (int i = 0; i < 200; i++) { rsp = requestStatus.process(cloudClient); if (rsp.getRequestStatus() == RequestStatusState.FAILED || rsp.getRequestStatus() == RequestStatusState.COMPLETED) { break; } Thread.sleep(50); } if (log.isInfoEnabled()) { log.info("####### DocCollection after: {}", cloudClient.getZkStateReader().getClusterState().getCollection(coll)); } if (shouldFail) { assertTrue(String.valueOf(rsp), rsp.getRequestStatus() == RequestStatusState.FAILED); } else { assertFalse(String.valueOf(rsp), rsp.getRequestStatus() == RequestStatusState.FAILED); } }
Example 5
Source File: AddReplicaTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { String collection = "addreplicatest_coll"; CloudSolrClient cloudClient = cluster.getSolrClient(); CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collection, "conf1", 2, 1); create.setMaxShardsPerNode(2); cloudClient.request(create); cluster.waitForActiveCollection(collection, 2, 2); ClusterState clusterState = cloudClient.getZkStateReader().getClusterState(); DocCollection coll = clusterState.getCollection(collection); String sliceName = coll.getSlices().iterator().next().getName(); Collection<Replica> replicas = coll.getSlice(sliceName).getReplicas(); CollectionAdminRequest.AddReplica addReplica = CollectionAdminRequest.addReplicaToShard(collection, sliceName); addReplica.processAsync("000", cloudClient); CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus("000"); CollectionAdminRequest.RequestStatusResponse rsp = requestStatus.process(cloudClient); assertNotSame(rsp.getRequestStatus(), COMPLETED); // wait for async request success boolean success = false; for (int i = 0; i < 200; i++) { rsp = requestStatus.process(cloudClient); if (rsp.getRequestStatus() == COMPLETED) { success = true; break; } assertNotSame(rsp.toString(), rsp.getRequestStatus(), RequestStatusState.FAILED); Thread.sleep(500); } assertTrue(success); Collection<Replica> replicas2 = cloudClient.getZkStateReader().getClusterState().getCollection(collection).getSlice(sliceName).getReplicas(); replicas2.removeAll(replicas); assertEquals(1, replicas2.size()); // use waitForFinalState addReplica.setWaitForFinalState(true); addReplica.processAsync("001", cloudClient); requestStatus = CollectionAdminRequest.requestStatus("001"); rsp = requestStatus.process(cloudClient); assertNotSame(rsp.getRequestStatus(), COMPLETED); // wait for async request success success = false; for (int i = 0; i < 200; i++) { rsp = requestStatus.process(cloudClient); if (rsp.getRequestStatus() == COMPLETED) { success = true; break; } assertNotSame(rsp.toString(), rsp.getRequestStatus(), RequestStatusState.FAILED); Thread.sleep(500); } assertTrue(success); // let the client watch fire Thread.sleep(1000); clusterState = cloudClient.getZkStateReader().getClusterState(); coll = clusterState.getCollection(collection); Collection<Replica> replicas3 = coll.getSlice(sliceName).getReplicas(); replicas3.removeAll(replicas); String replica2 = replicas2.iterator().next().getName(); assertEquals(2, replicas3.size()); for (Replica replica : replicas3) { if (replica.getName().equals(replica2)) { continue; // may be still recovering } assertSame(coll.toString() + "\n" + replica.toString(), replica.getState(), Replica.State.ACTIVE); } }