Skip to content

Commit

Permalink
fix: #24 Do not try to complete the Ensemble if container is not star…
Browse files Browse the repository at this point in the history
…ted 😉

Signed-off-by: Laurent Broudoux <[email protected]>
  • Loading branch information
lbroudoux committed Feb 20, 2024
1 parent ee0e09a commit 564cbed
Showing 1 changed file with 63 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,79 +238,84 @@ public List<DevServicesResultBuildItem> startMicrocksContainers(LaunchModeBuildI
*/
@BuildStep
@Produce(MicrocksEnsembleBuildItem.class)
public void complementMicrocksEnsemble(MicrocksBuildTimeConfig config, DevServicesLauncherConfigResultBuildItem devServicesConfigResult,
public void completeMicrocksEnsemble(MicrocksBuildTimeConfig config, DevServicesLauncherConfigResultBuildItem devServicesConfigResult,
CuratedApplicationShutdownBuildItem closeBuildItem) {

String microcksHost = ensembleHosts.getMicrocksHost();
// ensembleHosts may be null if container has not been started
// (If devservices are disabled or we couldn't locate existing containers)
if (ensembleHosts != null) {
String microcksHost = ensembleHosts.getMicrocksHost();

boolean aBrokerIsPresent = false;
String kafkaBootstrapServers = null;
boolean aBrokerIsPresent = false;
String kafkaBootstrapServers = null;

for (Map.Entry configEntry : devServicesConfigResult.getConfig().entrySet()) {
log.debugf("DevServices config: %s=%s", configEntry.getKey(), configEntry.getValue());
if ("kafka.bootstrap.servers".equals(configEntry.getKey())) {
kafkaBootstrapServers = configEntry.getValue().toString();
aBrokerIsPresent = true;
for (Map.Entry configEntry : devServicesConfigResult.getConfig().entrySet()) {
log.debugf("DevServices config: %s=%s", configEntry.getKey(), configEntry.getValue());
if ("kafka.bootstrap.servers".equals(configEntry.getKey())) {
kafkaBootstrapServers = configEntry.getValue().toString();
aBrokerIsPresent = true;
}
}
}

// Get the ensemble configuration or a default one.
DevServicesConfig devServiceConfig = config.defaultDevService().devservices();
DevServicesConfig.EnsembleConfiguration ensembleConfiguration = devServiceConfig.ensemble().orElse(new DevServicesConfig.EnsembleConfiguration() {
@Override
public boolean asyncEnabled() {
return false;
}
@Override
public boolean postmanEnabled() {
return false;
}
});
// Get the ensemble configuration or a default one.
DevServicesConfig devServiceConfig = config.defaultDevService().devservices();
DevServicesConfig.EnsembleConfiguration ensembleConfiguration = devServiceConfig.ensemble().orElse(new DevServicesConfig.EnsembleConfiguration() {
@Override
public boolean asyncEnabled() {
return false;
}

if (ensembleConfiguration.postmanEnabled() || aPostmanCollectionIsPresent) {
log.debug("Starting a GenericContainer with Postman...");
@Override
public boolean postmanEnabled() {
return false;
}
});

// We've got the conditions for launching a new GenericContainer with Postman !
GenericContainer<?> postmanContainer = new GenericContainer<>(
DockerImageName.parse(ensembleConfiguration.postmanImageName().orElse(MICROCKS_POSTMAN_LATEST)))
.withNetwork(Network.SHARED)
.withNetworkAliases(ensembleHosts.getPostmanHost())
.withAccessToHost(true)
.waitingFor(Wait.forLogMessage(".*postman-runtime wrapper listening on port.*", 1));
if (ensembleConfiguration.postmanEnabled() || aPostmanCollectionIsPresent) {
log.debug("Starting a GenericContainer with Postman...");

postmanContainer.start();
// We've got the conditions for launching a new GenericContainer with Postman !
GenericContainer<?> postmanContainer = new GenericContainer<>(
DockerImageName.parse(ensembleConfiguration.postmanImageName().orElse(MICROCKS_POSTMAN_LATEST)))
.withNetwork(Network.SHARED)
.withNetworkAliases(ensembleHosts.getPostmanHost())
.withAccessToHost(true)
.waitingFor(Wait.forLogMessage(".*postman-runtime wrapper listening on port.*", 1));

closeBuildItem.addCloseTask(postmanContainer::stop, true);
}
postmanContainer.start();

if (ensembleConfiguration.asyncEnabled() || aBrokerIsPresent) {
log.debug("Starting a MicrocksAsyncMinionContainer...");

// We've got the conditions for launching a new MicrocksAsyncMinionContainer !
MicrocksAsyncMinionContainer asyncMinionContainer = new MicrocksAsyncMinionContainer(Network.SHARED,
DockerImageName.parse(ensembleConfiguration.asyncImageName().orElse(MICROCKS_UBER_ASYNC_MINION_LATEST)), microcksHost)
.withAccessToHost(true);

// Configure connection to a Kafka broker if any.
if (kafkaBootstrapServers != null) {
if (kafkaBootstrapServers.contains(",")) {
String[] kafkaAddresses = kafkaBootstrapServers.split(",");
for (String kafkaAddress : kafkaAddresses) {
if (kafkaAddress.startsWith("PLAINTEXT://")) {
kafkaBootstrapServers = kafkaAddress.replace("PLAINTEXT://", "");
closeBuildItem.addCloseTask(postmanContainer::stop, true);
}

if (ensembleConfiguration.asyncEnabled() || aBrokerIsPresent) {
log.debug("Starting a MicrocksAsyncMinionContainer...");

// We've got the conditions for launching a new MicrocksAsyncMinionContainer !
MicrocksAsyncMinionContainer asyncMinionContainer = new MicrocksAsyncMinionContainer(Network.SHARED,
DockerImageName.parse(ensembleConfiguration.asyncImageName().orElse(MICROCKS_UBER_ASYNC_MINION_LATEST)), microcksHost)
.withAccessToHost(true);

// Configure connection to a Kafka broker if any.
if (kafkaBootstrapServers != null) {
if (kafkaBootstrapServers.contains(",")) {
String[] kafkaAddresses = kafkaBootstrapServers.split(",");
for (String kafkaAddress : kafkaAddresses) {
if (kafkaAddress.startsWith("PLAINTEXT://")) {
kafkaBootstrapServers = kafkaAddress.replace("PLAINTEXT://", "");
}
}
}
}

log.debugf("Adding a KafkaConnection to '%s' for MicrocksAsyncMinionContainer", kafkaBootstrapServers);
asyncMinionContainer.withKafkaConnection(new KafkaConnection(
kafkaBootstrapServers.replace("localhost", GenericContainer.INTERNAL_HOST_HOSTNAME)));
}
log.debugf("Adding a KafkaConnection to '%s' for MicrocksAsyncMinionContainer", kafkaBootstrapServers);
asyncMinionContainer.withKafkaConnection(new KafkaConnection(
kafkaBootstrapServers.replace("localhost", GenericContainer.INTERNAL_HOST_HOSTNAME)));
}

asyncMinionContainer.getNetworkAliases().add(ensembleHosts.getAsyncMinionHost());
asyncMinionContainer.start();
asyncMinionContainer.getNetworkAliases().add(ensembleHosts.getAsyncMinionHost());
asyncMinionContainer.start();

closeBuildItem.addCloseTask(asyncMinionContainer::stop, true);
closeBuildItem.addCloseTask(asyncMinionContainer::stop, true);
}
}
}

Expand Down Expand Up @@ -351,7 +356,7 @@ private RunningDevService startContainer(DevServicesConfig devServicesConfig, Do
LaunchMode launchMode, CurateOutcomeBuildItem outcomeBuildItem, Optional<Duration> timeout) {
if (!devServicesConfig.enabled()) {
// explicitly disabled
log.debug("Not starting devservices for Microcks as it has been disabled in the config");
log.info("Not starting devservices for Microcks as it has been disabled in the config");
return null;
}

Expand Down

0 comments on commit 564cbed

Please sign in to comment.