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


Java ClusterState.getLiveNodes方法代码示例

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


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

示例1: buildShardList

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
protected List<String> buildShardList(CloudSolrClient cloudSolrServer, final String collection) {
  ZkStateReader zkStateReader = cloudSolrServer.getZkStateReader();

  ClusterState clusterState = zkStateReader.getClusterState();
  DocCollection docCollection = clusterState.getCollection(collection);
  Collection<Slice> slices = docCollection.getSlices();

  if (slices == null) {
    throw new IllegalArgumentException("Collection " + collection + " not found!");
  }

  Set<String> liveNodes = clusterState.getLiveNodes();
  Random random = new Random();
  List<String> shards = new ArrayList<String>();
  for (Slice slice : slices) {
    List<String> replicas = new ArrayList<String>();
    for (Replica r : slice.getReplicas()) {
      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() + " does not have any active replicas!");
    }

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

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

示例2: getCoreUrl

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private String getCoreUrl(CoreContainer cores, String collectionName,
    String origCorename, ClusterState clusterState, Collection<Slice> slices,
    boolean byCoreName, boolean activeReplicas) {
  String coreUrl;
  Set<String> liveNodes = clusterState.getLiveNodes();
  Iterator<Slice> it = slices.iterator();
  while (it.hasNext()) {
    Slice slice = it.next();
    Map<String,Replica> sliceShards = slice.getReplicasMap();
    for (ZkNodeProps nodeProps : sliceShards.values()) {
      ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
      if (!activeReplicas || (liveNodes.contains(coreNodeProps.getNodeName())
          && coreNodeProps.getState().equals(ZkStateReader.ACTIVE))) {

        if (byCoreName && !collectionName.equals(coreNodeProps.getCoreName())) {
          // if it's by core name, make sure they match
          continue;
        }
        if (coreNodeProps.getBaseUrl().equals(cores.getZkController().getBaseUrl())) {
          // don't count a local core
          continue;
        }

        if (origCorename != null) {
          coreUrl = coreNodeProps.getBaseUrl() + "/" + origCorename;
        } else {
          coreUrl = coreNodeProps.getCoreUrl();
          if (coreUrl.endsWith("/")) {
            coreUrl = coreUrl.substring(0, coreUrl.length() - 1);
          }
        }

        return coreUrl;
      }
    }
  }
  return null;
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:SolrDispatchFilter.java

示例3: createCollection

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private ClusterState createCollection(ClusterState state, String collectionName, int numShards) {
  log.info("Create collection {} with numShards {}", collectionName, numShards);

  DocRouter router = DocRouter.DEFAULT;
  List<DocRouter.Range> ranges = router.partitionRange(numShards, router.fullRange());

  Map<String, DocCollection> newCollections = new LinkedHashMap<String,DocCollection>();


  Map<String, Slice> newSlices = new LinkedHashMap<String,Slice>();
  newCollections.putAll(state.getCollectionStates());
  for (int i = 0; i < numShards; i++) {
    final String sliceName = "shard" + (i+1);

    Map<String,Object> sliceProps = new LinkedHashMap<String,Object>(1);
    sliceProps.put(Slice.RANGE, ranges.get(i));

    newSlices.put(sliceName, new Slice(sliceName, null, sliceProps));
  }

  // TODO: fill in with collection properties read from the /collections/<collectionName> node
  Map<String,Object> collectionProps = defaultCollectionProps();

  DocCollection newCollection = new DocCollection(collectionName, newSlices, collectionProps, router);

  newCollections.put(collectionName, newCollection);
  ClusterState newClusterState = new ClusterState(state.getLiveNodes(), newCollections);
  return newClusterState;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:30,代码来源:Overseer.java

示例4: getRemotCoreUrl

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private String getRemotCoreUrl(CoreContainer cores, String collectionName, String origCorename) {
  ClusterState clusterState = cores.getZkController().getClusterState();
  Collection<Slice> slices = clusterState.getSlices(collectionName);
  boolean byCoreName = false;
  if (slices == null) {
    // look by core name
    byCoreName = true;
    Set<String> collections = clusterState.getCollections();
    for (String collection : collections) {
      slices = new ArrayList<Slice>();
      slices.addAll(clusterState.getSlices(collection));
    }
  }
  
  if (slices == null || slices.size() == 0) {
    return null;
  }
  
  Set<String> liveNodes = clusterState.getLiveNodes();
  Iterator<Slice> it = slices.iterator();
  while (it.hasNext()) {
    Slice slice = it.next();
    Map<String,Replica> sliceShards = slice.getReplicasMap();
    for (ZkNodeProps nodeProps : sliceShards.values()) {
      ZkCoreNodeProps coreNodeProps = new ZkCoreNodeProps(nodeProps);
      if (liveNodes.contains(coreNodeProps.getNodeName())
          && coreNodeProps.getState().equals(ZkStateReader.ACTIVE)) {
        if (byCoreName && !collectionName.equals(coreNodeProps.getCoreName())) {
          // if it's by core name, make sure they match
          continue;
        }
        if (coreNodeProps.getBaseUrl().equals(cores.getZkController().getBaseUrl())) {
          // don't count a local core
          continue;
        }
        String coreUrl;
        if (origCorename != null) {
          coreUrl = coreNodeProps.getBaseUrl() + "/" + origCorename;
        } else {
          coreUrl = coreNodeProps.getCoreUrl();
          if (coreUrl.endsWith("/")) {
            coreUrl = coreUrl.substring(0, coreUrl.length() - 1);
          }
        }

        return coreUrl;
      }
    }
  }
  return null;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:52,代码来源:SolrDispatchFilter.java

示例5: testSliceStateUpdate

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
@Test
public void testSliceStateUpdate() throws Exception {
  System.setProperty("solrcloud.update.delay", "1");
  
  /* Get ClusterState, update slice state and publish it to Zookeeper */

  ClusterState clusterState = container1.getZkController().getClusterState();
  Map<String, DocCollection> collectionStates =
      new LinkedHashMap<String, DocCollection>(clusterState.getCollectionStates());

  Map<String, Slice> slicesMap = clusterState.getSlicesMap("collection1");
  Map<String, Object> props = new HashMap<String, Object>(1);
  Slice slice = slicesMap.get("shard1");
  Map<String, Object> prop = slice.getProperties();
  prop.put("state", "inactive");
  Slice newSlice = new Slice(slice.getName(), slice.getReplicasMap(), prop);
  slicesMap.put(newSlice.getName(), newSlice);
  props.put(DocCollection.DOC_ROUTER, ImplicitDocRouter.NAME);

  DocCollection coll = new DocCollection("collection1", slicesMap, props, DocRouter.DEFAULT);
  collectionStates.put("collection1", coll);
  SolrZkClient zkClient = new SolrZkClient(zkServer.getZkAddress(),
      AbstractZkTestCase.TIMEOUT);

  ClusterState newState = new ClusterState(clusterState.getLiveNodes(), collectionStates);
  zkClient.setData(ZkStateReader.CLUSTER_STATE,
      ZkStateReader.toJSON(newState), true);
  zkClient.close();
  
  /* Read state from another container and confirm the change */
  ZkController zkController2 = container2.getZkController();
  ClusterState clusterState2 = null;
  Map<String, Slice> slices = null;
  for (int i = 75; i > 0; i--) {
    clusterState2 = zkController2.getClusterState();
    slices = clusterState2.getAllSlicesMap("collection1");
    if (slices != null && slices.containsKey("shard1")
        && slices.get("shard1").getState().equals("inactive")) {
      break;
    }
    Thread.sleep(500);
  }

  assertNotNull(slices);

  assertEquals("shard1", slices.get("shard1").getName());
  assertEquals("inactive", slices.get("shard1").getState());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:49,代码来源:SliceStateUpdateTest.java


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