You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ge...@apache.org on 2018/10/11 18:50:57 UTC

lucene-solr:branch_7x: SOLR-12565: Add SolrJ snippet to 'Using ZooKeeper to manage config' ref-guide page

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 184ad3b03 -> 720481e7c


SOLR-12565: Add SolrJ snippet to 'Using ZooKeeper to manage config' ref-guide page


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/720481e7
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/720481e7
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/720481e7

Branch: refs/heads/branch_7x
Commit: 720481e7c04dc6a69c681cccd543931cf262d78a
Parents: 184ad3b
Author: Jason Gerlowski <ge...@apache.org>
Authored: Thu Oct 11 14:21:49 2018 -0400
Committer: Jason Gerlowski <ge...@apache.org>
Committed: Thu Oct 11 14:31:27 2018 -0400

----------------------------------------------------------------------
 ...zookeeper-to-manage-configuration-files.adoc | 12 ++-
 .../ref_guide_examples/ZkConfigFilesTest.java   | 94 ++++++++++++++++++++
 2 files changed, 104 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/720481e7/solr/solr-ref-guide/src/using-zookeeper-to-manage-configuration-files.adoc
----------------------------------------------------------------------
diff --git a/solr/solr-ref-guide/src/using-zookeeper-to-manage-configuration-files.adoc b/solr/solr-ref-guide/src/using-zookeeper-to-manage-configuration-files.adoc
index b1b3b5a..546ee99 100644
--- a/solr/solr-ref-guide/src/using-zookeeper-to-manage-configuration-files.adoc
+++ b/solr/solr-ref-guide/src/using-zookeeper-to-manage-configuration-files.adoc
@@ -1,4 +1,6 @@
 = Using ZooKeeper to Manage Configuration Files
+:solr-root-path: ../../
+:example-source-dir: {solr-root-path}solrj/src/test/org/apache/solr/client/ref_guide_examples/
 // 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
@@ -51,7 +53,7 @@ IMPORTANT: It's a good idea to keep these files under version control.
 
 == Uploading Configuration Files using bin/solr or SolrJ
 
-In production situations, <<config-sets.adoc#config-sets,Config Sets>> can also be uploaded to ZooKeeper independent of collection creation using either Solr's <<solr-control-script-reference.adoc#solr-control-script-reference,Solr Control Script>> or the {solr-javadocs}/solr-solrj/org/apache/solr/client/solrj/impl/CloudSolrClient.html[CloudSolrClient.uploadConfig] java method.
+In production situations, <<config-sets.adoc#config-sets,Config Sets>> can also be uploaded to ZooKeeper independent of collection creation using either Solr's <<solr-control-script-reference.adoc#solr-control-script-reference,Solr Control Script>> or SolrJ.
 
 The below command can be used to upload a new configset using the bin/solr script.
 
@@ -60,6 +62,12 @@ The below command can be used to upload a new configset using the bin/solr scrip
 bin/solr zk upconfig -n <name for configset> -d <path to directory with configset>
 ----
 
+The following code shows how this can also be achieved using SolrJ:
+[source,java,indent=0]
+----
+include::{example-source-dir}ZkConfigFilesTest.java[tag=zk-configset-upload]
+----
+
 It is strongly recommended that the configurations be kept in a version control system, Git, SVN or similar.
 
 == Managing Your SolrCloud Configuration Files
@@ -85,4 +93,4 @@ If you for example would like to keep your `solr.xml` in ZooKeeper to avoid havi
 bin/solr zk cp file:local/file/path/to/solr.xml zk:/solr.xml -z localhost:2181
 ----
 
-NOTE: If you have defined `ZK_HOST` in `solr.in.sh`/`solr.in.cmd` (see <<setting-up-an-external-zookeeper-ensemble#updating-solr-s-include-files,instructions>>) you can omit `-z <zk host string>` from the above command.
\ No newline at end of file
+NOTE: If you have defined `ZK_HOST` in `solr.in.sh`/`solr.in.cmd` (see <<setting-up-an-external-zookeeper-ensemble#updating-solr-s-include-files,instructions>>) you can omit `-z <zk host string>` from the above command.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/720481e7/solr/solrj/src/test/org/apache/solr/client/ref_guide_examples/ZkConfigFilesTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/ref_guide_examples/ZkConfigFilesTest.java b/solr/solrj/src/test/org/apache/solr/client/ref_guide_examples/ZkConfigFilesTest.java
new file mode 100644
index 0000000..dcb1111
--- /dev/null
+++ b/solr/solrj/src/test/org/apache/solr/client/ref_guide_examples/ZkConfigFilesTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.client.ref_guide_examples;
+
+import java.io.File;
+import java.nio.file.Paths;
+import java.util.List;
+
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.cloud.SolrZkClient;
+import org.apache.solr.common.cloud.ZkConfigManager;
+import org.apache.solr.util.ExternalPaths;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Examples showing how to manipulate configsets in ZK.
+ *
+ * Snippets surrounded by "tag" and "end" comments are extracted and used in the Solr Reference Guide.
+ */
+public class ZkConfigFilesTest extends SolrCloudTestCase {
+
+  private static final int ZK_TIMEOUT_MILLIS = 10000;
+
+  @BeforeClass
+  public static void setUpCluster() throws Exception {
+    configureCluster(1)
+        .configure();
+  }
+
+  @Before
+  public void clearConfigsBefore() throws Exception {
+    clearConfigs();
+  }
+
+  @After
+  public void clearConfigsAfter() throws Exception {
+    clearConfigs();
+  }
+
+  private void clearConfigs() throws Exception {
+    ZkConfigManager manager = new ZkConfigManager(cluster.getZkClient());
+    List<String> configs = manager.listConfigs();
+    for (String config : configs) {
+      manager.deleteConfigDir(config);
+    }
+  }
+
+  @Test
+  public void testCanUploadConfigToZk() throws Exception {
+    final String zkConnectionString = cluster.getZkClient().getZkServerAddress();
+    final String localConfigSetDirectory = new File(ExternalPaths.TECHPRODUCTS_CONFIGSET).getAbsolutePath();
+
+    assertConfigsContainOnly();
+
+    // tag::zk-configset-upload[]
+    try (SolrZkClient zkClient = new SolrZkClient(zkConnectionString, ZK_TIMEOUT_MILLIS)) {
+      ZkConfigManager manager = new ZkConfigManager(zkClient);
+      manager.uploadConfigDir(Paths.get(localConfigSetDirectory), "nameForConfigset");
+    }
+    // end::zk-configset-upload[]
+
+    assertConfigsContainOnly("nameForConfigset");
+  }
+
+  private void assertConfigsContainOnly(String... expectedConfigs) throws Exception {
+    final int expectedSize = expectedConfigs.length;
+
+    ZkConfigManager manager = new ZkConfigManager(cluster.getZkClient());
+    List<String> actualConfigs = manager.listConfigs();
+
+    assertEquals(expectedSize, actualConfigs.size());
+    for (String expectedConfig : expectedConfigs) {
+      assertTrue("Expected ZK to contain " + expectedConfig + ", but it didn't.  Actual configs: ", actualConfigs.contains(expectedConfig));
+    }
+  }
+}