1 |
53801
|
claudio.at
|
package eu.dnetlib.functionality.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 |
|
|
|
16 |
|
|
private List<String> hosts;
|
17 |
|
|
|
18 |
|
|
private Optional<String> chroot;
|
19 |
|
|
|
20 |
|
|
public static ZkServers newInstance(final String zkUrl) {
|
21 |
|
|
|
22 |
|
|
//quorum0:2182,quorum1:2182,quorum2:2182,quorum3:2182,quorum4:2182/solr-dev-openaire
|
23 |
|
|
String urls = zkUrl;
|
24 |
|
|
final Optional<String> chRoot = Optional.of(StringUtils.substringAfterLast(zkUrl, "/"));
|
25 |
|
|
if (chRoot.isPresent() && StringUtils.isNotBlank(chRoot.get())) {
|
26 |
|
|
log.debug(String.format("found zk chroot %s", chRoot));
|
27 |
53822
|
claudio.at
|
urls = zkUrl.replace("/" + chRoot, "");
|
28 |
53801
|
claudio.at
|
}
|
29 |
|
|
|
30 |
|
|
final List<String> urlList = Lists.newArrayList(Splitter.on(",").omitEmptyStrings().split(urls));
|
31 |
|
|
log.debug(String.format("zk urls %s", zkUrl));
|
32 |
|
|
|
33 |
|
|
return new ZkServers(urlList, chRoot);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
public ZkServers(List<String> hosts, Optional<String> chroot) {
|
37 |
|
|
this.hosts = hosts;
|
38 |
|
|
this.chroot = chroot;
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
public List<String> getHosts() {
|
42 |
|
|
return hosts;
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
public void setHosts(List<String> hosts) {
|
46 |
|
|
this.hosts = hosts;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
public Optional<String> getChroot() {
|
50 |
|
|
return chroot;
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
public void setChroot(Optional<String> chroot) {
|
54 |
|
|
this.chroot = chroot;
|
55 |
|
|
}
|
56 |
|
|
}
|