-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #492 from mesos/bug/hardcoded-zk-mesos-endpoint
Allow arbitrary path in ZK url instead of appending /mesos
- Loading branch information
Showing
5 changed files
with
69 additions
and
74 deletions.
There are no files selected for viewing
23 changes: 8 additions & 15 deletions
23
...main/java/org/apache/mesos/elasticsearch/common/zookeeper/formatter/MesosZKFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
package org.apache.mesos.elasticsearch.common.zookeeper.formatter; | ||
|
||
import org.apache.mesos.elasticsearch.common.zookeeper.exception.ZKAddressException; | ||
import org.apache.mesos.elasticsearch.common.zookeeper.model.ZKAddress; | ||
import org.apache.mesos.elasticsearch.common.zookeeper.parser.ZKAddressParser; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Provides the ZooKeeper address(es) in a format required by Mesos. | ||
* | ||
* The format consists of a list of ZK servers and appends a /mesos | ||
* The format consists of a list of ZK servers and a path | ||
* | ||
* Example: zk://host1:port1,host2:port2/mesos | ||
*/ | ||
public class MesosZKFormatter extends AbstractZKFormatter { | ||
|
||
public static final String MESOS_PATH = "/mesos"; | ||
|
||
public MesosZKFormatter(ZKAddressParser parser) { | ||
super(parser); | ||
} | ||
|
||
/** | ||
* Get the ZooKeeper address for the mesos master, correctly formatted. | ||
* Validates the ZooKeeper address and returns it | ||
* | ||
* @param zkUrl The raw ZK address string in the format "zk://host:port/zkNode,..." | ||
* | ||
* @throws ZKAddressException if the raw zkURL is invalid. | ||
* @return the zookeeper addresses in the format host:port[,host:port,...]/mesos | ||
* | ||
* @return the zookeeper addresses in the format zk://host:port[,host:port,...]/mesos | ||
*/ | ||
public String format(String zkUrl) { | ||
List<ZKAddress> addressList = parser.validateZkUrl(zkUrl); | ||
StringBuilder builder = new StringBuilder(); | ||
addressList.forEach(add -> builder.append(",").append(add.getAddress()).append(":").append(add.getPort())); | ||
builder.deleteCharAt(0); // Delete first ',' | ||
builder.append(MESOS_PATH); // Append "/mesos" | ||
builder.insert(0, ZKAddress.ZK_PREFIX); // Prepend "zk://" | ||
return builder.toString(); | ||
parser.validateZkUrl(zkUrl); | ||
return zkUrl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters