This is an automated email from the ASF dual-hosted git repository.

anton-vinogradov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new f99457944c7 IGNITE-29305 Start and stop the SSL factory registry with 
the node's component lifecycle (#13851)
f99457944c7 is described below

commit f99457944c713249771c778ea22541d0d7195058
Author: Anton Vinogradov <[email protected]>
AuthorDate: Wed Nov 18 14:08:20 2026 +0300

    IGNITE-29305 Start and stop the SSL factory registry with the node's 
component lifecycle (#13851)
---
 .../ignite/internal/GridKernalContextImpl.java     |  7 ++-
 .../org/apache/ignite/internal/IgniteKernal.java   |  5 +-
 .../processors/ssl/SslFactoryRegistry.java         | 23 +++++----
 .../processors/ssl/SslFactoryRegistryTest.java     | 55 ++++++++++++----------
 .../ignite/ssl/SslCertificateHotReloadTest.java    | 25 ++++++++++
 .../junits/GridTestKernalContext.java              |  4 +-
 .../ignite/testframework/junits/IgniteMock.java    |  2 +-
 7 files changed, 74 insertions(+), 47 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index 8718e51a231..2778a85ee73 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -266,7 +266,7 @@ public class GridKernalContextImpl implements 
GridKernalContext, Externalizable
 
     /** */
     @GridToStringExclude
-    private final SslFactoryRegistry sslFactories = new SslFactoryRegistry();
+    private SslFactoryRegistry sslFactories;
 
     /** */
     @GridToStringInclude
@@ -451,6 +451,8 @@ public class GridKernalContextImpl implements 
GridKernalContext, Externalizable
 
         defragMgr = new IgniteDefragmentationImpl(this);
 
+        sslFactories = new SslFactoryRegistry(this);
+
         try {
             spring = SPRING.create(false);
         }
@@ -601,7 +603,8 @@ public class GridKernalContextImpl implements 
GridKernalContext, Externalizable
             indexProc = (IndexProcessor)comp;
         else if (!(comp instanceof DiscoveryNodeValidationProcessor
             || comp instanceof PlatformPluginProcessor
-            || comp instanceof QueryEngine))
+            || comp instanceof QueryEngine
+            || comp instanceof SslFactoryRegistry))
             assert (comp instanceof GridPluginComponent) : "Unknown manager 
class: " + comp.getClass();
 
         if (addToList)
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java 
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 2fdad26a97f..c5111575d9e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -1085,6 +1085,7 @@ public class IgniteKernal implements IgniteEx, 
Externalizable {
                 startProcessor(new GridTaskProcessor(ctx));
                 startProcessor((GridProcessor)SCHEDULE.createOptional(ctx));
                 startProcessor(createComponent(IgniteRestProcessor.class, 
ctx));
+                startProcessor(ctx.ssl());
                 startProcessor(new DataStreamProcessor(ctx));
                 startProcessor(new GridContinuousProcessor(ctx));
                 startProcessor(new DataStructuresProcessor(ctx));
@@ -1243,8 +1244,6 @@ public class IgniteKernal implements IgniteEx, 
Externalizable {
                 }
             }
 
-            ctx.ssl().start(ctx);
-
             // Start plugins.
             for (PluginProvider<?> provider : ctx.plugins().allProviders())
                 provider.onIgniteStart();
@@ -1724,8 +1723,6 @@ public class IgniteKernal implements IgniteEx, 
Externalizable {
         GridKernalGateway gw = this.gw.get();
 
         if (stopGuard.compareAndSet(false, true)) {
-            ctx.ssl().stop();
-
             // Only one thread is allowed to perform stop sequence.
             boolean firstStop = false;
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
index aa6b489f5a8..b23a170f33d 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistry.java
@@ -29,11 +29,10 @@ import java.util.concurrent.atomic.AtomicLong;
 import javax.cache.configuration.Factory;
 import javax.net.ssl.SSLContext;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.metric.MetricRegistryImpl;
 import 
org.apache.ignite.internal.thread.context.function.OperationContextAwareRunnable;
-import org.apache.ignite.logger.NullLogger;
 import org.apache.ignite.ssl.AbstractSslContextFactory;
 import org.jetbrains.annotations.Nullable;
 
@@ -42,7 +41,7 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static 
org.apache.ignite.internal.thread.pool.IgniteScheduledThreadPoolExecutor.newSingleThreadScheduledExecutor;
 
 /** SSL factories used by running transports. */
-public class SslFactoryRegistry {
+public class SslFactoryRegistry extends GridProcessorAdapter {
     /** */
     private static final long CHECK_PERIOD = HOURS.toMillis(1);
 
@@ -52,15 +51,17 @@ public class SslFactoryRegistry {
     /** */
     private volatile ScheduledExecutorService executor;
 
-    /** Logs nothing until the registry starts. */
-    private volatile IgniteLogger log = new NullLogger();
-
     /** */
     private final AtomicLong manualReloadAttempts = new AtomicLong();
 
     /** */
     private final AtomicLong automaticHotReloadAttempts = new AtomicLong();
 
+    /** @param ctx Kernal context. */
+    public SslFactoryRegistry(GridKernalContext ctx) {
+        super(ctx);
+    }
+
     /** */
     public synchronized void register(String transport, Factory<SSLContext> 
factory) {
         for (int i = 0; i < factories.size(); i++) {
@@ -86,8 +87,8 @@ public class SslFactoryRegistry {
         return res;
     }
 
-    /** */
-    public void start(GridKernalContext ctx) {
+    /** {@inheritDoc} */
+    @Override public void onKernalStart(boolean active) {
         MetricRegistryImpl metrics = ctx.metric().registry("ssl");
 
         metrics.register("ConsecutiveHotReloadFailures", 
this::consecutiveHotReloadFailures,
@@ -96,8 +97,6 @@ public class SslFactoryRegistry {
         metrics.register("AutomaticHotReloadAttempts", 
automaticHotReloadAttempts::get,
             "Number of automatic hot reload attempts.");
 
-        log = ctx.log(getClass());
-
         boolean hotReload = false;
 
         for (RegisteredFactory registered : factories) {
@@ -140,8 +139,8 @@ public class SslFactoryRegistry {
         }
     }
 
-    /** */
-    public void stop() {
+    /** {@inheritDoc} */
+    @Override public void onKernalStop(boolean cancel) {
         if (executor != null)
             executor.shutdownNow();
     }
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
index 4bf12cde354..9d9b858a338 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/ssl/SslFactoryRegistryTest.java
@@ -88,8 +88,8 @@ public class SslFactoryRegistryTest {
     /** Upper bound for waiting for an event that must happen. */
     private static final long TIMEOUT_MS = 30_000;
 
-    /** */
-    private final SslFactoryRegistry registry = new SslFactoryRegistry();
+    /** Created in the setup, after the logger stub. */
+    private SslFactoryRegistry registry;
 
     /** */
     private final SslContextFactory factory = mock(SslContextFactory.class);
@@ -141,6 +141,8 @@ public class SslFactoryRegistryTest {
         when(metricMgr.registry("ssl")).thenReturn(metrics);
         when(ctx.log(SslFactoryRegistry.class)).thenReturn(new NullLogger());
 
+        registry = new SslFactoryRegistry(ctx);
+
         when(executor.scheduleWithFixedDelay(any(Runnable.class), anyLong(), 
anyLong(), eq(MILLISECONDS))).thenAnswer(call -> {
             check = call.getArgument(0);
 
@@ -156,7 +158,7 @@ public class SslFactoryRegistryTest {
     @After
     public void tearDown() throws Exception {
         try {
-            registry.stop();
+            registry.onKernalStop(true);
         }
         finally {
             executorFactory.close();
@@ -190,7 +192,7 @@ public class SslFactoryRegistryTest {
     public void testDisabledFactoryDoesNotStartHotReload() throws Exception {
         writeFreshCertificates(keys);
         registerTransport("communication", factory(keys));
-        registry.start(ctx);
+        registry.onKernalStart(true);
 
         executorFactory.verifyNoInteractions();
         assertEquals(0, failures());
@@ -212,7 +214,7 @@ public class SslFactoryRegistryTest {
         registerTransport("communication", communication);
         registerTransport("discovery", communication);
         registerTransport("client connector", clientConnector);
-        registry.start(ctx);
+        registry.onKernalStart(true);
 
         long prevTime = communication.getHotReloadTime();
 
@@ -239,7 +241,7 @@ public class SslFactoryRegistryTest {
         clientConnector.setHotReloadEnabled(true);
         registerTransport("communication", communication);
         registerTransport("client connector", clientConnector);
-        registry.start(ctx);
+        registry.onKernalStart(true);
 
         long prevTime = communication.getHotReloadTime();
 
@@ -265,7 +267,7 @@ public class SslFactoryRegistryTest {
         save(authority.trustStore(), keys);
         communication.setHotReloadEnabled(true);
         registerTransport("communication", communication);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         check.run();
 
         assertEquals(1, logged.size());
@@ -291,7 +293,7 @@ public class SslFactoryRegistryTest {
         writeDueCertificates(keys);
         communication.setHotReloadEnabled(true);
         registerTransport("communication", communication);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         Files.delete(keys);
 
         verify(executor).scheduleWithFixedDelay(any(Runnable.class), eq(0L), 
eq(HOURS.toMillis(1)), eq(MILLISECONDS));
@@ -324,7 +326,7 @@ public class SslFactoryRegistryTest {
         registry.register("communication", factory);
 
         try (Scope ignored = OperationContext.set(reqId, "startup")) {
-            registry.start(ctx);
+            registry.onKernalStart(true);
         }
 
         assertNull(reloadReqId.get(TIMEOUT_MS, MILLISECONDS));
@@ -348,7 +350,7 @@ public class SslFactoryRegistryTest {
         clientConnector.setHotReloadEnabled(true);
         registry.register("communication", factory);
         registerTransport("client connector", clientConnector);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         writeFreshCertificates(keys);
         check.run();
 
@@ -371,7 +373,7 @@ public class SslFactoryRegistryTest {
         writeDueCertificates(keys);
         communication.setHotReloadEnabled(true);
         registerTransport("communication", communication);
-        registry.start(ctx);
+        registry.onKernalStart(true);
 
         long due = communication.getHotReloadTime();
 
@@ -407,7 +409,7 @@ public class SslFactoryRegistryTest {
         writeDueCertificates(keys);
         communication.setHotReloadEnabled(true);
         registerTransport("communication", communication);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         Files.delete(keys);
         check.run();
 
@@ -438,7 +440,7 @@ public class SslFactoryRegistryTest {
         writeDueCertificates(keys);
         communication.setHotReloadEnabled(true);
         registerTransport("communication", communication);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         check.run();
 
         assertEquals(1, failures());
@@ -483,7 +485,7 @@ public class SslFactoryRegistryTest {
 
         writeFreshCertificates(keys);
         registerTransport("communication", communication);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         registry.reload(communication);
 
         assertEquals(1, metric("ManualReloadAttempts"));
@@ -561,7 +563,7 @@ public class SslFactoryRegistryTest {
         AbstractSslContextFactory factory = 
mock(AbstractSslContextFactory.class);
 
         registry.register("client connector", factory);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         registry.reload(factory);
 
         verify(factory).init();
@@ -579,7 +581,7 @@ public class SslFactoryRegistryTest {
         writeDueCertificates(keys);
         communication.setHotReloadEnabled(true);
         registerTransport("communication", communication);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         Files.delete(keys);
         check.run();
 
@@ -611,7 +613,7 @@ public class SslFactoryRegistryTest {
         clientConnector.setHotReloadEnabled(true);
         registry.register("communication", factory);
         registerTransport("client connector", clientConnector);
-        registry.start(ctx);
+        registry.onKernalStart(true);
 
         long prevTime = clientConnector.getHotReloadTime();
 
@@ -646,7 +648,7 @@ public class SslFactoryRegistryTest {
         writeDueCertificates(keys);
         communication.setHotReloadEnabled(true);
         registerTransport("communication", communication);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         Files.delete(keys);
 
         when(executor.isShutdown()).thenAnswer(call -> {
@@ -707,7 +709,7 @@ public class SslFactoryRegistryTest {
         clientConnector.setHotReloadEnabled(true);
         registerTransport("communication", communication);
         registerTransport("client connector", clientConnector);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         check.run();
 
         assertEquals(1, failures());
@@ -760,11 +762,11 @@ public class SslFactoryRegistryTest {
         registry.register("communication", factory);
 
         try {
-            registry.start(ctx);
+            registry.onKernalStart(true);
 
             assertTrue(attemptStarted.await(TIMEOUT_MS, MILLISECONDS));
 
-            runAsync(registry::stop).get(TIMEOUT_MS);
+            runAsync(() -> registry.onKernalStop(true)).get(TIMEOUT_MS);
 
             assertTrue(attemptInterrupted.await(TIMEOUT_MS, MILLISECONDS));
         }
@@ -790,7 +792,7 @@ public class SslFactoryRegistryTest {
         }).when(factory).init();
 
         registry.register("communication", factory);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         check.run();
 
         assertEquals(0, failures());
@@ -823,19 +825,20 @@ public class SslFactoryRegistryTest {
 
         registry.register("communication", factory);
         registry.register("client connector", clientConnector);
-        registry.start(ctx);
+        registry.onKernalStart(true);
         check.run();
 
         assertEquals(1, loads.get());
     }
 
-    /** Makes the registry log to a listener and returns the hot reload lines 
it logs at info level and above, in order. */
+    /** Replaces the registry with one that logs to a listener and returns its 
hot reload lines at info level and above. */
     private List<String> captureLog() {
         return captureLog(false);
     }
 
     /**
-     * Makes the registry log to a listener and returns the hot reload lines 
it logs, in order.
+     * Replaces the registry with one that logs to a listener and returns the 
hot reload lines it logs, in order.
+     * Tests call it before they register factories.
      *
      * @param debug Whether the registry logs debug lines too.
      */
@@ -849,6 +852,8 @@ public class SslFactoryRegistryTest {
         });
         when(ctx.log(SslFactoryRegistry.class)).thenReturn(log);
 
+        registry = new SslFactoryRegistry(ctx);
+
         return logged;
     }
 
diff --git 
a/modules/core/src/test/java/org/apache/ignite/ssl/SslCertificateHotReloadTest.java
 
b/modules/core/src/test/java/org/apache/ignite/ssl/SslCertificateHotReloadTest.java
index 1b369d56303..98e0e0bb7d3 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/ssl/SslCertificateHotReloadTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/ssl/SslCertificateHotReloadTest.java
@@ -19,12 +19,14 @@ package org.apache.ignite.ssl;
 
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.util.List;
 import javax.net.ssl.SSLContext;
 import org.apache.ignite.Ignition;
 import org.apache.ignite.client.IgniteClient;
 import org.apache.ignite.client.SslMode;
 import org.apache.ignite.configuration.ClientConfiguration;
 import org.apache.ignite.configuration.ClientConnectorConfiguration;
+import org.apache.ignite.internal.GridComponent;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.spi.metric.LongMetric;
@@ -181,6 +183,29 @@ public class SslCertificateHotReloadTest extends 
GridCommonAbstractTest {
         }
     }
 
+    /**
+     * Given: a node with the client connector and REST, which stop their 
servers in their own {@code onKernalStop}.
+     * When: the node starts its components.
+     * Then: the SSL factory registry comes after both, so the node, which 
stops components in reverse order,
+     *     stops hot reload before them.
+     */
+    @Test
+    public void testHotReloadStopsBeforeClientConnectorAndRest() throws 
Exception {
+        IgniteEx node = startGrid(0);
+
+        try {
+            List<GridComponent> comps = node.context().components();
+            int clientConnector = 
comps.indexOf(node.context().clientListener());
+            int rest = comps.indexOf(node.context().rest());
+
+            assertTrue(clientConnector >= 0 && rest >= 0);
+            assertTrue(comps.indexOf(node.context().ssl()) > 
Math.max(clientConnector, rest));
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
     /**
      * Creates a client connector configuration that uses the given factory 
and requires client certificates.
      * The connector uses this factory instead of the node factory.
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
 
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
index c9064f1c1cc..730a1634fad 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridTestKernalContext.java
@@ -68,7 +68,7 @@ public class GridTestKernalContext extends 
GridKernalContextImpl {
     public GridTestKernalContext(IgniteLogger log, IgniteConfiguration cfg) {
         super(new GridLoggerProxy(log, null, null, null),
                 new IgniteKernal(null),
-                cfg,
+                cfg.setGridLogger(log),
                 new GridKernalGatewayImpl(null),
                 cfg.getPluginProviders() != null && 
cfg.getPluginProviders().length > 0 ?
                     Arrays.asList(cfg.getPluginProviders()) : 
U.allPluginProviders(),
@@ -81,8 +81,6 @@ public class GridTestKernalContext extends 
GridKernalContextImpl {
         GridTestUtils.setFieldValue(grid(), "ctx", this);
         GridTestUtils.setFieldValue(grid(), "distrOpCtx", new 
DistributedOperationContext());
 
-        config().setGridLogger(log);
-
         if (cfg.getMetricExporterSpi() == null || 
cfg.getMetricExporterSpi().length == 0)
             cfg.setMetricExporterSpi(new NoopMetricExporterSpi());
 
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
 
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
index 8794a212f0d..69c52547bca 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
@@ -159,7 +159,7 @@ public class IgniteMock implements IgniteEx {
         try {
             kernalCtx = new StandaloneGridKernalContext(new 
GridTestLog4jLogger(), null) {
                 /** */
-                private final SslFactoryRegistry ssl = new 
SslFactoryRegistry();
+                private final SslFactoryRegistry ssl = new 
SslFactoryRegistry(this);
 
                 /** {@inheritDoc} */
                 @Override public SslFactoryRegistry ssl() {

Reply via email to