apex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vro...@apache.org
Subject [25/29] incubator-apex-core git commit: APEX-181 added utility function to get all RM addresses
Date Sun, 11 Oct 2015 16:05:40 GMT
APEX-181 added utility function to get all RM addresses


Project: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/commit/3d0dd624
Tree: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/tree/3d0dd624
Diff: http://git-wip-us.apache.org/repos/asf/incubator-apex-core/diff/3d0dd624

Branch: refs/heads/feature-module
Commit: 3d0dd624a1b83b819fa64ab1f9fc3da6402db7fb
Parents: c442568
Author: David Yan <david@datatorrent.com>
Authored: Wed Oct 7 18:31:36 2015 -0700
Committer: David Yan <david@datatorrent.com>
Committed: Thu Oct 8 10:35:18 2015 -0700

----------------------------------------------------------------------
 .../stram/client/StramClientUtils.java           | 17 +++++++++++++++++
 .../stram/client/StramClientUtilsTest.java       | 19 ++++++++++++++++---
 2 files changed, 33 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/3d0dd624/engine/src/main/java/com/datatorrent/stram/client/StramClientUtils.java
----------------------------------------------------------------------
diff --git a/engine/src/main/java/com/datatorrent/stram/client/StramClientUtils.java b/engine/src/main/java/com/datatorrent/stram/client/StramClientUtils.java
index 04a3484..4ac6487 100644
--- a/engine/src/main/java/com/datatorrent/stram/client/StramClientUtils.java
+++ b/engine/src/main/java/com/datatorrent/stram/client/StramClientUtils.java
@@ -777,4 +777,21 @@ public class StramClientUtils
     return host + ":" + socketAddress.getPort();
   }
 
+  public static List<InetSocketAddress> getRMAddresses(Configuration conf)
+  {
+
+    List<InetSocketAddress> rmAddresses = new ArrayList<>();
+    if (ConfigUtils.isRMHAEnabled(conf)) {
+      // HA is enabled get all
+      for (String rmId : ConfigUtils.getRMHAIds(conf)) {
+        InetSocketAddress socketAddress = getRMWebAddress(conf, rmId);
+        rmAddresses.add(socketAddress);
+      }
+    } else {
+      InetSocketAddress socketAddress = getRMWebAddress(conf, null);
+      rmAddresses.add(socketAddress);
+    }
+    return rmAddresses;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-apex-core/blob/3d0dd624/engine/src/test/java/com/datatorrent/stram/client/StramClientUtilsTest.java
----------------------------------------------------------------------
diff --git a/engine/src/test/java/com/datatorrent/stram/client/StramClientUtilsTest.java b/engine/src/test/java/com/datatorrent/stram/client/StramClientUtilsTest.java
index e97b49f..f9fca05 100644
--- a/engine/src/test/java/com/datatorrent/stram/client/StramClientUtilsTest.java
+++ b/engine/src/test/java/com/datatorrent/stram/client/StramClientUtilsTest.java
@@ -19,7 +19,9 @@
 package com.datatorrent.stram.client;
 
 import java.net.InetAddress;
+import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
+import java.util.List;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -57,9 +59,16 @@ public class StramClientUtilsTest
     conf.set(YarnConfiguration.RM_WEBAPP_ADDRESS, "192.168.1.1:8032");
     conf.set(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS, "192.168.1.2:8032");
     Assert.assertEquals(getHostString("192.168.1.1") + ":8032", StramClientUtils.getSocketConnectString(StramClientUtils.getRMWebAddress(conf,
null)));
+    List<InetSocketAddress> addresses = StramClientUtils.getRMAddresses(conf);
+    Assert.assertEquals(1, addresses.size());
+    Assert.assertEquals(getHostString("192.168.1.1") + ":8032", StramClientUtils.getSocketConnectString(addresses.get(0)));
+
     conf.setBoolean(CommonConfigurationKeysPublic.HADOOP_SSL_ENABLED_KEY, true);
     Assert.assertEquals(getHostString("192.168.1.2") + ":8032", StramClientUtils.getSocketConnectString(StramClientUtils.getRMWebAddress(conf,
null)));
-    
+    addresses = StramClientUtils.getRMAddresses(conf);
+    Assert.assertEquals(1, addresses.size());
+    Assert.assertEquals(getHostString("192.168.1.2") + ":8032", StramClientUtils.getSocketConnectString(addresses.get(0)));
+
     // set localhost if host is unknown
     conf.set(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS, "someunknownhost.:8032");
 
@@ -70,12 +79,16 @@ public class StramClientUtilsTest
     Assert.assertEquals(InetAddress.getLocalHost().getCanonicalHostName() + ":8032", StramClientUtils.getSocketConnectString(StramClientUtils.getRMWebAddress(conf,
null)));
 
     // test when HA is enabled
-    conf.getBoolean(ConfigUtils.RM_HA_ENABLED, true);
+    conf.setBoolean(ConfigUtils.RM_HA_ENABLED, true);
     conf.set(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS + ".rm1", "192.168.1.1:8032");
     conf.set(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS + ".rm2", "192.168.1.2:8032");
+    conf.set("yarn.resourcemanager.ha.rm-ids", "rm1,rm2");
     Assert.assertEquals(getHostString("192.168.1.1") + ":8032", StramClientUtils.getSocketConnectString(StramClientUtils.getRMWebAddress(conf,
"rm1")));
     Assert.assertEquals(getHostString("192.168.1.2") + ":8032", StramClientUtils.getSocketConnectString(StramClientUtils.getRMWebAddress(conf,
"rm2")));
-
+    addresses = StramClientUtils.getRMAddresses(conf);
+    Assert.assertEquals(2, addresses.size());
+    Assert.assertEquals(getHostString("192.168.1.1") + ":8032", StramClientUtils.getSocketConnectString(addresses.get(0)));
+    Assert.assertEquals(getHostString("192.168.1.2") + ":8032", StramClientUtils.getSocketConnectString(addresses.get(1)));
   }
 
 }


Mime
View raw message