Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-15629 Cache metrics command implemented #10745

Merged
merged 158 commits into from Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
d0d188a
IGNITE-15629 Meta commands implemented
nizhikov Apr 27, 2023
7f2ed3f
Merge branch 'IGNITE-15629' into IGNITE-15629-meta
nizhikov Apr 27, 2023
9e55db8
IGNITE-15629 Meta commands implemented
nizhikov Apr 27, 2023
5848de4
IGNITE-15629 Meta commands implemented
nizhikov Apr 27, 2023
95424fd
IGNITE-15629 Meta commands implemented
nizhikov Apr 27, 2023
d6677fc
IGNITE-15629 Meta commands implemented
nizhikov Apr 27, 2023
ebca70f
IGNITE-15629 Cluster change tag command implemented
nizhikov Apr 27, 2023
05e5253
IGNITE-15629 Cluster change tag command implemented
nizhikov Apr 28, 2023
a786a15
IGNITE-15629 CDC commands implemented
nizhikov Apr 28, 2023
14f2f9d
IGNITE-15629 CDC commands implemented
nizhikov Apr 28, 2023
4776495
IGNITE-15629 Code review fixes
nizhikov Apr 28, 2023
dad10ee
IGNITE-15629 Code review fixes
nizhikov Apr 28, 2023
162e739
IGNITE-15629 Code review fixes
nizhikov Apr 28, 2023
6c7208d
Merge branch 'IGNITE-15629-meta' into IGNITE-15629-cdc
nizhikov Apr 28, 2023
1da0b31
IGNITE-15629 Shutdown command policy implemented + test fixes
nizhikov Apr 28, 2023
55dacb3
IGNITE-15629 Wal commands implemented
nizhikov Apr 28, 2023
fad1e2f
Merge branch 'IGNITE-15629' into IGNITE-15629-changetag
nizhikov Apr 28, 2023
1a3b589
Merge branch 'IGNITE-15629-changetag' into IGNITE-15629-wal
nizhikov Apr 28, 2023
c324cb0
IGNITE-15629 Wal commands implemented
nizhikov Apr 28, 2023
1485e0f
IGNITE-15629 Local commands implemented
nizhikov May 2, 2023
a8db18d
Merge branch 'IGNITE-15629' into IGNITE-15629-cdc
nizhikov May 2, 2023
a6f5720
IGNITE-15629 CDC command implemented
nizhikov May 2, 2023
7a12fe1
IGNITE-15629 CDC command implemented
nizhikov May 2, 2023
1cf5930
IGNITE-15629 CDC command implemented
nizhikov May 2, 2023
281c072
Merge branch 'IGNITE-15629-cdc' into IGNITE-15629-shutdown-policy
nizhikov May 2, 2023
df27c53
Merge branch 'IGNITE-15629-cdc' into IGNITE-15629-wal
nizhikov May 2, 2023
eb64228
Merge branch 'IGNITE-15629-cdc' into IGNITE-15629-local-commands
nizhikov May 2, 2023
1baa808
IGNITE-15629 Defragmentation command implemented
nizhikov May 2, 2023
3cd19b9
Merge branch 'IGNITE-15629' into IGNITE-15629-shutdown-policy
nizhikov May 3, 2023
b818d0a
IGNITE-15629 Review fixes.
nizhikov May 3, 2023
0c13b0f
IGNITE-15629 Review fixes.
nizhikov May 3, 2023
c545919
IGNITE-15629 Review fixes.
nizhikov May 3, 2023
5637de6
IGNITE-15629 Review fixes.
nizhikov May 3, 2023
db6abc3
Merge branch 'IGNITE-15629-shutdown-policy' into IGNITE-15629-wal
nizhikov May 3, 2023
02ab436
IGNITE-15629 WAL commands implemented
nizhikov May 3, 2023
8fcf300
Merge branch 'IGNITE-15629-wal' into IGNITE-15629-local-commands
nizhikov May 3, 2023
84cce67
Merge branch 'IGNITE-15629' into IGNITE-15629-shutdown-policy
nizhikov May 3, 2023
4771fda
Merge branch 'IGNITE-15629-shutdown-policy' into IGNITE-15629-wal
nizhikov May 3, 2023
6fcfd8b
Merge branch 'IGNITE-15629-wal' into IGNITE-15629-local-commands
nizhikov May 3, 2023
3958abc
IGNITE-15629-local-commands
nizhikov May 3, 2023
3aab881
Merge branch 'IGNITE-15629-local-commands' into IGNITE-15629-defragme…
nizhikov May 3, 2023
4ba7e96
IGNITE-15629 defragmentation command
nizhikov May 3, 2023
a2cd287
Merge branch 'IGNITE-15629' into IGNITE-15629-wal
nizhikov May 3, 2023
08d8afd
IGNITE-15629 API simplification
nizhikov May 3, 2023
c1d5411
IGNITE-15629 API simplification
nizhikov May 3, 2023
8579076
IGNITE-15629 API simplification
nizhikov May 3, 2023
a338593
Merge branch 'IGNITE-15629-wal' into IGNITE-15629-local-commands
nizhikov May 3, 2023
7e4e9b0
IGNITE-15629 Local commands implemented
nizhikov May 3, 2023
99c2168
IGNITE-15629 Defragmentation command implemented
nizhikov May 3, 2023
272dce9
IGNITE-15629 Defragmentation command implemented
nizhikov May 3, 2023
12c2e65
Merge branch 'IGNITE-15629' into IGNITE-15629-local-commands
nizhikov May 4, 2023
8458aff
IGNITE-15629 Local commands implemented
nizhikov May 4, 2023
8f34d7d
IGNITE-15629 Local commands implemented
nizhikov May 4, 2023
0c97528
IGNITE-15629 Local commands implemented
nizhikov May 4, 2023
442b3cf
IGNITE-15629 Local commands implemented
nizhikov May 4, 2023
20b68ed
IGNITE-15629 Local commands implemented
nizhikov May 5, 2023
c9e57bd
Merge branch 'IGNITE-15629-local-commands' into IGNITE-15629-defragme…
nizhikov May 5, 2023
d238c6d
IGNITE-15629 Defragmentation commands implemented
nizhikov May 5, 2023
6fcae7f
Merge branch 'IGNITE-15629' into IGNITE-15629-defragmentation
nizhikov May 5, 2023
ae63424
IGNITE-15629 Code review fixes.
nizhikov May 5, 2023
ed0c020
Merge branch 'IGNITE-15629-local-commands' into IGNITE-15629-defragme…
nizhikov May 5, 2023
d9345b7
IGNITE-15629 Code review fixes.
nizhikov May 5, 2023
3e6ec12
Merge branch 'IGNITE-15629' into IGNITE-15629-defragmentation
nizhikov May 5, 2023
5ed6260
Merge branch 'IGNITE-15629' into IGNITE-15629-defragmentation
nizhikov May 5, 2023
c0ed2a9
IGNITE-15629 Defragmentation command implemented
nizhikov May 5, 2023
3779300
IGNITE-15629 Consistency command implemented
nizhikov May 10, 2023
5486bee
IGNITE-15629 Persistence command implemented
nizhikov May 10, 2023
34d95b8
IGNITE-15629 Persistence commands implemented
nizhikov May 10, 2023
e57b5cd
IGNITE-15629 Baseline commands implemented
nizhikov May 10, 2023
f1087b6
IGNITE-15629 Baseline commands implemented
nizhikov May 11, 2023
a07f105
IGNITE-15629 Baseline commands implemented
nizhikov May 11, 2023
fe24c6d
IGNITE-15629 Baseline commands implemented
nizhikov May 11, 2023
abca26a
IGNITE-15629 Baseline commands implemented
nizhikov May 11, 2023
b4bd8d4
IGNITE-15629 Tx commands implemented
nizhikov May 12, 2023
1ae5cfe
IGNITE-15629 Tx commands implemented
nizhikov May 15, 2023
ca91c21
IGNITE-15629 Tx commands implemented
nizhikov May 15, 2023
8c77c17
IGNITE-15629 Tx commands implemented
nizhikov May 15, 2023
6c57953
Merge branch 'IGNITE-15629' into IGNITE-15629-tx
nizhikov May 15, 2023
e28f3fe
IGNITE-15629 Stop warm-up command implemented
nizhikov May 15, 2023
2dda901
IGNITE-15629 Diagnostic command implemented
nizhikov May 15, 2023
9e6bc5f
IGNITE-15629 Diagnostic command implemented
nizhikov May 16, 2023
b61501f
IGNITE-15629 Code review fixes
nizhikov May 16, 2023
97c0ece
Merge branch 'IGNITE-15629' into IGNITE-15629-baseline
nizhikov May 16, 2023
24e63f9
IGNITE-15629 Code review fixes
nizhikov May 16, 2023
2ced4e3
IGNITE-15629 Code review fixes
nizhikov May 16, 2023
8236e69
Merge branch 'IGNITE-15629-baseline' into IGNITE-15629-diagnostic
nizhikov May 16, 2023
fd92259
IGNITE-15629 Fixes
nizhikov May 16, 2023
5e8b662
Merge branch 'IGNITE-15629' into IGNITE-15629-tx
nizhikov May 16, 2023
1acf148
IGNITE-15629 Code review fixes
nizhikov May 16, 2023
0dcb32b
IGNITE-15629 Code review fixes
nizhikov May 17, 2023
b00ada8
IGNITE-15629 Code review fixes
nizhikov May 17, 2023
50e6ea3
Merge branch 'IGNITE-15629-tx' into IGNITE-15629-warmup
nizhikov May 17, 2023
a237f38
IGNITE-15629 Code review fixes
nizhikov May 17, 2023
9be2378
Merge branch 'IGNITE-15629-warmup' into IGNITE-15629-diagnostic
nizhikov May 17, 2023
51cfb04
IGNITE-15629 Code review fixes
nizhikov May 17, 2023
ea22710
IGNITE-15629 Code review fixes
nizhikov May 17, 2023
04f8fac
Merge branch 'IGNITE-15629-diagnostic' into IGNITE-15629-metric
nizhikov May 17, 2023
c71cfed
IGNITE-15629 Metric command implemented
nizhikov May 17, 2023
adb599c
IGNITE-15629 Metric command implemented
nizhikov May 17, 2023
285a454
IGNITE-15629 Tracing configuration command implemented
nizhikov May 17, 2023
75ed932
IGNITE-15629 Metric command implemented
nizhikov May 17, 2023
edc6ac4
Merge branch 'IGNITE-15629-metric' into IGNITE-15629-tracing
nizhikov May 17, 2023
814cfe7
IGNITE-15629 Metric command implemented
nizhikov May 17, 2023
02c7935
IGNITE-15629 Tracing configuration command implemented
nizhikov May 17, 2023
64fe45c
IGNITE-15629 Tracing configuration command implemented
nizhikov May 17, 2023
48fa7b1
Merge branch 'IGNITE-15629-tracing' into IGNITE-15629-consistency
nizhikov May 17, 2023
9509bc1
IGNITE-15629 Consistence command implemented
nizhikov May 17, 2023
602de94
IGNITE-15629 Consistence command implemented
nizhikov May 18, 2023
3369b57
Merge branch 'IGNITE-15629' into IGNITE-15629-consistency
nizhikov May 18, 2023
25c3832
IGNITE-15629 Consistence command implemented
nizhikov May 19, 2023
c716337
Merge branch 'IGNITE-15629' into IGNITE-15629-metric
nizhikov May 19, 2023
2c49093
Merge branch 'IGNITE-15629' into IGNITE-15629-tracing
nizhikov May 19, 2023
49358be
IGNITE-15629 Tracing command implemented
nizhikov May 19, 2023
485b459
Merge branch 'IGNITE-15629-tracing' into IGNITE-15629-consistency
nizhikov May 19, 2023
af0d4b1
IGNITE-15629 Tracing command implemented
nizhikov May 19, 2023
09ca4cf
IGNITE-15629 Snapshot command implemented
nizhikov May 19, 2023
d28bd28
IGNITE-15629 Consistence command implemented
nizhikov May 19, 2023
fd318b9
Merge branch 'IGNITE-15629-consistency' into IGNITE-15629-snapshot
nizhikov May 19, 2023
336c306
IGNITE-15629 Consistence command implemented
nizhikov May 19, 2023
9074a8d
Merge branch 'IGNITE-15629' into IGNITE-15629-tracing
nizhikov May 19, 2023
d231254
Merge branch 'IGNITE-15629-tracing' into IGNITE-15629-consistency
nizhikov May 19, 2023
d328360
Merge branch 'IGNITE-15629-consistency' into IGNITE-15629-snapshot
nizhikov May 19, 2023
ace6ed1
IGNITE-15629 Snapshot command implemented
nizhikov May 22, 2023
05f0a72
IGNITE-15629 Snapshot command implemented
nizhikov May 22, 2023
9869f3a
IGNITE-15629 Snapshot command implemented
nizhikov May 22, 2023
85469dd
IGNITE-15629 Cache destroy command implemented
nizhikov May 23, 2023
ca10158
Merge branch 'IGNITE-15629' into IGNITE-15629-consistency
nizhikov May 23, 2023
e5a7e55
Merge branch 'IGNITE-15629-consistency' into IGNITE-15629-snapshot
nizhikov May 23, 2023
a9e92a7
Merge branch 'IGNITE-15629-snapshot' into IGNITE-15629-cache-destroy
nizhikov May 23, 2023
83f257f
IGNITE-15629 Cache destroy command implemented
nizhikov May 23, 2023
a9b10a6
Merge branch 'IGNITE-15629' into IGNITE-15629-snapshot
nizhikov May 23, 2023
41c8f2b
Merge branch 'IGNITE-15629-snapshot' into IGNITE-15629-cache-destroy
nizhikov May 23, 2023
4d8312a
Merge branch 'IGNITE-15629' into IGNITE-15629-cache-destroy
nizhikov May 23, 2023
803041f
IGNITE-15629 Destroy cache command implemented
nizhikov May 25, 2023
f5daacc
IGNITE-15629 Indexes commands implemented
nizhikov May 25, 2023
fcf620b
IGNITE-15629 Indexes commands implemented
nizhikov May 25, 2023
c5ce904
IGNITE-15629 Indexes commands implemented
nizhikov May 25, 2023
78f2222
IGNITE-15629 Indexes commands implemented
nizhikov May 26, 2023
deb4ded
Merge branch 'IGNITE-15629' into IGNITE-15629-cache-index-rebuild
nizhikov May 26, 2023
3b74128
IGNITE-15629 Indexes commands implemented
nizhikov May 26, 2023
4582fc0
IGNITE-15629 Indexes commands implemented
nizhikov May 26, 2023
d568a50
IGNITE-15629 Cache clear command implemented
nizhikov May 26, 2023
77ce1de
IGNITE-15629 Cache create command implemented
nizhikov May 26, 2023
200e70e
IGNITE-15629 Cache clear/create/list commands implemented
nizhikov May 26, 2023
3bc0d33
IGNITE-15629 Cache index_list commands implemented
nizhikov May 26, 2023
5393e6d
IGNITE-15629 Cache validate_indexes commands implemented
nizhikov May 27, 2023
7cfbb1e
IGNITE-15629 Cache validate_indexes commands implemented
nizhikov May 27, 2023
79fa95f
IGNITE-15629 Cache check_index_inline_sizes commands implemented
nizhikov May 27, 2023
cfd2b97
IGNITE-15629 Cache reset_lost_partitions commands implemented
nizhikov May 27, 2023
ce4846f
IGNITE-15629 Cache contention commands implemented
nizhikov May 28, 2023
d379cf0
IGNITE-15629 Cache metrics command implemented
nizhikov May 28, 2023
9eaae91
IGNITE-19628 Add IndexQuery to performance statistics
NSAmelchev Jun 1, 2023
6d02219
Revert "IGNITE-19628 Add IndexQuery to performance statistics"
NSAmelchev Jun 1, 2023
b05c853
Merge branch 'master' into IGNITE-15629
nizhikov Jun 2, 2023
4ca9265
Merge branch 'IGNITE-15629' into IGNITE-15629-cache-metrics
nizhikov Jun 2, 2023
634418b
IGNITE-15629 Code cleanup
nizhikov Jun 2, 2023
d799f93
IGNITE-15629 Code cleanup
nizhikov Jun 2, 2023
e3574dc
IGNITE-15629 Code cleanup
nizhikov Jun 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

This file was deleted.

Expand Up @@ -33,6 +33,7 @@
import org.apache.ignite.internal.management.cache.CacheIndexesListCommand;
import org.apache.ignite.internal.management.cache.CacheIndexesRebuildStatusCommand;
import org.apache.ignite.internal.management.cache.CacheListCommand;
import org.apache.ignite.internal.management.cache.CacheMetricsCommand;
import org.apache.ignite.internal.management.cache.CacheResetLostPartitionsCommand;
import org.apache.ignite.internal.management.cache.CacheScheduleIndexesRebuildCommand;
import org.apache.ignite.internal.management.cache.CacheValidateIndexesCommand;
Expand Down Expand Up @@ -122,7 +123,7 @@ public enum CacheSubcommands {
/**
* Enable / disable cache metrics collection or show metrics collection status.
*/
METRICS("metrics", null, new CacheMetrics()),
METRICS(new CacheMetricsCommand()),

/**
* Index rebuild via the maintenance mode.
Expand Down
Expand Up @@ -23,7 +23,7 @@
import java.util.regex.Pattern;
import org.apache.ignite.Ignite;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.commandline.cache.CacheMetrics;
import org.apache.ignite.internal.management.cache.CacheMetricsCommand;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.G;
import org.apache.ignite.internal.visor.cache.metrics.CacheMetricsOperation;
Expand All @@ -34,16 +34,11 @@
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR;
import static org.apache.ignite.internal.commandline.CommandList.CACHE;
import static org.apache.ignite.internal.commandline.cache.CacheMetrics.ALL_CACHES_ARGUMENT;
import static org.apache.ignite.internal.commandline.cache.CacheMetrics.CACHES_ARGUMENT;
import static org.apache.ignite.internal.commandline.cache.CacheMetrics.EXPECTED_CACHES_LIST_MESSAGE;
import static org.apache.ignite.internal.commandline.cache.CacheMetrics.INCORRECT_CACHE_ARGUMENT_MESSAGE;
import static org.apache.ignite.internal.commandline.cache.CacheMetrics.INCORRECT_METRICS_OPERATION_MESSAGE;
import static org.apache.ignite.internal.commandline.cache.CacheSubcommands.METRICS;
import static org.apache.ignite.internal.util.lang.GridFunc.asMap;

/**
* Test for {@link CacheMetrics} command.
* Test for {@link CacheMetricsCommand} command.
*/
public class CacheMetricsCommandTest extends GridCommandHandlerAbstractTest {
/** Enable operation. */
Expand All @@ -61,6 +56,21 @@ public class CacheMetricsCommandTest extends GridCommandHandlerAbstractTest {
/** Cache two. */
private static final String CACHE_TWO = "cache-2";

/** */
private static final String ALL_CACHES_ARGUMENT = "--all-caches";

/** */
private static final String CACHES_ARGUMENT = "--caches";

/** Incorrect metrics operation message. */
public static final String INCORRECT_METRICS_OPERATION_MESSAGE = "Argument operation required";

/** Expected caches list message. */
public static final String EXPECTED_CACHES_LIST_MESSAGE = "Please specify a value for argument: --caches";

/** Incorrect cache argument message. */
public static final String INCORRECT_CACHE_ARGUMENT_MESSAGE = "One of [--all-caches, --caches] required";

/** {@inheritDoc} */
@Override public void beforeTest() throws Exception {
super.beforeTest();
Expand Down Expand Up @@ -148,34 +158,34 @@ public void testInvalidArguments() {
checkInvalidArguments(checkArgs + INCORRECT_METRICS_OPERATION_MESSAGE);

// Check when unknown operation passed
checkInvalidArguments(checkArgs + INCORRECT_METRICS_OPERATION_MESSAGE, "bad-command");
checkInvalidArguments(checkArgs + "Can't parse value 'bad-command'", "bad-command");

// Check when no --caches/--all-caches arguments passed
checkInvalidArguments(checkArgs + INCORRECT_CACHE_ARGUMENT_MESSAGE, ENABLE);
checkInvalidArguments(checkArgs + INCORRECT_CACHE_ARGUMENT_MESSAGE, STATUS);

String invalidCacheListFullMsg = "Check arguments. Expected " + EXPECTED_CACHES_LIST_MESSAGE;
String invalidCacheListFullMsg = checkArgs + EXPECTED_CACHES_LIST_MESSAGE;

// Check when --caches argument passed without list of caches
checkInvalidArguments(invalidCacheListFullMsg, ENABLE, CACHES_ARGUMENT);
checkInvalidArguments(invalidCacheListFullMsg, STATUS, CACHES_ARGUMENT);

String incorrectCacheArgFullMsg = checkArgs + INCORRECT_CACHE_ARGUMENT_MESSAGE;
String incorrectCacheArgFullMsg = checkArgs + "Unexpected argument: --arg";

// Check when unknown argument is passed after metric operation
checkInvalidArguments(incorrectCacheArgFullMsg, ENABLE, "--arg");
checkInvalidArguments(incorrectCacheArgFullMsg, STATUS, "--arg");

String unexpectedCacheArgMsg = "Unexpected argument of --cache subcommand: ";
String unexpectedCacheArgMsg = checkArgs + "Only one of [--all-caches, --caches] allowed";

// Check when extra argument passed after correct command
checkInvalidArguments(unexpectedCacheArgMsg + ALL_CACHES_ARGUMENT, ENABLE, CACHES_ARGUMENT, CACHE_ONE,
checkInvalidArguments(unexpectedCacheArgMsg, ENABLE, CACHES_ARGUMENT, CACHE_ONE,
ALL_CACHES_ARGUMENT);
checkInvalidArguments(unexpectedCacheArgMsg + CACHES_ARGUMENT, STATUS, ALL_CACHES_ARGUMENT, CACHES_ARGUMENT,
checkInvalidArguments(unexpectedCacheArgMsg, STATUS, ALL_CACHES_ARGUMENT, CACHES_ARGUMENT,
CACHE_ONE);

// Check when after --caches argument extra argument is passed instead of list of caches
checkInvalidArguments(unexpectedCacheArgMsg + ALL_CACHES_ARGUMENT, ENABLE, CACHES_ARGUMENT, ALL_CACHES_ARGUMENT);
checkInvalidArguments("Unexpected value: --all-caches", ENABLE, CACHES_ARGUMENT, ALL_CACHES_ARGUMENT);
}

/**
Expand Down
Expand Up @@ -1247,7 +1247,7 @@ public void testCacheCreate() {

assertContains(log, executeCommand(EXIT_CODE_INVALID_ARGUMENTS,
"--cache", CacheSubcommands.CREATE.name(), SPRING_XML_CONFIG),
"Please specify a value for argument: --springxmlconfig");
"Please specify a value for argument: --springXmlConfig");

autoConfirmation = true;

Expand Down
Expand Up @@ -407,8 +407,14 @@ else if (type == UUID.class) {
else if (type == IgniteUuid.class) {
return (T)IgniteUuid.fromString(val);
}
else if (type.isEnum())
return (T)Enum.valueOf((Class<Enum>)type, val.toUpperCase());
else if (type.isEnum()) {
try {
return (T)Enum.valueOf((Class<Enum>)type, val.toUpperCase());
}
catch (IllegalArgumentException e) {
throw new IllegalArgumentException("Can't parse value '" + val + "', expected type: " + type.getName());
}
}

throw new IgniteException("Unsupported argument type: " + type.getName());
}
Expand Down
Expand Up @@ -35,6 +35,7 @@ public CacheCommand() {
new CacheContentionCommand(),
new CacheResetLostPartitionsCommand(),
new CacheIndexesListCommand(),
new CacheMetricsCommand(),
new CacheIndexesRebuildStatusCommand(),
new CacheIndexesForceRebuildCommand(),
new CacheScheduleIndexesRebuildCommand()
Expand Down
@@ -0,0 +1,62 @@
/*
* 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.management.cache;

import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.management.api.ComputeCommand;
import org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsTask;
import org.apache.ignite.internal.visor.cache.metrics.VisorCacheMetricsTaskResult;
import static java.util.Arrays.asList;
import static org.apache.ignite.internal.management.SystemViewCommand.printTable;
import static org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleType.STRING;

/** */
public class CacheMetricsCommand implements ComputeCommand<CacheMetricsCommandArg, VisorCacheMetricsTaskResult> {
/** {@inheritDoc} */
@Override public String description() {
return "Manages user cache metrics collection: enables, disables it or shows status";
}

/** {@inheritDoc} */
@Override public Class<CacheMetricsCommandArg> argClass() {
return CacheMetricsCommandArg.class;
}

/** {@inheritDoc} */
@Override public Class<VisorCacheMetricsTask> taskClass() {
return VisorCacheMetricsTask.class;
}

/** {@inheritDoc} */
@Override public void printResult(CacheMetricsCommandArg arg, VisorCacheMetricsTaskResult res, Consumer<String> printer) {
try {
List<List<?>> values = res.result().entrySet()
.stream()
.map(e -> asList(e.getKey(), e.getValue() ? "enabled" : "disabled"))
.collect(Collectors.toList());

printTable(asList("Cache Name", "Metrics Status"), asList(STRING, STRING), values, printer);
}
catch (Exception e) {
throw new IgniteException(e);
}
}
}