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:35 UTC
[14/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/CoreAdminHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
deleted file mode 100644
index 66dc39e..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
+++ /dev/null
@@ -1,427 +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.lang.invoke.MethodHandles;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-
-import com.google.common.collect.ImmutableMap;
-import org.apache.commons.lang.StringUtils;
-import org.apache.solr.api.Api;
-import org.apache.solr.cloud.CloudDescriptor;
-import org.apache.solr.cloud.ZkController;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.params.CommonAdminParams;
-import org.apache.solr.common.params.CoreAdminParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.ExecutorUtil;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.CoreDescriptor;
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.logging.MDCLoggingContext;
-import org.apache.solr.metrics.SolrMetricManager;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.security.AuthorizationContext;
-import org.apache.solr.security.PermissionNameProvider;
-import org.apache.solr.util.DefaultSolrThreadFactory;
-import org.apache.solr.util.stats.MetricUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
-
-import static org.apache.solr.common.params.CoreAdminParams.ACTION;
-import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.STATUS;
-import static org.apache.solr.security.PermissionNameProvider.Name.CORE_EDIT_PERM;
-import static org.apache.solr.security.PermissionNameProvider.Name.CORE_READ_PERM;
-
-/**
- *
- * @since solr 1.3
- */
-public class CoreAdminHandler extends RequestHandlerBase implements PermissionNameProvider {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- protected final CoreContainer coreContainer;
- protected final Map<String, Map<String, TaskObject>> requestStatusMap;
- private final CoreAdminHandlerApi coreAdminHandlerApi;
-
- protected ExecutorService parallelExecutor = ExecutorUtil.newMDCAwareFixedThreadPool(50,
- new DefaultSolrThreadFactory("parallelCoreAdminExecutor"));
-
- protected static int MAX_TRACKED_REQUESTS = 100;
- public static String RUNNING = "running";
- public static String COMPLETED = "completed";
- public static String FAILED = "failed";
- public static String RESPONSE = "Response";
- public static String RESPONSE_STATUS = "STATUS";
- public static String RESPONSE_MESSAGE = "msg";
-
- public CoreAdminHandler() {
- super();
- // Unlike most request handlers, CoreContainer initialization
- // should happen in the constructor...
- this.coreContainer = null;
- HashMap<String, Map<String, TaskObject>> map = new HashMap<>(3, 1.0f);
- map.put(RUNNING, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
- map.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
- map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
- requestStatusMap = Collections.unmodifiableMap(map);
- coreAdminHandlerApi = new CoreAdminHandlerApi(this);
- }
-
-
- /**
- * Overloaded ctor to inject CoreContainer into the handler.
- *
- * @param coreContainer Core Container of the solr webapp installed.
- */
- public CoreAdminHandler(final CoreContainer coreContainer) {
- this.coreContainer = coreContainer;
- HashMap<String, Map<String, TaskObject>> map = new HashMap<>(3, 1.0f);
- map.put(RUNNING, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
- map.put(COMPLETED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
- map.put(FAILED, Collections.synchronizedMap(new LinkedHashMap<String, TaskObject>()));
- requestStatusMap = Collections.unmodifiableMap(map);
- coreAdminHandlerApi = new CoreAdminHandlerApi(this);
- }
-
-
- @Override
- final public void init(NamedList args) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "CoreAdminHandler should not be configured in solrconf.xml\n" +
- "it is a special Handler configured directly by the RequestDispatcher");
- }
-
- @Override
- public void initializeMetrics(SolrMetricManager manager, String registryName, String tag, String scope) {
- super.initializeMetrics(manager, registryName, tag, scope);
- parallelExecutor = MetricUtils.instrumentedExecutorService(parallelExecutor, this, manager.registry(registryName),
- SolrMetricManager.mkName("parallelCoreAdminExecutor", getCategory().name(),scope, "threadPool"));
- }
- @Override
- public Boolean registerV2() {
- return Boolean.TRUE;
- }
-
- /**
- * The instance of CoreContainer this handler handles. This should be the CoreContainer instance that created this
- * handler.
- *
- * @return a CoreContainer instance
- */
- public CoreContainer getCoreContainer() {
- return this.coreContainer;
- }
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
- // Make sure the cores is enabled
- try {
- CoreContainer cores = getCoreContainer();
- if (cores == null) {
- throw new SolrException(ErrorCode.BAD_REQUEST,
- "Core container instance missing");
- }
- //boolean doPersist = false;
- final String taskId = req.getParams().get(CommonAdminParams.ASYNC);
- final TaskObject taskObject = new TaskObject(taskId);
-
- if(taskId != null) {
- // Put the tasks into the maps for tracking
- if (getRequestStatusMap(RUNNING).containsKey(taskId) || getRequestStatusMap(COMPLETED).containsKey(taskId) || getRequestStatusMap(FAILED).containsKey(taskId)) {
- throw new SolrException(ErrorCode.BAD_REQUEST,
- "Duplicate request with the same requestid found.");
- }
-
- addTask(RUNNING, taskObject);
- }
-
- // Pick the action
- CoreAdminOperation op = opMap.get(req.getParams().get(ACTION, STATUS.toString()).toLowerCase(Locale.ROOT));
- if (op == null) {
- handleCustomAction(req, rsp);
- return;
- }
-
- final CallInfo callInfo = new CallInfo(this, req, rsp, op);
- String coreName = req.getParams().get(CoreAdminParams.CORE);
- if (coreName == null) {
- coreName = req.getParams().get(CoreAdminParams.NAME);
- }
- MDCLoggingContext.setCoreName(coreName);
- if (taskId == null) {
- callInfo.call();
- } else {
- try {
- MDC.put("CoreAdminHandler.asyncId", taskId);
- MDC.put("CoreAdminHandler.action", op.action.toString());
- parallelExecutor.execute(() -> {
- boolean exceptionCaught = false;
- try {
- callInfo.call();
- taskObject.setRspObject(callInfo.rsp);
- } catch (Exception e) {
- exceptionCaught = true;
- taskObject.setRspObjectFromException(e);
- } finally {
- removeTask("running", taskObject.taskId);
- if (exceptionCaught) {
- addTask("failed", taskObject, true);
- } else
- addTask("completed", taskObject, true);
- }
- });
- } finally {
- MDC.remove("CoreAdminHandler.asyncId");
- MDC.remove("CoreAdminHandler.action");
- }
- }
- } finally {
- rsp.setHttpCaching(false);
-
- }
- }
-
- /**
- * Handle Custom Action.
- * <p>
- * This method could be overridden by derived classes to handle custom actions. <br> By default - this method throws a
- * solr exception. Derived classes are free to write their derivation if necessary.
- */
- protected void handleCustomAction(SolrQueryRequest req, SolrQueryResponse rsp) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unsupported operation: " +
- req.getParams().get(ACTION));
- }
-
- public static ImmutableMap<String, String> paramToProp = ImmutableMap.<String, String>builder()
- .put(CoreAdminParams.CONFIG, CoreDescriptor.CORE_CONFIG)
- .put(CoreAdminParams.SCHEMA, CoreDescriptor.CORE_SCHEMA)
- .put(CoreAdminParams.DATA_DIR, CoreDescriptor.CORE_DATADIR)
- .put(CoreAdminParams.ULOG_DIR, CoreDescriptor.CORE_ULOGDIR)
- .put(CoreAdminParams.CONFIGSET, CoreDescriptor.CORE_CONFIGSET)
- .put(CoreAdminParams.LOAD_ON_STARTUP, CoreDescriptor.CORE_LOADONSTARTUP)
- .put(CoreAdminParams.TRANSIENT, CoreDescriptor.CORE_TRANSIENT)
- .put(CoreAdminParams.SHARD, CoreDescriptor.CORE_SHARD)
- .put(CoreAdminParams.COLLECTION, CoreDescriptor.CORE_COLLECTION)
- .put(CoreAdminParams.ROLES, CoreDescriptor.CORE_ROLES)
- .put(CoreAdminParams.CORE_NODE_NAME, CoreDescriptor.CORE_NODE_NAME)
- .put(ZkStateReader.NUM_SHARDS_PROP, CloudDescriptor.NUM_SHARDS)
- .put(CoreAdminParams.REPLICA_TYPE, CloudDescriptor.REPLICA_TYPE)
- .build();
-
- protected static Map<String, String> buildCoreParams(SolrParams params) {
-
- Map<String, String> coreParams = new HashMap<>();
-
- // standard core create parameters
- for (String param : paramToProp.keySet()) {
- String value = params.get(param, null);
- if (StringUtils.isNotEmpty(value)) {
- coreParams.put(paramToProp.get(param), value);
- }
- }
-
- // extra properties
- Iterator<String> paramsIt = params.getParameterNamesIterator();
- while (paramsIt.hasNext()) {
- String param = paramsIt.next();
- if (param.startsWith(CoreAdminParams.PROPERTY_PREFIX)) {
- String propName = param.substring(CoreAdminParams.PROPERTY_PREFIX.length());
- String propValue = params.get(param);
- coreParams.put(propName, propValue);
- }
- if (param.startsWith(ZkController.COLLECTION_PARAM_PREFIX)) {
- coreParams.put(param, params.get(param));
- }
- }
-
- return coreParams;
- }
-
-
-
- protected static String normalizePath(String path) {
- if (path == null)
- return null;
- path = path.replace('/', File.separatorChar);
- path = path.replace('\\', File.separatorChar);
- return path;
- }
-
- public static ModifiableSolrParams params(String... params) {
- ModifiableSolrParams msp = new ModifiableSolrParams();
- for (int i=0; i<params.length; i+=2) {
- msp.add(params[i], params[i+1]);
- }
- return msp;
- }
-
- //////////////////////// SolrInfoMBeans methods //////////////////////
-
- @Override
- public String getDescription() {
- return "Manage Multiple Solr Cores";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-
- @Override
- public Name getPermissionName(AuthorizationContext ctx) {
- String action = ctx.getParams().get(CoreAdminParams.ACTION);
- if (action == null) return CORE_READ_PERM;
- CoreAdminParams.CoreAdminAction coreAction = CoreAdminParams.CoreAdminAction.get(action);
- if (coreAction == null) return CORE_READ_PERM;
- return coreAction.isRead ?
- CORE_READ_PERM :
- CORE_EDIT_PERM;
- }
-
- /**
- * Helper class to manage the tasks to be tracked.
- * This contains the taskId, request and the response (if available).
- */
- static class TaskObject {
- String taskId;
- String rspInfo;
-
- public TaskObject(String taskId) {
- this.taskId = taskId;
- }
-
- public String getRspObject() {
- return rspInfo;
- }
-
- public void setRspObject(SolrQueryResponse rspObject) {
- this.rspInfo = rspObject.getToLogAsString("TaskId: " + this.taskId);
- }
-
- public void setRspObjectFromException(Exception e) {
- this.rspInfo = e.getMessage();
- }
- }
-
- /**
- * Helper method to add a task to a tracking type.
- */
- void addTask(String type, TaskObject o, boolean limit) {
- synchronized (getRequestStatusMap(type)) {
- if(limit && getRequestStatusMap(type).size() == MAX_TRACKED_REQUESTS) {
- String key = getRequestStatusMap(type).entrySet().iterator().next().getKey();
- getRequestStatusMap(type).remove(key);
- }
- addTask(type, o);
- }
- }
-
-
- private void addTask(String type, TaskObject o) {
- synchronized (getRequestStatusMap(type)) {
- getRequestStatusMap(type).put(o.taskId, o);
- }
- }
-
- /**
- * Helper method to remove a task from a tracking map.
- */
- private void removeTask(String map, String taskId) {
- synchronized (getRequestStatusMap(map)) {
- getRequestStatusMap(map).remove(taskId);
- }
- }
-
- /**
- * Helper method to get a request status map given the name.
- */
- Map<String, TaskObject> getRequestStatusMap(String key) {
- return requestStatusMap.get(key);
- }
-
- /**
- * Method to ensure shutting down of the ThreadPool Executor.
- */
- public void shutdown() {
- if (parallelExecutor != null && !parallelExecutor.isShutdown())
- ExecutorUtil.shutdownAndAwaitTermination(parallelExecutor);
- }
-
- private static final Map<String, CoreAdminOperation> opMap = new HashMap<>();
-
-
- static class CallInfo {
- final CoreAdminHandler handler;
- final SolrQueryRequest req;
- final SolrQueryResponse rsp;
- final CoreAdminOperation op;
-
- CallInfo(CoreAdminHandler handler, SolrQueryRequest req, SolrQueryResponse rsp, CoreAdminOperation op) {
- this.handler = handler;
- this.req = req;
- this.rsp = rsp;
- this.op = op;
- }
-
- void call() throws Exception {
- op.execute(this);
- }
-
- }
-
- @Override
- public Collection<Api> getApis() {
- return coreAdminHandlerApi.getApis();
- }
-
- static {
- for (CoreAdminOperation op : CoreAdminOperation.values())
- opMap.put(op.action.toString().toLowerCase(Locale.ROOT), op);
- }
- /**
- * used by the INVOKE action of core admin handler
- */
- public interface Invocable {
- Map<String, Object> invoke(SolrQueryRequest req);
- }
-
- interface CoreAdminOp {
- /**
- * @param it request/response object
- *
- * If the request is invalid throw a SolrException with SolrException.ErrorCode.BAD_REQUEST ( 400 )
- * If the execution of the command fails throw a SolrException with SolrException.ErrorCode.SERVER_ERROR ( 500 )
- *
- * Any non-SolrException's are wrapped at a higher level as a SolrException with SolrException.ErrorCode.SERVER_ERROR.
- */
- void execute(CallInfo it) throws Exception;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandlerApi.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandlerApi.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandlerApi.java
deleted file mode 100644
index cb2623d..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandlerApi.java
+++ /dev/null
@@ -1,85 +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.Arrays;
-import java.util.Collection;
-import java.util.EnumMap;
-import java.util.Map;
-
-import org.apache.solr.client.solrj.request.CollectionApiMapping.CommandMeta;
-import org.apache.solr.client.solrj.request.CollectionApiMapping.V2EndPoint;
-import org.apache.solr.client.solrj.request.CoreApiMapping;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-
-public class CoreAdminHandlerApi extends BaseHandlerApiSupport {
- private final CoreAdminHandler handler;
- static Collection<ApiCommand> apiCommands = createMapping();
-
- private static Collection<ApiCommand> createMapping() {
- Map<CoreApiMapping.Meta, ApiCommand> result = new EnumMap<>(CoreApiMapping.Meta.class);
-
- for (CoreApiMapping.Meta meta : CoreApiMapping.Meta.values()) {
-
- for (CoreAdminOperation op : CoreAdminOperation.values()) {
- if (op.action == meta.action) {
- result.put(meta, new ApiCommand() {
- @Override
- public CommandMeta meta() {
- return meta;
- }
-
- @Override
- public void invoke(SolrQueryRequest req, SolrQueryResponse rsp, BaseHandlerApiSupport apiHandler) throws Exception {
- op.execute(new CoreAdminHandler.CallInfo(((CoreAdminHandlerApi) apiHandler).handler,
- req,
- rsp,
- op));
- }
- });
- }
- }
- }
-
- for (CoreApiMapping.Meta meta : CoreApiMapping.Meta.values()) {
- if (result.get(meta) == null) {
- throw new RuntimeException("No implementation for " + meta.name());
- }
- }
-
- return result.values();
- }
-
- public CoreAdminHandlerApi(CoreAdminHandler handler) {
- this.handler = handler;
- }
-
-
- @Override
- protected Collection<ApiCommand> getCommands() {
- return apiCommands;
- }
-
- @Override
- protected Collection<V2EndPoint> getEndPoints() {
- return Arrays.asList(CoreApiMapping.EndPoint.values());
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java b/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java
deleted file mode 100644
index 1ccc7d4..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminOperation.java
+++ /dev/null
@@ -1,368 +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.nio.file.Path;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Optional;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.solr.cloud.CloudDescriptor;
-import org.apache.solr.cloud.ZkController;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-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.common.util.Utils;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.CoreDescriptor;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.SolrInfoBean;
-import org.apache.solr.core.snapshots.SolrSnapshotManager;
-import org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager;
-import org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData;
-import org.apache.solr.handler.admin.CoreAdminHandler.CoreAdminOp;
-import org.apache.solr.metrics.SolrMetricManager;
-import org.apache.solr.search.SolrIndexSearcher;
-import org.apache.solr.update.UpdateLog;
-import org.apache.solr.util.NumberUtils;
-import org.apache.solr.util.PropertiesUtil;
-import org.apache.solr.util.RefCounted;
-import org.apache.solr.util.TestInjection;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.solr.common.params.CommonParams.NAME;
-import static org.apache.solr.common.params.CoreAdminParams.COLLECTION;
-import static org.apache.solr.common.params.CoreAdminParams.CoreAdminAction.*;
-import static org.apache.solr.common.params.CoreAdminParams.REPLICA;
-import static org.apache.solr.common.params.CoreAdminParams.SHARD;
-import static org.apache.solr.handler.admin.CoreAdminHandler.COMPLETED;
-import static org.apache.solr.handler.admin.CoreAdminHandler.CallInfo;
-import static org.apache.solr.handler.admin.CoreAdminHandler.FAILED;
-import static org.apache.solr.handler.admin.CoreAdminHandler.RESPONSE;
-import static org.apache.solr.handler.admin.CoreAdminHandler.RESPONSE_MESSAGE;
-import static org.apache.solr.handler.admin.CoreAdminHandler.RESPONSE_STATUS;
-import static org.apache.solr.handler.admin.CoreAdminHandler.RUNNING;
-import static org.apache.solr.handler.admin.CoreAdminHandler.buildCoreParams;
-import static org.apache.solr.handler.admin.CoreAdminHandler.normalizePath;
-
-enum CoreAdminOperation implements CoreAdminOp {
-
- CREATE_OP(CREATE, it -> {
- assert TestInjection.injectRandomDelayInCoreCreation();
-
- SolrParams params = it.req.getParams();
- log().info("core create command {}", params);
- String coreName = params.required().get(CoreAdminParams.NAME);
- Map<String, String> coreParams = buildCoreParams(params);
- CoreContainer coreContainer = it.handler.coreContainer;
- Path instancePath = coreContainer.getCoreRootDirectory().resolve(coreName);
-
- // TODO: Should we nuke setting odd instance paths? They break core discovery, generally
- String instanceDir = it.req.getParams().get(CoreAdminParams.INSTANCE_DIR);
- if (instanceDir == null)
- instanceDir = it.req.getParams().get("property.instanceDir");
- if (instanceDir != null) {
- instanceDir = PropertiesUtil.substituteProperty(instanceDir, coreContainer.getContainerProperties());
- instancePath = coreContainer.getCoreRootDirectory().resolve(instanceDir).normalize();
- }
-
- boolean newCollection = params.getBool(CoreAdminParams.NEW_COLLECTION, false);
-
- coreContainer.create(coreName, instancePath, coreParams, newCollection);
-
- it.rsp.add("core", coreName);
- }),
- UNLOAD_OP(UNLOAD, it -> {
- SolrParams params = it.req.getParams();
- String cname = params.required().get(CoreAdminParams.CORE);
-
- boolean deleteIndexDir = params.getBool(CoreAdminParams.DELETE_INDEX, false);
- boolean deleteDataDir = params.getBool(CoreAdminParams.DELETE_DATA_DIR, false);
- boolean deleteInstanceDir = params.getBool(CoreAdminParams.DELETE_INSTANCE_DIR, false);
- boolean deleteMetricsHistory = params.getBool(CoreAdminParams.DELETE_METRICS_HISTORY, false);
- CoreDescriptor cdescr = it.handler.coreContainer.getCoreDescriptor(cname);
- it.handler.coreContainer.unload(cname, deleteIndexDir, deleteDataDir, deleteInstanceDir);
- if (deleteMetricsHistory) {
- MetricsHistoryHandler historyHandler = it.handler.coreContainer.getMetricsHistoryHandler();
- if (historyHandler != null) {
- CloudDescriptor cd = cdescr != null ? cdescr.getCloudDescriptor() : null;
- String registry;
- if (cd == null) {
- registry = SolrMetricManager.getRegistryName(SolrInfoBean.Group.core, cname);
- } else {
- String replicaName = Utils.parseMetricsReplicaName(cd.getCollectionName(), cname);
- registry = SolrMetricManager.getRegistryName(SolrInfoBean.Group.core,
- cd.getCollectionName(),
- cd.getShardId(),
- replicaName);
- }
- historyHandler.checkSystemCollection();
- historyHandler.removeHistory(registry);
- }
- }
-
- assert TestInjection.injectNonExistentCoreExceptionAfterUnload(cname);
- }),
- RELOAD_OP(RELOAD, it -> {
- SolrParams params = it.req.getParams();
- String cname = params.required().get(CoreAdminParams.CORE);
-
- it.handler.coreContainer.reload(cname);
- }),
- STATUS_OP(STATUS, new StatusOp()),
- SWAP_OP(SWAP, it -> {
- final SolrParams params = it.req.getParams();
- final String cname = params.required().get(CoreAdminParams.CORE);
- String other = params.required().get(CoreAdminParams.OTHER);
- it.handler.coreContainer.swap(cname, other);
- }),
-
- RENAME_OP(RENAME, it -> {
- SolrParams params = it.req.getParams();
- String name = params.required().get(CoreAdminParams.OTHER);
- String cname = params.required().get(CoreAdminParams.CORE);
-
- if (cname.equals(name)) return;
-
- it.handler.coreContainer.rename(cname, name);
- }),
-
- MERGEINDEXES_OP(MERGEINDEXES, new MergeIndexesOp()),
-
- SPLIT_OP(SPLIT, new SplitOp()),
-
- PREPRECOVERY_OP(PREPRECOVERY, new PrepRecoveryOp()),
-
- REQUESTRECOVERY_OP(REQUESTRECOVERY, it -> {
- final SolrParams params = it.req.getParams();
- final String cname = params.required().get(CoreAdminParams.CORE);
- log().info("It has been requested that we recover: core=" + cname);
-
- try (SolrCore core = it.handler.coreContainer.getCore(cname)) {
- if (core != null) {
- // This can take a while, but doRecovery is already async so don't worry about it here
- core.getUpdateHandler().getSolrCoreState().doRecovery(it.handler.coreContainer, core.getCoreDescriptor());
- } else {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
- }
- }
- }),
- REQUESTSYNCSHARD_OP(REQUESTSYNCSHARD, new RequestSyncShardOp()),
-
- REQUESTBUFFERUPDATES_OP(REQUESTBUFFERUPDATES, it -> {
- SolrParams params = it.req.getParams();
- String cname = params.required().get(CoreAdminParams.NAME);
- log().info("Starting to buffer updates on core:" + cname);
-
- try (SolrCore core = it.handler.coreContainer.getCore(cname)) {
- if (core == null)
- throw new SolrException(ErrorCode.BAD_REQUEST, "Core [" + cname + "] does not exist");
- UpdateLog updateLog = core.getUpdateHandler().getUpdateLog();
- if (updateLog.getState() != UpdateLog.State.ACTIVE) {
- throw new SolrException(ErrorCode.SERVER_ERROR, "Core " + cname + " not in active state");
- }
- updateLog.bufferUpdates();
- it.rsp.add("core", cname);
- it.rsp.add("status", "BUFFERING");
- } catch (Throwable e) {
- if (e instanceof SolrException)
- throw (SolrException) e;
- else
- throw new SolrException(ErrorCode.SERVER_ERROR, "Could not start buffering updates", e);
- } finally {
- if (it.req != null) it.req.close();
- }
- }),
- REQUESTAPPLYUPDATES_OP(REQUESTAPPLYUPDATES, new RequestApplyUpdatesOp()),
-
- REQUESTSTATUS_OP(REQUESTSTATUS, it -> {
- SolrParams params = it.req.getParams();
- String requestId = params.required().get(CoreAdminParams.REQUESTID);
- log().info("Checking request status for : " + requestId);
-
- if (it.handler.getRequestStatusMap(RUNNING).containsKey(requestId)) {
- it.rsp.add(RESPONSE_STATUS, RUNNING);
- } else if (it.handler.getRequestStatusMap(COMPLETED).containsKey(requestId)) {
- it.rsp.add(RESPONSE_STATUS, COMPLETED);
- it.rsp.add(RESPONSE, it.handler.getRequestStatusMap(COMPLETED).get(requestId).getRspObject());
- } else if (it.handler.getRequestStatusMap(FAILED).containsKey(requestId)) {
- it.rsp.add(RESPONSE_STATUS, FAILED);
- it.rsp.add(RESPONSE, it.handler.getRequestStatusMap(FAILED).get(requestId).getRspObject());
- } else {
- it.rsp.add(RESPONSE_STATUS, "notfound");
- it.rsp.add(RESPONSE_MESSAGE, "No task found in running, completed or failed tasks");
- }
- }),
-
- OVERSEEROP_OP(OVERSEEROP, it -> {
- ZkController zkController = it.handler.coreContainer.getZkController();
- if (zkController != null) {
- String op = it.req.getParams().get("op");
- String electionNode = it.req.getParams().get("electionNode");
- if (electionNode != null) {
- zkController.rejoinOverseerElection(electionNode, "rejoinAtHead".equals(op));
- } else {
- log().info("electionNode is required param");
- }
- }
- }),
-
- REJOINLEADERELECTION_OP(REJOINLEADERELECTION, it -> {
- ZkController zkController = it.handler.coreContainer.getZkController();
-
- if (zkController != null) {
- zkController.rejoinShardLeaderElection(it.req.getParams());
- } else {
- log().warn("zkController is null in CoreAdminHandler.handleRequestInternal:REJOINLEADERELECTION. No action taken.");
- }
- }),
- INVOKE_OP(INVOKE, new InvokeOp()),
- BACKUPCORE_OP(BACKUPCORE, new BackupCoreOp()),
- RESTORECORE_OP(RESTORECORE, new RestoreCoreOp()),
- CREATESNAPSHOT_OP(CREATESNAPSHOT, new CreateSnapshotOp()),
- DELETESNAPSHOT_OP(DELETESNAPSHOT, new DeleteSnapshotOp()),
- LISTSNAPSHOTS_OP(LISTSNAPSHOTS, it -> {
- final SolrParams params = it.req.getParams();
- String cname = params.required().get(CoreAdminParams.CORE);
-
- CoreContainer cc = it.handler.getCoreContainer();
-
- try ( SolrCore core = cc.getCore(cname) ) {
- if (core == null) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
- }
-
- SolrSnapshotMetaDataManager mgr = core.getSnapshotMetaDataManager();
- NamedList result = new NamedList();
- for (String name : mgr.listSnapshots()) {
- Optional<SnapshotMetaData> metadata = mgr.getSnapshotMetaData(name);
- if ( metadata.isPresent() ) {
- NamedList<String> props = new NamedList<>();
- props.add(SolrSnapshotManager.GENERATION_NUM, String.valueOf(metadata.get().getGenerationNumber()));
- props.add(SolrSnapshotManager.INDEX_DIR_PATH, metadata.get().getIndexDirPath());
- result.add(name, props);
- }
- }
- it.rsp.add(SolrSnapshotManager.SNAPSHOTS_INFO, result);
- }
- });
-
- final CoreAdminParams.CoreAdminAction action;
- final CoreAdminOp fun;
-
- CoreAdminOperation(CoreAdminParams.CoreAdminAction action, CoreAdminOp fun) {
- this.action = action;
- this.fun = fun;
- }
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- static Logger log() {
- return log;
- }
-
-
-
-
- /**
- * Returns the core status for a particular core.
- * @param cores - the enclosing core container
- * @param cname - the core to return
- * @param isIndexInfoNeeded - add what may be expensive index information. NOT returned if the core is not loaded
- * @return - a named list of key/value pairs from the core.
- * @throws IOException - LukeRequestHandler can throw an I/O exception
- */
- static NamedList<Object> getCoreStatus(CoreContainer cores, String cname, boolean isIndexInfoNeeded) throws IOException {
- NamedList<Object> info = new SimpleOrderedMap<>();
-
- if (cores.isCoreLoading(cname)) {
- info.add(NAME, cname);
- info.add("isLoaded", "false");
- info.add("isLoading", "true");
- } else {
- if (!cores.isLoaded(cname)) { // Lazily-loaded core, fill in what we can.
- // It would be a real mistake to load the cores just to get the status
- CoreDescriptor desc = cores.getUnloadedCoreDescriptor(cname);
- if (desc != null) {
- info.add(NAME, desc.getName());
- info.add("instanceDir", desc.getInstanceDir());
- // None of the following are guaranteed to be present in a not-yet-loaded core.
- String tmp = desc.getDataDir();
- if (StringUtils.isNotBlank(tmp)) info.add("dataDir", tmp);
- tmp = desc.getConfigName();
- if (StringUtils.isNotBlank(tmp)) info.add("config", tmp);
- tmp = desc.getSchemaName();
- if (StringUtils.isNotBlank(tmp)) info.add("schema", tmp);
- info.add("isLoaded", "false");
- }
- } else {
- try (SolrCore core = cores.getCore(cname)) {
- if (core != null) {
- info.add(NAME, core.getName());
- info.add("instanceDir", core.getResourceLoader().getInstancePath().toString());
- info.add("dataDir", normalizePath(core.getDataDir()));
- info.add("config", core.getConfigResource());
- info.add("schema", core.getSchemaResource());
- info.add("startTime", core.getStartTimeStamp());
- info.add("uptime", core.getUptimeMs());
- if (cores.isZooKeeperAware()) {
- info.add("lastPublished", core.getCoreDescriptor().getCloudDescriptor().getLastPublished().toString().toLowerCase(Locale.ROOT));
- info.add("configVersion", core.getSolrConfig().getZnodeVersion());
- SimpleOrderedMap cloudInfo = new SimpleOrderedMap<>();
- cloudInfo.add(COLLECTION, core.getCoreDescriptor().getCloudDescriptor().getCollectionName());
- cloudInfo.add(SHARD, core.getCoreDescriptor().getCloudDescriptor().getShardId());
- cloudInfo.add(REPLICA, core.getCoreDescriptor().getCloudDescriptor().getCoreNodeName());
- info.add("cloud", cloudInfo);
- }
- if (isIndexInfoNeeded) {
- RefCounted<SolrIndexSearcher> searcher = core.getSearcher();
- try {
- SimpleOrderedMap<Object> indexInfo = LukeRequestHandler.getIndexInfo(searcher.get().getIndexReader());
- long size = core.getIndexSize();
- indexInfo.add("sizeInBytes", size);
- indexInfo.add("size", NumberUtils.readableSize(size));
- info.add("index", indexInfo);
- } finally {
- searcher.decref();
- }
- }
- }
- }
- }
- }
- return info;
- }
-
- @Override
- public void execute(CallInfo it) throws Exception {
- try {
- fun.execute(it);
- } catch (SolrException | InterruptedException e) {
- // No need to re-wrap; throw as-is.
- throw e;
- } catch (Exception e) {
- throw new SolrException(ErrorCode.SERVER_ERROR, "Error handling '" + action.name() + "' action", e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/CreateSnapshotOp.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/CreateSnapshotOp.java b/solr/core/src/java/org/apache/solr/handler/admin/CreateSnapshotOp.java
deleted file mode 100644
index cdf2c38..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/CreateSnapshotOp.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 org.apache.lucene.index.IndexCommit;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CoreAdminParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.snapshots.SolrSnapshotManager;
-import org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager;
-
-class CreateSnapshotOp implements CoreAdminHandler.CoreAdminOp {
- @Override
- public void execute(CoreAdminHandler.CallInfo it) throws Exception {
- final SolrParams params = it.req.getParams();
- String commitName = params.required().get(CoreAdminParams.COMMIT_NAME);
- String cname = params.required().get(CoreAdminParams.CORE);
-
- CoreContainer cc = it.handler.getCoreContainer();
-
- try (SolrCore core = cc.getCore(cname)) {
- if (core == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
- }
-
- String indexDirPath = core.getIndexDir();
- IndexCommit ic = core.getDeletionPolicy().getLatestCommit();
- if (ic == null) {
- ic = core.withSearcher(searcher -> searcher.getIndexReader().getIndexCommit());
- }
- SolrSnapshotMetaDataManager mgr = core.getSnapshotMetaDataManager();
- mgr.snapshot(commitName, indexDirPath, ic.getGeneration());
-
- it.rsp.add(CoreAdminParams.CORE, core.getName());
- it.rsp.add(CoreAdminParams.COMMIT_NAME, commitName);
- it.rsp.add(SolrSnapshotManager.INDEX_DIR_PATH, indexDirPath);
- it.rsp.add(SolrSnapshotManager.GENERATION_NUM, ic.getGeneration());
- it.rsp.add(SolrSnapshotManager.FILE_LIST, ic.getFileNames());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/DeleteSnapshotOp.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/DeleteSnapshotOp.java b/solr/core/src/java/org/apache/solr/handler/admin/DeleteSnapshotOp.java
deleted file mode 100644
index ed1ec05..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/DeleteSnapshotOp.java
+++ /dev/null
@@ -1,51 +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.common.SolrException;
-import org.apache.solr.common.params.CoreAdminParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.SolrCore;
-
-
-class DeleteSnapshotOp implements CoreAdminHandler.CoreAdminOp {
-
- @Override
- public void execute(CoreAdminHandler.CallInfo it) throws Exception {
- final SolrParams params = it.req.getParams();
- String commitName = params.required().get(CoreAdminParams.COMMIT_NAME);
- String cname = params.required().get(CoreAdminParams.CORE);
-
- CoreContainer cc = it.handler.getCoreContainer();
- SolrCore core = cc.getCore(cname);
- if (core == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unable to locate core " + cname);
- }
-
- try {
- core.deleteNamedSnapshot(commitName);
- // Ideally we shouldn't need this. This is added since the RPC logic in
- // OverseerCollectionMessageHandler can not provide the coreName as part of the result.
- it.rsp.add(CoreAdminParams.CORE, core.getName());
- it.rsp.add(CoreAdminParams.COMMIT_NAME, commitName);
- } finally {
- core.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java
deleted file mode 100644
index 7b07a1e..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/HealthCheckHandler.java
+++ /dev/null
@@ -1,110 +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 org.apache.solr.common.SolrException;
-import org.apache.solr.common.cloud.ClusterState;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.solr.common.params.CommonParams.FAILURE;
-import static org.apache.solr.common.params.CommonParams.OK;
-import static org.apache.solr.common.params.CommonParams.STATUS;
-
-/*
- * Health Check Handler for reporting the health of a specific node.
- *
- * This checks if the node is:
- * 1. Connected to zookeeper
- * 2. listed in 'live_nodes'.
- */
-public class HealthCheckHandler extends RequestHandlerBase {
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- CoreContainer coreContainer;
-
- public HealthCheckHandler(final CoreContainer coreContainer) {
- super();
- this.coreContainer = coreContainer;
- }
-
- @Override
- final public void init(NamedList args) {
-
- }
-
- public CoreContainer getCoreContainer() {
- return this.coreContainer;
- }
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
-
- log.debug("Invoked HealthCheckHandler on [{}]", coreContainer.getZkController().getNodeName());
- CoreContainer cores = getCoreContainer();
-
- if(cores == null) {
- rsp.setException(new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Core container not initialized"));
- return;
- }
- if(!cores.isZooKeeperAware()) {
- //TODO: Support standalone instances
- rsp.setException(new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Health check is only available when running in SolrCloud mode"));
- return;
- }
- ZkStateReader zkStateReader = cores.getZkController().getZkStateReader();
- ClusterState clusterState = zkStateReader.getClusterState();
- // Check for isConnected and isClosed
- if(zkStateReader.getZkClient().isClosed() || !zkStateReader.getZkClient().isConnected()) {
- rsp.add(STATUS, FAILURE);
- rsp.setException(new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Host Unavailable: Not connected to zk"));
- return;
- }
-
- // Set status to true if this node is in live_nodes
- if (clusterState.getLiveNodes().contains(cores.getZkController().getNodeName())) {
- rsp.add(STATUS, OK);
- } else {
- rsp.add(STATUS, FAILURE);
- rsp.setException(new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Host Unavailable: Not in live nodes as per zk"));
- }
-
- rsp.setHttpCaching(false);
-
- return;
- }
-
- @Override
- public String getDescription() {
- return "Health check handler for SolrCloud node";
- }
-
- @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/InfoHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/InfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/InfoHandler.java
deleted file mode 100644
index a2bfb5b..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/InfoHandler.java
+++ /dev/null
@@ -1,157 +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.Collection;
-import java.util.Locale;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.solr.api.ApiBag.ReqHandlerToApi;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.handler.RequestHandlerBase;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.api.Api;
-
-import static java.util.Collections.singletonList;
-import static org.apache.solr.common.util.Utils.getSpec;
-import static org.apache.solr.common.params.CommonParams.PATH;
-
-public class InfoHandler extends RequestHandlerBase {
-
- protected final CoreContainer coreContainer;
-
- /**
- * Overloaded ctor to inject CoreContainer into the handler.
- *
- * @param coreContainer Core Container of the solr webapp installed.
- */
- public InfoHandler(final CoreContainer coreContainer) {
- this.coreContainer = coreContainer;
- handlers.put("threads", new ThreadDumpHandler());
- handlers.put("properties", new PropertiesRequestHandler());
- handlers.put("logging", new LoggingHandler(coreContainer));
- handlers.put("system", new SystemInfoHandler(coreContainer));
- }
-
-
- @Override
- final public void init(NamedList args) {
-
- }
-
- /**
- * The instance of CoreContainer this handler handles. This should be the CoreContainer instance that created this
- * handler.
- *
- * @return a CoreContainer instance
- */
- public CoreContainer getCoreContainer() {
- return this.coreContainer;
- }
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
- // Make sure the cores is enabled
- CoreContainer cores = getCoreContainer();
- if (cores == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- "Core container instance missing");
- }
-
- String path = (String) req.getContext().get(PATH);
- handle(req, rsp, path);
- }
-
- private void handle(SolrQueryRequest req, SolrQueryResponse rsp, String path) {
- int i = path.lastIndexOf('/');
- String name = path.substring(i + 1, path.length());
- RequestHandlerBase handler = handlers.get(name.toLowerCase(Locale.ROOT));
- if(handler == null) {
- throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No handler by name "+name + " available names are "+ handlers.keySet());
- }
- handler.handleRequest(req, rsp);
- rsp.setHttpCaching(false);
- }
-
-
- //////////////////////// SolrInfoMBeans methods //////////////////////
-
- @Override
- public String getDescription() {
- return "System Information";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-
- protected PropertiesRequestHandler getPropertiesHandler() {
- return (PropertiesRequestHandler) handlers.get("properties");
-
- }
-
- protected ThreadDumpHandler getThreadDumpHandler() {
- return (ThreadDumpHandler) handlers.get("threads");
- }
-
- protected LoggingHandler getLoggingHandler() {
- return (LoggingHandler) handlers.get("logging");
- }
-
- protected SystemInfoHandler getSystemInfoHandler() {
- return (SystemInfoHandler) handlers.get("system");
- }
-
- protected void setPropertiesHandler(PropertiesRequestHandler propertiesHandler) {
- handlers.put("properties", propertiesHandler);
- }
-
- protected void setThreadDumpHandler(ThreadDumpHandler threadDumpHandler) {
- handlers.put("threads", threadDumpHandler);
- }
-
- protected void setLoggingHandler(LoggingHandler loggingHandler) {
- handlers.put("logging", loggingHandler);
- }
-
- protected void setSystemInfoHandler(SystemInfoHandler systemInfoHandler) {
- handlers.put("system", systemInfoHandler);
- }
-
- @Override
- public SolrRequestHandler getSubHandler(String subPath) {
- return this;
- }
-
- private Map<String, RequestHandlerBase> handlers = new ConcurrentHashMap<>();
-
- @Override
- public Collection<Api> getApis() {
- return singletonList(new ReqHandlerToApi(this, getSpec("node.Info")));
- }
-
- @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/InvokeOp.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/InvokeOp.java b/solr/core/src/java/org/apache/solr/handler/admin/InvokeOp.java
deleted file mode 100644
index 04002fa..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/InvokeOp.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.lang.invoke.MethodHandles;
-import java.util.Map;
-
-import org.apache.solr.common.SolrException;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.core.SolrResourceLoader;
-import org.apache.solr.request.SolrQueryRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-class InvokeOp implements CoreAdminHandler.CoreAdminOp {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- static Map<String, Object> invokeAClass(SolrQueryRequest req, String c) {
- SolrResourceLoader loader = null;
- if (req.getCore() != null) loader = req.getCore().getResourceLoader();
- else if (req.getContext().get(CoreContainer.class.getName()) != null) {
- CoreContainer cc = (CoreContainer) req.getContext().get(CoreContainer.class.getName());
- loader = cc.getResourceLoader();
- }
-
- CoreAdminHandler.Invocable invokable = loader.newInstance(c, CoreAdminHandler.Invocable.class);
- Map<String, Object> result = invokable.invoke(req);
- log.info("Invocable_invoked {}", result);
- return result;
- }
-
- @Override
- public void execute(CoreAdminHandler.CallInfo it) throws Exception {
- String[] klas = it.req.getParams().getParams("class");
- if (klas == null || klas.length == 0) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "class is a required param");
- }
- for (String c : klas) {
- Map<String, Object> result = invokeAClass(it.req, c);
- it.rsp.add(c, result);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/admin/LoggingHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/LoggingHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/LoggingHandler.java
deleted file mode 100644
index ef52636..0000000
--- a/solr/core/src/java/org/apache/solr/handler/admin/LoggingHandler.java
+++ /dev/null
@@ -1,165 +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.Collections;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.params.SolrParams;
-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.logging.LogWatcher;
-import org.apache.solr.logging.LoggerInfo;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.util.plugin.SolrCoreAware;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * A request handler to show which loggers are registered and allows you to set them
- *
- * @since 4.0
- */
-public class LoggingHandler extends RequestHandlerBase implements SolrCoreAware {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- private LogWatcher watcher;
-
- public LoggingHandler(CoreContainer cc) {
- this.watcher = cc.getLogging();
- }
-
- public LoggingHandler() {
-
- }
-
- @Override
- public void inform(SolrCore core) {
- if (watcher == null) {
- watcher = core.getCoreContainer().getLogging();
- }
- }
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
- // Don't do anything if the framework is unknown
- if (watcher==null) {
- rsp.add("error", "Logging Not Initialized");
- return;
- }
- rsp.add("watcher", watcher.getName());
-
- SolrParams params = req.getParams();
- if(params.get("threshold")!=null) {
- watcher.setThreshold(params.get("threshold"));
- }
-
- // Write something at each level
- if(params.get("test")!=null) {
- log.trace("trace message");
- log.debug( "debug message");
- log.info("info (with exception)", new RuntimeException("test") );
- log.warn("warn (with exception)", new RuntimeException("test") );
- log.error("error (with exception)", new RuntimeException("test") );
- }
-
- String[] set = params.getParams("set");
- if (set != null) {
- for (String pair : set) {
- String[] split = pair.split(":");
- if (split.length != 2) {
- throw new SolrException(
- SolrException.ErrorCode.SERVER_ERROR,
- "Invalid format, expected level:value, got " + pair);
- }
- String category = split[0];
- String level = split[1];
-
- watcher.setLogLevel(category, level);
- }
- }
-
- String since = req.getParams().get("since");
- if(since != null) {
- long time = -1;
- try {
- time = Long.parseLong(since);
- }
- catch(Exception ex) {
- throw new SolrException(ErrorCode.BAD_REQUEST, "invalid timestamp: "+since);
- }
- AtomicBoolean found = new AtomicBoolean(false);
- SolrDocumentList docs = watcher.getHistory(time, found);
- if(docs==null) {
- rsp.add("error", "History not enabled");
- return;
- }
- else {
- SimpleOrderedMap<Object> info = new SimpleOrderedMap<>();
- if(time>0) {
- info.add("since", time);
- info.add("found", found.get());
- }
- else {
- info.add("levels", watcher.getAllLevels()); // show for the first request
- }
- info.add("last", watcher.getLastEvent());
- info.add("buffer", watcher.getHistorySize());
- info.add("threshold", watcher.getThreshold());
-
- rsp.add("info", info);
- rsp.add("history", docs);
- }
- }
- else {
- rsp.add("levels", watcher.getAllLevels());
-
- List<LoggerInfo> loggers = new ArrayList<>(watcher.getAllLoggers());
- Collections.sort(loggers);
-
- List<SimpleOrderedMap<?>> info = new ArrayList<>();
- for (LoggerInfo wrap : loggers) {
- info.add(wrap.getInfo());
- }
- rsp.add("loggers", info);
- }
- rsp.setHttpCaching(false);
- }
-
- // ////////////////////// SolrInfoMBeans methods //////////////////////
-
- @Override
- public String getDescription() {
- return "Logging Handler";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-
-}
\ No newline at end of file