davsclaus commented on code in PR #27537: URL: https://github.com/apache/camel/pull/27537#discussion_r4215908428
########## dsl/camel-jbang/camel-jbang-core/src/main/resources/log4j2-infra.properties: ########## @@ -0,0 +1,44 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +# camel infra run: the progress of pulling the container image, as plain lines, and errors +status = warn +name = CamelInfraLog4jConfiguration + +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = %m%n + +appender.pull.type = Console +appender.pull.name = pull +appender.pull.layout.type = PatternLayout +appender.pull.layout.pattern = %m%n +# only the pull messages of Testcontainers, not the creating and starting of the container +appender.pull.filter.pull.type = RegexFilter +appender.pull.filter.pull.regex = (Pulling docker image|Pulling image layers|Pull complete|Retrying pull|Failed to pull|Docker image pull).* Review Comment: Done in 33aab424cb90. ########## dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/LaunchManager.java: ########## @@ -559,6 +564,57 @@ LaunchOutcome outcome(String name) { /** What Camel prints when it has started, whatever the runtime: the start did not fail. */ static final Pattern STARTED = Pattern.compile("Apache Camel \\S+ \\(.*\\) started in"); + /** What camel infra run prints while it pulls the image of a service (the pull progress of Testcontainers). */ + static final Pattern PULL_PROGRESS = Pattern.compile( + "Pulling image layers:\\s*(\\d+) pending,\\s*(\\d+) downloaded,\\s*\\d+ extracted, \\((.+?)/(.+?)\\)"); + private static final Pattern SIZE = Pattern.compile("(\\d+(?:\\.\\d+)?) (bytes|KB|MB|GB|TB)"); + + /** + * The progress of an image pull in the given output, from its last progress line, such as {@code 2 of 4 layers, + * 22 MB}, or {@code 2 of 4 layers, 1 GB of 3 GB (33%)} once the total is known: Docker reports the size of a layer + * only when it starts on it. Null when the output has no progress, or the pull has completed since. + */ + static String pullProgress(String text) { + var m = PULL_PROGRESS.matcher(text); + String answer = null; + int last = -1; + while (m.find()) { + last = m.start(); + int pending = Integer.parseInt(m.group(1)); + int downloaded = Integer.parseInt(m.group(2)); + String done = m.group(3).trim(); + String total = m.group(4).trim(); + if (pending + downloaded == 0) { + // no layer reported yet + continue; + } + StringBuilder sb = new StringBuilder(); + sb.append(downloaded).append(" of ").append(pending + downloaded).append(" layers, ").append(done); + long doneBytes = bytes(done); + long totalBytes = bytes(total); + if (doneBytes >= 0 && totalBytes > 0) { + sb.append(" of ").append(total).append(" (").append(Math.min(100, doneBytes * 100 / totalBytes)) + .append("%)"); + } + answer = sb.toString(); + } + if (answer != null && text.lastIndexOf("Pull complete") > last) { + return null; + } + return answer; + } + + /** The bytes of a size as Testcontainers prints it (such as 22 MB), or -1 when it is not known (? MB). */ + private static long bytes(String size) { + var m = SIZE.matcher(size); + if (!m.matches()) { + return -1; + } + double n = Double.parseDouble(m.group(1)); + int power = List.of("bytes", "KB", "MB", "GB", "TB").indexOf(m.group(2)); + return (long) (n * Math.pow(1024, power)); Review Comment: Done in 33aab424cb90. -- 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]
