use of io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService in project quarkus by quarkusio.
the class RabbitMQDevServicesProcessor method startRabbitMQDevService.
@BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class)
public DevServicesResultBuildItem startRabbitMQDevService(DockerStatusBuildItem dockerStatusBuildItem, LaunchModeBuildItem launchMode, RabbitMQBuildTimeConfig rabbitmqClientBuildTimeConfig, Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem, LoggingSetupBuildItem loggingSetupBuildItem, GlobalDevServicesConfig devServicesConfig) {
RabbitMQDevServiceCfg configuration = getConfiguration(rabbitmqClientBuildTimeConfig);
if (devService != null) {
boolean shouldShutdownTheBroker = !configuration.equals(cfg);
if (!shouldShutdownTheBroker) {
return devService.toBuildItem();
}
shutdownBroker();
cfg = null;
}
StartupLogCompressor compressor = new StartupLogCompressor((launchMode.isTest() ? "(test) " : "") + "RabbitMQ Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem);
try {
RunningDevService newDevService = startRabbitMQBroker(dockerStatusBuildItem, configuration, launchMode, devServicesConfig.timeout);
if (newDevService != null) {
devService = newDevService;
Map<String, String> config = devService.getConfig();
if (devService.isOwner()) {
log.info("Dev Services for RabbitMQ started.");
log.infof("Other Quarkus applications in dev mode will find the " + "broker automatically. For Quarkus applications in production mode, you can connect to" + " this by starting your application with -Drabbitmq-host=%s -Drabbitmq-port=%s -Drabbitmq-username=%s -Drabbitmq-password=%s", config.get(RABBITMQ_HOST_PROP), config.get(RABBITMQ_PORT_PROP), config.get(RABBITMQ_USERNAME_PROP), config.get(RABBITMQ_PASSWORD_PROP));
}
}
if (devService == null) {
compressor.closeAndDumpCaptured();
} else {
compressor.close();
}
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
throw new RuntimeException(t);
}
if (devService == null) {
return null;
}
// Configure the watch dog
if (first) {
first = false;
Runnable closeTask = () -> {
if (devService != null) {
shutdownBroker();
log.info("Dev Services for RabbitMQ shut down.");
}
first = true;
devService = null;
cfg = null;
};
QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader();
((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask);
}
cfg = configuration;
return devService.toBuildItem();
}
use of io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService in project quarkus by quarkusio.
the class InfinispanDevServiceProcessor method startInfinispanContainers.
@BuildStep(onlyIfNot = IsNormal.class, onlyIf = { GlobalDevServicesConfig.Enabled.class })
public List<DevServicesResultBuildItem> startInfinispanContainers(LaunchModeBuildItem launchMode, DockerStatusBuildItem dockerStatusBuildItem, List<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem, InfinispanClientDevServiceBuildTimeConfig config, Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem, CuratedApplicationShutdownBuildItem closeBuildItem, LoggingSetupBuildItem loggingSetupBuildItem, GlobalDevServicesConfig devServicesConfig) {
// if not and the Infinispan containers have already started we just return
if (devServices != null) {
boolean restartRequired = !config.devService.equals(capturedDevServicesConfiguration);
if (!restartRequired) {
return devServices.stream().map(RunningDevService::toBuildItem).collect(Collectors.toList());
}
for (Closeable closeable : devServices) {
try {
closeable.close();
} catch (Throwable e) {
log.error("Failed to stop infinispan container", e);
}
}
devServices = null;
capturedDevServicesConfiguration = null;
}
capturedDevServicesConfiguration = config.devService;
List<RunningDevService> newDevServices = new ArrayList<>();
StartupLogCompressor compressor = new StartupLogCompressor((launchMode.isTest() ? "(test) " : "") + "Infinispan Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem);
try {
RunningDevService devService = startContainer(dockerStatusBuildItem, config.devService.devservices, launchMode.getLaunchMode(), !devServicesSharedNetworkBuildItem.isEmpty(), devServicesConfig.timeout);
if (devService == null) {
compressor.closeAndDumpCaptured();
return null;
}
newDevServices.add(devService);
log.infof("The infinispan server is ready to accept connections on %s", devService.getConfig().get(getConfigPrefix() + "server-list"));
compressor.close();
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
throw new RuntimeException(t);
}
devServices = newDevServices;
if (first) {
first = false;
Runnable closeTask = () -> {
if (devServices != null) {
for (Closeable closeable : devServices) {
try {
closeable.close();
} catch (Throwable t) {
log.error("Failed to stop infinispan", t);
}
}
}
first = true;
devServices = null;
capturedDevServicesConfiguration = null;
};
closeBuildItem.addCloseTask(closeTask, true);
}
return devServices.stream().map(RunningDevService::toBuildItem).collect(Collectors.toList());
}
use of io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService in project quarkus by quarkusio.
the class DevServicesKafkaProcessor method startKafka.
private RunningDevService startKafka(DockerStatusBuildItem dockerStatusBuildItem, KafkaDevServiceCfg config, LaunchModeBuildItem launchMode, boolean useSharedNetwork, Optional<Duration> timeout) {
if (!config.devServicesEnabled) {
// explicitly disabled
log.debug("Not starting dev services for Kafka, as it has been disabled in the config.");
return null;
}
// Check if kafka.bootstrap.servers is set
if (ConfigUtils.isPropertyPresent(KAFKA_BOOTSTRAP_SERVERS)) {
log.debug("Not starting dev services for Kafka, the kafka.bootstrap.servers is configured.");
return null;
}
// Verify that we have kafka channels without bootstrap.servers
if (!hasKafkaChannelWithoutBootstrapServers()) {
log.debug("Not starting dev services for Kafka, all the channels are configured.");
return null;
}
if (!dockerStatusBuildItem.isDockerAvailable()) {
log.warn("Docker isn't working, please configure the Kafka bootstrap servers property (kafka.bootstrap.servers).");
return null;
}
final Optional<ContainerAddress> maybeContainerAddress = kafkaContainerLocator.locateContainer(config.serviceName, config.shared, launchMode.getLaunchMode());
// Starting the broker
final Supplier<RunningDevService> defaultKafkaBrokerSupplier = () -> {
if (config.imageName.contains("strimzi")) {
StrimziKafkaContainer container = new StrimziKafkaContainer(config.imageName).withBrokerId(1).withKraft().waitForRunning();
ConfigureUtil.configureSharedNetwork(container, "kafka");
if (config.serviceName != null) {
container.withLabel(DevServicesKafkaProcessor.DEV_SERVICE_LABEL, config.serviceName);
}
if (config.fixedExposedPort != 0) {
container.withPort(config.fixedExposedPort);
}
timeout.ifPresent(container::withStartupTimeout);
container.start();
return new RunningDevService(Feature.KAFKA_CLIENT.getName(), container.getContainerId(), container::close, KAFKA_BOOTSTRAP_SERVERS, container.getBootstrapServers());
} else {
RedPandaKafkaContainer container = new RedPandaKafkaContainer(DockerImageName.parse(config.imageName), config.fixedExposedPort, launchMode.getLaunchMode() == LaunchMode.DEVELOPMENT ? config.serviceName : null, useSharedNetwork, config.redpanda);
timeout.ifPresent(container::withStartupTimeout);
container.start();
return new RunningDevService(Feature.KAFKA_CLIENT.getName(), container.getContainerId(), container::close, KAFKA_BOOTSTRAP_SERVERS, container.getBootstrapServers());
}
};
return maybeContainerAddress.map(containerAddress -> new RunningDevService(Feature.KAFKA_CLIENT.getName(), containerAddress.getId(), null, KAFKA_BOOTSTRAP_SERVERS, containerAddress.getUrl())).orElseGet(defaultKafkaBrokerSupplier);
}
use of io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService in project quarkus by quarkusio.
the class DevServicesMongoProcessor method startMongo.
private RunningDevService startMongo(DockerStatusBuildItem dockerStatusBuildItem, String connectionName, CapturedProperties capturedProperties, boolean useSharedNetwork, Optional<Duration> timeout) {
if (!capturedProperties.devServicesEnabled) {
// explicitly disabled
log.debug("Not starting devservices for " + (isDefault(connectionName) ? "default datasource" : connectionName) + " as it has been disabled in the config");
return null;
}
String configPrefix = getConfigPrefix(connectionName);
// TODO: do we need to check the hosts as well?
boolean needToStart = !ConfigUtils.isPropertyPresent(configPrefix + "connection-string");
if (!needToStart) {
// a connection string has been provided
log.debug("Not starting devservices for " + (isDefault(connectionName) ? "default datasource" : connectionName) + " as a connection string has been provided");
return null;
}
if (!dockerStatusBuildItem.isDockerAvailable()) {
log.warn("Please configure datasource URL for " + (isDefault(connectionName) ? "default datasource" : connectionName) + " or get a working docker instance");
return null;
}
MongoDBContainer mongoDBContainer;
if (capturedProperties.imageName != null) {
mongoDBContainer = new QuarkusMongoDBContainer(DockerImageName.parse(capturedProperties.imageName).asCompatibleSubstituteFor("mongo"), capturedProperties.fixedExposedPort, useSharedNetwork);
} else {
mongoDBContainer = new QuarkusMongoDBContainer(capturedProperties.fixedExposedPort, useSharedNetwork);
}
timeout.ifPresent(mongoDBContainer::withStartupTimeout);
mongoDBContainer.start();
Optional<String> databaseName = ConfigProvider.getConfig().getOptionalValue(configPrefix + "database", String.class);
String effectiveURL = databaseName.map(mongoDBContainer::getReplicaSetUrl).orElse(mongoDBContainer.getReplicaSetUrl());
if ((capturedProperties.connectionProperties != null) && !capturedProperties.connectionProperties.isEmpty()) {
effectiveURL = effectiveURL + "?" + URLEncodedUtils.format(capturedProperties.connectionProperties.entrySet().stream().map(e -> new BasicNameValuePair(e.getKey(), e.getValue())).collect(Collectors.toList()), StandardCharsets.UTF_8);
}
return new RunningDevService(Feature.MONGODB_CLIENT.getName(), mongoDBContainer.getContainerId(), mongoDBContainer::close, getConfigPrefix(connectionName) + "connection-string", effectiveURL);
}
use of io.quarkus.deployment.builditem.DevServicesResultBuildItem.RunningDevService in project quarkus by quarkusio.
the class DevServicesMongoProcessor method startMongo.
@BuildStep(onlyIfNot = IsNormal.class, onlyIf = GlobalDevServicesConfig.Enabled.class)
public List<DevServicesResultBuildItem> startMongo(List<MongoConnectionNameBuildItem> mongoConnections, DockerStatusBuildItem dockerStatusBuildItem, MongoClientBuildTimeConfig mongoClientBuildTimeConfig, List<DevServicesSharedNetworkBuildItem> devServicesSharedNetworkBuildItem, Optional<ConsoleInstalledBuildItem> consoleInstalledBuildItem, CuratedApplicationShutdownBuildItem closeBuildItem, LaunchModeBuildItem launchMode, LoggingSetupBuildItem loggingSetupBuildItem, GlobalDevServicesConfig globalDevServicesConfig) {
List<String> connectionNames = new ArrayList<>(mongoConnections.size());
for (MongoConnectionNameBuildItem mongoConnection : mongoConnections) {
connectionNames.add(mongoConnection.getName());
}
// TODO: handle named connections as well
if (connectionNames.size() != 1) {
return null;
}
if (!isDefault(connectionNames.get(0))) {
return null;
}
Map<String, CapturedProperties> currentCapturedProperties = captureProperties(connectionNames, mongoClientBuildTimeConfig);
// if not and the DB's have already started we just return
if (devServices != null) {
boolean restartRequired = !currentCapturedProperties.equals(capturedProperties);
if (!restartRequired) {
return devServices.stream().map(RunningDevService::toBuildItem).collect(Collectors.toList());
}
for (Closeable i : devServices) {
try {
i.close();
} catch (Throwable e) {
log.error("Failed to stop database", e);
}
}
devServices = null;
capturedProperties = null;
}
List<RunningDevService> newDevServices = new ArrayList<>(mongoConnections.size());
// TODO: we need to go through each connection
String connectionName = connectionNames.get(0);
RunningDevService devService;
StartupLogCompressor compressor = new StartupLogCompressor((launchMode.isTest() ? "(test) " : "") + "Mongo Dev Services Starting:", consoleInstalledBuildItem, loggingSetupBuildItem);
try {
devService = startMongo(dockerStatusBuildItem, connectionName, currentCapturedProperties.get(connectionName), !devServicesSharedNetworkBuildItem.isEmpty(), globalDevServicesConfig.timeout);
if (devService == null) {
compressor.closeAndDumpCaptured();
} else {
compressor.close();
}
} catch (Throwable t) {
compressor.closeAndDumpCaptured();
throw new RuntimeException(t);
}
if (devService != null) {
newDevServices.add(devService);
}
if (first) {
first = false;
Runnable closeTask = new Runnable() {
@Override
public void run() {
if (devServices != null) {
for (Closeable i : devServices) {
try {
i.close();
} catch (Throwable t) {
log.error("Failed to stop database", t);
}
}
}
first = true;
devServices = null;
capturedProperties = null;
}
};
closeBuildItem.addCloseTask(closeTask, true);
}
devServices = newDevServices;
capturedProperties = currentCapturedProperties;
return devServices.stream().map(RunningDevService::toBuildItem).collect(Collectors.toList());
}
Aggregations