protected static SolrClient getSolrClient() { String zkHostString = "127.0.0.1:9983"; // zkHostString for Solr gettingstarted example return new CloudSolrClient(zkHostString); }
/** * Initialize any state for this DB. Called once per DB instance; there is one DB instance per * client thread. */ @Override public void init() throws DBException { Properties props = getProperties(); commitTime = Integer .parseInt(props.getProperty("solr.commit.within.time", DEFAULT_COMMIT_WITHIN_TIME)); batchMode = Boolean.parseBoolean(props.getProperty("solr.batch.mode", DEFAULT_BATCH_MODE)); String jaasConfPath = props.getProperty("solr.jaas.conf.path"); if(jaasConfPath != null) { System.setProperty("java.security.auth.login.config", jaasConfPath); HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } // Check if Solr cluster is running in SolrCloud or Stand-alone mode Boolean cloudMode = Boolean.parseBoolean(props.getProperty("solr.cloud", DEFAULT_CLOUD_MODE)); System.err.println("Solr Cloud Mode = " + cloudMode); if (cloudMode) { System.err.println("Solr Zookeeper Remote Hosts = " + props.getProperty("solr.zookeeper.hosts", DEFAULT_ZOOKEEPER_HOSTS)); client = new CloudSolrClient( props.getProperty("solr.zookeeper.hosts", DEFAULT_ZOOKEEPER_HOSTS)); } else { client = new HttpSolrClient(props.getProperty("solr.base.url", DEFAULT_SOLR_BASE_URL)); } }
@Override public void prepare(Map<String, Object> topoConf, TopologyContext context, OutputCollector collector) { this.collector = collector; if (solrConfig.isKerberosEnabled()) { HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } solrMapper.configure(); this.solrClient = new CloudSolrClient(solrConfig.getZkHostString()); this.toCommitTuples = new ArrayList<>(capacity()); }
protected void prepare() { if (solrConfig.isKerberosEnabled()) { HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); } solrMapper.configure(); solrClient = new CloudSolrClient(solrConfig.getZkHostString()); }
public SolrIndex(final Configuration config) throws BackendException { Preconditions.checkArgument(config!=null); configuration = config; mode = Mode.parse(config.get(SOLR_MODE)); dynFields = config.get(DYNAMIC_FIELDS); keyFieldIds = parseKeyFieldsForCollections(config); maxResults = config.get(INDEX_MAX_RESULT_SET_SIZE); ttlField = config.get(TTL_FIELD); waitSearcher = config.get(WAIT_SEARCHER); if (mode==Mode.CLOUD) { String zookeeperUrl = config.get(SolrIndex.ZOOKEEPER_URL); CloudSolrClient cloudServer = new CloudSolrClient(zookeeperUrl, true); cloudServer.connect(); solrClient = cloudServer; } else if (mode==Mode.HTTP) { HttpClient clientParams = HttpClientUtil.createClient(new ModifiableSolrParams() {{ add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, config.get(HTTP_MAX_CONNECTIONS_PER_HOST).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS, config.get(HTTP_GLOBAL_MAX_CONNECTIONS).toString()); }}); solrClient = new LBHttpSolrClient(clientParams, config.get(HTTP_URLS)); } else { throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode); } }
@Override public void buildSchema() throws IOException { SolrClient solrClient = null; try { solrClient = new CloudSolrClient(solrConfig.getZkHostString()); SchemaRequest schemaRequest = new SchemaRequest(); logger.debug("Downloading schema for collection: {}", collection); SchemaResponse schemaResponse = schemaRequest.process(solrClient, collection); logger.debug("SchemaResponse Schema: {}", schemaResponse); SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation(); schema.setName(schemaRepresentation.getName()); schema.setVersion(Float.toString(schemaRepresentation.getVersion())); schema.setUniqueKey(schemaRepresentation.getUniqueKey()); schema.setFieldTypes(getFieldTypes(schemaRepresentation)); schema.setFields(getFields(schemaRepresentation.getFields())); schema.setDynamicFields(getFields(schemaRepresentation.getDynamicFields())); schema.setCopyFields(getCopyFields(schemaRepresentation)); } catch (SolrServerException e) { logger.error("Error while getting schema for collection: {}", collection, e); throw new IOException("Error while getting schema for collection :" + collection, e); } finally { if (solrClient != null) { solrClient.close(); } } }
final Integer zkConnectionTimeout = context.getProperty(ZK_CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue(); CloudSolrClient cloudSolrClient = new CloudSolrClient(solrLocation, httpClient); cloudSolrClient.setDefaultCollection(collection); cloudSolrClient.setZkClientTimeout(zkClientTimeout);
public CloudSolrClient getClient() { return new CloudSolrClient(zkHostString); }
@Override public SolrClient create(String spec) { return new CloudSolrClient(spec.substring("cloud:".length())); } }
@Override public SolrClient create(String spec) { return new CloudSolrClient(spec.substring("cloud:".length())); } }
private SolrClient getSolrclient(String core) { SolrClient solrClient; if (isCloud) { solrClient = new CloudSolrClient(zkHosts); } else { solrClient = new HttpSolrClient("http://" + solrHosts + "/solr"); } return solrClient; }
public synchronized CloudSolrClient getCloudSolrClient(String zkHost) { CloudSolrClient client = null; if (solrClients.containsKey(zkHost)) { client = (CloudSolrClient) solrClients.get(zkHost); } else { client = new CloudSolrClient(zkHost); client.connect(); solrClients.put(zkHost, client); } return client; }
@Override public void init(Configuration c) throws WriterException { String serverName = c.get("solr.cloud.address"); if (serverName == null) { throw new WriterException("Solr server address is not defined."); } String collection = c.get("solr.collection", "logs"); if(client == null) { client = new CloudSolrClient(serverName); client.setDefaultCollection(collection); } }
private SolrClient getCloudSolrClient() { LOG.debug("Creating CloudSolrClient using ZooKeeper: '{}'", solrZKHost); CloudSolrClient client = new CloudSolrClient(solrZKHost); client.setParser(new XMLResponseParser()); return client; }
@SuppressWarnings("rawtypes") @Override // FIXME: to be handled better public void init(NamedList args) { super.init(args); final String zkAddress = System.getProperty("zkHost"); if (isNotNullOrEmptyString(zkAddress)) { this.server= new CloudSolrClient(zkAddress); this.server.setDefaultCollection("store"); } }
AuthorizedSolrClient<CloudSolrClient> createClient() { CloudSolrClient solrClient = new CloudSolrClient(getZkHost(), createHttpClient()); return new AuthorizedSolrClient<>(solrClient, this); }
protected void prepare() { if (solrConfig.isKerberosEnabled()) HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); solrClient = new CloudSolrClient(solrConfig.getZkHostString()); }
@Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { this.collector = collector; if (solrConfig.isKerberosEnabled()) HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); this.solrClient = new CloudSolrClient(solrConfig.getZkHostString()); this.toCommitTuples = new ArrayList<>(capacity()); }
final CloudSolrClient server = new CloudSolrClient("localhost:2181"); try { //probably this is the line that missed from your code... server.connect(); final ClusterState clusterState = server.getZkStateReader().getClusterState(); final DocCollection collection = clusterState.getCollection("collection1"); //EVRIKA! collection object // and get the leader of the collection...pretty easy. Replica leader = clusterState.getLeader("collection1", "shard1"); } catch (Exception e) { // do your stuff } finally { server.close(); }
private boolean canCreateCollections(String host) throws Exception { UpdateRequest req = new UpdateRequest("/admin/collections"); req.setParam("action", "CREATE"); String solrCollection = "solr_" + System.nanoTime(); req.setParam("name", solrCollection); req.setParam("numShards", "2"); req.setParam("replicationFactor", "2"); req.setParam("collection.configName", "myconf"); CloudSolrClient cloudSolrServer = new CloudSolrClient(host); cloudSolrServer.setZkConnectTimeout(1000); NamedList<Object> request = cloudSolrServer.request(req); return request != null && request.get("success") != null; }