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

Fix Pulsar DevService network for @QuarkusIntegrationTest for docker-image-building #44265

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Closeable;
import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -21,12 +22,14 @@
import io.quarkus.deployment.builditem.CuratedApplicationShutdownBuildItem;
import io.quarkus.deployment.builditem.DevServicesResultBuildItem;
import io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService;
import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem;
import io.quarkus.deployment.builditem.DockerStatusBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.console.ConsoleInstalledBuildItem;
import io.quarkus.deployment.console.StartupLogCompressor;
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;
import io.quarkus.deployment.logging.LoggingSetupBuildItem;
import io.quarkus.devservices.common.ConfigureUtil;
import io.quarkus.devservices.common.ContainerLocator;
import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigUtils;
Expand All @@ -48,6 +51,7 @@ public class PulsarDevServicesProcessor {

private static final ContainerLocator pulsarContainerLocator = new ContainerLocator(DEV_SERVICE_LABEL,
PulsarContainer.BROKER_PORT);
private static final String DEV_SERVICE_PULSAR = "pulsar";
private static final String PULSAR_CLIENT_SERVICE_URL = "pulsar.client.serviceUrl";
private static final String PULSAR_ADMIN_SERVICE_URL = "pulsar.admin.serviceUrl";
static volatile RunningDevService devService;
Expand All @@ -59,12 +63,15 @@ public DevServicesResultBuildItem startPulsarDevService(
DockerStatusBuildItem dockerStatusBuildItem,
LaunchModeBuildItem launchMode,
PulsarBuildTimeConfig pulsarClientBuildTimeConfig,
List<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem,
Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem,
CuratedApplicationShutdownBuildItem closeBuildItem,
LoggingSetupBuildItem loggingSetupBuildItem,
GlobalDevServicesConfig devServicesConfig) {

PulsarDevServiceCfg configuration = getConfiguration(pulsarClientBuildTimeConfig);
boolean useSharedNetwork = DevServicesSharedNetworkBuildItem.isSharedNetworkRequired(devServicesConfig,
devServicesSharedNetworkBuildItem);

if (devService != null) {
boolean shouldShutdownTheBroker = !configuration.equals(cfg);
Expand All @@ -80,7 +87,7 @@ public DevServicesResultBuildItem startPulsarDevService(
loggingSetupBuildItem);
try {
RunningDevService newDevService = startPulsarContainer(dockerStatusBuildItem, configuration, launchMode,
devServicesConfig.timeout);
useSharedNetwork, devServicesConfig.timeout);
if (newDevService != null) {
devService = newDevService;
Map<String, String> config = devService.getConfig();
Expand Down Expand Up @@ -138,7 +145,8 @@ private void shutdownBroker() {
}

private RunningDevService startPulsarContainer(DockerStatusBuildItem dockerStatusBuildItem, PulsarDevServiceCfg config,
LaunchModeBuildItem launchMode, Optional<Duration> timeout) {
LaunchModeBuildItem launchMode,
boolean useSharedNetwork, Optional<Duration> timeout) {
if (!config.devServicesEnabled) {
// explicitly disabled
log.debug("Not starting Dev Services for Pulsar, as it has been disabled in the config.");
Expand Down Expand Up @@ -175,10 +183,21 @@ private RunningDevService startPulsarContainer(DockerStatusBuildItem dockerStatu
container.withPort(config.fixedExposedPort);
}
timeout.ifPresent(container::withStartupTimeout);
String hostName = null;
if (useSharedNetwork) {
hostName = ConfigureUtil.configureSharedNetwork(container, DEV_SERVICE_PULSAR);
}
container.start();

return getRunningService(container.getContainerId(), container::close, container.getPulsarBrokerUrl(),
container.getHttpServiceUrl());
var pulsarBrokerUrl = container.getPulsarBrokerUrl();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd do all this inside the PulsarContainer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, moved.

var httpHostServiceUrl = container.getHttpServiceUrl();
if (useSharedNetwork) {
pulsarBrokerUrl = getServiceUrl(hostName, PulsarContainer.BROKER_PORT);
httpHostServiceUrl = getHttpServiceUrl(hostName, PulsarContainer.BROKER_HTTP_PORT);
}

return getRunningService(container.getContainerId(), container::close, pulsarBrokerUrl,
httpHostServiceUrl);
};

return pulsarContainerLocator.locateContainer(config.serviceName, config.shared, launchMode.getLaunchMode())
Expand Down