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

ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 26400f6af94 IGNITE-27307 Migration Tools: flush logs on error in 
Ignite3ClusterContainer (#7214)
26400f6af94 is described below

commit 26400f6af9498bc98df2071450da52d856156829
Author: Tiago Marques Godinho <[email protected]>
AuthorDate: Thu Dec 11 14:08:39 2025 +0000

    IGNITE-27307 Migration Tools: flush logs on error in 
Ignite3ClusterContainer (#7214)
    
    * Close `Ignite3ClusterContainer` container resources if there's an error 
during start.
    * Add a label to the `Ignite3ClusterContainer` so that it's easier to 
identify the source of the cluster logs.
---
 .../tests/e2e/ErrorHandlingTest.java               |  3 +-
 .../tests/e2e/IgniteClientCredentialsTest.java     |  4 +-
 .../tests/bases/MigrationTestBase.java             |  3 +-
 .../tests/containers/Ignite3ClusterContainer.java  | 63 ++++++++++++----------
 4 files changed, 43 insertions(+), 30 deletions(-)

diff --git 
a/migration-tools/modules/e2e-ai3-tests/src/integrationTest/java/org/apache/ignite/migrationtools/tests/e2e/ErrorHandlingTest.java
 
b/migration-tools/modules/e2e-ai3-tests/src/integrationTest/java/org/apache/ignite/migrationtools/tests/e2e/ErrorHandlingTest.java
index 5d6c7e024eb..5195eafb118 100644
--- 
a/migration-tools/modules/e2e-ai3-tests/src/integrationTest/java/org/apache/ignite/migrationtools/tests/e2e/ErrorHandlingTest.java
+++ 
b/migration-tools/modules/e2e-ai3-tests/src/integrationTest/java/org/apache/ignite/migrationtools/tests/e2e/ErrorHandlingTest.java
@@ -40,7 +40,8 @@ public class ErrorHandlingTest {
     private static final Network network = Network.newNetwork();
 
     @Container
-    private static final Ignite3ClusterContainer AI3_CLUSTER = new 
Ignite3ClusterContainer(network);
+    private static final Ignite3ClusterContainer AI3_CLUSTER = new 
Ignite3ClusterContainer(network)
+            .withLabel(ErrorHandlingTest.class.getSimpleName());
 
     @Container
     private static final MigrationToolsContainer migrationToolsContainer = new 
MigrationToolsContainer(network);
diff --git 
a/migration-tools/modules/e2e-ai3-tests/src/integrationTest/java/org/apache/ignite/migrationtools/tests/e2e/IgniteClientCredentialsTest.java
 
b/migration-tools/modules/e2e-ai3-tests/src/integrationTest/java/org/apache/ignite/migrationtools/tests/e2e/IgniteClientCredentialsTest.java
index 8a3bb533652..67abcc12a38 100644
--- 
a/migration-tools/modules/e2e-ai3-tests/src/integrationTest/java/org/apache/ignite/migrationtools/tests/e2e/IgniteClientCredentialsTest.java
+++ 
b/migration-tools/modules/e2e-ai3-tests/src/integrationTest/java/org/apache/ignite/migrationtools/tests/e2e/IgniteClientCredentialsTest.java
@@ -45,7 +45,9 @@ public class IgniteClientCredentialsTest {
     private static final Network network = Network.newNetwork();
 
     @Container
-    private static final Ignite3ClusterContainer AI3_CLUSTER = new 
Ignite3ClusterContainer(network).withCredentials(credentials);
+    private static final Ignite3ClusterContainer AI3_CLUSTER = new 
Ignite3ClusterContainer(network)
+            .withCredentials(credentials)
+            .withLabel(IgniteClientCredentialsTest.class.getSimpleName());
 
     @Container
     private static final MigrationToolsContainer migrationToolsContainer = new 
MigrationToolsContainer(network);
diff --git 
a/migration-tools/modules/migration-tools-commons-tests/src/main/java/org/apache/ignite/migrationtools/tests/bases/MigrationTestBase.java
 
b/migration-tools/modules/migration-tools-commons-tests/src/main/java/org/apache/ignite/migrationtools/tests/bases/MigrationTestBase.java
index 930c87784c2..835c911151e 100644
--- 
a/migration-tools/modules/migration-tools-commons-tests/src/main/java/org/apache/ignite/migrationtools/tests/bases/MigrationTestBase.java
+++ 
b/migration-tools/modules/migration-tools-commons-tests/src/main/java/org/apache/ignite/migrationtools/tests/bases/MigrationTestBase.java
@@ -69,7 +69,8 @@ public class MigrationTestBase {
 
     // TODO: Add a cluster instead of a single instance. Create a ignite stuff 
perhaps.
     @Container
-    protected static final Ignite3ClusterContainer AI3_CLUSTER = new 
Ignite3ClusterContainer(network);
+    protected static final Ignite3ClusterContainer AI3_CLUSTER = new 
Ignite3ClusterContainer(network)
+            .withLabel(MigrationTestBase.class.getSimpleName());
 
     @Container
     protected static final MigrationToolsContainer MIGRATION_TOOLS_CONTAINER = 
new MigrationToolsContainer(network);
diff --git 
a/migration-tools/modules/migration-tools-commons-tests/src/main/java/org/apache/ignite/migrationtools/tests/containers/Ignite3ClusterContainer.java
 
b/migration-tools/modules/migration-tools-commons-tests/src/main/java/org/apache/ignite/migrationtools/tests/containers/Ignite3ClusterContainer.java
index 3f15e94915d..09f223a5041 100644
--- 
a/migration-tools/modules/migration-tools-commons-tests/src/main/java/org/apache/ignite/migrationtools/tests/containers/Ignite3ClusterContainer.java
+++ 
b/migration-tools/modules/migration-tools-commons-tests/src/main/java/org/apache/ignite/migrationtools/tests/containers/Ignite3ClusterContainer.java
@@ -27,7 +27,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
-import java.util.function.Consumer;
 import java.util.stream.Stream;
 import org.apache.ignite3.client.IgniteClient;
 import org.apache.logging.log4j.LogManager;
@@ -47,14 +46,15 @@ public class Ignite3ClusterContainer implements Startable {
 
     private static final Logger LOGGER = 
LogManager.getLogger(Ignite3ClusterContainer.class);
 
-    public final Network network;
-
-    public final GenericContainer node;
+    private final GenericContainer<?> node;
 
     private BufferedWriter logWriter;
 
     private @Nullable Map.Entry<String, String> credentials;
 
+    @Nullable
+    private String label = null;
+
     public Ignite3ClusterContainer() {
         this(Network.newNetwork());
     }
@@ -65,7 +65,6 @@ public class Ignite3ClusterContainer implements Startable {
      * @param network The network to deploy the containers on.
      */
     public Ignite3ClusterContainer(Network network) {
-        this.network = network;
         String imageName = dockerImageName();
         this.node = new GenericContainer(imageName)
                 .withNetwork(network)
@@ -116,38 +115,47 @@ public class Ignite3ClusterContainer implements Startable 
{
         return this;
     }
 
+    /**
+     * Add a label to the cluster so that container assets, most notably logs, 
are easily identifiable.
+     *
+     * @param label Label.
+     * @return The cluster container.
+     */
+    public Ignite3ClusterContainer withLabel(String label) {
+        this.label = label;
+        this.node.withLabel("org.apache.ignite.migrationtools.label",  label);
+        return this;
+    }
+
     @Override
     public void start() {
         this.node.start();
 
         Path parentFolder = Path.of("build/test-logs");
-        Path logFilePath = parentFolder.resolve("ignite-3-" + 
this.node.getContainerId().substring(0, 8));
+        String label = (this.label == null) ? "" : "-" + this.label;
+        Path logFilePath = parentFolder.resolve("ignite-3" + label + "-" + 
this.node.getContainerId().substring(0, 8));
         CountDownLatch startupLatch = new CountDownLatch(1);
 
         try {
             Files.createDirectories(parentFolder);
             this.logWriter = Files.newBufferedWriter(logFilePath);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-        this.node.followOutput((Consumer<OutputFrame>) frame -> {
-            var type = frame.getType();
-            if (type == OutputFrame.OutputType.STDOUT || type == 
OutputFrame.OutputType.STDERR) {
-                String msg = frame.getUtf8String();
-                try {
-                    this.logWriter.write(msg);
-                } catch (IOException e) {
-                    LOGGER.error("Error writing cluster logs to file: ", e);
-                }
 
-                if (msg.contains("[IgniteServerImpl] Apache Ignite started 
successfully!")) {
-                    startupLatch.countDown();
+            this.node.followOutput(frame -> {
+                var type = frame.getType();
+                if (type == OutputFrame.OutputType.STDOUT || type == 
OutputFrame.OutputType.STDERR) {
+                    String msg = frame.getUtf8String();
+                    try {
+                        this.logWriter.write(msg);
+                    } catch (IOException e) {
+                        LOGGER.error("Error writing cluster logs to file: ", 
e);
+                    }
+
+                    if (msg.contains("[IgniteServerImpl] Apache Ignite started 
successfully!")) {
+                        startupLatch.countDown();
+                    }
                 }
-            }
-        });
+            });
 
-        Container.ExecResult execRes = null;
-        try {
             List<String> args = new ArrayList<>(
                     List.of(
                             "/opt/ignite3cli/bin/ignite3",
@@ -166,7 +174,7 @@ public class Ignite3ClusterContainer implements Startable {
                 args.add(credentialsArg);
             }
 
-            execRes = this.node.execInContainer(args.toArray(String[]::new));
+            Container.ExecResult execRes = 
this.node.execInContainer(args.toArray(String[]::new));
 
             if (execRes.getExitCode() != 0) {
                 throw new RuntimeException("Could not init cluster: " + 
execRes.getStderr());
@@ -176,8 +184,9 @@ public class Ignite3ClusterContainer implements Startable {
             if (!started) {
                 throw new RuntimeException("Failed to catch cluster started 
signal after cluster init");
             }
-        } catch (IOException | InterruptedException e) {
-            throw new RuntimeException(e);
+        } catch (IOException | InterruptedException | RuntimeException ex) {
+            stop();
+            throw (ex instanceof RuntimeException ? (RuntimeException) ex : 
new RuntimeException(ex));
         }
     }
 

Reply via email to