Search in sources :

Example 1 with OverseerSolrResponse

use of org.apache.solr.cloud.OverseerSolrResponse in project lucene-solr by apache.

the class CollectionsHandler method handleResponse.

private SolrResponse handleResponse(String operation, ZkNodeProps m, SolrQueryResponse rsp, long timeout) throws KeeperException, InterruptedException {
    long time = System.nanoTime();
    if (m.containsKey(ASYNC) && m.get(ASYNC) != null) {
        String asyncId = m.getStr(ASYNC);
        if (asyncId.equals("-1")) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "requestid can not be -1. It is reserved for cleanup purposes.");
        }
        NamedList<String> r = new NamedList<>();
        if (coreContainer.getZkController().getOverseerCompletedMap().contains(asyncId) || coreContainer.getZkController().getOverseerFailureMap().contains(asyncId) || coreContainer.getZkController().getOverseerRunningMap().contains(asyncId) || overseerCollectionQueueContains(asyncId)) {
            r.add("error", "Task with the same requestid already exists.");
        } else {
            coreContainer.getZkController().getOverseerCollectionQueue().offer(Utils.toJSON(m));
        }
        r.add(CoreAdminParams.REQUESTID, (String) m.get(ASYNC));
        SolrResponse response = new OverseerSolrResponse(r);
        rsp.getValues().addAll(response.getResponse());
        return response;
    }
    QueueEvent event = coreContainer.getZkController().getOverseerCollectionQueue().offer(Utils.toJSON(m), timeout);
    if (event.getBytes() != null) {
        SolrResponse response = SolrResponse.deserialize(event.getBytes());
        rsp.getValues().addAll(response.getResponse());
        SimpleOrderedMap exp = (SimpleOrderedMap) response.getResponse().get("exception");
        if (exp != null) {
            Integer code = (Integer) exp.get("rspCode");
            rsp.setException(new SolrException(code != null && code != -1 ? ErrorCode.getErrorCode(code) : ErrorCode.SERVER_ERROR, (String) exp.get("msg")));
        }
        return response;
    } else {
        if (System.nanoTime() - time >= TimeUnit.NANOSECONDS.convert(timeout, TimeUnit.MILLISECONDS)) {
            throw new SolrException(ErrorCode.SERVER_ERROR, operation + " the collection time out:" + timeout / 1000 + "s");
        } else if (event.getWatchedEvent() != null) {
            throw new SolrException(ErrorCode.SERVER_ERROR, operation + " the collection error [Watcher fired on path: " + event.getWatchedEvent().getPath() + " state: " + event.getWatchedEvent().getState() + " type " + event.getWatchedEvent().getType() + "]");
        } else {
            throw new SolrException(ErrorCode.SERVER_ERROR, operation + " the collection unknown case");
        }
    }
}
Also used : OverseerSolrResponse(org.apache.solr.cloud.OverseerSolrResponse) NamedList(org.apache.solr.common.util.NamedList) QueueEvent(org.apache.solr.cloud.OverseerTaskQueue.QueueEvent) StrUtils.formatString(org.apache.solr.common.util.StrUtils.formatString) SolrResponse(org.apache.solr.client.solrj.SolrResponse) OverseerSolrResponse(org.apache.solr.cloud.OverseerSolrResponse) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrResponse (org.apache.solr.client.solrj.SolrResponse)1 OverseerSolrResponse (org.apache.solr.cloud.OverseerSolrResponse)1 QueueEvent (org.apache.solr.cloud.OverseerTaskQueue.QueueEvent)1 SolrException (org.apache.solr.common.SolrException)1 NamedList (org.apache.solr.common.util.NamedList)1 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)1 StrUtils.formatString (org.apache.solr.common.util.StrUtils.formatString)1