You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/10/23 00:05:32 UTC
[11/52] [abbrv] [partial] lucene-solr:jira/gradle: Add gradle support
for Solr
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandler.java
deleted file mode 100644
index 510ef48..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandler.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/*
- * 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.IOException;
-import java.io.InputStream;
-import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import com.google.common.collect.ImmutableList;
-import org.apache.solr.api.ApiBag;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.util.Utils;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.handler.RequestHandlerUtils;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.security.AuthenticationPlugin;
-import org.apache.solr.security.AuthorizationContext;
-import org.apache.solr.security.AuthorizationPlugin;
-import org.apache.solr.security.ConfigEditablePlugin;
-import org.apache.solr.security.PermissionNameProvider;
-import org.apache.solr.common.util.CommandOperation;
-import org.apache.solr.api.Api;
-import org.apache.solr.api.ApiBag.ReqHandlerToApi;
-import org.apache.solr.common.SpecProvider;
-import org.apache.solr.common.util.JsonSchemaValidator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
-
-public abstract class SecurityConfHandler extends RequestHandlerBase implements PermissionNameProvider {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- protected CoreContainer cores;
-
- public SecurityConfHandler(CoreContainer coreContainer) {
- this.cores = coreContainer;
- }
-
- @Override
- public PermissionNameProvider.Name getPermissionName(AuthorizationContext ctx) {
- switch (ctx.getHttpMethod()) {
- case "GET":
- return PermissionNameProvider.Name.SECURITY_READ_PERM;
- case "POST":
- return PermissionNameProvider.Name.SECURITY_EDIT_PERM;
- default:
- return null;
- }
- }
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
- RequestHandlerUtils.setWt(req, CommonParams.JSON);
- String httpMethod = (String) req.getContext().get("httpMethod");
- String path = (String) req.getContext().get("path");
- String key = path.substring(path.lastIndexOf('/')+1);
- if ("GET".equals(httpMethod)) {
- getConf(rsp, key);
- } else if ("POST".equals(httpMethod)) {
- Object plugin = getPlugin(key);
- doEdit(req, rsp, path, key, plugin);
- }
- }
-
- private void doEdit(SolrQueryRequest req, SolrQueryResponse rsp, String path, final String key, final Object plugin)
- throws IOException {
- ConfigEditablePlugin configEditablePlugin = null;
-
- if (plugin == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No " + key + " plugin configured");
- }
- if (plugin instanceof ConfigEditablePlugin) {
- configEditablePlugin = (ConfigEditablePlugin) plugin;
- } else {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, key + " plugin is not editable");
- }
-
- if (req.getContentStreams() == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No contentStream");
- }
- List<CommandOperation> ops = CommandOperation.readCommands(req.getContentStreams(), rsp.getValues());
- if (ops == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No commands");
- }
- for (int count = 1; count <= 3 ; count++ ) {
- SecurityConfig securityConfig = getSecurityConfig(true);
- Map<String, Object> data = securityConfig.getData();
- Map<String, Object> latestConf = (Map<String, Object>) data.get(key);
- if (latestConf == null) {
- throw new SolrException(SERVER_ERROR, "No configuration present for " + key);
- }
- List<CommandOperation> commandsCopy = CommandOperation.clone(ops);
- Map<String, Object> out = configEditablePlugin.edit(Utils.getDeepCopy(latestConf, 4) , commandsCopy);
- if (out == null) {
- List<Map> errs = CommandOperation.captureErrors(commandsCopy);
- if (!errs.isEmpty()) {
- rsp.add(CommandOperation.ERR_MSGS, errs);
- return;
- }
- log.debug("No edits made");
- return;
- } else {
- if(!Objects.equals(latestConf.get("class") , out.get("class"))){
- throw new SolrException(SERVER_ERROR, "class cannot be modified");
- }
- Map meta = getMapValue(out, "");
- meta.put("v", securityConfig.getVersion()+1);//encode the expected zkversion
- data.put(key, out);
-
- if(persistConf(securityConfig)) {
- securityConfEdited();
- return;
- }
- }
- log.debug("Security edit operation failed {} time(s)" + count);
- }
- throw new SolrException(SERVER_ERROR, "Failed to persist security config after 3 attempts. Giving up");
- }
-
- /**
- * Hook where you can do stuff after a config has been edited. Defaults to NOP
- */
- protected void securityConfEdited() {}
-
- Object getPlugin(String key) {
- Object plugin = null;
- if ("authentication".equals(key)) plugin = cores.getAuthenticationPlugin();
- if ("authorization".equals(key)) plugin = cores.getAuthorizationPlugin();
- return plugin;
- }
-
- protected abstract void getConf(SolrQueryResponse rsp, String key);
-
- public static Map<String, Object> getMapValue(Map<String, Object> lookupMap, String key) {
- Map<String, Object> m = (Map<String, Object>) lookupMap.get(key);
- if (m == null) lookupMap.put(key, m = new LinkedHashMap<>());
- return m;
- }
-
- public static List getListValue(Map<String, Object> lookupMap, String key) {
- List l = (List) lookupMap.get(key);
- if (l == null) lookupMap.put(key, l= new ArrayList());
- return l;
- }
-
- @Override
- public String getDescription() {
- return "Edit or read security configuration";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-
- /**
- * Gets security.json from source
- */
- public abstract SecurityConfig getSecurityConfig(boolean getFresh);
-
- /**
- * Persist security.json to the source, optionally with a version
- */
- protected abstract boolean persistConf(SecurityConfig securityConfig) throws IOException;
-
- /**
- * Object to hold security.json as nested <code>Map<String,Object></code> and optionally its version.
- * The version property is optional and defaults to -1 if not initialized.
- * The data object defaults to EMPTY_MAP if not set
- */
- public static class SecurityConfig {
- private Map<String, Object> data = Collections.EMPTY_MAP;
- private int version = -1;
-
- public SecurityConfig() {}
-
- /**
- * Sets the data as a Map
- * @param data a Map
- * @return SecurityConf object (builder pattern)
- */
- public SecurityConfig setData(Map<String, Object> data) {
- this.data = data;
- return this;
- }
-
- /**
- * Sets the data as an Object, but the object needs to be of type Map
- * @param data an Object of type Map<String,Object>
- * @return SecurityConf object (builder pattern)
- */
- public SecurityConfig setData(Object data) {
- if (data instanceof Map) {
- this.data = (Map<String, Object>) data;
- return this;
- } else {
- throw new SolrException(SERVER_ERROR, "Illegal format when parsing security.json, not object");
- }
- }
-
- /**
- * Sets version
- * @param version integer for version. Depends on underlying storage
- * @return SecurityConf object (builder pattern)
- */
- public SecurityConfig setVersion(int version) {
- this.version = version;
- return this;
- }
-
- public Map<String, Object> getData() {
- return data;
- }
-
- public int getVersion() {
- return version;
- }
-
- /**
- * Set data from input stream
- * @param securityJsonInputStream an input stream for security.json
- * @return this (builder pattern)
- */
- public SecurityConfig setData(InputStream securityJsonInputStream) {
- return setData(Utils.fromJSON(securityJsonInputStream));
- }
-
- public String toString() {
- return "SecurityConfig: version=" + version + ", data=" + Utils.toJSONString(data);
- }
- }
-
- private Collection<Api> apis;
- private AuthenticationPlugin authcPlugin;
- private AuthorizationPlugin authzPlugin;
-
- @Override
- public Collection<Api> getApis() {
- if (apis == null) {
- synchronized (this) {
- if (apis == null) {
- Collection<Api> apis = new ArrayList<>();
- final SpecProvider authcCommands = Utils.getSpec("cluster.security.authentication.Commands");
- final SpecProvider authzCommands = Utils.getSpec("cluster.security.authorization.Commands");
- apis.add(new ReqHandlerToApi(this, Utils.getSpec("cluster.security.authentication")));
- apis.add(new ReqHandlerToApi(this, Utils.getSpec("cluster.security.authorization")));
- SpecProvider authcSpecProvider = () -> {
- AuthenticationPlugin authcPlugin = cores.getAuthenticationPlugin();
- return authcPlugin != null && authcPlugin instanceof SpecProvider ?
- ((SpecProvider) authcPlugin).getSpec() :
- authcCommands.getSpec();
- };
-
- apis.add(new ReqHandlerToApi(this, authcSpecProvider) {
- @Override
- public synchronized Map<String, JsonSchemaValidator> getCommandSchema() {
- //it is possible that the Authentication plugin is modified since the last call. invalidate the
- // the cached commandSchema
- if(SecurityConfHandler.this.authcPlugin != cores.getAuthenticationPlugin()) commandSchema = null;
- SecurityConfHandler.this.authcPlugin = cores.getAuthenticationPlugin();
- return super.getCommandSchema();
- }
- });
-
- SpecProvider authzSpecProvider = () -> {
- AuthorizationPlugin authzPlugin = cores.getAuthorizationPlugin();
- return authzPlugin != null && authzPlugin instanceof SpecProvider ?
- ((SpecProvider) authzPlugin).getSpec() :
- authzCommands.getSpec();
- };
- apis.add(new ApiBag.ReqHandlerToApi(this, authzSpecProvider) {
- @Override
- public synchronized Map<String, JsonSchemaValidator> getCommandSchema() {
- //it is possible that the Authorization plugin is modified since the last call. invalidate the
- // the cached commandSchema
- if(SecurityConfHandler.this.authzPlugin != cores.getAuthorizationPlugin()) commandSchema = null;
- SecurityConfHandler.this.authzPlugin = cores.getAuthorizationPlugin();
- return super.getCommandSchema();
- }
- });
-
- this.apis = ImmutableList.copyOf(apis);
- }
- }
- }
- return this.apis;
- }
-
- @Override
- public Boolean registerV2() {
- return Boolean.TRUE;
- }
-}
-
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerLocal.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerLocal.java b/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerLocal.java
deleted file mode 100644
index 69ae3ed..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerLocal.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.invoke.MethodHandles;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Collections;
-
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.util.Utils;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.common.util.CommandOperation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Security Configuration Handler which works on standalone local files
- */
-public class SecurityConfHandlerLocal extends SecurityConfHandler {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- protected Path securityJsonPath;
-
- public SecurityConfHandlerLocal(CoreContainer coreContainer) {
- super(coreContainer);
- securityJsonPath = Paths.get(coreContainer.getSolrHome()).resolve("security.json");
- }
-
- /**
- * Fetches security props from SOLR_HOME
- * @param getFresh NOP
- * @return SecurityConfig whose data property either contains security.json, or an empty map if not found
- */
- @Override
- public SecurityConfig getSecurityConfig(boolean getFresh) {
- if (Files.exists(securityJsonPath)) {
- try (InputStream securityJsonIs = Files.newInputStream(securityJsonPath)) {
- return new SecurityConfig().setData(securityJsonIs);
- } catch (Exception e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Failed opening existing security.json file: " + securityJsonPath, e);
- }
- }
- return new SecurityConfig();
- }
-
- @Override
- protected void getConf(SolrQueryResponse rsp, String key) {
- SecurityConfig props = getSecurityConfig(false);
- Object o = props.getData().get(key);
- if (o == null) {
- rsp.add(CommandOperation.ERR_MSGS, Collections.singletonList("No " + key + " configured"));
- } else {
- rsp.add(key+".enabled", getPlugin(key)!=null);
- rsp.add(key, o);
- }
- }
-
- @Override
- protected boolean persistConf(SecurityConfig securityConfig) throws IOException {
- if (securityConfig == null || securityConfig.getData().isEmpty()) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Failed persisting security.json to SOLR_HOME. Object was empty.");
- }
- try(OutputStream securityJsonOs = Files.newOutputStream(securityJsonPath)) {
- securityJsonOs.write(Utils.toJSON(securityConfig.getData()));
- log.debug("Persisted security.json to {}", securityJsonPath);
- return true;
- } catch (Exception e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Failed persisting security.json to " + securityJsonPath, e);
- }
- }
-
- @Override
- public String getDescription() {
- return "Edit or read security configuration locally in SOLR_HOME";
- }
-
- @Override
- protected void securityConfEdited() {
- // Need to call explicitly since we will not get notified of changes to local security.json
- cores.securityNodeChanged();
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerZk.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerZk.java b/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerZk.java
deleted file mode 100644
index 9e77fe3..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/SecurityConfHandlerZk.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.Collections;
-
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.util.Utils;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.common.util.CommandOperation;
-import org.apache.zookeeper.KeeperException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
-import static org.apache.solr.common.cloud.ZkStateReader.SOLR_SECURITY_CONF_PATH;
-
-/**
- * Security Configuration Handler which works with Zookeeper
- */
-public class SecurityConfHandlerZk extends SecurityConfHandler {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- public SecurityConfHandlerZk(CoreContainer coreContainer) {
- super(coreContainer);
- }
-
- /**
- * Fetches security props from Zookeeper and adds version
- * @param getFresh refresh from ZK
- * @return SecurityConfig whose data property either contains security.json, or an empty map if not found
- */
- @Override
- public SecurityConfig getSecurityConfig(boolean getFresh) {
- ZkStateReader.ConfigData configDataFromZk = cores.getZkController().getZkStateReader().getSecurityProps(getFresh);
- return configDataFromZk == null ?
- new SecurityConfig() :
- new SecurityConfig().setData(configDataFromZk.data).setVersion(configDataFromZk.version);
- }
-
- @Override
- protected void getConf(SolrQueryResponse rsp, String key) {
- ZkStateReader.ConfigData map = cores.getZkController().getZkStateReader().getSecurityProps(false);
- Object o = map == null ? null : map.data.get(key);
- if (o == null) {
- rsp.add(CommandOperation.ERR_MSGS, Collections.singletonList("No " + key + " configured"));
- } else {
- rsp.add(key+".enabled", getPlugin(key)!=null);
- rsp.add(key, o);
- }
- }
-
- @Override
- protected boolean persistConf(SecurityConfig securityConfig) throws IOException {
- try {
- cores.getZkController().getZkClient().setData(SOLR_SECURITY_CONF_PATH,
- Utils.toJSON(securityConfig.getData()),
- securityConfig.getVersion(), true);
- log.debug("Persisted security.json to {}", SOLR_SECURITY_CONF_PATH);
- return true;
- } catch (KeeperException.BadVersionException bdve){
- log.warn("Failed persisting security.json to {}", SOLR_SECURITY_CONF_PATH, bdve);
- return false;
- } catch (Exception e) {
- throw new SolrException(SERVER_ERROR, "Unable to persist security.json", e);
- }
- }
-
- @Override
- public String getDescription() {
- return "Edit or read security configuration from Zookeeper";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/SegmentsInfoRequestHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SegmentsInfoRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SegmentsInfoRequestHandler.java
deleted file mode 100644
index 740280b..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/SegmentsInfoRequestHandler.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.MergePolicy;
-import org.apache.lucene.index.MergePolicy.MergeSpecification;
-import org.apache.lucene.index.MergePolicy.OneMerge;
-import org.apache.lucene.index.MergeTrigger;
-import org.apache.lucene.index.SegmentCommitInfo;
-import org.apache.lucene.index.SegmentInfos;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.search.SolrIndexSearcher;
-import org.apache.solr.util.RefCounted;
-
-import static org.apache.solr.common.params.CommonParams.NAME;
-
-/**
- * This handler exposes information about last commit generation segments
- */
-public class SegmentsInfoRequestHandler extends RequestHandlerBase {
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
- throws Exception {
- rsp.add("segments", getSegmentsInfo(req, rsp));
- rsp.setHttpCaching(false);
- }
-
- private SimpleOrderedMap<Object> getSegmentsInfo(SolrQueryRequest req, SolrQueryResponse rsp)
- throws Exception {
- SolrIndexSearcher searcher = req.getSearcher();
-
- SegmentInfos infos =
- SegmentInfos.readLatestCommit(searcher.getIndexReader().directory());
-
- List<String> mergeCandidates = getMergeCandidatesNames(req, infos);
-
- SimpleOrderedMap<Object> segmentInfos = new SimpleOrderedMap<>();
- SimpleOrderedMap<Object> segmentInfo = null;
- List<SegmentCommitInfo> sortable = new ArrayList<>();
- sortable.addAll(infos.asList());
- // Order by the number of live docs. The display is logarithmic so it is a little jumbled visually
- sortable.sort((s1, s2) -> {
- return (s2.info.maxDoc() - s2.getDelCount()) - (s1.info.maxDoc() - s1.getDelCount());
- });
- for (SegmentCommitInfo segmentCommitInfo : sortable) {
- segmentInfo = getSegmentInfo(segmentCommitInfo);
- if (mergeCandidates.contains(segmentCommitInfo.info.name)) {
- segmentInfo.add("mergeCandidate", true);
- }
- segmentInfos.add((String) segmentInfo.get(NAME), segmentInfo);
- }
-
- return segmentInfos;
- }
-
- 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;
- }
-
- private List<String> getMergeCandidatesNames(SolrQueryRequest req, SegmentInfos infos) throws IOException {
- List<String> result = new ArrayList<String>();
- RefCounted<IndexWriter> refCounted = req.getCore().getSolrCoreState().getIndexWriter(req.getCore());
- try {
- IndexWriter indexWriter = refCounted.get();
- //get chosen merge policy
- MergePolicy mp = indexWriter.getConfig().getMergePolicy();
- //Find merges
- MergeSpecification findMerges = mp.findMerges(MergeTrigger.EXPLICIT, infos, indexWriter);
- if (findMerges != null && findMerges.merges != null && findMerges.merges.size() > 0) {
- for (OneMerge merge : findMerges.merges) {
- //TODO: add merge grouping
- for (SegmentCommitInfo mergeSegmentInfo : merge.segments) {
- result.add(mergeSegmentInfo.info.name);
- }
- }
- }
-
- return result;
- } finally {
- refCounted.decref();
- }
- }
-
- @Override
- public String getDescription() {
- return "Lucene segments info.";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java
deleted file mode 100644
index 02577f1..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * 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 org.apache.solr.cloud.ZkSolrResourceLoader;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.cloud.SolrZkClient;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.ContentStreamBase;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.SolrResourceLoader;
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.RawResponseWriter;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.zookeeper.KeeperException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.invoke.MethodHandles;
-import java.net.URISyntaxException;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-
-/**
- * This handler uses the RawResponseWriter to give client access to
- * files inside ${solr.home}/conf
- * <p>
- * If you want to selectively restrict access some configuration files, you can list
- * these files in the {@link #HIDDEN} invariants. For example to hide
- * synonyms.txt and anotherfile.txt, you would register:
- * <br>
- * <pre>
- * <requestHandler name="/admin/file" class="org.apache.solr.handler.admin.ShowFileRequestHandler" >
- * <lst name="defaults">
- * <str name="echoParams">explicit</str>
- * </lst>
- * <lst name="invariants">
- * <str name="hidden">synonyms.txt</str>
- * <str name="hidden">anotherfile.txt</str>
- * <str name="hidden">*</str>
- * </lst>
- * </requestHandler>
- * </pre>
- *
- * At present, there is only explicit file names (including path) or the glob '*' are supported. Variants like '*.xml'
- * are NOT supported.ere
- *
- * <p>
- * The ShowFileRequestHandler uses the {@link RawResponseWriter} (wt=raw) to return
- * file contents. If you need to use a different writer, you will need to change
- * the registered invariant param for wt.
- * <p>
- * If you want to override the contentType header returned for a given file, you can
- * set it directly using: {@link #USE_CONTENT_TYPE}. For example, to get a plain text
- * version of schema.xml, try:
- * <pre>
- * http://localhost:8983/solr/admin/file?file=schema.xml&contentType=text/plain
- * </pre>
- *
- *
- * @since solr 1.3
- */
-public class ShowFileRequestHandler extends RequestHandlerBase
-{
- public static final String HIDDEN = "hidden";
- public static final String USE_CONTENT_TYPE = "contentType";
-
- protected Set<String> hiddenFiles;
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-
- public ShowFileRequestHandler()
- {
- super();
- }
-
- @Override
- public void init(NamedList args) {
- super.init( args );
- hiddenFiles = initHidden(invariants);
- }
-
- public static Set<String> initHidden(SolrParams invariants) {
-
- Set<String> hiddenRet = new HashSet<>();
- // Build a list of hidden files
- if (invariants != null) {
- String[] hidden = invariants.getParams(HIDDEN);
- if (hidden != null) {
- for (String s : hidden) {
- hiddenRet.add(s.toUpperCase(Locale.ROOT));
- }
- }
- }
- return hiddenRet;
- }
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
- throws InterruptedException, KeeperException, IOException {
-
- CoreContainer coreContainer = req.getCore().getCoreContainer();
- if (coreContainer.isZooKeeperAware()) {
- showFromZooKeeper(req, rsp, coreContainer);
- } else {
- showFromFileSystem(req, rsp);
- }
- }
-
- // 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);
- }
-
- // 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 );
- path = path.replace( '\\', '/' ); // normalize slashes
-
- 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);
- }
-
- //////////////////////// Static methods //////////////////////////////
-
- public static boolean isHiddenFile(SolrQueryRequest req, SolrQueryResponse rsp, String fnameIn, boolean reportError,
- Set<String> hiddenFiles) {
- String fname = fnameIn.toUpperCase(Locale.ROOT);
- if (hiddenFiles.contains(fname) || hiddenFiles.contains("*")) {
- if (reportError) {
- log.error("Cannot access " + fname);
- rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Can not access: " + fnameIn));
- }
- return true;
- }
-
- // This is slightly off, a valid path is something like ./schema.xml. I don't think it's worth the effort though
- // to fix it to handle all possibilities though.
- if (fname.indexOf("..") >= 0 || fname.startsWith(".")) {
- if (reportError) {
- log.error("Invalid path: " + fname);
- rsp.setException(new SolrException(SolrException.ErrorCode.FORBIDDEN, "Invalid path: " + fnameIn));
- }
- return true;
- }
- return false;
- }
-
- // Refactored to be usable from multiple methods. Gets the path of the requested file from ZK.
- // Returns null if the file is not found.
- //
- // Assumes that the file is in a parameter called "file".
-
- public static String getAdminFileFromZooKeeper(SolrQueryRequest req, SolrQueryResponse rsp, SolrZkClient zkClient,
- Set<String> hiddenFiles)
- throws KeeperException, InterruptedException {
- String adminFile = null;
- SolrCore core = req.getCore();
-
- final ZkSolrResourceLoader loader = (ZkSolrResourceLoader) core
- .getResourceLoader();
- String confPath = loader.getConfigSetZkPath();
-
- String fname = req.getParams().get("file", null);
- if (fname == null) {
- adminFile = confPath;
- } else {
- fname = fname.replace('\\', '/'); // normalize slashes
- if (isHiddenFile(req, rsp, fname, true, hiddenFiles)) {
- return null;
- }
- if (fname.startsWith("/")) { // Only files relative to conf are valid
- fname = fname.substring(1);
- }
- adminFile = confPath + "/" + fname;
- }
-
- // Make sure the file exists, is readable and is not a hidden file
- if (!zkClient.exists(adminFile, true)) {
- log.error("Can not find: " + adminFile);
- rsp.setException(new SolrException(SolrException.ErrorCode.NOT_FOUND, "Can not find: "
- + adminFile));
- return null;
- }
-
- return adminFile;
- }
-
-
- // Find the file indicated by the "file=XXX" parameter or the root of the conf directory on the local
- // file system. Respects all the "interesting" stuff around what the resource loader does to find files.
- public static File getAdminFileFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp,
- Set<String> hiddenFiles) {
- File adminFile = null;
- final SolrResourceLoader loader = req.getCore().getResourceLoader();
- File configdir = new File( loader.getConfigDir() );
- if (!configdir.exists()) {
- // TODO: maybe we should just open it this way to start with?
- try {
- configdir = new File( loader.getClassLoader().getResource(loader.getConfigDir()).toURI() );
- } catch (URISyntaxException e) {
- log.error("Can not access configuration directory!");
- rsp.setException(new SolrException( SolrException.ErrorCode.FORBIDDEN, "Can not access configuration directory!", e));
- return null;
- }
- }
- String fname = req.getParams().get("file", null);
- if( fname == null ) {
- adminFile = configdir;
- }
- else {
- fname = fname.replace( '\\', '/' ); // normalize slashes
- if( hiddenFiles.contains( fname.toUpperCase(Locale.ROOT) ) ) {
- log.error("Can not access: "+ fname);
- rsp.setException(new SolrException( SolrException.ErrorCode.FORBIDDEN, "Can not access: "+fname ));
- return null;
- }
- if( fname.indexOf( ".." ) >= 0 ) {
- log.error("Invalid path: "+ fname);
- rsp.setException(new SolrException( SolrException.ErrorCode.FORBIDDEN, "Invalid path: "+fname ));
- return null;
- }
- adminFile = new File( configdir, fname );
- }
- return adminFile;
- }
-
- public final Set<String> getHiddenFiles() {
- return hiddenFiles;
- }
-
- //////////////////////// SolrInfoMBeans methods //////////////////////
-
- @Override
- public String getDescription() {
- return "Admin Config File -- view or update config files directly";
- }
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/SolrInfoMBeanHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SolrInfoMBeanHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SolrInfoMBeanHandler.java
deleted file mode 100644
index f9a3c05..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/SolrInfoMBeanHandler.java
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * 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 org.apache.commons.io.IOUtils;
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.client.solrj.impl.XMLResponseParser;
-import org.apache.solr.core.SolrInfoBean;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.util.ContentStream;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.response.BinaryResponseWriter;
-import org.apache.solr.response.SolrQueryResponse;
-
-import java.io.StringReader;
-import java.text.NumberFormat;
-import java.util.Locale;
-import java.util.Set;
-import java.util.Map;
-import java.util.HashSet;
-
-/**
- * A request handler that provides info about all
- * registered SolrInfoMBeans.
- */
-@SuppressWarnings("unchecked")
-public class SolrInfoMBeanHandler extends RequestHandlerBase {
-
- /**
- * Take an array of any type and generate a Set containing the toString.
- * Set is guarantee to never be null (but may be empty)
- */
- private Set<String> arrayToSet(Object[] arr) {
- HashSet<String> r = new HashSet<>();
- if (null == arr) return r;
- for (Object o : arr) {
- if (null != o) r.add(o.toString());
- }
- return r;
- }
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
- NamedList<NamedList<NamedList<Object>>> cats = getMBeanInfo(req);
- if(req.getParams().getBool("diff", false)) {
- ContentStream body = null;
- try {
- body = req.getContentStreams().iterator().next();
- }
- catch(Exception ex) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "missing content-stream for diff");
- }
- String content = IOUtils.toString(body.getReader());
-
- NamedList<NamedList<NamedList<Object>>> ref = fromXML(content);
-
-
- // Normalize the output
- SolrQueryResponse wrap = new SolrQueryResponse();
- wrap.add("solr-mbeans", cats);
- cats = (NamedList<NamedList<NamedList<Object>>>)
- BinaryResponseWriter.getParsedResponse(req, wrap).get("solr-mbeans");
-
- // Get rid of irrelevant things
- ref = normalize(ref);
- cats = normalize(cats);
-
- // Only the changes
- boolean showAll = req.getParams().getBool("all", false);
- rsp.add("solr-mbeans", getDiff(ref,cats, showAll));
- }
- else {
- rsp.add("solr-mbeans", cats);
- }
- rsp.setHttpCaching(false); // never cache, no matter what init config looks like
- }
-
- static NamedList<NamedList<NamedList<Object>>> fromXML(String content) {
- int idx = content.indexOf("<response>");
- if(idx<0) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Body does not appear to be an XML response");
- }
-
- try {
- XMLResponseParser parser = new XMLResponseParser();
- return (NamedList<NamedList<NamedList<Object>>>)
- parser.processResponse(new StringReader(content)).get("solr-mbeans");
- }
- catch(Exception ex) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Unable to read original XML", ex);
- }
- }
-
- protected NamedList<NamedList<NamedList<Object>>> getMBeanInfo(SolrQueryRequest req) {
-
- NamedList<NamedList<NamedList<Object>>> cats = new NamedList<>();
-
- String[] requestedCats = req.getParams().getParams("cat");
- if (null == requestedCats || 0 == requestedCats.length) {
- for (SolrInfoBean.Category cat : SolrInfoBean.Category.values()) {
- cats.add(cat.name(), new SimpleOrderedMap<NamedList<Object>>());
- }
- } else {
- for (String catName : requestedCats) {
- cats.add(catName,new SimpleOrderedMap<NamedList<Object>>());
- }
- }
-
- Set<String> requestedKeys = arrayToSet(req.getParams().getParams("key"));
-
- Map<String, SolrInfoBean> reg = req.getCore().getInfoRegistry();
- for (Map.Entry<String, SolrInfoBean> entry : reg.entrySet()) {
- addMBean(req, cats, requestedKeys, entry.getKey(),entry.getValue());
- }
-
- for (SolrInfoBean infoMBean : req.getCore().getCoreContainer().getResourceLoader().getInfoMBeans()) {
- addMBean(req,cats,requestedKeys,infoMBean.getName(),infoMBean);
- }
- return cats;
- }
-
- private void addMBean(SolrQueryRequest req, NamedList<NamedList<NamedList<Object>>> cats, Set<String> requestedKeys, String key, SolrInfoBean m) {
- if ( ! ( requestedKeys.isEmpty() || requestedKeys.contains(key) ) ) return;
- NamedList<NamedList<Object>> catInfo = cats.get(m.getCategory().name());
- if ( null == catInfo ) return;
- NamedList<Object> mBeanInfo = new SimpleOrderedMap<>();
- mBeanInfo.add("class", m.getName());
- mBeanInfo.add("description", m.getDescription());
-
- if (req.getParams().getFieldBool(key, "stats", false))
- mBeanInfo.add("stats", m.getMetricsSnapshot());
-
- catInfo.add(key, mBeanInfo);
- }
-
- 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);
- diff.add( "_changed_", true ); // flag the changed thing
- 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;
- }
-
- public NamedList diffNamedList(NamedList ref, NamedList now) {
- NamedList out = new SimpleOrderedMap();
- for(int i=0; i<ref.size(); i++) {
- String name = ref.getName(i);
- Object r = ref.getVal(i);
- Object n = now.get(name);
- if (n == null) {
- if (r != null) {
- out.add("REMOVE " + name, r);
- now.remove(name);
- }
- }
- else if (r != null) {
- out.add(name, diffObject(r, n));
- now.remove(name);
- }
- }
-
- for(int i=0; i<now.size(); i++) {
- String name = now.getName(i);
- Object v = now.getVal(i);
- if(v!=null) {
- out.add("ADD "+name, v);
- }
- }
- return out;
- }
-
- public Object diffObject(Object ref, Object now) {
- if (now instanceof Map) {
- now = new NamedList((Map)now);
- }
- if(ref instanceof NamedList) {
- return diffNamedList((NamedList)ref, (NamedList)now);
- }
- if(ref.equals(now)) {
- return ref;
- }
- StringBuilder str = new StringBuilder();
- str.append("Was: ")
- .append(ref).append(", Now: ").append(now);
-
- if(ref instanceof Number) {
- NumberFormat nf = NumberFormat.getIntegerInstance(Locale.ROOT);
- if((ref instanceof Double) || (ref instanceof Float)) {
- nf = NumberFormat.getInstance(Locale.ROOT);
- }
- double dref = ((Number)ref).doubleValue();
- double dnow = ((Number)now).doubleValue();
- double diff = Double.NaN;
- if(Double.isNaN(dref)) {
- diff = dnow;
- }
- else if(Double.isNaN(dnow)) {
- diff = dref;
- }
- else {
- diff = dnow-dref;
- }
- str.append( ", Delta: ").append(nf.format(diff));
- }
- return str.toString();
- }
-
-
- /**
- * The 'avgRequestsPerSecond' field will make everything look like it changed
- */
- public NamedList normalize(NamedList input) {
- input.remove("avgRequestsPerSecond");
- for(int i=0; i<input.size(); i++) {
- Object v = input.getVal(i);
- if(v instanceof NamedList) {
- input.setVal(i, normalize((NamedList)v));
- }
- }
- return input;
- }
-
-
- @Override
- public String getDescription() {
- return "Get Info (and statistics) for registered SolrInfoMBeans";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/SplitOp.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SplitOp.java b/solr/core/src/java/org/apache/solr/handler/admin/SplitOp.java
deleted file mode 100644
index 31382c3..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/SplitOp.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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.lang.invoke.MethodHandles;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.solr.cloud.CloudDescriptor;
-import org.apache.solr.cloud.ZkShardTerms;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.cloud.ClusterState;
-import org.apache.solr.common.cloud.DocCollection;
-import org.apache.solr.common.cloud.DocRouter;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.params.CommonAdminParams;
-import org.apache.solr.common.params.CoreAdminParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.request.LocalSolrQueryRequest;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.update.SolrIndexSplitter;
-import org.apache.solr.update.SplitIndexCommand;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.solr.common.cloud.DocCollection.DOC_ROUTER;
-import static org.apache.solr.common.params.CommonParams.PATH;
-
-
-class SplitOp implements CoreAdminHandler.CoreAdminOp {
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- @Override
- public void execute(CoreAdminHandler.CallInfo it) throws Exception {
- SolrParams params = it.req.getParams();
- List<DocRouter.Range> ranges = null;
-
- String[] pathsArr = params.getParams(PATH);
- String rangesStr = params.get(CoreAdminParams.RANGES); // ranges=a-b,c-d,e-f
- if (rangesStr != null) {
- String[] rangesArr = rangesStr.split(",");
- if (rangesArr.length == 0) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "There must be at least one range specified to split an index");
- } else {
- ranges = new ArrayList<>(rangesArr.length);
- for (String r : rangesArr) {
- try {
- ranges.add(DocRouter.DEFAULT.fromString(r));
- } catch (Exception e) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Exception parsing hexadecimal hash range: " + r, e);
- }
- }
- }
- }
- String splitKey = params.get("split.key");
- String[] newCoreNames = params.getParams("targetCore");
- String cname = params.get(CoreAdminParams.CORE, "");
-
- if ((pathsArr == null || pathsArr.length == 0) && (newCoreNames == null || newCoreNames.length == 0)) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Either path or targetCore param must be specified");
- }
-
- log.info("Invoked split action for core: " + cname);
- String methodStr = params.get(CommonAdminParams.SPLIT_METHOD, SolrIndexSplitter.SplitMethod.REWRITE.toLower());
- SolrIndexSplitter.SplitMethod splitMethod = SolrIndexSplitter.SplitMethod.get(methodStr);
- if (splitMethod == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unsupported value of '" + CommonAdminParams.SPLIT_METHOD + "': " + methodStr);
- }
- SolrCore parentCore = it.handler.coreContainer.getCore(cname);
- List<SolrCore> newCores = null;
- SolrQueryRequest req = null;
-
- try {
- // TODO: allow use of rangesStr in the future
- List<String> paths = null;
- int partitions = pathsArr != null ? pathsArr.length : newCoreNames.length;
-
- DocRouter router = null;
- String routeFieldName = null;
- if (it.handler.coreContainer.isZooKeeperAware()) {
- ClusterState clusterState = it.handler.coreContainer.getZkController().getClusterState();
- String collectionName = parentCore.getCoreDescriptor().getCloudDescriptor().getCollectionName();
- DocCollection collection = clusterState.getCollection(collectionName);
- String sliceName = parentCore.getCoreDescriptor().getCloudDescriptor().getShardId();
- Slice slice = collection.getSlice(sliceName);
- router = collection.getRouter() != null ? collection.getRouter() : DocRouter.DEFAULT;
- if (ranges == null) {
- DocRouter.Range currentRange = slice.getRange();
- ranges = currentRange != null ? router.partitionRange(partitions, currentRange) : null;
- }
- Object routerObj = collection.get(DOC_ROUTER); // for back-compat with Solr 4.4
- if (routerObj instanceof Map) {
- Map routerProps = (Map) routerObj;
- routeFieldName = (String) routerProps.get("field");
- }
- }
-
- if (pathsArr == null) {
- newCores = new ArrayList<>(partitions);
- for (String newCoreName : newCoreNames) {
- SolrCore newcore = it.handler.coreContainer.getCore(newCoreName);
- if (newcore != null) {
- newCores.add(newcore);
- if (it.handler.coreContainer.isZooKeeperAware()) {
- // this core must be the only replica in its shard otherwise
- // we cannot guarantee consistency between replicas because when we add data to this replica
- CloudDescriptor cd = newcore.getCoreDescriptor().getCloudDescriptor();
- ClusterState clusterState = it.handler.coreContainer.getZkController().getClusterState();
- if (clusterState.getCollection(cd.getCollectionName()).getSlice(cd.getShardId()).getReplicas().size() != 1) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- "Core with core name " + newCoreName + " must be the only replica in shard " + cd.getShardId());
- }
- }
- } else {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Core with core name " + newCoreName + " expected but doesn't exist.");
- }
- }
- } else {
- paths = Arrays.asList(pathsArr);
- }
-
- req = new LocalSolrQueryRequest(parentCore, params);
-
- SplitIndexCommand cmd = new SplitIndexCommand(req, it.rsp, paths, newCores, ranges, router, routeFieldName, splitKey, splitMethod);
- parentCore.getUpdateHandler().split(cmd);
-
- if (it.handler.coreContainer.isZooKeeperAware()) {
- for (SolrCore newcore : newCores) {
- // the index of the core changed from empty to have some data, its term must be not zero
- CloudDescriptor cd = newcore.getCoreDescriptor().getCloudDescriptor();
- ZkShardTerms zkShardTerms = it.handler.coreContainer.getZkController().getShardTerms(cd.getCollectionName(), cd.getShardId());
- zkShardTerms.ensureHighestTermsAreNotZero();
- }
- }
-
- // After the split has completed, someone (here?) should start the process of replaying the buffered updates.
- } catch (Exception e) {
- log.error("ERROR executing split:", e);
- throw e;
- } finally {
- if (req != null) req.close();
- if (parentCore != null) parentCore.close();
- if (newCores != null) {
- for (SolrCore newCore : newCores) {
- newCore.close();
- }
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/StatusOp.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/StatusOp.java b/solr/core/src/java/org/apache/solr/handler/admin/StatusOp.java
deleted file mode 100644
index f2bddbd..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/StatusOp.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.solr.common.params.CoreAdminParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.core.CoreContainer;
-
-
-class StatusOp implements CoreAdminHandler.CoreAdminOp {
- @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);
- }
- 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);
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
deleted file mode 100644
index d8e10ab..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * 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.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;
-import java.util.LinkedList;
-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;
-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.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();
-
- /**
- * <p>
- * 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.
- * </p>
- *
- * <p>
- * TODO: should we refactor this (and the associated logic) into a helper method for any other places
- * where DNS is used?
- * </p>
- * @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 '{}' sysprop to true on startup to prevent future lookups if DNS can not be fixed.",
- readableTime, PREVENT_REVERSE_DNS_OF_LOCALHOST_SYSPROP);
-
- }
- }
-
- @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( "system", getSystemInfo() );
- if (solrCloudMode) {
- rsp.add("node", getCoreContainer(req, core).getZkController().getNodeName());
- }
- }
-
- 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<Object> getCoreInfo( SolrCore core, IndexSchema schema ) {
- SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
-
- info.add( "schema", schema != null ? schema.getSchemaName():"no schema!" );
-
- // Host
- info.add( "host", hostname );
-
- // Now
- info.add( "now", new Date() );
-
- // Start Time
- info.add( "start", core.getStartTimeStamp() );
-
- // Solr Home
- SimpleOrderedMap<Object> dirs = new SimpleOrderedMap<>();
- dirs.add( "cwd" , new File( System.getProperty("user.dir")).getAbsolutePath() );
- dirs.add("instance", core.getResourceLoader().getInstancePath().toString());
- try {
- dirs.add( "data", core.getDirectoryFactory().normalize(core.getDataDir()));
- } catch (IOException e) {
- log.warn("Problem getting the normalized data directory path", e);
- dirs.add( "data", "N/A" );
- }
- dirs.add( "dirimpl", core.getDirectoryFactory().getClass().getName());
- try {
- dirs.add( "index", core.getDirectoryFactory().normalize(core.getIndexDir()) );
- } catch (IOException e) {
- log.warn("Problem getting the normalized index directory path", e);
- dirs.add( "index", "N/A" );
- }
- info.add( "directory", dirs );
- return info;
- }
-
- /**
- * Get system info
- */
- public static SimpleOrderedMap<Object> getSystemInfo() {
- SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
-
- OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
- info.add(NAME, os.getName()); // add at least this one
- // add remaining ones dynamically using Java Beans API
- // also those from JVM implementation-specific classes
- MetricUtils.addMXBeanMetrics(os, MetricUtils.OS_MXBEAN_CLASSES, null, (name, metric) -> {
- if (info.get(name) == null) {
- info.add(name, ((Gauge) metric).getValue());
- }
- });
-
- // 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
- */
- 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;
- }
-
- private static SimpleOrderedMap<Object> getLuceneInfo() {
- SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
-
- Package p = SolrCore.class.getPackage();
-
- info.add( "solr-spec-version", p.getSpecificationVersion() );
- info.add( "solr-impl-version", p.getImplementationVersion() );
-
- p = LucenePackage.class.getPackage();
-
- info.add( "lucene-spec-version", p.getSpecificationVersion() );
- info.add( "lucene-impl-version", p.getImplementationVersion() );
-
- return info;
- }
-
- //////////////////////// SolrInfoMBeans methods //////////////////////
-
- @Override
- public String getDescription() {
- return "Get System Info";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-
- private static final long ONE_KB = 1024;
- private static final long ONE_MB = ONE_KB * ONE_KB;
- private static final long ONE_GB = ONE_KB * ONE_MB;
-
- /**
- * Return good default units based on byte size.
- */
- private static String humanReadableUnits(long bytes, DecimalFormat df) {
- String newSizeAndUnits;
-
- if (bytes / ONE_GB > 0) {
- newSizeAndUnits = String.valueOf(df.format((float)bytes / ONE_GB)) + " GB";
- } else if (bytes / ONE_MB > 0) {
- newSizeAndUnits = String.valueOf(df.format((float)bytes / ONE_MB)) + " MB";
- } else if (bytes / ONE_KB > 0) {
- newSizeAndUnits = String.valueOf(df.format((float)bytes / ONE_KB)) + " KB";
- } else {
- newSizeAndUnits = String.valueOf(bytes) + " bytes";
- }
-
- return newSizeAndUnits;
- }
-
- private static List<String> getInputArgumentsRedacted(RuntimeMXBean mx) {
- List<String> list = new LinkedList<>();
- for (String arg : mx.getInputArguments()) {
- if (arg.startsWith("-D") && arg.contains("=") && RedactionUtils.isSystemPropertySensitive(arg.substring(2, arg.indexOf("=")))) {
- list.add(String.format(Locale.ROOT, "%s=%s", arg.substring(0, arg.indexOf("=")), REDACT_STRING));
- } else {
- list.add(arg);
- }
- }
- return list;
- }
-
-}
-
-
-
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/ThreadDumpHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ThreadDumpHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/ThreadDumpHandler.java
deleted file mode 100644
index bb5b3ee..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/ThreadDumpHandler.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.IOException;
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-import java.lang.management.ThreadMXBean;
-import java.util.Locale;
-
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-
-import static org.apache.solr.common.params.CommonParams.ID;
-import static org.apache.solr.common.params.CommonParams.NAME;
-
-/**
- *
- * @since solr 1.2
- */
-public class ThreadDumpHandler extends RequestHandlerBase
-{
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException
- {
- SimpleOrderedMap<Object> system = new SimpleOrderedMap<>();
- rsp.add( "system", system );
-
- ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();
-
- // Thread Count
- SimpleOrderedMap<Object> nl = new SimpleOrderedMap<>();
- nl.add( "current",tmbean.getThreadCount() );
- nl.add( "peak", tmbean.getPeakThreadCount() );
- nl.add( "daemon", tmbean.getDaemonThreadCount() );
- system.add( "threadCount", nl );
-
- // Deadlocks
- ThreadInfo[] tinfos;
- long[] tids = tmbean.findMonitorDeadlockedThreads();
- if (tids != null) {
- tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
- NamedList<SimpleOrderedMap<Object>> lst = new NamedList<>();
- for (ThreadInfo ti : tinfos) {
- if (ti != null) {
- lst.add( "thread", getThreadInfo( ti, tmbean ) );
- }
- }
- system.add( "deadlocks", lst );
- }
-
- // Now show all the threads....
- tids = tmbean.getAllThreadIds();
- tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
- NamedList<SimpleOrderedMap<Object>> lst = new NamedList<>();
- for (ThreadInfo ti : tinfos) {
- if (ti != null) {
- lst.add( "thread", getThreadInfo( ti, tmbean ) );
- }
- }
- system.add( "threadDump", lst );
- rsp.setHttpCaching(false);
- }
-
- //--------------------------------------------------------------------------------
- //--------------------------------------------------------------------------------
-
- private static SimpleOrderedMap<Object> getThreadInfo( ThreadInfo ti, ThreadMXBean tmbean ) {
- SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
- long tid = ti.getThreadId();
-
- info.add( ID, tid );
- info.add(NAME, ti.getThreadName());
- info.add( "state", ti.getThreadState().toString() );
-
- if (ti.getLockName() != null) {
- info.add( "lock", ti.getLockName() );
- }
- if (ti.isSuspended()) {
- info.add( "suspended", true );
- }
- if (ti.isInNative()) {
- info.add( "native", true );
- }
-
- if (tmbean.isThreadCpuTimeSupported()) {
- info.add( "cpuTime", formatNanos(tmbean.getThreadCpuTime(tid)) );
- info.add( "userTime", formatNanos(tmbean.getThreadUserTime(tid)) );
- }
-
- if (ti.getLockOwnerName() != null) {
- SimpleOrderedMap<Object> owner = new SimpleOrderedMap<>();
- owner.add(NAME, ti.getLockOwnerName());
- owner.add( ID, ti.getLockOwnerId() );
- }
-
- // Add the stack trace
- int i=0;
- String[] trace = new String[ti.getStackTrace().length];
- for( StackTraceElement ste : ti.getStackTrace()) {
- trace[i++] = ste.toString();
- }
- info.add( "stackTrace", trace );
- return info;
- }
-
- private static String formatNanos(long ns) {
- return String.format(Locale.ROOT, "%.4fms", ns / (double) 1000000);
- }
-
- //////////////////////// SolrInfoMBeans methods //////////////////////
-
- @Override
- public String getDescription() {
- return "Thread Dump";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-}