mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat: adding appconfig service (#324)
* feat: adding appconfig service * fix: unittest appconfig service
This commit is contained in:
1 parent
494cff2e14
commit
e4d8d44724
25 files changed
+1284
-4
No files matched your search
@@ -79,6 +79,8 @@ public interface EmulatorConfig {
|
||||
SecretsManagerStorageConfig secretsmanager();
|
||||
AcmStorageConfig acm();
|
||||
OpenSearchStorageConfig opensearch();
|
||||
AppConfigStorageConfig appconfig();
|
||||
AppConfigDataStorageConfig appconfigdata();
|
||||
}
|
||||
|
||||
interface SsmStorageConfig {
|
||||
@@ -152,6 +154,20 @@ public interface EmulatorConfig {
|
||||
long flushIntervalMs();
|
||||
}
|
||||
|
||||
interface AppConfigStorageConfig {
|
||||
Optional<String> mode();
|
||||
|
||||
@WithDefault("5000")
|
||||
long flushIntervalMs();
|
||||
}
|
||||
|
||||
interface AppConfigDataStorageConfig {
|
||||
Optional<String> mode();
|
||||
|
||||
@WithDefault("5000")
|
||||
long flushIntervalMs();
|
||||
}
|
||||
|
||||
interface WalConfig {
|
||||
@WithDefault("30000")
|
||||
long compactionIntervalMs();
|
||||
@@ -196,6 +212,8 @@ public interface EmulatorConfig {
|
||||
OpenSearchServiceConfig opensearch();
|
||||
Ec2ServiceConfig ec2();
|
||||
EcsServiceConfig ecs();
|
||||
AppConfigServiceConfig appconfig();
|
||||
AppConfigDataServiceConfig appconfigdata();
|
||||
}
|
||||
|
||||
interface SsmServiceConfig {
|
||||
@@ -438,6 +456,16 @@ public interface EmulatorConfig {
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface AppConfigServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface AppConfigDataServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface InitHooksConfig {
|
||||
@WithDefault("/bin/sh")
|
||||
String shellExecutable();
|
||||
|
||||
@@ -3,6 +3,8 @@ package io.github.hectorvent.floci.core.common;
|
||||
import io.github.hectorvent.floci.services.cognito.CognitoOAuthController;
|
||||
import io.github.hectorvent.floci.services.cognito.CognitoWellKnownController;
|
||||
import io.github.hectorvent.floci.services.ses.SesController;
|
||||
import io.github.hectorvent.floci.services.appconfig.AppConfigController;
|
||||
import io.github.hectorvent.floci.services.appconfig.AppConfigDataController;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.container.ContainerRequestFilter;
|
||||
@@ -96,6 +98,12 @@ public class ServiceEnabledFilter implements ContainerRequestFilter {
|
||||
if (SesController.class.equals(resourceClass)) {
|
||||
return "email";
|
||||
}
|
||||
if (AppConfigController.class.equals(resourceClass)) {
|
||||
return "appconfig";
|
||||
}
|
||||
if (AppConfigDataController.class.equals(resourceClass)) {
|
||||
return "appconfigdata";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ public class ServiceRegistry {
|
||||
case "es" -> config.services().opensearch().enabled();
|
||||
case "ec2" -> config.services().ec2().enabled();
|
||||
case "ecs" -> config.services().ecs().enabled();
|
||||
case "appconfig" -> config.services().appconfig().enabled();
|
||||
case "appconfigdata" -> config.services().appconfigdata().enabled();
|
||||
default -> true;
|
||||
};
|
||||
}
|
||||
@@ -83,6 +85,8 @@ public class ServiceRegistry {
|
||||
if (config.services().acm().enabled()) enabled.add("acm");
|
||||
if (config.services().ses().enabled()) enabled.add("email");
|
||||
if (config.services().opensearch().enabled()) enabled.add("es");
|
||||
if (config.services().appconfig().enabled()) enabled.add("appconfig");
|
||||
if (config.services().appconfigdata().enabled()) enabled.add("appconfigdata");
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@@ -117,6 +121,8 @@ public class ServiceRegistry {
|
||||
services.put("es", status(config.services().opensearch().enabled()));
|
||||
services.put("ec2", status(config.services().ec2().enabled()));
|
||||
services.put("ecs", status(config.services().ecs().enabled()));
|
||||
services.put("appconfig", status(config.services().appconfig().enabled()));
|
||||
services.put("appconfigdata", status(config.services().appconfigdata().enabled()));
|
||||
return services;
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,8 @@ public class StorageFactory {
|
||||
case "cloudwatchmetrics" -> config.storage().services().cloudwatchmetrics().mode().orElse(globalMode);
|
||||
case "secretsmanager" -> config.storage().services().secretsmanager().mode().orElse(globalMode);
|
||||
case "opensearch" -> config.storage().services().opensearch().mode().orElse(globalMode);
|
||||
case "appconfig" -> config.storage().services().appconfig().mode().orElse(globalMode);
|
||||
case "appconfigdata" -> config.storage().services().appconfigdata().mode().orElse(globalMode);
|
||||
default -> globalMode;
|
||||
};
|
||||
}
|
||||
@@ -124,6 +126,8 @@ public class StorageFactory {
|
||||
case "cloudwatchmetrics" -> config.storage().services().cloudwatchmetrics().flushIntervalMs();
|
||||
case "secretsmanager" -> config.storage().services().secretsmanager().flushIntervalMs();
|
||||
case "opensearch" -> config.storage().services().opensearch().flushIntervalMs();
|
||||
case "appconfig" -> config.storage().services().appconfig().flushIntervalMs();
|
||||
case "appconfigdata" -> config.storage().services().appconfigdata().flushIntervalMs();
|
||||
default -> 5000L;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
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 jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
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;
|
||||
|
||||
@Path("/")
|
||||
@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;
|
||||
|
||||
@Inject
|
||||
public AppConfigController(AppConfigService service, ObjectMapper objectMapper) {
|
||||
this.service = service;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Application ────────────────────────────
|
||||
|
||||
@POST
|
||||
@Path("/applications")
|
||||
public Response createApplication(String body) throws IOException {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> request = objectMapper.readValue(body, Map.class);
|
||||
Application app = service.createApplication(request);
|
||||
return Response.status(201).entity(app).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/applications/{id}")
|
||||
public Response getApplication(@PathParam("id") String id) {
|
||||
return Response.ok(service.getApplication(id)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/applications")
|
||||
public Response listApplications() {
|
||||
List<Application> apps = service.listApplications();
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("Items");
|
||||
apps.forEach(items::addPOJO);
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/applications/{id}")
|
||||
public Response deleteApplication(@PathParam("id") String id) {
|
||||
service.deleteApplication(id);
|
||||
return Response.noContent().build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Environment ────────────────────────────
|
||||
|
||||
@POST
|
||||
@Path("/applications/{appId}/environments")
|
||||
public Response createEnvironment(@PathParam("appId") String appId, String body) throws IOException {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> request = objectMapper.readValue(body, Map.class);
|
||||
Environment env = service.createEnvironment(appId, request);
|
||||
return Response.status(201).entity(env).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/applications/{appId}/environments/{envId}")
|
||||
public Response getEnvironment(@PathParam("appId") String appId, @PathParam("envId") String envId) {
|
||||
return Response.ok(service.getEnvironment(appId, envId)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/applications/{appId}/environments")
|
||||
public Response listEnvironments(@PathParam("appId") String appId) {
|
||||
List<Environment> envs = service.listEnvironments(appId);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("Items");
|
||||
envs.forEach(items::addPOJO);
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Configuration Profile ────────────────────────────
|
||||
|
||||
@POST
|
||||
@Path("/applications/{appId}/configurationprofiles")
|
||||
public Response createConfigurationProfile(@PathParam("appId") String appId, String body) throws IOException {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> request = objectMapper.readValue(body, Map.class);
|
||||
ConfigurationProfile profile = service.createConfigurationProfile(appId, request);
|
||||
return Response.status(201).entity(profile).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/applications/{appId}/configurationprofiles/{profileId}")
|
||||
public Response getConfigurationProfile(@PathParam("appId") String appId, @PathParam("profileId") String profileId) {
|
||||
return Response.ok(service.getConfigurationProfile(appId, profileId)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/applications/{appId}/configurationprofiles")
|
||||
public Response listConfigurationProfiles(@PathParam("appId") String appId) {
|
||||
List<ConfigurationProfile> profiles = service.listConfigurationProfiles(appId);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("Items");
|
||||
profiles.forEach(items::addPOJO);
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Hosted Configuration Version ────────────────────────────
|
||||
|
||||
@POST
|
||||
@Path("/applications/{appId}/configurationprofiles/{profileId}/hostedconfigurationversions")
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
public Response createHostedConfigurationVersion(@PathParam("appId") String appId,
|
||||
@PathParam("profileId") String profileId,
|
||||
@HeaderParam("Content-Type") String contentType,
|
||||
@HeaderParam("Description") String description,
|
||||
byte[] content) {
|
||||
HostedConfigurationVersion version = service.createHostedConfigurationVersion(appId, profileId, content, contentType, description);
|
||||
return versionResponse(version, 201);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/applications/{appId}/configurationprofiles/{profileId}/hostedconfigurationversions/{versionNumber}")
|
||||
public Response getHostedConfigurationVersion(@PathParam("appId") String appId,
|
||||
@PathParam("profileId") String profileId,
|
||||
@PathParam("versionNumber") int versionNumber) {
|
||||
HostedConfigurationVersion version = service.getHostedConfigurationVersion(appId, profileId, versionNumber);
|
||||
return versionResponse(version, 200);
|
||||
}
|
||||
|
||||
private Response versionResponse(HostedConfigurationVersion v, int status) {
|
||||
Response.ResponseBuilder rb = Response.status(status).entity(v.getContent());
|
||||
rb.header("Application-Id", v.getApplicationId());
|
||||
rb.header("Configuration-Profile-Id", v.getConfigurationProfileId());
|
||||
rb.header("Version-Number", v.getVersionNumber());
|
||||
rb.header("Content-Type", v.getContentType());
|
||||
if (v.getDescription() != null) rb.header("Description", v.getDescription());
|
||||
return rb.build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Deployment Strategy ────────────────────────────
|
||||
|
||||
@POST
|
||||
@Path("/deploymentstrategies")
|
||||
public Response createDeploymentStrategy(String body) throws IOException {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> request = objectMapper.readValue(body, Map.class);
|
||||
DeploymentStrategy strategy = service.createDeploymentStrategy(request);
|
||||
return Response.status(201).entity(strategy).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/deploymentstrategies/{id}")
|
||||
public Response getDeploymentStrategy(@PathParam("id") String id) {
|
||||
return Response.ok(service.getDeploymentStrategy(id)).build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Deployment ────────────────────────────
|
||||
|
||||
@POST
|
||||
@Path("/applications/{appId}/environments/{envId}/deployments")
|
||||
public Response startDeployment(@PathParam("appId") String appId, @PathParam("envId") String envId, String body) throws IOException {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> request = objectMapper.readValue(body, Map.class);
|
||||
Deployment deployment = service.startDeployment(appId, envId, request);
|
||||
return Response.status(201).entity(deployment).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/applications/{appId}/environments/{envId}/deployments/{deploymentNumber}")
|
||||
public Response getDeployment(@PathParam("appId") String appId, @PathParam("envId") String envId, @PathParam("deploymentNumber") int deploymentNumber) {
|
||||
return Response.ok(service.getDeployment(appId, envId, deploymentNumber)).build();
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.appconfig.AppConfigDataService.ConfigurationData;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class AppConfigDataController {
|
||||
private static final Logger LOG = Logger.getLogger(AppConfigDataController.class);
|
||||
|
||||
private final AppConfigDataService service;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public AppConfigDataController(AppConfigDataService service, ObjectMapper objectMapper) {
|
||||
this.service = service;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/configurationsessions")
|
||||
public Response startConfigurationSession(String body) throws IOException {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> request = objectMapper.readValue(body, Map.class);
|
||||
String token = service.startConfigurationSession(request);
|
||||
return Response.status(201).entity(Map.of("InitialConfigurationToken", token)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/configuration")
|
||||
public Response getLatestConfiguration(@QueryParam("configuration_token") String token) {
|
||||
ConfigurationData data = service.getLatestConfiguration(token);
|
||||
return Response.ok(data.content())
|
||||
.header("Content-Type", data.contentType())
|
||||
.header("Version-Label", data.configurationVersion())
|
||||
.header("Next-Poll-Configuration-Token", data.nextPollConfigurationToken())
|
||||
.header("Next-Poll-Interval-In-Seconds", 15)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.ConfigurationSession;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.HostedConfigurationVersion;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@ApplicationScoped
|
||||
public class AppConfigDataService {
|
||||
private static final Logger LOG = Logger.getLogger(AppConfigDataService.class);
|
||||
|
||||
private final StorageBackend<String, ConfigurationSession> sessionStore;
|
||||
private final AppConfigService appConfigService;
|
||||
|
||||
@Inject
|
||||
public AppConfigDataService(StorageFactory storageFactory, AppConfigService appConfigService) {
|
||||
this.sessionStore = storageFactory.create("appconfigdata", "appconfigdata-sessions.json", new TypeReference<>() {});
|
||||
this.appConfigService = appConfigService;
|
||||
}
|
||||
|
||||
public String startConfigurationSession(Map<String, Object> request) {
|
||||
String appId = (String) request.get("ApplicationIdentifier");
|
||||
String envId = (String) request.get("EnvironmentIdentifier");
|
||||
String profileId = (String) request.get("ConfigurationProfileIdentifier");
|
||||
|
||||
// Validate resources exist
|
||||
appConfigService.getEnvironment(appId, envId);
|
||||
appConfigService.getConfigurationProfile(appId, profileId);
|
||||
|
||||
ConfigurationSession session = new ConfigurationSession();
|
||||
session.setId(UUID.randomUUID().toString());
|
||||
session.setApplicationId(appId);
|
||||
session.setEnvironmentId(envId);
|
||||
session.setConfigurationProfileId(profileId);
|
||||
session.setRequiredMinimumPollIntervalInSeconds((Integer) request.getOrDefault("RequiredMinimumPollIntervalInSeconds", 15));
|
||||
session.setCurrentToken(UUID.randomUUID().toString());
|
||||
|
||||
sessionStore.put(session.getCurrentToken(), session);
|
||||
LOG.infov("Started AppConfigData session {0} for app {1}, env {2}, profile {3}", session.getId(), appId, envId, profileId);
|
||||
return session.getCurrentToken();
|
||||
}
|
||||
|
||||
public ConfigurationData getLatestConfiguration(String token) {
|
||||
ConfigurationSession session = sessionStore.get(token)
|
||||
.orElseThrow(() -> new AwsException("BadRequestException", "Invalid configuration token", 400));
|
||||
|
||||
String activeVersion = appConfigService.getActiveVersion(session.getEnvironmentId(), session.getConfigurationProfileId());
|
||||
|
||||
HostedConfigurationVersion version = null;
|
||||
if (activeVersion != null) {
|
||||
try {
|
||||
version = appConfigService.getHostedConfigurationVersion(session.getApplicationId(), session.getConfigurationProfileId(), Integer.parseInt(activeVersion));
|
||||
} catch (Exception e) {
|
||||
LOG.warnv("Active version {0} not found for session {1}", activeVersion, session.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// Generate next token
|
||||
String nextToken = UUID.randomUUID().toString();
|
||||
session.setCurrentToken(nextToken);
|
||||
sessionStore.delete(token); // Old token is invalid
|
||||
sessionStore.put(nextToken, session);
|
||||
|
||||
byte[] content = (version != null) ? version.getContent() : new byte[0];
|
||||
String contentType = (version != null) ? version.getContentType() : "application/octet-stream";
|
||||
String versionLabel = (version != null) ? String.valueOf(version.getVersionNumber()) : "";
|
||||
|
||||
return new ConfigurationData(content, contentType, versionLabel, nextToken);
|
||||
}
|
||||
|
||||
public record ConfigurationData(byte[] content, String contentType, String configurationVersion, String nextPollConfigurationToken) {}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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 jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ApplicationScoped
|
||||
public class AppConfigService {
|
||||
private static final Logger LOG = Logger.getLogger(AppConfigService.class);
|
||||
|
||||
private final StorageBackend<String, Application> applicationStore;
|
||||
private final StorageBackend<String, Environment> environmentStore;
|
||||
private final StorageBackend<String, ConfigurationProfile> profileStore;
|
||||
private final StorageBackend<String, DeploymentStrategy> strategyStore;
|
||||
private final StorageBackend<String, HostedConfigurationVersion> versionStore;
|
||||
private final StorageBackend<String, Deployment> deploymentStore;
|
||||
private final StorageBackend<String, String> activeConfigStore; // envId::profileId -> versionNumber
|
||||
|
||||
@Inject
|
||||
public AppConfigService(StorageFactory storageFactory, EmulatorConfig config) {
|
||||
this.applicationStore = storageFactory.create("appconfig", "appconfig-applications.json", new TypeReference<>() {});
|
||||
this.environmentStore = storageFactory.create("appconfig", "appconfig-environments.json", new TypeReference<>() {});
|
||||
this.profileStore = storageFactory.create("appconfig", "appconfig-profiles.json", new TypeReference<>() {});
|
||||
this.strategyStore = storageFactory.create("appconfig", "appconfig-strategies.json", new TypeReference<>() {});
|
||||
this.versionStore = storageFactory.create("appconfig", "appconfig-versions.json", new TypeReference<>() {});
|
||||
this.deploymentStore = storageFactory.create("appconfig", "appconfig-deployments.json", new TypeReference<>() {});
|
||||
this.activeConfigStore = storageFactory.create("appconfig", "appconfig-active-configs.json", new TypeReference<>() {});
|
||||
}
|
||||
|
||||
// ──────────────────────────── Application ────────────────────────────
|
||||
|
||||
public Application createApplication(Map<String, Object> request) {
|
||||
Application app = new Application();
|
||||
app.setId(shortId(7));
|
||||
app.setName((String) request.get("Name"));
|
||||
app.setDescription((String) request.get("Description"));
|
||||
applicationStore.put(app.getId(), app);
|
||||
return app;
|
||||
}
|
||||
|
||||
public Application getApplication(String id) {
|
||||
return applicationStore.get(id).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Application not found", 404));
|
||||
}
|
||||
|
||||
public List<Application> listApplications() {
|
||||
return applicationStore.scan(k -> true);
|
||||
}
|
||||
|
||||
public void deleteApplication(String id) {
|
||||
applicationStore.delete(id);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Environment ────────────────────────────
|
||||
|
||||
public Environment createEnvironment(String appId, Map<String, Object> request) {
|
||||
getApplication(appId);
|
||||
Environment env = new Environment();
|
||||
env.setId(shortId(7));
|
||||
env.setApplicationId(appId);
|
||||
env.setName((String) request.get("Name"));
|
||||
env.setDescription((String) request.get("Description"));
|
||||
env.setState("READY");
|
||||
environmentStore.put(env.getId(), env);
|
||||
return env;
|
||||
}
|
||||
|
||||
public Environment getEnvironment(String appId, String envId) {
|
||||
Environment env = environmentStore.get(envId).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Environment not found", 404));
|
||||
if (!env.getApplicationId().equals(appId)) throw new AwsException("ResourceNotFoundException", "Environment not found in this application", 404);
|
||||
return env;
|
||||
}
|
||||
|
||||
public List<Environment> listEnvironments(String appId) {
|
||||
return environmentStore.scan(k -> true).stream()
|
||||
.filter(e -> e.getApplicationId().equals(appId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Configuration Profile ────────────────────────────
|
||||
|
||||
public ConfigurationProfile createConfigurationProfile(String appId, Map<String, Object> request) {
|
||||
getApplication(appId);
|
||||
ConfigurationProfile profile = new ConfigurationProfile();
|
||||
profile.setId(shortId(7));
|
||||
profile.setApplicationId(appId);
|
||||
profile.setName((String) request.get("Name"));
|
||||
profile.setDescription((String) request.get("Description"));
|
||||
profile.setLocationUri((String) request.get("LocationUri"));
|
||||
profile.setType((String) request.get("Type"));
|
||||
profileStore.put(profile.getId(), profile);
|
||||
return profile;
|
||||
}
|
||||
|
||||
public ConfigurationProfile getConfigurationProfile(String appId, String profileId) {
|
||||
ConfigurationProfile profile = profileStore.get(profileId).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Configuration profile not found", 404));
|
||||
if (!profile.getApplicationId().equals(appId)) throw new AwsException("ResourceNotFoundException", "Profile not found in this application", 404);
|
||||
return profile;
|
||||
}
|
||||
|
||||
public List<ConfigurationProfile> listConfigurationProfiles(String appId) {
|
||||
return profileStore.scan(k -> true).stream()
|
||||
.filter(p -> p.getApplicationId().equals(appId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Hosted Configuration Version ────────────────────────────
|
||||
|
||||
public HostedConfigurationVersion createHostedConfigurationVersion(String appId, String profileId, byte[] content, String contentType, String description) {
|
||||
getConfigurationProfile(appId, profileId);
|
||||
String prefix = appId + "::" + profileId + "::";
|
||||
int nextVersion = versionStore.scan(k -> k.startsWith(prefix))
|
||||
.stream().mapToInt(HostedConfigurationVersion::getVersionNumber).max().orElse(0) + 1;
|
||||
|
||||
HostedConfigurationVersion version = new HostedConfigurationVersion();
|
||||
version.setApplicationId(appId);
|
||||
version.setConfigurationProfileId(profileId);
|
||||
version.setVersionNumber(nextVersion);
|
||||
version.setContent(content);
|
||||
version.setContentType(contentType);
|
||||
version.setDescription(description);
|
||||
|
||||
versionStore.put(prefix + nextVersion, version);
|
||||
return version;
|
||||
}
|
||||
|
||||
public HostedConfigurationVersion getHostedConfigurationVersion(String appId, String profileId, int versionNumber) {
|
||||
return versionStore.get(appId + "::" + profileId + "::" + versionNumber)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Hosted configuration version not found", 404));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Deployment Strategy ────────────────────────────
|
||||
|
||||
public DeploymentStrategy createDeploymentStrategy(Map<String, Object> request) {
|
||||
DeploymentStrategy strategy = new DeploymentStrategy();
|
||||
strategy.setId(shortId(7));
|
||||
strategy.setName((String) request.get("Name"));
|
||||
strategy.setDescription((String) request.get("Description"));
|
||||
strategy.setDeploymentDurationInMinutes((Integer) request.getOrDefault("DeploymentDurationInMinutes", 0));
|
||||
strategy.setGrowthFactor(((Number) request.getOrDefault("GrowthFactor", 100.0f)).floatValue());
|
||||
strategy.setFinalBakeTimeInMinutes((Integer) request.getOrDefault("FinalBakeTimeInMinutes", 0));
|
||||
strategy.setGrowthType((String) request.getOrDefault("GrowthType", "LINEAR"));
|
||||
strategy.setReplicateTo((String) request.getOrDefault("ReplicateTo", "NONE"));
|
||||
strategyStore.put(strategy.getId(), strategy);
|
||||
return strategy;
|
||||
}
|
||||
|
||||
public DeploymentStrategy getDeploymentStrategy(String id) {
|
||||
return strategyStore.get(id).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Deployment strategy not found", 404));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Deployment ────────────────────────────
|
||||
|
||||
public Deployment startDeployment(String appId, String envId, Map<String, Object> request) {
|
||||
getEnvironment(appId, envId);
|
||||
String profileId = (String) request.get("ConfigurationProfileId");
|
||||
String version = (String) request.get("ConfigurationVersion");
|
||||
String strategyId = (String) request.get("DeploymentStrategyId");
|
||||
|
||||
getConfigurationProfile(appId, profileId);
|
||||
getDeploymentStrategy(strategyId);
|
||||
|
||||
Deployment deployment = new Deployment();
|
||||
deployment.setApplicationId(appId);
|
||||
deployment.setEnvironmentId(envId);
|
||||
deployment.setConfigurationProfileId(profileId);
|
||||
deployment.setConfigurationVersion(version);
|
||||
deployment.setDeploymentStrategyId(strategyId);
|
||||
deployment.setDeploymentNumber(deploymentStore.keys().size() + 1);
|
||||
deployment.setState("COMPLETE"); // Synchronous immediate deployment
|
||||
deployment.setDescription((String) request.get("Description"));
|
||||
|
||||
deploymentStore.put(appId + "::" + envId + "::" + deployment.getDeploymentNumber(), deployment);
|
||||
|
||||
// Update active configuration
|
||||
activeConfigStore.put(envId + "::" + profileId, version);
|
||||
|
||||
LOG.infov("Started deployment for app {0}, env {1}, profile {2}, version {3}. State: COMPLETE", appId, envId, profileId, version);
|
||||
return deployment;
|
||||
}
|
||||
|
||||
public Deployment getDeployment(String appId, String envId, int deploymentNumber) {
|
||||
return deploymentStore.get(appId + "::" + envId + "::" + deploymentNumber)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Deployment not found", 404));
|
||||
}
|
||||
|
||||
public String getActiveVersion(String envId, String profileId) {
|
||||
return activeConfigStore.get(envId + "::" + profileId).orElse(null);
|
||||
}
|
||||
|
||||
private static String shortId(int length) {
|
||||
return UUID.randomUUID().toString().replace("-", "").substring(0, length);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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 Application {
|
||||
@JsonProperty("Id")
|
||||
private String id;
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
@JsonProperty("Description")
|
||||
private String description;
|
||||
|
||||
public Application() {}
|
||||
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
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 ConfigurationProfile {
|
||||
@JsonProperty("Id")
|
||||
private String id;
|
||||
@JsonProperty("ApplicationId")
|
||||
private String applicationId;
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
@JsonProperty("Description")
|
||||
private String description;
|
||||
@JsonProperty("LocationUri")
|
||||
private String locationUri;
|
||||
@JsonProperty("Type")
|
||||
private String type; // AWS.AppConfig.FeatureFlags, AWS.Freeform
|
||||
|
||||
public ConfigurationProfile() {}
|
||||
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public String getLocationUri() { return locationUri; }
|
||||
public void setLocationUri(String locationUri) { this.locationUri = locationUri; }
|
||||
|
||||
public String getType() { return type; }
|
||||
public void setType(String type) { this.type = type; }
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package io.github.hectorvent.floci.services.appconfig.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ConfigurationSession {
|
||||
private String id;
|
||||
private String applicationId;
|
||||
private String environmentId;
|
||||
private String configurationProfileId;
|
||||
private int requiredMinimumPollIntervalInSeconds;
|
||||
private String currentToken;
|
||||
private String lastConfigurationVersion;
|
||||
|
||||
public ConfigurationSession() {}
|
||||
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
|
||||
public String getEnvironmentId() { return environmentId; }
|
||||
public void setEnvironmentId(String environmentId) { this.environmentId = environmentId; }
|
||||
|
||||
public String getConfigurationProfileId() { return configurationProfileId; }
|
||||
public void setConfigurationProfileId(String configurationProfileId) { this.configurationProfileId = configurationProfileId; }
|
||||
|
||||
public int getRequiredMinimumPollIntervalInSeconds() { return requiredMinimumPollIntervalInSeconds; }
|
||||
public void setRequiredMinimumPollIntervalInSeconds(int requiredMinimumPollIntervalInSeconds) { this.requiredMinimumPollIntervalInSeconds = requiredMinimumPollIntervalInSeconds; }
|
||||
|
||||
public String getCurrentToken() { return currentToken; }
|
||||
public void setCurrentToken(String currentToken) { this.currentToken = currentToken; }
|
||||
|
||||
public String getLastConfigurationVersion() { return lastConfigurationVersion; }
|
||||
public void setLastConfigurationVersion(String lastConfigurationVersion) { this.lastConfigurationVersion = lastConfigurationVersion; }
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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 Deployment {
|
||||
@JsonProperty("ApplicationId")
|
||||
private String applicationId;
|
||||
@JsonProperty("EnvironmentId")
|
||||
private String environmentId;
|
||||
@JsonProperty("ConfigurationProfileId")
|
||||
private String configurationProfileId;
|
||||
@JsonProperty("DeploymentNumber")
|
||||
private int deploymentNumber;
|
||||
@JsonProperty("ConfigurationName")
|
||||
private String configurationName;
|
||||
@JsonProperty("ConfigurationVersion")
|
||||
private String configurationVersion;
|
||||
@JsonProperty("DeploymentStrategyId")
|
||||
private String deploymentStrategyId;
|
||||
@JsonProperty("State")
|
||||
private String state; // BAKING, VALIDATING, DEPLOYING, COMPLETE, ROLLING_BACK, ROLLED_BACK
|
||||
@JsonProperty("Description")
|
||||
private String description;
|
||||
|
||||
public Deployment() {}
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
|
||||
public String getEnvironmentId() { return environmentId; }
|
||||
public void setEnvironmentId(String environmentId) { this.environmentId = environmentId; }
|
||||
|
||||
public String getConfigurationProfileId() { return configurationProfileId; }
|
||||
public void setConfigurationProfileId(String configurationProfileId) { this.configurationProfileId = configurationProfileId; }
|
||||
|
||||
public int getDeploymentNumber() { return deploymentNumber; }
|
||||
public void setDeploymentNumber(int deploymentNumber) { this.deploymentNumber = deploymentNumber; }
|
||||
|
||||
public String getConfigurationName() { return configurationName; }
|
||||
public void setConfigurationName(String configurationName) { this.configurationName = configurationName; }
|
||||
|
||||
public String getConfigurationVersion() { return configurationVersion; }
|
||||
public void setConfigurationVersion(String configurationVersion) { this.configurationVersion = configurationVersion; }
|
||||
|
||||
public String getDeploymentStrategyId() { return deploymentStrategyId; }
|
||||
public void setDeploymentStrategyId(String deploymentStrategyId) { this.deploymentStrategyId = deploymentStrategyId; }
|
||||
|
||||
public String getState() { return state; }
|
||||
public void setState(String state) { this.state = state; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
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 DeploymentStrategy {
|
||||
@JsonProperty("Id")
|
||||
private String id;
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
@JsonProperty("Description")
|
||||
private String description;
|
||||
@JsonProperty("DeploymentDurationInMinutes")
|
||||
private int deploymentDurationInMinutes;
|
||||
@JsonProperty("GrowthFactor")
|
||||
private float growthFactor;
|
||||
@JsonProperty("FinalBakeTimeInMinutes")
|
||||
private int finalBakeTimeInMinutes;
|
||||
@JsonProperty("GrowthType")
|
||||
private String growthType; // LINEAR, EXPONENTIAL
|
||||
@JsonProperty("ReplicateTo")
|
||||
private String replicateTo; // NONE, SSM_DOCUMENT
|
||||
|
||||
public DeploymentStrategy() {}
|
||||
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public int getDeploymentDurationInMinutes() { return deploymentDurationInMinutes; }
|
||||
public void setDeploymentDurationInMinutes(int deploymentDurationInMinutes) { this.deploymentDurationInMinutes = deploymentDurationInMinutes; }
|
||||
|
||||
public float getGrowthFactor() { return growthFactor; }
|
||||
public void setGrowthFactor(float growthFactor) { this.growthFactor = growthFactor; }
|
||||
|
||||
public int getFinalBakeTimeInMinutes() { return finalBakeTimeInMinutes; }
|
||||
public void setFinalBakeTimeInMinutes(int finalBakeTimeInMinutes) { this.finalBakeTimeInMinutes = finalBakeTimeInMinutes; }
|
||||
|
||||
public String getGrowthType() { return growthType; }
|
||||
public void setGrowthType(String growthType) { this.growthType = growthType; }
|
||||
|
||||
public String getReplicateTo() { return replicateTo; }
|
||||
public void setReplicateTo(String replicateTo) { this.replicateTo = replicateTo; }
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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 Environment {
|
||||
@JsonProperty("Id")
|
||||
private String id;
|
||||
@JsonProperty("ApplicationId")
|
||||
private String applicationId;
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
@JsonProperty("Description")
|
||||
private String description;
|
||||
@JsonProperty("State")
|
||||
private String state; // READY, DEPLOYING, ROLLING_BACK, ROLLED_BACK
|
||||
|
||||
public Environment() {}
|
||||
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public String getState() { return state; }
|
||||
public void setState(String state) { this.state = state; }
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
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 HostedConfigurationVersion {
|
||||
@JsonProperty("ApplicationId")
|
||||
private String applicationId;
|
||||
@JsonProperty("ConfigurationProfileId")
|
||||
private String configurationProfileId;
|
||||
@JsonProperty("VersionNumber")
|
||||
private int versionNumber;
|
||||
@JsonProperty("Description")
|
||||
private String description;
|
||||
@JsonProperty("Content")
|
||||
private byte[] content;
|
||||
@JsonProperty("ContentType")
|
||||
private String contentType;
|
||||
|
||||
public HostedConfigurationVersion() {}
|
||||
|
||||
public String getApplicationId() { return applicationId; }
|
||||
public void setApplicationId(String applicationId) { this.applicationId = applicationId; }
|
||||
|
||||
public String getConfigurationProfileId() { return configurationProfileId; }
|
||||
public void setConfigurationProfileId(String configurationProfileId) { this.configurationProfileId = configurationProfileId; }
|
||||
|
||||
public int getVersionNumber() { return versionNumber; }
|
||||
public void setVersionNumber(int versionNumber) { this.versionNumber = versionNumber; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public byte[] getContent() { return content; }
|
||||
public void setContent(byte[] content) { this.content = content; }
|
||||
|
||||
public String getContentType() { return contentType; }
|
||||
public void setContentType(String contentType) { this.contentType = contentType; }
|
||||
}
|
||||
Reference in new issue
Block a user