Search in sources :

Example 1 with ZkConfigManager

use of org.apache.solr.common.cloud.ZkConfigManager in project lucene-solr by apache.

the class ZkContainer method initZooKeeper.

public void initZooKeeper(final CoreContainer cc, String solrHome, CloudConfig config) {
    ZkController zkController = null;
    String zkRun = System.getProperty("zkRun");
    if (zkRun != null && config == null)
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Cannot start Solr in cloud mode - no cloud config provided");
    if (config == null)
        // not in zk mode
        return;
    String zookeeperHost = config.getZkHost();
    // zookeeper in quorum mode currently causes a failure when trying to
    // register log4j mbeans.  See SOLR-2369
    // TODO: remove after updating to an slf4j based zookeeper
    System.setProperty("zookeeper.jmx.log4j.disable", "true");
    if (zkRun != null) {
        String zkDataHome = System.getProperty("zkServerDataDir", Paths.get(solrHome).resolve("zoo_data").toString());
        String zkConfHome = System.getProperty("zkServerConfDir", solrHome);
        zkServer = new SolrZkServer(stripChroot(zkRun), stripChroot(config.getZkHost()), zkDataHome, zkConfHome, config.getSolrHostPort());
        zkServer.parseConfig();
        zkServer.start();
        // set client from server config if not already set
        if (zookeeperHost == null) {
            zookeeperHost = zkServer.getClientString();
        }
    }
    int zkClientConnectTimeout = 30000;
    if (zookeeperHost != null) {
        // we are ZooKeeper enabled
        try {
            // If this is an ensemble, allow for a long connect time for other servers to come up
            if (zkRun != null && zkServer.getServers().size() > 1) {
                // 1 day for embedded ensemble
                zkClientConnectTimeout = 24 * 60 * 60 * 1000;
                log.info("Zookeeper client=" + zookeeperHost + "  Waiting for a quorum.");
            } else {
                log.info("Zookeeper client=" + zookeeperHost);
            }
            String confDir = System.getProperty("bootstrap_confdir");
            boolean boostrapConf = Boolean.getBoolean("bootstrap_conf");
            if (!ZkController.checkChrootPath(zookeeperHost, (confDir != null) || boostrapConf || zkRunOnly)) {
                throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "A chroot was specified in ZkHost but the znode doesn't exist. " + zookeeperHost);
            }
            zkController = new ZkController(cc, zookeeperHost, zkClientConnectTimeout, config, new CurrentCoreDescriptorProvider() {

                @Override
                public List<CoreDescriptor> getCurrentDescriptors() {
                    List<CoreDescriptor> descriptors = new ArrayList<>(cc.getLoadedCoreNames().size());
                    Collection<SolrCore> cores = cc.getCores();
                    for (SolrCore core : cores) {
                        descriptors.add(core.getCoreDescriptor());
                    }
                    return descriptors;
                }
            });
            if (zkRun != null && zkServer.getServers().size() > 1 && confDir == null && boostrapConf == false) {
                // we are part of an ensemble and we are not uploading the config - pause to give the config time
                // to get up
                Thread.sleep(10000);
            }
            if (confDir != null) {
                Path configPath = Paths.get(confDir);
                if (!Files.isDirectory(configPath))
                    throw new IllegalArgumentException("bootstrap_confdir must be a directory of configuration files");
                String confName = System.getProperty(ZkController.COLLECTION_PARAM_PREFIX + ZkController.CONFIGNAME_PROP, "configuration1");
                ZkConfigManager configManager = new ZkConfigManager(zkController.getZkClient());
                configManager.uploadConfigDir(configPath, confName);
            }
            if (boostrapConf) {
                ZkController.bootstrapConf(zkController.getZkClient(), cc, solrHome);
            }
        } catch (InterruptedException e) {
            // Restore the interrupted status
            Thread.currentThread().interrupt();
            log.error("", e);
            throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
        } catch (TimeoutException e) {
            log.error("Could not connect to ZooKeeper", e);
            throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
        } catch (IOException | KeeperException e) {
            log.error("", e);
            throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR, "", e);
        }
    }
    this.zkController = zkController;
}
Also used : Path(java.nio.file.Path) ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) ArrayList(java.util.ArrayList) CurrentCoreDescriptorProvider(org.apache.solr.cloud.CurrentCoreDescriptorProvider) IOException(java.io.IOException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) SolrZkServer(org.apache.solr.cloud.SolrZkServer) ZkController(org.apache.solr.cloud.ZkController) SolrException(org.apache.solr.common.SolrException) KeeperException(org.apache.zookeeper.KeeperException) ZooKeeperException(org.apache.solr.common.cloud.ZooKeeperException) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ZkConfigManager

use of org.apache.solr.common.cloud.ZkConfigManager in project lucene-solr by apache.

the class ZkController method bootstrapConf.

/**
   * If in SolrCloud mode, upload config sets for each SolrCore in solr.xml.
   */
public static void bootstrapConf(SolrZkClient zkClient, CoreContainer cc, String solrHome) throws IOException {
    ZkConfigManager configManager = new ZkConfigManager(zkClient);
    //List<String> allCoreNames = cfg.getAllCoreNames();
    List<CoreDescriptor> cds = cc.getCoresLocator().discover(cc);
    log.info("bootstrapping config for " + cds.size() + " cores into ZooKeeper using solr.xml from " + solrHome);
    for (CoreDescriptor cd : cds) {
        String coreName = cd.getName();
        String confName = cd.getCollectionName();
        if (StringUtils.isEmpty(confName))
            confName = coreName;
        Path udir = cd.getInstanceDir().resolve("conf");
        log.info("Uploading directory " + udir + " with name " + confName + " for SolrCore " + coreName);
        configManager.uploadConfigDir(udir, confName);
    }
}
Also used : Path(java.nio.file.Path) ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) CoreDescriptor(org.apache.solr.core.CoreDescriptor)

Example 3 with ZkConfigManager

use of org.apache.solr.common.cloud.ZkConfigManager in project lucene-solr by apache.

the class OverseerConfigSetMessageHandler method deleteConfigSet.

private void deleteConfigSet(String configSetName, boolean force) throws IOException {
    ZkConfigManager configManager = new ZkConfigManager(zkStateReader.getZkClient());
    if (!configManager.configExists(configSetName)) {
        throw new SolrException(ErrorCode.BAD_REQUEST, "ConfigSet does not exist to delete: " + configSetName);
    }
    for (Map.Entry<String, DocCollection> entry : zkStateReader.getClusterState().getCollectionsMap().entrySet()) {
        if (configSetName.equals(zkStateReader.readConfigName(entry.getKey())))
            throw new SolrException(ErrorCode.BAD_REQUEST, "Can not delete ConfigSet as it is currently being used by collection [" + entry.getKey() + "]");
    }
    String propertyPath = ConfigSetProperties.DEFAULT_FILENAME;
    NamedList properties = getConfigSetProperties(getPropertyPath(configSetName, propertyPath));
    if (properties != null) {
        Object immutable = properties.get(ConfigSetProperties.IMMUTABLE_CONFIGSET_ARG);
        boolean isImmutableConfigSet = immutable != null ? Boolean.parseBoolean(immutable.toString()) : false;
        if (!force && isImmutableConfigSet) {
            throw new SolrException(ErrorCode.BAD_REQUEST, "Requested delete of immutable ConfigSet: " + configSetName);
        }
    }
    configManager.deleteConfigDir(configSetName);
}
Also used : ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) NamedList(org.apache.solr.common.util.NamedList) DocCollection(org.apache.solr.common.cloud.DocCollection) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap) Map(java.util.Map) SolrException(org.apache.solr.common.SolrException)

Example 4 with ZkConfigManager

use of org.apache.solr.common.cloud.ZkConfigManager in project lucene-solr by apache.

the class TestCloudSolrClientConnections method testCloudClientUploads.

@Test
public void testCloudClientUploads() throws Exception {
    Path configPath = getFile("solrj").toPath().resolve("solr/configsets/configset-2/conf");
    MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(0, createTempDir(), buildJettyConfig("/solr"));
    try {
        CloudSolrClient client = cluster.getSolrClient();
        try {
            ((ZkClientClusterStateProvider) client.getClusterStateProvider()).uploadConfig(configPath, "testconfig");
            fail("Requests to a non-running cluster should throw a SolrException");
        } catch (SolrException e) {
            assertTrue("Unexpected message: " + e.getMessage(), e.getMessage().contains("cluster not found/not ready"));
        }
        cluster.startJettySolrRunner();
        client.connect(20, TimeUnit.SECONDS);
        ((ZkClientClusterStateProvider) client.getClusterStateProvider()).uploadConfig(configPath, "testconfig");
        ZkConfigManager configManager = new ZkConfigManager(client.getZkStateReader().getZkClient());
        assertTrue("List of uploaded configs does not contain 'testconfig'", configManager.listConfigs().contains("testconfig"));
    } finally {
        cluster.shutdown();
    }
}
Also used : Path(java.nio.file.Path) ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 5 with ZkConfigManager

use of org.apache.solr.common.cloud.ZkConfigManager in project lucene-solr by apache.

the class HdfsRecoveryZkTest method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    dfsCluster = HdfsTestUtil.setupClass(createTempDir().toFile().getAbsolutePath());
    System.setProperty("solr.hdfs.blockcache.blocksperbank", "2048");
    ZkConfigManager configManager = new ZkConfigManager(zkClient());
    configManager.uploadConfigDir(configset("cloud-hdfs"), "conf");
    System.setProperty("solr.hdfs.home", HdfsTestUtil.getDataDir(dfsCluster, "data"));
}
Also used : ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) BeforeClass(org.junit.BeforeClass)

Aggregations

ZkConfigManager (org.apache.solr.common.cloud.ZkConfigManager)14 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)6 SolrException (org.apache.solr.common.SolrException)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)3 SolrClient (org.apache.solr.client.solrj.SolrClient)3 ConfigSetAdminResponse (org.apache.solr.client.solrj.response.ConfigSetAdminResponse)3 Test (org.junit.Test)3 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 Map (java.util.Map)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)2 Create (org.apache.solr.client.solrj.request.ConfigSetAdminRequest.Create)2 NamedList (org.apache.solr.common.util.NamedList)2 KeeperException (org.apache.zookeeper.KeeperException)2 BeforeClass (org.junit.BeforeClass)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ParseException (com.google.protobuf.TextFormat.ParseException)1 FileInputStream (java.io.FileInputStream)1