ololo3000 commented on code in PR #9694:
URL: https://github.com/apache/ignite/pull/9694#discussion_r851794375


##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/CacheMetricsManage.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.commandline.cache;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.logging.Logger;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.commandline.AbstractCommand;
+import org.apache.ignite.internal.commandline.Command;
+import org.apache.ignite.internal.commandline.CommandArgIterator;
+import org.apache.ignite.internal.commandline.TaskExecutor;
+import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
+import 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg;
+import org.apache.ignite.internal.commandline.systemview.SystemViewCommand;
+import org.apache.ignite.internal.util.typedef.F;
+import 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTask;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskArg;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskResult;
+
+import static java.util.Arrays.asList;
+import static org.apache.ignite.internal.commandline.CommandLogger.optional;
+import static org.apache.ignite.internal.commandline.CommandLogger.or;
+import static 
org.apache.ignite.internal.commandline.cache.CacheSubcommands.METRICS_MANAGE;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.ALL_CACHES;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.CACHES;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.DISABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.ENABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.STATUS;
+import static 
org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleType.STRING;
+
+/**
+ * Cache sub-command for a cache metrics collection management. It provides to 
enable, disable or show status.
+ */
+public class CacheMetricsManage extends 
AbstractCommand<VisorCacheMetricsManageTaskArg> {
+    /** Incorrect sub command message. */
+    public static final String INCORRECT_SUB_COMMAND_MESSAGE = "Expected 
correct sub-command.";
+
+    /** Incorrect cache argument message. */
+    public static final String INCORRECT_CACHE_ARGUMENT_MESSAGE =
+        String.format("'%s' or '%s' arguments should be passed.", CACHES, 
ALL_CACHES);
+
+    /** Invalid caches list message. */
+    public static final String INVALID_CACHES_LIST_MESSAGE = "comma-separated 
list of cache names.";
+
+    /** No caches processed message. */
+    public static final String NONE_CACHES_PROCECCED_MESSAGE = "None of caches 
have been processed. " +
+        "Are there any caches in cluster?";
+
+    /** Duplicated '--caches' option message. */
+    public static final String DUPLICATED_CACHES_OPTION_MESSAGE = "Duplicated 
'" + CACHES + "' option found.";
+
+    /** Duplicated '--all-caches' option message. */
+    public static final String DUPLICATED_ALL_CACHES_OPTION_MESSAGE = 
"Duplicated '" + ALL_CACHES + "' option found.";
+
+    /** Success message. */
+    public static final String SUCCESS_MESSAGE = "Command performed 
successfully.";
+
+    /** Task argument. */
+    private VisorCacheMetricsManageTaskArg arg;
+
+    /** {@inheritDoc} */
+    @Override public Object execute(GridClientConfiguration clientCfg, Logger 
log) throws Exception {
+        try (GridClient client = Command.startClient(clientCfg)) {
+            VisorCacheMetricsManageTaskResult taskResult = 
TaskExecutor.executeTaskByNameOnNode(client,
+                VisorCacheMetricsManageTask.class.getName(), arg, null, 
clientCfg);
+
+            return processTaskResult(log, taskResult.result());
+        }
+    }
+
+    /**
+     * @param log Logger.
+     * @param result Task result.
+     */
+    private String processTaskResult(Logger log, Object result) {
+        Objects.requireNonNull(result);
+
+        switch (arg.subCommand()) {
+            case ENABLE:
+            case DISABLE:
+                String resultMsg = ((Integer)result) > 0 ? SUCCESS_MESSAGE : 
NONE_CACHES_PROCECCED_MESSAGE;
+
+                log.info(resultMsg);
+
+                break;
+            case STATUS:
+                Map<String, Boolean> statusTaskResult = (Map<String, 
Boolean>)result;
+
+                if (statusTaskResult.isEmpty())
+                    log.info(NONE_CACHES_PROCECCED_MESSAGE);
+                else {
+                    Collection<List<?>> values = 
F.viewReadOnly(statusTaskResult.entrySet(),
+                        e -> asList(e.getKey(), e.getValue() ? "enabled" : 
"disabled"));
+
+                    SystemViewCommand.printTable(asList("Cache Name", 
"Status"), asList(STRING, STRING), values, log);
+                }
+
+                break;
+            default:
+                throw new IllegalStateException("Unexpected value: " + 
arg.subCommand());
+        }
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void printUsage(Logger log) {
+        String desc = "Manages user cache metrics collection: enables, 
disables them or shows status.";
+
+        usageCache(log, METRICS_MANAGE, desc, null, or(ENABLE, DISABLE, 
STATUS),

Review Comment:
   It seems we should pass map of command arguments and corresponding 
descriptions instead of the `null`.



##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/systemview/SystemViewCommand.java:
##########
@@ -101,7 +101,7 @@ public class SystemViewCommand extends 
AbstractCommand<VisorSystemViewTaskArg> {
      * @param data Table data rows.
      * @param log Logger.
      */
-    public static void printTable(List<String> titles, List<SimpleType> types, 
List<List<?>> data, Logger log) {
+    public static void printTable(List<String> titles, List<SimpleType> types, 
Collection<List<?>> data, Logger log) {

Review Comment:
   Let's change argument list to
   `Collection<String> titles, Collection<SimpleType> types, Collection<? 
extends Collection<?>> data, Logger log` then.



##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/argument/CacheMetricsManageCommandArg.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.commandline.cache.argument;
+
+import org.apache.ignite.internal.commandline.argument.CommandArg;
+import org.apache.ignite.internal.commandline.cache.CacheMetricsManage;
+
+/**
+ * Command arguments for {@link CacheMetricsManage} command.
+ */
+public enum CacheMetricsManageCommandArg implements CommandArg {
+    /** Argument for applying a sub-command to all user caches. */

Review Comment:
   The java doc should be fixed - it seem that now it just duplicates 
ALL_CACHES java doc text.



##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/CacheMetricsManage.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.commandline.cache;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.logging.Logger;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.commandline.AbstractCommand;
+import org.apache.ignite.internal.commandline.Command;
+import org.apache.ignite.internal.commandline.CommandArgIterator;
+import org.apache.ignite.internal.commandline.TaskExecutor;
+import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
+import 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg;
+import org.apache.ignite.internal.commandline.systemview.SystemViewCommand;
+import org.apache.ignite.internal.util.typedef.F;
+import 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTask;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskArg;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskResult;
+
+import static java.util.Arrays.asList;
+import static org.apache.ignite.internal.commandline.CommandLogger.optional;
+import static org.apache.ignite.internal.commandline.CommandLogger.or;
+import static 
org.apache.ignite.internal.commandline.cache.CacheSubcommands.METRICS_MANAGE;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.ALL_CACHES;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.CACHES;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.DISABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.ENABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.STATUS;
+import static 
org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleType.STRING;
+
+/**
+ * Cache sub-command for a cache metrics collection management. It provides to 
enable, disable or show status.
+ */
+public class CacheMetricsManage extends 
AbstractCommand<VisorCacheMetricsManageTaskArg> {
+    /** Incorrect sub command message. */
+    public static final String INCORRECT_SUB_COMMAND_MESSAGE = "Expected 
correct sub-command.";
+
+    /** Incorrect cache argument message. */
+    public static final String INCORRECT_CACHE_ARGUMENT_MESSAGE =
+        String.format("'%s' or '%s' arguments should be passed.", CACHES, 
ALL_CACHES);
+
+    /** Invalid caches list message. */
+    public static final String INVALID_CACHES_LIST_MESSAGE = "comma-separated 
list of cache names.";
+
+    /** No caches processed message. */
+    public static final String NONE_CACHES_PROCECCED_MESSAGE = "None of caches 
have been processed. " +
+        "Are there any caches in cluster?";
+
+    /** Duplicated '--caches' option message. */
+    public static final String DUPLICATED_CACHES_OPTION_MESSAGE = "Duplicated 
'" + CACHES + "' option found.";
+
+    /** Duplicated '--all-caches' option message. */
+    public static final String DUPLICATED_ALL_CACHES_OPTION_MESSAGE = 
"Duplicated '" + ALL_CACHES + "' option found.";
+
+    /** Success message. */
+    public static final String SUCCESS_MESSAGE = "Command performed 
successfully.";
+
+    /** Task argument. */
+    private VisorCacheMetricsManageTaskArg arg;
+
+    /** {@inheritDoc} */
+    @Override public Object execute(GridClientConfiguration clientCfg, Logger 
log) throws Exception {
+        try (GridClient client = Command.startClient(clientCfg)) {
+            VisorCacheMetricsManageTaskResult taskResult = 
TaskExecutor.executeTaskByNameOnNode(client,
+                VisorCacheMetricsManageTask.class.getName(), arg, null, 
clientCfg);
+
+            return processTaskResult(log, taskResult.result());
+        }
+    }
+
+    /**
+     * @param log Logger.
+     * @param result Task result.
+     */
+    private String processTaskResult(Logger log, Object result) {
+        Objects.requireNonNull(result);
+
+        switch (arg.subCommand()) {
+            case ENABLE:
+            case DISABLE:
+                String resultMsg = ((Integer)result) > 0 ? SUCCESS_MESSAGE : 
NONE_CACHES_PROCECCED_MESSAGE;
+
+                log.info(resultMsg);
+
+                break;
+            case STATUS:
+                Map<String, Boolean> statusTaskResult = (Map<String, 
Boolean>)result;
+
+                if (statusTaskResult.isEmpty())
+                    log.info(NONE_CACHES_PROCECCED_MESSAGE);
+                else {
+                    Collection<List<?>> values = 
F.viewReadOnly(statusTaskResult.entrySet(),
+                        e -> asList(e.getKey(), e.getValue() ? "enabled" : 
"disabled"));
+
+                    SystemViewCommand.printTable(asList("Cache Name", 
"Status"), asList(STRING, STRING), values, log);

Review Comment:
   May be `Metrics Enable Status` instead of `Status`?



##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/CacheMetricsManage.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.commandline.cache;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.logging.Logger;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.commandline.AbstractCommand;
+import org.apache.ignite.internal.commandline.Command;
+import org.apache.ignite.internal.commandline.CommandArgIterator;
+import org.apache.ignite.internal.commandline.TaskExecutor;
+import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
+import 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg;
+import org.apache.ignite.internal.commandline.systemview.SystemViewCommand;
+import org.apache.ignite.internal.util.typedef.F;
+import 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTask;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskArg;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskResult;
+
+import static java.util.Arrays.asList;
+import static org.apache.ignite.internal.commandline.CommandLogger.optional;
+import static org.apache.ignite.internal.commandline.CommandLogger.or;
+import static 
org.apache.ignite.internal.commandline.cache.CacheSubcommands.METRICS_MANAGE;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.ALL_CACHES;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.CACHES;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.DISABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.ENABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.STATUS;
+import static 
org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleType.STRING;
+
+/**
+ * Cache sub-command for a cache metrics collection management. It provides to 
enable, disable or show status.

Review Comment:
   It seems that provides `ability` is missing.



##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/argument/CacheMetricsManageCommandArg.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.commandline.cache.argument;
+
+import org.apache.ignite.internal.commandline.argument.CommandArg;
+import org.apache.ignite.internal.commandline.cache.CacheMetricsManage;
+
+/**
+ * Command arguments for {@link CacheMetricsManage} command.

Review Comment:
   Let's change it to something like this - Common arguments for all {@link 
CacheMetricsManage} sub-commands.



##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/CacheMetricsManage.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.commandline.cache;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.logging.Logger;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.commandline.AbstractCommand;
+import org.apache.ignite.internal.commandline.Command;
+import org.apache.ignite.internal.commandline.CommandArgIterator;
+import org.apache.ignite.internal.commandline.TaskExecutor;
+import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
+import 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg;
+import org.apache.ignite.internal.commandline.systemview.SystemViewCommand;
+import org.apache.ignite.internal.util.typedef.F;
+import 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTask;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskArg;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskResult;
+
+import static java.util.Arrays.asList;
+import static org.apache.ignite.internal.commandline.CommandLogger.optional;
+import static org.apache.ignite.internal.commandline.CommandLogger.or;
+import static 
org.apache.ignite.internal.commandline.cache.CacheSubcommands.METRICS_MANAGE;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.ALL_CACHES;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.CACHES;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.DISABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.ENABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.STATUS;
+import static 
org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleType.STRING;
+
+/**
+ * Cache sub-command for a cache metrics collection management. It provides to 
enable, disable or show status.
+ */
+public class CacheMetricsManage extends 
AbstractCommand<VisorCacheMetricsManageTaskArg> {
+    /** Incorrect sub command message. */
+    public static final String INCORRECT_SUB_COMMAND_MESSAGE = "Expected 
correct sub-command.";
+
+    /** Incorrect cache argument message. */
+    public static final String INCORRECT_CACHE_ARGUMENT_MESSAGE =
+        String.format("'%s' or '%s' arguments should be passed.", CACHES, 
ALL_CACHES);

Review Comment:
   May be something like: Expected one of the ... arguments. Multiple argument 
usage is invalid.



##########
modules/core/src/main/java/org/apache/ignite/internal/visor/cache/metrics/VisorCacheMetricsManageTask.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.visor.cache.metrics;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.task.GridInternal;
+import org.apache.ignite.internal.processors.task.GridVisorManagementTask;
+import org.apache.ignite.internal.visor.VisorJob;
+import org.apache.ignite.internal.visor.VisorOneNodeTask;
+import org.jetbrains.annotations.Nullable;
+
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.ENABLE;
+
+/**
+ * Task for a cache metrics manage command.
+ */
+@GridInternal
+@GridVisorManagementTask
+public class VisorCacheMetricsManageTask extends 
VisorOneNodeTask<VisorCacheMetricsManageTaskArg, 
VisorCacheMetricsManageTaskResult> {
+    /** Serial version uid. */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override protected VisorCacheMetricsManageJob 
job(VisorCacheMetricsManageTaskArg arg) {
+        return new VisorCacheMetricsManageJob(arg, false);
+    }
+
+    /**
+     * Job result is a collection of processed cache names.

Review Comment:
   This javadoc does not describe what is actually happening.



##########
modules/core/src/main/java/org/apache/ignite/internal/visor/cache/metrics/VisorCacheMetricsManageTask.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.visor.cache.metrics;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.TreeMap;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.task.GridInternal;
+import org.apache.ignite.internal.processors.task.GridVisorManagementTask;
+import org.apache.ignite.internal.visor.VisorJob;
+import org.apache.ignite.internal.visor.VisorOneNodeTask;
+import org.jetbrains.annotations.Nullable;
+
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.ENABLE;
+
+/**
+ * Task for a cache metrics manage command.
+ */
+@GridInternal
+@GridVisorManagementTask
+public class VisorCacheMetricsManageTask extends 
VisorOneNodeTask<VisorCacheMetricsManageTaskArg, 
VisorCacheMetricsManageTaskResult> {
+    /** Serial version uid. */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override protected VisorCacheMetricsManageJob 
job(VisorCacheMetricsManageTaskArg arg) {
+        return new VisorCacheMetricsManageJob(arg, false);
+    }
+
+    /**
+     * Job result is a collection of processed cache names.
+     */
+    private static class VisorCacheMetricsManageJob extends 
VisorJob<VisorCacheMetricsManageTaskArg,
+        VisorCacheMetricsManageTaskResult> {
+        /** Serial version uid. */
+        private static final long serialVersionUID = 0L;
+
+        /**
+         * Create job with specified argument.
+         *
+         * @param arg   Job argument.
+         * @param debug Flag indicating whether debug information should be 
printed into node log.
+         */
+        protected VisorCacheMetricsManageJob(@Nullable 
VisorCacheMetricsManageTaskArg arg, boolean debug) {
+            super(arg, debug);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected VisorCacheMetricsManageTaskResult run(@Nullable 
VisorCacheMetricsManageTaskArg arg)
+            throws IgniteException {
+            if (arg != null) {
+                Collection<String> cacheNames = arg.applyToAllCaches() ? 
ignite.cacheNames() : arg.cacheNames();
+
+                try {
+                    switch (arg.subCommand()) {
+                        case ENABLE:
+                        case DISABLE:
+                            ignite.cluster().enableStatistics(cacheNames, 
ENABLE == arg.subCommand());

Review Comment:
   Let's skip `enableStatistics` method call if `cacheNames` are empty.



##########
modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/CacheMetricsManage.java:
##########
@@ -0,0 +1,198 @@
+/*
+ * 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.commandline.cache;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.logging.Logger;
+import org.apache.ignite.internal.client.GridClient;
+import org.apache.ignite.internal.client.GridClientConfiguration;
+import org.apache.ignite.internal.commandline.AbstractCommand;
+import org.apache.ignite.internal.commandline.Command;
+import org.apache.ignite.internal.commandline.CommandArgIterator;
+import org.apache.ignite.internal.commandline.TaskExecutor;
+import org.apache.ignite.internal.commandline.argument.CommandArgUtils;
+import 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg;
+import org.apache.ignite.internal.commandline.systemview.SystemViewCommand;
+import org.apache.ignite.internal.util.typedef.F;
+import 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTask;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskArg;
+import 
org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsManageTaskResult;
+
+import static java.util.Arrays.asList;
+import static org.apache.ignite.internal.commandline.CommandLogger.optional;
+import static org.apache.ignite.internal.commandline.CommandLogger.or;
+import static 
org.apache.ignite.internal.commandline.cache.CacheSubcommands.METRICS_MANAGE;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.ALL_CACHES;
+import static 
org.apache.ignite.internal.commandline.cache.argument.CacheMetricsManageCommandArg.CACHES;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.DISABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.ENABLE;
+import static 
org.apache.ignite.internal.visor.cache.metrics.CacheMetricsManageSubCommand.STATUS;
+import static 
org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleType.STRING;
+
+/**
+ * Cache sub-command for a cache metrics collection management. It provides to 
enable, disable or show status.
+ */
+public class CacheMetricsManage extends 
AbstractCommand<VisorCacheMetricsManageTaskArg> {
+    /** Incorrect sub command message. */
+    public static final String INCORRECT_SUB_COMMAND_MESSAGE = "Expected 
correct sub-command.";
+
+    /** Incorrect cache argument message. */
+    public static final String INCORRECT_CACHE_ARGUMENT_MESSAGE =
+        String.format("'%s' or '%s' arguments should be passed.", CACHES, 
ALL_CACHES);
+
+    /** Invalid caches list message. */
+    public static final String INVALID_CACHES_LIST_MESSAGE = "comma-separated 
list of cache names.";
+
+    /** No caches processed message. */
+    public static final String NONE_CACHES_PROCECCED_MESSAGE = "None of caches 
have been processed. " +

Review Comment:
   Typo : PROCECCED



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