Example usage for org.apache.solr.core CoreContainer isZooKeeperAware

List of usage examples for org.apache.solr.core CoreContainer isZooKeeperAware

Introduction

In this page you can find the example usage for org.apache.solr.core CoreContainer isZooKeeperAware.

Prototype

public boolean isZooKeeperAware() 

Source Link

Usage

From source file:alba.components.FilteredShowFileRequestHandler.java

License:Apache License

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
        throws InterruptedException, KeeperException, IOException {

    CoreContainer coreContainer = req.getCore().getCoreDescriptor().getCoreContainer();
    if (coreContainer.isZooKeeperAware()) {
        showFromZooKeeper(req, rsp, coreContainer);
    } else {/*from  ww  w .  ja v a  2 s  . c o  m*/
        showFromFileSystem(req, rsp);
    }
}

From source file:edu.harvard.gis.hhypermap.bop.solrplugins.DateShardRoutingSearchHandler.java

License:Apache License

private void addShardsParamIfWeCan(SolrQueryRequest req) {
    CoreDescriptor coreDescriptor = req.getCore().getCoreDescriptor();
    CoreContainer coreContainer = coreDescriptor.getCoreContainer();
    if (!coreContainer.isZooKeeperAware()) {
        return;//from  www.  java  2  s . co m
    }
    if (!req.getParams().getBool("distrib", true)) {
        return;
    }
    final String shards = req.getParams().get(ShardParams.SHARDS);
    if (shards != null) {
        return; // we already have the shards
    }

    String startStrParam = req.getParams().get(START_PARAM);
    String endStrParam = req.getParams().get(END_PARAM);

    Instant startInst = // null means open-ended ('*')
            startStrParam == null ? null : DateMathParser.parseMath(null, startStrParam).toInstant();
    Instant endInst = endStrParam == null ? null : DateMathParser.parseMath(null, endStrParam).toInstant();

    if (startInst == null && endInst == null) {
        return;
    }

    ZkController zkController = coreContainer.getZkController();
    String collection = req.getParams().get("collection", coreDescriptor.getCollectionName());
    List<Slice> slices = getOrderedSlices(zkController, collection);
    if (slices.size() <= 1) {
        return;
    }

    List<String> routeShardNames = new ArrayList<>(); // the result
    boolean findingStart = (startInst != null);
    String prevShardName = null;
    Instant prevShardStartKey = null;

    for (Slice slice : slices) {
        String name = slice.getName();
        Instant shardStartKey = parseStartKeyFromShardName(name);
        if (prevShardStartKey != null && prevShardStartKey.isAfter(shardStartKey)) {
            throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "shards not in order? " + slice);
        }
        if (findingStart) {
            // As we advance shards, is this one finally > the 'start'? If so, accept it.
            if (shardStartKey.isAfter(startInst)) {
                if (prevShardName != null) {
                    routeShardNames.add(prevShardName);
                }
                findingStart = false; // thus findingEnd
            }
        }
        if (!findingStart && endInst == null) { // take all the remainder since 'end' is null
            routeShardNames.add(name);
        } else if (!findingStart) { // findingEnd
            if (shardStartKey.isAfter(endInst)) {
                break;
            }
            routeShardNames.add(name);
        }

        prevShardName = name;
        prevShardStartKey = shardStartKey;
    }
    if (findingStart) {
        routeShardNames.add(prevShardName);
    }

    if (routeShardNames.size() == slices.size()) {
        return;
    }

    ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
    String shardsValue = StrUtils.join(routeShardNames, ',');
    params.set(ShardParams.SHARDS, shardsValue);
    req.setParams(params);
    log.debug("Set shards: {}", shardsValue);
}

From source file:org.vootoo.server.Vootoo.java

License:Apache License

public static Map<String, Integer> checkStateIsValid(CoreContainer cores, String stateVer) {
    Map<String, Integer> result = null;
    String[] pairs = null;/*w  w w.ja  v  a 2  s .  c o m*/
    if (stateVer != null && !stateVer.isEmpty() && cores.isZooKeeperAware()) {
        // many have multiple collections separated by |
        pairs = StringUtils.split(stateVer, '|');
        for (String pair : pairs) {
            String[] pcs = StringUtils.split(pair, ':');
            if (pcs.length == 2 && !pcs[0].isEmpty() && !pcs[1].isEmpty()) {
                Integer status = cores.getZkController().getZkStateReader().compareStateVersions(pcs[0],
                        Integer.parseInt(pcs[1]));
                if (status != null) {
                    if (result == null)
                        result = new HashMap<>();
                    result.put(pcs[0], status);
                }
            }
        }
    }
    return result;
}