Skip to content

Commit

Permalink
GG-18750: Incorrect formatting of idle_verify output
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-chudov committed Jun 13, 2019
1 parent 865fdad commit 9f20fb9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.apache.ignite.IgniteException;
Expand All @@ -41,6 +42,7 @@
import org.apache.ignite.internal.processors.cache.verify.PartitionKey;
import org.apache.ignite.internal.processors.cache.verify.VerifyBackupPartitionsTaskV2;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.SB;
import org.apache.ignite.internal.visor.verify.CacheFilterEnum;
import org.apache.ignite.internal.visor.verify.VisorIdleVerifyDumpTask;
import org.apache.ignite.internal.visor.verify.VisorIdleVerifyDumpTaskArg;
Expand Down Expand Up @@ -319,6 +321,8 @@ private void cacheIdleVerifyDump(

String path = executeTask(client, VisorIdleVerifyDumpTask.class, arg, clientCfg);

logParsedArgs(arg, logger::info);

logger.info("VisorIdleVerifyDumpTask successfully written output to '" + path + "'");
}

Expand All @@ -332,22 +336,42 @@ private void cacheIdleVerifyV2(
GridClientConfiguration clientCfg,
Logger log
) throws GridClientException {
IdleVerifyResultV2 res = executeTask(
client,
VisorIdleVerifyTaskV2.class,
new VisorIdleVerifyTaskArg(
args.caches(),
args.excludeCaches(),
args.isSkipZeros(),
args.getCacheFilterEnum(),
args.idleCheckCrc()
),
clientCfg
VisorIdleVerifyTaskArg taskArg = new VisorIdleVerifyTaskArg(
args.caches(),
args.excludeCaches(),
args.isSkipZeros(),
args.getCacheFilterEnum(),
args.idleCheckCrc()
);

IdleVerifyResultV2 res = executeTask(client, VisorIdleVerifyTaskV2.class, taskArg, clientCfg);

logParsedArgs(taskArg, log::info);

res.print(log::info);
}

/**
* Passes idle_verify parsed arguments to given log consumer.
*
* @param args idle_verify arguments.
* @param logConsumer Logger.
*/
public static void logParsedArgs(VisorIdleVerifyTaskArg args, Consumer<String> logConsumer) {
SB options = new SB("idle_verify task was executed with the following args: ");

options
.a("caches=[")
.a(args.caches() == null ? "" : String.join(", ", args.caches()))
.a("], excluded=[")
.a(args.excludeCaches() == null ? "" : String.join(", ", args.excludeCaches()))
.a("]")
.a(", cacheFilter=[")
.a(args.cacheFilterEnum().toString())
.a("]\n");

logConsumer.accept(options.toString());
}

/**
* @param client Client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,25 @@ private void print(Consumer<String> printer, boolean printExceptionMessages) {
}
}
else {
printer.accept("idle_verify failed.");
printer.accept("\nidle_verify failed.\n");

if (noMatchingCaches)
printer.accept("There are no caches matching given filter options.");
printer.accept("\nThere are no caches matching given filter options.\n");
}

if (!F.isEmpty(exceptions())) {
printer.accept("Idle verify failed on nodes:\n");
printer.accept("\nIdle verify failed on nodes:\n");

for (Map.Entry<ClusterNode, Exception> e : exceptions().entrySet()) {
ClusterNode n = e.getKey();

printer.accept("Node ID: " + n.id() + " " + n.addresses() + " consistent ID: " + n.consistentId() + "\n");
printer.accept("\nNode ID: " + n.id() + " " + n.addresses() + "\nConsistent ID: " + n.consistentId() + "\n");

if (printExceptionMessages) {
printer.accept("Exception message:" + "\n");
String msg = e.getValue().getMessage();

printer.accept(e.getValue().getMessage() + "\n");
printer.accept("Exception: " + e.getValue().getClass().getCanonicalName() + "\n");
printer.accept(msg == null ? "" : msg + "\n");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@
import org.apache.ignite.compute.ComputeTaskAdapter;
import org.apache.ignite.internal.processors.task.GridInternal;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.visor.verify.CacheFilterEnum;
import org.apache.ignite.internal.visor.verify.VisorIdleVerifyDumpTaskArg;
import org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskArg;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.apache.ignite.resources.LoggerResource;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.commandline.cache.argument.IdleVerifyCommandArg.CACHE_FILTER;
import static org.apache.ignite.internal.commandline.cache.argument.IdleVerifyCommandArg.EXCLUDE_CACHES;
import static org.apache.ignite.internal.commandline.cache.IdleVerify.logParsedArgs;

/**
* Task for collection checksums primary and backup partitions of specified caches. <br> Argument: Set of cache names,
Expand Down Expand Up @@ -227,7 +225,7 @@ private void writeResult(
if (!partitions.isEmpty())
writer.write("idle_verify check has finished, found " + partitions.size() + " partitions\n");

writer.write("idle_verify task was executed with the following args: " + taskArgsAsCmd() + "\n");
logParsedArgs(taskArg, writer::write);

if (skippedRecords > 0)
writer.write(skippedRecords + " partitions was skipped\n");
Expand All @@ -247,40 +245,6 @@ private void writeResult(
}
}

/**
* Method that builds command line string from the taskArg field.
*
* @return command line argument string
*/
private String taskArgsAsCmd() {
StringBuilder result = new StringBuilder();

if (!F.isEmpty(taskArg.caches())) {
for (String cache : taskArg.caches()) {
result.append(cache);
result.append(" ");
}
}

if (taskArg.cacheFilterEnum() != null && taskArg.cacheFilterEnum() != CacheFilterEnum.DEFAULT) {
result.append(CACHE_FILTER);
result.append(" ");
result.append(taskArg.cacheFilterEnum());
result.append(" ");
}

if (!F.isEmpty(taskArg.excludeCaches())) {
result.append(EXCLUDE_CACHES + " ");

for (String excluded : taskArg.excludeCaches()) {
result.append(excluded);
result.append(" ");
}
}

return result.toString();
}

/**
* @return Comparator for {@link PartitionHashRecordV2}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ public void testCacheIdleVerifyMultipleCacheFilterOptions()
testCacheIdleVerifyMultipleCacheFilterOptionsCommon(
true,
"idle_verify check has finished, found",
"idle_verify task was executed with the following args: --cache-filter SYSTEM --exclude-caches wrong.* ",
"idle_verify task was executed with the following args: caches=[], excluded=[wrong.*], cacheFilter=[SYSTEM]",
"--cache", "idle_verify", "--dump", "--cache-filter", "SYSTEM", "--exclude-caches", "wrong.*"
);
testCacheIdleVerifyMultipleCacheFilterOptionsCommon(
Expand Down Expand Up @@ -1529,7 +1529,7 @@ public void testCacheIdleVerifyMultipleCacheFilterOptions()
);
testCacheIdleVerifyMultipleCacheFilterOptionsCommon(
true,
"There are no caches matching given filter options.",
"There are no caches matching given filter options",
null,
"--cache", "idle_verify", "--exclude-caches", ".*"
);
Expand Down Expand Up @@ -2126,7 +2126,7 @@ public void testCacheIdleVerifyDumpExcludedCacheGrp() throws Exception {
if (fileNameMatcher.find()) {
String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1))));

assertContains(log, dumpWithConflicts, "There are no caches matching given filter options.");
assertContains(log, dumpWithConflicts, "There are no caches matching given filter options");
}
else
fail("Should be found dump with conflicts");
Expand Down

0 comments on commit 9f20fb9

Please sign in to comment.