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())));
}
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));
}
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));
}
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());
}
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);
}
}
Aggregations