Search in sources :

Example 36 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method getRequestState.

static RequestStatusState getRequestState(String requestId, SolrClient client) throws IOException, SolrServerException {
    CollectionAdminResponse response = getStatusResponse(requestId, client);
    NamedList innerResponse = (NamedList) response.getResponse().get("status");
    return RequestStatusState.fromKey((String) innerResponse.get("state"));
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList)

Example 37 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.

the class SharedFSAutoReplicaFailoverTest method testBasics.

// very slow tests, especially since jetty is started and stopped
// serially
private void testBasics() throws Exception {
    String collection1 = "solrj_collection";
    Create createCollectionRequest = CollectionAdminRequest.createCollection(collection1, "conf1", 2, 2).setMaxShardsPerNode(2).setRouterField("myOwnField").setAutoAddReplicas(true);
    CollectionAdminResponse response = createCollectionRequest.process(cloudClient);
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    waitForRecoveriesToFinish(collection1, false);
    String collection2 = "solrj_collection2";
    createCollectionRequest = CollectionAdminRequest.createCollection(collection2, "conf1", 2, 2).setMaxShardsPerNode(2).setRouterField("myOwnField").setAutoAddReplicas(false);
    CollectionAdminResponse response2 = createCollectionRequest.process(getCommonCloudSolrClient());
    assertEquals(0, response2.getStatus());
    assertTrue(response2.isSuccess());
    waitForRecoveriesToFinish(collection2, false);
    String collection3 = "solrj_collection3";
    createCollectionRequest = CollectionAdminRequest.createCollection(collection3, "conf1", 5, 1).setMaxShardsPerNode(1).setRouterField("myOwnField").setAutoAddReplicas(true);
    CollectionAdminResponse response3 = createCollectionRequest.process(getCommonCloudSolrClient());
    assertEquals(0, response3.getStatus());
    assertTrue(response3.isSuccess());
    waitForRecoveriesToFinish(collection3, false);
    // a collection has only 1 replica per a shard
    String collection4 = "solrj_collection4";
    createCollectionRequest = CollectionAdminRequest.createCollection(collection4, "conf1", 5, 1).setMaxShardsPerNode(5).setRouterField("text").setAutoAddReplicas(true);
    CollectionAdminResponse response4 = createCollectionRequest.process(getCommonCloudSolrClient());
    assertEquals(0, response4.getStatus());
    assertTrue(response4.isSuccess());
    waitForRecoveriesToFinish(collection4, false);
    // all collections
    String[] collections = { collection1, collection2, collection3, collection4 };
    // add some documents to collection4
    final int numDocs = 100;
    // indexed but not committed
    addDocs(collection4, numDocs, false);
    // no result because not committed yet
    queryAndAssertResultSize(collection4, 0, 10000);
    assertUlogDir(collections);
    ChaosMonkey.stop(jettys.get(1));
    ChaosMonkey.stop(jettys.get(2));
    Thread.sleep(5000);
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 120000));
    assertSliceAndReplicaCount(collection1);
    assertEquals(4, ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection1));
    assertTrue(ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection2) < 4);
    // collection3 has maxShardsPerNode=1, there are 4 standard jetties and one control jetty and 2 nodes stopped
    ClusterStateUtil.waitForLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection3, 3, 30000);
    // collection4 has maxShardsPerNode=5 and setMaxShardsPerNode=5
    ClusterStateUtil.waitForLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection4, 5, 30000);
    // all docs should be queried after failover
    // to query all docs
    cloudClient.commit();
    assertSingleReplicationAndShardSize(collection4, 5);
    queryAndAssertResultSize(collection4, numDocs, 10000);
    // collection1 should still be at 4
    assertEquals(4, ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection1));
    // and collection2 less than 4
    assertTrue(ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection2) < 4);
    assertUlogDir(collections);
    ChaosMonkey.stop(jettys);
    ChaosMonkey.stop(controlJetty);
    assertTrue("Timeout waiting for all not live", ClusterStateUtil.waitForAllReplicasNotLive(cloudClient.getZkStateReader(), 45000));
    ChaosMonkey.start(jettys);
    ChaosMonkey.start(controlJetty);
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 120000));
    assertSliceAndReplicaCount(collection1);
    assertSingleReplicationAndShardSize(collection3, 5);
    // all docs should be queried
    assertSingleReplicationAndShardSize(collection4, 5);
    queryAndAssertResultSize(collection4, numDocs, 10000);
    assertUlogDir(collections);
    int jettyIndex = random().nextInt(jettys.size());
    ChaosMonkey.stop(jettys.get(jettyIndex));
    ChaosMonkey.start(jettys.get(jettyIndex));
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 60000));
    assertSliceAndReplicaCount(collection1);
    assertUlogDir(collections);
    assertSingleReplicationAndShardSize(collection3, 5);
    ClusterStateUtil.waitForLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection3, 5, 30000);
    assertSingleReplicationAndShardSize(collection4, 5);
    ClusterStateUtil.waitForLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection4, 5, 30000);
    //disable autoAddReplicas
    Map m = makeMap("action", CollectionParams.CollectionAction.CLUSTERPROP.toLower(), "name", ZkStateReader.AUTO_ADD_REPLICAS, "val", "false");
    SolrRequest request = new QueryRequest(new MapSolrParams(m));
    request.setPath("/admin/collections");
    cloudClient.request(request);
    int currentCount = ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection1);
    ChaosMonkey.stop(jettys.get(3));
    //solr.xml has defined workLoopDelay=10s and waitAfterExpiration=10s
    //Hence waiting for 30 seconds to be on the safe side.
    Thread.sleep(30000);
    //Ensures that autoAddReplicas has not kicked in.
    assertTrue(currentCount > ClusterStateUtil.getLiveAndActiveReplicaCount(cloudClient.getZkStateReader(), collection1));
    //enable autoAddReplicas
    m = makeMap("action", CollectionParams.CollectionAction.CLUSTERPROP.toLower(), "name", ZkStateReader.AUTO_ADD_REPLICAS);
    request = new QueryRequest(new MapSolrParams(m));
    request.setPath("/admin/collections");
    cloudClient.request(request);
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 90000));
    assertSliceAndReplicaCount(collection1);
    assertUlogDir(collections);
    // restart all to test core saved state
    ChaosMonkey.stop(jettys);
    ChaosMonkey.stop(controlJetty);
    assertTrue("Timeout waiting for all not live", ClusterStateUtil.waitForAllReplicasNotLive(cloudClient.getZkStateReader(), 45000));
    ChaosMonkey.start(jettys);
    ChaosMonkey.start(controlJetty);
    assertTrue("Timeout waiting for all live and active", ClusterStateUtil.waitForAllActiveAndLiveReplicas(cloudClient.getZkStateReader(), collection1, 120000));
    assertSliceAndReplicaCount(collection1);
    assertUlogDir(collections);
    assertSliceAndReplicaCount(collection1);
    assertSingleReplicationAndShardSize(collection3, 5);
    // all docs should be queried
    assertSingleReplicationAndShardSize(collection4, 5);
    queryAndAssertResultSize(collection4, numDocs, 10000);
}
Also used : MapSolrParams(org.apache.solr.common.params.MapSolrParams) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) Create(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create) SolrRequest(org.apache.solr.client.solrj.SolrRequest) HashMap(java.util.HashMap) Map(java.util.Map) Utils.makeMap(org.apache.solr.common.util.Utils.makeMap)

Example 38 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.

the class ReplicationFactorTest method testRf2NotUsingDirectUpdates.

protected void testRf2NotUsingDirectUpdates() throws Exception {
    int numShards = 2;
    int replicationFactor = 2;
    int maxShardsPerNode = 1;
    String testCollectionName = "repfacttest_c8n_2x2";
    String shardId = "shard1";
    int minRf = 2;
    CollectionAdminResponse resp = createCollection(testCollectionName, numShards, replicationFactor, maxShardsPerNode);
    if (resp.getResponse().get("failure") != null) {
        CollectionAdminRequest.deleteCollection(testCollectionName).process(cloudClient);
        resp = createCollection(testCollectionName, numShards, replicationFactor, maxShardsPerNode);
        if (resp.getResponse().get("failure") != null) {
            fail("Could not create " + testCollectionName);
        }
    }
    cloudClient.setDefaultCollection(testCollectionName);
    List<Replica> replicas = ensureAllReplicasAreActive(testCollectionName, shardId, numShards, replicationFactor, 30);
    assertTrue("Expected active 1 replicas for " + testCollectionName, replicas.size() == 1);
    List<SolrInputDocument> batch = new ArrayList<SolrInputDocument>(10);
    for (int i = 0; i < 15; i++) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField(id, String.valueOf(i));
        doc.addField("a_t", "hello" + i);
        batch.add(doc);
    }
    // send directly to the leader using HttpSolrServer instead of CloudSolrServer (to test support for non-direct updates)
    UpdateRequest up = new UpdateRequest();
    up.setParam(UpdateRequest.MIN_REPFACT, String.valueOf(minRf));
    up.add(batch);
    Replica leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, shardId);
    sendNonDirectUpdateRequestReplicaWithRetry(leader, up, 2, testCollectionName);
    sendNonDirectUpdateRequestReplicaWithRetry(replicas.get(0), up, 2, testCollectionName);
    // so now kill the replica of shard2 and verify the achieved rf is only 1
    List<Replica> shard2Replicas = ensureAllReplicasAreActive(testCollectionName, "shard2", numShards, replicationFactor, 30);
    assertTrue("Expected active 1 replicas for " + testCollectionName, replicas.size() == 1);
    getProxyForReplica(shard2Replicas.get(0)).close();
    Thread.sleep(2000);
    // shard1 will have rf=2 but shard2 will only have rf=1
    sendNonDirectUpdateRequestReplicaWithRetry(leader, up, 1, testCollectionName);
    sendNonDirectUpdateRequestReplicaWithRetry(replicas.get(0), up, 1, testCollectionName);
    // heal the partition
    getProxyForReplica(shard2Replicas.get(0)).reopen();
    Thread.sleep(2000);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica)

Example 39 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.

the class TestConfigSetsAPI method testUploadWithScriptUpdateProcessor.

@Test
public void testUploadWithScriptUpdateProcessor() throws Exception {
    for (boolean withAuthorization : Arrays.asList(false, true)) {
        String suffix;
        if (withAuthorization) {
            suffix = "-trusted";
            protectConfigsHandler();
            uploadConfigSet("with-script-processor", suffix, "solr", "SolrRocks");
        } else {
            suffix = "-untrusted";
            uploadConfigSet("with-script-processor", suffix, null, null);
        }
        // try to create a collection with the uploaded configset
        CollectionAdminResponse resp = createCollection("newcollection2", "with-script-processor" + suffix, 1, 1, solrCluster.getSolrClient());
        if (withAuthorization) {
            scriptRequest("newcollection2");
        } else {
            log.info("Client saw errors: " + resp.getErrorMessages());
            assertTrue(resp.getErrorMessages() != null && resp.getErrorMessages().size() > 0);
            assertTrue(resp.getErrorMessages().getVal(0).contains("The configset for this collection was uploaded without any authentication"));
        }
    }
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) BasicAuthIntegrationTest(org.apache.solr.security.BasicAuthIntegrationTest) Test(org.junit.Test)

Example 40 with CollectionAdminResponse

use of org.apache.solr.client.solrj.response.CollectionAdminResponse in project lucene-solr by apache.

the class AsyncCallRequestStatusResponseTest method testAsyncCallStatusResponse.

@Test
public void testAsyncCallStatusResponse() throws Exception {
    String asyncId = CollectionAdminRequest.createCollection("asynccall", "conf", 2, 1).processAsync(cluster.getSolrClient());
    waitForState("Expected collection 'asynccall' to have 2 shards and 1 replica", "asynccall", clusterShape(2, 1));
    int tries = 0;
    while (true) {
        final RequestStatusState state = CollectionAdminRequest.requestStatus(asyncId).process(cluster.getSolrClient()).getRequestStatus();
        if (state == RequestStatusState.COMPLETED)
            break;
        if (tries++ > 10)
            fail("Expected to see RequestStatusState.COMPLETED but was " + state.toString());
        TimeUnit.SECONDS.sleep(1);
    }
    CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus(asyncId);
    CollectionAdminResponse rsp = requestStatus.process(cluster.getSolrClient());
    NamedList<?> r = rsp.getResponse();
    // Check that there's more response than the hardcoded status and states
    assertEquals("Assertion Failure" + r.toString(), 5, r.size());
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) RequestStatusState(org.apache.solr.client.solrj.response.RequestStatusState) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Test(org.junit.Test)

Aggregations

CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)59 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)30 Test (org.junit.Test)21 NamedList (org.apache.solr.common.util.NamedList)11 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)9 SolrClient (org.apache.solr.client.solrj.SolrClient)8 SolrServerException (org.apache.solr.client.solrj.SolrServerException)8 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 ArrayList (java.util.ArrayList)7 Replica (org.apache.solr.common.cloud.Replica)7 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)6 IOException (java.io.IOException)5 Map (java.util.Map)5 SolrRequest (org.apache.solr.client.solrj.SolrRequest)5 HttpResponse (org.apache.http.HttpResponse)4 HttpGet (org.apache.http.client.methods.HttpGet)4 HttpPost (org.apache.http.client.methods.HttpPost)4 StringEntity (org.apache.http.entity.StringEntity)4 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)4