Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-16487 Use PATCH HTTP verb instead of PUT for modifying cluster/node configuration #638

Merged
merged 1 commit into from Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -43,8 +43,8 @@ public class ConfigurationClient {
/** Url for getting configuration from REST endpoint of the node. */
private static final String GET_URL = "/management/v1/configuration/";

/** Url for setting configuration with REST endpoint of the node. */
private static final String SET_URL = "/management/v1/configuration/";
/** Url for patching configuration with REST endpoint of the node. */
private static final String PATCH_URL = "/management/v1/configuration/";

/** Http client. */
private final HttpClient httpClient;
Expand Down Expand Up @@ -119,9 +119,9 @@ public String get(
public void set(String host, int port, String rawHoconData, PrintWriter out, ColorScheme cs, String type) {
var req = HttpRequest
.newBuilder()
.PUT(HttpRequest.BodyPublishers.ofString(renderJsonFromHocon(rawHoconData)))
.method("PATCH", HttpRequest.BodyPublishers.ofString(renderJsonFromHocon(rawHoconData)))
.header("Content-Type", "application/json")
.uri(URI.create("http://" + host + ":" + port + SET_URL + type + "/"))
.uri(URI.create("http://" + host + ":" + port + PATCH_URL + type + "/"))
.build();

try {
Expand Down
Expand Up @@ -553,7 +553,7 @@ void setHocon() throws IOException, InterruptedException {
Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> "http://localhost:8081/management/v1/configuration/node/".equals(r.uri().toString())
&& "PUT".equals(r.method())
&& "PATCH".equals(r.method())
&& r.bodyPublisher().get().contentLength() == expSentContent.getBytes().length
&& "application/json".equals(r.headers().firstValue("Content-Type").get())),
any());
Expand Down Expand Up @@ -583,7 +583,7 @@ void setJson() throws IOException, InterruptedException {
Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> "http://localhost:8081/management/v1/configuration/node/".equals(r.uri().toString())
&& "PUT".equals(r.method())
&& "PATCH".equals(r.method())
&& r.bodyPublisher().get().contentLength() == expSentContent.getBytes().length
&& "application/json".equals(r.headers().firstValue("Content-Type").get())),
any());
Expand Down
Expand Up @@ -126,12 +126,12 @@ public void start() {
CLUSTER_CFG_URL + ":" + PATH_PARAM,
(req, resp) -> handleRepresentByPath(req, resp, clusterCfgPresentation)
)
.put(
.patch(
NODE_CFG_URL,
APPLICATION_JSON,
(req, resp) -> handleUpdate(req, resp, nodeCfgPresentation)
)
.put(
.patch(
CLUSTER_CFG_URL,
APPLICATION_JSON,
(req, resp) -> handleUpdate(req, resp, clusterCfgPresentation)
Expand Down
Expand Up @@ -106,6 +106,23 @@ public Router put(
return this;
}

/**
* Defines a PATCH route.
*
* @param route Route.
* @param acceptType Accept type.
* @param hnd Actual handler of the request.
* @return Router
*/
public Router patch(
String route,
AsciiString acceptType,
BiConsumer<RestApiHttpRequest, RestApiHttpResponse> hnd
) {
addRoute(new Route(route, HttpMethod.PATCH, acceptType.toString(), hnd));
return this;
}

/**
* Adds the route to router chain.
*
Expand Down
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.internal.rest.routes;

import static io.netty.handler.codec.http.HttpMethod.GET;
import static io.netty.handler.codec.http.HttpMethod.PATCH;
import static io.netty.handler.codec.http.HttpMethod.PUT;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -82,4 +83,13 @@ void testMatchByUriWithParams() {
var req = new DefaultHttpRequest(HTTP_1_1, GET, "/user/John");
assertTrue(route.match(req));
}

@Test
void testPatchVerbMatch() {
var route = new Route("/user", PATCH, null, (request, response) -> {
});
var req = new DefaultHttpRequest(HTTP_1_1, PATCH, "/user");

assertTrue(route.match(req));
}
}