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


Java ClusterState.getSlicesMap方法代码示例

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


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

示例1: assertAllActive

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

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private List<Node> getCollectionUrls(SolrQueryRequest req, String collection) {
  ClusterState clusterState = req.getCore().getCoreDescriptor()
      .getCoreContainer().getZkController().getClusterState();
  List<Node> urls = new ArrayList<>();
  Map<String,Slice> slices = clusterState.getSlicesMap(collection);
  if (slices == null) {
    throw new ZooKeeperException(ErrorCode.BAD_REQUEST,
        "Could not find collection in zk: " + clusterState);
  }
  for (Map.Entry<String,Slice> sliceEntry : slices.entrySet()) {
    Slice replicas = slices.get(sliceEntry.getKey());

    Map<String,Replica> shardMap = replicas.getReplicasMap();
    
    for (Entry<String,Replica> entry : shardMap.entrySet()) {
      ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(entry.getValue());
      if (clusterState.liveNodesContain(nodeProps.getNodeName())) {
        urls.add(new StdNode(nodeProps, collection, replicas.getName()));
      }
    }
  }
  if (urls.size() == 0) {
    return null;
  }
  return urls;
}
 
开发者ID:europeana,项目名称:search,代码行数:27,代码来源:DistributedUpdateProcessor.java

示例3: assignNode

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
public static String assignNode(String collection, ClusterState state) {
  Map<String, Slice> sliceMap = state.getSlicesMap(collection);
  if (sliceMap == null) {
    return "core_node1";
  }

  int max = 0;
  for (Slice slice : sliceMap.values()) {
    for (Replica replica : slice.getReplicas()) {
      Matcher m = COUNT.matcher(replica.getName());
      if (m.matches()) {
        max = Math.max(max, Integer.parseInt(m.group(1)));
      }
    }
  }

  return "core_node" + (max + 1);
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:Assign.java

示例4: getUrlFromZk

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private String getUrlFromZk(String collection) {
  ClusterState clusterState = getCommonCloudSolrServer().getZkStateReader().getClusterState();
  Map<String,Slice> slices = clusterState.getSlicesMap(collection);
  
  if (slices == null) {
    throw new SolrException(ErrorCode.BAD_REQUEST, "Could not find collection:" + collection);
  }
  
  for (Map.Entry<String,Slice> entry : slices.entrySet()) {
    Slice slice = entry.getValue();
    Map<String,Replica> shards = slice.getReplicasMap();
    Set<Map.Entry<String,Replica>> shardEntries = shards.entrySet();
    for (Map.Entry<String,Replica> shardEntry : shardEntries) {
      final ZkNodeProps node = shardEntry.getValue();
      if (clusterState.liveNodesContain(node.getStr(ZkStateReader.NODE_NAME_PROP))) {
        return ZkCoreNodeProps.getCoreUrl(node.getStr(ZkStateReader.BASE_URL_PROP), collection); //new ZkCoreNodeProps(node).getCoreUrl();
      }
    }
  }
  
  throw new RuntimeException("Could not find a live node for collection:" + collection);
}
 
开发者ID:europeana,项目名称:search,代码行数:23,代码来源:CollectionsAPIDistributedZkTest.java

示例5: getCollectionUrls

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private List<Node> getCollectionUrls(SolrQueryRequest req, String collection, String coreNodeName) {
  ClusterState clusterState = req.getCore().getCoreDescriptor()
      .getCoreContainer().getZkController().getClusterState();
  List<Node> urls = new ArrayList<Node>();
  Map<String,Slice> slices = clusterState.getSlicesMap(collection);
  if (slices == null) {
    throw new ZooKeeperException(ErrorCode.BAD_REQUEST,
        "Could not find collection in zk: " + clusterState);
  }
  for (Map.Entry<String,Slice> sliceEntry : slices.entrySet()) {
    Slice replicas = slices.get(sliceEntry.getKey());

    Map<String,Replica> shardMap = replicas.getReplicasMap();
    
    for (Entry<String,Replica> entry : shardMap.entrySet()) {
      ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(entry.getValue());
      if (clusterState.liveNodesContain(nodeProps.getNodeName()) && !entry.getKey().equals(coreNodeName)) {
        urls.add(new StdNode(nodeProps));
      }
    }
  }
  if (urls.size() == 0) {
    return null;
  }
  return urls;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:DistributedUpdateProcessor.java

示例6: areAnyOtherReplicasActive

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private boolean areAnyOtherReplicasActive(ZkController zkController,
    ZkNodeProps leaderProps, String collection, String shardId) {
  ClusterState clusterState = zkController.getZkStateReader()
      .getClusterState();
  Map<String,Slice> slices = clusterState.getSlicesMap(collection);
  Slice slice = slices.get(shardId);
  Map<String,Replica> replicasMap = slice.getReplicasMap();
  for (Map.Entry<String,Replica> shard : replicasMap.entrySet()) {
    String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
    // System.out.println("state:"
    // + state
    // + shard.getValue().get(ZkStateReader.NODE_NAME_PROP)
    // + " live: "
    // + clusterState.liveNodesContain(shard.getValue().get(
    // ZkStateReader.NODE_NAME_PROP)));
    if (state.equals(ZkStateReader.ACTIVE)
        && clusterState.liveNodesContain(shard.getValue().getStr(
            ZkStateReader.NODE_NAME_PROP))
        && !new ZkCoreNodeProps(shard.getValue()).getCoreUrl().equals(
            new ZkCoreNodeProps(leaderProps).getCoreUrl())) {
      return true;
    }
  }
  
  return false;
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:ElectionContext.java

示例7: getCollectionUrls

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private List<Node> getCollectionUrls(SolrQueryRequest req, String collection) {
  ClusterState clusterState = req.getCore().getCoreDescriptor()
      .getCoreContainer().getZkController().getClusterState();
  List<Node> urls = new ArrayList<Node>();
  Map<String,Slice> slices = clusterState.getSlicesMap(collection);
  if (slices == null) {
    throw new ZooKeeperException(ErrorCode.BAD_REQUEST,
        "Could not find collection in zk: " + clusterState);
  }
  for (Map.Entry<String,Slice> sliceEntry : slices.entrySet()) {
    Slice replicas = slices.get(sliceEntry.getKey());

    Map<String,Replica> shardMap = replicas.getReplicasMap();
    
    for (Entry<String,Replica> entry : shardMap.entrySet()) {
      ZkCoreNodeProps nodeProps = new ZkCoreNodeProps(entry.getValue());
      if (clusterState.liveNodesContain(nodeProps.getNodeName())) {
        urls.add(new StdNode(nodeProps));
      }
    }
  }
  if (urls.size() == 0) {
    return null;
  }
  return urls;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:27,代码来源:DistributedUpdateProcessor.java

示例8: waitForRecoveriesToFinish

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

示例9: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的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();
            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(Replica.State.RECOVERING.toString())
                            || state.equals(Replica.State.DOWN.toString()))
                            && 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:apache,项目名称:incubator-atlas,代码行数:38,代码来源:Solr5Index.java

示例10: collectStartTimes

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private void collectStartTimes(String collectionName,
      Map<String,Long> urlToTime) throws SolrServerException, IOException {
    ClusterState clusterState = getCommonCloudSolrServer().getZkStateReader()
        .getClusterState();
//    Map<String,DocCollection> collections = clusterState.getCollectionStates();
    if (clusterState.hasCollection(collectionName)) {
      Map<String,Slice> slices = clusterState.getSlicesMap(collectionName);

      Iterator<Entry<String,Slice>> it = slices.entrySet().iterator();
      while (it.hasNext()) {
        Entry<String,Slice> sliceEntry = it.next();
        Map<String,Replica> sliceShards = sliceEntry.getValue().getReplicasMap();
        Iterator<Entry<String,Replica>> shardIt = sliceShards.entrySet()
            .iterator();
        while (shardIt.hasNext()) {
          Entry<String,Replica> shardEntry = shardIt.next();
          ZkCoreNodeProps coreProps = new ZkCoreNodeProps(shardEntry.getValue());
          HttpSolrServer server = new HttpSolrServer(coreProps.getBaseUrl());
          CoreAdminResponse mcr;
          try {
            mcr = CoreAdminRequest.getStatus(coreProps.getCoreName(), server);
          } finally {
            server.shutdown();
          }
          long before = mcr.getStartTime(coreProps.getCoreName()).getTime();
          urlToTime.put(coreProps.getCoreUrl(), before);
        }
      }
    } else {
      throw new IllegalArgumentException("Could not find collection in :"
          + clusterState.getCollections());
    }
  }
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:CollectionsAPIDistributedZkTest.java

示例11: waitForRecoveriesToFinish

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

示例12: getCoreByCollection

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的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.getSlicesMap(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:pkarmstr,项目名称:NYBC,代码行数:37,代码来源:SolrDispatchFilter.java

示例13: areAnyOtherReplicasActive

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
private boolean areAnyOtherReplicasActive(ZkController zkController,
    ZkNodeProps leaderProps, String collection, String shardId) {
  ClusterState clusterState = zkController.getZkStateReader()
      .getClusterState();
  Map<String,Slice> slices = clusterState.getSlicesMap(collection);
  Slice slice = slices.get(shardId);
  if (!slice.getState().equals(Slice.ACTIVE)) {
    //Return false if the Slice is not active yet.
    return false;
  }
  Map<String,Replica> replicasMap = slice.getReplicasMap();
  for (Map.Entry<String,Replica> shard : replicasMap.entrySet()) {
    String state = shard.getValue().getStr(ZkStateReader.STATE_PROP);
    // System.out.println("state:"
    // + state
    // + shard.getValue().get(ZkStateReader.NODE_NAME_PROP)
    // + " live: "
    // + clusterState.liveNodesContain(shard.getValue().get(
    // ZkStateReader.NODE_NAME_PROP)));
    if (state.equals(ZkStateReader.ACTIVE)
        && clusterState.liveNodesContain(shard.getValue().getStr(
            ZkStateReader.NODE_NAME_PROP))
        && !new ZkCoreNodeProps(shard.getValue()).getCoreUrl().equals(
            new ZkCoreNodeProps(leaderProps).getCoreUrl())) {
      return true;
    }
  }
  
  return false;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:31,代码来源:ElectionContext.java

示例14: waitForRecoveriesToFinish

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

示例15: waitForRecoveriesToFinish

import org.apache.solr.common.cloud.ClusterState; //导入方法依赖的package包/类
protected 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("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) {
          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,代码行数:51,代码来源:TestMiniSolrCloudCluster.java


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