hadoop git commit: HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

2016-10-18 Thread zhz
Repository: hadoop
Updated Branches:
  refs/heads/branch-2.7 d053d1c3f -> bd1676359


HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

(cherry picked from commit ee233ec95ce8cfc8309d3adc072d926cd85eba08)
(cherry picked from commit 731ed9cad81f91e9da18148f0c4757a38ca406f6)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/bd167635
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/bd167635
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/bd167635

Branch: refs/heads/branch-2.7
Commit: bd16763591ec24c7f180353990d1644655968e66
Parents: d053d1c
Author: Robert Kanter 
Authored: Fri Jul 24 09:41:53 2015 -0700
Committer: Zhe Zhang 
Committed: Tue Oct 18 10:25:52 2016 -0700

--
 hadoop-common-project/hadoop-common/CHANGES.txt |  1 +
 .../org/apache/hadoop/net/ServerSocketUtil.java | 63 
 2 files changed, 64 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd167635/hadoop-common-project/hadoop-common/CHANGES.txt
--
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 4f16aa6..ffbc311 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -7,6 +7,7 @@ Release 2.7.4 - UNRELEASED
   NEW FEATURES
 
   IMPROVEMENTS
+HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)
 
   OPTIMIZATIONS
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/bd167635/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
new file mode 100644
index 000..0ce835f
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.net;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServerSocketUtil {
+
+  private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class);
+
+  /**
+   * Port scan & allocate is how most other apps find ports
+   * 
+   * @param port given port
+   * @param retries number of retires
+   * @return
+   * @throws IOException
+   */
+  public static int getPort(int port, int retries) throws IOException {
+Random rand = new Random();
+int tryPort = port;
+int tries = 0;
+while (true) {
+  if (tries > 0) {
+tryPort = port + rand.nextInt(65535 - port);
+  }
+  LOG.info("Using port " + tryPort);
+  try (ServerSocket s = new ServerSocket(tryPort)) {
+return tryPort;
+  } catch (IOException e) {
+tries++;
+if (tries >= retries) {
+  LOG.info("Port is already in use; giving up");
+  throw e;
+} else {
+  LOG.info("Port is already in use; trying again");
+}
+  }
+}
+  }
+
+}


-
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org



[17/50] [abbrv] hadoop git commit: HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

2015-07-28 Thread jianhe
HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ee233ec9
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ee233ec9
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ee233ec9

Branch: refs/heads/YARN-1197
Commit: ee233ec95ce8cfc8309d3adc072d926cd85eba08
Parents: 0fcb4a8
Author: Robert Kanter rkan...@apache.org
Authored: Fri Jul 24 09:41:53 2015 -0700
Committer: Robert Kanter rkan...@apache.org
Committed: Fri Jul 24 09:41:53 2015 -0700

--
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 .../org/apache/hadoop/net/ServerSocketUtil.java | 63 
 2 files changed, 65 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee233ec9/hadoop-common-project/hadoop-common/CHANGES.txt
--
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 56edcac..d6d43f2 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -725,6 +725,8 @@ Release 2.8.0 - UNRELEASED
 HADOOP-12189. Improve CallQueueManager#swapQueue to make queue elements
 drop nearly impossible. (Zhihai Xu via wang)
 
+HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)
+
   OPTIMIZATIONS
 
 HADOOP-11785. Reduce the number of listStatus operation in distcp

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee233ec9/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
new file mode 100644
index 000..0ce835f
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.net;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServerSocketUtil {
+
+  private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class);
+
+  /**
+   * Port scan  allocate is how most other apps find ports
+   * 
+   * @param port given port
+   * @param retries number of retires
+   * @return
+   * @throws IOException
+   */
+  public static int getPort(int port, int retries) throws IOException {
+Random rand = new Random();
+int tryPort = port;
+int tries = 0;
+while (true) {
+  if (tries  0) {
+tryPort = port + rand.nextInt(65535 - port);
+  }
+  LOG.info(Using port  + tryPort);
+  try (ServerSocket s = new ServerSocket(tryPort)) {
+return tryPort;
+  } catch (IOException e) {
+tries++;
+if (tries = retries) {
+  LOG.info(Port is already in use; giving up);
+  throw e;
+} else {
+  LOG.info(Port is already in use; trying again);
+}
+  }
+}
+  }
+
+}



[27/50] [abbrv] hadoop git commit: HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

2015-07-27 Thread zjshen
HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/5e1eb48c
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/5e1eb48c
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/5e1eb48c

Branch: refs/heads/YARN-2928
Commit: 5e1eb48cff1ecf32287617ee56a6d84ec8f38ca7
Parents: 21c9cb8
Author: Robert Kanter rkan...@apache.org
Authored: Fri Jul 24 09:41:53 2015 -0700
Committer: Zhijie Shen zjs...@apache.org
Committed: Mon Jul 27 12:57:35 2015 -0700

--
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 .../org/apache/hadoop/net/ServerSocketUtil.java | 63 
 2 files changed, 65 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/5e1eb48c/hadoop-common-project/hadoop-common/CHANGES.txt
--
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 56edcac..d6d43f2 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -725,6 +725,8 @@ Release 2.8.0 - UNRELEASED
 HADOOP-12189. Improve CallQueueManager#swapQueue to make queue elements
 drop nearly impossible. (Zhihai Xu via wang)
 
+HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)
+
   OPTIMIZATIONS
 
 HADOOP-11785. Reduce the number of listStatus operation in distcp

http://git-wip-us.apache.org/repos/asf/hadoop/blob/5e1eb48c/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
new file mode 100644
index 000..0ce835f
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.net;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServerSocketUtil {
+
+  private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class);
+
+  /**
+   * Port scan  allocate is how most other apps find ports
+   * 
+   * @param port given port
+   * @param retries number of retires
+   * @return
+   * @throws IOException
+   */
+  public static int getPort(int port, int retries) throws IOException {
+Random rand = new Random();
+int tryPort = port;
+int tries = 0;
+while (true) {
+  if (tries  0) {
+tryPort = port + rand.nextInt(65535 - port);
+  }
+  LOG.info(Using port  + tryPort);
+  try (ServerSocket s = new ServerSocket(tryPort)) {
+return tryPort;
+  } catch (IOException e) {
+tries++;
+if (tries = retries) {
+  LOG.info(Port is already in use; giving up);
+  throw e;
+} else {
+  LOG.info(Port is already in use; trying again);
+}
+  }
+}
+  }
+
+}



[13/37] hadoop git commit: HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

2015-07-27 Thread arp
HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ee233ec9
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ee233ec9
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ee233ec9

Branch: refs/heads/HDFS-7240
Commit: ee233ec95ce8cfc8309d3adc072d926cd85eba08
Parents: 0fcb4a8
Author: Robert Kanter rkan...@apache.org
Authored: Fri Jul 24 09:41:53 2015 -0700
Committer: Robert Kanter rkan...@apache.org
Committed: Fri Jul 24 09:41:53 2015 -0700

--
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 .../org/apache/hadoop/net/ServerSocketUtil.java | 63 
 2 files changed, 65 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee233ec9/hadoop-common-project/hadoop-common/CHANGES.txt
--
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 56edcac..d6d43f2 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -725,6 +725,8 @@ Release 2.8.0 - UNRELEASED
 HADOOP-12189. Improve CallQueueManager#swapQueue to make queue elements
 drop nearly impossible. (Zhihai Xu via wang)
 
+HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)
+
   OPTIMIZATIONS
 
 HADOOP-11785. Reduce the number of listStatus operation in distcp

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee233ec9/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
new file mode 100644
index 000..0ce835f
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.net;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServerSocketUtil {
+
+  private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class);
+
+  /**
+   * Port scan  allocate is how most other apps find ports
+   * 
+   * @param port given port
+   * @param retries number of retires
+   * @return
+   * @throws IOException
+   */
+  public static int getPort(int port, int retries) throws IOException {
+Random rand = new Random();
+int tryPort = port;
+int tries = 0;
+while (true) {
+  if (tries  0) {
+tryPort = port + rand.nextInt(65535 - port);
+  }
+  LOG.info(Using port  + tryPort);
+  try (ServerSocket s = new ServerSocket(tryPort)) {
+return tryPort;
+  } catch (IOException e) {
+tries++;
+if (tries = retries) {
+  LOG.info(Port is already in use; giving up);
+  throw e;
+} else {
+  LOG.info(Port is already in use; trying again);
+}
+  }
+}
+  }
+
+}



[11/29] hadoop git commit: HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

2015-07-25 Thread aw
HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ee233ec9
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ee233ec9
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ee233ec9

Branch: refs/heads/HADOOP-12111
Commit: ee233ec95ce8cfc8309d3adc072d926cd85eba08
Parents: 0fcb4a8
Author: Robert Kanter rkan...@apache.org
Authored: Fri Jul 24 09:41:53 2015 -0700
Committer: Robert Kanter rkan...@apache.org
Committed: Fri Jul 24 09:41:53 2015 -0700

--
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 .../org/apache/hadoop/net/ServerSocketUtil.java | 63 
 2 files changed, 65 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee233ec9/hadoop-common-project/hadoop-common/CHANGES.txt
--
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 56edcac..d6d43f2 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -725,6 +725,8 @@ Release 2.8.0 - UNRELEASED
 HADOOP-12189. Improve CallQueueManager#swapQueue to make queue elements
 drop nearly impossible. (Zhihai Xu via wang)
 
+HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)
+
   OPTIMIZATIONS
 
 HADOOP-11785. Reduce the number of listStatus operation in distcp

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee233ec9/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
new file mode 100644
index 000..0ce835f
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.net;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServerSocketUtil {
+
+  private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class);
+
+  /**
+   * Port scan  allocate is how most other apps find ports
+   * 
+   * @param port given port
+   * @param retries number of retires
+   * @return
+   * @throws IOException
+   */
+  public static int getPort(int port, int retries) throws IOException {
+Random rand = new Random();
+int tryPort = port;
+int tries = 0;
+while (true) {
+  if (tries  0) {
+tryPort = port + rand.nextInt(65535 - port);
+  }
+  LOG.info(Using port  + tryPort);
+  try (ServerSocket s = new ServerSocket(tryPort)) {
+return tryPort;
+  } catch (IOException e) {
+tries++;
+if (tries = retries) {
+  LOG.info(Port is already in use; giving up);
+  throw e;
+} else {
+  LOG.info(Port is already in use; trying again);
+}
+  }
+}
+  }
+
+}



hadoop git commit: HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

2015-07-24 Thread rkanter
Repository: hadoop
Updated Branches:
  refs/heads/trunk 0fcb4a8cf - ee233ec95


HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ee233ec9
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ee233ec9
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ee233ec9

Branch: refs/heads/trunk
Commit: ee233ec95ce8cfc8309d3adc072d926cd85eba08
Parents: 0fcb4a8
Author: Robert Kanter rkan...@apache.org
Authored: Fri Jul 24 09:41:53 2015 -0700
Committer: Robert Kanter rkan...@apache.org
Committed: Fri Jul 24 09:41:53 2015 -0700

--
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 .../org/apache/hadoop/net/ServerSocketUtil.java | 63 
 2 files changed, 65 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee233ec9/hadoop-common-project/hadoop-common/CHANGES.txt
--
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 56edcac..d6d43f2 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -725,6 +725,8 @@ Release 2.8.0 - UNRELEASED
 HADOOP-12189. Improve CallQueueManager#swapQueue to make queue elements
 drop nearly impossible. (Zhihai Xu via wang)
 
+HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)
+
   OPTIMIZATIONS
 
 HADOOP-11785. Reduce the number of listStatus operation in distcp

http://git-wip-us.apache.org/repos/asf/hadoop/blob/ee233ec9/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
new file mode 100644
index 000..0ce835f
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.net;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServerSocketUtil {
+
+  private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class);
+
+  /**
+   * Port scan  allocate is how most other apps find ports
+   * 
+   * @param port given port
+   * @param retries number of retires
+   * @return
+   * @throws IOException
+   */
+  public static int getPort(int port, int retries) throws IOException {
+Random rand = new Random();
+int tryPort = port;
+int tries = 0;
+while (true) {
+  if (tries  0) {
+tryPort = port + rand.nextInt(65535 - port);
+  }
+  LOG.info(Using port  + tryPort);
+  try (ServerSocket s = new ServerSocket(tryPort)) {
+return tryPort;
+  } catch (IOException e) {
+tries++;
+if (tries = retries) {
+  LOG.info(Port is already in use; giving up);
+  throw e;
+} else {
+  LOG.info(Port is already in use; trying again);
+}
+  }
+}
+  }
+
+}



hadoop git commit: HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

2015-07-24 Thread rkanter
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 6a71a0a23 - 731ed9cad


HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)

(cherry picked from commit ee233ec95ce8cfc8309d3adc072d926cd85eba08)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/731ed9ca
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/731ed9ca
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/731ed9ca

Branch: refs/heads/branch-2
Commit: 731ed9cad81f91e9da18148f0c4757a38ca406f6
Parents: 6a71a0a
Author: Robert Kanter rkan...@apache.org
Authored: Fri Jul 24 09:41:53 2015 -0700
Committer: Robert Kanter rkan...@apache.org
Committed: Fri Jul 24 09:42:04 2015 -0700

--
 hadoop-common-project/hadoop-common/CHANGES.txt |  2 +
 .../org/apache/hadoop/net/ServerSocketUtil.java | 63 
 2 files changed, 65 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/hadoop/blob/731ed9ca/hadoop-common-project/hadoop-common/CHANGES.txt
--
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt 
b/hadoop-common-project/hadoop-common/CHANGES.txt
index 82ee763..ed86e2e 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -217,6 +217,8 @@ Release 2.8.0 - UNRELEASED
 HADOOP-12189. Improve CallQueueManager#swapQueue to make queue elements
 drop nearly impossible. (Zhihai Xu via wang)
 
+HADOOP-12259. Utility to Dynamic port allocation (brahmareddy via rkanter)
+
   OPTIMIZATIONS
 
 HADOOP-11785. Reduce the number of listStatus operation in distcp

http://git-wip-us.apache.org/repos/asf/hadoop/blob/731ed9ca/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
--
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
new file mode 100644
index 000..0ce835f
--- /dev/null
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/net/ServerSocketUtil.java
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.net;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Random;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServerSocketUtil {
+
+  private static final Log LOG = LogFactory.getLog(ServerSocketUtil.class);
+
+  /**
+   * Port scan  allocate is how most other apps find ports
+   * 
+   * @param port given port
+   * @param retries number of retires
+   * @return
+   * @throws IOException
+   */
+  public static int getPort(int port, int retries) throws IOException {
+Random rand = new Random();
+int tryPort = port;
+int tries = 0;
+while (true) {
+  if (tries  0) {
+tryPort = port + rand.nextInt(65535 - port);
+  }
+  LOG.info(Using port  + tryPort);
+  try (ServerSocket s = new ServerSocket(tryPort)) {
+return tryPort;
+  } catch (IOException e) {
+tries++;
+if (tries = retries) {
+  LOG.info(Port is already in use; giving up);
+  throw e;
+} else {
+  LOG.info(Port is already in use; trying again);
+}
+  }
+}
+  }
+
+}