Search in sources :

Example 36 with SimpleOrderedMap

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

the class LukeRequestHandler method getSchemaInfo.

/**
   * Return info from the index
   */
private static SimpleOrderedMap<Object> getSchemaInfo(IndexSchema schema) {
    Map<String, List<String>> typeusemap = new TreeMap<>();
    Map<String, Object> fields = new TreeMap<>();
    SchemaField uniqueField = schema.getUniqueKeyField();
    for (SchemaField f : schema.getFields().values()) {
        populateFieldInfo(schema, typeusemap, fields, uniqueField, f);
    }
    Map<String, Object> dynamicFields = new TreeMap<>();
    for (SchemaField f : schema.getDynamicFieldPrototypes()) {
        populateFieldInfo(schema, typeusemap, dynamicFields, uniqueField, f);
    }
    SimpleOrderedMap<Object> types = new SimpleOrderedMap<>();
    Map<String, FieldType> sortedTypes = new TreeMap<>(schema.getFieldTypes());
    for (FieldType ft : sortedTypes.values()) {
        SimpleOrderedMap<Object> field = new SimpleOrderedMap<>();
        field.add("fields", typeusemap.get(ft.getTypeName()));
        field.add("tokenized", ft.isTokenized());
        field.add("className", ft.getClass().getName());
        field.add("indexAnalyzer", getAnalyzerInfo(ft.getIndexAnalyzer()));
        field.add("queryAnalyzer", getAnalyzerInfo(ft.getQueryAnalyzer()));
        field.add("similarity", getSimilarityInfo(ft.getSimilarity()));
        types.add(ft.getTypeName(), field);
    }
    // Must go through this to maintain binary compatbility. Putting a TreeMap into a resp leads to casting errors
    SimpleOrderedMap<Object> finfo = new SimpleOrderedMap<>();
    SimpleOrderedMap<Object> fieldsSimple = new SimpleOrderedMap<>();
    for (Map.Entry<String, Object> ent : fields.entrySet()) {
        fieldsSimple.add(ent.getKey(), ent.getValue());
    }
    finfo.add("fields", fieldsSimple);
    SimpleOrderedMap<Object> dynamicSimple = new SimpleOrderedMap<>();
    for (Map.Entry<String, Object> ent : dynamicFields.entrySet()) {
        dynamicSimple.add(ent.getKey(), ent.getValue());
    }
    finfo.add("dynamicFields", dynamicSimple);
    finfo.add("uniqueKeyField", null == uniqueField ? null : uniqueField.getName());
    finfo.add("similarity", getSimilarityInfo(schema.getSimilarity()));
    finfo.add("types", types);
    return finfo;
}
Also used : TreeMap(java.util.TreeMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) FieldType(org.apache.solr.schema.FieldType) SchemaField(org.apache.solr.schema.SchemaField) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 37 with SimpleOrderedMap

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

the class LukeRequestHandler method handleRequestBody.

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    IndexSchema schema = req.getSchema();
    SolrIndexSearcher searcher = req.getSearcher();
    DirectoryReader reader = searcher.getIndexReader();
    SolrParams params = req.getParams();
    ShowStyle style = ShowStyle.get(params.get("show"));
    // If no doc is given, show all fields and top terms
    rsp.add("index", getIndexInfo(reader));
    if (ShowStyle.INDEX == style) {
        // that's all we need
        return;
    }
    Integer docId = params.getInt(DOC_ID);
    if (docId == null && params.get(ID) != null) {
        // Look for something with a given solr ID
        SchemaField uniqueKey = schema.getUniqueKeyField();
        String v = uniqueKey.getType().toInternal(params.get(ID));
        Term t = new Term(uniqueKey.getName(), v);
        docId = searcher.getFirstMatch(t);
        if (docId < 0) {
            throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can't find document: " + params.get(ID));
        }
    }
    // Read the document from the index
    if (docId != null) {
        if (style != null && style != ShowStyle.DOC) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "missing doc param for doc style");
        }
        Document doc = null;
        try {
            doc = reader.document(docId);
        } catch (Exception ex) {
        }
        if (doc == null) {
            throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can't find document: " + docId);
        }
        SimpleOrderedMap<Object> info = getDocumentFieldsInfo(doc, docId, reader, schema);
        SimpleOrderedMap<Object> docinfo = new SimpleOrderedMap<>();
        docinfo.add("docId", docId);
        docinfo.add("lucene", info);
        docinfo.add("solr", doc);
        rsp.add("doc", docinfo);
    } else if (ShowStyle.SCHEMA == style) {
        rsp.add("schema", getSchemaInfo(req.getSchema()));
    } else {
        rsp.add("fields", getIndexedFieldsInfo(req));
    }
    // Add some generally helpful information
    NamedList<Object> info = new SimpleOrderedMap<>();
    info.add("key", getFieldFlagsKey());
    info.add("NOTE", "Document Frequency (df) is not updated when a document is marked for deletion.  df values include deleted documents.");
    rsp.add("info", info);
    rsp.setHttpCaching(false);
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) Term(org.apache.lucene.index.Term) Document(org.apache.lucene.document.Document) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) SolrException(org.apache.solr.common.SolrException) IOException(java.io.IOException) SchemaField(org.apache.solr.schema.SchemaField) SolrParams(org.apache.solr.common.params.SolrParams) IndexSchema(org.apache.solr.schema.IndexSchema) SolrException(org.apache.solr.common.SolrException)

Example 38 with SimpleOrderedMap

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

the class MetricsHandler method handleRequestBody.

@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
    if (container == null) {
        throw new SolrException(SolrException.ErrorCode.INVALID_STATE, "Core container instance not initialized");
    }
    boolean compact = req.getParams().getBool(COMPACT_PARAM, true);
    MetricFilter mustMatchFilter = parseMustMatchFilter(req);
    MetricUtils.PropertyFilter propertyFilter = parsePropertyFilter(req);
    List<MetricType> metricTypes = parseMetricTypes(req);
    List<MetricFilter> metricFilters = metricTypes.stream().map(MetricType::asMetricFilter).collect(Collectors.toList());
    Set<String> requestedRegistries = parseRegistries(req);
    NamedList response = new SimpleOrderedMap();
    for (String registryName : requestedRegistries) {
        MetricRegistry registry = metricManager.registry(registryName);
        SimpleOrderedMap result = new SimpleOrderedMap();
        MetricUtils.toMaps(registry, metricFilters, mustMatchFilter, propertyFilter, false, false, compact, false, (k, v) -> result.add(k, v));
        if (result.size() > 0) {
            response.add(registryName, result);
        }
    }
    rsp.getValues().add("metrics", response);
}
Also used : NamedList(org.apache.solr.common.util.NamedList) MetricRegistry(com.codahale.metrics.MetricRegistry) MetricUtils(org.apache.solr.util.stats.MetricUtils) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) MetricFilter(com.codahale.metrics.MetricFilter) SolrException(org.apache.solr.common.SolrException)

Example 39 with SimpleOrderedMap

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

the class StatusOp method execute.

@Override
public void execute(CoreAdminHandler.CallInfo it) throws Exception {
    SolrParams params = it.req.getParams();
    String cname = params.get(CoreAdminParams.CORE);
    String indexInfo = params.get(CoreAdminParams.INDEX_INFO);
    boolean isIndexInfoNeeded = Boolean.parseBoolean(null == indexInfo ? "true" : indexInfo);
    NamedList<Object> status = new SimpleOrderedMap<>();
    Map<String, Exception> failures = new HashMap<>();
    for (Map.Entry<String, CoreContainer.CoreLoadFailure> failure : it.handler.coreContainer.getCoreInitFailures().entrySet()) {
        failures.put(failure.getKey(), failure.getValue().exception);
    }
    try {
        if (cname == null) {
            for (String name : it.handler.coreContainer.getAllCoreNames()) {
                status.add(name, CoreAdminOperation.getCoreStatus(it.handler.coreContainer, name, isIndexInfoNeeded));
            }
            it.rsp.add("initFailures", failures);
        } else {
            failures = failures.containsKey(cname) ? Collections.singletonMap(cname, failures.get(cname)) : Collections.<String, Exception>emptyMap();
            it.rsp.add("initFailures", failures);
            status.add(cname, CoreAdminOperation.getCoreStatus(it.handler.coreContainer, cname, isIndexInfoNeeded));
        }
        it.rsp.add("status", status);
    } catch (Exception ex) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Error handling 'status' action ", ex);
    }
}
Also used : HashMap(java.util.HashMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrException(org.apache.solr.common.SolrException) SolrParams(org.apache.solr.common.params.SolrParams) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map) HashMap(java.util.HashMap) SolrException(org.apache.solr.common.SolrException)

Example 40 with SimpleOrderedMap

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

the class SystemInfoHandler method getJvmInfo.

/**
   * Get JVM Info - including memory info
   */
public static SimpleOrderedMap<Object> getJvmInfo() {
    SimpleOrderedMap<Object> jvm = new SimpleOrderedMap<>();
    final String javaVersion = System.getProperty("java.specification.version", "unknown");
    final String javaVendor = System.getProperty("java.specification.vendor", "unknown");
    final String javaName = System.getProperty("java.specification.name", "unknown");
    final String jreVersion = System.getProperty("java.version", "unknown");
    final String jreVendor = System.getProperty("java.vendor", "unknown");
    final String vmVersion = System.getProperty("java.vm.version", "unknown");
    final String vmVendor = System.getProperty("java.vm.vendor", "unknown");
    final String vmName = System.getProperty("java.vm.name", "unknown");
    // Summary Info
    jvm.add("version", jreVersion + " " + vmVersion);
    jvm.add(NAME, jreVendor + " " + vmName);
    // details
    SimpleOrderedMap<Object> java = new SimpleOrderedMap<>();
    java.add("vendor", javaVendor);
    java.add(NAME, javaName);
    java.add("version", javaVersion);
    jvm.add("spec", java);
    SimpleOrderedMap<Object> jre = new SimpleOrderedMap<>();
    jre.add("vendor", jreVendor);
    jre.add("version", jreVersion);
    jvm.add("jre", jre);
    SimpleOrderedMap<Object> vm = new SimpleOrderedMap<>();
    vm.add("vendor", vmVendor);
    vm.add(NAME, vmName);
    vm.add("version", vmVersion);
    jvm.add("vm", vm);
    Runtime runtime = Runtime.getRuntime();
    jvm.add("processors", runtime.availableProcessors());
    // not thread safe, but could be thread local
    DecimalFormat df = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.ROOT));
    SimpleOrderedMap<Object> mem = new SimpleOrderedMap<>();
    SimpleOrderedMap<Object> raw = new SimpleOrderedMap<>();
    long free = runtime.freeMemory();
    long max = runtime.maxMemory();
    long total = runtime.totalMemory();
    long used = total - free;
    double percentUsed = ((double) (used) / (double) max) * 100;
    raw.add("free", free);
    mem.add("free", humanReadableUnits(free, df));
    raw.add("total", total);
    mem.add("total", humanReadableUnits(total, df));
    raw.add("max", max);
    mem.add("max", humanReadableUnits(max, df));
    raw.add("used", used);
    mem.add("used", humanReadableUnits(used, df) + " (%" + df.format(percentUsed) + ")");
    raw.add("used%", percentUsed);
    mem.add("raw", raw);
    jvm.add("memory", mem);
    // JMX properties -- probably should be moved to a different handler
    SimpleOrderedMap<Object> jmx = new SimpleOrderedMap<>();
    try {
        RuntimeMXBean mx = ManagementFactory.getRuntimeMXBean();
        if (mx.isBootClassPathSupported()) {
            jmx.add("bootclasspath", mx.getBootClassPath());
        }
        jmx.add("classpath", mx.getClassPath());
        // the input arguments passed to the Java virtual machine
        // which does not include the arguments to the main method.
        jmx.add("commandLineArgs", getInputArgumentsRedacted(mx));
        jmx.add("startTime", new Date(mx.getStartTime()));
        jmx.add("upTimeMS", mx.getUptime());
    } catch (Exception e) {
        log.warn("Error getting JMX properties", e);
    }
    jvm.add("jmx", jmx);
    return jvm;
}
Also used : DecimalFormat(java.text.DecimalFormat) RuntimeMXBean(java.lang.management.RuntimeMXBean) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Date(java.util.Date) IOException(java.io.IOException)

Aggregations

SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)132 NamedList (org.apache.solr.common.util.NamedList)70 ArrayList (java.util.ArrayList)37 SolrException (org.apache.solr.common.SolrException)32 Map (java.util.Map)28 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 List (java.util.List)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)19 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