Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.cloud.api.collections;
import static org.apache.solr.common.SolrException.ErrorCode.BAD_REQUEST;
import static org.apache.solr.common.SolrException.ErrorCode.SERVER_ERROR;
import static org.apache.solr.common.params.CollectionAdminParams.ROUTER_PREFIX;
import java.lang.invoke.MethodHandles;
import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.solr.client.solrj.RoutedAliasTypes;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.cloud.Aliases;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.admin.CollectionsHandler;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.update.AddUpdateCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class RoutedAlias {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@SuppressWarnings("WeakerAccess")
public static final String ROUTER_TYPE_NAME = ROUTER_PREFIX + "name";
@SuppressWarnings("WeakerAccess")
public static final String ROUTER_FIELD = ROUTER_PREFIX + "field";
public static final String CREATE_COLLECTION_PREFIX = "create-collection.";
@SuppressWarnings("WeakerAccess")
public static final Set MINIMAL_REQUIRED_PARAMS = Set.of(ROUTER_TYPE_NAME, ROUTER_FIELD);
public static final String ROUTED_ALIAS_NAME_CORE_PROP = "routedAliasName"; // core prop
public static final String DIMENSIONAL = "Dimensional[";
public static final String TIME = "time";
public static final String CATEGORY = "category";
// This class is created once per request and the overseer methods prevent duplicate create
// requests from creating extra copies via locking on the alias name. All we need to track here is
// that we don't spam preemptive creates to the overseer multiple times from *this* request.
boolean preemptiveCreateOnceAlready = false;
public static SolrException newAliasMustExistException(String aliasName) {
throw new SolrException(
SolrException.ErrorCode.SERVICE_UNAVAILABLE,
"Routed alias " + aliasName + " appears to have been removed during request processing.");
}
/**
* Factory method for implementations of this interface. There should be no reason to construct
* instances elsewhere, and routed alias types are encouraged to have package private
* constructors.
*
* @param aliasName The alias name (will be returned by {@link #getAliasName()}
* @param props The properties from an overseer message.
* @return An implementation appropriate for the supplied properties, or null if no type is
* specified.
* @throws SolrException If the properties are invalid or the router type is unknown.
*/
public static RoutedAlias fromProps(String aliasName, Map props)
throws SolrException {
String typeStr = props.get(ROUTER_TYPE_NAME);
if (typeStr == null) {
return null; // non-routed aliases are being created
}
List routerTypes = new ArrayList<>();
// check for Dimensional[foo,bar,baz]
if (typeStr.startsWith(DIMENSIONAL)) {
// multi-dimensional routed alias
typeStr = typeStr.substring(DIMENSIONAL.length(), typeStr.length() - 1);
String[] types = typeStr.split(",");
java.util.List fields = new ArrayList<>();
if (types.length > 2) {
throw new SolrException(
BAD_REQUEST,
"More than 2 dimensions is not supported yet. "
+ "Please monitor SOLR-13628 for progress");
}
for (int i = 0; i < types.length; i++) {
String type = types[i];
addRouterTypeOf(type, routerTypes);
// v2 api case - the v2 -> v1 mapping mechanisms can't handle this conversion because they
// expect strings or arrays of strings, not lists of objects.
// TODO: The generic types for props are a lie
if (props.containsKey("router.routerList")) {
HashMap tmp = new HashMap<>(props);
@SuppressWarnings({"unchecked"})
List