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:38 UTC
[17/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/RequestHandlerUtils.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/RequestHandlerUtils.java b/solr/core/src/java/org/apache/solr/handler/RequestHandlerUtils.java
deleted file mode 100644
index 4441024..0000000
--- a/solr/core/src/java/org/apache/solr/handler/RequestHandlerUtils.java
+++ /dev/null
@@ -1,135 +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;
-
-import java.io.IOException;
-import java.util.*;
-
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.MapSolrParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.params.UpdateParams;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.update.CommitUpdateCommand;
-import org.apache.solr.update.RollbackUpdateCommand;
-import org.apache.solr.update.processor.UpdateRequestProcessor;
-
-/**
- * Common helper functions for RequestHandlers
- *
- *
- * @since solr 1.2
- */
-public class RequestHandlerUtils
-{
- /**
- * A common way to mark the response format as experimental
- */
- public static void addExperimentalFormatWarning( SolrQueryResponse rsp )
- {
- rsp.add( "WARNING", "This response format is experimental. It is likely to change in the future." );
- }
-
-
- /**
- * Check the request parameters and decide if it should commit or optimize.
- * If it does, it will check other related parameters such as "waitFlush" and "waitSearcher"
- */
- public static boolean handleCommit(SolrQueryRequest req, UpdateRequestProcessor processor, SolrParams params, boolean force ) throws IOException
- {
- if( params == null) {
- params = new MapSolrParams( new HashMap<String, String>() );
- }
-
- boolean optimize = params.getBool( UpdateParams.OPTIMIZE, false );
- boolean commit = params.getBool( UpdateParams.COMMIT, false );
- boolean softCommit = params.getBool( UpdateParams.SOFT_COMMIT, false );
- boolean prepareCommit = params.getBool( UpdateParams.PREPARE_COMMIT, false );
-
-
- if( optimize || commit || softCommit || prepareCommit || force ) {
- CommitUpdateCommand cmd = new CommitUpdateCommand(req, optimize );
- updateCommit(cmd, params);
- processor.processCommit( cmd );
- return true;
- }
-
-
- return false;
- }
-
-
- private static Set<String> commitParams = new HashSet<>(Arrays.asList(new String[]{UpdateParams.OPEN_SEARCHER, UpdateParams.WAIT_SEARCHER, UpdateParams.SOFT_COMMIT, UpdateParams.EXPUNGE_DELETES, UpdateParams.MAX_OPTIMIZE_SEGMENTS, UpdateParams.PREPARE_COMMIT}));
-
- public static void validateCommitParams(SolrParams params) {
- Iterator<String> i = params.getParameterNamesIterator();
- while (i.hasNext()) {
- String key = i.next();
- if (!commitParams.contains(key)) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Unknown commit parameter '" + key + "'");
- }
- }
- }
-
- /**
- * Modify UpdateCommand based on request parameters
- */
- public static void updateCommit(CommitUpdateCommand cmd, SolrParams params) {
- if( params == null ) return;
-
- cmd.openSearcher = params.getBool( UpdateParams.OPEN_SEARCHER, cmd.openSearcher );
- cmd.waitSearcher = params.getBool( UpdateParams.WAIT_SEARCHER, cmd.waitSearcher );
- cmd.softCommit = params.getBool( UpdateParams.SOFT_COMMIT, cmd.softCommit );
- cmd.expungeDeletes = params.getBool( UpdateParams.EXPUNGE_DELETES, cmd.expungeDeletes );
- cmd.maxOptimizeSegments = params.getInt( UpdateParams.MAX_OPTIMIZE_SEGMENTS, cmd.maxOptimizeSegments );
- cmd.prepareCommit = params.getBool( UpdateParams.PREPARE_COMMIT, cmd.prepareCommit );
- }
-
-
- /**
- * @since Solr 1.4
- */
- public static boolean handleRollback(SolrQueryRequest req, UpdateRequestProcessor processor, SolrParams params, boolean force ) throws IOException
- {
- if( params == null ) {
- params = new MapSolrParams( new HashMap<String, String>() );
- }
-
- boolean rollback = params.getBool( UpdateParams.ROLLBACK, false );
-
- if( rollback || force ) {
- RollbackUpdateCommand cmd = new RollbackUpdateCommand(req);
- processor.processRollback( cmd );
- return true;
- }
- return false;
- }
-
- /**
- * @since 6.7
- */
- public static void setWt(SolrQueryRequest req, String wt) {
- SolrParams params = req.getParams();
- if (params.get(CommonParams.WT) != null) return;//wt is set by user
- Map<String, String> map = new HashMap<>(1);
- map.put(CommonParams.WT, wt);
- map.put("indent", "true");
- req.setParams(SolrParams.wrapDefaults(params, new MapSolrParams(map)));
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/RestoreCore.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/RestoreCore.java b/solr/core/src/java/org/apache/solr/handler/RestoreCore.java
deleted file mode 100644
index e750631..0000000
--- a/solr/core/src/java/org/apache/solr/handler/RestoreCore.java
+++ /dev/null
@@ -1,162 +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;
-
-import java.lang.invoke.MethodHandles;
-import java.net.URI;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.util.concurrent.Callable;
-import java.util.concurrent.Future;
-
-import org.apache.lucene.codecs.CodecUtil;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexInput;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.core.DirectoryFactory;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.backup.repository.BackupRepository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class RestoreCore implements Callable<Boolean> {
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- private final String backupName;
- private final URI backupLocation;
- private final SolrCore core;
- private final BackupRepository backupRepo;
-
- public RestoreCore(BackupRepository backupRepo, SolrCore core, URI location, String name) {
- this.backupRepo = backupRepo;
- this.core = core;
- this.backupLocation = location;
- this.backupName = name;
- }
-
- @Override
- public Boolean call() throws Exception {
- return doRestore();
- }
-
- public boolean doRestore() throws Exception {
-
- URI backupPath = backupRepo.resolve(backupLocation, backupName);
- SimpleDateFormat dateFormat = new SimpleDateFormat(SnapShooter.DATE_FMT, Locale.ROOT);
- String restoreIndexName = "restore." + dateFormat.format(new Date());
- String restoreIndexPath = core.getDataDir() + restoreIndexName;
-
- String indexDirPath = core.getIndexDir();
- Directory restoreIndexDir = null;
- Directory indexDir = null;
- try {
-
- restoreIndexDir = core.getDirectoryFactory().get(restoreIndexPath,
- DirectoryFactory.DirContext.DEFAULT, core.getSolrConfig().indexConfig.lockType);
-
- //Prefer local copy.
- indexDir = core.getDirectoryFactory().get(indexDirPath,
- DirectoryFactory.DirContext.DEFAULT, core.getSolrConfig().indexConfig.lockType);
-
- //Move all files from backupDir to restoreIndexDir
- for (String filename : backupRepo.listAll(backupPath)) {
- checkInterrupted();
- log.info("Copying file {} to restore directory ", filename);
- try (IndexInput indexInput = backupRepo.openInput(backupPath, filename, IOContext.READONCE)) {
- Long checksum = null;
- try {
- checksum = CodecUtil.retrieveChecksum(indexInput);
- } catch (Exception e) {
- log.warn("Could not read checksum from index file: " + filename, e);
- }
- long length = indexInput.length();
- IndexFetcher.CompareResult compareResult = IndexFetcher.compareFile(indexDir, filename, length, checksum);
- if (!compareResult.equal ||
- (IndexFetcher.filesToAlwaysDownloadIfNoChecksums(filename, length, compareResult))) {
- backupRepo.copyFileTo(backupPath, filename, restoreIndexDir);
- } else {
- //prefer local copy
- restoreIndexDir.copyFrom(indexDir, filename, filename, IOContext.READONCE);
- }
- } catch (Exception e) {
- log.warn("Exception while restoring the backup index ", e);
- throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Exception while restoring the backup index", e);
- }
- }
- log.debug("Switching directories");
- core.modifyIndexProps(restoreIndexName);
-
- boolean success;
- try {
- core.getUpdateHandler().newIndexWriter(false);
- openNewSearcher();
- success = true;
- log.info("Successfully restored to the backup index");
- } catch (Exception e) {
- //Rollback to the old index directory. Delete the restore index directory and mark the restore as failed.
- log.warn("Could not switch to restored index. Rolling back to the current index", e);
- Directory dir = null;
- try {
- dir = core.getDirectoryFactory().get(core.getDataDir(), DirectoryFactory.DirContext.META_DATA,
- core.getSolrConfig().indexConfig.lockType);
- dir.deleteFile(IndexFetcher.INDEX_PROPERTIES);
- } finally {
- if (dir != null) {
- core.getDirectoryFactory().release(dir);
- }
- }
-
- core.getDirectoryFactory().doneWithDirectory(restoreIndexDir);
- core.getDirectoryFactory().remove(restoreIndexDir);
- core.getUpdateHandler().newIndexWriter(false);
- openNewSearcher();
- throw new SolrException(SolrException.ErrorCode.UNKNOWN, "Exception while restoring the backup index", e);
- }
- if (success) {
- core.getDirectoryFactory().doneWithDirectory(indexDir);
- // Cleanup all index files not associated with any *named* snapshot.
- core.deleteNonSnapshotIndexFiles(indexDirPath);
- }
-
- return true;
- } finally {
- if (restoreIndexDir != null) {
- core.getDirectoryFactory().release(restoreIndexDir);
- }
- if (indexDir != null) {
- core.getDirectoryFactory().release(indexDir);
- }
- }
- }
-
- private void checkInterrupted() throws InterruptedException {
- if (Thread.currentThread().isInterrupted()) {
- throw new InterruptedException("Stopping restore process. Thread was interrupted.");
- }
- }
-
- private void openNewSearcher() throws Exception {
- Future[] waitSearcher = new Future[1];
- core.getSearcher(true, false, waitSearcher, true);
- if (waitSearcher[0] != null) {
- waitSearcher[0].get();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/SQLHandler.java b/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
deleted file mode 100644
index 6b0330a..0000000
--- a/solr/core/src/java/org/apache/solr/handler/SQLHandler.java
+++ /dev/null
@@ -1,201 +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;
-
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.calcite.config.Lex;
-import org.apache.solr.client.solrj.io.Tuple;
-import org.apache.solr.client.solrj.io.comp.StreamComparator;
-import org.apache.solr.client.solrj.io.stream.ExceptionStream;
-import org.apache.solr.client.solrj.io.stream.TupleStream;
-import org.apache.solr.common.SolrException;
-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.core.CoreContainer;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.handler.sql.CalciteSolrDriver;
-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.plugin.SolrCoreAware;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SQLHandler extends RequestHandlerBase implements SolrCoreAware, PermissionNameProvider {
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- private static String defaultZkhost = null;
- private static String defaultWorkerCollection = null;
-
- static final String sqlNonCloudErrorMsg = "/sql handler only works in Solr Cloud mode";
-
- private boolean isCloud = false;
-
- public void inform(SolrCore core) {
- CoreContainer coreContainer = core.getCoreContainer();
-
- if(coreContainer.isZooKeeperAware()) {
- defaultZkhost = core.getCoreContainer().getZkController().getZkServerAddress();
- defaultWorkerCollection = core.getCoreDescriptor().getCollectionName();
- isCloud = true;
- }
- }
-
- @Override
- public PermissionNameProvider.Name getPermissionName(AuthorizationContext request) {
- return PermissionNameProvider.Name.READ_PERM;
- }
-
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
- ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
- params = adjustParams(params);
- req.setParams(params);
-
- String sql = params.get("stmt");
- // Set defaults for parameters
- params.set("numWorkers", params.getInt("numWorkers", 1));
- params.set("workerCollection", params.get("workerCollection", defaultWorkerCollection));
- params.set("workerZkhost", params.get("workerZkhost", defaultZkhost));
- params.set("aggregationMode", params.get("aggregationMode", "facet"));
-
- TupleStream tupleStream = null;
- try {
-
- if(!isCloud) {
- throw new IllegalStateException(sqlNonCloudErrorMsg);
- }
-
- if(sql == null) {
- throw new Exception("stmt parameter cannot be null");
- }
-
- String url = CalciteSolrDriver.CONNECT_STRING_PREFIX;
-
- Properties properties = new Properties();
- // Add all query parameters
- Iterator<String> parameterNamesIterator = params.getParameterNamesIterator();
- while(parameterNamesIterator.hasNext()) {
- String param = parameterNamesIterator.next();
- properties.setProperty(param, params.get(param));
- }
-
- // Set these last to ensure that they are set properly
- properties.setProperty("lex", Lex.MYSQL.toString());
- properties.setProperty("zk", defaultZkhost);
-
- String driverClass = CalciteSolrDriver.class.getCanonicalName();
-
- // JDBC driver requires metadata from the SQLHandler. Default to false since this adds a new Metadata stream.
- boolean includeMetadata = params.getBool("includeMetadata", false);
- tupleStream = new SqlHandlerStream(url, sql, null, properties, driverClass, includeMetadata);
-
- tupleStream = new StreamHandler.TimerStream(new ExceptionStream(tupleStream));
-
- rsp.add("result-set", tupleStream);
- } catch(Exception e) {
- //Catch the SQL parsing and query transformation exceptions.
- if(tupleStream != null) {
- tupleStream.close();
- }
- SolrException.log(log, e);
- rsp.add("result-set", new StreamHandler.DummyErrorStream(e));
- }
- }
-
- public String getDescription() {
- return "SQLHandler";
- }
-
- public String getSource() {
- return null;
- }
-
- /*
- * Only necessary for SolrJ JDBC driver since metadata has to be passed back
- */
- private static class SqlHandlerStream extends CalciteJDBCStream {
- private final boolean includeMetadata;
- private boolean firstTuple = true;
- List<String> metadataFields = new ArrayList<>();
- Map<String, String> metadataAliases = new HashMap<>();
-
- SqlHandlerStream(String connectionUrl, String sqlQuery, StreamComparator definedSort,
- Properties connectionProperties, String driverClassName, boolean includeMetadata)
- throws IOException {
- super(connectionUrl, sqlQuery, definedSort, connectionProperties, driverClassName);
-
- this.includeMetadata = includeMetadata;
- }
-
- @Override
- public Tuple read() throws IOException {
- // Return a metadata tuple as the first tuple and then pass through to the JDBCStream.
- if(firstTuple) {
- try {
- Map<String, Object> fields = new HashMap<>();
-
- firstTuple = false;
-
- ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
-
- for(int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
- String columnName = resultSetMetaData.getColumnName(i);
- String columnLabel = resultSetMetaData.getColumnLabel(i);
- metadataFields.add(columnName);
- metadataAliases.put(columnName, columnLabel);
- }
-
- if(includeMetadata) {
- fields.put("isMetadata", true);
- fields.put("fields", metadataFields);
- fields.put("aliases", metadataAliases);
- return new Tuple(fields);
- }
- } catch (SQLException e) {
- throw new IOException(e);
- }
- }
-
- Tuple tuple = super.read();
- if(!tuple.EOF) {
- tuple.fieldNames = metadataFields;
- tuple.fieldLabels = metadataAliases;
- }
- return tuple;
- }
- }
-
- private ModifiableSolrParams adjustParams(SolrParams params) {
- ModifiableSolrParams adjustedParams = new ModifiableSolrParams();
- adjustedParams.add(params);
- adjustedParams.add(CommonParams.OMIT_HEADER, "true");
- return adjustedParams;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java b/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java
deleted file mode 100644
index fb84e84..0000000
--- a/solr/core/src/java/org/apache/solr/handler/SchemaHandler.java
+++ /dev/null
@@ -1,257 +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;
-
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.solr.api.Api;
-import org.apache.solr.api.ApiBag;
-import org.apache.solr.cloud.ZkSolrResourceLoader;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.MapSolrParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.SimpleOrderedMap;
-import org.apache.solr.common.util.StrUtils;
-import org.apache.solr.common.util.Utils;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.schema.IndexSchema;
-import org.apache.solr.schema.ManagedIndexSchema;
-import org.apache.solr.schema.SchemaManager;
-import org.apache.solr.schema.ZkIndexSchemaReader;
-import org.apache.solr.security.AuthorizationContext;
-import org.apache.solr.security.PermissionNameProvider;
-import org.apache.solr.util.plugin.SolrCoreAware;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static java.util.Collections.singletonMap;
-import static org.apache.solr.common.params.CommonParams.JSON;
-import static org.apache.solr.schema.IndexSchema.SchemaProps.Handler.COPY_FIELDS;
-import static org.apache.solr.schema.IndexSchema.SchemaProps.Handler.DYNAMIC_FIELDS;
-import static org.apache.solr.schema.IndexSchema.SchemaProps.Handler.FIELDS;
-import static org.apache.solr.schema.IndexSchema.SchemaProps.Handler.FIELD_TYPES;
-
-public class SchemaHandler extends RequestHandlerBase implements SolrCoreAware, PermissionNameProvider {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private boolean isImmutableConfigSet = false;
-
- private static final Map<String, String> level2;
-
- static {
- Map s = Utils.makeMap(
- FIELD_TYPES.nameLower, null,
- FIELDS.nameLower, "fl",
- DYNAMIC_FIELDS.nameLower, "fl",
- COPY_FIELDS.nameLower, null
- );
-
- level2 = Collections.unmodifiableMap(s);
- }
-
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
- RequestHandlerUtils.setWt(req, JSON);
- String httpMethod = (String) req.getContext().get("httpMethod");
- if ("POST".equals(httpMethod)) {
- if (isImmutableConfigSet) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "ConfigSet is immutable");
- }
- if (req.getContentStreams() == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "no stream");
- }
-
- try {
- List errs = new SchemaManager(req).performOperations();
- if (!errs.isEmpty())
- throw new ApiBag.ExceptionWithErrObject(SolrException.ErrorCode.BAD_REQUEST,"error processing commands", errs);
- } catch (IOException e) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error reading input String " + e.getMessage(), e);
- }
- } else {
- handleGET(req, rsp);
- }
- }
-
- @Override
- public PermissionNameProvider.Name getPermissionName(AuthorizationContext ctx) {
- switch (ctx.getHttpMethod()) {
- case "GET":
- return PermissionNameProvider.Name.SCHEMA_READ_PERM;
- case "POST":
- return PermissionNameProvider.Name.SCHEMA_EDIT_PERM;
- default:
- return null;
- }
- }
-
- private void handleGET(SolrQueryRequest req, SolrQueryResponse rsp) {
- try {
- String path = (String) req.getContext().get("path");
- switch (path) {
- case "/schema":
- rsp.add(IndexSchema.SCHEMA, req.getSchema().getNamedPropertyValues());
- break;
- case "/schema/version":
- rsp.add(IndexSchema.VERSION, req.getSchema().getVersion());
- break;
- case "/schema/uniquekey":
- rsp.add(IndexSchema.UNIQUE_KEY, req.getSchema().getUniqueKeyField().getName());
- break;
- case "/schema/similarity":
- rsp.add(IndexSchema.SIMILARITY, req.getSchema().getSimilarityFactory().getNamedPropertyValues());
- break;
- case "/schema/name": {
- final String schemaName = req.getSchema().getSchemaName();
- if (null == schemaName) {
- String message = "Schema has no name";
- throw new SolrException(SolrException.ErrorCode.NOT_FOUND, message);
- }
- rsp.add(IndexSchema.NAME, schemaName);
- break;
- }
- case "/schema/zkversion": {
- int refreshIfBelowVersion = -1;
- Object refreshParam = req.getParams().get("refreshIfBelowVersion");
- if (refreshParam != null)
- refreshIfBelowVersion = (refreshParam instanceof Number) ? ((Number) refreshParam).intValue()
- : Integer.parseInt(refreshParam.toString());
- int zkVersion = -1;
- IndexSchema schema = req.getSchema();
- if (schema instanceof ManagedIndexSchema) {
- ManagedIndexSchema managed = (ManagedIndexSchema) schema;
- zkVersion = managed.getSchemaZkVersion();
- if (refreshIfBelowVersion != -1 && zkVersion < refreshIfBelowVersion) {
- log.info("REFRESHING SCHEMA (refreshIfBelowVersion=" + refreshIfBelowVersion +
- ", currentVersion=" + zkVersion + ") before returning version!");
- ZkSolrResourceLoader zkSolrResourceLoader = (ZkSolrResourceLoader) req.getCore().getResourceLoader();
- ZkIndexSchemaReader zkIndexSchemaReader = zkSolrResourceLoader.getZkIndexSchemaReader();
- managed = zkIndexSchemaReader.refreshSchemaFromZk(refreshIfBelowVersion);
- zkVersion = managed.getSchemaZkVersion();
- }
- }
- rsp.add("zkversion", zkVersion);
- break;
- }
- default: {
- List<String> parts = StrUtils.splitSmart(path, '/');
- if (parts.get(0).isEmpty()) parts.remove(0);
- if (parts.size() > 1 && level2.containsKey(parts.get(1))) {
- String realName = parts.get(1);
- String fieldName = IndexSchema.nameMapping.get(realName);
-
- String pathParam = level2.get(realName);
- if (parts.size() > 2) {
- req.setParams(SolrParams.wrapDefaults(new MapSolrParams(singletonMap(pathParam, parts.get(2))), req.getParams()));
- }
- Map propertyValues = req.getSchema().getNamedPropertyValues(realName, req.getParams());
- Object o = propertyValues.get(fieldName);
- if(parts.size()> 2) {
- String name = parts.get(2);
- if (o instanceof List) {
- List list = (List) o;
- for (Object obj : list) {
- if (obj instanceof SimpleOrderedMap) {
- SimpleOrderedMap simpleOrderedMap = (SimpleOrderedMap) obj;
- if(name.equals(simpleOrderedMap.get("name"))) {
- rsp.add(fieldName.substring(0, realName.length() - 1), simpleOrderedMap);
- return;
- }
- }
- }
- }
- throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No such path " + path);
- } else {
- rsp.add(fieldName, o);
- }
- return;
- }
-
- throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "No such path " + path);
- }
- }
-
- } catch (Exception e) {
- rsp.setException(e);
- }
- }
-
- private static Set<String> subPaths = new HashSet<>(Arrays.asList(
- "version",
- "uniquekey",
- "name",
- "similarity",
- "defaultsearchfield",
- "solrqueryparser",
- "zkversion"
- ));
- static {
- subPaths.addAll(level2.keySet());
- }
-
- @Override
- public SolrRequestHandler getSubHandler(String subPath) {
- List<String> parts = StrUtils.splitSmart(subPath, '/');
- if (parts.get(0).isEmpty()) parts.remove(0);
- String prefix = parts.get(0);
- if(subPaths.contains(prefix)) return this;
-
- return null;
- }
-
- @Override
- public String getDescription() {
- return "CRUD operations over the Solr schema";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-
- @Override
- public void inform(SolrCore core) {
- isImmutableConfigSet = SolrConfigHandler.getImmutable(core);
- }
-
- @Override
- public Collection<Api> getApis() {
- return ApiBag.wrapRequestHandlers(this, "core.SchemaRead",
- "core.SchemaRead.fields",
- "core.SchemaRead.copyFields",
- "core.SchemaEdit",
- "core.SchemaRead.dynamicFields_fieldTypes"
- );
-
- }
-
- @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/SnapShooter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java b/solr/core/src/java/org/apache/solr/handler/SnapShooter.java
deleted file mode 100644
index 2c3c691..0000000
--- a/solr/core/src/java/org/apache/solr/handler/SnapShooter.java
+++ /dev/null
@@ -1,308 +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;
-
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.net.URI;
-import java.nio.file.Paths;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.function.Consumer;
-
-import org.apache.lucene.index.IndexCommit;
-import org.apache.lucene.store.Directory;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.SolrException.ErrorCode;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.core.DirectoryFactory.DirContext;
-import org.apache.solr.core.IndexDeletionPolicyWrapper;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.backup.repository.BackupRepository;
-import org.apache.solr.core.backup.repository.BackupRepository.PathType;
-import org.apache.solr.core.backup.repository.LocalFileSystemRepository;
-import org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * <p> Provides functionality equivalent to the snapshooter script </p>
- * This is no longer used in standard replication.
- *
- *
- * @since solr 1.4
- */
-public class SnapShooter {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- private SolrCore solrCore;
- private String snapshotName = null;
- private String directoryName = null;
- private URI baseSnapDirPath = null;
- private URI snapshotDirPath = null;
- private BackupRepository backupRepo = null;
- private String commitName; // can be null
-
- @Deprecated
- public SnapShooter(SolrCore core, String location, String snapshotName) {
- String snapDirStr = null;
- // Note - This logic is only applicable to the usecase where a shared file-system is exposed via
- // local file-system interface (primarily for backwards compatibility). For other use-cases, users
- // will be required to specify "location" where the backup should be stored.
- if (location == null) {
- snapDirStr = core.getDataDir();
- } else {
- snapDirStr = core.getCoreDescriptor().getInstanceDir().resolve(location).normalize().toString();
- }
- initialize(new LocalFileSystemRepository(), core, Paths.get(snapDirStr).toUri(), snapshotName, null);
- }
-
- public SnapShooter(BackupRepository backupRepo, SolrCore core, URI location, String snapshotName, String commitName) {
- initialize(backupRepo, core, location, snapshotName, commitName);
- }
-
- private void initialize(BackupRepository backupRepo, SolrCore core, URI location, String snapshotName, String commitName) {
- this.solrCore = Objects.requireNonNull(core);
- this.backupRepo = Objects.requireNonNull(backupRepo);
- this.baseSnapDirPath = location;
- this.snapshotName = snapshotName;
- if (snapshotName != null) {
- directoryName = "snapshot." + snapshotName;
- } else {
- SimpleDateFormat fmt = new SimpleDateFormat(DATE_FMT, Locale.ROOT);
- directoryName = "snapshot." + fmt.format(new Date());
- }
- this.snapshotDirPath = backupRepo.resolve(location, directoryName);
- this.commitName = commitName;
- }
-
- public BackupRepository getBackupRepository() {
- return backupRepo;
- }
-
- /**
- * Gets the parent directory of the snapshots. This is the {@code location}
- * given in the constructor.
- */
- public URI getLocation() {
- return this.baseSnapDirPath;
- }
-
- public void validateDeleteSnapshot() {
- Objects.requireNonNull(this.snapshotName);
-
- boolean dirFound = false;
- String[] paths;
- try {
- paths = backupRepo.listAll(baseSnapDirPath);
- for (String path : paths) {
- if (path.equals(this.directoryName)
- && backupRepo.getPathType(baseSnapDirPath.resolve(path)) == PathType.DIRECTORY) {
- dirFound = true;
- break;
- }
- }
- if(dirFound == false) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Snapshot " + snapshotName + " cannot be found in directory: " + baseSnapDirPath);
- }
- } catch (IOException e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to find snapshot " + snapshotName + " in directory: " + baseSnapDirPath, e);
- }
- }
-
- protected void deleteSnapAsync(final ReplicationHandler replicationHandler) {
- new Thread(() -> deleteNamedSnapshot(replicationHandler)).start();
- }
-
- public void validateCreateSnapshot() throws IOException {
- // Note - Removed the current behavior of creating the directory hierarchy.
- // Do we really need to provide this support?
- if (!backupRepo.exists(baseSnapDirPath)) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- " Directory does not exist: " + snapshotDirPath);
- }
-
- if (backupRepo.exists(snapshotDirPath)) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
- "Snapshot directory already exists: " + snapshotDirPath);
- }
- }
-
- public NamedList createSnapshot() throws Exception {
- IndexCommit indexCommit;
- if (commitName != null) {
- indexCommit = getIndexCommitFromName();
- return createSnapshot(indexCommit);
- } else {
- indexCommit = getIndexCommit();
- IndexDeletionPolicyWrapper deletionPolicy = solrCore.getDeletionPolicy();
- deletionPolicy.saveCommitPoint(indexCommit.getGeneration());
- try {
- return createSnapshot(indexCommit);
- } finally {
- deletionPolicy.releaseCommitPoint(indexCommit.getGeneration());
- }
- }
- }
-
- private IndexCommit getIndexCommit() throws IOException {
- IndexDeletionPolicyWrapper delPolicy = solrCore.getDeletionPolicy();
- IndexCommit indexCommit = delPolicy.getLatestCommit();
- if (indexCommit != null) {
- return indexCommit;
- }
- return solrCore.withSearcher(searcher -> searcher.getIndexReader().getIndexCommit());
- }
-
- private IndexCommit getIndexCommitFromName() throws IOException {
- assert commitName !=null;
- IndexCommit indexCommit;
- SolrSnapshotMetaDataManager snapshotMgr = solrCore.getSnapshotMetaDataManager();
- Optional<IndexCommit> commit = snapshotMgr.getIndexCommitByName(commitName);
- if (commit.isPresent()) {
- indexCommit = commit.get();
- } else {
- throw new SolrException(ErrorCode.BAD_REQUEST, "Unable to find an index commit with name " + commitName +
- " for core " + solrCore.getName());
- }
- return indexCommit;
- }
-
- public void createSnapAsync(final int numberToKeep, Consumer<NamedList> result) throws IOException {
- IndexCommit indexCommit;
- if (commitName != null) {
- indexCommit = getIndexCommitFromName();
- } else {
- indexCommit = getIndexCommit();
- }
- createSnapAsync(indexCommit, numberToKeep, result);
- }
-
- private void createSnapAsync(final IndexCommit indexCommit, final int numberToKeep, Consumer<NamedList> result) {
- //TODO should use Solr's ExecutorUtil
- new Thread(() -> {
- try {
- result.accept(createSnapshot(indexCommit));
- } catch (Exception e) {
- log.error("Exception while creating snapshot", e);
- NamedList snapShootDetails = new NamedList<>();
- snapShootDetails.add("exception", e.getMessage());
- result.accept(snapShootDetails);
- } finally {
- solrCore.getDeletionPolicy().releaseCommitPoint(indexCommit.getGeneration());
- }
- if (snapshotName == null) {
- try {
- deleteOldBackups(numberToKeep);
- } catch (IOException e) {
- log.warn("Unable to delete old snapshots ", e);
- }
- }
- }).start();
-
- }
-
- // note: remember to reserve the indexCommit first so it won't get deleted concurrently
- protected NamedList createSnapshot(final IndexCommit indexCommit) throws Exception {
- assert indexCommit != null;
- log.info("Creating backup snapshot " + (snapshotName == null ? "<not named>" : snapshotName) + " at " + baseSnapDirPath);
- boolean success = false;
- try {
- NamedList<Object> details = new NamedList<>();
- details.add("startTime", new Date().toString());//bad; should be Instant.now().toString()
-
- Collection<String> files = indexCommit.getFileNames();
- Directory dir = solrCore.getDirectoryFactory().get(solrCore.getIndexDir(), DirContext.DEFAULT, solrCore.getSolrConfig().indexConfig.lockType);
- try {
- for(String fileName : files) {
- backupRepo.copyFileFrom(dir, fileName, snapshotDirPath);
- }
- } finally {
- solrCore.getDirectoryFactory().release(dir);
- }
-
- details.add("fileCount", files.size());
- details.add("status", "success");
- details.add("snapshotCompletedAt", new Date().toString());//bad; should be Instant.now().toString()
- details.add("snapshotName", snapshotName);
- log.info("Done creating backup snapshot: " + (snapshotName == null ? "<not named>" : snapshotName) +
- " at " + baseSnapDirPath);
- success = true;
- return details;
- } finally {
- if (!success) {
- try {
- backupRepo.deleteDirectory(snapshotDirPath);
- } catch (Exception excDuringDelete) {
- log.warn("Failed to delete "+snapshotDirPath+" after snapshot creation failed due to: "+excDuringDelete);
- }
- }
- }
- }
-
- private void deleteOldBackups(int numberToKeep) throws IOException {
- String[] paths = backupRepo.listAll(baseSnapDirPath);
- List<OldBackupDirectory> dirs = new ArrayList<>();
- for (String f : paths) {
- if (backupRepo.getPathType(baseSnapDirPath.resolve(f)) == PathType.DIRECTORY) {
- OldBackupDirectory obd = new OldBackupDirectory(baseSnapDirPath, f);
- if (obd.getTimestamp().isPresent()) {
- dirs.add(obd);
- }
- }
- }
- if (numberToKeep > dirs.size() -1) {
- return;
- }
- Collections.sort(dirs);
- int i=1;
- for (OldBackupDirectory dir : dirs) {
- if (i++ > numberToKeep) {
- backupRepo.deleteDirectory(dir.getPath());
- }
- }
- }
-
- protected void deleteNamedSnapshot(ReplicationHandler replicationHandler) {
- log.info("Deleting snapshot: " + snapshotName);
-
- NamedList<Object> details = new NamedList<>();
-
- try {
- URI path = baseSnapDirPath.resolve("snapshot." + snapshotName);
- backupRepo.deleteDirectory(path);
-
- details.add("status", "success");
- details.add("snapshotDeletedAt", new Date().toString());
-
- } catch (IOException e) {
- details.add("status", "Unable to delete snapshot: " + snapshotName);
- log.warn("Unable to delete snapshot: " + snapshotName, e);
- }
-
- replicationHandler.snapShootDetails = details;
- }
-
- public static final String DATE_FMT = "yyyyMMddHHmmssSSS";
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java b/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java
deleted file mode 100644
index 53d543f..0000000
--- a/solr/core/src/java/org/apache/solr/handler/SolrConfigHandler.java
+++ /dev/null
@@ -1,898 +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;
-
-import java.io.IOException;
-import java.lang.invoke.MethodHandles;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import org.apache.solr.api.Api;
-import org.apache.solr.api.ApiBag;
-import org.apache.solr.client.solrj.SolrClient;
-import org.apache.solr.client.solrj.SolrRequest;
-import org.apache.solr.client.solrj.SolrResponse;
-import org.apache.solr.client.solrj.impl.HttpSolrClient;
-import org.apache.solr.cloud.ZkController;
-import org.apache.solr.cloud.ZkSolrResourceLoader;
-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.Replica;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.MapSolrParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.CommandOperation;
-import org.apache.solr.common.util.ExecutorUtil;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.StrUtils;
-import org.apache.solr.common.util.Utils;
-import org.apache.solr.core.ConfigOverlay;
-import org.apache.solr.core.PluginInfo;
-import org.apache.solr.core.RequestParams;
-import org.apache.solr.core.SolrConfig;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.core.SolrResourceLoader;
-import org.apache.solr.request.LocalSolrQueryRequest;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
-import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.schema.SchemaManager;
-import org.apache.solr.security.AuthorizationContext;
-import org.apache.solr.security.PermissionNameProvider;
-import org.apache.solr.util.DefaultSolrThreadFactory;
-import org.apache.solr.util.RTimer;
-import org.apache.solr.util.SolrPluginUtils;
-import org.apache.solr.util.plugin.SolrCoreAware;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static com.google.common.base.Strings.isNullOrEmpty;
-import static java.util.Collections.singletonList;
-import static org.apache.solr.common.params.CoreAdminParams.NAME;
-import static org.apache.solr.common.util.StrUtils.formatString;
-import static org.apache.solr.common.util.Utils.makeMap;
-import static org.apache.solr.core.ConfigOverlay.NOT_EDITABLE;
-import static org.apache.solr.core.ConfigOverlay.ZNODEVER;
-import static org.apache.solr.core.ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG;
-import static org.apache.solr.core.PluginInfo.APPENDS;
-import static org.apache.solr.core.PluginInfo.DEFAULTS;
-import static org.apache.solr.core.PluginInfo.INVARIANTS;
-import static org.apache.solr.core.RequestParams.USEPARAM;
-import static org.apache.solr.core.SolrConfig.PluginOpts.REQUIRE_CLASS;
-import static org.apache.solr.core.SolrConfig.PluginOpts.REQUIRE_NAME;
-import static org.apache.solr.core.SolrConfig.PluginOpts.REQUIRE_NAME_IN_OVERLAY;
-import static org.apache.solr.schema.FieldType.CLASS_NAME;
-
-public class SolrConfigHandler extends RequestHandlerBase implements SolrCoreAware, PermissionNameProvider {
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- public static final String CONFIGSET_EDITING_DISABLED_ARG = "disable.configEdit";
- public static final boolean configEditing_disabled = Boolean.getBoolean(CONFIGSET_EDITING_DISABLED_ARG);
- private static final Map<String, SolrConfig.SolrPluginInfo> namedPlugins;
- private Lock reloadLock = new ReentrantLock(true);
-
- public Lock getReloadLock() {
- return reloadLock;
- }
-
- private boolean isImmutableConfigSet = false;
-
- static {
- Map<String, SolrConfig.SolrPluginInfo> map = new HashMap<>();
- for (SolrConfig.SolrPluginInfo plugin : SolrConfig.plugins) {
- if (plugin.options.contains(REQUIRE_NAME) || plugin.options.contains(REQUIRE_NAME_IN_OVERLAY)) {
- map.put(plugin.getCleanTag().toLowerCase(Locale.ROOT), plugin);
- }
- }
- namedPlugins = Collections.unmodifiableMap(map);
- }
-
- @Override
- public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
-
- RequestHandlerUtils.setWt(req, CommonParams.JSON);
- String httpMethod = (String) req.getContext().get("httpMethod");
- Command command = new Command(req, rsp, httpMethod);
- if ("POST".equals(httpMethod)) {
- if (configEditing_disabled || isImmutableConfigSet) {
- final String reason = configEditing_disabled ? "due to " + CONFIGSET_EDITING_DISABLED_ARG : "because ConfigSet is immutable";
- throw new SolrException(SolrException.ErrorCode.FORBIDDEN, " solrconfig editing is not enabled " + reason);
- }
- try {
- command.handlePOST();
- } finally {
- RequestHandlerUtils.addExperimentalFormatWarning(rsp);
- }
- } else {
- command.handleGET();
- }
- }
-
- @Override
- public void inform(SolrCore core) {
- isImmutableConfigSet = getImmutable(core);
- }
-
- public static boolean getImmutable(SolrCore core) {
- NamedList configSetProperties = core.getConfigSetProperties();
- if(configSetProperties == null) return false;
- Object immutable = configSetProperties.get(IMMUTABLE_CONFIGSET_ARG);
- return immutable != null ? Boolean.parseBoolean(immutable.toString()) : false;
- }
-
-
- private class Command {
- private final SolrQueryRequest req;
- private final SolrQueryResponse resp;
- private final String method;
- private String path;
- List<String> parts;
-
- private Command(SolrQueryRequest req, SolrQueryResponse resp, String httpMethod) {
- this.req = req;
- this.resp = resp;
- this.method = httpMethod;
- path = (String) req.getContext().get("path");
- if (path == null) path = getDefaultPath();
- parts = StrUtils.splitSmart(path, '/');
- if (parts.get(0).isEmpty()) parts.remove(0);
- }
-
- private String getDefaultPath() {
- return "/config";
- }
-
- private void handleGET() {
- if (parts.size() == 1) {
- //this is the whole config. sent out the whole payload
- resp.add("config", getConfigDetails(null, req));
- } else {
- if (ConfigOverlay.NAME.equals(parts.get(1))) {
- resp.add(ConfigOverlay.NAME, req.getCore().getSolrConfig().getOverlay());
- } else if (RequestParams.NAME.equals(parts.get(1))) {
- if (parts.size() == 3) {
- RequestParams params = req.getCore().getSolrConfig().getRequestParams();
- RequestParams.ParamSet p = params.getParams(parts.get(2));
- Map m = new LinkedHashMap<>();
- m.put(ZNODEVER, params.getZnodeVersion());
- if (p != null) {
- m.put(RequestParams.NAME, makeMap(parts.get(2), p.toMap(new LinkedHashMap<>())));
- }
- resp.add(SolrQueryResponse.NAME, m);
- } else {
- resp.add(SolrQueryResponse.NAME, req.getCore().getSolrConfig().getRequestParams());
- }
-
- } else {
- if (ZNODEVER.equals(parts.get(1))) {
- resp.add(ZNODEVER, Utils.makeMap(
- ConfigOverlay.NAME, req.getCore().getSolrConfig().getOverlay().getZnodeVersion(),
- RequestParams.NAME, req.getCore().getSolrConfig().getRequestParams().getZnodeVersion()));
- boolean isStale = false;
- int expectedVersion = req.getParams().getInt(ConfigOverlay.NAME, -1);
- int actualVersion = req.getCore().getSolrConfig().getOverlay().getZnodeVersion();
- if (expectedVersion > actualVersion) {
- log.info("expecting overlay version {} but my version is {}", expectedVersion, actualVersion);
- isStale = true;
- } else if (expectedVersion != -1) {
- log.info("I already have the expected version {} of config", expectedVersion);
- }
- expectedVersion = req.getParams().getInt(RequestParams.NAME, -1);
- actualVersion = req.getCore().getSolrConfig().getRequestParams().getZnodeVersion();
- if (expectedVersion > actualVersion) {
- log.info("expecting params version {} but my version is {}", expectedVersion, actualVersion);
- isStale = true;
- } else if (expectedVersion != -1) {
- log.info("I already have the expected version {} of params", expectedVersion);
- }
- if (isStale && req.getCore().getResourceLoader() instanceof ZkSolrResourceLoader) {
- new Thread(() -> {
- if (!reloadLock.tryLock()) {
- log.info("Another reload is in progress . Not doing anything");
- return;
- }
- try {
- log.info("Trying to update my configs");
- SolrCore.getConfListener(req.getCore(), (ZkSolrResourceLoader) req.getCore().getResourceLoader()).run();
- } catch (Exception e) {
- log.error("Unable to refresh conf ", e);
- } finally {
- reloadLock.unlock();
- }
- }, SolrConfigHandler.class.getSimpleName() + "-refreshconf").start();
- } else {
- log.info("isStale {} , resourceloader {}", isStale, req.getCore().getResourceLoader().getClass().getName());
- }
-
- } else {
- Map<String, Object> m = getConfigDetails(parts.get(1), req);
- Map<String, Object> val = makeMap(parts.get(1), m.get(parts.get(1)));
- String componentName = req.getParams().get("componentName");
- if (componentName != null) {
- Map map = (Map) val.get(parts.get(1));
- if (map != null) {
- val.put(parts.get(1), makeMap(componentName, map.get(componentName)));
- }
- }
-
- resp.add("config", val);
- }
- }
- }
- }
-
- private Map<String, Object> getConfigDetails(String componentType, SolrQueryRequest req) {
- String componentName = componentType == null ? null : req.getParams().get("componentName");
- boolean showParams = req.getParams().getBool("expandParams", false);
- Map<String, Object> map = this.req.getCore().getSolrConfig().toMap(new LinkedHashMap<>());
- if (componentType != null && !SolrRequestHandler.TYPE.equals(componentType)) return map;
- Map reqHandlers = (Map) map.get(SolrRequestHandler.TYPE);
- if (reqHandlers == null) map.put(SolrRequestHandler.TYPE, reqHandlers = new LinkedHashMap<>());
- List<PluginInfo> plugins = this.req.getCore().getImplicitHandlers();
- for (PluginInfo plugin : plugins) {
- if (SolrRequestHandler.TYPE.equals(plugin.type)) {
- if (!reqHandlers.containsKey(plugin.name)) {
- reqHandlers.put(plugin.name, plugin);
- }
- }
- }
- if (!showParams) return map;
- for (Object o : reqHandlers.entrySet()) {
- Map.Entry e = (Map.Entry) o;
- if (componentName == null || e.getKey().equals(componentName)) {
- Map<String, Object> m = expandUseParams(req, e.getValue());
- e.setValue(m);
- }
- }
-
- return map;
- }
-
- private Map<String, Object> expandUseParams(SolrQueryRequest req,
- Object plugin) {
-
- Map<String, Object> pluginInfo = null;
- if (plugin instanceof Map) {
- pluginInfo = (Map) plugin;
- } else if (plugin instanceof PluginInfo) {
- pluginInfo = ((PluginInfo) plugin).toMap(new LinkedHashMap<>());
- }
- String useParams = (String) pluginInfo.get(USEPARAM);
- String useparamsInReq = req.getOriginalParams().get(USEPARAM);
- if (useParams != null || useparamsInReq != null) {
- Map m = new LinkedHashMap<>();
- pluginInfo.put("_useParamsExpanded_", m);
- List<String> params = new ArrayList<>();
- if (useParams != null) params.addAll(StrUtils.splitSmart(useParams, ','));
- if (useparamsInReq != null) params.addAll(StrUtils.splitSmart(useparamsInReq, ','));
- for (String param : params) {
- RequestParams.ParamSet p = this.req.getCore().getSolrConfig().getRequestParams().getParams(param);
- if (p != null) {
- m.put(param, p);
- } else {
- m.put(param, "[NOT AVAILABLE]");
- }
- }
-
-
- LocalSolrQueryRequest r = new LocalSolrQueryRequest(req.getCore(), req.getOriginalParams());
- r.getContext().put(USEPARAM, useParams);
- NamedList nl = new PluginInfo(SolrRequestHandler.TYPE, pluginInfo).initArgs;
- SolrPluginUtils.setDefaults(r,
- getSolrParamsFromNamedList(nl, DEFAULTS),
- getSolrParamsFromNamedList(nl, APPENDS),
- getSolrParamsFromNamedList(nl, INVARIANTS));
- //SolrParams.wrapDefaults(maskUseParams, req.getParams())
-
- MapSolrParams mask = new MapSolrParams(ImmutableMap.<String, String>builder()
- .put("componentName", "")
- .put("expandParams", "")
- .build());
- pluginInfo.put("_effectiveParams_",
- SolrParams.wrapDefaults(mask, r.getParams()));
- }
- return pluginInfo;
- }
-
-
- private void handlePOST() throws IOException {
- List<CommandOperation> ops = CommandOperation.readCommands(req.getContentStreams(), resp.getValues());
- if (ops == null) return;
- try {
- for (; ; ) {
- ArrayList<CommandOperation> opsCopy = new ArrayList<>(ops.size());
- for (CommandOperation op : ops) opsCopy.add(op.getCopy());
- try {
- if (parts.size() > 1 && RequestParams.NAME.equals(parts.get(1))) {
- RequestParams params = RequestParams.getFreshRequestParams(req.getCore().getResourceLoader(), req.getCore().getSolrConfig().getRequestParams());
- handleParams(opsCopy, params);
- } else {
- ConfigOverlay overlay = SolrConfig.getConfigOverlay(req.getCore().getResourceLoader());
- handleCommands(opsCopy, overlay);
- }
- break;//succeeded . so no need to go over the loop again
- } catch (ZkController.ResourceModifiedInZkException e) {
- //retry
- log.info("Race condition, the node is modified in ZK by someone else " + e.getMessage());
- }
- }
- } catch (Exception e) {
- resp.setException(e);
- resp.add(CommandOperation.ERR_MSGS, singletonList(SchemaManager.getErrorStr(e)));
- }
-
- }
-
-
- private void handleParams(ArrayList<CommandOperation> ops, RequestParams params) {
- for (CommandOperation op : ops) {
- switch (op.name) {
- case SET:
- case UPDATE: {
- Map<String, Object> map = op.getDataMap();
- if (op.hasError()) break;
-
- for (Map.Entry<String, Object> entry : map.entrySet()) {
-
- Map val;
- String key = entry.getKey();
- if (isNullOrEmpty(key)) {
- op.addError("null key ");
- continue;
- }
- key = key.trim();
- String err = validateName(key);
- if (err != null) {
- op.addError(err);
- continue;
- }
-
- try {
- val = (Map) entry.getValue();
- } catch (Exception e1) {
- op.addError("invalid params for key : " + key);
- continue;
- }
-
- if (val.containsKey("")) {
- op.addError("Empty keys are not allowed in params");
- continue;
- }
-
- RequestParams.ParamSet old = params.getParams(key);
- if (op.name.equals(UPDATE)) {
- if (old == null) {
- op.addError(formatString("unknown paramset {0} cannot update ", key));
- continue;
- }
- params = params.setParams(key, old.update(val));
- } else {
- Long version = old == null ? 0 : old.getVersion() + 1;
- params = params.setParams(key, RequestParams.createParamSet(val, version));
- }
-
- }
- break;
-
- }
- case "delete": {
- List<String> name = op.getStrs(CommandOperation.ROOT_OBJ);
- if (op.hasError()) break;
- for (String s : name) {
- if (params.getParams(s) == null) {
- op.addError(formatString("can't delete . No such params ''{0}'' exist", s));
- }
- params = params.setParams(s, null);
- }
- }
- }
- }
-
-
- List errs = CommandOperation.captureErrors(ops);
- if (!errs.isEmpty()) {
- throw new ApiBag.ExceptionWithErrObject(SolrException.ErrorCode.BAD_REQUEST,"error processing params", errs);
- }
-
- SolrResourceLoader loader = req.getCore().getResourceLoader();
- if (loader instanceof ZkSolrResourceLoader) {
- ZkSolrResourceLoader zkLoader = (ZkSolrResourceLoader) loader;
- if (ops.isEmpty()) {
- ZkController.touchConfDir(zkLoader);
- } else {
- log.debug("persisting params data : {}", Utils.toJSONString(params.toMap(new LinkedHashMap<>())));
- int latestVersion = ZkController.persistConfigResourceToZooKeeper(zkLoader,
- params.getZnodeVersion(), RequestParams.RESOURCE, params.toByteArray(), true);
-
- log.debug("persisted to version : {} ", latestVersion);
- waitForAllReplicasState(req.getCore().getCoreDescriptor().getCloudDescriptor().getCollectionName(),
- req.getCore().getCoreContainer().getZkController(), RequestParams.NAME, latestVersion, 30);
- }
-
- } else {
- SolrResourceLoader.persistConfLocally(loader, RequestParams.RESOURCE, params.toByteArray());
- req.getCore().getSolrConfig().refreshRequestParams();
- }
-
- }
-
- private void handleCommands(List<CommandOperation> ops, ConfigOverlay overlay) throws IOException {
- for (CommandOperation op : ops) {
- switch (op.name) {
- case SET_PROPERTY:
- overlay = applySetProp(op, overlay);
- break;
- case UNSET_PROPERTY:
- overlay = applyUnset(op, overlay);
- break;
- case SET_USER_PROPERTY:
- overlay = applySetUserProp(op, overlay);
- break;
- case UNSET_USER_PROPERTY:
- overlay = applyUnsetUserProp(op, overlay);
- break;
- default: {
- List<String> pcs = StrUtils.splitSmart(op.name.toLowerCase(Locale.ROOT), '-');
- if (pcs.size() != 2) {
- op.addError(formatString("Unknown operation ''{0}'' ", op.name));
- } else {
- String prefix = pcs.get(0);
- String name = pcs.get(1);
- if (cmdPrefixes.contains(prefix) && namedPlugins.containsKey(name)) {
- SolrConfig.SolrPluginInfo info = namedPlugins.get(name);
- if ("delete".equals(prefix)) {
- overlay = deleteNamedComponent(op, overlay, info.getCleanTag());
- } else {
- overlay = updateNamedPlugin(info, op, overlay, prefix.equals("create") || prefix.equals("add"));
- }
- } else {
- op.unknownOperation();
- }
- }
- }
- }
- }
- List errs = CommandOperation.captureErrors(ops);
- if (!errs.isEmpty()) {
- throw new ApiBag.ExceptionWithErrObject(SolrException.ErrorCode.BAD_REQUEST,"error processing commands", errs);
- }
-
- SolrResourceLoader loader = req.getCore().getResourceLoader();
- if (loader instanceof ZkSolrResourceLoader) {
- int latestVersion = ZkController.persistConfigResourceToZooKeeper((ZkSolrResourceLoader) loader, overlay.getZnodeVersion(),
- ConfigOverlay.RESOURCE_NAME, overlay.toByteArray(), true);
- log.info("Executed config commands successfully and persisted to ZK {}", ops);
- waitForAllReplicasState(req.getCore().getCoreDescriptor().getCloudDescriptor().getCollectionName(),
- req.getCore().getCoreContainer().getZkController(),
- ConfigOverlay.NAME,
- latestVersion, 30);
- } else {
- SolrResourceLoader.persistConfLocally(loader, ConfigOverlay.RESOURCE_NAME, overlay.toByteArray());
- req.getCore().getCoreContainer().reload(req.getCore().getName());
- log.info("Executed config commands successfully and persited to File System {}", ops);
- }
-
- }
-
- private ConfigOverlay deleteNamedComponent(CommandOperation op, ConfigOverlay overlay, String typ) {
- String name = op.getStr(CommandOperation.ROOT_OBJ);
- if (op.hasError()) return overlay;
- if (overlay.getNamedPlugins(typ).containsKey(name)) {
- return overlay.deleteNamedPlugin(name, typ);
- } else {
- op.addError(formatString("NO such {0} ''{1}'' ", typ, name));
- return overlay;
- }
- }
-
- private ConfigOverlay updateNamedPlugin(SolrConfig.SolrPluginInfo info, CommandOperation op, ConfigOverlay overlay, boolean isCeate) {
- String name = op.getStr(NAME);
- String clz = info.options.contains(REQUIRE_CLASS) ? op.getStr(CLASS_NAME) : op.getStr(CLASS_NAME, null);
- op.getMap(DEFAULTS, null);
- op.getMap(PluginInfo.INVARIANTS, null);
- op.getMap(PluginInfo.APPENDS, null);
- if (op.hasError()) return overlay;
- if (!verifyClass(op, clz, info.clazz)) return overlay;
- if (pluginExists(info, overlay, name)) {
- if (isCeate) {
- op.addError(formatString(" ''{0}'' already exists . Do an ''{1}'' , if you want to change it ", name, "update-" + info.getTagCleanLower()));
- return overlay;
- } else {
- return overlay.addNamedPlugin(op.getDataMap(), info.getCleanTag());
- }
- } else {
- if (isCeate) {
- return overlay.addNamedPlugin(op.getDataMap(), info.getCleanTag());
- } else {
- op.addError(formatString(" ''{0}'' does not exist . Do an ''{1}'' , if you want to create it ", name, "create-" + info.getTagCleanLower()));
- return overlay;
- }
- }
- }
-
- private boolean pluginExists(SolrConfig.SolrPluginInfo info, ConfigOverlay overlay, String name) {
- List<PluginInfo> l = req.getCore().getSolrConfig().getPluginInfos(info.clazz.getName());
- for (PluginInfo pluginInfo : l) if(name.equals( pluginInfo.name)) return true;
- return overlay.getNamedPlugins(info.getCleanTag()).containsKey(name);
- }
-
- private boolean verifyClass(CommandOperation op, String clz, Class expected) {
- if (clz == null) return true;
- if (!"true".equals(String.valueOf(op.getStr("runtimeLib", null)))) {
- //this is not dynamically loaded so we can verify the class right away
- try {
- req.getCore().createInitInstance(new PluginInfo(SolrRequestHandler.TYPE, op.getDataMap()), expected, clz, "");
- } catch (Exception e) {
- op.addError(e.getMessage());
- return false;
- }
-
- }
- return true;
- }
-
- private ConfigOverlay applySetUserProp(CommandOperation op, ConfigOverlay overlay) {
- Map<String, Object> m = op.getDataMap();
- if (op.hasError()) return overlay;
- for (Map.Entry<String, Object> e : m.entrySet()) {
- String name = e.getKey();
- Object val = e.getValue();
- overlay = overlay.setUserProperty(name, val);
- }
- return overlay;
- }
-
- private ConfigOverlay applyUnsetUserProp(CommandOperation op, ConfigOverlay overlay) {
- List<String> name = op.getStrs(CommandOperation.ROOT_OBJ);
- if (op.hasError()) return overlay;
- for (String o : name) {
- if (!overlay.getUserProps().containsKey(o)) {
- op.addError(formatString("No such property ''{0}''", name));
- } else {
- overlay = overlay.unsetUserProperty(o);
- }
- }
- return overlay;
- }
-
-
- private ConfigOverlay applyUnset(CommandOperation op, ConfigOverlay overlay) {
- List<String> name = op.getStrs(CommandOperation.ROOT_OBJ);
- if (op.hasError()) return overlay;
-
- for (String o : name) {
- if (!ConfigOverlay.isEditableProp(o, false, null)) {
- op.addError(formatString(NOT_EDITABLE, name));
- } else {
- overlay = overlay.unsetProperty(o);
- }
- }
- return overlay;
- }
-
- private ConfigOverlay applySetProp(CommandOperation op, ConfigOverlay overlay) {
- Map<String, Object> m = op.getDataMap();
- if (op.hasError()) return overlay;
- for (Map.Entry<String, Object> e : m.entrySet()) {
- String name = e.getKey();
- Object val = e.getValue();
- Class typ = ConfigOverlay.checkEditable(name, false, null);
- if (typ == null) {
- op.addError(formatString(NOT_EDITABLE, name));
- continue;
- }
-
- if (val != null) {
- if (typ == String.class) val = val.toString();
- String typeErr = "Property {0} must be of {1} type ";
- if (typ == Boolean.class) {
- try {
- val = Boolean.parseBoolean(val.toString());
- } catch (Exception exp) {
- op.addError(formatString(typeErr, name, typ.getSimpleName()));
- continue;
- }
- } else if (typ == Integer.class) {
- try {
- val = Integer.parseInt(val.toString());
- } catch (Exception exp) {
- op.addError(formatString(typeErr, name, typ.getSimpleName()));
- continue;
- }
-
- } else if (typ == Float.class) {
- try {
- val = Float.parseFloat(val.toString());
- } catch (Exception exp) {
- op.addError(formatString(typeErr, name, typ.getSimpleName()));
- continue;
- }
-
- }
- }
-
-
- overlay = overlay.setProperty(name, val);
- }
- return overlay;
- }
-
- }
-
- public static String validateName(String s) {
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if ((c >= 'A' && c <= 'Z') ||
- (c >= 'a' && c <= 'z') ||
- (c >= '0' && c <= '9') ||
- c == '_' ||
- c == '-' ||
- c == '.'
- ) continue;
- else {
- return formatString("''{0}'' name should only have chars [a-zA-Z_-.0-9] ", s);
- }
- }
- return null;
- }
-
- @Override
- public SolrRequestHandler getSubHandler(String path) {
- if (subPaths.contains(path)) return this;
- if (path.startsWith("/params/")) return this;
- return null;
- }
-
-
- private static Set<String> subPaths = new HashSet<>(Arrays.asList("/overlay", "/params", "/updateHandler",
- "/query", "/jmx", "/requestDispatcher", "/znodeVersion"));
-
- static {
- for (SolrConfig.SolrPluginInfo solrPluginInfo : SolrConfig.plugins)
- subPaths.add("/" + solrPluginInfo.getCleanTag());
-
- }
-
- //////////////////////// SolrInfoMBeans methods //////////////////////
-
-
- @Override
- public String getDescription() {
- return "Edit solrconfig.xml";
- }
-
- @Override
- public Category getCategory() {
- return Category.ADMIN;
- }
-
-
- public static final String SET_PROPERTY = "set-property";
- public static final String UNSET_PROPERTY = "unset-property";
- public static final String SET_USER_PROPERTY = "set-user-property";
- public static final String UNSET_USER_PROPERTY = "unset-user-property";
- public static final String SET = "set";
- public static final String UPDATE = "update";
- public static final String CREATE = "create";
- private static Set<String> cmdPrefixes = ImmutableSet.of(CREATE, UPDATE, "delete", "add");
-
- /**
- * Block up to a specified maximum time until we see agreement on the schema
- * version in ZooKeeper across all replicas for a collection.
- */
- private static void waitForAllReplicasState(String collection,
- ZkController zkController,
- String prop,
- int expectedVersion,
- int maxWaitSecs) {
- final RTimer timer = new RTimer();
- // get a list of active replica cores to query for the schema zk version (skipping this core of course)
- List<PerReplicaCallable> concurrentTasks = new ArrayList<>();
-
- for (String coreUrl : getActiveReplicaCoreUrls(zkController, collection)) {
- PerReplicaCallable e = new PerReplicaCallable(coreUrl, prop, expectedVersion, maxWaitSecs);
- concurrentTasks.add(e);
- }
- if (concurrentTasks.isEmpty()) return; // nothing to wait for ...
-
- log.info(formatString("Waiting up to {0} secs for {1} replicas to set the property {2} to be of version {3} for collection {4}",
- maxWaitSecs, concurrentTasks.size(), prop, expectedVersion, collection));
-
- // use an executor service to invoke schema zk version requests in parallel with a max wait time
- int poolSize = Math.min(concurrentTasks.size(), 10);
- ExecutorService parallelExecutor =
- ExecutorUtil.newMDCAwareFixedThreadPool(poolSize, new DefaultSolrThreadFactory("solrHandlerExecutor"));
- try {
- List<Future<Boolean>> results =
- parallelExecutor.invokeAll(concurrentTasks, maxWaitSecs, TimeUnit.SECONDS);
-
- // determine whether all replicas have the update
- List<String> failedList = null; // lazily init'd
- for (int f = 0; f < results.size(); f++) {
- Boolean success = false;
- Future<Boolean> next = results.get(f);
- if (next.isDone() && !next.isCancelled()) {
- // looks to have finished, but need to check if it succeeded
- try {
- success = next.get();
- } catch (ExecutionException e) {
- // shouldn't happen since we checked isCancelled
- }
- }
-
- if (!success) {
- String coreUrl = concurrentTasks.get(f).coreUrl;
- log.warn("Core " + coreUrl + "could not get the expected version " + expectedVersion);
- if (failedList == null) failedList = new ArrayList<>();
- failedList.add(coreUrl);
- }
- }
-
- // if any tasks haven't completed within the specified timeout, it's an error
- if (failedList != null)
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- formatString("{0} out of {1} the property {2} to be of version {3} within {4} seconds! Failed cores: {5}",
- failedList.size(), concurrentTasks.size() + 1, prop, expectedVersion, maxWaitSecs, failedList));
-
- } catch (InterruptedException ie) {
- log.warn(formatString(
- "Core was interrupted . trying to set the property {1} to version {2} to propagate to {3} replicas for collection {4}",
- prop, expectedVersion, concurrentTasks.size(), collection));
- Thread.currentThread().interrupt();
- } finally {
- ExecutorUtil.shutdownAndAwaitTermination(parallelExecutor);
- }
-
- log.info("Took {}ms to set the property {} to be of version {} for collection {}",
- timer.getTime(), prop, expectedVersion, collection);
- }
-
- public static List<String> getActiveReplicaCoreUrls(ZkController zkController,
- String collection) {
- List<String> activeReplicaCoreUrls = new ArrayList<>();
- ClusterState clusterState = zkController.getZkStateReader().getClusterState();
- Set<String> liveNodes = clusterState.getLiveNodes();
- final DocCollection docCollection = clusterState.getCollectionOrNull(collection);
- if (docCollection != null && docCollection.getActiveSlices() != null && docCollection.getActiveSlices().size() > 0) {
- final Collection<Slice> activeSlices = docCollection.getActiveSlices();
- for (Slice next : activeSlices) {
- Map<String, Replica> replicasMap = next.getReplicasMap();
- if (replicasMap != null) {
- for (Map.Entry<String, Replica> entry : replicasMap.entrySet()) {
- Replica replica = entry.getValue();
- if (replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())) {
- activeReplicaCoreUrls.add(replica.getCoreUrl());
- }
- }
- }
- }
- }
- return activeReplicaCoreUrls;
- }
-
- @Override
- public Name getPermissionName(AuthorizationContext ctx) {
- switch (ctx.getHttpMethod()) {
- case "GET":
- return Name.CONFIG_READ_PERM;
- case "POST":
- return Name.CONFIG_EDIT_PERM;
- default:
- return null;
- }
- }
-
- private static class PerReplicaCallable extends SolrRequest implements Callable<Boolean> {
- String coreUrl;
- String prop;
- int expectedZkVersion;
- Number remoteVersion = null;
- int maxWait;
-
- PerReplicaCallable(String coreUrl, String prop, int expectedZkVersion, int maxWait) {
- super(METHOD.GET, "/config/" + ZNODEVER);
- this.coreUrl = coreUrl;
- this.expectedZkVersion = expectedZkVersion;
- this.prop = prop;
- this.maxWait = maxWait;
- }
-
- @Override
- public SolrParams getParams() {
- return new ModifiableSolrParams()
- .set(prop, expectedZkVersion)
- .set(CommonParams.WT, CommonParams.JAVABIN);
- }
-
- @Override
- public Boolean call() throws Exception {
- final RTimer timer = new RTimer();
- int attempts = 0;
- try (HttpSolrClient solr = new HttpSolrClient.Builder(coreUrl).build()) {
- // eventually, this loop will get killed by the ExecutorService's timeout
- while (true) {
- try {
- long timeElapsed = (long) timer.getTime() / 1000;
- if (timeElapsed >= maxWait) {
- return false;
- }
- log.info("Time elapsed : {} secs, maxWait {}", timeElapsed, maxWait);
- Thread.sleep(100);
- NamedList<Object> resp = solr.httpUriRequest(this).future.get();
- if (resp != null) {
- Map m = (Map) resp.get(ZNODEVER);
- if (m != null) {
- remoteVersion = (Number) m.get(prop);
- if (remoteVersion != null && remoteVersion.intValue() >= expectedZkVersion) break;
- }
- }
-
- attempts++;
- log.info(formatString("Could not get expectedVersion {0} from {1} for prop {2} after {3} attempts", expectedZkVersion, coreUrl, prop, attempts));
- } catch (Exception e) {
- if (e instanceof InterruptedException) {
- break; // stop looping
- } else {
- log.warn("Failed to get /schema/zkversion from " + coreUrl + " due to: " + e);
- }
- }
- }
- }
- return true;
- }
-
-
- @Override
- protected SolrResponse createResponse(SolrClient client) {
- return null;
- }
- }
-
- @Override
- public Collection<Api> getApis() {
- return ApiBag.wrapRequestHandlers(this,
- "core.config",
- "core.config.Commands",
- "core.config.Params",
- "core.config.Params.Commands");
- }
-
- @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/SolrDefaultStreamFactory.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/SolrDefaultStreamFactory.java b/solr/core/src/java/org/apache/solr/handler/SolrDefaultStreamFactory.java
deleted file mode 100644
index c072f0b..0000000
--- a/solr/core/src/java/org/apache/solr/handler/SolrDefaultStreamFactory.java
+++ /dev/null
@@ -1,54 +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;
-
-import org.apache.solr.client.solrj.io.Lang;
-import org.apache.solr.client.solrj.io.stream.expr.DefaultStreamFactory;
-import org.apache.solr.core.SolrResourceLoader;
-
-/**
- * A default collection of mappings, used to convert strings into stream expressions.
- * Same as {@link DefaultStreamFactory} plus functions that rely directly on either
- * Lucene or Solr capabilities that are not part of {@link Lang}.
- *
- * @since 7.5
- */
-public class SolrDefaultStreamFactory extends DefaultStreamFactory {
-
- private SolrResourceLoader solrResourceLoader;
-
- public SolrDefaultStreamFactory() {
- super();
- this.withFunctionName("analyze", AnalyzeEvaluator.class);
- this.withFunctionName("classify", ClassifyStream.class);
- this.withFunctionName("haversineMeters", HaversineMetersEvaluator.class);
- }
-
- public SolrDefaultStreamFactory withSolrResourceLoader(SolrResourceLoader solrResourceLoader) {
- this.solrResourceLoader = solrResourceLoader;
- return this;
- }
-
- public void setSolrResourceLoader(SolrResourceLoader solrResourceLoader) {
- this.solrResourceLoader = solrResourceLoader;
- }
-
- public SolrResourceLoader getSolrResourceLoader() {
- return solrResourceLoader;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/0ae21ad0/solr/core/src/java/org/apache/solr/handler/StandardRequestHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/StandardRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/StandardRequestHandler.java
deleted file mode 100644
index e87aa68..0000000
--- a/solr/core/src/java/org/apache/solr/handler/StandardRequestHandler.java
+++ /dev/null
@@ -1,37 +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;
-
-import org.apache.solr.handler.component.*;
-
-@Deprecated
-public class StandardRequestHandler extends SearchHandler
-{
- //////////////////////// SolrInfoMBeans methods //////////////////////
-
- @Override
- public String getDescription() {
- return "The standard Solr request handler";
- }
-}
-
-
-
-
-
-
-