SOLR-13983: remove or replace process execution in SystemInfoHandler

This commit is contained in:
Robert Muir 2019-12-18 09:03:07 -05:00
parent 53a82aedcb
commit 8c14015e52
4 changed files with 5 additions and 53 deletions

View File

@ -36,6 +36,9 @@ Upgrade Notes
* SOLR-14092: BlockJoinFacetComponent is marked for deprecation and will be removed in 9.0.
Users are encouraged to migrate to uniqueBlock() in JSON Facet API. (Mikhail Khludnev)
* SOLR-13983: Process execution is removed from SystemInfoHandler. A best-effort attempt to
execute "uname -a" and "uptime" on non-Windows platforms is no longer made. (rmuir)
New Features
---------------------
(No changes)

View File

@ -18,14 +18,11 @@ package org.apache.solr.handler.admin;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
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.nio.charset.Charset;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Date;
@ -34,9 +31,7 @@ import java.util.List;
import java.util.Locale;
import com.codahale.metrics.Gauge;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.LucenePackage;
import org.apache.lucene.util.Constants;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
@ -227,49 +222,9 @@ public class SystemInfoHandler extends RequestHandlerBase
}
});
// Try some command line things:
try {
if (!Constants.WINDOWS) {
info.add( "uname", execute( "uname -a" ) );
info.add( "uptime", execute( "uptime" ) );
}
} catch( Exception ex ) {
log.warn("Unable to execute command line tools to get operating system properties.", ex);
}
return info;
}
/**
* Utility function to execute a function
*/
private static String execute( String cmd )
{
InputStream in = null;
Process process = null;
try {
process = Runtime.getRuntime().exec(cmd);
in = process.getInputStream();
// use default charset from locale here, because the command invoked also uses the default locale:
return IOUtils.toString(new InputStreamReader(in, Charset.defaultCharset()));
} catch( Exception ex ) {
// ignore - log.warn("Error executing command", ex);
return "(error executing: " + cmd + ")";
} catch (Error err) {
if (err.getMessage() != null && (err.getMessage().contains("posix_spawn") || err.getMessage().contains("UNIXProcess"))) {
log.warn("Error forking command due to JVM locale bug (see https://issues.apache.org/jira/browse/SOLR-6387): " + err.getMessage());
return "(error executing: " + cmd + ")";
}
throw err;
} finally {
if (process != null) {
IOUtils.closeQuietly( process.getOutputStream() );
IOUtils.closeQuietly( process.getInputStream() );
IOUtils.closeQuietly( process.getErrorStream() );
}
}
}
/**
* Get JVM Info - including memory info
*/

View File

@ -22,13 +22,7 @@ solrAdminApp.controller('IndexController', function($scope, System, Cores, Const
$scope.system = data;
// load average
var load_average = ( data.system.uptime || '' ).match( /load averages?: (\d+[.,]\d\d),? (\d+[.,]\d\d),? (\d+[.,]\d\d)/ );
if (load_average) {
for (var i=0;i<2;i++) {
load_average[i]=load_average[i].replace(",","."); // for European users
}
$scope.load_average = load_average.slice(1);
}
$scope.load_average = data.system.systemLoadAverage.toFixed(2);
// physical memory
var memoryMax = parse_memory_value(data.system.totalPhysicalMemorySize);

View File

@ -106,7 +106,7 @@ limitations under the License.
<div class="block" id="system">
<h2><span>System</span>
<small class="bar-desc">{{load_average[0]}} {{load_average[1]}} {{load_average[2]}}</small>
<small class="bar-desc">{{load_average}}</small>
</h2>
<a class="reload" ng-click="reload()"><span>reload</span></a>