Search in sources :

Example 46 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project RecordManager2 by moravianlibrary.

the class AbstractKrameriusTest method initSolrServerWithException.

protected void initSolrServerWithException() throws Exception {
    reset(solrServerFactory);
    expect(solrServerFactory.create(eq(SOLR_URL), eq(Mode.KRAMERIUS))).andReturn(mockedSolrServer).anyTimes();
    replay(solrServerFactory);
    reset(mockedSolrServer);
    Capture<SolrQuery> capturedQueryRequest = EasyMock.newCapture();
    SolrDocumentList documents = new SolrDocumentList();
    SolrDocument doc1 = new SolrDocument();
    doc1.addField("PID", "uuid:00931210-02b6-11e5-b939-0800200c9a66");
    SolrDocument doc2 = new SolrDocument();
    doc2.addField("PID", "uuid:0095bca0-614f-11e2-bcfd-0800200c9a66");
    documents.add(doc1);
    documents.add(doc2);
    NamedList<Object> solrResponse1 = new NamedList<Object>();
    solrResponse1.add("response", documents);
    // 1st response - SolrServerExceptions
    expect(mockedSolrServer.query(and(capture(capturedQueryRequest), anyObject(SolrQuery.class)))).andThrow(new SolrServerException("Bad status code: 500"));
    // 2nd response - SolrServerException
    expect(mockedSolrServer.query(and(capture(capturedQueryRequest), anyObject(SolrQuery.class)))).andThrow(new SolrServerException("Something bad happened to poor SOLR"));
    // 3rd response - OK
    expect(mockedSolrServer.query(and(capture(capturedQueryRequest), anyObject(SolrQuery.class)))).andReturn(new QueryResponse(solrResponse1, null));
    replay(mockedSolrServer);
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) NamedList(org.apache.solr.common.util.NamedList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) EasyMock.anyObject(org.easymock.EasyMock.anyObject) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 47 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project beijingThirdPeriod by weidongcao.

the class SimpleSorl method deleteByQuery.

public void deleteByQuery(String queryCon) {
    System.out.println("======================deleteByQuery ===================");
    UpdateResponse rsp;
    try {
        UpdateRequest commit = new UpdateRequest();
        commit.deleteByQuery(queryCon);
        commit.setCommitWithin(5000);
        commit.process(client);
        System.out.println("url:" + commit.getPath() + "\t xml:" + commit.getXML() + " method:" + commit.getMethod());
    // rsp = client.deleteByQuery(queryCon);
    // client.commit();
    // System.out.println("delete query:" + queryCon + " result:" + rsp.getStatus() + " Qtime:" + rsp.getQTime());
    } catch (SolrServerException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 48 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project beijingThirdPeriod by weidongcao.

the class SimpleSorl method deleteById.

public void deleteById(String id) {
    System.out.println("======================deleteById ===================");
    try {
        UpdateResponse rsp = client.deleteById(id);
        client.commit();
        System.out.println("delete id:" + id + " result:" + rsp.getStatus() + " Qtime:" + rsp.getQTime());
    } catch (SolrServerException | IOException e) {
        e.printStackTrace();
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 49 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project vind by RBMHTechnology.

the class CollectionManagementService method updateCollection.

/**
 * 1. Check if config set is already deployed on the solr server, if not: download from repo and upload to zK
 * 2. Switch configuration
 * 3. Check if dependencies (runtime-libs) are installed, if not download and install (and name it with group:artefact:version)
 * 4. Add/Update collection runtime-libs
 *
 * @param collectionName {@link String} name of the collection to update.
 * @param configName should be either the name of an already defined configuration in the solr cloud or the full
 *                   name of an artifact accessible in one of the default repositories.
 * @throws {@link IOException} is thrown when a problem with the solr request occurs.
 */
public void updateCollection(String collectionName, String configName) throws IOException {
    final String origConfigName;
    try {
        final CollectionAdminResponse status = new CollectionAdminRequest.ClusterStatus().setCollectionName(collectionName).process(client);
        if (status.getStatus() == 0) {
            origConfigName = (String) ((Map) ((SimpleOrderedMap) ((NamedList) status.getResponse().get("cluster")).get("collections")).get(collectionName)).get("configName");
        // origMaxShards = (String)((Map) ((SimpleOrderedMap) ((NamedList) status.getResponse().get("cluster")).get("collections")).get(collectionName)).get("maxShardsPerNode");
        // origReplicationFactor = (String)((Map) ((SimpleOrderedMap) ((NamedList) status.getResponse().get("cluster")).get("collections")).get(collectionName)).get("replicationFactor");
        } else {
            throw new IOException("Unable to get current status of collection [" + collectionName + "]");
        }
    } catch (SolrServerException e) {
        throw new IOException("Unable to get current status of collection [" + collectionName + "]", e);
    }
    // TODO get and remove current runtime libs: Is this really needed?
    // Update or install configuration
    this.checkAndInstallConfiguration(configName, true);
    if (!origConfigName.equals(configName)) {
        // Change config set of the collection to the new one
        try (final SolrZkClient zkClient = new SolrZkClient(zkHost, 4000)) {
            // TODO: The following call to the collections API is working from solr >= 6
            /*final SolrQuery modifyCollectionQuery = new SolrQuery();
                modifyCollectionQuery.setRequestHandler("/admin/collections");
                modifyCollectionQuery.set("action", "MODIFYCOLLECTION");
                modifyCollectionQuery.set("collection", collectionName);
                modifyCollectionQuery.set("collection.configName", configName);
                modifyCollectionQuery.set("rule", new String[0]);
                modifyCollectionQuery.set("snitch", new String[0]);
                modifyCollectionQuery.set("maxShardsPerNode", origMaxShards);
                modifyCollectionQuery.set("replicationFactor", origReplicationFactor);
                client.query(modifyCollectionQuery);

                or probably

                final CollectionAdminResponse modifyCollection = new CollectionAdminRequest.ModifyCollection()
                        .setCollectionName(collectionName)
                        create.setConfigName(configName);
                        create.setNumShards(numOfShards);
                        create.setReplicationFactor(numOfReplicas);
                        .process(client);
                */
            // Update link to config set
            ZkController.linkConfSet(zkClient, collectionName, configName);
            // Reload collection
            final CollectionAdminResponse reload = new CollectionAdminRequest.Reload().setCollectionName(collectionName).process(client);
            if (!reload.isSuccess()) {
                throw new IOException("Unable to reload collection [" + collectionName + "]");
            }
        } catch (SolrServerException e) {
            throw new IOException("Unable to update collection [" + collectionName + "]", e);
        } catch (KeeperException | InterruptedException e) {
            throw new IOException("Unable to update collection [" + collectionName + "]", e);
        }
    }
    final Map<String, Long> updatedRuntimeDependencies = checkAndInstallRuntimeDependencies(collectionName);
    this.addOrUpdateRuntimeDependencies(updatedRuntimeDependencies, collectionName);
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) KeeperException(org.apache.zookeeper.KeeperException)

Example 50 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project vind by RBMHTechnology.

the class CollectionManagementService method createCollection.

/**
 * 1. Check if config set is already deployed on the solr server, if not: download from repo and upload to zK
 * 2. Create collection
 * 3. Check if dependencies (runtime-libs) are installed, if not download and install (and name it with group:artefact:version)
 * 4. Add/Update collection runtime-libs
 *
 * @param collectionName {@link String} name of the collection to create.
 * @param configName should be either the name of an already defined configuration in the solr cloud or the full
 *                   name of an artifact accessible in one of the default repositories.
 * @param numOfShards integer number of shards
 * @param numOfReplicas integer number of replicas
 * @throws {@link IOException} thrown if is not possible to create the collection.
 */
public void createCollection(String collectionName, String configName, int numOfShards, int numOfReplicas) throws IOException {
    checkAndInstallConfiguration(configName);
    try {
        Create create = new CollectionAdminRequest.Create();
        create.setCollectionName(collectionName);
        create.setConfigName(configName);
        create.setNumShards(numOfShards);
        create.setReplicationFactor(numOfReplicas);
        create.process(client);
    } catch (IOException | SolrServerException e) {
        throw new IOException("Cannot create collection", e);
    }
    Map<String, Long> runtimeDependencies = checkAndInstallRuntimeDependencies(collectionName);
    addOrUpdateRuntimeDependencies(runtimeDependencies, collectionName);
}
Also used : Create(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Aggregations

SolrServerException (org.apache.solr.client.solrj.SolrServerException)281 IOException (java.io.IOException)210 SolrQuery (org.apache.solr.client.solrj.SolrQuery)101 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)97 ArrayList (java.util.ArrayList)58 SolrException (org.apache.solr.common.SolrException)57 SolrDocument (org.apache.solr.common.SolrDocument)55 SolrInputDocument (org.apache.solr.common.SolrInputDocument)50 SolrDocumentList (org.apache.solr.common.SolrDocumentList)44 HashMap (java.util.HashMap)30 Map (java.util.Map)29 List (java.util.List)27 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)26 SolrClient (org.apache.solr.client.solrj.SolrClient)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)23 NamedList (org.apache.solr.common.util.NamedList)22 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)19 Date (java.util.Date)18 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)17 SolrParams (org.apache.solr.common.params.SolrParams)13