[
https://issues.apache.org/jira/browse/YARN-3528?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14610715#comment-14610715
]
Varun Saxena commented on YARN-3528:
------------------------------------
[~brahmareddy], looked at your code. Its somewhat repetitive. IIUC, what you
are trying to achieve here is first try a passed port and then randomize. You
can change the code as under. Disclaimer : Havent tested it but should work.
{code}
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");
}
}
}
}
{code}
> Tests with 12345 as hard-coded port break jenkins
> -------------------------------------------------
>
> Key: YARN-3528
> URL: https://issues.apache.org/jira/browse/YARN-3528
> Project: Hadoop YARN
> Issue Type: Bug
> Affects Versions: 3.0.0
> Environment: ASF Jenkins
> Reporter: Steve Loughran
> Assignee: Brahma Reddy Battula
> Priority: Blocker
> Labels: test
> Attachments: YARN-3528-002.patch, YARN-3528.patch
>
>
> A lot of the YARN tests have hard-coded the port 12345 for their services to
> come up on.
> This makes it impossible to have scheduled or precommit tests to run
> consistently on the ASF jenkins hosts. Instead the tests fail regularly and
> appear to get ignored completely.
> A quick grep of "12345" shows up many places in the test suite where this
> practise has developed.
> * All {{BaseContainerManagerTest}} subclasses
> * {{TestNodeManagerShutdown}}
> * {{TestContainerManager}}
> + others
> This needs to be addressed through portscanning and dynamic port allocation.
> Please can someone do this.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)