当前位置: 首页>>代码示例>>Java>>正文


Java CloudSolrClient.connect方法代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.impl.CloudSolrClient.connect方法的典型用法代码示例。如果您正苦于以下问题:Java CloudSolrClient.connect方法的具体用法?Java CloudSolrClient.connect怎么用?Java CloudSolrClient.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.client.solrj.impl.CloudSolrClient的用法示例。


在下文中一共展示了CloudSolrClient.connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startCluster

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
@BeforeClass
public static void startCluster() throws Exception {
  File solrXml = new File("src/test/resources/solr.xml");

  tempDir = Files.createTempDirectory("MiniSolrCloudCluster");

  try {
    cluster = new MiniSolrCloudCluster(1, null, tempDir, MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML, null, null);
  } catch (Exception exc) {
    log.error("Failed to initialize a MiniSolrCloudCluster due to: " + exc, exc);
    throw exc;
  }

  cloudSolrClient = new CloudSolrClient(cluster.getZkServer().getZkAddress(), true);
  cloudSolrClient.connect();

  assertTrue(!cloudSolrClient.getZkStateReader().getClusterState().getLiveNodes().isEmpty());
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:19,代码来源:TestSolrCloudClusterSupport.java

示例2: SolrCloudFixture

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
public SolrCloudFixture(String solrHome) throws Exception {
    String xml = IOHelper.loadText(new FileInputStream(new File(solrHome, "solr-no-core.xml")));
    miniCluster = new MiniSolrCloudCluster(1, "/solr", new File("target/tmp").toPath(), 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 {
            log.info("JETTY RUNNING AT " + jetty.getBaseUrl() + " PORT " + jetty.getLocalPort());
        }
    }

    solrClient = new CloudSolrClient(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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:SolrCloudFixture.java

示例3: FakeRetrySolrServer

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
public FakeRetrySolrServer(String zkString, boolean alwaysFail, int retries) {
  CloudSolrClient client  = new CloudSolrClient(zkString);
  client.setDefaultCollection(DEFAULT_COLLECTION);
  client.connect();
  this.delegate = client;
  this.alwaysFail = alwaysFail;
  this.retries = retries;
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:9,代码来源:LucidWorksWriterTest.java

示例4: getCloudSolrClient

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
public static CloudSolrClient getCloudSolrClient(String url) throws MalformedURLException {
  CloudSolrClient sc = new CloudSolrClient(url.replace('|', ','));
  sc.setParallelUpdates(true);
  sc.connect();
  return sc;
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:7,代码来源:SolrUtils.java

示例5: getSplits

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
@Override
public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
  this.conf = job;
  boolean isZk = false;
  String connectionUri = job.get(SOLR_ZKHOST);
  String collection = job.get(SOLR_COLLECTION);
  List<String> shards = null;

  if (collection == null) {
    throw new IOException(SOLR_COLLECTION + " not provided or is empty");
  }

  if (connectionUri != null && connectionUri != "") {
    isZk = true;
    CloudSolrClient solrCloud = null;
    try {
      solrCloud = new CloudSolrClient.Builder()
          .withZkHost(connectionUri)
          .build();
      solrCloud.setDefaultCollection(collection);
      solrCloud.connect();
      // first get a list of replicas to query for this collection
      shards = buildShardList(solrCloud, collection);
    } catch (Exception ex) {
      log.warn("Error getting the Shard: " + ex.getMessage());
    } finally {
      if (solrCloud != null) {
        solrCloud.close();
      }
    }

  } else {
    connectionUri = job.get(SOLR_SERVER_URL);
  }

  if (connectionUri == null || connectionUri == "") {
    throw new IOException(SOLR_ZKHOST + " nor " + SOLR_SERVER_URL + " provided or is empty");
  }

  InputSplit[] splits = null;
  if (shards != null) {
    //Create more splits.
    splits = new InputSplit[shards.size()];
    for (int i = 0; i < shards.size(); i++) {
      splits[i] = new LWInputSplit(isZk, true, shards.get(i));
    }
  } else {
    splits = new InputSplit[] { new LWInputSplit(isZk, false, connectionUri) };
  }

  return splits;
}
 
开发者ID:lucidworks,项目名称:solr-hadoop-common,代码行数:53,代码来源:LWMapRedInputFormat.java

示例6: getShardList

import org.apache.solr.client.solrj.impl.CloudSolrClient; //导入方法依赖的package包/类
/**
 * Returns the list of shards of the default collection.
 *
 * @param zkHost            ZooKeeper URL
 * @param chronixCollection Solr collection name for chronix time series data
 * @return the list of shards of the default collection
 */
public List<String> getShardList(String zkHost, String chronixCollection) throws IOException {

    CloudSolrClient cloudSolrClient = new CloudSolrClient(zkHost);
    List<String> shards = new ArrayList<>();

    try {
        cloudSolrClient.connect();

        ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();

        ClusterState clusterState = zkStateReader.getClusterState();

        String[] collections;
        if (clusterState.hasCollection(chronixCollection)) {
            collections = new String[]{chronixCollection};
        } else {
            // might be a collection alias?
            Aliases aliases = zkStateReader.getAliases();
            String aliasedCollections = aliases.getCollectionAlias(chronixCollection);
            if (aliasedCollections == null)
                throw new IllegalArgumentException("Collection " + chronixCollection + " not found!");
            collections = aliasedCollections.split(",");
        }

        Set<String> liveNodes = clusterState.getLiveNodes();
        Random random = new Random(5150);

        for (String coll : collections) {
            for (Slice slice : clusterState.getSlices(coll)) {
                List<String> replicas = new ArrayList<>();
                for (Replica r : slice.getReplicas()) {
                    if (r.getState().equals(Replica.State.ACTIVE)) {
                        ZkCoreNodeProps replicaCoreProps = new ZkCoreNodeProps(r);
                        if (liveNodes.contains(replicaCoreProps.getNodeName()))
                            replicas.add(replicaCoreProps.getCoreUrl());
                    }
                }
                int numReplicas = replicas.size();
                if (numReplicas == 0)
                    throw new IllegalStateException("Shard " + slice.getName() + " in collection " +
                            coll + " does not have any active replicas!");

                String replicaUrl = (numReplicas == 1) ? replicas.get(0) : replicas.get(random.nextInt(replicas.size()));
                shards.add(replicaUrl);
            }
        }
    } finally {
        cloudSolrClient.close();
    }

    return shards;
}
 
开发者ID:ChronixDB,项目名称:chronix.spark,代码行数:60,代码来源:ChronixSolrCloudStorage.java


注:本文中的org.apache.solr.client.solrj.impl.CloudSolrClient.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。