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


Java SolrZkClient.getData方法代码示例

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


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

示例1: 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

示例2: 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

示例3: readConfigName

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
/**
 * Returns config value given collection name
 * Borrowed heavily from Solr's ZKController.
 */
public String readConfigName(SolrZkClient zkClient, String collection)
throws KeeperException, InterruptedException {
  if (collection == null) {
    throw new IllegalArgumentException("collection must not be null");
  }
  String configName = null;

  // first check for alias
  byte[] aliasData = zkClient.getData(ZkStateReader.ALIASES, null, null, true);
  Aliases aliases = ClusterState.load(aliasData);
  String alias = aliases.getCollectionAlias(collection);
  if (alias != null) {
    List<String> aliasList = StrUtils.splitSmart(alias, ",", true);
    if (aliasList.size() > 1) {
      throw new IllegalArgumentException("collection cannot be an alias that maps to multiple collections");
    }
    collection = aliasList.get(0);
  }
  
  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection;
  if (LOG.isInfoEnabled()) {
    LOG.info("Load collection config from:" + path);
  }
  byte[] data = zkClient.getData(path, null, null, true);
  
  if(data != null) {
    ZkNodeProps props = ZkNodeProps.load(data);
    configName = props.getStr(ZkController.CONFIGNAME_PROP);
  }
  
  if (configName != null && !zkClient.exists(ZkController.CONFIGS_ZKNODE + "/" + configName, true)) {
    LOG.error("Specified config does not exist in ZooKeeper:" + configName);
    throw new IllegalArgumentException("Specified config does not exist in ZooKeeper:"
      + configName);
  }

  return configName;
}
 
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:ZooKeeperDownloader.java

示例4: readConfigName

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
/**
 * Returns config value given collection name
 * Borrowed heavily from Solr's ZKController.
 */
public String readConfigName(SolrZkClient zkClient, String collection)
throws KeeperException, InterruptedException {
  if (collection == null) {
    throw new IllegalArgumentException("collection must not be null");
  }
  String configName = null;

  // first check for alias
  collection = checkForAlias(zkClient, collection);
  
  String path = ZkStateReader.COLLECTIONS_ZKNODE + "/" + collection;
  if (LOG.isInfoEnabled()) {
    LOG.info("Load collection config from:" + path);
  }
  byte[] data = zkClient.getData(path, null, null, true);
  
  if(data != null) {
    ZkNodeProps props = ZkNodeProps.load(data);
    configName = props.getStr(ZkController.CONFIGNAME_PROP);
  }
  
  if (configName != null && !zkClient.exists(ZkController.CONFIGS_ZKNODE + "/" + configName, true)) {
    LOG.error("Specified config does not exist in ZooKeeper:" + configName);
    throw new IllegalArgumentException("Specified config does not exist in ZooKeeper:"
      + configName);
  }

  return configName;
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:ZooKeeperInspector.java

示例5: checkForAlias

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private String checkForAlias(SolrZkClient zkClient, String collection)
    throws KeeperException, InterruptedException {
  byte[] aliasData = zkClient.getData(ZkStateReader.ALIASES, null, null, true);
  Aliases aliases = ClusterState.load(aliasData);
  String alias = aliases.getCollectionAlias(collection);
  if (alias != null) {
    List<String> aliasList = StrUtils.splitSmart(alias, ",", true);
    if (aliasList.size() > 1) {
      throw new IllegalArgumentException("collection cannot be an alias that maps to multiple collections");
    }
    collection = aliasList.get(0);
  }
  return collection;
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:ZooKeeperInspector.java

示例6: loadConfigSolr

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private ConfigSolr loadConfigSolr(SolrResourceLoader loader) {

    String solrxmlLocation = System.getProperty("solr.solrxml.location", "solrhome");

    if (solrxmlLocation == null || "solrhome".equalsIgnoreCase(solrxmlLocation))
      return ConfigSolr.fromSolrHome(loader, loader.getInstanceDir());

    if ("zookeeper".equalsIgnoreCase(solrxmlLocation)) {
      String zkHost = System.getProperty("zkHost");
      log.info("Trying to read solr.xml from " + zkHost);
      if (StringUtils.isEmpty(zkHost))
        throw new SolrException(ErrorCode.SERVER_ERROR,
            "Could not load solr.xml from zookeeper: zkHost system property not set");
      SolrZkClient zkClient = new SolrZkClient(zkHost, 30000);
      try {
        if (!zkClient.exists("/solr.xml", true))
          throw new SolrException(ErrorCode.SERVER_ERROR, "Could not load solr.xml from zookeeper: node not found");
        byte[] data = zkClient.getData("/solr.xml", null, null, true);
        return ConfigSolr.fromInputStream(loader, new ByteArrayInputStream(data));
      } catch (Exception e) {
        throw new SolrException(ErrorCode.SERVER_ERROR, "Could not load solr.xml from zookeeper", e);
      } finally {
        zkClient.close();
      }
    }

    throw new SolrException(ErrorCode.SERVER_ERROR,
        "Bad solr.solrxml.location set: " + solrxmlLocation + " - should be 'solrhome' or 'zookeeper'");
  }
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:SolrDispatchFilter.java

示例7: getLeaderId

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
public static String getLeaderId(SolrZkClient zkClient) throws KeeperException,InterruptedException{
  byte[] data = null;
  try {
    data = zkClient.getData("/overseer_elect/leader", null, new Stat(), true);
  } catch (KeeperException.NoNodeException e) {
    return null;
  }
  Map m = (Map) ZkStateReader.fromJSON(data);
  return  (String) m.get("id");
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:OverseerCollectionProcessor.java

示例8: testQuitCommand

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private void testQuitCommand() throws Exception{
  String collectionName = "testOverseerQuit";

  createCollection(collectionName, client);

  waitForRecoveriesToFinish(collectionName, false);

  SolrZkClient zk = client.getZkStateReader().getZkClient();
  byte[] data = new byte[0];
  data = zk.getData("/overseer_elect/leader", null, new Stat(), true);
  Map m = (Map) ZkStateReader.fromJSON(data);
  String s = (String) m.get("id");
  String leader = LeaderElector.getNodeName(s);
  Overseer.getInQueue(zk).offer(ZkStateReader.toJSON(new ZkNodeProps(Overseer.QUEUE_OPERATION, Overseer.QUIT)));
  long timeout = System.currentTimeMillis()+10000;
  String newLeader=null;
  for(;System.currentTimeMillis() < timeout;){
    newLeader = OverseerCollectionProcessor.getLeaderNode(zk);
    if(newLeader!=null && !newLeader.equals(leader)) break;
    Thread.sleep(100);
  }
  assertNotSame( "Leader not changed yet",newLeader,leader);



  assertTrue("The old leader should have rejoined election ", OverseerCollectionProcessor.getSortedOverseerNodeNames(zk).contains(leader));
}
 
开发者ID:europeana,项目名称:search,代码行数:28,代码来源:OverseerRolesTest.java

示例9: assertFileNotInZooKeeper

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
protected final void assertFileNotInZooKeeper(SolrZkClient zkClient, String parent, String fileName) throws Exception {
  List<String> kids = zkClient.getChildren(parent, null, true);
  for (String kid : kids) {
    if (kid.equalsIgnoreCase(fileName)) {
      String rawContent = new String(zkClient.getData(fileName, null, null, true), StandardCharsets.UTF_8);
      fail("File '" + fileName + "' was unexpectedly found in ZooKeeper.  Content starts with '"
          + rawContent.substring(0, 100) + " [...]'");
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:TestCloudManagedSchema.java

示例10: getLeaderNode

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
public static String getLeaderNode(SolrZkClient zkClient) throws KeeperException, InterruptedException {
    byte[] data = new byte[0];
    try {
      data = zkClient.getData("/overseer_elect/leader", null, new Stat(), true);
    } catch (KeeperException.NoNodeException e) {
      return null;
    }
    Map m = (Map) ZkStateReader.fromJSON(data);
    String s = (String) m.get("id");
//    log.info("leader-id {}",s);
    String nodeName = LeaderElector.getNodeName(s);
//    log.info("Leader {}", nodeName);
    return nodeName;
  }
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:15,代码来源:OverseerCollectionProcessor.java

示例11: showFromZooKeeper

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private void showFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp,
    CoreContainer coreContainer) throws KeeperException,
    InterruptedException, UnsupportedEncodingException {

  SolrZkClient zkClient = coreContainer.getZkController().getZkClient();

  String adminFile = getAdminFileFromZooKeeper(req, rsp, zkClient, hiddenFiles);

  if (adminFile == null) {
    return;
  }

  // Show a directory listing
  List<String> children = zkClient.getChildren(adminFile, null, true);
  if (children.size() > 0) {
    
    NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>();
    for (String f : children) {
      if (isHiddenFile(req, rsp, f, false, hiddenFiles)) {
        continue;
      }

      SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>();
      files.add(f, fileInfo);
      List<String> fchildren = zkClient.getChildren(adminFile + "/" + f, null, true);
      if (fchildren.size() > 0) {
        fileInfo.add("directory", true);
      } else {
        // TODO? content type
        fileInfo.add("size", f.length());
      }
      // TODO: ?
      // fileInfo.add( "modified", new Date( f.lastModified() ) );
    }
    rsp.add("files", files);
  } else {
    // Include the file contents
    // The file logic depends on RawResponseWriter, so force its use.
    ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
    params.set(CommonParams.WT, "raw");
    req.setParams(params);
    ContentStreamBase content = new ContentStreamBase.ByteArrayStream(zkClient.getData(adminFile, null, null, true), adminFile);
    content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
    
    rsp.add(RawResponseWriter.CONTENT, content);
  }
  rsp.setHttpCaching(false);
}
 
开发者ID:europeana,项目名称:search,代码行数:49,代码来源:ShowFileRequestHandler.java

示例12: showFromZooKeeper

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private void showFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp,
    CoreContainer coreContainer) throws KeeperException,
    InterruptedException, UnsupportedEncodingException {
  String adminFile = null;
  SolrCore core = req.getCore();
  SolrZkClient zkClient = coreContainer.getZkController().getZkClient();
  final ZkSolrResourceLoader loader = (ZkSolrResourceLoader) core
      .getResourceLoader();
  String confPath = loader.getCollectionZkPath();
  
  String fname = req.getParams().get("file", null);
  if (fname == null) {
    adminFile = confPath;
  } else {
    fname = fname.replace('\\', '/'); // normalize slashes
    if (hiddenFiles.contains(fname.toUpperCase(Locale.ROOT))) {
      rsp.setException(new SolrException(ErrorCode.FORBIDDEN, "Can not access: " + fname));
      return;
    }
    if (fname.indexOf("..") >= 0) {
      rsp.setException(new SolrException(ErrorCode.FORBIDDEN, "Invalid path: " + fname));
      return;
    }
    if (fname.startsWith("/")) { // Only files relative to conf are valid
      fname = fname.substring(1);
    }
    adminFile = confPath + "/" + fname;
  }
  
  // Make sure the file exists, is readable and is not a hidden file
  if (!zkClient.exists(adminFile, true)) {
    rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not find: "
                                       + adminFile));
    return;
  }
  
  // Show a directory listing
  List<String> children = zkClient.getChildren(adminFile, null, true);
  if (children.size() > 0) {
    
    NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<SimpleOrderedMap<Object>>();
    for (String f : children) {
      if (hiddenFiles.contains(f.toUpperCase(Locale.ROOT))) {
        continue; // don't show 'hidden' files
      }
      if (f.startsWith(".")) {
        continue; // skip hidden system files...
      }
      
      SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<Object>();
      files.add(f, fileInfo);
      List<String> fchildren = zkClient.getChildren(adminFile, null, true);
      if (fchildren.size() > 0) {
        fileInfo.add("directory", true);
      } else {
        // TODO? content type
        fileInfo.add("size", f.length());
      }
      // TODO: ?
      // fileInfo.add( "modified", new Date( f.lastModified() ) );
    }
    rsp.add("files", files);
  } else {
    // Include the file contents
    // The file logic depends on RawResponseWriter, so force its use.
    ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
    params.set(CommonParams.WT, "raw");
    req.setParams(params);
    
    ContentStreamBase content = new ContentStreamBase.StringStream(
        new String(zkClient.getData(adminFile, null, null, true), "UTF-8"));
    content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
    
    rsp.add(RawResponseWriter.CONTENT, content);
  }
  rsp.setHttpCaching(false);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:78,代码来源:ShowFileRequestHandler.java

示例13: showFromZooKeeper

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private void showFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp,
    CoreContainer coreContainer) throws KeeperException,
    InterruptedException, UnsupportedEncodingException {

  SolrZkClient zkClient = coreContainer.getZkController().getZkClient();

  String adminFile = getAdminFileFromZooKeeper(req, rsp, zkClient, hiddenFiles);

  if (adminFile == null) {
    return;
  }

  // Show a directory listing
  List<String> children = zkClient.getChildren(adminFile, null, true);
  if (children.size() > 0) {
    
    NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<SimpleOrderedMap<Object>>();
    for (String f : children) {
      if (isHiddenFile(req, rsp, f, false, hiddenFiles)) {
        continue;
      }

      SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<Object>();
      files.add(f, fileInfo);
      List<String> fchildren = zkClient.getChildren(adminFile + "/" + f, null, true);
      if (fchildren.size() > 0) {
        fileInfo.add("directory", true);
      } else {
        // TODO? content type
        fileInfo.add("size", f.length());
      }
      // TODO: ?
      // fileInfo.add( "modified", new Date( f.lastModified() ) );
    }
    rsp.add("files", files);
  } else {
    // Include the file contents
    // The file logic depends on RawResponseWriter, so force its use.
    ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
    params.set(CommonParams.WT, "raw");
    req.setParams(params);
    ContentStreamBase content = new ContentStreamBase.ByteArrayStream(zkClient.getData(adminFile, null, null, true), adminFile);
    content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
    
    rsp.add(RawResponseWriter.CONTENT, content);
  }
  rsp.setHttpCaching(false);
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:49,代码来源:ShowFileRequestHandler.java

示例14: getFileContentFromZooKeeper

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private String getFileContentFromZooKeeper(SolrZkClient zkClient, String fileName)
    throws IOException, SolrServerException, KeeperException, InterruptedException {

  return (new String(zkClient.getData(fileName, null, null, true), StandardCharsets.UTF_8));

}
 
开发者ID:europeana,项目名称:search,代码行数:7,代码来源:TestCloudManagedSchema.java


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