Github user revans2 commented on a diff in the pull request:
https://github.com/apache/incubator-storm/pull/61#discussion_r11358591
--- Diff: storm-core/src/jvm/backtype/storm/nimbus/NimbusLeadership.java ---
@@ -0,0 +1,104 @@
+package backtype.storm.nimbus;
+
+import java.io.UnsupportedEncodingException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import backtype.storm.Config;
+import backtype.storm.utils.Utils;
+
+import com.netflix.curator.framework.CuratorFramework;
+import com.netflix.curator.framework.recipes.locks.InterProcessMutex;
+import com.netflix.curator.utils.ZKPaths;
+
+@SuppressWarnings("rawtypes")
+public class NimbusLeadership {
+
+ private static final String STORM_NIMBUS_LEADERSHIP_PATH =
"/nimbus/leadership";
+
+ private Map conf;
+ private CuratorFramework curator;
+ private InterProcessMutex mutex;
+ private boolean isLeader = false;
+
+ public NimbusLeadership(final Map conf) {
+ this.conf = conf;
+ }
+
+ public void acquireLeaderShip() throws Exception {
+ String nimbusHostName =
InetAddress.getLocalHost().getCanonicalHostName();
+ Object nimbusPort = conf.get(Config.NIMBUS_THRIFT_PORT);
+ String nodeId = nimbusHostName + ":" + nimbusPort.toString();
+ initCurator();
+ initLeadershipMutex(nodeId);
+ mutex.acquire();
+ isLeader = true;
+ }
+
+ public InetSocketAddress getNimbusLeaderAddress() throws Exception {
+ InetSocketAddress leaderAddress = null;
+ initCurator();
+ initLeadershipMutex(null);
+ Collection<String> nimbusNodesPath =
mutex.getParticipantNodes();
+ if (nimbusNodesPath.size() > 0) {
+ leaderAddress =
parseAddress(nimbusNodesPath.iterator().next());
+ }
+ close();
+ return leaderAddress;
+ }
+
+ public List<InetSocketAddress> getNimbusHosts() throws Exception {
+ List<InetSocketAddress> nimbusAddressList = new
ArrayList<InetSocketAddress>();
+ initCurator();
+ initLeadershipMutex(null);
+ Collection<String> nimbusNodesPath =
mutex.getParticipantNodes();
+ for (String nimbusNodePath : nimbusNodesPath) {
+ nimbusAddressList.add(parseAddress(nimbusNodePath));
+ }
+ close();
+ return nimbusAddressList;
+ }
+
+ public void close() {
--- End diff --
The spacing appears to be off here compared to the rest of the file.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---