This is an automated email from the ASF dual-hosted git repository.
apkhmv 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 dea9e4068f IGNITE-22254 Cluster initialization fails when event log is
configured (#3775)
dea9e4068f is described below
commit dea9e4068f067762a1abc909270b755074faf7d4
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Thu May 16 17:22:16 2024 +0300
IGNITE-22254 Cluster initialization fails when event log is configured
(#3775)
* IGNITE-22254 Cluster initialization fails when event log is configured
* Register types in the static initialization block
---
.../src/testFixtures/resources/log4j2-test.xml | 2 +-
modules/eventlog/build.gradle | 6 ++
.../ignite/internal/eventlog/ItEventLogTest.java | 104 +++++++++++++++++++++
.../internal/eventlog/api/IgniteEventType.java | 6 ++
.../apache/ignite/internal/app/IgnitionImpl.java | 2 +
5 files changed, 119 insertions(+), 1 deletion(-)
diff --git a/modules/core/src/testFixtures/resources/log4j2-test.xml
b/modules/core/src/testFixtures/resources/log4j2-test.xml
index 15cf265f10..241c0a91d9 100755
--- a/modules/core/src/testFixtures/resources/log4j2-test.xml
+++ b/modules/core/src/testFixtures/resources/log4j2-test.xml
@@ -51,7 +51,7 @@
<RollingFile name="EVENTLOG_FILE"
append="true"
fileName="build/event.log"
- filePattern="build/event.log">
+ filePattern="build/event.log.%i">
<PatternLayout pattern="%m%n"/>
<Policies>
<OnStartupTriggeringPolicy/>
diff --git a/modules/eventlog/build.gradle b/modules/eventlog/build.gradle
index 71d665a02c..d61214477e 100644
--- a/modules/eventlog/build.gradle
+++ b/modules/eventlog/build.gradle
@@ -42,13 +42,19 @@ dependencies {
integrationTestAnnotationProcessor
project(':ignite-configuration-annotation-processor')
+ integrationTestImplementation libs.awaitility
integrationTestImplementation testFixtures(project(':ignite-runner'))
integrationTestImplementation testFixtures(project(':ignite-core'))
integrationTestImplementation
testFixtures(project(':ignite-configuration'))
integrationTestImplementation project(':ignite-api')
integrationTestImplementation project(':ignite-configuration')
+ integrationTestImplementation project(':ignite-client')
}
test {
systemProperty "buildDirPath", project.buildDir.path
}
+
+integrationTest {
+ systemProperty "buildDirPath", project.buildDir.path
+}
diff --git
a/modules/eventlog/src/integrationTest/java/org/apache/ignite/internal/eventlog/ItEventLogTest.java
b/modules/eventlog/src/integrationTest/java/org/apache/ignite/internal/eventlog/ItEventLogTest.java
new file mode 100644
index 0000000000..e662a7eee1
--- /dev/null
+++
b/modules/eventlog/src/integrationTest/java/org/apache/ignite/internal/eventlog/ItEventLogTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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.eventlog;
+
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.matchesRegex;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.client.BasicAuthenticator;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+class ItEventLogTest extends ClusterPerClassIntegrationTest {
+ private static final String PROVIDER_NAME = "basic";
+
+ private static final String USERNAME = "admin";
+
+ private static final String PASSWORD = "password";
+
+ private static Path eventlogPath;
+
+ @BeforeAll
+ static void captureEventLogPath() {
+ String buildDirPath = System.getProperty("buildDirPath");
+ eventlogPath = Path.of(buildDirPath).resolve("event.log");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 1;
+ }
+
+ @Override
+ protected void configureInitParameters(InitParametersBuilder builder) {
+ String securityConfiguration = "security {\n"
+ + " enabled:true,\n"
+ + " authentication.providers." + PROVIDER_NAME + ":{\n"
+ + " type:basic, users." + USERNAME + ".password:" +
PASSWORD + "\n"
+ + " }\n},\n";
+
+ String eventLog = "eventlog {\n"
+ + " sinks.logSink.channel: testChannel,\n"
+ + " channels.testChannel.events: [USER_AUTHENTICATED],\n"
+ + "}\n";
+
+ builder.clusterConfiguration(securityConfiguration + eventLog);
+ }
+
+ @Test
+ void logsToFile() throws Exception {
+ // Given the event log is initially empty.
+ assertThat(readEventLog(), is(empty()));
+
+ // When client is connected.
+ BasicAuthenticator authenticator =
BasicAuthenticator.builder().username(USERNAME).password(PASSWORD).build();
+ try (IgniteClient ignored =
IgniteClient.builder().addresses("127.0.0.1:10800").authenticator(authenticator).build())
{
+ // do nothing
+ }
+
+ // Then single event is written to file.
+ await().until(ItEventLogTest::readEventLog, hasSize(1));
+
+ // And event is written in JSON format.
+ String expectedEventJsonPattern = "\\{"
+ + "\"type\":\"USER_AUTHENTICATED\","
+ + "\"timestamp\":\\d*,"
+ + "\"productVersion\":\".*\","
+ + "\"user\":\\{\"username\":\"" + USERNAME +
"\",\"authenticationProvider\":\"" + PROVIDER_NAME + "\"},"
+ + "\"fields\":\\{}"
+ + "}";
+
+ assertThat(readEventLog(),
contains(matchesRegex(expectedEventJsonPattern)));
+ }
+
+ private static List<String> readEventLog() throws IOException {
+ return Files.readAllLines(eventlogPath);
+ }
+}
diff --git
a/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/IgniteEventType.java
b/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/IgniteEventType.java
index 05844d0ad0..894ef3327d 100644
---
a/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/IgniteEventType.java
+++
b/modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/IgniteEventType.java
@@ -33,4 +33,10 @@ public enum IgniteEventType {
// and the EventTypeRegistry will not be able to validate the event
types.
Arrays.stream(values()).forEach(type ->
EventTypeRegistry.register(type.name()));
}
+
+ /**
+ * Registers all event types through the static initialization block once.
+ */
+ public static void initialize() {
+ }
}
diff --git
a/modules/runner/src/main/java/org/apache/ignite/internal/app/IgnitionImpl.java
b/modules/runner/src/main/java/org/apache/ignite/internal/app/IgnitionImpl.java
index 8a1c6edc7b..5ba9a99409 100644
---
a/modules/runner/src/main/java/org/apache/ignite/internal/app/IgnitionImpl.java
+++
b/modules/runner/src/main/java/org/apache/ignite/internal/app/IgnitionImpl.java
@@ -31,6 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.InitParameters;
+import org.apache.ignite.internal.eventlog.api.IgniteEventType;
import org.apache.ignite.internal.lang.NodeStoppingException;
import org.apache.ignite.internal.logger.IgniteLogger;
import org.apache.ignite.internal.logger.Loggers;
@@ -90,6 +91,7 @@ public class IgnitionImpl implements Ignition {
@Nullable ClassLoader serviceLoaderClassLoader
) {
ErrorGroups.initialize();
+ IgniteEventType.initialize();
Objects.requireNonNull(cfgPath, "Config path must not be null");
if (Files.notExists(cfgPath)) {