sashapolo commented on code in PR #1267:
URL: https://github.com/apache/ignite-3/pull/1267#discussion_r1018026066


##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/NodeNameRegistry.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli;
+
+import static 
org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+
+import jakarta.inject.Singleton;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import 
org.apache.ignite.internal.cli.call.cluster.topology.PhysicalTopologyCall;
+import org.apache.ignite.internal.cli.core.call.UrlCallInput;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+import org.apache.ignite.rest.client.model.ClusterNode;
+import org.apache.ignite.rest.client.model.NodeMetadata;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Registry to get a node URL by a node name.
+ */
+@Singleton
+public class NodeNameRegistry {
+
+    private final IgniteLogger log = Loggers.forClass(getClass());
+    private volatile Map<String, URL> nodeNameToNodeUrl = new HashMap<>();

Review Comment:
   ```suggestion
       private volatile Map<String, URL> nodeNameToNodeUrl = Map.of();
   ```



##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/Await.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli;
+
+import java.time.Duration;
+import java.util.function.Supplier;
+
+/** Utility class to await some condition. */
+public final class Await {

Review Comment:
   Looks like this class is no longer needed



##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/NodeNameTest.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.commands;
+
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import java.time.Duration;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+/** Tests for ignite node commands with a provided node name. */
+public class NodeNameTest extends CliCommandTestNotInitializedIntegrationBase {
+
+    private String nodeName;
+
+    @BeforeEach
+    void setUp() throws InterruptedException {
+        nodeNameRegistry.startPullingUpdates("http://localhost:10301";);
+        // wait to pulling node names
+        waitForCondition(() -> !nodeNameRegistry.getAllNames().isEmpty(), 
Duration.ofSeconds(5).toMillis());

Review Comment:
   you need to wrap this call with `assertTrue` (`waitForCondition` returns a 
`boolean`)



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/NodeNameRegistry.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli;
+
+import static 
org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+
+import jakarta.inject.Singleton;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import 
org.apache.ignite.internal.cli.call.cluster.topology.PhysicalTopologyCall;
+import org.apache.ignite.internal.cli.core.call.UrlCallInput;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+import org.apache.ignite.rest.client.model.ClusterNode;
+import org.apache.ignite.rest.client.model.NodeMetadata;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Registry to get a node URL by a node name.
+ */
+@Singleton
+public class NodeNameRegistry {
+
+    private final IgniteLogger log = Loggers.forClass(getClass());
+    private volatile Map<String, URL> nodeNameToNodeUrl = new HashMap<>();
+    private ScheduledExecutorService executor;
+
+    /**
+     * Start pulling updates from a node.
+     *
+     * @param nodeUrl Node URL.
+     */
+    public synchronized void startPullingUpdates(String nodeUrl) {
+        stopPullingUpdates();
+        if (executor == null) {
+            executor = Executors.newSingleThreadScheduledExecutor(new 
NamedThreadFactory("NodeNameRegistry", log));
+            executor.scheduleWithFixedDelay(() -> updateNodeNames(nodeUrl), 0, 
5, TimeUnit.SECONDS);
+        }
+    }
+
+    /**
+     * Gets a node url by a provided node name.
+     */
+    public Optional<URL> getNodeUrl(String nodeName) {
+        return Optional.ofNullable(nodeNameToNodeUrl.get(nodeName));
+    }
+
+    /**
+     * Gets all node names.
+     */
+    public List<String> getAllNames() {
+        return new ArrayList<>(nodeNameToNodeUrl.keySet());
+    }
+
+    /**
+     * Stops pulling updates.
+     */
+    public synchronized void stopPullingUpdates() {
+        if (executor != null) {
+            shutdownAndAwaitTermination(executor, 3, TimeUnit.SECONDS);
+        }
+    }
+
+    private void updateNodeNames(String nodeUrl) {
+        PhysicalTopologyCall topologyCall = new PhysicalTopologyCall();
+        nodeNameToNodeUrl = topologyCall.execute(new 
UrlCallInput(nodeUrl)).body().stream().map(NodeNameRegistry::toNodeNameAndUrlPair)

Review Comment:
   I would suggest to reformat this code a little bit, because it is quite 
difficult to read now, for example:
   ```
   nodeNameToNodeUrl = topologyCall.execute(new UrlCallInput(nodeUrl))
           .body()
           .stream()
           .map(NodeNameRegistry::toNodeNameAndUrlPair)
           .filter(it -> it.url != null)
           .collect(Collectors.toUnmodifiableMap(it -> it.name, it -> it.url));
   ```        



##########
modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java:
##########
@@ -190,6 +204,17 @@ public void beforeNodeStop() {
             public boolean isStopped() {
                 return shutdownFuture.isDone();
             }
+
+            @Override
+            public void updateMetadata(NodeMetadata metadata) {
+                
cluster.updateMetadata(metadata).subscribeOn(scheduler).subscribe();
+                MembershipEvent membershipEvent = 
createUpdated(cluster.member(),
+                        
cluster.<NodeMetadata>metadata().map(METADATA_CODEC::serialize).orElse(null),
+                        METADATA_CODEC.serialize(metadata),
+                        System.currentTimeMillis()
+                );
+                topologyService.onMembershipEvent(membershipEvent);

Review Comment:
   I don't like the idea of emitting an artificial event here, because you 
serialize the metadata just to immediately desererialize it just to update the 
local member's metadata. Maybe we should simply add an `updateMetadata` method 
to the `ScaleCubeTopologyService`



##########
modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java:
##########
@@ -59,6 +68,12 @@ public class ScaleCubeClusterServiceFactory {
     /** Logger. */
     private static final IgniteLogger LOG = 
Loggers.forClass(ScaleCubeClusterServiceFactory.class);
 
+    /** Metadata codec. */
+    private static final JdkMetadataCodec METADATA_CODEC = new 
JdkMetadataCodec();
+
+    /** Scalecube cluster executor to update metadata.  */
+    private final Scheduler scheduler = 
scheduler("ScaleCubeClusterServiceFactory");

Review Comment:
   I still don't understand why do we need this scheduler. ScaleCube already 
dispatches the `updateMetadata` call on its internal executor



##########
modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeClusterServiceFactory.java:
##########
@@ -59,6 +68,12 @@ public class ScaleCubeClusterServiceFactory {
     /** Logger. */
     private static final IgniteLogger LOG = 
Loggers.forClass(ScaleCubeClusterServiceFactory.class);
 
+    /** Metadata codec. */
+    private static final JdkMetadataCodec METADATA_CODEC = new 
JdkMetadataCodec();

Review Comment:
   I would suggest using `MetadataCodec.INSTANCE`



##########
modules/network/src/test/java/org/apache/ignite/network/scalecube/MetadataSerDeTest.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network.scalecube;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import io.scalecube.cluster.metadata.JdkMetadataCodec;
+import java.nio.ByteBuffer;
+import org.apache.ignite.network.NodeMetadata;
+import org.junit.jupiter.api.Test;
+
+class MetadataSerDeTest {

Review Comment:
   I think this test is a bit redundant, since we are testing a 3rd party class 
here



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/NodeUrlMixin.java:
##########
@@ -17,23 +17,66 @@
 
 package org.apache.ignite.internal.cli.commands.node;
 
+import static 
org.apache.ignite.internal.cli.commands.OptionsConstants.NODE_NAME_DESC;
+import static 
org.apache.ignite.internal.cli.commands.OptionsConstants.NODE_NAME_OPTION;
+import static 
org.apache.ignite.internal.cli.commands.OptionsConstants.NODE_NAME_OPTION_SHORT;
 import static 
org.apache.ignite.internal.cli.commands.OptionsConstants.NODE_URL_DESC;
 import static 
org.apache.ignite.internal.cli.commands.OptionsConstants.NODE_URL_OPTION;
 import static 
org.apache.ignite.internal.cli.commands.OptionsConstants.URL_OPTION_SHORT;
 
+import jakarta.inject.Inject;
 import java.net.URL;
+import org.apache.ignite.internal.cli.NodeNameRegistry;
 import org.apache.ignite.internal.cli.core.converters.UrlConverter;
+import org.apache.ignite.internal.cli.deprecated.IgniteCliException;
+import org.jetbrains.annotations.Nullable;
+import picocli.CommandLine.ArgGroup;
 import picocli.CommandLine.Option;
 
 /**
  * Mixin class for node URL option.
  */
 public class NodeUrlMixin {
-    /** Node URL option. */
-    @Option(names = {URL_OPTION_SHORT, NODE_URL_OPTION}, description = 
NODE_URL_DESC, converter = UrlConverter.class)
-    private URL nodeUrl;
 
+    @ArgGroup
+    private Options options;
+
+    @Inject
+    NodeNameRegistry nodeNameRegistry;

Review Comment:
   Shall it be `private`?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/NodeNameRegistry.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli;
+
+import static 
org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+
+import jakarta.inject.Singleton;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import 
org.apache.ignite.internal.cli.call.cluster.topology.PhysicalTopologyCall;
+import org.apache.ignite.internal.cli.core.call.UrlCallInput;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+import org.apache.ignite.rest.client.model.ClusterNode;
+import org.apache.ignite.rest.client.model.NodeMetadata;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Registry to get a node URL by a node name.
+ */
+@Singleton
+public class NodeNameRegistry {
+
+    private final IgniteLogger log = Loggers.forClass(getClass());
+    private volatile Map<String, URL> nodeNameToNodeUrl = new HashMap<>();
+    private ScheduledExecutorService executor;
+
+    /**
+     * Start pulling updates from a node.
+     *
+     * @param nodeUrl Node URL.
+     */
+    public synchronized void startPullingUpdates(String nodeUrl) {
+        stopPullingUpdates();
+        if (executor == null) {
+            executor = Executors.newSingleThreadScheduledExecutor(new 
NamedThreadFactory("NodeNameRegistry", log));
+            executor.scheduleWithFixedDelay(() -> updateNodeNames(nodeUrl), 0, 
5, TimeUnit.SECONDS);
+        }
+    }
+
+    /**
+     * Gets a node url by a provided node name.
+     */
+    public Optional<URL> getNodeUrl(String nodeName) {
+        return Optional.ofNullable(nodeNameToNodeUrl.get(nodeName));
+    }
+
+    /**
+     * Gets all node names.
+     */
+    public List<String> getAllNames() {
+        return new ArrayList<>(nodeNameToNodeUrl.keySet());

Review Comment:
   You no longer need to copy this collection, you can return the `keySet` 
directly



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/converters/NodeNameOrUrlConverter.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.core.converters;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.regex.Pattern;
+import org.apache.ignite.internal.cli.NodeNameRegistry;
+import org.apache.ignite.internal.cli.commands.node.NodeUrl;
+import picocli.CommandLine;
+import picocli.CommandLine.TypeConversionException;
+
+/** Converter for {@link NodeUrl}. */
+public class NodeNameOrUrlConverter implements 
CommandLine.ITypeConverter<NodeUrl> {
+
+    private static final Pattern URL_PATTERN = Pattern.compile("^.*[/:].*");

Review Comment:
   ok



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/NodeNameRegistry.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli;
+
+import static 
org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+
+import jakarta.inject.Singleton;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import 
org.apache.ignite.internal.cli.call.cluster.topology.PhysicalTopologyCall;
+import org.apache.ignite.internal.cli.core.call.UrlCallInput;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+import org.apache.ignite.rest.client.model.ClusterNode;
+import org.apache.ignite.rest.client.model.NodeMetadata;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Registry to get a node URL by a node name.
+ */
+@Singleton
+public class NodeNameRegistry {
+
+    private final IgniteLogger log = Loggers.forClass(getClass());
+    private volatile Map<String, URL> nodeNameToNodeUrl = new HashMap<>();
+    private ScheduledExecutorService executor;
+
+    /**
+     * Start pulling updates from a node.
+     *
+     * @param nodeUrl Node URL.
+     */
+    public synchronized void startPullingUpdates(String nodeUrl) {
+        stopPullingUpdates();
+        if (executor == null) {
+            executor = Executors.newSingleThreadScheduledExecutor(new 
NamedThreadFactory("NodeNameRegistry", log));
+            executor.scheduleWithFixedDelay(() -> updateNodeNames(nodeUrl), 0, 
5, TimeUnit.SECONDS);
+        }
+    }
+
+    /**
+     * Gets a node url by a provided node name.
+     */
+    public Optional<URL> getNodeUrl(String nodeName) {
+        return Optional.ofNullable(nodeNameToNodeUrl.get(nodeName));
+    }
+
+    /**
+     * Gets all node names.
+     */
+    public List<String> getAllNames() {
+        return new ArrayList<>(nodeNameToNodeUrl.keySet());
+    }
+
+    /**
+     * Stops pulling updates.
+     */
+    public synchronized void stopPullingUpdates() {
+        if (executor != null) {
+            shutdownAndAwaitTermination(executor, 3, TimeUnit.SECONDS);

Review Comment:
   You used to assign `null` to the executor, why did you remove that?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/OptionsConstants.java:
##########
@@ -47,4 +50,13 @@ public class OptionsConstants {
 
     /** URL option short name. */
     public static final String URL_OPTION_SHORT = "-u";
+
+    /** Node name option long name. */
+    public static final String NODE_NAME_OPTION = "--node-name";
+
+    /** Node name option short name. */
+    public static final String NODE_NAME_OPTION_SHORT = "-n";
+
+    /** Node name option description. */
+    public static final String NODE_NAME_DESC = "Name of ignite node";

Review Comment:
   ```suggestion
       public static final String NODE_NAME_DESC = "Name of an Ignite node";
   ```



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/NodeNameRegistry.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli;
+
+import static 
org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+
+import jakarta.inject.Singleton;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+import 
org.apache.ignite.internal.cli.call.cluster.topology.PhysicalTopologyCall;
+import org.apache.ignite.internal.cli.core.call.UrlCallInput;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+import org.apache.ignite.rest.client.model.ClusterNode;
+import org.apache.ignite.rest.client.model.NodeMetadata;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Registry to get a node URL by a node name.
+ */
+@Singleton
+public class NodeNameRegistry {
+
+    private final IgniteLogger log = Loggers.forClass(getClass());
+    private volatile Map<String, URL> nodeNameToNodeUrl = new HashMap<>();
+    private ScheduledExecutorService executor;
+
+    /**
+     * Start pulling updates from a node.
+     *
+     * @param nodeUrl Node URL.
+     */
+    public synchronized void startPullingUpdates(String nodeUrl) {
+        stopPullingUpdates();
+        if (executor == null) {
+            executor = Executors.newSingleThreadScheduledExecutor(new 
NamedThreadFactory("NodeNameRegistry", log));
+            executor.scheduleWithFixedDelay(() -> updateNodeNames(nodeUrl), 0, 
5, TimeUnit.SECONDS);
+        }
+    }
+
+    /**
+     * Gets a node url by a provided node name.
+     */
+    public Optional<URL> getNodeUrl(String nodeName) {
+        return Optional.ofNullable(nodeNameToNodeUrl.get(nodeName));
+    }
+
+    /**
+     * Gets all node names.
+     */
+    public List<String> getAllNames() {
+        return new ArrayList<>(nodeNameToNodeUrl.keySet());
+    }
+
+    /**
+     * Stops pulling updates.
+     */
+    public synchronized void stopPullingUpdates() {
+        if (executor != null) {
+            shutdownAndAwaitTermination(executor, 3, TimeUnit.SECONDS);
+        }
+    }
+
+    private void updateNodeNames(String nodeUrl) {
+        PhysicalTopologyCall topologyCall = new PhysicalTopologyCall();
+        nodeNameToNodeUrl = topologyCall.execute(new 
UrlCallInput(nodeUrl)).body().stream().map(NodeNameRegistry::toNodeNameAndUrlPair)
+                .filter(it -> it.url != null).collect(Collectors.toMap(it -> 
it.name, it -> it.url));
+    }
+
+    private static NodeNameAndUrlPair toNodeNameAndUrlPair(ClusterNode node) {
+        return new NodeNameAndUrlPair(node.getName(), 
urlFromClusterNode(node.getMetadata()));
+    }
+
+    @Nullable
+    private static URL urlFromClusterNode(NodeMetadata metadata) {
+        if (metadata == null) {
+            return null;
+        }
+        try {
+            return new URL("http://"; + metadata.getRestHost() + ":" + 
metadata.getRestPort());
+        } catch (Exception e) {
+            return null;

Review Comment:
   Shall we at least log the exception?



##########
modules/network/src/main/java/org/apache/ignite/network/scalecube/NodeMetadataDeserializer.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network.scalecube;
+
+import io.scalecube.cluster.metadata.JdkMetadataCodec;
+import java.nio.ByteBuffer;
+import org.apache.ignite.network.NodeMetadata;
+import org.jetbrains.annotations.Nullable;
+
+/** Deserializer for {@link org.apache.ignite.network.NodeMetadata}. */
+public class NodeMetadataDeserializer {

Review Comment:
   Why do you need this class? Can we use `JdkMetadataCodec` directly?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to