This is an automated email from the ASF dual-hosted git repository. timoninmaxim pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push: new e441d91e793 IGNITE-17384 Print partition conflicts into control-utility.log (#10438) e441d91e793 is described below commit e441d91e7934623b292221b532a205e75124401b Author: Ilhom <ilhom.ulma...@gmail.com> AuthorDate: Mon Dec 19 11:35:03 2022 +0300 IGNITE-17384 Print partition conflicts into control-utility.log (#10438) --- .../internal/commandline/cache/IdleVerify.java | 25 ++++++++-------- .../util/GridCommandHandlerClusterByClassTest.java | 33 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/IdleVerify.java b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/IdleVerify.java index 1a0d32ae982..61659fb00b7 100644 --- a/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/IdleVerify.java +++ b/modules/control-utility/src/main/java/org/apache/ignite/internal/commandline/cache/IdleVerify.java @@ -213,7 +213,7 @@ public class IdleVerify extends AbstractCommand<IdleVerify.Arguments> { if (args.dump()) cacheIdleVerifyDump(client, clientCfg, logger); else if (idleVerifyV2) - cacheIdleVerifyV2(client, clientCfg); + cacheIdleVerifyV2(client, clientCfg, logger); else legacyCacheIdleVerify(client, clientCfg, logger); } @@ -320,10 +320,12 @@ public class IdleVerify extends AbstractCommand<IdleVerify.Arguments> { /** * @param client Client. * @param clientCfg Client configuration. + * @param logger Logger to use. */ private void cacheIdleVerifyV2( GridClient client, - GridClientConfiguration clientCfg + GridClientConfiguration clientCfg, + IgniteLogger logger ) throws GridClientException { VisorIdleVerifyTaskArg taskArg = new VisorIdleVerifyTaskArg( args.caches(), @@ -335,10 +337,13 @@ public class IdleVerify extends AbstractCommand<IdleVerify.Arguments> { IdleVerifyResultV2 res = executeTask(client, VisorIdleVerifyTaskV2.class, taskArg, clientCfg); - logParsedArgs(taskArg, System.out::print); - res.print(System.out::print, false); + logParsedArgs(taskArg, logger::info); + + StringBuilder sb = new StringBuilder(); + res.print(sb::append, false); + logger.info(sb.toString()); - if (F.isEmpty(res.exceptions())) + if (F.isEmpty(res.exceptions()) && !res.hasConflicts()) return; try { @@ -349,18 +354,14 @@ public class IdleVerify extends AbstractCommand<IdleVerify.Arguments> { res.print(pw::print, true); pw.flush(); - System.out.println("See log for additional information. " + f.getAbsolutePath()); + logger.info("See log for additional information. " + f.getAbsolutePath()); } catch (FileNotFoundException e) { - System.err.println("Can't write exceptions to file " + f.getAbsolutePath() + " " + e.getMessage()); - - e.printStackTrace(); + logger.error("Can't write exceptions to file " + f.getAbsolutePath(), e); } } catch (IgniteCheckedException e) { - System.err.println("Can't find work directory. " + e.getMessage()); - - e.printStackTrace(); + logger.error("Can't find work directory. " + e.getMessage(), e); } } diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java index 657ebc3a18b..d40f05bfcbb 100644 --- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java +++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java @@ -490,6 +490,39 @@ public class GridCommandHandlerClusterByClassTest extends GridCommandHandlerClus ); } + /** */ + @Test + public void testCacheIdleVerifyDumpFile() throws IOException { + IgniteEx ignite = crd; + + createCacheAndPreload(ignite, 100); + + injectTestSystemOut(); + + HashSet<Integer> clearKeys = new HashSet<>(asList(1, 2, 3, 4, 5, 6)); + + ignite.context().cache().cache(DEFAULT_CACHE_NAME).clearLocallyAll(clearKeys, true, true, true); + + assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify")); + + Pattern fileNamePattern = Pattern.compile("See log for additional information. (.*)"); + Matcher matcher = fileNamePattern.matcher(testOut.toString()); + + if (matcher.find()) { + String fileContent = new String(Files.readAllBytes(Paths.get(matcher.group(1)))); + String out = testOut.toString(); + + assertContains(log, out, fileContent); + + String summaryStr = "Total:" + nl() + DEFAULT_CACHE_NAME + " (6)" + nl() + "1,2,3,4,5,6" + nl(); + + assertContains(log, fileContent, "conflict partitions"); + assertContains(log, fileContent, summaryStr); + } + else + fail("Should contain file name"); + } + /** */ @Test public void testCacheIdleVerifyNodeFilter() {