valepakh commented on code in PR #3430:
URL: https://github.com/apache/ignite-3/pull/3430#discussion_r1533426347


##########
modules/client-handler/build.gradle:
##########
@@ -40,6 +40,7 @@ dependencies {
     implementation project(':ignite-placement-driver-api')
     implementation project(':ignite-cluster-management')
     implementation project(':ignite-compute')
+    implementation project(':ignite-eventlog')

Review Comment:
   Why do we need this?



##########
modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/TestServer.java:
##########
@@ -75,7 +75,7 @@ public TestServer(ClientConnectorConfiguration 
clientConnectorConfiguration, Net
         this.testSslConfig = testSslConfig;
         this.authenticationManager = securityConfiguration == null
                 ? new DummyAuthenticationManager()
-                : new AuthenticationManagerImpl(securityConfiguration);
+                : new AuthenticationManagerImpl(securityConfiguration, (ign) 
-> {});

Review Comment:
   ```suggestion
                   : new AuthenticationManagerImpl(securityConfiguration, ign 
-> {});
   ```



##########
modules/client/build.gradle:
##########
@@ -27,6 +27,7 @@ dependencies {
     implementation project(':ignite-marshaller-common')
     implementation project(':ignite-metrics')
     implementation project(':ignite-catalog-dsl')
+    implementation project(':ignite-eventlog')

Review Comment:
   Should be in the `testImplementation`



##########
modules/client/src/test/java/org/apache/ignite/client/TestServer.java:
##########
@@ -205,7 +205,8 @@ public TestServer(
         if (securityConfiguration == null) {
             authenticationManager = new DummyAuthenticationManager();
         } else {
-            authenticationManager = new 
AuthenticationManagerImpl(securityConfiguration);
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-21665.
+            authenticationManager = new 
AuthenticationManagerImpl(securityConfiguration, (ign) -> {});

Review Comment:
   ```suggestion
               authenticationManager = new 
AuthenticationManagerImpl(securityConfiguration, ign -> {});
   ```



##########
modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/EventFactory.java:
##########
@@ -0,0 +1,34 @@
+/*
+ * 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.api;
+
+import org.apache.ignite.internal.eventlog.event.EventUser;
+
+/**
+ * The factory that is responsible for creating events. This interface should 
be used everywhere where events are created.
+ * Only scpecial cases should use {@link 
org.apache.ignite.internal.eventlog.event.EventBuilder} directly, for example, 
in tests.

Review Comment:
   ```suggestion
    * Only special cases should use {@link 
org.apache.ignite.internal.eventlog.event.EventBuilder} directly, for example, 
in tests.
   ```



##########
modules/eventlog/src/test/java/org/apache/ignite/internal/eventlog/event/EventBuilderTest.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.event;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.greaterThan;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Map;
+import org.apache.ignite.internal.eventlog.api.Event;
+import 
org.apache.ignite.internal.eventlog.event.exception.InvalidEventTypeException;
+import 
org.apache.ignite.internal.eventlog.event.exception.InvalidProductVersionException;
+import 
org.apache.ignite.internal.eventlog.event.exception.MissingEventTypeException;
+import 
org.apache.ignite.internal.eventlog.event.exception.MissingEventUserException;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+class EventBuilderTest {
+    private static final String EVENT_TYPE = "TEST_EVENT_TYPE";
+
+    @BeforeAll
+    static void beforeAll() {
+        // Register test event type in order to be able to create events with 
it.
+        EventTypeRegistry.register(EVENT_TYPE);
+    }
+
+    @Test
+    void buildPositive() {
+        Event event = Event.builder()
+                .type(EVENT_TYPE)
+                .timestamp(1)
+                .productVersion("1.1.1")
+                .user(EventUser.system())
+                .fields(Map.of("key", "value"))
+                .build();
+
+        assertEquals(EVENT_TYPE, event.type());
+        assertEquals(1, event.timestamp());
+        assertEquals("1.1.1", event.productVersion());
+        assertEquals(EventUser.system(), event.user());
+        assertEquals(Map.of("key", "value"), event.fields());
+    }
+
+    @Test
+    void buildWithoutFields() {
+        Event event = Event.builder()
+                .type(EVENT_TYPE)
+                .timestamp(1)
+                .productVersion("1.1.1")
+                .user(EventUser.system())
+                .build();
+
+        assertEquals(EVENT_TYPE, event.type());
+        assertEquals(1, event.timestamp());
+        assertEquals("1.1.1", event.productVersion());
+        assertEquals(EventUser.system(), event.user());
+        assertEquals(Map.of(), event.fields());
+    }
+
+    @Test
+    void buildWithDefaults() {
+        Event event = Event.builder()
+                .type(EVENT_TYPE)
+                .user(EventUser.system())
+                .build();
+
+        assertEquals(EVENT_TYPE, event.type());
+        assertThat(event.timestamp(), greaterThan(0L));
+        assertEquals("3.0.0", event.productVersion());
+        assertEquals(EventUser.system(), event.user());
+        assertEquals(Map.of(), event.fields());
+    }
+
+    @Test
+    void buildIncorrectType() {
+        var thrown = assertThrows(

Review Comment:
   You could use `IgniteTestUtils.assertThrows` here to tests the exception 
message right away.



##########
modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/event/exception/NotUniqueEventTypeException.java:
##########
@@ -0,0 +1,37 @@
+/*
+ * 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.event.exception;
+
+import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
+
+import org.apache.ignite.internal.lang.IgniteInternalException;
+
+/** Thrown when an event type is not unique. */
+public class NotUniqueEventTypeException extends IgniteInternalException {
+
+    private static final long serialVersionUID = 6299123813806042917L;
+
+    /**
+     * Constructor.
+     *
+     * @param type The type of the event.
+     */
+    public NotUniqueEventTypeException(String type) {
+        super(INTERNAL_ERR, "Event type `%s` is already registered. Please, 
use another name.");

Review Comment:
   `String.format` is missing here. Which means that the 
`EventTypeRegistryTest` should check the exception message.



##########
modules/security/src/main/java/org/apache/ignite/internal/security/authentication/AuthenticationManagerImpl.java:
##########
@@ -158,6 +165,14 @@ public UserDetails authenticate(AuthenticationRequest<?, 
?> authenticationReques
                         .map(authenticator -> authenticate(authenticator, 
authenticationRequest))
                         .filter(Objects::nonNull)
                         .findFirst()
+                        .map(userDetails ->  {
+                            eventLog.log(() ->
+                                    
IgniteEvents.CONNECTION_ESTABLISHED.create(EventUser.of(

Review Comment:
   The description of these events should be provided somewhere, and the name 
"connection established" looks odd, it seems more like "user authenticated"?



##########
modules/rest/build.gradle:
##########
@@ -39,6 +39,7 @@ dependencies {
     implementation project(':ignite-code-deployment')
     implementation project(':ignite-security-api')
     implementation project(':ignite-compute')
+    api project(':ignite-eventlog')

Review Comment:
   Why `api`?



##########
modules/eventlog/src/main/java/org/apache/ignite/internal/eventlog/api/Event.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.api;
+
+import java.util.Map;
+import org.apache.ignite.internal.eventlog.event.EventBuilder;
+import org.apache.ignite.internal.eventlog.event.EventTypeRegistry;
+import org.apache.ignite.internal.eventlog.event.EventUser;
+
+/** Represents an event object that can be logged to the event log. */
+public interface Event {
+    /** The type of the event. The type must be registered in the {@link 
EventTypeRegistry}. */
+    String type();
+
+    /** The unix timestamp of the event. */
+    long timestamp();
+
+    /** The product version. The version is compatible with vemver. */

Review Comment:
   ```suggestion
       /** The product version. The version is compatible with semver. */
   ```



-- 
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