List of usage examples for org.apache.solr.common.cloud ZkStateReader getZkClient
public SolrZkClient getZkClient()
From source file:org.apache.beam.sdk.io.solr.SolrIOTest.java
License:Apache License
@BeforeClass public static void beforeClass() throws Exception { // setup credential for solr user, // See https://cwiki.apache.org/confluence/display/solr/Basic+Authentication+Plugin String password = "SolrRocks"; // salt's size can be arbitrary byte[] salt = new byte[random().nextInt(30) + 1]; random().nextBytes(salt);/*ww w . j a va2s . co m*/ String base64Salt = BaseEncoding.base64().encode(salt); String sha56 = Sha256AuthenticationProvider.sha256(password, base64Salt); String credential = sha56 + " " + base64Salt; String securityJson = "{" + "'authentication':{" + " 'blockUnknown': true," + " 'class':'solr.BasicAuthPlugin'," + " 'credentials':{'solr':'" + credential + "'}}" + "}"; configureCluster(3).addConfig("conf", getFile("cloud-minimal/conf").toPath()).configure(); ZkStateReader zkStateReader = cluster.getSolrClient().getZkStateReader(); zkStateReader.getZkClient().setData("/security.json", securityJson.getBytes(Charset.defaultCharset()), true); String zkAddress = cluster.getZkServer().getZkAddress(); connectionConfiguration = SolrIO.ConnectionConfiguration.create(zkAddress).withBasicCredentials("solr", password); solrClient = connectionConfiguration.createClient(); SolrIOTestUtils.createCollection(SOLR_COLLECTION, NUM_SHARDS, 1, solrClient); }
From source file:org.apache.jackrabbit.oak.plugins.index.solr.server.RemoteSolrServerProvider.java
License:Apache License
private void createCollectionIfNeeded(CloudSolrServer cloudSolrServer) throws SolrServerException { String solrCollection = remoteSolrServerConfiguration.getSolrCollection(); try {//from www . ja v a 2 s .c o m ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader(); SolrZkClient zkClient = zkStateReader.getZkClient(); if (zkClient.isConnected() && !zkClient.exists("/configs/" + solrCollection, false)) { String solrConfDir = remoteSolrServerConfiguration.getSolrConfDir(); File dir; if (solrConfDir != null && solrConfDir.length() > 0) { dir = new File(solrConfDir); } else { dir = new File(getClass().getResource("/solr/oak/conf").getFile()); } ZkController.uploadConfigDir(zkClient, dir, solrCollection); UpdateRequest req = new UpdateRequest("/admin/collections"); req.setParam("action", "CREATE"); req.setParam("numShards", String.valueOf(remoteSolrServerConfiguration.getSolrShardsNo())); req.setParam("replicationFactor", String.valueOf(remoteSolrServerConfiguration.getSolrReplicationFactor())); req.setParam("collection.configName", solrCollection); req.setParam("name", solrCollection); cloudSolrServer.request(req); } } catch (Exception e) { log.warn("could not create collection {}", solrCollection); throw new SolrServerException(e); } }
From source file:org.opencommercesearch.CloudSearchServer.java
License:Apache License
/** * Get the underlying zookeeper client.// w ww. j ava 2 s . c o m * @param locale The locale of the wanted ZK client. * @return Usable zookeeper client. */ public SolrZkClient getZkClient(Locale locale) { if (zkClient == null) { ZkStateReader stateReader = getCatalogSolrServer(locale).getZkStateReader(); if (stateReader == null) { try { getCatalogSolrServer(locale).ping(); } catch (IOException ex) { if (isLoggingDebug()) { logDebug(ex); } } catch (SolrServerException ex) { if (isLoggingDebug()) { logDebug(ex); } } stateReader = getCatalogSolrServer(locale).getZkStateReader(); } if (stateReader != null) { zkClient = stateReader.getZkClient(); } } if (zkClient == null && isLoggingWarning()) { logWarning("Unable to get Solr ZooKeeper Client"); } return zkClient; }