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

Dev console and UI for listing running dev services #23048

Merged
merged 4 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,11 @@
<artifactId>quarkus-devservices-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devservices-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
* Used to start and configure dev services, any processor starting dev services should produce these items.
*
* Quarkus will make sure the relevant settings are present in both JVM and native modes.
*
* @deprecated use {@link DevServicesResultBuildItem}
*/
@Deprecated(since = "https://github.com/quarkusio/quarkus/pull/23048")
public final class DevServicesConfigResultBuildItem extends MultiBuildItem {

final String key;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package io.quarkus.deployment.builditem;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import io.quarkus.builder.item.MultiBuildItem;

/**
* BuildItem for running dev services
* Combines injected configs to the application with container id (if it exists).
*
* Processors are expected to return this build item not only when the dev service first starts,
* but also if a running dev service already exists.
*
* {@link RunningDevService} helps to manage the lifecycle of the running dev service
*/
public final class DevServicesResultBuildItem extends MultiBuildItem {

private final String name;
private final String containerId;
private final Map<String, String> config;

public DevServicesResultBuildItem(String name, String containerId, Map<String, String> config) {
this.name = name;
this.containerId = containerId;
this.config = config;
}

public String getName() {
return name;
}

public String getContainerId() {
return containerId;
}

public Map<String, String> getConfig() {
return config;
}

public static class RunningDevService implements Closeable {

private final String name;
private final String containerId;
private final Map<String, String> config;
private final Closeable closeable;

private static Map<String, String> mapOf(String key, String value) {
Map<String, String> map = new HashMap<>();
map.put(key, value);
return map;
}

public RunningDevService(String name, String containerId, Closeable closeable, String key, String value) {
this(name, containerId, closeable, mapOf(key, value));
}

public RunningDevService(String name, String containerId, Closeable closeable, Map<String, String> config) {
this.name = name;
this.containerId = containerId;
this.closeable = closeable;
this.config = Collections.unmodifiableMap(config);
}

public String getName() {
return name;
}

public String getContainerId() {
return containerId;
}

public Map<String, String> getConfig() {
return config;
}

public Closeable getCloseable() {
return closeable;
}

public boolean isOwner() {
return closeable != null;
}

@Override
public void close() throws IOException {
this.closeable.close();
}

public DevServicesResultBuildItem toBuildItem() {
return new DevServicesResultBuildItem(name, containerId, config);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package io.quarkus.deployment.dev.devservices;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public class ContainerInfo {

private String id;
private String[] names;
private String imageName;
private String status;
private String[] networks;
private Map<String, String> labels;
private ContainerPort[] exposedPorts;

public ContainerInfo() {
}

public ContainerInfo(String id, String[] names, String imageName, String status, String[] networks,
Map<String, String> labels, ContainerPort[] exposedPorts) {
this.id = id;
this.names = names;
this.imageName = imageName;
this.status = status;
this.networks = networks;
this.labels = labels;
this.exposedPorts = exposedPorts;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getShortId() {
return id.substring(0, 12);
}

public String[] getNames() {
return names;
}

public void setNames(String[] names) {
this.names = names;
}

public String formatNames() {
return String.join(",", getNames());
}

public String getImageName() {
return imageName;
}

public void setImageName(String imageName) {
this.imageName = imageName;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String[] getNetworks() {
return networks;
}

public void setNetworks(String[] networks) {
this.networks = networks;
}

public String formatNetworks() {
return String.join(",", getNetworks());
}

public Map<String, String> getLabels() {
return labels;
}

public void setLabels(Map<String, String> labels) {
this.labels = labels;
}

public ContainerPort[] getExposedPorts() {
return exposedPorts;
}

public void setExposedPorts(ContainerPort[] exposedPorts) {
this.exposedPorts = exposedPorts;
}

public String formatPorts() {
return Arrays.stream(getExposedPorts())
.filter(p -> p.getPublicPort() != null)
.map(c -> c.getIp() + ":" + c.getPublicPort() + "->" + c.getPrivatePort() + "/" + c.getType())
.collect(Collectors.joining(" ,"));
}

public static class ContainerPort {
private String ip;
private Integer privatePort;
private Integer publicPort;
private String type;

public ContainerPort() {
}

public ContainerPort(String ip, Integer privatePort, Integer publicPort, String type) {
this.ip = ip;
this.privatePort = privatePort;
this.publicPort = publicPort;
this.type = type;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}

public Integer getPrivatePort() {
return privatePort;
}

public void setPrivatePort(Integer privatePort) {
this.privatePort = privatePort;
}

public Integer getPublicPort() {
return publicPort;
}

public void setPublicPort(Integer publicPort) {
this.publicPort = publicPort;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.quarkus.deployment.dev.devservices;

import java.util.Map;
import java.util.stream.Collectors;

import io.quarkus.builder.item.MultiBuildItem;

public final class DevServiceDescriptionBuildItem extends MultiBuildItem {
private String name;
private ContainerInfo containerInfo;
private Map<String, String> configs;

public DevServiceDescriptionBuildItem() {
}

public DevServiceDescriptionBuildItem(String name, ContainerInfo containerInfo, Map<String, String> configs) {
this.name = name;
this.containerInfo = containerInfo;
this.configs = configs;
}

public boolean hasContainerInfo() {
return containerInfo != null;
}

public String getName() {
return name;
}

public ContainerInfo getContainerInfo() {
return containerInfo;
}

public Map<String, String> getConfigs() {
return configs;
}

public void setName(String name) {
this.name = name;
}

public void setContainerInfo(ContainerInfo containerInfo) {
this.containerInfo = containerInfo;
}

public void setConfigs(Map<String, String> configs) {
this.configs = configs;
}

public String formatConfigs() {
return configs.entrySet().stream()
.map(e -> e.getKey() + "=" + e.getValue())
.collect(Collectors.joining(", "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem;
import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem;
import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem;
import io.quarkus.deployment.builditem.DevServicesResultBuildItem;
import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem;
import io.quarkus.deployment.builditem.ServiceStartBuildItem;

Expand All @@ -32,9 +33,13 @@ List<DevServicesConfigResultBuildItem> deprecated(List<DevServicesNativeConfigRe
@Produce(ServiceStartBuildItem.class)
DevServicesLauncherConfigResultBuildItem setup(BuildProducer<RunTimeConfigurationDefaultBuildItem> runtimeConfig,
List<DevServicesConfigResultBuildItem> devServicesConfigResultBuildItems,
List<DevServicesResultBuildItem> devServicesResultBuildItems,
CuratedApplicationShutdownBuildItem shutdownBuildItem) {
Map<String, String> newProperties = new HashMap<>(devServicesConfigResultBuildItems.stream().collect(
Collectors.toMap(DevServicesConfigResultBuildItem::getKey, DevServicesConfigResultBuildItem::getValue)));
for (DevServicesResultBuildItem resultBuildItem : devServicesResultBuildItems) {
newProperties.putAll(resultBuildItem.getConfig());
}
Config config = ConfigProvider.getConfig();
//check if there are existing already started dev services
//if there were no changes to the processors they don't produce config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

Expand All @@ -11,12 +13,13 @@
import io.quarkus.amazon.lambda.runtime.LambdaHotReplacementRecorder;
import io.quarkus.amazon.lambda.runtime.MockEventServer;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.IsNormal;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Produce;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.DevServicesConfigResultBuildItem;
import io.quarkus.deployment.builditem.DevServicesResultBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.RuntimeApplicationShutdownBuildItem;
import io.quarkus.deployment.builditem.ServiceStartBuildItem;
Expand Down Expand Up @@ -54,7 +57,7 @@ private boolean legacyTestingEnabled() {
public void startEventServer(LaunchModeBuildItem launchMode,
LambdaConfig config,
Optional<EventServerOverrideBuildItem> override,
BuildProducer<DevServicesConfigResultBuildItem> devServicePropertiesProducer,
BuildProducer<DevServicesResultBuildItem> devServicePropertiesProducer,
BuildProducer<RuntimeApplicationShutdownBuildItem> runtimeApplicationShutdownBuildItemBuildProducer)
throws Exception {
if (!launchMode.getLaunchMode().isDevOrTest())
Expand All @@ -77,8 +80,10 @@ public void startEventServer(LaunchModeBuildItem launchMode,
startMode = launchMode.getLaunchMode();
server.start(port);
String baseUrl = "localhost:" + port + MockEventServer.BASE_PATH;
Map<String, String> properties = new HashMap<>();
properties.put(AmazonLambdaApi.QUARKUS_INTERNAL_AWS_LAMBDA_TEST_API, baseUrl);
devServicePropertiesProducer.produce(
new DevServicesConfigResultBuildItem(AmazonLambdaApi.QUARKUS_INTERNAL_AWS_LAMBDA_TEST_API, baseUrl));
new DevServicesResultBuildItem(Feature.AMAZON_LAMBDA.getName(), null, properties));
Runnable closeTask = () -> {
if (server != null) {
try {
Expand Down
Loading