Search in sources :

Example 1 with Create

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

the class BasicDistributedZkTest method createCores.

protected void createCores(final HttpSolrClient client, ThreadPoolExecutor executor, final String collection, final int numShards, int cnt) {
    for (int i = 0; i < cnt; i++) {
        final int freezeI = i;
        executor.execute(() -> {
            Create createCmd = new Create();
            createCmd.setCoreName(collection + freezeI);
            createCmd.setCollection(collection);
            createCmd.setNumShards(numShards);
            try {
                String core3dataDir = createTempDir(collection).toFile().getAbsolutePath();
                createCmd.setDataDir(getDataDir(core3dataDir));
                client.request(createCmd);
            } catch (SolrServerException | IOException e) {
                throw new RuntimeException(e);
            }
        });
    }
}
Also used : Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 2 with Create

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

the class CollectionsAPIDistributedZkTest method testNoCollectionSpecified.

@Test
public void testNoCollectionSpecified() throws Exception {
    // TODO - should we remove this behaviour?
    assertFalse(cluster.getSolrClient().getZkStateReader().getClusterState().hasCollection("corewithnocollection"));
    assertFalse(cluster.getSolrClient().getZkStateReader().getClusterState().hasCollection("corewithnocollection2"));
    // try and create a SolrCore with no collection name
    Create createCmd = new Create();
    createCmd.setCoreName("corewithnocollection");
    createCmd.setCollection("");
    String dataDir = createTempDir().toFile().getAbsolutePath();
    createCmd.setDataDir(dataDir);
    createCmd.setNumShards(1);
    createCmd.setCollectionConfigName("conf");
    cluster.getSolrClient().request(createCmd);
    // try and create a SolrCore with no collection name
    createCmd.setCollection(null);
    createCmd.setCoreName("corewithnocollection2");
    cluster.getSolrClient().request(createCmd);
    // in both cases, the collection should have default to the core name
    cluster.getSolrClient().getZkStateReader().forceUpdateCollection("corewithnocollection");
    cluster.getSolrClient().getZkStateReader().forceUpdateCollection("corewithnocollection2");
    assertTrue(cluster.getSolrClient().getZkStateReader().getClusterState().hasCollection("corewithnocollection"));
    assertTrue(cluster.getSolrClient().getZkStateReader().getClusterState().hasCollection("corewithnocollection2"));
}
Also used : Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) Test(org.junit.Test)

Example 3 with Create

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

the class BasicDistributedZk2Test method testNodeWithoutCollectionForwarding.

private void testNodeWithoutCollectionForwarding() throws Exception {
    final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
    try (HttpSolrClient client = getHttpSolrClient(baseUrl)) {
        client.setConnectionTimeout(30000);
        Create createCmd = new Create();
        createCmd.setRoles("none");
        createCmd.setCoreName(ONE_NODE_COLLECTION + "core");
        createCmd.setCollection(ONE_NODE_COLLECTION);
        createCmd.setNumShards(1);
        createCmd.setDataDir(getDataDir(createTempDir(ONE_NODE_COLLECTION).toFile().getAbsolutePath()));
        client.request(createCmd);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    waitForCollection(cloudClient.getZkStateReader(), ONE_NODE_COLLECTION, 1);
    waitForRecoveriesToFinish(ONE_NODE_COLLECTION, cloudClient.getZkStateReader(), false);
    cloudClient.getZkStateReader().getLeaderRetry(ONE_NODE_COLLECTION, SHARD1, 30000);
    int docs = 2;
    for (SolrClient client : clients) {
        final String clientUrl = getBaseUrl((HttpSolrClient) client);
        addAndQueryDocs(clientUrl, docs);
        docs += 2;
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Create(org.apache.solr.client.solrj.request.CoreAdminRequest.Create) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException)

Example 4 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 5 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)

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