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


Java SolrZkClient.exists方法代码示例

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


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

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

示例2: tryCleanPath

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
static void tryCleanPath(String zkHost, String path) throws Exception {
  SolrZkClient zkClient = new SolrZkClient(zkHost, TIMEOUT);
  if (zkClient.exists(path, true)) {
    zkClient.clean(path);
  }
  zkClient.close();
}
 
开发者ID:europeana,项目名称:search,代码行数:8,代码来源:AbstractZkTestCase.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: 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

示例6: getAdminFileFromZooKeeper

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
public static String getAdminFileFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, SolrZkClient zkClient,
                                               Set<String> hiddenFiles)
    throws KeeperException, InterruptedException {
  String adminFile = null;
  SolrCore core = req.getCore();

  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 (isHiddenFile(req, rsp, fname, true, hiddenFiles)) {
      return null;
    }
    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)) {
    log.error("Can not find: " + adminFile);
    rsp.setException(new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can not find: "
        + adminFile));
    return null;
  }

  return adminFile;
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:ShowFileRequestHandler.java

示例7: prioritizeOverseerNodes

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private synchronized void prioritizeOverseerNodes() throws KeeperException, InterruptedException {
  SolrZkClient zk = zkStateReader.getZkClient();
  if(!zk.exists(ZkStateReader.ROLES,true))return;
  Map m = (Map) ZkStateReader.fromJSON(zk.getData(ZkStateReader.ROLES, null, new Stat(), true));

  List overseerDesignates = (List) m.get("overseer");
  if(overseerDesignates==null || overseerDesignates.isEmpty()) return;
  String ldr = getLeaderNode(zk);
  if(overseerDesignates.contains(ldr)) return;
  log.info("prioritizing overseer nodes at {} overseer designates are {}", myId, overseerDesignates);
  List<String> electionNodes = getSortedElectionNodes(zk);
  if(electionNodes.size()<2) return;
  log.info("sorted nodes {}", electionNodes);

  String designateNodeId = null;
  for (String electionNode : electionNodes) {
    if(overseerDesignates.contains( LeaderElector.getNodeName(electionNode))){
      designateNodeId = electionNode;
      break;
    }
  }

  if(designateNodeId == null){
    log.warn("No live overseer designate ");
    return;
  }
  if(!designateNodeId.equals( electionNodes.get(1))) { //checking if it is already at no:1
    log.info("asking node {} to come join election at head", designateNodeId);
    invokeOverseerOp(designateNodeId, "rejoinAtHead"); //ask designate to come first
    log.info("asking the old first in line {} to rejoin election  ",electionNodes.get(1) );
    invokeOverseerOp(electionNodes.get(1), "rejoin");//ask second inline to go behind
  }
  //now ask the current leader to QUIT , so that the designate can takeover
  Overseer.getInQueue(zkStateReader.getZkClient()).offer(
      ZkStateReader.toJSON(new ZkNodeProps(Overseer.QUEUE_OPERATION, Overseer.QUIT,
          "id",getLeaderId(zkStateReader.getZkClient()))));

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

示例8: processRoleCommand

import org.apache.solr.common.cloud.SolrZkClient; //导入方法依赖的package包/类
private void processRoleCommand(ZkNodeProps message, String operation) throws KeeperException, InterruptedException {
  SolrZkClient zkClient = zkStateReader.getZkClient();
  Map roles = null;
  String node = message.getStr("node");

  String roleName = message.getStr("role");
  boolean nodeExists = false;
  if(nodeExists = zkClient.exists(ZkStateReader.ROLES, true)){
    roles = (Map) ZkStateReader.fromJSON(zkClient.getData(ZkStateReader.ROLES, null, new Stat(), true));
  } else {
    roles = new LinkedHashMap(1);
  }

  List nodeList= (List) roles.get(roleName);
  if(nodeList == null) roles.put(roleName, nodeList = new ArrayList());
  if(ADDROLE.toString().toLowerCase(Locale.ROOT).equals(operation) ){
    log.info("Overseer role added to {}", node);
    if(!nodeList.contains(node)) nodeList.add(node);
  } else if(REMOVEROLE.toString().toLowerCase(Locale.ROOT).equals(operation)) {
    log.info("Overseer role removed from {}", node);
    nodeList.remove(node);
  }

  if(nodeExists){
    zkClient.setData(ZkStateReader.ROLES, ZkStateReader.toJSON(roles),true);
  } else {
    zkClient.create(ZkStateReader.ROLES, ZkStateReader.toJSON(roles), CreateMode.PERSISTENT,true);
  }
  //if there are too many nodes this command may time out. And most likely dedicated
  // overseers are created when there are too many nodes  . So , do this operation in a separate thread
  new Thread(){
    @Override
    public void run() {
      try {
        prioritizeOverseerNodes();
      } catch (Exception e) {
        log.error("Error in prioritizing Overseer",e);
      }

    }
  }.start();
}
 
开发者ID:europeana,项目名称:search,代码行数:43,代码来源:OverseerCollectionProcessor.java

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


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