diff options
author | Harald Musum <musum@yahoo-inc.com> | 2017-10-12 18:02:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-12 18:02:56 +0200 |
commit | 2e1b909b1dbf01ed53367d84f9e0f40f0757737f (patch) | |
tree | 0f3f367abe036f87893a757f86d7bfe1c5789c9d | |
parent | 0d7cff740eaca62c4db1e9586fe4b9f67a8b6db7 (diff) | |
parent | 9cc3de14e07a536f1b514df2467d6a40b938abac (diff) |
Merge pull request #3733 from vespa-engine/hakonhall/avoid-httpexception-on-409
Avoid HttpException on 409
2 files changed, 25 insertions, 4 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/HttpException.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/HttpException.java index fd7f6308593..f4e8c63235d 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/HttpException.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/HttpException.java @@ -18,10 +18,18 @@ public class HttpException extends RuntimeException { throw new HttpException(statusCode, message); } - if (status == Response.Status.NOT_FOUND) { - throw new NotFoundException(message); - } else if (status.getFamily() != Response.Status.Family.SUCCESSFUL) { - throw new HttpException(status, message); + if (status.getFamily() == Response.Status.Family.SUCCESSFUL) { + return; + } + + switch (status) { + case NOT_FOUND: throw new NotFoundException(message); + case CONFLICT: + // A response body is assumed to be present, and + // will later be interpreted as an error. + return; + default: + throw new HttpException(status, message); } } diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutorTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutorTest.java index e197dd8bc54..21d53593b65 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutorTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutorTest.java @@ -143,6 +143,19 @@ public class ConfigServerHttpRequestExecutorTest { assertLogStringContainsGETForAHost(); } + @Test + public void testConflict() throws Exception { + Set<String> configServers = new ArraySet<>(2); + configServers.add("host1"); + configServers.add("host2"); + // Server is returning 409, no exception is thrown. + mockReturnCode = 409; + ConfigServerHttpRequestExecutor executor = + new ConfigServerHttpRequestExecutor(configServers, createClientMock()); + executor.get("/path", 666, TestPojo.class); + assertLogStringContainsGETForAHost(); + } + private void assertLogStringContainsGETForAHost() { String logString = mockLog.toString(); //assertThat(logString, startsWith("GET http://host")); |