Skip to content

Commit b9adacf

Browse files
authored
Merge pull request JanusGraph#1331 from jerryjch/merge-to-master
Merge PR JanusGraph#1282 to master
2 parents be6a62f + f7dd044 commit b9adacf

File tree

3 files changed

+54
-34
lines changed

3 files changed

+54
-34
lines changed

janusgraph-hadoop-parent/janusgraph-hadoop-core/src/main/java/org/janusgraph/hadoop/MapReduceIndexManagement.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.slf4j.Logger;
5555
import org.slf4j.LoggerFactory;
5656

57+
import java.util.Collection;
5758
import java.util.EnumSet;
5859
import java.util.Iterator;
5960
import java.util.Set;
@@ -177,7 +178,7 @@ public JanusGraphManagement.IndexJobFuture updateIndex(Index index, SchemaAction
177178
janusGraphMapReduceConfiguration.set(JanusGraphHadoopConfiguration.SCAN_JOB_CONFIG_ROOT,
178179
GraphDatabaseConfiguration.class.getName() + "#JOB_NS");
179180
// Copy the StandardJanusGraph configuration under JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS
180-
org.apache.commons.configuration.Configuration localConfiguration = graph.getConfiguration().getLocalConfiguration();
181+
org.apache.commons.configuration.Configuration localConfiguration = graph.getConfiguration().getConfigurationAtOpen();
181182
localConfiguration.clearProperty(Graph.GRAPH);
182183
copyInputKeys(hadoopConf, localConfiguration);
183184

@@ -192,22 +193,18 @@ public JanusGraphManagement.IndexJobFuture updateIndex(Index index, SchemaAction
192193

193194
private static void copyInputKeys(org.apache.hadoop.conf.Configuration hadoopConf, org.apache.commons.configuration.Configuration source) {
194195
// Copy IndexUpdateJob settings into the hadoop-backed cfg
195-
Iterator<String> iterator = source.getKeys();
196-
while (iterator.hasNext()) {
197-
String key = iterator.next();
198-
ConfigElement.PathIdentifier pid;
199-
try {
200-
pid = ConfigElement.parse(ROOT_NS, key);
201-
} catch (RuntimeException e) {
202-
log.debug("[inputkeys] Skipping {}", key, e);
203-
continue;
204-
}
205-
206-
if (!pid.element.isOption())
207-
continue;
196+
Iterator<String> keyIter = source.getKeys();
197+
while (keyIter.hasNext()) {
198+
String key = keyIter.next();
208199

209200
String k = ConfigElement.getPath(JanusGraphHadoopConfiguration.GRAPH_CONFIG_KEYS, true) + "." + key;
210-
String v = source.getProperty(key).toString();
201+
Object vObject = source.getProperty(key);
202+
String v;
203+
if (vObject instanceof Collection) {
204+
v = Joiner.on(",").join((Collection<String>) vObject);
205+
} else {
206+
v = vObject.toString();
207+
}
211208

212209
hadoopConf.set(k, v);
213210
log.debug("[inputkeys] Set {}={}", k, v);

janusgraph-solr/src/main/java/org/janusgraph/diskstorage/solr/SolrIndex.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.time.Instant;
2727
import java.util.AbstractMap.SimpleEntry;
2828
import java.util.ArrayList;
29+
import java.util.Arrays;
2930
import java.util.Collection;
3031
import java.util.Collections;
3132
import java.util.Date;
@@ -168,10 +169,13 @@ public static Mode parse(String mode) {
168169
ConfigOption.Type.GLOBAL_OFFLINE, "ttl");
169170

170171
/** SolrCloud Configuration */
171-
172-
public static final ConfigOption<String> ZOOKEEPER_URL = new ConfigOption<>(SOLR_NS,"zookeeper-url",
172+
/*
173+
* TODO Rename ZOOKEEPER_URL and "zookeeper-url" to ZOOKEEPER_URLS and
174+
* "zookeeper-urls" in future major releases.
175+
*/
176+
public static final ConfigOption<String[]> ZOOKEEPER_URL = new ConfigOption<String[]>(SOLR_NS,"zookeeper-url",
173177
"URL of the Zookeeper instance coordinating the SolrCloud cluster",
174-
ConfigOption.Type.MASKABLE, "localhost:2181");
178+
ConfigOption.Type.MASKABLE, new String[] { "localhost:2181" });
175179

176180
public static final ConfigOption<Integer> NUM_SHARDS = new ConfigOption<>(SOLR_NS,"num-shards",
177181
"Number of shards for a collection. This applies when creating a new collection which is only supported under the SolrCloud operation mode.",
@@ -268,18 +272,36 @@ public SolrIndex(final Configuration config) throws BackendException {
268272
final ModifiableSolrParams clientParams = new ModifiableSolrParams();
269273
switch (mode) {
270274
case CLOUD:
271-
final String zookeeperUrl = config.get(SolrIndex.ZOOKEEPER_URL);
272-
final CloudSolrClient cloudServer = new CloudSolrClient.Builder()
275+
final String[] zookeeperUrl = config.get(SolrIndex.ZOOKEEPER_URL);
276+
// Process possible zookeeper chroot. e.g. localhost:2181/solr
277+
// chroot has to be the same assuming one Zookeeper ensemble.
278+
// Parse from the last string. If found, take it as the chroot.
279+
String chroot = null;
280+
for (int i = zookeeperUrl.length - 1; i >= 0; i--) {
281+
int chrootIndex = zookeeperUrl[i].indexOf("/");
282+
if (chrootIndex != -1) {
283+
String hostAndPort = zookeeperUrl[i].substring(0, chrootIndex);
284+
if (chroot == null) {
285+
chroot = zookeeperUrl[i].substring(chrootIndex);
286+
}
287+
zookeeperUrl[i] = hostAndPort;
288+
}
289+
}
290+
final CloudSolrClient.Builder builder = new CloudSolrClient.Builder()
273291
.withLBHttpSolrClientBuilder(
274292
new LBHttpSolrClient.Builder()
275293
.withHttpSolrClientBuilder(new HttpSolrClient.Builder().withInvariantParams(clientParams))
276294
.withBaseSolrUrls(config.get(HTTP_URLS))
277-
)
278-
.withZkHost(zookeeperUrl)
279-
.sendUpdatesOnlyToShardLeaders()
280-
.build();
295+
)
296+
.withZkHost(Arrays.asList(zookeeperUrl))
297+
.sendUpdatesOnlyToShardLeaders();
298+
if (chroot != null) {
299+
builder.withZkChroot(chroot);
300+
}
301+
final CloudSolrClient cloudServer = builder.build();
281302
cloudServer.connect();
282303
solrClient = cloudServer;
304+
283305
break;
284306
case HTTP:
285307
clientParams.add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString());
@@ -292,7 +314,6 @@ public SolrIndex(final Configuration config) throws BackendException {
292314
.withBaseSolrUrls(config.get(HTTP_URLS))
293315
.build();
294316

295-
296317
break;
297318
default:
298319
throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode);
@@ -1208,4 +1229,4 @@ private static void waitForRecoveriesToFinish(CloudSolrClient server, String col
12081229
}
12091230
}
12101231

1211-
}
1232+
}

janusgraph-solr/src/test/java/org/janusgraph/diskstorage/solr/SolrRunner.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import com.google.common.base.Joiner;
1818
import com.google.common.base.Preconditions;
19+
import com.google.common.base.Strings;
20+
1921
import org.apache.commons.io.FileUtils;
2022
import org.apache.solr.client.solrj.embedded.JettyConfig;
2123
import org.apache.solr.cloud.ConfigurableMiniSolrCloudCluster;
@@ -34,7 +36,7 @@
3436

3537
public class SolrRunner {
3638

37-
public static final String ZOOKEEPER_URLS = System.getProperty("index.search.solr.zookeeper-url");
39+
public static final String ZOOKEEPER_URLS_SYSTEM_PROPERTY = System.getProperty("index.search.solr.zookeeper-url");
3840

3941
protected static final int NUM_SERVERS = 1;
4042
protected static final String[] COLLECTIONS = readCollections();
@@ -58,7 +60,7 @@ public static void start() throws Exception {
5860
public static void start(boolean isKerberosEnabled) throws Exception {
5961
kerberosEnabled = isKerberosEnabled;
6062

61-
if (ZOOKEEPER_URLS != null) {
63+
if (ZOOKEEPER_URLS_SYSTEM_PROPERTY != null) {
6264
return;
6365
}
6466
String userDir = System.getProperty("user.dir");
@@ -98,18 +100,18 @@ public static void start(boolean isKerberosEnabled) throws Exception {
98100
}
99101
}
100102

101-
public static String getZookeeperUrls() {
102-
final String zookeeperUrls;
103-
if (ZOOKEEPER_URLS == null) {
104-
zookeeperUrls = miniSolrCloudCluster.getZkServer().getZkAddress();
103+
public static String[] getZookeeperUrls() {
104+
final String[] zookeeperUrls;
105+
if (Strings.isNullOrEmpty(ZOOKEEPER_URLS_SYSTEM_PROPERTY)) {
106+
zookeeperUrls = new String[] { miniSolrCloudCluster.getZkServer().getZkAddress() };
105107
} else {
106-
zookeeperUrls = ZOOKEEPER_URLS;
108+
zookeeperUrls = ZOOKEEPER_URLS_SYSTEM_PROPERTY.split(",");
107109
}
108110
return zookeeperUrls;
109111
}
110112

111113
public static void stop() throws Exception {
112-
if (ZOOKEEPER_URLS != null) {
114+
if (ZOOKEEPER_URLS_SYSTEM_PROPERTY != null) {
113115
return;
114116
}
115117
System.clearProperty("solr.solrxml.location");

0 commit comments

Comments
 (0)