You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/07/04 13:56:37 UTC

[GitHub] [ignite-3] Pochatkin commented on a diff in pull request #905: IGNITE-17091: Implement status command

Pochatkin commented on code in PR #905:
URL: https://github.com/apache/ignite-3/pull/905#discussion_r913024830


##########
modules/cli/src/main/java/org/apache/ignite/cli/commands/node/status/NodeStatusSubCommand.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.cli.commands.node.status;
+
+import jakarta.inject.Inject;
+import jakarta.inject.Singleton;
+import java.util.concurrent.Callable;
+import org.apache.ignite.cli.call.node.status.NodeStatusCall;
+import org.apache.ignite.cli.commands.BaseCommand;
+import org.apache.ignite.cli.commands.decorators.NodeStatusDecorator;
+import org.apache.ignite.cli.core.call.CallExecutionPipeline;
+import org.apache.ignite.cli.core.call.StatusCallInput;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+/**
+ * Display the node status.
+ */
+@Command(name = "status",
+        description = "Prints status of the node.")
+@Singleton
+public class NodeStatusSubCommand extends BaseCommand implements Callable<Integer> {
+
+    /**
+     * Node url option.
+     */
+    @SuppressWarnings("PMD.UnusedPrivateField")
+    @Option(
+            names = {"--node-url"}, description = "Url to node.",
+            descriptionKey = "ignite.node-url", defaultValue = "http://localhost:10300"

Review Comment:
   Default value not needed anymore after IGNITE-17130



##########
modules/cli/src/main/java/org/apache/ignite/cli/call/cluster/status/ClusterStatusCall.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.cli.call.cluster.status;
+
+import jakarta.inject.Singleton;
+import org.apache.ignite.cli.call.cluster.status.ClusterStatus.ClusterStatusBuilder;
+import org.apache.ignite.cli.core.call.Call;
+import org.apache.ignite.cli.core.call.CallOutput;
+import org.apache.ignite.cli.core.call.DefaultCallOutput;
+import org.apache.ignite.cli.core.call.StatusCallInput;
+import org.apache.ignite.cli.core.exception.IgniteCliApiException;
+import org.apache.ignite.cli.deprecated.CliPathsConfigLoader;
+import org.apache.ignite.cli.deprecated.IgnitePaths;
+import org.apache.ignite.cli.deprecated.builtins.node.NodeManager;
+import org.apache.ignite.rest.client.api.ClusterManagementApi;
+import org.apache.ignite.rest.client.invoker.ApiClient;
+import org.apache.ignite.rest.client.invoker.ApiException;
+import org.apache.ignite.rest.client.model.ClusterState;
+
+/**
+ * Call to get cluster status.
+ */
+@Singleton
+public class ClusterStatusCall implements Call<StatusCallInput, ClusterStatus> {
+
+    private final NodeManager nodeManager;
+
+    private final CliPathsConfigLoader cliPathsCfgLdr;
+
+    /**
+     * Default constructor.
+     */
+    public ClusterStatusCall(NodeManager nodeManager, CliPathsConfigLoader cliPathsCfgLdr) {
+        this.nodeManager = nodeManager;
+        this.cliPathsCfgLdr = cliPathsCfgLdr;
+    }
+
+    @Override
+    public CallOutput<ClusterStatus> execute(StatusCallInput input) {
+        IgnitePaths paths = cliPathsCfgLdr.loadIgnitePathsOrThrowError();
+        ClusterStatusBuilder clusterStatusBuilder = ClusterStatus.builder()
+                .nodeCount(nodeManager.getRunningNodes(paths.logDir, paths.cliPidsDir()).size());
+
+        try {
+            ClusterState clusterState = fetchClusterState(input.getClusterUrl());
+            clusterStatusBuilder
+                    .initialized(true)
+                    .name(clusterState.getClusterTag().getClusterName())
+                    .cmgNodes(clusterState.getCmgNodes());

Review Comment:
   As I see from org.apache.ignite.internal.cluster.management.rest.ClusterManagementController.clusterState clusterState can be null. NPE possible here. But moreover I think that return null as value from REST call its bad practice. Please do not add null check here, better change sematic of org.apache.ignite.internal.cluster.management.rest.ClusterManagementController.clusterState to not return null as value.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org