Search in sources :

Example 46 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class ThreadDumpHandler method handleRequestBody.

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
    SimpleOrderedMap<Object> system = new SimpleOrderedMap<>();
    rsp.add("system", system);
    ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();
    // Thread Count
    SimpleOrderedMap<Object> nl = new SimpleOrderedMap<>();
    nl.add("current", tmbean.getThreadCount());
    nl.add("peak", tmbean.getPeakThreadCount());
    nl.add("daemon", tmbean.getDaemonThreadCount());
    system.add("threadCount", nl);
    // Deadlocks
    ThreadInfo[] tinfos;
    long[] tids = tmbean.findMonitorDeadlockedThreads();
    if (tids != null) {
        tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
        NamedList<SimpleOrderedMap<Object>> lst = new NamedList<>();
        for (ThreadInfo ti : tinfos) {
            if (ti != null) {
                lst.add("thread", getThreadInfo(ti, tmbean));
            }
        }
        system.add("deadlocks", lst);
    }
    // Now show all the threads....
    tids = tmbean.getAllThreadIds();
    tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
    NamedList<SimpleOrderedMap<Object>> lst = new NamedList<>();
    for (ThreadInfo ti : tinfos) {
        if (ti != null) {
            lst.add("thread", getThreadInfo(ti, tmbean));
        }
    }
    system.add("threadDump", lst);
    rsp.setHttpCaching(false);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 47 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SegmentsInfoRequestHandler method getSegmentsInfo.

private SimpleOrderedMap<Object> getSegmentsInfo(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    SolrIndexSearcher searcher = req.getSearcher();
    SegmentInfos infos = SegmentInfos.readLatestCommit(searcher.getIndexReader().directory());
    List<String> mergeCandidates = getMergeCandidatesNames(req, infos);
    SimpleOrderedMap<Object> segmentInfos = new SimpleOrderedMap<>();
    SimpleOrderedMap<Object> segmentInfo = null;
    for (SegmentCommitInfo segmentCommitInfo : infos) {
        segmentInfo = getSegmentInfo(segmentCommitInfo);
        if (mergeCandidates.contains(segmentCommitInfo.info.name)) {
            segmentInfo.add("mergeCandidate", true);
        }
        segmentInfos.add((String) segmentInfo.get(NAME), segmentInfo);
    }
    return segmentInfos;
}
Also used : SegmentInfos(org.apache.lucene.index.SegmentInfos) SegmentCommitInfo(org.apache.lucene.index.SegmentCommitInfo) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 48 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class SolrInfoMBeanHandler method diffNamedList.

public NamedList diffNamedList(NamedList ref, NamedList now) {
    NamedList out = new SimpleOrderedMap();
    for (int i = 0; i < ref.size(); i++) {
        String name = ref.getName(i);
        Object r = ref.getVal(i);
        Object n = now.remove(name);
        if (n == null) {
            if (r != null) {
                out.add("REMOVE " + name, r);
            }
        } else {
            out.add(name, diffObject(r, n));
        }
    }
    for (int i = 0; i < now.size(); i++) {
        String name = now.getName(i);
        Object v = now.getVal(i);
        if (v != null) {
            out.add("ADD " + name, v);
        }
    }
    return out;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Example 49 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class FieldType method getAnalyzerProperties.

/** 
   * Returns a description of the given analyzer, by either reporting the Analyzer class
   * name (and optionally luceneMatchVersion) if it's not a TokenizerChain, or if it is,
   * querying each analysis factory for its name and args.
   */
protected static SimpleOrderedMap<Object> getAnalyzerProperties(Analyzer analyzer) {
    SimpleOrderedMap<Object> analyzerProps = new SimpleOrderedMap<>();
    if (analyzer instanceof TokenizerChain) {
        Map<String, String> factoryArgs;
        TokenizerChain tokenizerChain = (TokenizerChain) analyzer;
        CharFilterFactory[] charFilterFactories = tokenizerChain.getCharFilterFactories();
        if (0 < charFilterFactories.length) {
            List<SimpleOrderedMap<Object>> charFilterProps = new ArrayList<>();
            for (CharFilterFactory charFilterFactory : charFilterFactories) {
                SimpleOrderedMap<Object> props = new SimpleOrderedMap<>();
                props.add(CLASS_NAME, charFilterFactory.getClassArg());
                factoryArgs = charFilterFactory.getOriginalArgs();
                if (null != factoryArgs) {
                    for (String key : factoryArgs.keySet()) {
                        if (!CLASS_NAME.equals(key)) {
                            if (LUCENE_MATCH_VERSION_PARAM.equals(key)) {
                                if (charFilterFactory.isExplicitLuceneMatchVersion()) {
                                    props.add(key, factoryArgs.get(key));
                                }
                            } else {
                                props.add(key, factoryArgs.get(key));
                            }
                        }
                    }
                }
                charFilterProps.add(props);
            }
            analyzerProps.add(CHAR_FILTERS, charFilterProps);
        }
        SimpleOrderedMap<Object> tokenizerProps = new SimpleOrderedMap<>();
        TokenizerFactory tokenizerFactory = tokenizerChain.getTokenizerFactory();
        tokenizerProps.add(CLASS_NAME, tokenizerFactory.getClassArg());
        factoryArgs = tokenizerFactory.getOriginalArgs();
        if (null != factoryArgs) {
            for (String key : factoryArgs.keySet()) {
                if (!CLASS_NAME.equals(key)) {
                    if (LUCENE_MATCH_VERSION_PARAM.equals(key)) {
                        if (tokenizerFactory.isExplicitLuceneMatchVersion()) {
                            tokenizerProps.add(key, factoryArgs.get(key));
                        }
                    } else {
                        tokenizerProps.add(key, factoryArgs.get(key));
                    }
                }
            }
        }
        analyzerProps.add(TOKENIZER, tokenizerProps);
        TokenFilterFactory[] filterFactories = tokenizerChain.getTokenFilterFactories();
        if (0 < filterFactories.length) {
            List<SimpleOrderedMap<Object>> filterProps = new ArrayList<>();
            for (TokenFilterFactory filterFactory : filterFactories) {
                SimpleOrderedMap<Object> props = new SimpleOrderedMap<>();
                props.add(CLASS_NAME, filterFactory.getClassArg());
                factoryArgs = filterFactory.getOriginalArgs();
                if (null != factoryArgs) {
                    for (String key : factoryArgs.keySet()) {
                        if (!CLASS_NAME.equals(key)) {
                            if (LUCENE_MATCH_VERSION_PARAM.equals(key)) {
                                if (filterFactory.isExplicitLuceneMatchVersion()) {
                                    props.add(key, factoryArgs.get(key));
                                }
                            } else {
                                props.add(key, factoryArgs.get(key));
                            }
                        }
                    }
                }
                filterProps.add(props);
            }
            analyzerProps.add(FILTERS, filterProps);
        }
    } else {
        // analyzer is not instanceof TokenizerChain
        analyzerProps.add(CLASS_NAME, analyzer.getClass().getName());
        if (analyzer.getVersion() != Version.LATEST) {
            analyzerProps.add(LUCENE_MATCH_VERSION_PARAM, analyzer.getVersion().toString());
        }
    }
    return analyzerProps;
}
Also used : TokenizerFactory(org.apache.lucene.analysis.util.TokenizerFactory) CharFilterFactory(org.apache.lucene.analysis.util.CharFilterFactory) ArrayList(java.util.ArrayList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) TokenFilterFactory(org.apache.lucene.analysis.util.TokenFilterFactory) TokenizerChain(org.apache.solr.analysis.TokenizerChain)

Example 50 with SimpleOrderedMap

use of org.apache.solr.common.util.SimpleOrderedMap in project lucene-solr by apache.

the class HttpSolrCall method writeResponse.

private void writeResponse(SolrQueryResponse solrRsp, QueryResponseWriter responseWriter, Method reqMethod) throws IOException {
    try {
        Object invalidStates = solrReq.getContext().get(CloudSolrClient.STATE_VERSION);
        // the response for each request
        if (invalidStates != null)
            solrRsp.add(CloudSolrClient.STATE_VERSION, invalidStates);
        // Now write it out
        final String ct = responseWriter.getContentType(solrReq, solrRsp);
        // don't call setContentType on null
        if (null != ct)
            response.setContentType(ct);
        if (solrRsp.getException() != null) {
            NamedList info = new SimpleOrderedMap();
            int code = ResponseUtils.getErrorInfo(solrRsp.getException(), info, log);
            solrRsp.add("error", info);
            response.setStatus(code);
        }
        if (Method.HEAD != reqMethod) {
            // Prevent close of container streams, see SOLR-8933
            OutputStream out = new CloseShieldOutputStream(response.getOutputStream());
            QueryResponseWriterUtil.writeQueryResponse(out, responseWriter, solrReq, solrRsp, ct);
        }
    //else http HEAD request, nothing to write out, waited this long just to get ContentType
    } catch (EOFException e) {
        log.info("Unable to write response, client closed connection or we are shutting down", e);
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) OutputStream(java.io.OutputStream) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream) EOFException(java.io.EOFException) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream)

Aggregations

SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)131 NamedList (org.apache.solr.common.util.NamedList)69 ArrayList (java.util.ArrayList)36 SolrException (org.apache.solr.common.SolrException)32 Map (java.util.Map)27 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 IOException (java.io.IOException)19 List (java.util.List)19 HashMap (java.util.HashMap)18 SolrParams (org.apache.solr.common.params.SolrParams)16 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)16 SchemaField (org.apache.solr.schema.SchemaField)16 FieldType (org.apache.solr.schema.FieldType)14 BytesRef (org.apache.lucene.util.BytesRef)13 Test (org.junit.Test)13 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)12 SolrDocumentList (org.apache.solr.common.SolrDocumentList)11 HashSet (java.util.HashSet)10 SolrCore (org.apache.solr.core.SolrCore)10 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)9