Search in sources :

Example 6 with Create

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);
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException)

Example 7 with Create

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));
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) Callable(java.util.concurrent.Callable) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException)

Example 8 with Create

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));
}
Also used : Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) Test(org.junit.Test)

Example 9 with Create

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"));
}
Also used : Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) Slice(org.apache.solr.common.cloud.Slice) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Test(org.junit.Test)

Example 10 with Create

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"));
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Test(org.junit.Test)

Aggregations

Create (org.apache.solr.client.solrj.request.CoreAdminRequest.Create)12 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)7 SolrClient (org.apache.solr.client.solrj.SolrClient)5 SolrException (org.apache.solr.common.SolrException)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 Callable (java.util.concurrent.Callable)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 Unload (org.apache.solr.client.solrj.request.CoreAdminRequest.Unload)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 CollectionAdminResponse (org.apache.solr.client.solrj.response.CollectionAdminResponse)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 Slice (org.apache.solr.common.cloud.Slice)1 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)1 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1