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


##########
modules/runner/src/main/java/org/apache/ignite/internal/configuration/DistributedConfigurationUpdater.java:
##########
@@ -31,37 +31,37 @@ public class DistributedConfigurationUpdater implements 
IgniteComponent {
 
     private static final IgniteLogger LOG = 
Loggers.forClass(DistributedConfigurationUpdater.class);
 
-    private final CompletableFuture<ConfigurationPresentation<String>> 
clusterCfgPresentation = new CompletableFuture<>();
+    private final ClusterManagementGroupManager cmgMgr;
 
-    public void 
setDistributedConfigurationPresentation(ConfigurationPresentation<String> 
presentation) {
-        clusterCfgPresentation.complete(presentation);
-    }
+    private final ConfigurationPresentation<String> presentation;
 
-    /**
-     * Applies changes to the cluster configuration when {@link 
DistributedConfigurationUpdater#clusterCfgPresentation}
-     * is complete.
-     *
-     * @param configurationToApply Cluster configuration that should be 
applied.
-     * @return Future that will be completed when cluster configuration is 
updated.
-     */
-    public CompletableFuture<Void> updateConfiguration(String 
configurationToApply) {
-        return clusterCfgPresentation.thenCompose(presentation -> 
presentation.update(configurationToApply))
-                .whenComplete((v, e) -> {
-                    if (e != null) {
-                        LOG.error("Unable to update cluster configuration", e);
-                    } else {
-                        LOG.info("Cluster configuration updated successfully");
-                    }
-                });
+    public DistributedConfigurationUpdater(ClusterManagementGroupManager 
cmgMgr, ConfigurationPresentation<String> presentation) {
+        this.cmgMgr = cmgMgr;
+        this.presentation = presentation;
     }
 
     @Override
     public void start() {
-
+        cmgMgr.clusterConfigurationToUpdate()
+                .thenCompose(action -> {

Review Comment:
   Why do you need to use `thenCompose` here? This future is not returned 
anywhere. `thenAccept` looks more suitable



##########
modules/cluster-management/src/main/java/org/apache/ignite/internal/cluster/management/ClusterManagementGroupManager.java:
##########
@@ -388,44 +388,47 @@ private void onElectedAsLeader(long term) {
                     }
                 });
 
-        raftServiceAfterJoin().whenComplete((service, e) -> {
-            if (e != null) {
-                LOG.error("Error when joining to the raft service", e);
-                
updateDistributedConfigurationActionFuture.completeExceptionally(e);
-            } else {
-                service.readClusterState()
-                        .thenAccept(state -> {
-                            String configuration = 
state.clusterConfigurationToApply();
-                            if (configuration != null) {
-                                
updateDistributedConfigurationActionFuture.complete(
-                                        new 
UpdateDistributedConfigurationAction(
-                                                configuration,
-                                                () -> 
removeClusterConfigFromClusterState(service)
-                                        ));
-                            } else {
-                                
updateDistributedConfigurationActionFuture.cancel(true);
-                            }
-                        });
-            }
-        });
+        raftServiceAfterJoin().thenCompose(service -> 
service.readClusterState()
+                .thenAccept(state -> {

Review Comment:
   `thenAccept` and `whenComplete` can be united into a single `whenComplete` 
here



##########
modules/runner/src/test/java/org/apache/ignite/internal/configuration/DistributedConfigurationUpdaterTest.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.configuration;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.concurrent.CompletableFuture;
+import 
org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager;
+import 
org.apache.ignite.internal.cluster.management.UpdateDistributedConfigurationAction;
+import 
org.apache.ignite.internal.configuration.presentation.ConfigurationPresentation;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+class DistributedConfigurationUpdaterTest {
+
+    @Mock
+    public ConfigurationPresentation<String> presentation;
+
+    @Mock
+    public ClusterManagementGroupManager cmgMgr;
+
+    @Test
+    public void nextActionIsCompletedAfterUpdatingConfiguration() {
+
+        // Set up mocks.
+        
when(presentation.update(anyString())).thenReturn(completedFuture(null));
+
+        CompletableFuture<Void> nextAction = new CompletableFuture<>();
+        String configuration = "security.authentication.enabled:true";
+        UpdateDistributedConfigurationAction 
updateDistributedConfigurationAction =
+                new UpdateDistributedConfigurationAction(
+                        configuration,
+                        () -> {
+                            nextAction.complete(null);
+                            return null;
+                        }
+                );
+
+        when(cmgMgr.clusterConfigurationToUpdate())
+                
.thenReturn(completedFuture(updateDistributedConfigurationAction));
+
+        // Run updater.
+        DistributedConfigurationUpdater distributedConfigurationUpdater = new 
DistributedConfigurationUpdater(
+                cmgMgr,
+                presentation
+        );
+
+        distributedConfigurationUpdater.start();
+
+        // Verify that configuration was updated.
+        verify(presentation, times(1)).update(configuration);
+
+        // Verify that next action is completed.
+        nextAction.join();

Review Comment:
   This comment was not fixed



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