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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations