Skip to content

Commit

Permalink
Merge pull request #25344 from gsmet/2.9.0-backports-1
Browse files Browse the repository at this point in the history
2.9.0 backports 1
  • Loading branch information
gsmet authored May 3, 2022
2 parents 7eddb34 + 3556287 commit 9acab81
Show file tree
Hide file tree
Showing 132 changed files with 1,907 additions and 338 deletions.
19 changes: 15 additions & 4 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<cronutils.version>9.1.6</cronutils.version>
<quartz.version>2.3.2</quartz.version>
<h2.version>2.1.210</h2.version>
<postgresql-jdbc.version>42.3.4</postgresql-jdbc.version>
<postgresql-jdbc.version>42.3.3</postgresql-jdbc.version>
<mariadb-jdbc.version>3.0.4</mariadb-jdbc.version>
<mysql-jdbc.version>8.0.29</mysql-jdbc.version>
<mssql-jdbc.version>7.2.2.jre8</mssql-jdbc.version>
Expand All @@ -127,8 +127,8 @@
<junit.jupiter.version>5.8.2</junit.jupiter.version>
<junit-pioneer.version>1.5.0</junit-pioneer.version>
<testng.version>6.14.2</testng.version>
<infinispan.version>13.0.8.Final</infinispan.version>
<infinispan.protostream.version>4.4.1.Final</infinispan.protostream.version>
<infinispan.version>13.0.9.Final</infinispan.version>
<infinispan.protostream.version>4.4.3.Final</infinispan.protostream.version>
<caffeine.version>2.9.3</caffeine.version>
<netty.version>4.1.74.Final</netty.version>
<reactive-streams.version>1.0.3</reactive-streams.version>
Expand All @@ -152,7 +152,7 @@
<maven-invoker.version>3.1.0</maven-invoker.version>
<awaitility.version>4.2.0</awaitility.version>
<jboss-logmanager.version>1.0.9</jboss-logmanager.version>
<flyway.version>8.5.9</flyway.version>
<flyway.version>8.5.10</flyway.version>
<yasson.version>1.0.11</yasson.version>
<liquibase.version>4.9.1</liquibase.version>
<snakeyaml.version>1.30</snakeyaml.version>
Expand Down Expand Up @@ -317,6 +317,17 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- OpenTelemetry components, imported as a BOM -->
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- Quarkus uses jboss-parent and it comes with 3.8.1-jboss-1, we don't want that in the templates -->
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<kotlin.version>1.6.21</kotlin.version>
<dokka.version>1.6.10</dokka.version>
<dokka.version>1.6.21</dokka.version>
<scala.version>2.13.8</scala.version>
<scala-maven-plugin.version>4.6.1</scala-maven-plugin.version>
<!-- not pretty but this is used in the codestarts and we don't want to break compatibility -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.DockerStatusBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;

public class DockerStatusProcessor {

@BuildStep
DockerStatusBuildItem IsDockerWorking(LaunchModeBuildItem launchMode) {
return new DockerStatusBuildItem(new IsDockerWorking(launchMode.getLaunchMode().isDevOrTest()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.function.BooleanSupplier;
Expand All @@ -25,6 +27,8 @@
public class IsDockerWorking implements BooleanSupplier {

private static final Logger LOGGER = Logger.getLogger(IsDockerWorking.class.getName());
public static final int DOCKER_HOST_CHECK_TIMEOUT = 1000;
public static final int DOCKER_CMD_CHECK_TIMEOUT = 3000;

private final List<Strategy> strategies;

Expand All @@ -40,6 +44,7 @@ public IsDockerWorking(boolean silent) {
@Override
public boolean getAsBoolean() {
for (Strategy strategy : strategies) {
LOGGER.debugf("Checking Docker Environment using strategy %s", strategy.getClass().getName());
Result result = strategy.get();
if (result == Result.AVAILABLE) {
return true;
Expand Down Expand Up @@ -113,7 +118,8 @@ public Result get() {
if (dockerHost != null && !dockerHost.startsWith("unix:")) {
try {
URI url = new URI(dockerHost);
try (Socket s = new Socket(url.getHost(), url.getPort())) {
try (Socket s = new Socket()) {
s.connect(new InetSocketAddress(url.getHost(), url.getPort()), DOCKER_HOST_CHECK_TIMEOUT);
return Result.AVAILABLE;
} catch (IOException e) {
LOGGER.warnf(
Expand Down Expand Up @@ -143,7 +149,7 @@ private DockerBinaryStrategy(boolean silent) {
@Override
public Result get() {
try {
if (!ExecUtil.execSilent(binary, "-v")) {
if (!ExecUtil.execSilentWithTimeout(Duration.ofMillis(DOCKER_CMD_CHECK_TIMEOUT), binary, "-v")) {
LOGGER.warnf("'%s -v' returned an error code. Make sure your Docker binary is correct", binary);
return Result.UNKNOWN;
}
Expand All @@ -154,7 +160,8 @@ public Result get() {

try {
OutputFilter filter = new OutputFilter();
if (ExecUtil.exec(new File("."), filter, "docker", "version", "--format", "'{{.Server.Version}}'")) {
if (ExecUtil.execWithTimeout(new File("."), filter, Duration.ofMillis(DOCKER_CMD_CHECK_TIMEOUT),
"docker", "version", "--format", "'{{.Server.Version}}'")) {
LOGGER.debugf("Docker daemon found. Version: %s", filter.getOutput());
return Result.AVAILABLE;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.deployment.builditem;

import io.quarkus.builder.item.SimpleBuildItem;
import io.quarkus.deployment.IsDockerWorking;

public final class DockerStatusBuildItem extends SimpleBuildItem {

private final IsDockerWorking isDockerWorking;
private Boolean cachedStatus;

public DockerStatusBuildItem(IsDockerWorking isDockerWorking) {
this.isDockerWorking = isDockerWorking;
}

public synchronized boolean isDockerAvailable() {
if (cachedStatus == null) {
cachedStatus = isDockerWorking.getAsBoolean();
}
return cachedStatus;
}
}
130 changes: 122 additions & 8 deletions core/deployment/src/main/java/io/quarkus/deployment/util/ExecUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import org.jboss.logging.Logger;
Expand All @@ -17,6 +19,8 @@ public class ExecUtil {
private static final Function<InputStream, Runnable> PRINT_OUTPUT = i -> new HandleOutput(i);
private static final Function<InputStream, Runnable> SILENT = i -> new HandleOutput(i, Logger.Level.DEBUG);

private static final int PROCESS_CHECK_INTERVAL = 500;

private static class HandleOutput implements Runnable {

private final InputStream is;
Expand Down Expand Up @@ -60,6 +64,18 @@ public static boolean exec(String command, String... args) {
return exec(new File("."), command, args);
}

/**
* Execute the specified command until the given timeout from within the current directory.
*
* @param timeout The timeout
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean execWithTimeout(Duration timeout, String command, String... args) {
return execWithTimeout(new File("."), timeout, command, args);
}

/**
* Execute the specified command from within the current directory and hide the output.
*
Expand All @@ -71,6 +87,18 @@ public static boolean execSilent(String command, String... args) {
return execSilent(new File("."), command, args);
}

/**
* Execute the specified command until the given timeout from within the current directory and hide the output.
*
* @param timeout The timeout
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean execSilentWithTimeout(Duration timeout, String command, String... args) {
return execSilentWithTimeout(new File("."), timeout, command, args);
}

/**
* Execute the specified command from within the specified directory.
*
Expand All @@ -83,6 +111,19 @@ public static boolean exec(File directory, String command, String... args) {
return exec(directory, PRINT_OUTPUT, command, args);
}

/**
* Execute the specified command until the given timeout from within the specified directory.
*
* @param directory The directory
* @param timeout The timeout
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean execWithTimeout(File directory, Duration timeout, String command, String... args) {
return execWithTimeout(directory, PRINT_OUTPUT, timeout, command, args);
}

/**
* Execute the specified command from within the specified directory and hide the output.
*
Expand All @@ -95,6 +136,19 @@ public static boolean execSilent(File directory, String command, String... args)
return exec(directory, SILENT, command, args);
}

/**
* Execute the specified command until the given timeout from within the specified directory and hide the output.
*
* @param directory The directory
* @param timeout The timeout
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean execSilentWithTimeout(File directory, Duration timeout, String command, String... args) {
return execWithTimeout(directory, SILENT, timeout, command, args);
}

/**
* Execute the specified command from within the specified directory.
* The method allows specifying an output filter that processes the command output.
Expand All @@ -107,27 +161,87 @@ public static boolean execSilent(File directory, String command, String... args)
*/
public static boolean exec(File directory, Function<InputStream, Runnable> outputFilterFunction, String command,
String... args) {
Process process = null;
try {
Process process = startProcess(directory, command, args);
outputFilterFunction.apply(process.getInputStream());
process.waitFor();
return process.exitValue() == 0;
} catch (InterruptedException e) {
return false;
}
}

/**
* Execute the specified command until the given timeout from within the specified directory.
* The method allows specifying an output filter that processes the command output.
*
* @param directory The directory
* @param outputFilterFunction A {@link Function} that gets an {@link InputStream} and returns an outputFilter.
* @param timeout The timeout
* @param command The command
* @param args The command arguments
* @return true if commands where executed successfully
*/
public static boolean execWithTimeout(File directory, Function<InputStream, Runnable> outputFilterFunction,
Duration timeout, String command, String... args) {
try {
Process process = startProcess(directory, command, args);
Thread t = new Thread(outputFilterFunction.apply(process.getInputStream()));
t.setName("Process stdout");
t.setDaemon(true);
t.start();
process.waitFor(timeout.toMillis(), TimeUnit.MILLISECONDS);
destroyProcess(process);
return process.exitValue() == 0;
} catch (InterruptedException e) {
return false;
}
}

/**
* Start a process executing given command with arguments within the specified directory.
*
* @param directory The directory
* @param command The command
* @param args The command arguments
* @return the process
*/
public static Process startProcess(File directory, String command, String... args) {
try {
String[] cmd = new String[args.length + 1];
cmd[0] = command;
if (args.length > 0) {
System.arraycopy(args, 0, cmd, 1, args.length);
}
process = new ProcessBuilder()
return new ProcessBuilder()
.directory(directory)
.command(cmd)
.redirectErrorStream(true)
.start();

outputFilterFunction.apply(process.getInputStream()).run();
process.waitFor();
} catch (IOException e) {
throw new RuntimeException("Input/Output error while executing command.", e);
} catch (InterruptedException e) {
return false;
}
return process != null && process.exitValue() == 0;
}

/**
* Kill the process, if still alive, kill it forcibly
*
* @param process the process to kill
*/
public static void destroyProcess(Process process) {
process.destroy();
int i = 0;
while (process.isAlive() && i++ < 10) {
try {
process.waitFor(PROCESS_CHECK_INTERVAL, TimeUnit.MILLISECONDS);
} catch (InterruptedException ignored) {
Thread.currentThread().interrupt();
}
}

if (process.isAlive()) {
process.destroyForcibly();
}
}

}
Loading

0 comments on commit 9acab81

Please sign in to comment.