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


Java ZkStateReader.getClusterState方法代码示例

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


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

示例1: assertAllActive

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
protected void assertAllActive(String collection,ZkStateReader zkStateReader)
    throws KeeperException, InterruptedException {

    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    Map<String,Slice> slices = clusterState.getSlicesMap(collection);
    if (slices == null) {
      throw new IllegalArgumentException("Cannot find collection:" + collection);
    }
    for (Map.Entry<String,Slice> entry : slices.entrySet()) {
      Map<String,Replica> shards = entry.getValue().getReplicasMap();
      for (Map.Entry<String,Replica> shard : shards.entrySet()) {

        String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
        if (!state.equals(ZkStateReader.ACTIVE)) {
          fail("Not all shards are ACTIVE - found a shard that is: " + state);
        }
      }
    }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:AbstractDistribZkTestBase.java

示例2: waitTillRecovered

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private void waitTillRecovered() throws Exception {
  for (int i = 0; i < 30; i++) {
    Thread.sleep(3000);
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    DocCollection collection1 = clusterState.getCollection("collection1");
    Slice slice = collection1.getSlice("shard1");
    Collection<Replica> replicas = slice.getReplicas();
    boolean allActive = true;
    for (Replica replica : replicas) {
      if (!clusterState.liveNodesContain(replica.getNodeName())
          || !replica.get(ZkStateReader.STATE_PROP).equals(
          ZkStateReader.ACTIVE)) {
        allActive = false;
        break;
      }
    }
    if (allActive) {
      return;
    }
  }
  printLayout();
  fail("timeout waiting to see recovered node");
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:ChaosMonkeyShardSplitTest.java

示例3: waitTillAllNodesActive

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private void waitTillAllNodesActive() throws Exception {
  for (int i = 0; i < 60; i++) { 
    Thread.sleep(3000);
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    DocCollection collection1 = clusterState.getCollection("collection1");
    Slice slice = collection1.getSlice("shard1");
    Collection<Replica> replicas = slice.getReplicas();
    boolean allActive = true;
    for (Replica replica : replicas) {
      if (!clusterState.liveNodesContain(replica.getNodeName())
          || !replica.get(ZkStateReader.STATE_PROP).equals(
              ZkStateReader.ACTIVE)) {
        allActive = false;
        break;
      }
    }
    if (allActive) {
      return;
    }
  }
  printLayout();
  fail("timeout waiting to see all nodes active");
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:SyncSliceTest.java

示例4: getActiveOrRecoveringReplicas

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

示例5: confirmShardDeletion

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
protected void confirmShardDeletion(String shard) throws SolrServerException, KeeperException,
    InterruptedException {
  ZkStateReader zkStateReader = cloudClient.getZkStateReader();
  ClusterState clusterState = zkStateReader.getClusterState();
  int counter = 10;
  while (counter-- > 0) {
    zkStateReader.updateClusterState(true);
    clusterState = zkStateReader.getClusterState();
    if (clusterState.getSlice("collection1", shard) == null) {
      break;
    }
    Thread.sleep(1000);
  }

  assertNull("Cluster still contains shard1 even after waiting for it to be deleted.",
      clusterState.getSlice(AbstractDistribZkTestBase.DEFAULT_COLLECTION, SHARD1));
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:DeleteShardTest.java

示例6: checkIfCollectionExists

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Checks if the collection has already been created in Solr.
 */
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    return clusterState.getCollectionOrNull(collection) != null;
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:10,代码来源:SolrIndex.java

示例7: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Wait for all the collection shards to be ready.
 */
private static void waitForRecoveriesToFinish(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    try {
        boolean cont = true;

        while (cont) {
            boolean sawLiveRecovering = false;
            zkStateReader.updateClusterState(true);
            ClusterState clusterState = zkStateReader.getClusterState();
            Map<String, Slice> slices = clusterState.getSlicesMap(collection);
            Preconditions.checkNotNull("Could not find collection:" + collection, slices);

           // change paths for Replica.State per Solr refactoring
           // remove SYNC state per: http://tinyurl.com/pag6rwt
           for (Map.Entry<String, Slice> entry : slices.entrySet()) {
                Map<String, Replica> shards = entry.getValue().getReplicasMap();
                for (Map.Entry<String, Replica> shard : shards.entrySet()) {
                    String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
                    if ((state.equals(Replica.State.RECOVERING) || state.equals(Replica.State.DOWN))
                            && clusterState.liveNodesContain(shard.getValue().getStr(
                            ZkStateReader.NODE_NAME_PROP))) {
                        sawLiveRecovering = true;
                    }
                }
            }


            if (!sawLiveRecovering) {
                cont = false;
            } else {
                Thread.sleep(1000);
            }
        }
    } finally {
        logger.info("Exiting solr wait");
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:41,代码来源:SolrIndex.java

示例8: buildShardList

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

示例9: checkIfCollectionExists

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Checks if the collection has already been created in Solr.
 */
private static boolean checkIfCollectionExists(CloudSolrClient server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    zkStateReader.updateClusterState();
    ClusterState clusterState = zkStateReader.getClusterState();
    return clusterState.getCollectionOrNull(collection) != null;
}
 
开发者ID:apache,项目名称:incubator-atlas,代码行数:10,代码来源:Solr5Index.java

示例10: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
/**
 * Wait for all the collection shards to be ready.
 */
private static void waitForRecoveriesToFinish(CloudSolrServer server, String collection) throws KeeperException, InterruptedException {
    ZkStateReader zkStateReader = server.getZkStateReader();
    try {
        boolean cont = true;

        while (cont) {
            boolean sawLiveRecovering = false;
            zkStateReader.updateClusterState(true);
            ClusterState clusterState = zkStateReader.getClusterState();
            Map<String, Slice> slices = clusterState.getSlicesMap(collection);
            Preconditions.checkNotNull("Could not find collection:" + collection, slices);

            for (Map.Entry<String, Slice> entry : slices.entrySet()) {
                Map<String, Replica> shards = entry.getValue().getReplicasMap();
                for (Map.Entry<String, Replica> shard : shards.entrySet()) {
                    String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
                    if ((state.equals(ZkStateReader.RECOVERING)
                            || state.equals(ZkStateReader.SYNC) || state
                            .equals(ZkStateReader.DOWN))
                            && clusterState.liveNodesContain(shard.getValue().getStr(
                            ZkStateReader.NODE_NAME_PROP))) {
                        sawLiveRecovering = true;
                    }
                }
            }
            if (!sawLiveRecovering) {
                cont = false;
            } else {
                Thread.sleep(1000);
            }
        }
    } finally {
        logger.info("Exiting solr wait");
    }
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:39,代码来源:SolrIndex.java

示例11: getCoreByCollection

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
private SolrCore getCoreByCollection(CoreContainer cores, String corename, String path) {
  String collection = corename;
  ZkStateReader zkStateReader = cores.getZkController().getZkStateReader();
  
  ClusterState clusterState = zkStateReader.getClusterState();
  Map<String,Slice> slices = clusterState.getActiveSlicesMap(collection);
  if (slices == null) {
    return null;
  }
  // look for a core on this node
  Set<Entry<String,Slice>> entries = slices.entrySet();
  SolrCore core = null;
  done:
  for (Entry<String,Slice> entry : entries) {
    // first see if we have the leader
    ZkNodeProps leaderProps = clusterState.getLeader(collection, entry.getKey());
    if (leaderProps != null) {
      core = checkProps(cores, path, leaderProps);
    }
    if (core != null) {
      break done;
    }
    
    // check everyone then
    Map<String,Replica> shards = entry.getValue().getReplicasMap();
    Set<Entry<String,Replica>> shardEntries = shards.entrySet();
    for (Entry<String,Replica> shardEntry : shardEntries) {
      Replica zkProps = shardEntry.getValue();
      core = checkProps(cores, path, zkProps);
      if (core != null) {
        break done;
      }
    }
  }
  return core;
}
 
开发者ID:europeana,项目名称:search,代码行数:37,代码来源:SolrDispatchFilter.java

示例12: setSliceState

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
protected void setSliceState(String slice, String state) throws SolrServerException, IOException,
    KeeperException, InterruptedException {
  DistributedQueue inQueue = Overseer.getInQueue(cloudClient.getZkStateReader().getZkClient());
  Map<String, Object> propMap = new HashMap<>();
  propMap.put(Overseer.QUEUE_OPERATION, "updateshardstate");
  propMap.put(slice, state);
  propMap.put(ZkStateReader.COLLECTION_PROP, "collection1");
  ZkNodeProps m = new ZkNodeProps(propMap);
  ZkStateReader zkStateReader = cloudClient.getZkStateReader();
  inQueue.offer(ZkStateReader.toJSON(m));
  boolean transition = false;

  for (int counter = 10; counter > 0; counter--) {
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    String sliceState = clusterState.getSlice("collection1", slice).getState();
    if (sliceState.equals(state)) {
      transition = true;
      break;
    }
    Thread.sleep(1000);
  }

  if (!transition) {
    throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not set shard [" + slice + "] as " + state);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:28,代码来源:DeleteShardTest.java

示例13: ensureAllReplicasAreActive

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

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

  ClusterState cs = zkr.getClusterState();
  DocCollection docCollection = cs.getCollection(testCollectionName);
  Collection<Slice> slices = docCollection.getActiveSlices();
  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().forceUpdateCollection(testCollectionName);
    }

    cs = cloudSolrClient.getZkStateReader().getClusterState();
    assertNotNull(cs);
    allReplicasUp = true; // assume true
    for (Slice shard : docCollection.getActiveSlices()) {
      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) {
        Replica.State replicaState = replica.getState();
        if (!Replica.State.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,项目名称:solr-hadoop-common,代码行数:64,代码来源:SolrCloudClusterSupport.java

示例14: ensureAllReplicasAreActive

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

示例15: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ZkStateReader; //导入方法依赖的package包/类
public static void waitForRecoveriesToFinish(String collection,
    ZkStateReader zkStateReader, boolean verbose, boolean failOnTimeout, int timeoutSeconds)
    throws Exception {
  log.info("Wait for recoveries to finish - collection: " + collection + " failOnTimeout:" + failOnTimeout + " timeout (sec):" + timeoutSeconds);
  boolean cont = true;
  int cnt = 0;
  
  while (cont) {
    if (verbose) System.out.println("-");
    boolean sawLiveRecovering = false;
    zkStateReader.updateClusterState(true);
    ClusterState clusterState = zkStateReader.getClusterState();
    Map<String,Slice> slices = clusterState.getSlicesMap(collection);
    assertNotNull("Could not find collection:" + collection, slices);
    for (Map.Entry<String,Slice> entry : slices.entrySet()) {
      Map<String,Replica> shards = entry.getValue().getReplicasMap();
      for (Map.Entry<String,Replica> shard : shards.entrySet()) {
        if (verbose) System.out.println("replica:" + shard.getValue().getName() + " rstate:"
            + shard.getValue().getStr(ZkStateReader.STATE_PROP)
            + " live:"
            + clusterState.liveNodesContain(shard.getValue().getNodeName()));
        String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
        if ((state.equals(ZkStateReader.RECOVERING) || state
            .equals(ZkStateReader.SYNC) || state.equals(ZkStateReader.DOWN))
            && clusterState.liveNodesContain(shard.getValue().getStr(
            ZkStateReader.NODE_NAME_PROP))) {
          sawLiveRecovering = true;
        }
      }
    }
    if (!sawLiveRecovering || cnt == timeoutSeconds) {
      if (!sawLiveRecovering) {
        if (verbose) System.out.println("no one is recoverying");
      } else {
        if (verbose) System.out.println("Gave up waiting for recovery to finish..");
        if (failOnTimeout) {
          Diagnostics.logThreadDumps("Gave up waiting for recovery to finish.  THREAD DUMP:");
          zkStateReader.getZkClient().printLayoutToStdOut();
          fail("There are still nodes recoverying - waited for " + timeoutSeconds + " seconds");
          // won't get here
          return;
        }
      }
      cont = false;
    } else {
      Thread.sleep(1000);
    }
    cnt++;
  }

  log.info("Recoveries finished - collection: " + collection);
}
 
开发者ID:europeana,项目名称:search,代码行数:53,代码来源:AbstractDistribZkTestBase.java


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