Search in sources :

Example 1 with CoreAdminResponse

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

the class TestSolrProperties method testProperties.

@Test
public void testProperties() throws Exception {
    UpdateRequest up = new UpdateRequest();
    up.setAction(ACTION.COMMIT, true, true);
    up.deleteByQuery("*:*");
    up.process(getSolrCore0());
    up.process(getSolrCore1());
    up.clear();
    // Add something to each core
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "AAA");
    doc.setField("core0", "yup stopfra stopfrb stopena stopenb");
    // Add to core0
    up.add(doc);
    up.process(getSolrCore0());
    SolrTestCaseJ4.ignoreException("unknown field");
    // You can't add it to core1
    try {
        up.process(getSolrCore1());
        fail("Can't add core0 field to core1!");
    } catch (Exception ex) {
    }
    // Add to core1
    doc.setField("id", "BBB");
    doc.setField("core1", "yup stopfra stopfrb stopena stopenb");
    doc.removeField("core0");
    up.add(doc);
    up.process(getSolrCore1());
    // You can't add it to core1
    try {
        SolrTestCaseJ4.ignoreException("core0");
        up.process(getSolrCore0());
        fail("Can't add core1 field to core0!");
    } catch (Exception ex) {
    }
    SolrTestCaseJ4.resetExceptionIgnores();
    // now Make sure AAA is in 0 and BBB in 1
    SolrQuery q = new SolrQuery();
    QueryRequest r = new QueryRequest(q);
    q.setQuery("id:AAA");
    assertEquals(1, r.process(getSolrCore0()).getResults().size());
    assertEquals(0, r.process(getSolrCore1()).getResults().size());
    // Now test Changing the default core
    assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
    assertEquals(0, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
    assertEquals(0, getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
    assertEquals(1, getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());
    // Now test reloading it should have a newer open time
    String name = "core0";
    SolrClient coreadmin = getSolrAdmin();
    CoreAdminResponse mcr = CoreAdminRequest.getStatus(name, coreadmin);
    long before = mcr.getStartTime(name).getTime();
    CoreAdminRequest.reloadCore(name, coreadmin);
    mcr = CoreAdminRequest.getStatus(name, coreadmin);
    long after = mcr.getStartTime(name).getTime();
    assertTrue("should have more recent time: " + after + "," + before, after > before);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 2 with CoreAdminResponse

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

the class TestCoreAdmin method testConfigSet.

@Test
public void testConfigSet() throws Exception {
    SolrClient client = getSolrAdmin();
    File testDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName()).toFile();
    File newCoreInstanceDir = new File(testDir, "newcore");
    CoreAdminRequest.Create req = new CoreAdminRequest.Create();
    req.setCoreName("corewithconfigset");
    req.setInstanceDir(newCoreInstanceDir.getAbsolutePath());
    req.setConfigSet("configset-2");
    CoreAdminResponse response = req.process(client);
    assertThat((String) response.getResponse().get("core"), is("corewithconfigset"));
    try (SolrCore core = cores.getCore("corewithconfigset")) {
        assertThat(core, is(notNullValue()));
    }
}
Also used : SolrClient(org.apache.solr.client.solrj.SolrClient) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) SolrCore(org.apache.solr.core.SolrCore) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) File(java.io.File) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) Test(org.junit.Test)

Example 3 with CoreAdminResponse

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

the class ReplaceNodeTest method test.

@Test
public void test() throws Exception {
    cluster.waitForAllNodes(5000);
    String coll = "replacenodetest_coll";
    log.info("total_jettys: " + cluster.getJettySolrRunners().size());
    CloudSolrClient cloudClient = cluster.getSolrClient();
    Set<String> liveNodes = cloudClient.getZkStateReader().getClusterState().getLiveNodes();
    ArrayList<String> l = new ArrayList<>(liveNodes);
    Collections.shuffle(l, random());
    String emptyNode = l.remove(0);
    String node2bdecommissioned = l.get(0);
    CollectionAdminRequest.Create create;
    // NOTE: always using the createCollection that takes in 'int' for all types of replicas, so we never
    // have to worry about null checking when comparing the Create command with the final Slices
    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), CollectionAdminRequest.createCollection(coll, "conf1", 5, 1, 0, 1), CollectionAdminRequest.createCollection(coll, "conf1", 5, 0, 2, 0));
    create.setCreateNodeSet(StrUtils.join(l, ',')).setMaxShardsPerNode(3);
    cloudClient.request(create);
    log.info("excluded_node : {}  ", emptyNode);
    new CollectionAdminRequest.ReplaceNode(node2bdecommissioned, emptyNode).processAsync("000", cloudClient);
    CollectionAdminRequest.RequestStatus requestStatus = CollectionAdminRequest.requestStatus("000");
    boolean success = false;
    for (int i = 0; i < 200; i++) {
        CollectionAdminRequest.RequestStatusResponse rsp = requestStatus.process(cloudClient);
        if (rsp.getRequestStatus() == RequestStatusState.COMPLETED) {
            success = true;
            break;
        }
        assertFalse(rsp.getRequestStatus() == RequestStatusState.FAILED);
        Thread.sleep(50);
    }
    assertTrue(success);
    try (HttpSolrClient coreclient = getHttpSolrClient(cloudClient.getZkStateReader().getBaseUrlForNodeName(node2bdecommissioned))) {
        CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreclient);
        assertTrue(status.getCoreStatus().size() == 0);
    }
    //let's do it back
    new CollectionAdminRequest.ReplaceNode(emptyNode, node2bdecommissioned).setParallel(Boolean.TRUE).processAsync("001", cloudClient);
    requestStatus = CollectionAdminRequest.requestStatus("001");
    for (int i = 0; i < 200; i++) {
        CollectionAdminRequest.RequestStatusResponse rsp = requestStatus.process(cloudClient);
        if (rsp.getRequestStatus() == RequestStatusState.COMPLETED) {
            success = true;
            break;
        }
        assertFalse(rsp.getRequestStatus() == RequestStatusState.FAILED);
        Thread.sleep(50);
    }
    assertTrue(success);
    try (HttpSolrClient coreclient = getHttpSolrClient(cloudClient.getZkStateReader().getBaseUrlForNodeName(emptyNode))) {
        CoreAdminResponse status = CoreAdminRequest.getStatus(null, coreclient);
        assertEquals("Expecting no cores but found some: " + status.getCoreStatus(), 0, status.getCoreStatus().size());
    }
    DocCollection collection = cloudClient.getZkStateReader().getClusterState().getCollection(coll);
    assertEquals(create.getNumShards().intValue(), collection.getSlices().size());
    for (Slice s : collection.getSlices()) {
        assertEquals(create.getNumNrtReplicas().intValue(), s.getReplicas(EnumSet.of(Replica.Type.NRT)).size());
        assertEquals(create.getNumTlogReplicas().intValue(), s.getReplicas(EnumSet.of(Replica.Type.TLOG)).size());
        assertEquals(create.getNumPullReplicas().intValue(), s.getReplicas(EnumSet.of(Replica.Type.PULL)).size());
    }
}
Also used : ArrayList(java.util.ArrayList) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) Test(org.junit.Test)

Example 4 with CoreAdminResponse

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

the class DistributedVersionInfoTest method reloadCollection.

protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception {
    ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica);
    String coreName = coreProps.getCoreName();
    boolean reloadedOk = false;
    try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) {
        CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client);
        long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime();
        Thread.sleep(1000);
        // send reload command for the collection
        log.info("Sending RELOAD command for " + testCollectionName);
        CollectionAdminRequest.reloadCollection(testCollectionName).process(client);
        // reload can take a short while
        Thread.sleep(2000);
        // verify reload is done, waiting up to 30 seconds for slow test environments
        long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS);
        while (System.nanoTime() < timeout) {
            statusResp = CoreAdminRequest.getStatus(coreName, client);
            long startTimeAfterReload = statusResp.getStartTime(coreName).getTime();
            if (startTimeAfterReload > leaderCoreStartTime) {
                reloadedOk = true;
                break;
            }
            // else ... still waiting to see the reloaded core report a later start time
            Thread.sleep(1000);
        }
    }
    return reloadedOk;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse)

Example 5 with CoreAdminResponse

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

the class AbstractFullDistribZkTestBase method reloadCollection.

protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception {
    ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica);
    String coreName = coreProps.getCoreName();
    boolean reloadedOk = false;
    try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) {
        CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client);
        long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime();
        Thread.sleep(1000);
        // send reload command for the collection
        log.info("Sending RELOAD command for " + testCollectionName);
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.RELOAD.toString());
        params.set("name", testCollectionName);
        QueryRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        // reload can take a short while
        Thread.sleep(2000);
        // verify reload is done, waiting up to 30 seconds for slow test environments
        long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS);
        while (System.nanoTime() < timeout) {
            statusResp = CoreAdminRequest.getStatus(coreName, client);
            long startTimeAfterReload = statusResp.getStartTime(coreName).getTime();
            if (startTimeAfterReload > leaderCoreStartTime) {
                reloadedOk = true;
                break;
            }
            // else ... still waiting to see the reloaded core report a later start time
            Thread.sleep(1000);
        }
    }
    return reloadedOk;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

CoreAdminResponse (org.apache.solr.client.solrj.response.CoreAdminResponse)9 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)3 SolrClient (org.apache.solr.client.solrj.SolrClient)2 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)2 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 GoraException (org.apache.gora.util.GoraException)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)1 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)1 CoreAdminRequest (org.apache.solr.client.solrj.request.CoreAdminRequest)1 Create (org.apache.solr.client.solrj.request.CoreAdminRequest.Create)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1