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