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


Java ClusterState.getActiveSlices方法代码示例

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


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

示例1: getActiveOrRecoveringReplicas

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
protected List<Replica> getActiveOrRecoveringReplicas(String testCollectionName, String shardId) throws Exception {    
  Map<String,Replica> activeReplicas = new HashMap<String,Replica>();    
  ZkStateReader zkr = cloudClient.getZkStateReader();
  ClusterState cs = zkr.getClusterState();
  assertNotNull(cs);
  for (Slice shard : cs.getActiveSlices(testCollectionName)) {
    if (shard.getName().equals(shardId)) {
      for (Replica replica : shard.getReplicas()) {
        String replicaState = replica.getStr(ZkStateReader.STATE_PROP);
        if (ZkStateReader.ACTIVE.equals(replicaState) || ZkStateReader.RECOVERING.equals(replicaState)) {
          activeReplicas.put(replica.getName(), replica);
        }
      }
    }
  }        
  List<Replica> replicas = new ArrayList<Replica>();
  replicas.addAll(activeReplicas.values());
  return replicas;
}
 
开发者ID:europeana,项目名称:search,代码行数:20,代码来源:HttpPartitionTest.java

示例2: 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.getActiveSlices(collectionName);
  boolean byCoreName = false;
  
  if (slices == null) {
    slices = new ArrayList<>();
    // look by core name
    byCoreName = true;
    slices = getSlicesForCollections(clusterState, slices, true);
    if (slices == null || slices.size() == 0) {
      slices = getSlicesForCollections(clusterState, slices, false);
    }
  }
  
  if (slices == null || slices.size() == 0) {
    return null;
  }
  
  String coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
      slices, byCoreName, true);
  
  if (coreUrl == null) {
    coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
        slices, byCoreName, false);
  }
  
  return coreUrl;
}
 
开发者ID:europeana,项目名称:search,代码行数:30,代码来源:SolrDispatchFilter.java

示例3: 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.getActiveSlices(collectionName);
  boolean byCoreName = false;
  
  if (slices == null) {
    slices = new ArrayList<Slice>();
    // look by core name
    byCoreName = true;
    slices = getSlicesForCollections(clusterState, slices, true);
    if (slices == null || slices.size() == 0) {
      slices = getSlicesForCollections(clusterState, slices, false);
    }
  }
  
  if (slices == null || slices.size() == 0) {
    return null;
  }
  
  String coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
      slices, byCoreName, true);
  
  if (coreUrl == null) {
    coreUrl = getCoreUrl(cores, collectionName, origCorename, clusterState,
        slices, byCoreName, false);
  }
  
  return coreUrl;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:30,代码来源:SolrDispatchFilter.java

示例4: ensureAllReplicasAreActive

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
protected static void ensureAllReplicasAreActive(String testCollectionName, int shards, int rf, int maxWaitSecs)
    throws Exception {
  long startMs = System.currentTimeMillis();

  ZkStateReader zkr = cloudSolrClient.getZkStateReader();
  zkr.updateClusterState(); // force the state to be fresh

  ClusterState cs = zkr.getClusterState();
  Collection<Slice> slices = cs.getActiveSlices(testCollectionName);
  assertTrue(slices.size() == shards);
  boolean allReplicasUp = false;
  long waitMs = 0L;
  long maxWaitMs = maxWaitSecs * 1000L;
  Replica leader = null;
  while (waitMs < maxWaitMs && !allReplicasUp) {
    // refresh state every 2 secs
    if (waitMs % 2000 == 0) {
      log.info("Updating ClusterState");
      cloudSolrClient.getZkStateReader().updateClusterState();
    }

    cs = cloudSolrClient.getZkStateReader().getClusterState();
    assertNotNull(cs);
    allReplicasUp = true; // assume true
    for (Slice shard : cs.getActiveSlices(testCollectionName)) {
      String shardId = shard.getName();
      assertNotNull("No Slice for " + shardId, shard);
      Collection<Replica> replicas = shard.getReplicas();
      assertTrue(replicas.size() == rf);
      leader = shard.getLeader();
      assertNotNull(leader);
      log.info("Found " + replicas.size() + " replicas and leader on " +
          leader.getNodeName() + " for " + shardId + " in " + testCollectionName);

      // ensure all replicas are "active"
      for (Replica replica : replicas) {
        String replicaState = replica.getStr(ZkStateReader.STATE_PROP);
        if (!"active".equals(replicaState)) {
          log.info("Replica " + replica.getName() + " for shard " + shardId + " is currently " + replicaState);
          allReplicasUp = false;
        }
      }
    }

    if (!allReplicasUp) {
      try {
        Thread.sleep(500L);
      } catch (Exception ignoreMe) {
      }
      waitMs += 500L;
    }
  } // end while

  if (!allReplicasUp)
    fail("Didn't see all replicas for " + testCollectionName +
        " come up within " + maxWaitMs + " ms! ClusterState: " + printClusterStateInfo(testCollectionName));

  long diffMs = (System.currentTimeMillis() - startMs);
  log.info("Took " + diffMs + " ms to see all replicas become active for " + testCollectionName);
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:61,代码来源:TestSolrCloudClusterSupport.java

示例5: getShardReplicationFactor

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
/**
 * Walks the NamedList response after performing an update request looking for
 * the replication factor that was achieved in each shard involved in the request.
 * For single doc updates, there will be only one shard in the return value. 
 */
@SuppressWarnings("rawtypes")
public Map<String,Integer> getShardReplicationFactor(String collection, NamedList resp) {
  connect();
  
  Map<String,Integer> results = new HashMap<String,Integer>();
  if (resp instanceof CloudSolrServer.RouteResponse) {
    NamedList routes = ((CloudSolrServer.RouteResponse)resp).getRouteResponses();      
    ClusterState clusterState = zkStateReader.getClusterState();     
    Map<String,String> leaders = new HashMap<String,String>();
    for (Slice slice : clusterState.getActiveSlices(collection)) {
      Replica leader = slice.getLeader();
      if (leader != null) {
        ZkCoreNodeProps zkProps = new ZkCoreNodeProps(leader);
        String leaderUrl = zkProps.getBaseUrl() + "/" + zkProps.getCoreName();
        leaders.put(leaderUrl, slice.getName());
        String altLeaderUrl = zkProps.getBaseUrl() + "/" + collection;
        leaders.put(altLeaderUrl, slice.getName());
      }
    }
    
    Iterator<Map.Entry<String,Object>> routeIter = routes.iterator();
    while (routeIter.hasNext()) {
      Map.Entry<String,Object> next = routeIter.next();
      String host = next.getKey();
      NamedList hostResp = (NamedList)next.getValue();
      Integer rf = (Integer)((NamedList)hostResp.get("responseHeader")).get(UpdateRequest.REPFACT);
      if (rf != null) {
        String shard = leaders.get(host);
        if (shard == null) {
          if (host.endsWith("/"))
            shard = leaders.get(host.substring(0,host.length()-1));
          if (shard == null) {
            shard = host;
          }
        }
        results.put(shard, rf);
      }
    }
  }    
  return results;
}
 
开发者ID:europeana,项目名称:search,代码行数:47,代码来源:CloudSolrServer.java

示例6: waitToSeeReplicasActive

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
protected void waitToSeeReplicasActive(String testCollectionName, String shardId, Set<String> replicasToCheck, int maxWaitSecs) throws Exception {
  long startMs = System.currentTimeMillis();

  ZkStateReader zkr = cloudClient.getZkStateReader();
  zkr.updateClusterState(true); // force the state to be fresh

  ClusterState cs = zkr.getClusterState();
  Collection<Slice> slices = cs.getActiveSlices(testCollectionName);
  boolean allReplicasUp = false;
  long waitMs = 0L;
  long maxWaitMs = maxWaitSecs * 1000L;
  while (waitMs < maxWaitMs && !allReplicasUp) {
    // refresh state every 2 secs
    if (waitMs % 2000 == 0)
      cloudClient.getZkStateReader().updateClusterState(true);

    cs = cloudClient.getZkStateReader().getClusterState();
    assertNotNull(cs);
    Slice shard = cs.getSlice(testCollectionName, shardId);
    assertNotNull("No Slice for "+shardId, shard);
    allReplicasUp = true; // assume true

    // wait to see all replicas are "active"
    for (Replica replica : shard.getReplicas()) {
      if (!replicasToCheck.contains(replica.getName()))
        continue;

      String replicaState = replica.getStr(ZkStateReader.STATE_PROP);
      if (!ZkStateReader.ACTIVE.equals(replicaState)) {
        log.info("Replica " + replica.getName() + " is currently " + replicaState);
        allReplicasUp = false;
      }
    }

    if (!allReplicasUp) {
      try {
        Thread.sleep(1000L);
      } catch (Exception ignoreMe) {}
      waitMs += 1000L;
    }
  } // end while

  if (!allReplicasUp)
    fail("Didn't see replicas "+ replicasToCheck +
        " come up within " + maxWaitMs + " ms! ClusterState: " + printClusterStateInfo(testCollectionName));

  long diffMs = (System.currentTimeMillis() - startMs);
  log.info("Took " + diffMs + " ms to see replicas ["+replicasToCheck+"] become active.");
}
 
开发者ID:europeana,项目名称:search,代码行数:50,代码来源:HttpPartitionTest.java


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