List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer getCoreContainer
public CoreContainer getCoreContainer()
From source file:com.indoqa.solr.server.factory.SolrServerFactory.java
License:Apache License
private void destroyEmbeddedSolrServer() { this.logger.info("Shutting down embedded Solr server with url: " + this.url); this.solrServer.shutdown(); if (this.solrServer instanceof EmbeddedSolrServer) { EmbeddedSolrServer embeddedSolrServer = (EmbeddedSolrServer) this.solrServer; embeddedSolrServer.getCoreContainer().shutdown(); }//from www. jav a 2 s . c om this.solrServer = null; }
From source file:com.indoqa.solr.spring.client.SolrClientFactory.java
License:Apache License
private void destroyEmbeddedSolrServer() throws IOException { this.logger.info("Shutting down embedded Solr server with url: " + this.url); this.solrClient.close(); if (this.solrClient instanceof EmbeddedSolrServer) { EmbeddedSolrServer embeddedSolrServer = (EmbeddedSolrServer) this.solrClient; embeddedSolrServer.getCoreContainer().shutdown(); }/* ww w. j a va2 s . co m*/ this.solrClient = null; }
From source file:fr.gael.dhus.service.SystemService.java
License:Open Source License
/** * Performs Solr restoration./*w w w .j a v a 2s. 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(); } }
From source file:jp.co.tis.gsp.tools.dba.dialect.SolrDialect.java
License:Apache License
@Override public void exportSchema(String user, String password, String schema, File dumpFile) throws MojoExecutionException { String solrUrl = url.substring("jdbc:solr:".length()); try {/*from w w w . j a v a 2s . c o m*/ SolrConnection connection = ConnectionTypeDetector.getInstance().find(solrUrl); if (connection instanceof EmbeddedConnectionImpl) { System.err.println(solrUrl); EmbeddedSolrServer solrServer = (EmbeddedSolrServer) connection.getSolrServer(); SolrCore core = solrServer.getCoreContainer() .getCore(solrServer.getCoreContainer().getDefaultCoreName()); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(dumpFile.getAbsolutePath())); } } catch (Exception e) { throw new MojoExecutionException("Export error", e); } }
From source file:org.opencms.search.solr.CmsSolrIndex.java
License:Open Source License
/** * @see org.opencms.search.CmsSearchIndex#createIndexBackup() */// ww w . ja v a 2s .co m @Override protected String createIndexBackup() { if (!isBackupReindexing()) { // if no backup is generated we don't need to do anything return null; } if (m_solr instanceof EmbeddedSolrServer) { EmbeddedSolrServer ser = (EmbeddedSolrServer) m_solr; CoreContainer con = ser.getCoreContainer(); SolrCore core = con.getCore(getCoreName()); if (core != null) { try { SolrRequestHandler h = core.getRequestHandler("/replication"); if (h instanceof ReplicationHandler) { h.handleRequest( new LocalSolrQueryRequest(core, CmsRequestUtil.createParameterMap("?command=backup")), new SolrQueryResponse()); } } finally { core.close(); } } } return null; }
From source file:org.springframework.data.rest.webmvc.solr.SolrInfrastructureConfig.java
License:Apache License
/** * {@link SpringJUnit4ClassRunner} executes {@link ClassRule}s before the actual shutdown of the * {@link ApplicationContext}. This causes the {@link TemporaryFolder} to vanish before Solr can gracefully shutdown. * <br />/*ww w. j ava 2 s. c o m*/ * To prevent error messages popping up we register a {@link CloseHook} re adding the index directory and removing it * after {@link SolrCore#close()}. * * @param factory */ private void attachCloseHook(SolrClientFactory factory) { EmbeddedSolrServer server = (EmbeddedSolrServer) factory.getSolrClient(); for (SolrCore core : server.getCoreContainer().getCores()) { core.addCloseHook(new CloseHook() { private String path; @Override public void preClose(SolrCore core) { CoreDescriptor cd = core.getCoreDescriptor(); if (cd == null) { return; } File tmp = new File(core.getIndexDir()).getParentFile(); if (tmp.exists()) { return; } try { File indexFile = new File(tmp, "index"); indexFile.mkdirs(); this.path = indexFile.getPath(); } catch (Exception e) { e.printStackTrace(); } } @Override public void postClose(SolrCore core) { if (!StringUtils.hasText(this.path)) { return; } File tmp = new File(this.path); if (tmp.exists() && tmp.getPath().startsWith(FileUtils.getTempDirectoryPath())) { try { FileUtils.deleteDirectory(tmp); } catch (IOException e) { e.printStackTrace(); } } } }); } }
From source file:org.springframework.data.solr.server.support.SolrClientUtilTests.java
License:Apache License
/** * @see DATASOLR-203// ww w.j av a 2s . co m */ @Test public void cloningEmbeddedSolrServerShouldReuseCoreContainer() { CoreContainer coreContainer = Mockito.mock(CoreContainer.class); EmbeddedSolrServer solrServer = new EmbeddedSolrServer(coreContainer, "core1"); EmbeddedSolrServer clone = SolrClientUtils.clone(solrServer, "core1"); Assert.assertThat(clone.getCoreContainer(), IsSame.sameInstance(coreContainer)); }
From source file:org.springframework.data.solr.server.support.SolrServerUtilTests.java
License:Apache License
/** * @see DATASOLR-203/* w w w .j a v a 2 s . c o m*/ */ @Test public void cloningEmbeddedSolrServerShouldReuseCoreContainer() { CoreContainer coreContainer = Mockito.mock(CoreContainer.class); EmbeddedSolrServer solrServer = new EmbeddedSolrServer(coreContainer, null); EmbeddedSolrServer clone = SolrServerUtils.clone(solrServer, "core1"); Assert.assertThat(clone.getCoreContainer(), IsSame.sameInstance(coreContainer)); }