feat(appconfig): implement ListDeployments (#3749)

* feat(appconfig): add deployment listing service

* feat(appconfig): expose ListDeployments

* docs(appconfig): document ListDeployments

* chore(appconfig): clean controller imports

* fix(appconfig): make deployment pagination cursor-based
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-09-16 22:31:48 -04:00
1 parent 66bcdaf675
commit d624988ff8
6 files changed
+415 -9

No files matched your search

@@ -3,14 +3,26 @@ package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.appconfig.model.*;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.services.appconfig.model.Application;
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationProfile;
import io.github.hectorvent.floci.services.appconfig.model.Deployment;
import io.github.hectorvent.floci.services.appconfig.model.DeploymentStrategy;
import io.github.hectorvent.floci.services.appconfig.model.Environment;
import io.github.hectorvent.floci.services.appconfig.model.HostedConfigurationVersion;
import io.github.hectorvent.floci.services.appconfig.model.HostedConfigurationVersionSummary;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@@ -19,8 +31,6 @@ import java.util.Map;
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class AppConfigController {
private static final Logger LOG = Logger.getLogger(AppConfigController.class);
private final AppConfigService service;
private final ObjectMapper objectMapper;
@@ -228,6 +238,23 @@ public class AppConfigController {
return Response.status(201).entity(deployment).build();
}
@GET
@Path("/applications/{appId}/environments/{envId}/deployments")
public Response listDeployments(@PathParam("appId") String appId,
@PathParam("envId") String envId,
@QueryParam("max_results") String maxResults,
@QueryParam("next_token") String nextToken) {
AppConfigService.DeploymentPage page = service.listDeployments(appId, envId,
Pagination.parseMaxResults(maxResults, "BadRequestException"), nextToken);
ObjectNode root = objectMapper.createObjectNode();
ArrayNode items = root.putArray("Items");
page.items().forEach(items::addPOJO);
if (page.nextToken() != null) {
root.put("NextToken", page.nextToken());
}
return Response.ok(root).build();
}
@GET
@Path("/applications/{appId}/environments/{envId}/deployments/{deploymentNumber}")
public Response getDeployment(@PathParam("appId") String appId, @PathParam("envId") String envId, @PathParam("deploymentNumber") int deploymentNumber) {
@@ -5,12 +5,24 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.appconfig.model.*;
import io.github.hectorvent.floci.services.appconfig.model.Application;
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationProfile;
import io.github.hectorvent.floci.services.appconfig.model.Deployment;
import io.github.hectorvent.floci.services.appconfig.model.DeploymentStrategy;
import io.github.hectorvent.floci.services.appconfig.model.DeploymentSummary;
import io.github.hectorvent.floci.services.appconfig.model.Environment;
import io.github.hectorvent.floci.services.appconfig.model.HostedConfigurationVersion;
import io.github.hectorvent.floci.services.appconfig.model.HostedConfigurationVersionSummary;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@ApplicationScoped
public class AppConfigService {
@@ -23,6 +35,8 @@ public class AppConfigService {
private final StorageBackend<String, HostedConfigurationVersion> versionStore;
private final StorageBackend<String, Deployment> deploymentStore;
private final StorageBackend<String, String> activeConfigStore; // envId::profileId -> versionNumber
private final Map<String, DeploymentPageToken> deploymentPageTokens = new ConcurrentHashMap<>();
private static final int MAX_DEPLOYMENT_PAGE_TOKENS = 1000;
@Inject
public AppConfigService(StorageFactory storageFactory, EmulatorConfig config) {
@@ -294,6 +308,87 @@ public class AppConfigService {
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Deployment not found", 404));
}
public DeploymentPage listDeployments(String appId, String envId, Integer maxResults, String nextToken) {
getEnvironment(appId, envId);
int pageSize = maxResults == null ? 50 : maxResults;
if (pageSize < 1 || pageSize > 50) {
throw new AwsException("BadRequestException", "max_results must be between 1 and 50", 400);
}
String scope = appId + "::" + envId;
Integer afterDeploymentNumber = null;
if (nextToken != null) {
DeploymentPageToken token = deploymentPageTokens.get(nextToken);
if (token == null || !token.scope().equals(scope)) {
throw new AwsException("BadRequestException", "Invalid next_token", 400);
}
afterDeploymentNumber = token.lastDeploymentNumber();
}
List<Deployment> deployments = deploymentStore.scan(k -> true).stream()
.filter(deployment -> appId.equals(deployment.getApplicationId()))
.filter(deployment -> envId.equals(deployment.getEnvironmentId()))
.sorted(Comparator.comparingInt(Deployment::getDeploymentNumber).reversed())
.toList();
int start = 0;
if (afterDeploymentNumber != null) {
while (start < deployments.size()
&& deployments.get(start).getDeploymentNumber() >= afterDeploymentNumber) {
start++;
}
}
int end = Math.min(start + pageSize, deployments.size());
List<DeploymentSummary> items = deployments.subList(start, end).stream()
.map(this::toDeploymentSummary)
.toList();
String resultToken = null;
if (end < deployments.size()) {
resultToken = createDeploymentPageToken(scope,
items.get(items.size() - 1).getDeploymentNumber());
} else if (nextToken != null) {
deploymentPageTokens.remove(nextToken);
}
return new DeploymentPage(items, resultToken);
}
private DeploymentSummary toDeploymentSummary(Deployment deployment) {
DeploymentSummary summary = new DeploymentSummary();
summary.setConfigurationProfileId(deployment.getConfigurationProfileId());
summary.setConfigurationVersion(deployment.getConfigurationVersion());
summary.setDeploymentNumber(deployment.getDeploymentNumber());
summary.setState(deployment.getState());
summary.setConfigurationName(deployment.getConfigurationName());
ConfigurationProfile profile = profileStore.get(deployment.getConfigurationProfileId()).orElse(null);
if (profile != null) {
summary.setConfigurationName(profile.getName());
summary.setType(profile.getType());
}
DeploymentStrategy strategy = getDeploymentStrategy(deployment.getDeploymentStrategyId());
summary.setDeploymentDurationInMinutes(strategy.getDeploymentDurationInMinutes());
summary.setFinalBakeTimeInMinutes(strategy.getFinalBakeTimeInMinutes());
summary.setGrowthFactor(strategy.getGrowthFactor());
summary.setGrowthType(strategy.getGrowthType());
summary.setPercentageComplete("COMPLETE".equals(deployment.getState()) ? 100.0f : 0.0f);
return summary;
}
private String createDeploymentPageToken(String scope, int lastDeploymentNumber) {
while (deploymentPageTokens.size() >= MAX_DEPLOYMENT_PAGE_TOKENS) {
deploymentPageTokens.keySet().stream().findFirst().ifPresent(deploymentPageTokens::remove);
}
String token = UUID.randomUUID().toString().replace("-", "");
deploymentPageTokens.put(token, new DeploymentPageToken(scope, lastDeploymentNumber));
return token;
}
private record DeploymentPageToken(String scope, int lastDeploymentNumber) {
}
public record DeploymentPage(List<DeploymentSummary> items, String nextToken) {
}
public String getActiveVersion(String envId, String profileId) {
return activeConfigStore.get(envId + "::" + profileId).orElse(null);
}
@@ -0,0 +1,70 @@
package io.github.hectorvent.floci.services.appconfig.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class DeploymentSummary {
@JsonProperty("CompletedAt")
private String completedAt;
@JsonProperty("ConfigurationName")
private String configurationName;
@JsonProperty("ConfigurationProfileId")
private String configurationProfileId;
@JsonProperty("ConfigurationVersion")
private String configurationVersion;
@JsonProperty("DeploymentDurationInMinutes")
private Integer deploymentDurationInMinutes;
@JsonProperty("DeploymentNumber")
private int deploymentNumber;
@JsonProperty("FinalBakeTimeInMinutes")
private Integer finalBakeTimeInMinutes;
@JsonProperty("GrowthFactor")
private Float growthFactor;
@JsonProperty("GrowthType")
private String growthType;
@JsonProperty("PercentageComplete")
private Float percentageComplete;
@JsonProperty("StartedAt")
private String startedAt;
@JsonProperty("State")
private String state;
@JsonProperty("Type")
private String type;
@JsonProperty("VersionLabel")
private String versionLabel;
public DeploymentSummary() {
}
public String getCompletedAt() { return completedAt; }
public void setCompletedAt(String completedAt) { this.completedAt = completedAt; }
public String getConfigurationName() { return configurationName; }
public void setConfigurationName(String configurationName) { this.configurationName = configurationName; }
public String getConfigurationProfileId() { return configurationProfileId; }
public void setConfigurationProfileId(String configurationProfileId) { this.configurationProfileId = configurationProfileId; }
public String getConfigurationVersion() { return configurationVersion; }
public void setConfigurationVersion(String configurationVersion) { this.configurationVersion = configurationVersion; }
public Integer getDeploymentDurationInMinutes() { return deploymentDurationInMinutes; }
public void setDeploymentDurationInMinutes(Integer deploymentDurationInMinutes) { this.deploymentDurationInMinutes = deploymentDurationInMinutes; }
public int getDeploymentNumber() { return deploymentNumber; }
public void setDeploymentNumber(int deploymentNumber) { this.deploymentNumber = deploymentNumber; }
public Integer getFinalBakeTimeInMinutes() { return finalBakeTimeInMinutes; }
public void setFinalBakeTimeInMinutes(Integer finalBakeTimeInMinutes) { this.finalBakeTimeInMinutes = finalBakeTimeInMinutes; }
public Float getGrowthFactor() { return growthFactor; }
public void setGrowthFactor(Float growthFactor) { this.growthFactor = growthFactor; }
public String getGrowthType() { return growthType; }
public void setGrowthType(String growthType) { this.growthType = growthType; }
public Float getPercentageComplete() { return percentageComplete; }
public void setPercentageComplete(Float percentageComplete) { this.percentageComplete = percentageComplete; }
public String getStartedAt() { return startedAt; }
public void setStartedAt(String startedAt) { this.startedAt = startedAt; }
public String getState() { return state; }
public void setState(String state) { this.state = state; }
public String getType() { return type; }
public void setType(String type) { this.type = type; }
public String getVersionLabel() { return versionLabel; }
public void setVersionLabel(String versionLabel) { this.versionLabel = versionLabel; }
}