Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.admin;
import java.io.File;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.management.RuntimeMXBean;
import java.net.InetAddress;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import com.codahale.metrics.Gauge;
import org.apache.lucene.LucenePackage;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.security.AuthorizationPlugin;
import org.apache.solr.security.RuleBasedAuthorizationPluginBase;
import org.apache.solr.util.RTimer;
import org.apache.solr.util.RedactionUtils;
import org.apache.solr.util.stats.MetricUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.solr.common.params.CommonParams.NAME;
/**
* This handler returns system info
*
* @since solr 1.2
*/
public class SystemInfoHandler extends RequestHandlerBase
{
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final String PARAM_NODE = "node";
public static String REDACT_STRING = RedactionUtils.getRedactString();
/**
*
* Undocumented expert level system property to prevent doing a reverse lookup of our hostname.
* This property will be logged as a suggested workaround if any problems are noticed when doing reverse
* lookup.
*
*
*
* TODO: should we refactor this (and the associated logic) into a helper method for any other places
* where DNS is used?
*
* @see #initHostname
*/
private static final String PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP = "solr.dns.prevent.reverse.lookup";
// on some platforms, resolving canonical hostname can cause the thread
// to block for several seconds if nameservices aren't available
// so resolve this once per handler instance
//(ie: not static, so core reload will refresh)
private String hostname = null;
private CoreContainer cc;
public SystemInfoHandler() {
this(null);
}
public SystemInfoHandler(CoreContainer cc) {
super();
this.cc = cc;
initHostname();
}
private void initHostname() {
if (null != System.getProperty(PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP, null)) {
log.info("Resolving canonical hostname for local host prevented due to '{}' sysprop",
PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP);
hostname = null;
return;
}
RTimer timer = new RTimer();
try {
InetAddress addr = InetAddress.getLocalHost();
hostname = addr.getCanonicalHostName();
} catch (Exception e) {
log.warn("Unable to resolve canonical hostname for local host, possible DNS misconfiguration. SET THE '{}' {}"
, PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP
, " sysprop to true on startup to prevent future lookups if DNS can not be fixed.", e);
hostname = null;
return;
}
timer.stop();
if (15000D < timer.getTime()) {
String readableTime = String.format(Locale.ROOT, "%.3f", (timer.getTime() / 1000));
log.warn("Resolving canonical hostname for local host took {} seconds, possible DNS misconfiguration. Set the '{}' {}"
, readableTime, PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP,
" sysprop to true on startup to prevent future lookups if DNS can not be fixed.");
}
}
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{
rsp.setHttpCaching(false);
SolrCore core = req.getCore();
if (AdminHandlersProxy.maybeProxyToNodes(req, rsp, getCoreContainer(req, core))) {
return; // Request was proxied to other node
}
if (core != null) rsp.add( "core", getCoreInfo( core, req.getSchema() ) );
boolean solrCloudMode = getCoreContainer(req, core).isZooKeeperAware();
rsp.add( "mode", solrCloudMode ? "solrcloud" : "std");
if (solrCloudMode) {
rsp.add("zkHost", getCoreContainer(req, core).getZkController().getZkServerAddress());
}
if (cc != null)
rsp.add( "solr_home", cc.getSolrHome());
rsp.add( "lucene", getLuceneInfo() );
rsp.add( "jvm", getJvmInfo() );
rsp.add( "security", getSecurityInfo(req) );
rsp.add( "system", getSystemInfo() );
if (solrCloudMode) {
rsp.add("node", getCoreContainer(req, core).getZkController().getNodeName());
}
SolrEnvironment env = SolrEnvironment.getFromSyspropOrClusterprop(solrCloudMode ?
getCoreContainer(req, core).getZkController().zkStateReader : null);
if (env.isDefined()) {
rsp.add("environment", env.getCode());
if (env.getLabel() != null) {
rsp.add("environment_label", env.getLabel());
}
if (env.getColor() != null) {
rsp.add("environment_color", env.getColor());
}
}
}
private CoreContainer getCoreContainer(SolrQueryRequest req, SolrCore core) {
CoreContainer coreContainer;
if (core != null) {
coreContainer = req.getCore().getCoreContainer();
} else {
coreContainer = cc;
}
return coreContainer;
}
/**
* Get system info
*/
private SimpleOrderedMap