Search in sources :

Example 96 with SimpleOrderedMap

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

the class PluginInfoHandler method getSolrInfoBeans.

private static SimpleOrderedMap<Object> getSolrInfoBeans(SolrCore core, boolean stats) {
    SimpleOrderedMap<Object> list = new SimpleOrderedMap<>();
    for (SolrInfoBean.Category cat : SolrInfoBean.Category.values()) {
        SimpleOrderedMap<Object> category = new SimpleOrderedMap<>();
        list.add(cat.name(), category);
        Map<String, SolrInfoBean> reg = core.getInfoRegistry();
        for (Map.Entry<String, SolrInfoBean> entry : reg.entrySet()) {
            SolrInfoBean m = entry.getValue();
            if (m.getCategory() != cat)
                continue;
            String na = "Not Declared";
            SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
            category.add(entry.getKey(), info);
            info.add(NAME, (m.getName() != null ? m.getName() : na));
            info.add("description", (m.getDescription() != null ? m.getDescription() : na));
            if (stats) {
                info.add("stats", m.getMetricsSnapshot());
            }
        }
    }
    return list;
}
Also used : SolrInfoBean(org.apache.solr.core.SolrInfoBean) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Map(java.util.Map)

Example 97 with SimpleOrderedMap

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

the class SegmentsInfoRequestHandler method getSegmentInfo.

private SimpleOrderedMap<Object> getSegmentInfo(SegmentCommitInfo segmentCommitInfo) throws IOException {
    SimpleOrderedMap<Object> segmentInfoMap = new SimpleOrderedMap<>();
    segmentInfoMap.add(NAME, segmentCommitInfo.info.name);
    segmentInfoMap.add("delCount", segmentCommitInfo.getDelCount());
    segmentInfoMap.add("sizeInBytes", segmentCommitInfo.sizeInBytes());
    segmentInfoMap.add("size", segmentCommitInfo.info.maxDoc());
    Long timestamp = Long.parseLong(segmentCommitInfo.info.getDiagnostics().get("timestamp"));
    segmentInfoMap.add("age", new Date(timestamp));
    segmentInfoMap.add("source", segmentCommitInfo.info.getDiagnostics().get("source"));
    segmentInfoMap.add("version", segmentCommitInfo.info.getVersion().toString());
    return segmentInfoMap;
}
Also used : SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) Date(java.util.Date)

Example 98 with SimpleOrderedMap

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

the class ShowFileRequestHandler method showFromFileSystem.

// Return the file indicated (or the directory listing) from the local file system.
private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) {
    File adminFile = getAdminFileFromFileSystem(req, rsp, hiddenFiles);
    if (adminFile == null) {
        // exception already recorded
        return;
    }
    // Make sure the file exists, is readable and is not a hidden file
    if (!adminFile.exists()) {
        log.error("Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]");
        rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]"));
        return;
    }
    if (!adminFile.canRead() || adminFile.isHidden()) {
        log.error("Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]");
        rsp.setException(new SolrException(ErrorCode.NOT_FOUND, "Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]"));
        return;
    }
    // Show a directory listing
    if (adminFile.isDirectory()) {
        // it's really a directory, just go for it.
        int basePath = adminFile.getAbsolutePath().length() + 1;
        NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>();
        for (File f : adminFile.listFiles()) {
            String path = f.getAbsolutePath().substring(basePath);
            // normalize slashes
            path = path.replace('\\', '/');
            if (isHiddenFile(req, rsp, f.getName().replace('\\', '/'), false, hiddenFiles)) {
                continue;
            }
            SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>();
            files.add(path, fileInfo);
            if (f.isDirectory()) {
                fileInfo.add("directory", true);
            } else {
                // TODO? content type
                fileInfo.add("size", f.length());
            }
            fileInfo.add("modified", new Date(f.lastModified()));
        }
        rsp.add("files", files);
    } else {
        // Include the file contents
        //The file logic depends on RawResponseWriter, so force its use.
        ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
        params.set(CommonParams.WT, "raw");
        req.setParams(params);
        ContentStreamBase content = new ContentStreamBase.FileStream(adminFile);
        content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
        rsp.add(RawResponseWriter.CONTENT, content);
    }
    rsp.setHttpCaching(false);
}
Also used : File(java.io.File) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) SolrException(org.apache.solr.common.SolrException) Date(java.util.Date) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 99 with SimpleOrderedMap

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

the class ShowFileRequestHandler method showFromZooKeeper.

// Get a list of files from ZooKeeper for from the path in the file= parameter.
private void showFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, CoreContainer coreContainer) throws KeeperException, InterruptedException, UnsupportedEncodingException {
    SolrZkClient zkClient = coreContainer.getZkController().getZkClient();
    String adminFile = getAdminFileFromZooKeeper(req, rsp, zkClient, hiddenFiles);
    if (adminFile == null) {
        return;
    }
    // Show a directory listing
    List<String> children = zkClient.getChildren(adminFile, null, true);
    if (children.size() > 0) {
        NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>();
        for (String f : children) {
            if (isHiddenFile(req, rsp, f, false, hiddenFiles)) {
                continue;
            }
            SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>();
            files.add(f, fileInfo);
            List<String> fchildren = zkClient.getChildren(adminFile + "/" + f, null, true);
            if (fchildren.size() > 0) {
                fileInfo.add("directory", true);
            } else {
                // TODO? content type
                fileInfo.add("size", f.length());
            }
        // TODO: ?
        // fileInfo.add( "modified", new Date( f.lastModified() ) );
        }
        rsp.add("files", files);
    } else {
        // Include the file contents
        // The file logic depends on RawResponseWriter, so force its use.
        ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
        params.set(CommonParams.WT, "raw");
        req.setParams(params);
        ContentStreamBase content = new ContentStreamBase.ByteArrayStream(zkClient.getData(adminFile, null, null, true), adminFile);
        content.setContentType(req.getParams().get(USE_CONTENT_TYPE));
        rsp.add(RawResponseWriter.CONTENT, content);
    }
    rsp.setHttpCaching(false);
}
Also used : SolrZkClient(org.apache.solr.common.cloud.SolrZkClient) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) ContentStreamBase(org.apache.solr.common.util.ContentStreamBase)

Example 100 with SimpleOrderedMap

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

the class SolrInfoMBeanHandler method getDiff.

protected NamedList<NamedList<NamedList<Object>>> getDiff(NamedList<NamedList<NamedList<Object>>> ref, NamedList<NamedList<NamedList<Object>>> now, boolean includeAll) {
    NamedList<NamedList<NamedList<Object>>> changed = new NamedList<>();
    // Cycle through each category
    for (int i = 0; i < ref.size(); i++) {
        String category = ref.getName(i);
        NamedList<NamedList<Object>> ref_cat = ref.get(category);
        NamedList<NamedList<Object>> now_cat = now.get(category);
        if (now_cat != null) {
            String ref_txt = ref_cat + "";
            String now_txt = now_cat + "";
            if (!ref_txt.equals(now_txt)) {
                // Something in the category changed
                // Now iterate the real beans
                NamedList<NamedList<Object>> cat = new SimpleOrderedMap<>();
                for (int j = 0; j < ref_cat.size(); j++) {
                    String name = ref_cat.getName(j);
                    NamedList<Object> ref_bean = ref_cat.get(name);
                    NamedList<Object> now_bean = now_cat.get(name);
                    ref_txt = ref_bean + "";
                    now_txt = now_bean + "";
                    if (!ref_txt.equals(now_txt)) {
                        //              System.out.println( "----" );
                        //              System.out.println( category +" : " + name );
                        //              System.out.println( "REF: " + ref_txt );
                        //              System.out.println( "NOW: " + now_txt );
                        // Calculate the differences
                        NamedList diff = diffNamedList(ref_bean, now_bean);
                        // flag the changed thing
                        diff.add("_changed_", true);
                        cat.add(name, diff);
                    } else if (includeAll) {
                        cat.add(name, ref_bean);
                    }
                }
                if (cat.size() > 0) {
                    changed.add(category, cat);
                }
            } else if (includeAll) {
                changed.add(category, ref_cat);
            }
        }
    }
    return changed;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

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