Search in sources :

Example 6 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)

Example 7 with CoreAdminResponse

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

the class CollectionsAPIDistributedZkTest method addReplicaTest.

@Test
public void addReplicaTest() throws Exception {
    String collectionName = "addReplicaColl";
    CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setMaxShardsPerNode(4).process(cluster.getSolrClient());
    ArrayList<String> nodeList = new ArrayList<>(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes());
    Collections.shuffle(nodeList, random());
    String newReplicaName = Assign.assignNode(getCollectionState(collectionName));
    CollectionAdminRequest.addReplicaToShard(collectionName, "shard1").setNode(nodeList.get(0)).process(cluster.getSolrClient());
    Replica newReplica = getCollectionState(collectionName).getReplica(newReplicaName);
    assertEquals("Replica should be created on the right node", cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getStr(ZkStateReader.BASE_URL_PROP));
    newReplicaName = Assign.assignNode(getCollectionState(collectionName));
    Path instancePath = createTempDir();
    CollectionAdminRequest.addReplicaToShard(collectionName, "shard1").withProperty(CoreAdminParams.INSTANCE_DIR, instancePath.toString()).process(cluster.getSolrClient());
    newReplica = getCollectionState(collectionName).getReplica(newReplicaName);
    assertNotNull(newReplica);
    try (HttpSolrClient coreclient = getHttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP))) {
        CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient);
        NamedList<Object> coreStatus = status.getCoreStatus(newReplica.getStr("core"));
        String instanceDirStr = (String) coreStatus.get("instanceDir");
        assertEquals(instanceDirStr, instancePath.toString());
    }
    //Test to make sure we can't create another replica with an existing core_name of that collection
    String coreName = newReplica.getStr(CORE_NAME_PROP);
    SolrException e = expectThrows(SolrException.class, () -> {
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", "addreplica");
        params.set("collection", collectionName);
        params.set("shard", "shard1");
        params.set("name", coreName);
        QueryRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        cluster.getSolrClient().request(request);
    });
    assertTrue(e.getMessage().contains("Another replica with the same core name already exists for this collection"));
    // Check that specifying property.name works. DO NOT remove this when the "name" property is deprecated
    // for ADDREPLICA, this is "property.name". See SOLR-7132
    newReplicaName = Assign.assignNode(getCollectionState(collectionName));
    CollectionAdminRequest.addReplicaToShard(collectionName, "shard1").withProperty(CoreAdminParams.NAME, "propertyDotName").process(cluster.getSolrClient());
    newReplica = getCollectionState(collectionName).getReplica(newReplicaName);
    assertEquals("'core' should be 'propertyDotName' ", "propertyDotName", newReplica.getStr("core"));
}
Also used : Path(java.nio.file.Path) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) SolrException(org.apache.solr.common.SolrException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 8 with CoreAdminResponse

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

the class CollectionsAPISolrJTest method testCloudInfoInCoreStatus.

@Test
public void testCloudInfoInCoreStatus() throws IOException, SolrServerException {
    String collectionName = "corestatus_test";
    CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).setStateFormat(1).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    String nodeName = ((NamedList) response.getResponse().get("success")).getName(0);
    String corename = (String) ((NamedList) ((NamedList) response.getResponse().get("success")).getVal(0)).get("core");
    try (HttpSolrClient coreclient = getHttpSolrClient(cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeName))) {
        CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreclient);
        Map m = status.getResponse().asMap(5);
        assertEquals(collectionName, Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "collection")));
        assertNotNull(Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "shard")));
        assertNotNull(Utils.getObjectByPath(m, true, Arrays.asList("status", corename, "cloud", "replica")));
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) Map(java.util.Map) Test(org.junit.Test)

Aggregations

CoreAdminResponse (org.apache.solr.client.solrj.response.CoreAdminResponse)8 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)5 Test (org.junit.Test)5 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)3 ArrayList (java.util.ArrayList)2 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 MalformedURLException (java.net.MalformedURLException)1 Path (java.nio.file.Path)1 Map (java.util.Map)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 Create (org.apache.solr.client.solrj.request.CoreAdminRequest.Create)1 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)1 CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)1