use of org.apache.solr.client.solrj.request.CoreAdminRequest.Create in project lucene-solr by apache.
the class BasicDistributedZkTest method createNewCollection.
private void createNewCollection(final String collection) throws InterruptedException {
final List<SolrClient> collectionClients = new ArrayList<>();
otherCollectionClients.put(collection, collectionClients);
int unique = 0;
for (final SolrClient client : clients) {
unique++;
final String baseUrl = ((HttpSolrClient) client).getBaseURL().substring(0, ((HttpSolrClient) client).getBaseURL().length() - DEFAULT_COLLECTION.length() - 1);
final int frozeUnique = unique;
Callable call = () -> {
try (HttpSolrClient client1 = getHttpSolrClient(baseUrl)) {
client1.setConnectionTimeout(15000);
client1.setSoTimeout(60000);
Create createCmd = new Create();
createCmd.setCoreName(collection);
createCmd.setDataDir(getDataDir(createTempDir(collection).toFile().getAbsolutePath()));
client1.request(createCmd);
} catch (Exception e) {
e.printStackTrace();
//fails
}
return null;
};
collectionClients.add(createNewSolrClient(collection, baseUrl));
pending.add(completionService.submit(call));
while (pending != null && pending.size() > 0) {
Future<Object> future = completionService.take();
if (future == null)
return;
pending.remove(future);
}
}
}
use of org.apache.solr.client.solrj.request.CoreAdminRequest.Create in project lucene-solr by apache.
the class BasicDistributedZkTest method createSolrCore.
private void createSolrCore(final String collection, List<SolrClient> collectionClients, final String baseUrl, final int num, final String shardId) {
Callable call = () -> {
try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
// client.setConnectionTimeout(15000);
Create createCmd = new Create();
createCmd.setRoles("none");
createCmd.setCoreName(collection + num);
createCmd.setCollection(collection);
if (random().nextBoolean()) {
// sometimes we use an explicit core node name
createCmd.setCoreNodeName("anode" + nodeCounter.incrementAndGet());
}
if (shardId == null) {
createCmd.setNumShards(2);
}
createCmd.setDataDir(getDataDir(createTempDir(collection).toFile().getAbsolutePath()));
if (shardId != null) {
createCmd.setShardId(shardId);
}
client.request(createCmd);
} catch (Exception e) {
e.printStackTrace();
//fail
}
return null;
};
pending.add(completionService.submit(call));
collectionClients.add(createNewSolrClient(collection + num, baseUrl));
}
use of org.apache.solr.client.solrj.request.CoreAdminRequest.Create in project lucene-solr by apache.
the class CollectionsAPIDistributedZkTest method deletePartiallyCreatedCollection.
@Test
public void deletePartiallyCreatedCollection() throws Exception {
final String collectionName = "halfdeletedcollection";
// create a core that simulates something left over from a partially-deleted collection
Create createCmd = new Create();
createCmd.setCoreName("halfdeletedcollection_shard1_replica1");
createCmd.setCollection(collectionName);
createCmd.setCollectionConfigName("conf");
String dataDir = createTempDir().toFile().getAbsolutePath();
createCmd.setDataDir(dataDir);
createCmd.setNumShards(2);
createCmd.process(cluster.getSolrClient());
CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
assertFalse(CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
CollectionAdminRequest.createCollection(collectionName, "conf", 2, 1).process(cluster.getSolrClient());
assertTrue(CollectionAdminRequest.listCollections(cluster.getSolrClient()).contains(collectionName));
}
use of org.apache.solr.client.solrj.request.CoreAdminRequest.Create in project lucene-solr by apache.
the class CollectionsAPIDistributedZkTest method testNoConfigSetExist.
@Test
public void testNoConfigSetExist() throws Exception {
final CloudSolrClient cloudClient = cluster.getSolrClient();
assertFalse(cloudClient.getZkStateReader().getClusterState().hasCollection("corewithnocollection3"));
// try and create a SolrCore with no collection name
Create createCmd = new Create();
createCmd.setCoreName("corewithnocollection3");
createCmd.setCollection("");
String dataDir = createTempDir().toFile().getAbsolutePath();
createCmd.setDataDir(dataDir);
createCmd.setNumShards(1);
createCmd.setCollectionConfigName("conf123");
expectThrows(Exception.class, () -> {
cluster.getSolrClient().request(createCmd);
});
TimeUnit.MILLISECONDS.sleep(1000);
// in both cases, the collection should have default to the core name
cloudClient.getZkStateReader().forceUpdateCollection("corewithnocollection3");
Collection<Slice> slices = cloudClient.getZkStateReader().getClusterState().getActiveSlices("corewithnocollection3");
int replicaCount = 0;
if (slices != null) {
for (Slice slice : slices) {
replicaCount += slice.getReplicas().size();
}
}
assertEquals("replicaCount", 0, replicaCount);
// TODO - WTF? shouldn't this *not* contain the collection?
assertTrue(CollectionAdminRequest.listCollections(cloudClient).contains("corewithnocollection3"));
}
use of org.apache.solr.client.solrj.request.CoreAdminRequest.Create in project lucene-solr by apache.
the class CollectionsAPIDistributedZkTest method testCreateShouldFailOnExistingCore.
@Test
public void testCreateShouldFailOnExistingCore() throws Exception {
// first we make a core with the core name the collections api
// will try and use - this will cause our mock fail
Create createCmd = new Create();
createCmd.setCoreName(Assign.buildCoreName("halfcollection", "shard1", Replica.Type.NRT, 1));
createCmd.setCollection("halfcollectionblocker");
String dataDir = createTempDir().toFile().getAbsolutePath();
createCmd.setDataDir(dataDir);
createCmd.setNumShards(1);
createCmd.setCollectionConfigName("conf");
try (SolrClient client = cluster.getJettySolrRunner(0).newClient()) {
client.request(createCmd);
}
createCmd = new Create();
createCmd.setCoreName(Assign.buildCoreName("halfcollection", "shard1", Replica.Type.NRT, 1));
createCmd.setCollection("halfcollectionblocker2");
dataDir = createTempDir().toFile().getAbsolutePath();
createCmd.setDataDir(dataDir);
createCmd.setNumShards(1);
createCmd.setCollectionConfigName("conf");
try (SolrClient client = cluster.getJettySolrRunner(1).newClient()) {
client.request(createCmd);
}
String nn1 = cluster.getJettySolrRunner(0).getNodeName();
String nn2 = cluster.getJettySolrRunner(1).getNodeName();
CollectionAdminResponse resp = CollectionAdminRequest.createCollection("halfcollection", "conf", 2, 1).setCreateNodeSet(nn1 + "," + nn2).process(cluster.getSolrClient());
SimpleOrderedMap success = (SimpleOrderedMap) resp.getResponse().get("success");
SimpleOrderedMap failure = (SimpleOrderedMap) resp.getResponse().get("failure");
assertNotNull(resp.toString(), success);
assertNotNull(resp.toString(), failure);
String val1 = success.getVal(0).toString();
String val2 = failure.getVal(0).toString();
assertTrue(val1.contains("SolrException") || val2.contains("SolrException"));
}
Aggregations