diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-02-08 11:19:19 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-02-08 11:19:19 +0100 |
commit | 3abb7bc8bc8d6845284c86cd4b6869536e0daee9 (patch) | |
tree | af7071d95eabf149b6aae2f5ce2eba0289936417 /node-repository | |
parent | b69c1cad6dae7506c22e13ceb2432d8f1839ab4d (diff) |
Nonfunctional changes only
Diffstat (limited to 'node-repository')
4 files changed, 28 insertions, 27 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/ErrorResponse.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/ErrorResponse.java index 7c5a1fffbc0..701ae665757 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/ErrorResponse.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/ErrorResponse.java @@ -15,6 +15,13 @@ public class ErrorResponse extends HttpResponse { private final Slime slime = new Slime(); + public enum errorCodes { + NOT_FOUND, + BAD_REQUEST, + METHOD_NOT_ALLOWED, + INTERNAL_SERVER_ERROR + } + public ErrorResponse(int code, String errorType, String message) { super(code); Cursor root = slime.setObject(); @@ -22,15 +29,6 @@ public class ErrorResponse extends HttpResponse { root.setString("message", message); } - public enum errorCodes { - NOT_FOUND, - BAD_REQUEST, - METHOD_NOT_ALLOWED, - INTERNAL_SERVER_ERROR, - INVALID_APPLICATION_PACKAGE, - UNKNOWN_VESPA_VERSION - } - public static ErrorResponse notFoundError(String message) { return new ErrorResponse(NOT_FOUND, errorCodes.NOT_FOUND.name(), message); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodesApiHandler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodesApiHandler.java index 7e329e1599b..f9d878dabec 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodesApiHandler.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodesApiHandler.java @@ -67,13 +67,14 @@ public class NodesApiHandler extends LoggingRequestHandler { case PATCH: return handlePATCH(request); default: return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is not supported"); } - } catch (NotFoundException | com.yahoo.vespa.hosted.provision.NotFoundException e) { + } + catch (NotFoundException | com.yahoo.vespa.hosted.provision.NotFoundException e) { return ErrorResponse.notFoundError(Exceptions.toMessageString(e)); - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) { return ErrorResponse.badRequest(Exceptions.toMessageString(e)); } catch (RuntimeException e) { - e.printStackTrace(); log.log(Level.WARNING, "Unexpected error handling '" + request.getUri() + "'", e); return ErrorResponse.internalServerError(Exceptions.toMessageString(e)); } @@ -88,7 +89,7 @@ public class NodesApiHandler extends LoggingRequestHandler { if (path.startsWith("/nodes/v2/state/")) return new NodesResponse(ResponseType.nodesInStateList, request, nodeRepository); if (path.startsWith("/nodes/v2/acl/")) return new NodeAclResponse(request, nodeRepository); if (path.equals( "/nodes/v2/command/")) return ResourcesResponse.fromStrings(request.getUri(), "restart", "reboot"); - return ErrorResponse.notFoundError("Nothing at path '" + request.getUri().getPath() + "'"); + return ErrorResponse.notFoundError("Nothing at path '" + path + "'"); } private HttpResponse handlePUT(HttpRequest request) { @@ -114,7 +115,7 @@ public class NodesApiHandler extends LoggingRequestHandler { return new MessageResponse("Moved " + lastElement(path) + " to active"); } else { - return ErrorResponse.notFoundError("Cannot put to path '" + request.getUri().getPath() + "'"); + return ErrorResponse.notFoundError("Cannot put to path '" + path + "'"); } } @@ -171,11 +172,11 @@ public class NodesApiHandler extends LoggingRequestHandler { } public int addNodes(InputStream jsonStream) { - List<Node> nodes = createNodesFromSlime(getSlimeFromInputStream(jsonStream).get()); + List<Node> nodes = createNodesFromSlime(toSlime(jsonStream).get()); return nodeRepository.addNodes(nodes).size(); } - private static Slime getSlimeFromInputStream(InputStream jsonStream) { + private Slime toSlime(InputStream jsonStream) { try { byte[] jsonBytes = IOUtils.readBytes(jsonStream, 1000 * 1000); return SlimeUtils.jsonToSlime(jsonBytes); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java index 3ca0c4ff365..1239069c1a0 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java @@ -8,17 +8,19 @@ package com.yahoo.vespa.hosted.provision.testutils; * @author dybis */ public class ContainerConfig { + public static final String servicesXmlV2(int port) { return - "<jdisc version=\"1.0\">" + - " <component id=\"com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors\"/>" + - " <component id=\"com.yahoo.vespa.hosted.provision.testutils.MockNodeRepository\"/>" + - " <handler id=\"com.yahoo.vespa.hosted.provision.restapi.v2.NodesApiHandler\">" + - " <binding>http://*/nodes/v2/*</binding>" + - " </handler>" + - " <http>\n" + - " <server id='myServer' port='" + port + "' />\n" + - " </http>" + - "</jdisc>"; + "<jdisc version='1.0'>" + + " <component id='com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors'/>" + + " <component id='com.yahoo.vespa.hosted.provision.testutils.MockNodeRepository'/>" + + " <handler id='com.yahoo.vespa.hosted.provision.restapi.v2.NodesApiHandler'>" + + " <binding>http://*/nodes/v2/*</binding>" + + " </handler>" + + " <http>" + + " <server id='myServer' port='" + port + "' />" + + " </http>" + + "</jdisc>"; } + } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java index d2af29765fd..20440c2bc9e 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java @@ -469,7 +469,7 @@ public class RestApiTest { assertResponse(request, 200, "{\"message\":\"Scheduled reboot of " + rebootCount + " matching nodes\"}"); } - /** Replace @include(localFile) with the content of the file */ + /** Replaces @include(localFile) with the content of the file */ private String include(String response) throws IOException { // Please don't look at this code int includeIndex = response.indexOf("@include("); |