org.apache.solr.client.solrj.request.CoreAdminRequest Java Examples
The following examples show how to use
org.apache.solr.client.solrj.request.CoreAdminRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceSolrClient.java From ranger with Apache License 2.0 | 6 votes |
public List<String> getCoresList(List<String> ignoreCollectionList) throws Exception { CoreAdminRequest request = new CoreAdminRequest(); request.setAction(CoreAdminAction.STATUS); String decPassword = getDecryptedPassword(); if (username != null && decPassword != null) { request.setBasicAuthCredentials(username, decPassword); } CoreAdminResponse cores = request.process(solrClient); // List of the cores List<String> coreList = new ArrayList<String>(); for (int i = 0; i < cores.getCoreStatus().size(); i++) { if (ignoreCollectionList == null || !ignoreCollectionList.contains(cores.getCoreStatus() .getName(i))) { coreList.add(cores.getCoreStatus().getName(i)); } } return coreList; }
Example #2
Source File: CollectionsAPISolrJTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testCloudInfoInCoreStatus() throws IOException, SolrServerException { String collectionName = "corestatus_test"; CollectionAdminResponse response = CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2) .process(cluster.getSolrClient()); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); cluster.waitForActiveCollection(collectionName, 2, 4); String nodeName = (String) response._get("success[0]/key", null); String corename = (String) response._get(asList("success", nodeName, "core"), null); try (HttpSolrClient coreclient = getHttpSolrClient(cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeName))) { CoreAdminResponse status = CoreAdminRequest.getStatus(corename, coreclient); assertEquals(collectionName, status._get(asList("status", corename, "cloud", "collection"), null)); assertNotNull(status._get(asList("status", corename, "cloud", "shard"), null)); assertNotNull(status._get(asList("status", corename, "cloud", "replica"), null)); } }
Example #3
Source File: SolrStandaloneScraper.java From lucene-solr with Apache License 2.0 | 6 votes |
private Set<String> getCores() throws IOException { Set<String> cores = new HashSet<>(); CoreAdminRequest coreAdminRequest = new CoreAdminRequest(); coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS); coreAdminRequest.setIndexInfoNeeded(false); NamedList<Object> coreAdminResponse; try { coreAdminResponse = solrClient.request(coreAdminRequest); } catch (SolrServerException e) { throw new IOException("Failed to get cores", e); } JsonNode statusJsonNode = OBJECT_MAPPER.readTree((String) coreAdminResponse.get("response")).get("status"); for (JsonNode jsonNode : statusJsonNode) { cores.add(jsonNode.get("name").textValue()); } return cores; }
Example #4
Source File: CollectionsAPIDistributedZkTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private void collectStartTimes(String collectionName, Map<String,Long> urlToTime) throws SolrServerException, IOException { DocCollection collectionState = getCollectionState(collectionName); if (collectionState != null) { for (Slice shard : collectionState) { for (Replica replica : shard) { ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica); CoreStatus coreStatus; try (HttpSolrClient server = getHttpSolrClient(coreProps.getBaseUrl())) { coreStatus = CoreAdminRequest.getCoreStatus(coreProps.getCoreName(), false, server); } long before = coreStatus.getCoreStartTime().getTime(); urlToTime.put(coreProps.getCoreUrl(), before); } } } else { throw new IllegalArgumentException("Could not find collection " + collectionName); } }
Example #5
Source File: TestEmbeddedSolrServerConstructors.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testNodeConfigConstructor() throws Exception { Path path = createTempDir(); NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", path) .setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString()) .build(); try (EmbeddedSolrServer server = new EmbeddedSolrServer(config, "newcore")) { CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create(); createRequest.setCoreName("newcore"); createRequest.setConfigSet("minimal"); server.request(createRequest); SolrInputDocument doc = new SolrInputDocument(); doc.addField("articleid", "test"); server.add("newcore", doc); server.commit(); assertEquals(1, server.query(new SolrQuery("*:*")).getResults().getNumFound()); assertEquals(1, server.query("newcore", new SolrQuery("*:*")).getResults().getNumFound()); } }
Example #6
Source File: MergeIndexesExampleTestBase.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testMergeIndexesByDirName() throws Exception { UpdateRequest up = setupCores(); // Now get the index directory of core1 and merge with core0 CoreAdminRequest.mergeIndexes("core0", new String[] {getIndexDirCore1()}, new String[0], getSolrAdmin()); // Now commit the merged index up.clear(); // just do commit up.process(getSolrCore0()); assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size()); assertEquals(1, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size()); }
Example #7
Source File: SolrOperationsService.java From Decision with Apache License 2.0 | 5 votes |
public List<String> getCoreList() throws IOException, SolrServerException { SolrClient solrClient = getSolrclient(null); CoreAdminRequest coreAdminRequest = new CoreAdminRequest(); coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS); CoreAdminResponse cores = coreAdminRequest.process(solrClient); List<String> coreList = new ArrayList<String>(); for (int i = 0; i < cores.getCoreStatus().size(); i++) { coreList.add(cores.getCoreStatus().getName(i)); } return coreList; }
Example #8
Source File: DistributedVersionInfoTest.java From lucene-solr with Apache License 2.0 | 5 votes |
protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception { ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica); String coreName = coreProps.getCoreName(); boolean reloadedOk = false; try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); Thread.sleep(1000); // send reload command for the collection log.info("Sending RELOAD command for {}", testCollectionName); CollectionAdminRequest.reloadCollection(testCollectionName) .process(client); Thread.sleep(2000); // reload can take a short while // verify reload is done, waiting up to 30 seconds for slow test environments long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS); while (System.nanoTime() < timeout) { statusResp = CoreAdminRequest.getStatus(coreName, client); long startTimeAfterReload = statusResp.getStartTime(coreName).getTime(); if (startTimeAfterReload > leaderCoreStartTime) { reloadedOk = true; break; } // else ... still waiting to see the reloaded core report a later start time Thread.sleep(1000); } } return reloadedOk; }
Example #9
Source File: ReplaceNodeNoTargetTest.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Given a cloud client and a nodename, build an HTTP client for that node, and ask it for it's core status */ private CoreAdminResponse getCoreStatusForNamedNode(final CloudSolrClient cloudClient, final String nodeName) throws Exception { try (HttpSolrClient coreclient = getHttpSolrClient (cloudClient.getZkStateReader().getBaseUrlForNodeName(nodeName))) { return CoreAdminRequest.getStatus(null, coreclient); } }
Example #10
Source File: TestJettySolrRunner.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testPassSolrHomeToRunner() throws Exception { // We set a non-standard coreRootDirectory, create a core, and check that it has been // built in the correct place Path solrHome = createTempDir(); Path coresDir = createTempDir("crazy_path_to_cores"); Path configsets = Paths.get(TEST_HOME()).resolve("configsets"); String solrxml = "<solr><str name=\"configSetBaseDir\">CONFIGSETS</str><str name=\"coreRootDirectory\">COREROOT</str></solr>" .replace("CONFIGSETS", configsets.toString()) .replace("COREROOT", coresDir.toString()); Files.write(solrHome.resolve("solr.xml"), solrxml.getBytes(StandardCharsets.UTF_8)); JettyConfig jettyConfig = buildJettyConfig("/solr"); JettySolrRunner runner = new JettySolrRunner(solrHome.toString(), new Properties(), jettyConfig); try { runner.start(); try (SolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) { CoreAdminRequest.Create createReq = new CoreAdminRequest.Create(); createReq.setCoreName("newcore"); createReq.setConfigSet("minimal"); client.request(createReq); } assertTrue(Files.exists(coresDir.resolve("newcore").resolve("core.properties"))); } finally { runner.stop(); } }
Example #11
Source File: DistributedDebugComponentTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@BeforeClass public static void createThings() throws Exception { systemSetPropertySolrDisableShardsWhitelist("true"); solrHome = createSolrHome(); createAndStartJetty(solrHome.getAbsolutePath()); String url = jetty.getBaseUrl().toString(); collection1 = getHttpSolrClient(url + "/collection1"); collection2 = getHttpSolrClient(url + "/collection2"); String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1"; String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2"; shard1 = urlCollection1.replaceAll("https?://", ""); shard2 = urlCollection2.replaceAll("https?://", ""); //create second core try (HttpSolrClient nodeClient = getHttpSolrClient(url)) { CoreAdminRequest.Create req = new CoreAdminRequest.Create(); req.setCoreName("collection2"); req.setConfigSet("collection1"); nodeClient.request(req); } SolrInputDocument doc = new SolrInputDocument(); doc.setField("id", "1"); doc.setField("text", "batman"); collection1.add(doc); collection1.commit(); doc.setField("id", "2"); doc.setField("text", "superman"); collection2.add(doc); collection2.commit(); }
Example #12
Source File: AbstractFullDistribZkTestBase.java From lucene-solr with Apache License 2.0 | 5 votes |
protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception { ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica); String coreName = coreProps.getCoreName(); boolean reloadedOk = false; try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) { CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client); long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime(); Thread.sleep(1000); // send reload command for the collection log.info("Sending RELOAD command for {}", testCollectionName); ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", CollectionParams.CollectionAction.RELOAD.toString()); params.set("name", testCollectionName); QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); client.request(request); Thread.sleep(2000); // reload can take a short while // verify reload is done, waiting up to 30 seconds for slow test environments long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS); while (System.nanoTime() < timeout) { statusResp = CoreAdminRequest.getStatus(coreName, client); long startTimeAfterReload = statusResp.getStartTime(coreName).getTime(); if (startTimeAfterReload > leaderCoreStartTime) { reloadedOk = true; break; } // else ... still waiting to see the reloaded core report a later start time Thread.sleep(1000); } } return reloadedOk; }
Example #13
Source File: SolrCloudTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Get the {@link CoreStatus} data for a {@link Replica} * <p> * This assumes that the replica is hosted on a live node. */ protected static CoreStatus getCoreStatus(Replica replica) throws IOException, SolrServerException { JettySolrRunner jetty = cluster.getReplicaJetty(replica); try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString(), cluster.getSolrClient().getHttpClient())) { return CoreAdminRequest.getCoreStatus(replica.getCoreName(), client); } }
Example #14
Source File: MergeIndexesExampleTestBase.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testMergeMultipleRequest() throws Exception { CoreAdminRequest.MergeIndexes req = new CoreAdminRequest.MergeIndexes(); req.setCoreName("core0"); req.setIndexDirs(Arrays.asList("/path/1", "/path/2")); req.setSrcCores(Arrays.asList("core1", "core2")); SolrParams params = req.getParams(); assertEquals(2, params.getParams(CoreAdminParams.SRC_CORE).length); assertEquals(2, params.getParams(CoreAdminParams.INDEX_DIR).length); }
Example #15
Source File: MergeIndexesExampleTestBase.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testMergeIndexesByCoreName() throws Exception { UpdateRequest up = setupCores(); CoreAdminRequest.mergeIndexes("core0", new String[0], new String[] {"core1"}, getSolrAdmin()); // Now commit the merged index up.clear(); // just do commit up.process(getSolrCore0()); assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size()); assertEquals(1, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size()); }
Example #16
Source File: CoreAdminHandlerTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testDeleteInstanceDirAfterCreateFailure() throws Exception { assumeFalse("Ignore test on windows because it does not delete data directory immediately after unload", Constants.WINDOWS); File solrHomeDirectory = createTempDir("solr-home").toFile(); copySolrHomeToTemp(solrHomeDirectory, "corex"); File corex = new File(solrHomeDirectory, "corex"); FileUtils.write(new File(corex, "core.properties"), "", StandardCharsets.UTF_8); JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr")); runner.start(); try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex", DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT)) { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "123"); client.add(doc); client.commit(); } Path dataDir = null; try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString())) { CoreStatus status = CoreAdminRequest.getCoreStatus("corex", true, client); String dataDirectory = status.getDataDirectory(); dataDir = Paths.get(dataDirectory); assertTrue(Files.exists(dataDir)); } File subHome = new File(solrHomeDirectory, "corex" + File.separator + "conf"); String top = SolrTestCaseJ4.TEST_HOME() + "/collection1/conf"; FileUtils.copyFile(new File(top, "bad-error-solrconfig.xml"), new File(subHome, "solrconfig.xml")); try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString(), DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT)) { // this is expected because we put a bad solrconfig -- ignore expectThrows(Exception.class, () -> CoreAdminRequest.reloadCore("corex", client)); CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false); req.setDeleteDataDir(true); req.setDeleteInstanceDir(false); // important because the data directory is inside the instance directory req.setCoreName("corex"); req.process(client); } runner.stop(); assertTrue("The data directory was not cleaned up on unload after a failed core reload", Files.notExists(dataDir)); }
Example #17
Source File: DeleteInactiveReplicaTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void deleteInactiveReplicaTest() throws Exception { String collectionName = "delDeadColl"; int replicationFactor = 2; int numShards = 2; int maxShardsPerNode = ((((numShards + 1) * replicationFactor) / cluster.getJettySolrRunners().size())) + 1; CollectionAdminRequest.createCollection(collectionName, "conf", numShards, replicationFactor) .setMaxShardsPerNode(maxShardsPerNode) .process(cluster.getSolrClient()); waitForState("Expected a cluster of 2 shards and 2 replicas", collectionName, (n, c) -> { return DocCollection.isFullyActive(n, c, numShards, replicationFactor); }); DocCollection collectionState = getCollectionState(collectionName); Slice shard = getRandomShard(collectionState); Replica replica = getRandomReplica(shard); JettySolrRunner jetty = cluster.getReplicaJetty(replica); CoreDescriptor replicaCd; try (SolrCore core = jetty.getCoreContainer().getCore(replica.getCoreName())) { replicaCd = core.getCoreDescriptor(); } cluster.stopJettySolrRunner(jetty); waitForState("Expected replica " + replica.getName() + " on down node to be removed from cluster state", collectionName, (n, c) -> { Replica r = c.getReplica(replica.getCoreName()); return r == null || r.getState() != Replica.State.ACTIVE; }); if (log.isInfoEnabled()) { log.info("Removing replica {}/{} ", shard.getName(), replica.getName()); } CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()) .process(cluster.getSolrClient()); waitForState("Expected deleted replica " + replica.getName() + " to be removed from cluster state", collectionName, (n, c) -> { return c.getReplica(replica.getCoreName()) == null; }); cluster.startJettySolrRunner(jetty); log.info("restarted jetty"); TimeOut timeOut = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME); timeOut.waitFor("Expected data dir and instance dir of " + replica.getName() + " is deleted", () -> !Files.exists(replicaCd.getInstanceDir()) && !FileUtils.fileExists(replicaCd.getDataDir())); // Check that we can't create a core with no coreNodeName try (SolrClient queryClient = getHttpSolrClient(jetty.getBaseUrl().toString())) { Exception e = expectThrows(Exception.class, () -> { CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create(); createRequest.setCoreName("testcore"); createRequest.setCollection(collectionName); createRequest.setShardId("shard2"); queryClient.request(createRequest); }); assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().contains("coreNodeName missing")); } }
Example #18
Source File: CoreAdminHandlerTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testUnloadForever() throws Exception { File solrHomeDirectory = createTempDir("solr-home").toFile(); copySolrHomeToTemp(solrHomeDirectory, "corex"); File corex = new File(solrHomeDirectory, "corex"); FileUtils.write(new File(corex, "core.properties"), "", StandardCharsets.UTF_8); JettySolrRunner runner = new JettySolrRunner(solrHomeDirectory.getAbsolutePath(), buildJettyConfig("/solr")); runner.start(); try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex", DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT)) { SolrInputDocument doc = new SolrInputDocument(); doc.addField("id", "123"); client.add(doc); client.commit(); } try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex", DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT)) { QueryResponse result = client.query(new SolrQuery("id:*")); assertEquals(1,result.getResults().getNumFound()); } try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl().toString(), DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT)) { CoreAdminRequest.Unload req = new CoreAdminRequest.Unload(false); req.setDeleteInstanceDir(false);//random().nextBoolean()); req.setCoreName("corex"); req.process(client); } BaseHttpSolrClient.RemoteSolrException rse = expectThrows(BaseHttpSolrClient.RemoteSolrException.class, () -> { try (HttpSolrClient client = getHttpSolrClient(runner.getBaseUrl() + "/corex", DEFAULT_CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT * 1000)) { client.query(new SolrQuery("id:*")); } finally { runner.stop(); } }); assertEquals("Should have received a 404 error", 404, rse.code()); }
Example #19
Source File: CollectionsAPIDistributedZkTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void addReplicaTest() throws Exception { String collectionName = "addReplicaColl"; CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2) .setMaxShardsPerNode(4) .process(cluster.getSolrClient()); cluster.waitForActiveCollection(collectionName, 2, 4); ArrayList<String> nodeList = new ArrayList<>(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes()); Collections.shuffle(nodeList, random()); CollectionAdminResponse response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1") .setNode(nodeList.get(0)) .process(cluster.getSolrClient()); Replica newReplica = grabNewReplica(response, getCollectionState(collectionName)); assertEquals("Replica should be created on the right node", cluster.getSolrClient().getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)), newReplica.getStr(ZkStateReader.BASE_URL_PROP)); Path instancePath = createTempDir(); response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1") .withProperty(CoreAdminParams.INSTANCE_DIR, instancePath.toString()) .process(cluster.getSolrClient()); newReplica = grabNewReplica(response, getCollectionState(collectionName)); assertNotNull(newReplica); try (HttpSolrClient coreclient = getHttpSolrClient(newReplica.getStr(ZkStateReader.BASE_URL_PROP))) { CoreAdminResponse status = CoreAdminRequest.getStatus(newReplica.getStr("core"), coreclient); NamedList<Object> coreStatus = status.getCoreStatus(newReplica.getStr("core")); String instanceDirStr = (String) coreStatus.get("instanceDir"); assertEquals(instanceDirStr, instancePath.toString()); } //Test to make sure we can't create another replica with an existing core_name of that collection String coreName = newReplica.getStr(CORE_NAME_PROP); SolrException e = expectThrows(SolrException.class, () -> { ModifiableSolrParams params = new ModifiableSolrParams(); params.set("action", "addreplica"); params.set("collection", collectionName); params.set("shard", "shard1"); params.set("name", coreName); QueryRequest request = new QueryRequest(params); request.setPath("/admin/collections"); cluster.getSolrClient().request(request); }); assertTrue(e.getMessage().contains("Another replica with the same core name already exists for this collection")); // Check that specifying property.name works. DO NOT remove this when the "name" property is deprecated // for ADDREPLICA, this is "property.name". See SOLR-7132 response = CollectionAdminRequest.addReplicaToShard(collectionName, "shard1") .withProperty(CoreAdminParams.NAME, "propertyDotName") .process(cluster.getSolrClient()); newReplica = grabNewReplica(response, getCollectionState(collectionName)); assertEquals("'core' should be 'propertyDotName' ", "propertyDotName", newReplica.getStr("core")); }
Example #20
Source File: TestMiniSolrCloudClusterSSL.java From lucene-solr with Apache License 2.0 | 4 votes |
/** Sanity check that our test scaffolding for validating SSL peer names fails when it should */ public void testSslWithInvalidPeerName() throws Exception { // NOTE: first initialize the cluster w/o peer name checks, which means our server will use // certs with a bogus hostname/ip and clients shouldn't care... final SSLTestConfig sslConfig = new SSLTestConfig(true, false, false); HttpClientUtil.setSocketFactoryRegistryProvider(sslConfig.buildClientSocketFactoryRegistryProvider()); Http2SolrClient.setDefaultSSLConfig(sslConfig.buildClientSSLConfig()); System.setProperty(ZkStateReader.URL_SCHEME, "https"); final JettyConfig config = JettyConfig.builder().withSSLConfig(sslConfig.buildServerSSLConfig()).build(); final MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(NUM_SERVERS, createTempDir(), config); try { checkClusterWithCollectionCreations(cluster, sslConfig); // now initialize a client that still uses the existing SSLContext/Provider, so it will accept // our existing certificate, but *does* care about validating the peer name System.setProperty(HttpClientUtil.SYS_PROP_CHECK_PEER_NAME, "true"); HttpClientUtil.resetHttpClientBuilder(); Http2SolrClient.resetSslContextFactory(); // and validate we get failures when trying to talk to our cluster... final List<JettySolrRunner> jettys = cluster.getJettySolrRunners(); for (JettySolrRunner jetty : jettys) { final String baseURL = jetty.getBaseUrl().toString(); // verify new solr clients validate peer name and can't talk to this server Exception ex = expectThrows(SolrServerException.class, () -> { try (HttpSolrClient client = getRandomizedHttpSolrClient(baseURL)) { CoreAdminRequest req = new CoreAdminRequest(); req.setAction( CoreAdminAction.STATUS ); client.request(req); } }); assertTrue("Expected an root cause SSL Exception, got: " + ex.toString(), ex.getCause() instanceof SSLException); } } finally { cluster.shutdown(); } }
Example #21
Source File: TestMiniSolrCloudClusterSSL.java From lucene-solr with Apache License 2.0 | 4 votes |
/** * verify that we can query all of the Jetty instances the specified cluster using the expected * options (based on the sslConfig), and that we can <b>NOT</b> query the Jetty instances in * specified cluster in the ways that should fail (based on the sslConfig) * * @see #getRandomizedHttpSolrClient */ private static void checkClusterJettys(final MiniSolrCloudCluster cluster, final SSLTestConfig sslConfig) throws Exception { final boolean ssl = sslConfig.isSSLMode(); List<JettySolrRunner> jettys = cluster.getJettySolrRunners(); for (JettySolrRunner jetty : jettys) { final String baseURL = jetty.getBaseUrl().toString(); // basic base URL sanity checks assertTrue("WTF baseURL: " + baseURL, null != baseURL && 10 < baseURL.length()); assertEquals("http vs https: " + baseURL, ssl ? "https" : "http:", baseURL.substring(0,5)); // verify solr client success with expected protocol try (HttpSolrClient client = getRandomizedHttpSolrClient(baseURL)) { assertEquals(0, CoreAdminRequest.getStatus(/* all */ null, client).getStatus()); } // sanity check the HttpClient used under the hood by our the cluster's CloudSolrClient // ensure it has the necessary protocols/credentials for each jetty server // // NOTE: we're not responsible for closing the cloud client final HttpClient cloudClient = cluster.getSolrClient().getLbClient().getHttpClient(); try (HttpSolrClient client = getRandomizedHttpSolrClient(baseURL)) { assertEquals(0, CoreAdminRequest.getStatus(/* all */ null, client).getStatus()); } final String wrongBaseURL = baseURL.replaceFirst((ssl ? "https://" : "http://"), (ssl ? "http://" : "https://")); // verify solr client using wrong protocol can't talk to server expectThrows(SolrServerException.class, () -> { try (HttpSolrClient client = getRandomizedHttpSolrClient(wrongBaseURL)) { CoreAdminRequest req = new CoreAdminRequest(); req.setAction( CoreAdminAction.STATUS ); client.request(req); } }); if (! sslConfig.isClientAuthMode()) { // verify simple HTTP(S) client can't do HEAD request for URL with wrong protocol try (CloseableHttpClient client = getSslAwareClientWithNoClientCerts()) { final String wrongUrl = wrongBaseURL + "/admin/cores"; // vastly diff exception details between plain http vs https, not worried about details here expectThrows(IOException.class, () -> { doHeadRequest(client, wrongUrl); }); } } if (ssl) { // verify expected results for a HEAD request to valid URL from HTTP(S) client w/o client certs try (CloseableHttpClient client = getSslAwareClientWithNoClientCerts()) { final String url = baseURL + "/admin/cores"; if (sslConfig.isClientAuthMode()) { // w/o a valid client cert, SSL connection should fail expectThrows(IOException.class, () -> { doHeadRequest(client, url); }); } else { assertEquals("Wrong status for head request ("+url+") when clientAuth=" + sslConfig.isClientAuthMode(), 200, doHeadRequest(client, url)); } } } } }
Example #22
Source File: LeaderElectionContextKeyTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void test() throws KeeperException, InterruptedException, IOException, SolrServerException { ZkStateReader stateReader = cluster.getSolrClient().getZkStateReader(); stateReader.forceUpdateCollection(TEST_COLLECTION_1); ClusterState clusterState = stateReader.getClusterState(); // The test assume that TEST_COLLECTION_1 and TEST_COLLECTION_2 will have identical layout // ( same replica's name on every shard ) for (int i = 1; i <= 2; i++) { String coll1ShardiLeader = clusterState.getCollection(TEST_COLLECTION_1).getLeader("shard"+i).getName(); String coll2ShardiLeader = clusterState.getCollection(TEST_COLLECTION_2).getLeader("shard"+i).getName(); String assertMss = String.format(Locale.ROOT, "Expect %s and %s each have a replica with same name on shard %s", coll1ShardiLeader, coll2ShardiLeader, "shard"+i); assertEquals( assertMss, coll1ShardiLeader, coll2ShardiLeader ); } String shard = "shard" + String.valueOf(random().nextInt(2) + 1); Replica replica = clusterState.getCollection(TEST_COLLECTION_1).getLeader(shard); assertNotNull(replica); try (SolrClient shardLeaderClient = new HttpSolrClient.Builder(replica.get("base_url").toString()).build()) { assertEquals(1L, getElectionNodes(TEST_COLLECTION_1, shard, stateReader.getZkClient()).size()); List<String> collection2Shard1Nodes = getElectionNodes(TEST_COLLECTION_2, "shard1", stateReader.getZkClient()); List<String> collection2Shard2Nodes = getElectionNodes(TEST_COLLECTION_2, "shard2", stateReader.getZkClient()); CoreAdminRequest.unloadCore(replica.getCoreName(), shardLeaderClient); // Waiting for leader election being kicked off long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(60, TimeUnit.SECONDS); boolean found = false; while (System.nanoTime() < timeout) { try { found = getElectionNodes(TEST_COLLECTION_1, shard, stateReader.getZkClient()).size() == 0; break; } catch (KeeperException.NoNodeException nne) { // ignore } } assertTrue(found); // There are no leader election was kicked off on testCollection2 assertThat(collection2Shard1Nodes, CoreMatchers.is(getElectionNodes(TEST_COLLECTION_2, "shard1", stateReader.getZkClient()))); assertThat(collection2Shard2Nodes, CoreMatchers.is(getElectionNodes(TEST_COLLECTION_2, "shard2", stateReader.getZkClient()))); } }
Example #23
Source File: AuthorizedSolrClient.java From beam with Apache License 2.0 | 4 votes |
CoreAdminResponse process(CoreAdminRequest request) throws IOException, SolrServerException { return process(null, request); }
Example #24
Source File: TestSolrProperties.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testProperties() throws Exception { UpdateRequest up = new UpdateRequest(); up.setAction(ACTION.COMMIT, true, true); up.deleteByQuery("*:*"); up.process(getSolrCore0()); up.process(getSolrCore1()); up.clear(); // Add something to each core SolrInputDocument doc = new SolrInputDocument(); doc.setField("id", "AAA"); doc.setField("core0", "yup stopfra stopfrb stopena stopenb"); // Add to core0 up.add(doc); up.process(getSolrCore0()); SolrTestCaseJ4.ignoreException("unknown field"); // You can't add it to core1 expectThrows(Exception.class, () -> up.process(getSolrCore1())); // Add to core1 doc.setField("id", "BBB"); doc.setField("core1", "yup stopfra stopfrb stopena stopenb"); doc.removeField("core0"); up.add(doc); up.process(getSolrCore1()); // You can't add it to core1 SolrTestCaseJ4.ignoreException("core0"); expectThrows(Exception.class, () -> up.process(getSolrCore0())); SolrTestCaseJ4.resetExceptionIgnores(); // now Make sure AAA is in 0 and BBB in 1 SolrQuery q = new SolrQuery(); QueryRequest r = new QueryRequest(q); q.setQuery("id:AAA"); assertEquals(1, r.process(getSolrCore0()).getResults().size()); assertEquals(0, r.process(getSolrCore1()).getResults().size()); // Now test Changing the default core assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size()); assertEquals(0, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size()); assertEquals(0, getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size()); assertEquals(1, getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size()); // Now test reloading it should have a newer open time String name = "core0"; SolrClient coreadmin = getSolrAdmin(); CoreAdminResponse mcr = CoreAdminRequest.getStatus(name, coreadmin); long before = mcr.getStartTime(name).getTime(); CoreAdminRequest.reloadCore(name, coreadmin); mcr = CoreAdminRequest.getStatus(name, coreadmin); long after = mcr.getStartTime(name).getTime(); assertTrue("should have more recent time: " + after + "," + before, after > before); }