1
|
package eu.dnetlib.index.utils;
|
2
|
|
3
|
import com.google.common.base.Splitter;
|
4
|
import com.google.common.collect.Lists;
|
5
|
import org.apache.commons.lang3.StringUtils;
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
|
9
|
import java.util.List;
|
10
|
import java.util.Optional;
|
11
|
|
12
|
public class ZkServers {
|
13
|
|
14
|
private static final Log log = LogFactory.getLog(ZkServers.class);
|
15
|
public static final String SEPARATOR = "/";
|
16
|
|
17
|
private List<String> hosts;
|
18
|
|
19
|
private Optional<String> chroot;
|
20
|
|
21
|
public static ZkServers newInstance(final String zkUrl) {
|
22
|
|
23
|
//quorum0:2182,quorum1:2182,quorum2:2182,quorum3:2182,quorum4:2182/solr-dev-openaire
|
24
|
String urls = zkUrl;
|
25
|
final Optional<String> chRoot = Optional.of(SEPARATOR + StringUtils.substringAfterLast(zkUrl, SEPARATOR));
|
26
|
if (chRoot.isPresent() && StringUtils.isNotBlank(chRoot.get())) {
|
27
|
log.debug(String.format("found zk chroot %s", chRoot));
|
28
|
urls = zkUrl.replace(chRoot.get(), "");
|
29
|
}
|
30
|
|
31
|
final List<String> urlList = Lists.newArrayList(Splitter.on(",").omitEmptyStrings().split(urls));
|
32
|
log.debug(String.format("zk urls %s", zkUrl));
|
33
|
|
34
|
return new ZkServers(urlList, chRoot);
|
35
|
}
|
36
|
|
37
|
public ZkServers(List<String> hosts, Optional<String> chroot) {
|
38
|
this.hosts = hosts;
|
39
|
this.chroot = chroot;
|
40
|
}
|
41
|
|
42
|
public List<String> getHosts() {
|
43
|
return hosts;
|
44
|
}
|
45
|
|
46
|
public void setHosts(List<String> hosts) {
|
47
|
this.hosts = hosts;
|
48
|
}
|
49
|
|
50
|
public Optional<String> getChroot() {
|
51
|
return chroot;
|
52
|
}
|
53
|
|
54
|
public void setChroot(Optional<String> chroot) {
|
55
|
this.chroot = chroot;
|
56
|
}
|
57
|
}
|
58
|
|