Search in sources :

Example 1 with CoreStatus

use of org.apache.solr.client.solrj.request.CoreStatus in project lucene-solr by apache.

the class DeleteReplicaTest method deleteReplicaAndVerifyDirectoryCleanup.

@Test
public void deleteReplicaAndVerifyDirectoryCleanup() throws Exception {
    final String collectionName = "deletereplica_test";
    CollectionAdminRequest.createCollection(collectionName, "conf", 1, 2).process(cluster.getSolrClient());
    Replica leader = cluster.getSolrClient().getZkStateReader().getLeaderRetry(collectionName, "shard1");
    //Confirm that the instance and data directory exist
    CoreStatus coreStatus = getCoreStatus(leader);
    assertTrue("Instance directory doesn't exist", Files.exists(Paths.get(coreStatus.getInstanceDirectory())));
    assertTrue("DataDirectory doesn't exist", Files.exists(Paths.get(coreStatus.getDataDirectory())));
    CollectionAdminRequest.deleteReplica(collectionName, "shard1", leader.getName()).process(cluster.getSolrClient());
    Replica newLeader = cluster.getSolrClient().getZkStateReader().getLeaderRetry(collectionName, "shard1");
    assertFalse(leader.equals(newLeader));
    //Confirm that the instance and data directory were deleted by default
    assertFalse("Instance directory still exists", Files.exists(Paths.get(coreStatus.getInstanceDirectory())));
    assertFalse("DataDirectory still exists", Files.exists(Paths.get(coreStatus.getDataDirectory())));
}
Also used : CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 2 with CoreStatus

use of org.apache.solr.client.solrj.request.CoreStatus in project lucene-solr by apache.

the class DeleteReplicaTest method deleteLiveReplicaTest.

@Test
public void deleteLiveReplicaTest() throws Exception {
    final String collectionName = "delLiveColl";
    CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).process(cluster.getSolrClient());
    DocCollection state = getCollectionState(collectionName);
    Slice shard = getRandomShard(state);
    Replica replica = getRandomReplica(shard, (r) -> r.getState() == Replica.State.ACTIVE);
    CoreStatus coreStatus = getCoreStatus(replica);
    Path dataDir = Paths.get(coreStatus.getDataDirectory());
    Exception e = expectThrows(Exception.class, () -> {
        CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()).setOnlyIfDown(true).process(cluster.getSolrClient());
    });
    assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().contains("state is 'active'"));
    assertTrue("Data directory for " + replica.getName() + " should not have been deleted", Files.exists(dataDir));
    CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()).process(cluster.getSolrClient());
    waitForState("Expected replica " + replica.getName() + " to have been removed", collectionName, (n, c) -> {
        Slice testShard = c.getSlice(shard.getName());
        return testShard.getReplica(replica.getName()) == null;
    });
    assertFalse("Data directory for " + replica.getName() + " should have been removed", Files.exists(dataDir));
}
Also used : Path(java.nio.file.Path) CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 3 with CoreStatus

use of org.apache.solr.client.solrj.request.CoreStatus in project lucene-solr by apache.

the class CoreAdminHandlerTest method testDeleteInstanceDirAfterCreateFailure.

@Test
public void testDeleteInstanceDirAfterCreateFailure() throws Exception {
    assumeFalse("Ignore test on windows because it does not delete data directory immediately after unload", Constants.WINDOWS);
    File solrHomeDirectory = new File(initCoreDataDir, getClass().getName() + "-corex-" + System.nanoTime());
    solrHomeDirectory.mkdirs();
    copySolrHomeToTemp(solrHomeDirectory, "corex");
    File corex = new File(solrHomeDirectory, "corex");
    FileUtils.write(new File(corex, "core.properties"), "", StandardCharsets.UTF_8);
    JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr"));
    runner.start();
    try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex")) {
        client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
        client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", "123");
        client.add(doc);
        client.commit();
    }
    Path dataDir = null;
    try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) {
        CoreStatus status = CoreAdminRequest.getCoreStatus("corex", true, client);
        String dataDirectory = status.getDataDirectory();
        dataDir = Paths.get(dataDirectory);
        assertTrue(Files.exists(dataDir));
    }
    File subHome = new File(solrHomeDirectory, "corex" + File.separator + "conf");
    String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf";
    FileUtils.copyFile(new File(top, "bad-error-solrconfig.xml"), new File(subHome, "solrconfig.xml"));
    try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) {
        client.setConnectionTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
        client.setSoTimeout(SolrTestCaseJ4.DEFAULT_CONNECTION_TIMEOUT);
        try {
            CoreAdminRequest.reloadCore("corex", client);
        } catch (Exception e) {
        // this is expected because we put a bad solrconfig -- ignore
        }
        CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false);
        req.setDeleteDataDir(true);
        // important because the data directory is inside the instance directory
        req.setDeleteInstanceDir(false);
        req.setCoreName("corex");
        req.process(client);
    }
    runner.stop();
    assertTrue("The data directory was not cleaned up on unload after a failed core reload", Files.notExists(dataDir));
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Path(java.nio.file.Path) SolrInputDocument(org.apache.solr.common.SolrInputDocument) CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CoreAdminRequest(org.apache.solr.client.solrj.request.CoreAdminRequest) File(java.io.File) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 4 with CoreStatus

use of org.apache.solr.client.solrj.request.CoreStatus in project lucene-solr by apache.

the class CollectionsAPISolrJTest method testCreateCollectionWithPropertyParam.

@Test
public void testCreateCollectionWithPropertyParam() throws Exception {
    String collectionName = "solrj_test_core_props";
    Path tmpDir = createTempDir("testPropertyParamsForCreate");
    Path dataDir = tmpDir.resolve("dataDir-" + TestUtil.randomSimpleString(random(), 1, 5));
    Path ulogDir = tmpDir.resolve("ulogDir-" + TestUtil.randomSimpleString(random(), 1, 5));
    CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1).withProperty(CoreAdminParams.DATA_DIR, dataDir.toString()).withProperty(CoreAdminParams.ULOG_DIR, ulogDir.toString()).process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    assertTrue(response.isSuccess());
    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
    assertEquals(1, coresStatus.size());
    DocCollection testCollection = getCollectionState(collectionName);
    Replica replica1 = testCollection.getReplica("core_node1");
    CoreStatus coreStatus = getCoreStatus(replica1);
    assertEquals(Paths.get(coreStatus.getDataDirectory()).toString(), dataDir.toString());
}
Also used : Path(java.nio.file.Path) CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) NamedList(org.apache.solr.common.util.NamedList) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 5 with CoreStatus

use of org.apache.solr.client.solrj.request.CoreStatus in project lucene-solr by apache.

the class CollectionsAPIDistributedZkTest method collectStartTimes.

private void collectStartTimes(String collectionName, Map<String, Long> urlToTime) throws SolrServerException, IOException {
    DocCollection collectionState = getCollectionState(collectionName);
    if (collectionState != null) {
        for (Slice shard : collectionState) {
            for (Replica replica : shard) {
                ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica);
                CoreStatus coreStatus;
                try (HttpSolrClient server = getHttpSolrClient(coreProps.getBaseUrl())) {
                    coreStatus = CoreAdminRequest.getCoreStatus(coreProps.getCoreName(), false, server);
                }
                long before = coreStatus.getCoreStartTime().getTime();
                urlToTime.put(coreProps.getCoreUrl(), before);
            }
        }
    } else {
        throw new IllegalArgumentException("Could not find collection " + collectionName);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica)

Aggregations

CoreStatus (org.apache.solr.client.solrj.request.CoreStatus)6 Replica (org.apache.solr.common.cloud.Replica)5 Test (org.junit.Test)5 Path (java.nio.file.Path)3 DocCollection (org.apache.solr.common.cloud.DocCollection)3 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)2 SolrException (org.apache.solr.common.SolrException)2 Slice (org.apache.solr.common.cloud.Slice)2 File (java.io.File)1 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)1 CoreAdminRequest (org.apache.solr.client.solrj.request.CoreAdminRequest)1 CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)1 NamedList (org.apache.solr.common.util.NamedList)1