Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import org.apache.ignite.configuration.RootKey;
import org.apache.ignite.configuration.annotation.ConfigurationType;
import org.apache.ignite.configuration.schemas.table.TablesConfiguration;
import org.apache.ignite.internal.affinity.event.AffinityEvent;
import org.apache.ignite.internal.affinity.event.AffinityEventParameters;
Expand All @@ -50,6 +50,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
Expand Down Expand Up @@ -80,8 +81,11 @@ public class AffinityManagerTest {
@BeforeEach
void setUp() {
try {
cfrMgr = new ConfigurationManager(rootConfigurationKeys(), Arrays.asList(
new TestConfigurationStorage(ConfigurationType.DISTRIBUTED)));
cfrMgr = new ConfigurationManager(
rootConfigurationKeys(),
Map.of(),
new TestConfigurationStorage(DISTRIBUTED)
);

cfrMgr.start();

Expand Down Expand Up @@ -117,7 +121,7 @@ void setUp() {
" }\n" +
" }\n" +
" }\n" +
"}", ConfigurationType.DISTRIBUTED);
"}");
}
catch (Exception e) {
LOG.error("Failed to bootstrap the test configuration manager.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public void setAndGetWithManualHost() {
"set",
"--node-endpoint",
"localhost:" + restPort,
"--type", "node", //TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
"node.metastorageNodes=[\"localhost1\"]"
);

Expand All @@ -103,7 +104,8 @@ public void setAndGetWithManualHost() {
"config",
"get",
"--node-endpoint",
"localhost:" + restPort
"localhost:" + restPort,
"--type", "node" //TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
);

assertEquals(0, exitCode);
Expand All @@ -123,7 +125,8 @@ public void partialGet() {
"--node-endpoint",
"localhost:" + restPort,
"--selector",
"network"
"network",
"--type", "node" //TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
);

assertEquals(0, exitCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,24 @@ public ConfigurationClient(HttpClient httpClient) {
* @param host String representation of server node host.
* @param port Host REST port.
* @param rawHoconPath HOCON dot-delimited path of requested configuration.
* @param type Configuration type: {@code node} or {@code cluster}.
* @return JSON string with node configuration.
*/
//TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
public String get(
String host,
int port,
@Nullable String rawHoconPath) {
@Nullable String rawHoconPath,
String type
) {
var req = HttpRequest
.newBuilder()
.header("Content-Type", "application/json");

if (rawHoconPath == null)
req.uri(URI.create("http://" + host + ":" + port + GET_URL));
req.uri(URI.create("http://" + host + ":" + port + GET_URL + type + "/"));
else
req.uri(URI.create("http://" + host + ":" + port + GET_URL +
rawHoconPath));
req.uri(URI.create("http://" + host + ":" + port + GET_URL + type + "/" + rawHoconPath));

try {
HttpResponse<String> res =
Expand All @@ -109,13 +112,15 @@ public String get(
* @param rawHoconData Valid HOCON represented as a string.
* @param out PrintWriter for printing user messages.
* @param cs ColorScheme to enrich user messages.
* @param type Configuration type: {@code node} or {@code cluster}.
*/
public void set(String host, int port, String rawHoconData, PrintWriter out, ColorScheme cs) {
//TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
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)))
.header("Content-Type", "application/json")
.uri(URI.create("http://" + host + ":" + port + SET_URL))
.uri(URI.create("http://" + host + ":" + port + SET_URL + type + "/"))
.build();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,20 @@ public static class GetConfigCommandSpec extends CommandSpec {
)
private String selector;

/** Configuration type: {@code node} or {@code cluster}. */
@CommandLine.Option(
names = "--type",
description = "Configuration type (\"node\" or \"cluster\")",
required = true
)
//TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
private String type;

/** {@inheritDoc} */
@Override public void run() {
spec.commandLine().getOut().println(
configurationClient.get(cfgHostnameOptions.host(), cfgHostnameOptions.port(), selector));
configurationClient.get(cfgHostnameOptions.host(), cfgHostnameOptions.port(), selector, type)
);
}
}

Expand All @@ -81,10 +91,25 @@ public static class SetConfigCommandSpec extends CommandSpec {
@CommandLine.Mixin
private CfgHostnameOptions cfgHostnameOptions;

/** Configuration type: {@code node} or {@code cluster}. */
//TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
@CommandLine.Option(
names = "--type",
description = "Configuration type (\"node\" or \"cluster\")",
required = true
)
private String type;

/** {@inheritDoc} */
@Override public void run() {
configurationClient.set(cfgHostnameOptions.host(), cfgHostnameOptions.port(), cfg,
spec.commandLine().getOut(), spec.commandLine().getColorScheme());
configurationClient.set(
cfgHostnameOptions.host(),
cfgHostnameOptions.port(),
cfg,
spec.commandLine().getOut(),
spec.commandLine().getColorScheme(),
type
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,19 +484,20 @@ void setUp() {
}

/** */
//TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
@Test
@DisplayName("get --node-endpoint localhost:8081")
@DisplayName("get --node-endpoint localhost:8081 --type node")
void get() throws IOException, InterruptedException {
when(res.statusCode()).thenReturn(HttpURLConnection.HTTP_OK);
when(res.body()).thenReturn("{\"baseline\":{\"autoAdjust\":{\"enabled\":true}}}");
when(httpClient.<String>send(any(), any())).thenReturn(res);

var exitCode =
cmd(ctx).execute("config get --node-endpoint localhost:8081".split(" "));
cmd(ctx).execute("config get --node-endpoint localhost:8081 --type node".split(" "));

Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> "http://localhost:8081/management/v1/configuration/".equals(r.uri().toString()) &&
argThat(r -> "http://localhost:8081/management/v1/configuration/node/".equals(r.uri().toString()) &&
"application/json".equals(r.headers().firstValue("Content-Type").get())),
any());
assertEquals("{\n" +
Expand All @@ -509,21 +510,22 @@ void get() throws IOException, InterruptedException {
}

/** */
//TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
@Test
@DisplayName("get --node-endpoint localhost:8081 --selector local.baseline")
@DisplayName("get --node-endpoint localhost:8081 --selector local.baseline --type node")
void getSubtree() throws IOException, InterruptedException {
when(res.statusCode()).thenReturn(HttpURLConnection.HTTP_OK);
when(res.body()).thenReturn("{\"autoAdjust\":{\"enabled\":true}}");
when(httpClient.<String>send(any(), any())).thenReturn(res);

var exitCode =
cmd(ctx).execute(("config get --node-endpoint localhost:8081 " +
"--selector local.baseline").split(" "));
"--selector local.baseline --type node").split(" "));

Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r ->
"http://localhost:8081/management/v1/configuration/local.baseline".equals(r.uri().toString()) &&
"http://localhost:8081/management/v1/configuration/node/local.baseline".equals(r.uri().toString()) &&
"application/json".equals(r.headers().firstValue("Content-Type").get())),
any());
assertEquals("{\n" +
Expand All @@ -534,8 +536,9 @@ void getSubtree() throws IOException, InterruptedException {
}

/** */
//TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
@Test
@DisplayName("set --node-endpoint localhost:8081 local.baseline.autoAdjust.enabled=true")
@DisplayName("set --node-endpoint localhost:8081 local.baseline.autoAdjust.enabled=true --type node")
void setHocon() throws IOException, InterruptedException {
when(res.statusCode()).thenReturn(HttpURLConnection.HTTP_OK);
when(httpClient.<String>send(any(), any())).thenReturn(res);
Expand All @@ -545,12 +548,12 @@ void setHocon() throws IOException, InterruptedException {
var cmd = cmd(ctx);
var exitCode =
cmd.execute(("config set --node-endpoint localhost:8081 " +
"local.baseline.autoAdjust.enabled=true"
"local.baseline.autoAdjust.enabled=true --type node"
).split(" "));

Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> "http://localhost:8081/management/v1/configuration/".equals(r.uri().toString()) &&
argThat(r -> "http://localhost:8081/management/v1/configuration/node/".equals(r.uri().toString()) &&
"PUT".equals(r.method()) &&
r.bodyPublisher().get().contentLength() == expSentContent.getBytes().length &&
"application/json".equals(r.headers().firstValue("Content-Type").get())),
Expand All @@ -561,8 +564,12 @@ void setHocon() throws IOException, InterruptedException {
}

/** */
//TODO: Fix in https://issues.apache.org/jira/browse/IGNITE-15306
@Test
@DisplayName("set --node-endpoint localhost:8081 {\"local\":{\"baseline\":{\"autoAdjust\":{\"enabled\":true}}}}")
@DisplayName(
"set --node-endpoint localhost:8081 {\"local\":{\"baseline\":{\"autoAdjust\":{\"enabled\":true}}}} " +
"--type node"
)
void setJson() throws IOException, InterruptedException {
when(res.statusCode()).thenReturn(HttpURLConnection.HTTP_OK);
when(httpClient.<String>send(any(), any())).thenReturn(res);
Expand All @@ -572,12 +579,12 @@ void setJson() throws IOException, InterruptedException {
var cmd = cmd(ctx);
var exitCode =
cmd.execute(("config set --node-endpoint localhost:8081 " +
"local.baseline.autoAdjust.enabled=true"
"local.baseline.autoAdjust.enabled=true --type node"
).split(" "));

Assertions.assertEquals(0, exitCode);
verify(httpClient).send(
argThat(r -> "http://localhost:8081/management/v1/configuration/".equals(r.uri().toString()) &&
argThat(r -> "http://localhost:8081/management/v1/configuration/node/".equals(r.uri().toString()) &&
"PUT".equals(r.method()) &&
r.bodyPublisher().get().contentLength() == expSentContent.getBytes().length &&
"application/json".equals(r.headers().firstValue("Content-Type").get())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import io.netty.channel.ChannelFuture;
import org.apache.ignite.app.Ignite;
import org.apache.ignite.configuration.annotation.ConfigurationType;
import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
import org.apache.ignite.internal.configuration.ConfigurationRegistry;
import org.apache.ignite.internal.configuration.storage.TestConfigurationStorage;
Expand All @@ -34,6 +34,7 @@
import org.msgpack.core.MessagePack;
import org.slf4j.helpers.NOPLogger;

import static org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -179,9 +180,9 @@ void testHandshakeInvalidVersionReturnsError() throws Exception {

private ChannelFuture startServer() throws InterruptedException {
configurationRegistry = new ConfigurationRegistry(
Collections.singletonList(ClientConnectorConfiguration.KEY),
Collections.emptyMap(),
Collections.singletonList(new TestConfigurationStorage(ConfigurationType.LOCAL))
List.of(ClientConnectorConfiguration.KEY),
Map.of(),
new TestConfigurationStorage(LOCAL)
);

configurationRegistry.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
package org.apache.ignite.client;

import java.net.InetSocketAddress;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import io.netty.channel.ChannelFuture;
import io.netty.util.ResourceLeakDetector;
import org.apache.ignite.app.Ignite;
import org.apache.ignite.client.fakes.FakeIgnite;
import org.apache.ignite.client.handler.ClientHandlerModule;
import org.apache.ignite.configuration.annotation.ConfigurationType;
import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
import org.apache.ignite.internal.configuration.ConfigurationRegistry;
import org.apache.ignite.internal.configuration.storage.TestConfigurationStorage;
Expand All @@ -34,6 +34,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.slf4j.helpers.NOPLogger;

import static org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

Expand Down Expand Up @@ -89,9 +90,9 @@ public static Ignite startClient(String... addrs) {

public static ChannelFuture startServer(String host) throws InterruptedException {
configurationRegistry = new ConfigurationRegistry(
Collections.singletonList(ClientConnectorConfiguration.KEY),
Collections.emptyMap(),
Collections.singletonList(new TestConfigurationStorage(ConfigurationType.LOCAL))
List.of(ClientConnectorConfiguration.KEY),
Map.of(),
new TestConfigurationStorage(LOCAL)
);

configurationRegistry.start();
Expand Down
Loading