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


Java ZkNodeProps.load方法代码示例

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


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

示例1: containsTaskWithRequestId

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
/**
 * Returns true if the queue contains a task with the specified async id.
 */
public boolean containsTaskWithRequestId(String requestId)
    throws KeeperException, InterruptedException {

  List<String> childNames = zookeeper.getChildren(dir, null, true);
  for (String childName : childNames) {
    if (childName != null) {
      try {
        byte[] data = zookeeper.getData(dir + "/" + childName, null, null, true);
        if (data != null) {
          ZkNodeProps message = ZkNodeProps.load(data);
          if (message.containsKey(OverseerCollectionProcessor.ASYNC)) {
            LOG.debug(">>>> {}", message.get(OverseerCollectionProcessor.ASYNC));
            if(message.get(OverseerCollectionProcessor.ASYNC).equals(requestId)) return true;
          }
        }
      } catch (KeeperException.NoNodeException e) {
        // Another client removed the node first, try next
      }
    }
  }

  return false;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:DistributedQueue.java

示例2: getLeaderUrl

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
private String getLeaderUrl(final String collection, final String slice)
    throws KeeperException, InterruptedException {
  int iterCount = 60;
  while (iterCount-- > 0) {
    try {
      byte[] data = zkClient.getData(
          ZkStateReader.getShardLeadersPath(collection, slice), null, null,
          true);
      ZkCoreNodeProps leaderProps = new ZkCoreNodeProps(
          ZkNodeProps.load(data));
      return leaderProps.getCoreUrl();
    } catch (NoNodeException e) {
      Thread.sleep(500);
    }
  }
  zkClient.printLayoutToStdOut();
  throw new RuntimeException("Could not get leader props");
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:LeaderElectionTest.java

示例3: testBasic

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
@Test
public void testBasic() throws IOException {
  
  Map<String,Object> props = new HashMap<>();
  props.put("prop1", "value1");
  props.put("prop2", "value2");
  props.put("prop3", "value3");
  props.put("prop4", "value4");
  props.put("prop5", "value5");
  props.put("prop6", "value6");
  
  ZkNodeProps zkProps = new ZkNodeProps(props);
  byte[] bytes = ZkStateReader.toJSON(zkProps);
  
  ZkNodeProps props2 = ZkNodeProps.load(bytes);
  assertEquals("value1", props2.getStr("prop1"));
  assertEquals("value2", props2.getStr("prop2"));
  assertEquals("value3", props2.getStr("prop3"));
  assertEquals("value4", props2.getStr("prop4"));
  assertEquals("value5", props2.getStr("prop5"));
  assertEquals("value6", props2.getStr("prop6"));
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:ZkNodePropsTest.java

示例4: readConfigName

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
/**
 * Returns config value
 */
public String readConfigName(String collection) throws KeeperException,
    InterruptedException {

  String configName = null;

  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(CONFIGNAME_PROP);
  }
  
  if (configName != null && !zkClient.exists(CONFIGS_ZKNODE + "/" + configName, true)) {
    log.error("Specified config does not exist in ZooKeeper:" + configName);
    throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
        "Specified config does not exist in ZooKeeper:" + configName);
  }

  return configName;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:28,代码来源:ZkController.java

示例5: testBasic

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
@Test
public void testBasic() throws IOException {
  
  Map<String,Object> props = new HashMap<String,Object>();
  props.put("prop1", "value1");
  props.put("prop2", "value2");
  props.put("prop3", "value3");
  props.put("prop4", "value4");
  props.put("prop5", "value5");
  props.put("prop6", "value6");
  
  ZkNodeProps zkProps = new ZkNodeProps(props);
  byte[] bytes = ZkStateReader.toJSON(zkProps);
  
  ZkNodeProps props2 = ZkNodeProps.load(bytes);
  assertEquals("value1", props2.getStr("prop1"));
  assertEquals("value2", props2.getStr("prop2"));
  assertEquals("value3", props2.getStr("prop3"));
  assertEquals("value4", props2.getStr("prop4"));
  assertEquals("value5", props2.getStr("prop5"));
  assertEquals("value6", props2.getStr("prop6"));
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:23,代码来源:ZkNodePropsTest.java

示例6: readConfigName

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的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

示例7: readConfigName

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的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

示例8: handleCrateCollMessage

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
private void handleCrateCollMessage(byte[] bytes) {
  try {
    ZkNodeProps props = ZkNodeProps.load(bytes);
    if("createcollection".equals(props.getStr("operation"))){
      String collName = props.getStr("name") ;
      if(collName != null) collectionsSet.add(collName);
    }
  } catch (Exception e) { }
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:OverseerCollectionProcessorTest.java

示例9: getCollectionsLeaders

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
public Map <String,ZkNodeProps> getCollectionsLeaders() {
    List<String> capiservers = new ArrayList<String>();
    Map<String,ZkNodeProps> capiserversProps = new HashMap<String, ZkNodeProps>();
    try {
      zkStateReader.updateClusterState(true);
      capiservers = zkClient.getChildren(CAPISERVER_PATH, null, true);
      for(String serverName : capiservers) {
        ZkNodeProps props = ZkNodeProps.load(zkClient.getData(
            CAPISERVER_PATH + "/" + serverName, null, null, true));
        capiserversProps.put(serverName, props);
      }
    } catch (KeeperException | InterruptedException e1) {
      LOG.error("Error while updating Cluster State!", e1);
    }
//    ClusterState state = zkStateReader.getClusterState();
//    Set<String> collections = state.getCollections();
//    for(String collection : collections) {
//      List<Slice> activeSlices = new ArrayList<Slice>(state.getActiveSlices(collection));
//      for(Slice slice : activeSlices) {
//        Replica replica = slice.getLeader();
//        Map<String,Object> properties = replica.getProperties();
//        String baseUrl = (String) properties.get("base_url");
//        String[] splits = baseUrl.split(":");
//        String host = splits[1].substring(splits[1].lastIndexOf("/")+1, splits[1].length());
//        String port = splits[2].substring(0, splits[2].indexOf("/"));
//        leaders.put(host, port);
//      }
//    }
    return capiserversProps;
  }
 
开发者ID:lucidworks,项目名称:solr-couchbase-plugin,代码行数:31,代码来源:CouchbaseRequestHandler.java

示例10: getConfName

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
private void getConfName(String collection, String collectionPath,
    Map<String,Object> collectionProps) throws KeeperException,
    InterruptedException {
  // check for configName
  log.info("Looking for collection configName");
  List<String> configNames = null;
  int retry = 1;
  int retryLimt = 6;
  for (; retry < retryLimt; retry++) {
    if (zkClient.exists(collectionPath, true)) {
      ZkNodeProps cProps = ZkNodeProps.load(zkClient.getData(collectionPath, null, null, true));
      if (cProps.containsKey(CONFIGNAME_PROP)) {
        break;
      }
    }
   
    // if there is only one conf, use that
    try {
      configNames = zkClient.getChildren(CONFIGS_ZKNODE, null,
          true);
    } catch (NoNodeException e) {
      // just keep trying
    }
    if (configNames != null && configNames.size() == 1) {
      // no config set named, but there is only 1 - use it
      log.info("Only one config set found in zk - using it:" + configNames.get(0));
      collectionProps.put(CONFIGNAME_PROP,  configNames.get(0));
      break;
    }
    
    if (configNames != null && configNames.contains(collection)) {
      log.info("Could not find explicit collection configName, but found config name matching collection name - using that set.");
      collectionProps.put(CONFIGNAME_PROP,  collection);
      break;
    }
    
    log.info("Could not find collection configName - pausing for 3 seconds and trying again - try: " + retry);
    Thread.sleep(3000);
  }
  if (retry == retryLimt) {
    log.error("Could not find configName for collection " + collection);
    throw new ZooKeeperException(
        SolrException.ErrorCode.SERVER_ERROR,
        "Could not find configName for collection " + collection + " found:" + configNames);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:47,代码来源:ZkController.java

示例11: testUpConfigLinkConfigClearZk

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
@Test
public void testUpConfigLinkConfigClearZk() throws Exception {
  File tmpDir = createTempDir();
  
  // test upconfig
  String confsetname = "confsetone";
  String[] args = new String[] {
      "-zkhost",
      zkServer.getZkAddress(),
      "-cmd",
      "upconfig",
      "-confdir",
      ExternalPaths.EXAMPLE_HOME + File.separator + "collection1"
          + File.separator + "conf", "-confname", confsetname};
  ZkCLI.main(args);
  
  assertTrue(zkClient.exists(ZkController.CONFIGS_ZKNODE + "/" + confsetname, true));

  // print help
  // ZkCLI.main(new String[0]);
  
  // test linkconfig
  args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
      "linkconfig", "-collection", "collection1", "-confname", confsetname};
  ZkCLI.main(args);
  
  ZkNodeProps collectionProps = ZkNodeProps.load(zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null, true));
  assertTrue(collectionProps.containsKey("configName"));
  assertEquals(confsetname, collectionProps.getStr("configName"));
  
  // test down config
  File confDir = new File(tmpDir,
      "solrtest-confdropspot-" + this.getClass().getName() + "-" + System.currentTimeMillis());
  assertFalse(confDir.exists());

  args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
      "downconfig", "-confdir", confDir.getAbsolutePath(), "-confname", confsetname};
  ZkCLI.main(args);
  
  File[] files = confDir.listFiles();
  List<String> zkFiles = zkClient.getChildren(ZkController.CONFIGS_ZKNODE + "/" + confsetname, null, true);
  assertEquals(files.length, zkFiles.size());
  
  File sourceConfDir = new File(ExternalPaths.EXAMPLE_HOME + File.separator + "collection1"
          + File.separator + "conf");
  // filter out all directories starting with . (e.g. .svn)
  Collection<File> sourceFiles = FileUtils.listFiles(sourceConfDir, TrueFileFilter.INSTANCE, new RegexFileFilter("[^\\.].*"));
  for (File sourceFile :sourceFiles){
      int indexOfRelativePath = sourceFile.getAbsolutePath().lastIndexOf("collection1" + File.separator + "conf");
      String relativePathofFile = sourceFile.getAbsolutePath().substring(indexOfRelativePath + 17, sourceFile.getAbsolutePath().length());
      File downloadedFile = new File(confDir,relativePathofFile);
      assertTrue(downloadedFile.getAbsolutePath() + " does not exist source:" + sourceFile.getAbsolutePath(), downloadedFile.exists());
      assertTrue("Content didn't change",FileUtils.contentEquals(sourceFile,downloadedFile));
  }
  
 
  // test reset zk
  args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
      "clear", "/"};
  ZkCLI.main(args);

  assertEquals(0, zkClient.getChildren("/", null, true).size());
}
 
开发者ID:europeana,项目名称:search,代码行数:64,代码来源:ZkCLITest.java

示例12: testUpConfigLinkConfigClearZk

import org.apache.solr.common.cloud.ZkNodeProps; //导入方法依赖的package包/类
@Test
public void testUpConfigLinkConfigClearZk() throws Exception {
  // test upconfig
  String confsetname = "confsetone";
  String[] args = new String[] {
      "-zkhost",
      zkServer.getZkAddress(),
      "-cmd",
      "upconfig",
      "-confdir",
      ExternalPaths.EXAMPLE_HOME + File.separator + "collection1"
          + File.separator + "conf", "-confname", confsetname};
  ZkCLI.main(args);
  
  assertTrue(zkClient.exists(ZkController.CONFIGS_ZKNODE + "/" + confsetname, true));

  // print help
  // ZkCLI.main(new String[0]);
  
  // test linkconfig
  args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
      "linkconfig", "-collection", "collection1", "-confname", confsetname};
  ZkCLI.main(args);
  
  ZkNodeProps collectionProps = ZkNodeProps.load(zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/collection1", null, null, true));
  assertTrue(collectionProps.containsKey("configName"));
  assertEquals(confsetname, collectionProps.getStr("configName"));
  
  // test down config
  File confDir = new File(TEMP_DIR,
      "solrtest-confdropspot-" + this.getClass().getName() + "-" + System.currentTimeMillis());
  
  assertFalse(confDir.exists());
  
  args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
      "downconfig", "-confdir", confDir.getAbsolutePath(), "-confname", confsetname};
  ZkCLI.main(args);
  
  File[] files = confDir.listFiles();
  List<String> zkFiles = zkClient.getChildren(ZkController.CONFIGS_ZKNODE + "/" + confsetname, null, true);
  assertEquals(files.length, zkFiles.size());
  
  // test reset zk
  args = new String[] {"-zkhost", zkServer.getZkAddress(), "-cmd",
      "clear", "/"};
  ZkCLI.main(args);

  assertEquals(0, zkClient.getChildren("/", null, true).size());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:50,代码来源:ZkCLITest.java


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