Example usage for org.apache.solr.client.solrj.embedded EmbeddedSolrServer close

List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer close

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.embedded EmbeddedSolrServer close.

Prototype

@Override
public void close() throws IOException 

Source Link

Document

Shutdown all cores within the EmbeddedSolrServer instance

Usage

From source file:com.ngdata.hbaseindexer.mr.TestUtils.java

License:Apache License

public static void validateSolrServerDocumentCount(File solrHomeDir, FileSystem fs, Path outDir,
        int expectedDocs, int expectedShards) throws IOException, SolrServerException {

    long actualDocs = 0;
    int actualShards = 0;
    for (FileStatus dir : fs.listStatus(outDir)) { // for each shard
        if (dir.getPath().getName().startsWith("part") && dir.isDirectory()) {
            actualShards++;/*from w w w .  j  av  a 2s.c o m*/
            EmbeddedSolrServer solr = createEmbeddedSolrServer(solrHomeDir, fs, dir.getPath());

            try {
                SolrQuery query = new SolrQuery();
                query.setQuery("*:*");
                QueryResponse resp = solr.query(query);
                long numDocs = resp.getResults().getNumFound();
                actualDocs += numDocs;
            } finally {
                solr.close();
            }
        }
    }
    assertEquals(expectedShards, actualShards);
    assertEquals(expectedDocs, actualDocs);
}

From source file:fr.gael.dhus.service.SystemService.java

License:Open Source License

/**
 * Performs Solr restoration./*w w w .  j  a v  a2 s.  c  o m*/
 *
 * @param properties properties containing arguments to execute the restoration.
 */
private static void restoreSolr5Index(Properties properties) throws IOException, SolrServerException {
    String solrHome = properties.getProperty("dhus.solr.home");
    String coreName = properties.getProperty("dhus.solr.core.name");
    final String name = properties.getProperty("dhus.solr.backup.name");
    final String location = properties.getProperty("dhus.solr.backup.location");

    if (solrHome == null || coreName == null || name == null || location == null) {
        throw new UnsupportedOperationException();
    }

    System.setProperty("solr.solr.home", solrHome);
    CoreContainer core = new CoreContainer(solrHome);
    EmbeddedSolrServer server = new EmbeddedSolrServer(core, coreName);
    try {
        server.getCoreContainer().load();

        SolrQuery query = new SolrQuery();
        query.setRequestHandler("/replication");
        query.set("command", "restore");
        query.set("name", name);
        query.set("location", location);

        server.query(query);
        LOGGER.info("SolR indexes restored.");
    } finally {
        server.close();
    }

}