List of usage examples for org.apache.solr.client.solrj.embedded JettySolrRunner isRunning
public boolean isRunning()
From source file:org.apache.camel.component.solr.SolrCloudFixture.java
License:Apache License
public SolrCloudFixture(String solrHome) throws Exception { miniCluster = new MiniSolrCloudCluster(1, "/solr", new File(solrHome, "solr-no-core.xml"), null, null); String zkAddr = miniCluster.getZkServer().getZkAddress(); String zkHost = miniCluster.getZkServer().getZkHost(); buildZooKeeper(zkHost, zkAddr, new File(solrHome), "solrconfig.xml", "schema.xml"); List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners(); for (JettySolrRunner jetty : jettys) { if (!jetty.isRunning()) { log.warn("JETTY NOT RUNNING!"); } else {/*from w w w. j a va 2 s.c o m*/ log.info("JETTY RUNNING AT " + jetty.getBaseUrl() + " PORT " + jetty.getLocalPort()); } } solrClient = new CloudSolrServer(zkAddr, true); solrClient.connect(); createCollection(solrClient, "collection1", 1, 1, "conf1"); Thread.sleep(1000); // takes some time to setup the collection... // otherwise you'll get no live solr servers solrClient.setDefaultCollection("collection1"); SolrInputDocument doc = new SolrInputDocument(); doc.setField("id", "1"); solrClient.add(doc); solrClient.commit(); }
From source file:org.apache.coheigea.bigdata.solr.ranger.RangerSolrCloudTest.java
License:Apache License
@BeforeClass public static void setUp() throws Exception { JettyConfig.Builder jettyConfig = JettyConfig.builder(); jettyConfig.waitForLoadingCoresToFinish(null); String solrConfig = new String(Files.readAllBytes(Paths.get("target/test-classes/solrcloud/solr.xml")), Charset.defaultCharset()); tempDir = Files.createTempDirectory("solrcloud"); server = new MiniSolrCloudCluster(2, tempDir, solrConfig, jettyConfig.build()); // Insert the RangerSolrAuthorizer + BasicAuthPlugin try (ZkStateReader zkStateReader = new ZkStateReader(server.getZkServer().getZkAddress(), 10000, 10000)) { zkStateReader.getZkClient().delete(ZkStateReader.SOLR_SECURITY_CONF_PATH, 0, true); String securityJson = new String(Files.readAllBytes(Paths.get("src/test/resources/security.json")), Charset.defaultCharset()); zkStateReader.getZkClient().create(ZkStateReader.SOLR_SECURITY_CONF_PATH, securityJson.getBytes(Charset.defaultCharset()), CreateMode.PERSISTENT, true); }//from w w w . j a v a 2 s . c o m String configName = "core1Config"; File configDir = Paths.get("target/test-classes/solrcloud").toFile(); server.uploadConfigDir(configDir, configName); Map<String, String> collectionProperties = new HashMap<>(); collectionProperties.put("config", "solrconfig.xml"); collectionProperties.put("schema", "schema.xml"); server.createCollection("docs", 1, 1, configName, collectionProperties); JettySolrRunner startedServer = server.startJettySolrRunner(); assertTrue(startedServer.isRunning()); }
From source file:org.apache.coheigea.bigdata.solr.SolrCloudTest.java
License:Apache License
@BeforeClass public static void setUp() throws Exception { JettyConfig.Builder jettyConfig = JettyConfig.builder(); jettyConfig.waitForLoadingCoresToFinish(null); String solrConfig = new String(Files.readAllBytes(Paths.get("target/test-classes/solrcloud/solr.xml")), Charset.defaultCharset()); tempDir = Files.createTempDirectory("solrcloud"); server = new MiniSolrCloudCluster(2, tempDir, solrConfig, jettyConfig.build()); String configName = "core1Config"; File configDir = Paths.get("target/test-classes/solrcloud").toFile(); server.uploadConfigDir(configDir, configName); Map<String, String> collectionProperties = new HashMap<>(); collectionProperties.put("config", "solrconfig.xml"); collectionProperties.put("schema", "schema.xml"); server.createCollection("docs", 1, 1, configName, collectionProperties); JettySolrRunner startedServer = server.startJettySolrRunner(); assertTrue(startedServer.isRunning()); }
From source file:org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider.java
License:Apache License
private SolrServer createSolrServer() throws Exception { log.info("creating new embedded solr server with config: {}", solrServerConfiguration); String solrHomePath = solrServerConfiguration.getSolrHomePath(); String coreName = solrServerConfiguration.getCoreName(); EmbeddedSolrServerConfiguration.HttpConfiguration httpConfiguration = solrServerConfiguration .getHttpConfiguration();//from w w w.j a v a2s.c o m if (solrHomePath != null && coreName != null) { checkSolrConfiguration(solrHomePath, coreName); if (httpConfiguration != null) { if (log.isInfoEnabled()) { log.info("starting embedded Solr server with http bindings"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(JettySolrRunner.class.getClassLoader()); Integer httpPort = httpConfiguration.getHttpPort(); String context = httpConfiguration.getContext(); JettySolrRunner jettySolrRunner = null; try { jettySolrRunner = new JettySolrRunner(solrHomePath, context, httpPort, "solrconfig.xml", "schema.xml", true); if (log.isInfoEnabled()) { log.info("Jetty runner instantiated"); } jettySolrRunner.start(true); if (log.isInfoEnabled()) { log.info("Jetty runner started"); } } catch (Exception t) { if (log.isErrorEnabled()) { log.error("an error has occurred while starting Solr Jetty", t); } } finally { if (jettySolrRunner != null && !jettySolrRunner.isRunning()) { try { jettySolrRunner.stop(); if (log.isInfoEnabled()) { log.info("Jetty runner stopped"); } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("error while stopping the Jetty runner", e); } } } Thread.currentThread().setContextClassLoader(classLoader); } if (log.isInfoEnabled()) { log.info("starting HTTP Solr server"); } return new HttpWithJettySolrServer( SolrServerConfigurationDefaults.LOCAL_BASE_URL + ':' + httpPort + context + '/' + coreName, jettySolrRunner); } else { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(CoreContainer.class.getClassLoader()); CoreContainer coreContainer = new CoreContainer(solrHomePath); try { if (!coreContainer.isLoaded(coreName)) { coreContainer.load(); } } catch (Exception e) { log.error("cannot load core {}, shutting down embedded Solr..", coreName, e); try { coreContainer.shutdown(); } catch (Exception se) { log.error("could not shutdown embedded Solr", se); } return null; } finally { Thread.currentThread().setContextClassLoader(classLoader); } EmbeddedSolrServer server = new EmbeddedSolrServer(coreContainer, coreName); if (server.ping().getStatus() == 0) { return server; } else { throw new IOException("the embedded Solr server is not alive"); } } } else { throw new Exception("SolrServer configuration proprties not set"); } }