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;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
import org.apache.solr.cloud.api.collections.CreateCollectionCmd;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkMaintenanceUtils;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.cloud.ZooKeeperException;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.ConfigSetProperties;
import org.apache.solr.core.ConfigSetService;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.util.FileTypeMagicUtil;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** SolrCloud Zookeeper ConfigSetService impl. */
public class ZkConfigSetService extends ConfigSetService {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final ZkController zkController;
private final SolrZkClient zkClient;
/** ZkNode where named configs are stored */
public static final String CONFIGS_ZKNODE = "/configs";
public ZkConfigSetService(CoreContainer cc) {
super(cc.getResourceLoader(), cc.getConfig().hasSchemaCache());
this.zkController = cc.getZkController();
this.zkClient = cc.getZkController().getZkClient();
}
/** This is for ZkCLI and some tests */
public ZkConfigSetService(SolrZkClient zkClient) {
super(null, false);
this.zkController = null;
this.zkClient = zkClient;
}
@Override
public SolrResourceLoader createCoreResourceLoader(CoreDescriptor cd) {
final String colName = cd.getCollectionName();
// For back compat with cores that can create collections without the collections API
try {
if (!zkClient.exists(ZkStateReader.COLLECTIONS_ZKNODE + "/" + colName, true)) {
// TODO remove this functionality or maybe move to a CLI mechanism
log.warn(
"Auto-creating collection (in ZK) from core descriptor (on disk). This feature may go away!");
CreateCollectionCmd.createCollectionZkNode(
zkController.getSolrCloudManager().getDistribStateManager(),
colName,
cd.getCloudDescriptor().getParams(),
zkController.getCoreContainer().getConfigSetService());
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ZooKeeperException(
SolrException.ErrorCode.SERVER_ERROR, "Interrupted auto-creating collection", e);
} catch (KeeperException e) {
throw new ZooKeeperException(
SolrException.ErrorCode.SERVER_ERROR, "Failure auto-creating collection", e);
}
// The configSet is read from ZK and populated. Ignore CD's pre-existing configSet; only
// populated in standalone
String configSetName = zkController.getClusterState().getCollection(colName).getConfigName();
cd.setConfigSet(configSetName);
return new ZkSolrResourceLoader(
cd.getInstanceDir(), configSetName, parentLoader.getClassLoader(), zkController);
}
@Override
protected NamedList