feat: per-app resource limits, auto-slug, and polished create dialogs

Add per-app memory limit and CPU shares (stored on AppEntity, used by
DeploymentService with fallback to global defaults). JAR upload is now
optional at creation time. Both create modals show the computed slug in
the dialog title and use consistent Cancel-left/Action-right button
layout with inline styles to avoid Modal CSS conflicts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-07 14:53:57 +02:00
parent 3d41d4a3da
commit 8febdba533
12 changed files with 180 additions and 70 deletions

View File

@@ -52,13 +52,14 @@ public class AppController {
public ResponseEntity<AppResponse> create(
@PathVariable UUID environmentId,
@RequestPart("metadata") String metadataJson,
@RequestPart("file") MultipartFile file,
@RequestPart(value = "file", required = false) MultipartFile file,
Authentication authentication) {
try {
var request = objectMapper.readValue(metadataJson, CreateAppRequest.class);
UUID actorId = resolveActorId(authentication);
var entity = appService.create(environmentId, request.slug(), request.displayName(), file, actorId);
var entity = appService.create(environmentId, request.slug(), request.displayName(),
file, request.memoryLimit(), request.cpuShares(), actorId);
return ResponseEntity.status(HttpStatus.CREATED).body(toResponse(entity));
} catch (IllegalArgumentException e) {
var msg = e.getMessage();
@@ -168,6 +169,7 @@ public class AppController {
app.getId(), app.getEnvironmentId(), app.getSlug(), app.getDisplayName(),
app.getJarOriginalFilename(), app.getJarSizeBytes(), app.getJarChecksum(),
app.getExposedPort(), routeUrl,
app.getMemoryLimit(), app.getCpuShares(),
app.getCurrentDeploymentId(), app.getPreviousDeploymentId(),
app.getCreatedAt(), app.getUpdatedAt());
}

View File

@@ -42,6 +42,12 @@ public class AppEntity {
@Column(name = "exposed_port")
private Integer exposedPort;
@Column(name = "memory_limit", length = 20)
private String memoryLimit;
@Column(name = "cpu_shares")
private Integer cpuShares;
@Column(name = "created_at", nullable = false)
private Instant createdAt;
@@ -81,6 +87,10 @@ public class AppEntity {
public void setPreviousDeploymentId(UUID previousDeploymentId) { this.previousDeploymentId = previousDeploymentId; }
public Integer getExposedPort() { return exposedPort; }
public void setExposedPort(Integer exposedPort) { this.exposedPort = exposedPort; }
public String getMemoryLimit() { return memoryLimit; }
public void setMemoryLimit(String memoryLimit) { this.memoryLimit = memoryLimit; }
public Integer getCpuShares() { return cpuShares; }
public void setCpuShares(Integer cpuShares) { this.cpuShares = cpuShares; }
public Instant getCreatedAt() { return createdAt; }
public Instant getUpdatedAt() { return updatedAt; }
}

View File

@@ -41,8 +41,11 @@ public class AppService {
this.runtimeConfig = runtimeConfig;
}
public AppEntity create(UUID envId, String slug, String displayName, MultipartFile jarFile, UUID actorId) {
validateJarFile(jarFile);
public AppEntity create(UUID envId, String slug, String displayName,
MultipartFile jarFile, String memoryLimit, Integer cpuShares, UUID actorId) {
if (jarFile != null && !jarFile.isEmpty()) {
validateJarFile(jarFile);
}
var env = environmentRepository.findById(envId)
.orElseThrow(() -> new IllegalArgumentException("Environment not found: " + envId));
@@ -54,17 +57,21 @@ public class AppService {
var tenantId = env.getTenantId();
enforceTierLimit(tenantId);
var relativePath = "tenants/" + tenantId + "/envs/" + env.getSlug() + "/apps/" + slug + "/app.jar";
var checksum = storeJar(jarFile, relativePath);
var entity = new AppEntity();
entity.setEnvironmentId(envId);
entity.setSlug(slug);
entity.setDisplayName(displayName);
entity.setJarStoragePath(relativePath);
entity.setJarChecksum(checksum);
entity.setJarOriginalFilename(jarFile.getOriginalFilename());
entity.setJarSizeBytes(jarFile.getSize());
entity.setMemoryLimit(memoryLimit);
entity.setCpuShares(cpuShares);
if (jarFile != null && !jarFile.isEmpty()) {
var relativePath = "tenants/" + tenantId + "/envs/" + env.getSlug() + "/apps/" + slug + "/app.jar";
var checksum = storeJar(jarFile, relativePath);
entity.setJarStoragePath(relativePath);
entity.setJarChecksum(checksum);
entity.setJarOriginalFilename(jarFile.getOriginalFilename());
entity.setJarSizeBytes(jarFile.getSize());
}
var saved = appRepository.save(entity);

View File

@@ -13,6 +13,8 @@ public record AppResponse(
String jarChecksum,
Integer exposedPort,
String routeUrl,
String memoryLimit,
Integer cpuShares,
UUID currentDeploymentId,
UUID previousDeploymentId,
Instant createdAt,

View File

@@ -9,5 +9,9 @@ public record CreateAppRequest(
@Pattern(regexp = "^[a-z0-9][a-z0-9-]*[a-z0-9]$", message = "Slug must be lowercase alphanumeric with hyphens")
String slug,
@NotBlank @Size(max = 255)
String displayName
String displayName,
@Size(max = 20)
@Pattern(regexp = "^(\\d+[mgMG])?$", message = "Memory limit must be like 256m, 512m, 1g")
String memoryLimit,
Integer cpuShares
) {}

View File

@@ -137,6 +137,13 @@ public class DeploymentService {
String.valueOf(app.getExposedPort()));
}
long memoryBytes = app.getMemoryLimit() != null
? parseMemoryBytes(app.getMemoryLimit())
: runtimeConfig.parseMemoryLimitBytes();
int cpuShares = app.getCpuShares() != null
? app.getCpuShares()
: runtimeConfig.getContainerCpuShares();
var containerId = runtimeOrchestrator.startContainer(new StartContainerRequest(
deployment.getImageRef(),
containerName,
@@ -149,8 +156,8 @@ public class DeploymentService {
"CAMELEER_ENVIRONMENT_ID", env.getSlug(),
"CAMELEER_DISPLAY_NAME", containerName
),
runtimeConfig.parseMemoryLimitBytes(),
runtimeConfig.getContainerCpuShares(),
memoryBytes,
cpuShares,
runtimeConfig.getAgentHealthPort(),
labels
));
@@ -232,6 +239,16 @@ public class DeploymentService {
return deploymentRepository.findById(deploymentId);
}
static long parseMemoryBytes(String limit) {
var s = limit.trim().toLowerCase();
if (s.endsWith("g")) {
return Long.parseLong(s.substring(0, s.length() - 1)) * 1024 * 1024 * 1024;
} else if (s.endsWith("m")) {
return Long.parseLong(s.substring(0, s.length() - 1)) * 1024 * 1024;
}
return Long.parseLong(s);
}
boolean waitForHealthy(String containerId, int timeoutSeconds) {
var deadline = System.currentTimeMillis() + (timeoutSeconds * 1000L);
while (System.currentTimeMillis() < deadline) {

View File

@@ -0,0 +1,2 @@
ALTER TABLE apps ADD COLUMN memory_limit VARCHAR(20);
ALTER TABLE apps ADD COLUMN cpu_shares INTEGER;