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


Java ClusterState.getCollectionStates方法代码示例

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


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

示例1: checkForMissingCollection

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private void checkForMissingCollection(String collectionName)
    throws Exception {
  // check for a  collection - we poll the state
  long timeoutAt = System.currentTimeMillis() + 45000;
  boolean found = true;
  while (System.currentTimeMillis() < timeoutAt) {
    getCommonCloudSolrServer().getZkStateReader().updateClusterState(true);
    ClusterState clusterState = getCommonCloudSolrServer().getZkStateReader().getClusterState();
    Map<String,DocCollection> collections = clusterState
        .getCollectionStates();
    if (!collections.containsKey(collectionName)) {
      found = false;
      break;
    }
    Thread.sleep(100);
  }
  if (found) {
    fail("Found collection that should be gone " + collectionName);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:21,代码来源:CollectionsAPIDistributedZkTest.java

示例2: checkCollectionExpectations

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private String checkCollectionExpectations(String collectionName, List<Integer> numShardsNumReplicaList, List<String> nodesAllowedToRunShards) {
  ClusterState clusterState = getCommonCloudSolrServer().getZkStateReader().getClusterState();
  
  int expectedSlices = numShardsNumReplicaList.get(0);
  // The Math.min thing is here, because we expect replication-factor to be reduced to if there are not enough live nodes to spread all shards of a collection over different nodes
  int expectedShardsPerSlice = numShardsNumReplicaList.get(1);
  int expectedTotalShards = expectedSlices * expectedShardsPerSlice;
  
    Map<String,DocCollection> collections = clusterState
        .getCollectionStates();
    if (collections.containsKey(collectionName)) {
      Map<String,Slice> slices = collections.get(collectionName).getSlicesMap();
      // did we find expectedSlices slices/shards?
    if (slices.size() != expectedSlices) {
      return "Found new collection " + collectionName + ", but mismatch on number of slices. Expected: " + expectedSlices + ", actual: " + slices.size();
    }
    int totalShards = 0;
    for (String sliceName : slices.keySet()) {
      for (Replica replica : slices.get(sliceName).getReplicas()) {
        if (nodesAllowedToRunShards != null && !nodesAllowedToRunShards.contains(replica.getStr(ZkStateReader.NODE_NAME_PROP))) {
          return "Shard " + replica.getName() + " created on node " + replica.getStr(ZkStateReader.NODE_NAME_PROP) + " not allowed to run shards for the created collection " + collectionName;
        }
      }
      totalShards += slices.get(sliceName).getReplicas().size();
    }
    if (totalShards != expectedTotalShards) {
      return "Found new collection " + collectionName + " with correct number of slices, but mismatch on number of shards. Expected: " + expectedTotalShards + ", actual: " + totalShards; 
      }
    return null;
  } else {
    return "Could not find new collection " + collectionName;
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:34,代码来源:AbstractFullDistribZkTestBase.java

示例3: 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.getCollectionStates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。