mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
1 parent
73546637ec
commit
ecf25d4736
5 files changed
+161
-8
No files matched your search
@@ -274,6 +274,20 @@ public class LambdaController {
|
||||
return Response.status(201).entity(buildFunctionConfiguration(version)).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/functions/{functionName}/versions")
|
||||
public Response listVersionsByFunction(@Context HttpHeaders headers,
|
||||
@PathParam("functionName") String functionName) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<LambdaFunction> versions = lambdaService.listVersionsByFunction(region, functionName);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("Versions");
|
||||
for (LambdaFunction v : versions) {
|
||||
items.add(objectMapper.valueToTree(buildFunctionConfiguration(v)));
|
||||
}
|
||||
return Response.ok(root).build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Aliases ────────────────────────────
|
||||
|
||||
@POST
|
||||
@@ -384,7 +398,7 @@ public class LambdaController {
|
||||
if (fn.getImageUri() != null) node.put("ImageUri", fn.getImageUri());
|
||||
node.put("LastModified", String.valueOf(fn.getLastModified()));
|
||||
node.put("RevisionId", fn.getRevisionId());
|
||||
node.put("Version", "$LATEST");
|
||||
node.put("Version", fn.getVersion());
|
||||
|
||||
if (fn.getEnvironment() != null && !fn.getEnvironment().isEmpty()) {
|
||||
ObjectNode envNode = node.putObject("Environment");
|
||||
|
||||
@@ -66,14 +66,18 @@ public class LambdaFunctionStore {
|
||||
|
||||
public void save(String region, LambdaFunction fn) {
|
||||
// Remove old index entry if URL changed or was removed
|
||||
get(region, fn.getFunctionName()).ifPresent(this::deindexFunction);
|
||||
get(region, fn.getFunctionName(), fn.getVersion()).ifPresent(this::deindexFunction);
|
||||
|
||||
backend.put(regionKey(region, fn.getFunctionName()), fn);
|
||||
backend.put(regionKey(region, fn.getFunctionName(), fn.getVersion()), fn);
|
||||
indexFunction(fn);
|
||||
}
|
||||
|
||||
public Optional<LambdaFunction> get(String region, String functionName) {
|
||||
return backend.get(regionKey(region, functionName));
|
||||
return get(region, functionName, "$LATEST");
|
||||
}
|
||||
|
||||
public Optional<LambdaFunction> get(String region, String functionName, String version) {
|
||||
return backend.get(regionKey(region, functionName, version));
|
||||
}
|
||||
|
||||
public Optional<LambdaFunction> getByUrlId(String urlId) {
|
||||
@@ -82,6 +86,11 @@ public class LambdaFunctionStore {
|
||||
|
||||
public List<LambdaFunction> list(String region) {
|
||||
String prefix = "lambda::" + region + "::";
|
||||
return backend.scan(key -> key.startsWith(prefix) && key.endsWith("::$LATEST"));
|
||||
}
|
||||
|
||||
public List<LambdaFunction> listVersions(String region, String functionName) {
|
||||
String prefix = "lambda::" + region + "::" + functionName + "::";
|
||||
return backend.scan(key -> key.startsWith(prefix));
|
||||
}
|
||||
|
||||
@@ -90,13 +99,14 @@ public class LambdaFunctionStore {
|
||||
}
|
||||
|
||||
public void delete(String region, String functionName) {
|
||||
get(region, functionName).ifPresent(fn -> {
|
||||
// Delete all versions
|
||||
listVersions(region, functionName).forEach(fn -> {
|
||||
deindexFunction(fn);
|
||||
backend.delete(regionKey(region, functionName));
|
||||
backend.delete(regionKey(region, functionName, fn.getVersion()));
|
||||
});
|
||||
}
|
||||
|
||||
private static String regionKey(String region, String functionName) {
|
||||
return "lambda::" + region + "::" + functionName;
|
||||
private static String regionKey(String region, String functionName, String version) {
|
||||
return "lambda::" + region + "::" + functionName + "::" + (version != null ? version : "$LATEST");
|
||||
}
|
||||
}
|
||||
@@ -359,6 +359,7 @@ public class LambdaService {
|
||||
int version = versionCounters.merge(region + "::" + functionName, 1, Integer::sum);
|
||||
LambdaFunction snapshot = new LambdaFunction();
|
||||
snapshot.setFunctionName(fn.getFunctionName());
|
||||
snapshot.setVersion(String.valueOf(version));
|
||||
snapshot.setFunctionArn(fn.getFunctionArn().replace(":$LATEST", "") + ":" + version);
|
||||
snapshot.setRuntime(fn.getRuntime());
|
||||
snapshot.setRole(fn.getRole());
|
||||
@@ -372,9 +373,17 @@ public class LambdaService {
|
||||
snapshot.setEnvironment(fn.getEnvironment());
|
||||
snapshot.setLastModified(System.currentTimeMillis());
|
||||
snapshot.setRevisionId(UUID.randomUUID().toString());
|
||||
|
||||
functionStore.save(region, snapshot);
|
||||
LOG.infov("Published version {0} for function {1}", version, functionName);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
public List<LambdaFunction> listVersionsByFunction(String region, String functionName) {
|
||||
getFunction(region, functionName); // verify function exists
|
||||
return functionStore.listVersions(region, functionName);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Aliases ────────────────────────────
|
||||
|
||||
public LambdaAlias createAlias(String region, String functionName, String aliasName,
|
||||
|
||||
@@ -30,6 +30,7 @@ public class LambdaFunction {
|
||||
private Map<String, String> tags = new HashMap<>();
|
||||
private long lastModified;
|
||||
private String revisionId;
|
||||
private String version = "$LATEST";
|
||||
private LambdaUrlConfig urlConfig;
|
||||
|
||||
@JsonIgnore
|
||||
@@ -95,6 +96,9 @@ public class LambdaFunction {
|
||||
public String getRevisionId() { return revisionId; }
|
||||
public void setRevisionId(String revisionId) { this.revisionId = revisionId; }
|
||||
|
||||
public String getVersion() { return version; }
|
||||
public void setVersion(String version) { this.version = version; }
|
||||
|
||||
public LambdaUrlConfig getUrlConfig() { return urlConfig; }
|
||||
public void setUrlConfig(LambdaUrlConfig urlConfig) { this.urlConfig = urlConfig; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user