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


##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/call/unit/DeployUndeployTestSupport.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.cli.call.unit;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.cli.core.call.ProgressTracker;
+
+class DeployUndeployTestSupport {
+    static Path emptyFilePath() {
+        try {
+            return Files.createTempFile("empty", ".txt");

Review Comment:
   Could we use `@WorkDirectory` here?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/unit/DeployUnitCallFactory.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.cli.call.unit;
+
+import jakarta.inject.Inject;
+import jakarta.inject.Singleton;
+import org.apache.ignite.internal.cli.core.ApiClientFactory;
+import org.apache.ignite.internal.cli.core.call.ProgressTracker;
+import org.apache.ignite.internal.cli.core.repl.registry.UnitsRegistry;
+
+/** Factory for {@link DeployUnitCall}. */
+@Singleton
+public class DeployUnitCallFactory {
+
+    @Inject

Review Comment:
   Why constructor injection wasn't used here but was used later in the similar 
ListUnitCall?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/unit/DeployUnitCall.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.cli.call.unit;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.concurrent.CompletableFuture;
+import okhttp3.Call;
+import org.apache.ignite.internal.cli.core.ApiClientFactory;
+import org.apache.ignite.internal.cli.core.call.AsyncCall;
+import org.apache.ignite.internal.cli.core.call.CallOutput;
+import org.apache.ignite.internal.cli.core.call.DefaultCallOutput;
+import org.apache.ignite.internal.cli.core.call.ProgressTracker;
+import org.apache.ignite.internal.cli.core.exception.IgniteCliApiException;
+import 
org.apache.ignite.internal.cli.core.exception.UnitAlreadyExistsException;
+import org.apache.ignite.internal.cli.core.repl.registry.UnitsRegistry;
+import org.apache.ignite.internal.cli.core.style.component.MessageUiComponent;
+import org.apache.ignite.internal.cli.core.style.element.UiElements;
+import org.apache.ignite.rest.client.api.DeploymentApi;
+import org.apache.ignite.rest.client.invoker.ApiException;
+
+/** Call to deploy a unit. */
+public class DeployUnitCall implements AsyncCall<DeployUnitCallInput, String> {
+
+    private final ProgressTracker tracker;
+
+    private final ApiClientFactory clientFactory;
+
+    private final UnitsRegistry unitsRegistry;
+
+    DeployUnitCall(ProgressTracker tracker, ApiClientFactory clientFactory, 
UnitsRegistry registry) {
+        this.tracker = tracker;
+        this.clientFactory = clientFactory;
+        this.unitsRegistry = registry;
+    }
+
+    @Override
+    public CompletableFuture<CallOutput<String>> execute(DeployUnitCallInput 
input) {
+        try {
+            DeploymentApi api = new 
DeploymentApi(clientFactory.getClient(input.clusterUrl()));
+
+            File file = input.path().toFile();
+            if (!file.exists()) {
+                return 
CompletableFuture.completedFuture(DefaultCallOutput.failure(new 
FileNotFoundException(input.path().toString())));

Review Comment:
   Maybe add static import for better readability?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/unit/DeployUnitCall.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.cli.call.unit;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.concurrent.CompletableFuture;
+import okhttp3.Call;
+import org.apache.ignite.internal.cli.core.ApiClientFactory;
+import org.apache.ignite.internal.cli.core.call.AsyncCall;
+import org.apache.ignite.internal.cli.core.call.CallOutput;
+import org.apache.ignite.internal.cli.core.call.DefaultCallOutput;
+import org.apache.ignite.internal.cli.core.call.ProgressTracker;
+import org.apache.ignite.internal.cli.core.exception.IgniteCliApiException;
+import 
org.apache.ignite.internal.cli.core.exception.UnitAlreadyExistsException;
+import org.apache.ignite.internal.cli.core.repl.registry.UnitsRegistry;
+import org.apache.ignite.internal.cli.core.style.component.MessageUiComponent;
+import org.apache.ignite.internal.cli.core.style.element.UiElements;
+import org.apache.ignite.rest.client.api.DeploymentApi;
+import org.apache.ignite.rest.client.invoker.ApiException;
+
+/** Call to deploy a unit. */
+public class DeployUnitCall implements AsyncCall<DeployUnitCallInput, String> {
+
+    private final ProgressTracker tracker;
+
+    private final ApiClientFactory clientFactory;
+
+    private final UnitsRegistry unitsRegistry;
+
+    DeployUnitCall(ProgressTracker tracker, ApiClientFactory clientFactory, 
UnitsRegistry registry) {
+        this.tracker = tracker;
+        this.clientFactory = clientFactory;
+        this.unitsRegistry = registry;
+    }
+
+    @Override
+    public CompletableFuture<CallOutput<String>> execute(DeployUnitCallInput 
input) {
+        try {
+            DeploymentApi api = new 
DeploymentApi(clientFactory.getClient(input.clusterUrl()));
+
+            File file = input.path().toFile();
+            if (!file.exists()) {
+                return 
CompletableFuture.completedFuture(DefaultCallOutput.failure(new 
FileNotFoundException(input.path().toString())));
+            }
+
+            TrackingCallback<Boolean> callback = new 
TrackingCallback<>(tracker);
+            Call call = api.deployUnitAsync(input.id(), file, input.version(), 
callback);
+
+            return CompletableFuture.supplyAsync(() -> {
+                try {
+                    callback.awaitDone();
+                } catch (InterruptedException e) {
+                    throw new RuntimeException(e);

Review Comment:
   Why an exception is thrown here? What will be the result of this?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/repl/completer/CompleterConf.java:
##########
@@ -147,6 +157,12 @@ public CompleterConfBuilder disableOptions(String... 
disableOptions) {
             return this;
         }
 
+        /** Setup single positional parameter completer flag. It means that 
the completer should be applied only for parameter once. */

Review Comment:
   ```suggestion
           /** Setup single positional parameter completer flag. It means that 
the completer should be applied for the parameter only once. */
   ```



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/repl/completer/DynamicCompletionInsider.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.cli.core.repl.completer;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.internal.cli.commands.TopLevelCliReplCommand;
+import org.apache.ignite.internal.cli.commands.node.NodeNameOrUrl;
+import org.jetbrains.annotations.NotNull;
+import picocli.CommandLine;
+import picocli.CommandLine.MissingParameterException;
+import picocli.CommandLine.Model.ArgSpec;
+import picocli.CommandLine.ParseResult;
+
+/** Provides insight into dynamic completion. */
+public class DynamicCompletionInsider {
+
+    private final CommandLine commandLine;
+
+    public DynamicCompletionInsider() {
+        commandLine = new CommandLine(TopLevelCliReplCommand.class);
+        commandLine.registerConverter(NodeNameOrUrl.class, value -> null);
+    }
+
+    @NotNull

Review Comment:
   ```suggestion
   ```



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/repl/completer/unit/ArgumentParser.java:
##########
@@ -0,0 +1,55 @@
+/*
+ * 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.cli.core.repl.completer.unit;
+
+import jakarta.inject.Singleton;
+import org.apache.ignite.internal.cli.commands.TopLevelCliReplCommand;
+import org.jetbrains.annotations.Nullable;
+import picocli.CommandLine;
+import picocli.CommandLine.ParseResult;
+
+/** Parses typed words. */
+@Singleton
+public class ArgumentParser {
+
+    private final CommandLine commandLine;
+
+    public ArgumentParser() {
+        commandLine = new CommandLine(TopLevelCliReplCommand.class);
+    }
+
+    /**
+     * Gets unit ID from typed words.

Review Comment:
   It's unclear why this is specific for unit ID? It seems like it returns the 
first matched argument?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/repl/registry/impl/UnitsRegistryImpl.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * 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.cli.core.repl.registry.impl;
+
+import jakarta.inject.Singleton;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.internal.cli.call.unit.ListUnitCall;
+import org.apache.ignite.internal.cli.call.unit.UnitStatusRecord;
+import org.apache.ignite.internal.cli.core.call.CallOutput;
+import org.apache.ignite.internal.cli.core.call.UrlCallInput;
+import org.apache.ignite.internal.cli.core.repl.AsyncSessionEventListener;
+import org.apache.ignite.internal.cli.core.repl.SessionInfo;
+import org.apache.ignite.internal.cli.core.repl.registry.NodeNameRegistry;
+import org.apache.ignite.internal.cli.core.repl.registry.UnitsRegistry;
+
+/** Implementation of {@link NodeNameRegistry}. */

Review Comment:
   ```suggestion
   /** Implementation of {@link UnitsRegistry}. */
   ```



##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/unit/ItDeploymentUnitTest.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.cli.commands.unit;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import 
org.apache.ignite.internal.cli.commands.CliCommandTestInitializedIntegrationBase;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+/** Integration test for deployment commands. */
+public class ItDeploymentUnitTest extends 
CliCommandTestInitializedIntegrationBase {
+
+    private String path;
+
+    @BeforeEach
+    void setUp(@TempDir Path tmpDir) throws IOException {

Review Comment:
   `@WorkDirectory` should be used here as well



##########
modules/cli/src/integrationTest/java/org/apache/ignite/internal/rest/ItGeneratedRestClientTest.java:
##########
@@ -364,6 +374,44 @@ void enableInvalidNodeMetric() throws 
JsonProcessingException {
         assertThat(problem.getDetail(), containsString("Metrics source with 
given name doesn't exist: no.such.metric"));
     }
 
+    @Test
+    void deployUndeployUnitSync() throws ApiException {
+        assertThat(deploymentApi.units(), empty());
+
+        deploymentApi.deployUnit("test.unit.id", emptyFile(), "1.0.0");
+        List<UnitStatus> units = deploymentApi.units();
+        assertThat(units, hasSize(1));
+        assertThat(units.get(0).getId(), equalTo("test.unit.id"));
+        assertThat(units.get(0).getVersionToConsistentIds().values(), 
not(empty()));
+
+        assertThat(deploymentApi.versions("test.unit.id"), contains("1.0.0"));
+
+        deploymentApi.undeployUnit("test.unit.id", "1.0.0");
+        assertThat(deploymentApi.units(), empty());
+    }
+
+    @Test
+    void undeployFailed() throws JsonProcessingException {
+        ApiException thrown = assertThrows(
+                ApiException.class,
+                () -> deploymentApi.undeployUnit("test.unit.id", "0.0.0")
+        );
+
+        assertThat(thrown.getCode(), equalTo(404));
+
+        Problem problem = objectMapper.readValue(thrown.getResponseBody(), 
Problem.class);
+        assertThat(problem.getStatus(), equalTo(404));
+        assertThat(problem.getDetail(), containsString("Unit test.unit.id with 
version 0.0.0 doesn't exist"));
+    }
+
+    private File emptyFile() {

Review Comment:
   And here



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/call/AsyncCallExecutionPipeline.java:
##########
@@ -56,10 +56,12 @@ public int runPipelineInternal() {
         I callInput = inputProvider.get();
 
         progressBarBuilder.setConsumer(new 
DelegatingProgressBarConsumer(this::print));
+        progressBarBuilder.setUpdateIntervalMillis(1);

Review Comment:
   Why is it necessary to set such low update interval?



##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/repl/completer/DynamicCompletionInsider.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.cli.core.repl.completer;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.internal.cli.commands.TopLevelCliReplCommand;
+import org.apache.ignite.internal.cli.commands.node.NodeNameOrUrl;
+import org.jetbrains.annotations.NotNull;

Review Comment:
   ```suggestion
   ```



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