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


Java SolrZkClient类代码示例

本文整理汇总了Java中org.apache.solr.common.cloud.SolrZkClient的典型用法代码示例。如果您正苦于以下问题:Java SolrZkClient类的具体用法?Java SolrZkClient怎么用?Java SolrZkClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SolrZkClient类属于org.apache.solr.common.cloud包,在下文中一共展示了SolrZkClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadConfig

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
/**
 * Upload config to ZK
 * 
 * @param log maven log
 * @throws MojoExecutionException exception
 */
public synchronized void uploadConfig(Log log) throws MojoExecutionException {
	try (SolrZkClient zkClient = new SolrZkClient(solrCloud.getZkServer().getZkAddress(chroot), TIMEOUT, TIMEOUT, null)) {
		ZkConfigManager manager = new ZkConfigManager(zkClient);
		if(manager.configExists(configName)) {
			throw new MojoExecutionException("Config " + configName + " already exists on ZK");
		}
		
		log.debug("about to upload config from " + confDir + " to " + configName);
		manager.uploadConfigDir(confDir, configName);
		log.debug("Config uploaded");
	}
	catch (IOException e) {
		throw new MojoExecutionException("Can't upload solr config in ZK " + configName, e);
	}
}
 
开发者ID:BorisNaguet,项目名称:solr-maven-plugin,代码行数:22,代码来源:SolrCloudManager.java

示例2: buildZooKeeper

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
public void buildZooKeeper(String zkHost, String zkAddress, File solrhome, String config, String schema)
    throws Exception {
    zkClient = new SolrZkClient(zkAddress, 60000);

    Map<String, Object> props = new HashMap<String, Object>();
    props.put("configName", "conf1");

    // for now, always upload the config and schema to the canonical names
    putConfig("conf1", zkClient, solrhome, config, "solrconfig.xml");
    putConfig("conf1", zkClient, solrhome, schema, "schema.xml");

    putConfig("conf1", zkClient, solrhome, "stopwords.txt");
    putConfig("conf1", zkClient, solrhome, "stopwords_en.txt");
    putConfig("conf1", zkClient, solrhome, "protwords.txt");
    putConfig("conf1", zkClient, solrhome, "currency.xml");
    putConfig("conf1", zkClient, solrhome, "enumsConfig.xml");
    putConfig("conf1", zkClient, solrhome, "open-exchange-rates.json");
    putConfig("conf1", zkClient, solrhome, "mapping-ISOLatin1Accent.txt");
    putConfig("conf1", zkClient, solrhome, "old_synonyms.txt");
    putConfig("conf1", zkClient, solrhome, "synonyms.txt");
    putConfig("conf1", zkClient, solrhome, "elevate.xml");
    zkClient.close();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:SolrCloudFixture.java

示例3: downloadConfigDir

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
/**
 * Download and return the config directory from ZK
 */
public File downloadConfigDir(SolrZkClient zkClient, String configName, File dir)
throws IOException, InterruptedException, KeeperException {
  Preconditions.checkArgument(dir.exists());
  Preconditions.checkArgument(dir.isDirectory());
  ZkController.downloadConfigDir(zkClient, configName, dir);
  File confDir = new File(dir, "conf");
  if (!confDir.isDirectory()) {
    // create a temporary directory with "conf" subdir and mv the config in there.  This is
    // necessary because of CDH-11188; solrctl does not generate nor accept directories with e.g.
    // conf/solrconfig.xml which is necessary for proper solr operation.  This should work
    // even if solrctl changes.
    confDir = new File(Files.createTempDir().getAbsolutePath(), "conf");
    confDir.getParentFile().deleteOnExit();
    Files.move(dir, confDir);
    dir = confDir.getParentFile();
  }
  verifyConfigDir(confDir);
  return dir;
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:ZooKeeperDownloader.java

示例4: downloadConfigDir

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
/**
 * Download and return the config directory from ZK
 */
public File downloadConfigDir(SolrZkClient zkClient, String configName)
throws IOException, InterruptedException, KeeperException {
  File dir = Files.createTempDir();
  dir.deleteOnExit();
  ZkController.downloadConfigDir(zkClient, configName, dir);
  File confDir = new File(dir, "conf");
  if (!confDir.isDirectory()) {
    // create a temporary directory with "conf" subdir and mv the config in there.  This is
    // necessary because of CDH-11188; solrctl does not generate nor accept directories with e.g.
    // conf/solrconfig.xml which is necessary for proper solr operation.  This should work
    // even if solrctl changes.
    confDir = new File(Files.createTempDir().getAbsolutePath(), "conf");
    confDir.getParentFile().deleteOnExit();
    Files.move(dir, confDir);
    dir = confDir.getParentFile();
  }
  FileUtils.writeStringToFile(new File(dir, "solr.xml"), "<solr><cores><core name=\"collection1\" instanceDir=\".\" /></cores></solr>", "UTF-8");
  verifyConfigDir(confDir);
  return dir;
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:ZooKeeperInspector.java

示例5: checkChrootPath

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
/**
 * Validates if the chroot exists in zk (or if it is successfully created).
 * Optionally, if create is set to true this method will create the path in
 * case it doesn't exist
 * 
 * @return true if the path exists or is created false if the path doesn't
 *         exist and 'create' = false
 */
public static boolean checkChrootPath(String zkHost, boolean create)
    throws KeeperException, InterruptedException {
  if (!containsChroot(zkHost)) {
    return true;
  }
  log.info("zkHost includes chroot");
  String chrootPath = zkHost.substring(zkHost.indexOf("/"), zkHost.length());
  SolrZkClient tmpClient = new SolrZkClient(zkHost.substring(0,
      zkHost.indexOf("/")), 60 * 1000);
  boolean exists = tmpClient.exists(chrootPath, true);
  if (!exists && create) {
    tmpClient.makePath(chrootPath, false, true);
    exists = true;
  }
  tmpClient.close();
  return exists;
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:ZkController.java

示例6: downloadFromZK

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
public static void downloadFromZK(SolrZkClient zkClient, String zkPath,
    File dir) throws IOException, KeeperException, InterruptedException {
  List<String> files = zkClient.getChildren(zkPath, null, true);
  
  for (String file : files) {
    List<String> children = zkClient.getChildren(zkPath + "/" + file, null, true);
    if (children.size() == 0) {
      byte[] data = zkClient.getData(zkPath + "/" + file, null, null, true);
      dir.mkdirs(); 
      log.info("Write file " + new File(dir, file));
      FileUtils.writeByteArrayToFile(new File(dir, file), data);
    } else {
      downloadFromZK(zkClient, zkPath + "/" + file, new File(dir, file));
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:ZkController.java

示例7: bootstrapConf

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
/**
 * If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
 */
public static void bootstrapConf(SolrZkClient zkClient, CoreContainer cc, String solrHome) throws IOException,
    KeeperException, InterruptedException {

  //List<String> allCoreNames = cfg.getAllCoreNames();
  List<CoreDescriptor> cds = cc.getCoresLocator().discover(cc);
  
  log.info("bootstrapping config for " + cds.size() + " cores into ZooKeeper using solr.xml from " + solrHome);

  for (CoreDescriptor cd : cds) {
    String coreName = cd.getName();
    String confName = cd.getCollectionName();
    if (StringUtils.isEmpty(confName))
      confName = coreName;
    String instanceDir = cd.getInstanceDir();
    File udir = new File(instanceDir, "conf");
    log.info("Uploading directory " + udir + " with name " + confName + " for SolrCore " + coreName);
    ZkController.uploadConfigDir(zkClient, udir, confName);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:ZkController.java

示例8: testZkBasedJsonStorage

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
/**
 * Runs persisted managed resource creation and update tests on Zookeeper storage.
 */
@Test
public void testZkBasedJsonStorage() throws Exception {
  
  // test using ZooKeeper
  assertTrue("Not using ZooKeeper", h.getCoreContainer().isZooKeeperAware());    
  SolrZkClient zkClient = h.getCoreContainer().getZkController().getZkClient();    
  SolrResourceLoader loader = new SolrResourceLoader("./");    
  // Solr unit tests can only write to their working directory due to
  // a custom Java Security Manager installed in the test environment
  NamedList<String> initArgs = new NamedList<>();
  try {
    ZooKeeperStorageIO zkStorageIO = new ZooKeeperStorageIO(zkClient, "/test");
    zkStorageIO.configure(loader, initArgs);
    doStorageTests(loader, zkStorageIO);
  } finally {
    zkClient.close();
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:TestManagedResourceStorage.java

示例9: setUp

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
  super.setUp();
  dataDir1 = createTempDir();
  dataDir2  = createTempDir();

  home = ExternalPaths.EXAMPLE_MULTICORE_HOME;
  System.setProperty("solr.solr.home", home);
  System.setProperty( "solr.core0.data.dir", dataDir1.getCanonicalPath() ); 
  System.setProperty( "solr.core1.data.dir", dataDir2.getCanonicalPath() ); 
  
  zkDir = dataDir1.getAbsolutePath() + File.separator
      + "zookeeper/server1/data";
  zkServer = new ZkTestServer(zkDir);
  zkServer.run();
  
  SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT);
  zkClient.makePath("/solr", false, true);
  zkClient.close();
  
  System.setProperty("zkHost", zkServer.getZkAddress());
}
 
开发者ID:europeana,项目名称:search,代码行数:24,代码来源:TestMultiCoreConfBootstrap.java

示例10: electNewOverseer

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
/**
 * Elects a new overseer
 *
 * @return SolrZkClient
 */
private SolrZkClient electNewOverseer(String address) throws KeeperException,
    InterruptedException, IOException {
  SolrZkClient zkClient = new SolrZkClient(address, TIMEOUT);
  ZkStateReader reader = new ZkStateReader(zkClient);
  LeaderElector overseerElector = new LeaderElector(zkClient);
  UpdateShardHandler updateShardHandler = new UpdateShardHandler(null);
  // TODO: close Overseer
  Overseer overseer = new Overseer(
      new HttpShardHandlerFactory().getShardHandler(), updateShardHandler, "/admin/cores", reader, null, new MockConfigSolr());
  overseer.close();
  ElectionContext ec = new OverseerElectionContext(zkClient, overseer,
      address.replaceAll("/", "_"));
  overseerElector.setup(ec);
  overseerElector.joinElection(ec, false);
  return zkClient;
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:ChaosMonkeyShardSplitTest.java

示例11: electNewOverseer

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
private SolrZkClient electNewOverseer(String address)
    throws InterruptedException, TimeoutException, IOException,
    KeeperException, ParserConfigurationException, SAXException {
  SolrZkClient zkClient = new SolrZkClient(address, TIMEOUT);
  ZkStateReader reader = new ZkStateReader(zkClient);
  readers.add(reader);
  LeaderElector overseerElector = new LeaderElector(zkClient);
  if (overseers.size() > 0) {
    overseers.get(overseers.size() -1).close();
    overseers.get(overseers.size() -1).getZkStateReader().getZkClient().close();
  }
  UpdateShardHandler updateShardHandler = new UpdateShardHandler(null);
  Overseer overseer = new Overseer(
      new HttpShardHandlerFactory().getShardHandler(), updateShardHandler, "/admin/cores", reader, null, new MockConfigSolr());
  overseers.add(overseer);
  ElectionContext ec = new OverseerElectionContext(zkClient, overseer,
      address.replaceAll("/", "_"));
  overseerElector.setup(ec);
  overseerElector.joinElection(ec, false);
  return zkClient;
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:OverseerTest.java

示例12: downloadFromZK

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
public static void downloadFromZK(SolrZkClient zkClient, String zkPath,
    File dir) throws IOException, KeeperException, InterruptedException {
  List<String> files = zkClient.getChildren(zkPath, null, true);
  
  for (String file : files) {
    List<String> children = zkClient.getChildren(zkPath + "/" + file, null, true);
    if (children.size() == 0) {
      byte[] data = zkClient.getData(zkPath + "/" + file, null, null, true);
      dir.mkdirs(); 
      log.info("Write file " + new File(dir, file));
      FileUtils.writeStringToFile(new File(dir, file), new String(data, "UTF-8"), "UTF-8");
    } else {
      downloadFromZK(zkClient, zkPath + "/" + file, new File(dir, file));
    }
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:17,代码来源:ZkController.java

示例13: bootstrapConf

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
/**
 * If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
 */
public static void bootstrapConf(SolrZkClient zkClient, Config cfg, String solrHome) throws IOException,
    KeeperException, InterruptedException {
  log.info("bootstraping config into ZooKeeper using solr.xml");
  NodeList nodes = (NodeList)cfg.evaluate("solr/cores/core", XPathConstants.NODESET);

  for (int i=0; i<nodes.getLength(); i++) {
    Node node = nodes.item(i);
    String rawName = DOMUtil.substituteProperty(DOMUtil.getAttr(node, "name", null), new Properties());
    String instanceDir = DOMUtil.getAttr(node, "instanceDir", null);
    File idir = new File(instanceDir);
    if (!idir.isAbsolute()) {
      idir = new File(solrHome, instanceDir);
    }
    String confName = DOMUtil.substituteProperty(DOMUtil.getAttr(node, "collection", null), new Properties());
    if (confName == null) {
      confName = rawName;
    }
    File udir = new File(idir, "conf");
    log.info("Uploading directory " + udir + " with name " + confName + " for SolrCore " + rawName);
    ZkController.uploadConfigDir(zkClient, udir, confName);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:26,代码来源:ZkController.java

示例14: setUp

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
  super.setUp();
  
  createTempDir();
  dataDir2 = new File(TEMP_DIR, getSimpleClassName() + "-core1-"
      + System.currentTimeMillis());
  dataDir2.mkdirs();

  home = ExternalPaths.EXAMPLE_MULTICORE_HOME;
  System.setProperty("solr.solr.home", home);
  System.setProperty( "solr.core0.data.dir", dataDir.getCanonicalPath() ); 
  System.setProperty( "solr.core1.data.dir", dataDir2.getCanonicalPath() ); 
  
  zkDir = dataDir.getAbsolutePath() + File.separator
      + "zookeeper/server1/data";
  zkServer = new ZkTestServer(zkDir);
  zkServer.run();
  
  SolrZkClient zkClient = new SolrZkClient(zkServer.getZkHost(), AbstractZkTestCase.TIMEOUT);
  zkClient.makePath("/solr", false, true);
  zkClient.close();
  
  System.setProperty("zkHost", zkServer.getZkAddress());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:TestMultiCoreConfBootstrap.java

示例15: ClientThread

import org.apache.solr.common.cloud.SolrZkClient; //导入依赖的package包/类
public ClientThread(int nodeNumber) throws Exception {
  super("Thread-" + nodeNumber);
  
  props = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, Integer.toString(nodeNumber), ZkStateReader.CORE_NAME_PROP, "");

  this.zkClient = new SolrZkClient(server.getZkAddress(), TIMEOUT, TIMEOUT, new OnReconnect() {
    
    @Override
    public void command() {
      try {
        setupOnConnect();
      } catch (Throwable t) {
      } 
    }
  });
 this.nodeNumber = nodeNumber;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:18,代码来源:LeaderElectionTest.java


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