mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(bedrockagentcore): emulate the AgentCore control plane and InvokeAgentRuntime stub (#2316)
* docs(bedrockagentcore): add AgentCore emulation design + upgrade path
* feat(bedrockagentcore): add agent runtime CRUD control plane
Implements the bedrock-agentcore-control runtime registry (Phase 1):
Create/Get/List/Update/Delete AgentRuntime plus ListAgentRuntimeVersions,
with immutable version snapshots, cursor pagination, and ISO-8601 timestamps.
- REST-JSON controller + service + reflection-safe models
- ServiceRegistry descriptor + EmulatorConfig toggle
- Unit + RestAssured integration tests
- AWS SDK v2 compatibility test (sdk-test-java)
- Service docs page
Refs lex00/floci#2
* feat(bedrockagentcore): add agent runtime endpoints
Phase 2: Create/Get/Update/Delete/List AgentRuntimeEndpoint under
/runtimes/{id}/runtime-endpoints/, with a DEFAULT endpoint auto-created per
runtime and agentEndpoint/<uuid> ARNs. RestAssured + SDK v2 compat tests.
Refs lex00/floci#3
* feat(bedrockagentcore): add InvokeAgentRuntime data-plane stub
Phase 3: POST /runtimes/{agentRuntimeArn}/invocations returns a fixed,
configurable canned response ({"output":"yes"}) and echoes the runtime
session id. Opaque payload is never parsed; streaming is not emulated.
Separate stateless bedrock-agentcore service. RestAssured + SDK v2 compat tests.
Refs lex00/floci#4
* feat(bedrockagentcore): add tagging and workload identity
Phase 4:
- TagResource/UntagResource/ListTagsForResource for runtime ARNs via a
TagHandler on the shared /tags/{arn} route
- Workload identity RPC CRUD (POST /identities/<Op>); each runtime auto-creates
a resolvable workload identity
- Workload-identity timestamps are epoch-seconds (unixTimestamp), distinct from
the runtime ISO-8601 timestamps
RestAssured + SDK v2 compat tests.
Refs lex00/floci#5
* feat(bedrockagentcore): add gateway and memory primitives
Phase 5 (optional): metadata-only CRUD registries.
- Gateways (POST /gateways/) + gateway targets, standard REST
- Memory (POST /memories/create, GET /memories/{id}/details, ...), action-suffix
- Gateway timestamps are ISO-8601; memory timestamps are epoch seconds
RestAssured + SDK v2 compat tests.
Refs lex00/floci#6
* fix(bedrockagentcore): correctness fixes from adversarial audit
- Fix ListAgentRuntimeVersions pagination cycling for >=10 versions: sort by
the pagination cursor and zero-pad the version cursor (closes #7)
- Capture authorizerConfiguration/protocolConfiguration in version snapshots so
GetAgentRuntime?version returns the requested version's config (closes #8)
- Support tagging AgentCore gateways (AWS-taggable): add tags to Gateway,
dispatch the TagHandler by ARN resource type, store tags on CreateGateway;
non-taggable AgentCore ARNs now 400 (closes #9)
- Validate maxResults range (1..N) across all list operations (closes #12)
Adds regression tests: version-pagination multi-page, version-config snapshot,
gateway tag round-trip (REST + SDK), unsupported-ARN 400, maxResults + malformed
nextToken validation, and an HTTP-level multi-page pagination test.
Refs lex00/floci#14
* feat(bedrockagentcore): clientToken idempotency, invoke existence flag, config docs
- clientToken idempotency for Runtime/Endpoint/Memory create+delete (lenient:
same token returns the existing resource; completed-delete tokens tracked
in-memory so a replayed delete returns 202 not 404) (closes #10)
- InvokeAgentRuntime existence check behind floci.services.bedrock-agent-core
.validate-runtime-exists (default false, preserving permissive behavior);
when on, unknown runtime ARNs return ResourceNotFoundException (closes #11)
- Document that YAML config keys are hyphenated (bedrock-agent-core-control),
distinct from the reported service name (closes #13)
Adds unit tests (create/delete idempotency), a TestProfile integration test for
the existence flag, and an SDK v2 idempotency compat test.
Refs lex00/floci#10 lex00/floci#11 lex00/floci#13
* ci: trigger fork pipeline dry-run
* test(bedrockagentcore): add persistence, region-isolation, concurrency and boundary coverage
Closes the structural test gaps from the audit (issue #14):
- Persistence-across-restart: full AgentRuntime (JsonNode config, Instants,
version snapshots, endpoints, tags, env vars) round-trips through
PersistentStorage to disk and reloads intact
- Region isolation: a runtime is invisible/ungettable from another region
- Concurrency: concurrent creates all persist (no dropped inserts)
- Endpoint version retargeting, gateway + target update, duplicate-name 409,
and memory eventExpiryDuration boundaries (2/3/365/366)
Refs lex00/floci#14
* fix(bedrockagentcore): validate endpoint versions and the identity in a tagging ARN
createEndpoint and updateEndpoint stored agentRuntimeVersion without resolving
it against the runtime, so a version that was never published produced a READY
endpoint whose generated runtime ARN resolves to nothing. Both now reject one
the runtime has not published.
Tag operations resolved a resource from the ARN's id suffix alone, so an ARN
naming another account or region but a local id reached the local runtime or
gateway and could read or change its tags. The shared tag dispatch now checks
both fields against the request, which covers runtimes and gateways in one
place, and reports not found rather than a validation error so the response
does not confirm what sits behind the foreign identity.
This commit is contained in:
1 parent
6b14999974
commit
4e6e6df06d
43 files changed
+5405
No files matched your search
@@ -575,6 +575,8 @@ public interface EmulatorConfig {
|
||||
EksServiceConfig eks();
|
||||
MwaaServiceConfig mwaa();
|
||||
PipesServiceConfig pipes();
|
||||
BedrockAgentCoreControlServiceConfig bedrockAgentCoreControl();
|
||||
BedrockAgentCoreServiceConfig bedrockAgentCore();
|
||||
ElbV2ServiceConfig elbv2();
|
||||
CodeBuildServiceConfig codebuild();
|
||||
CodeDeployServiceConfig codedeploy();
|
||||
@@ -1603,6 +1605,22 @@ public interface EmulatorConfig {
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface BedrockAgentCoreControlServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface BedrockAgentCoreServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
@WithDefault("{\"output\":\"yes\"}")
|
||||
String invokeResponse();
|
||||
|
||||
@WithDefault("false")
|
||||
boolean validateRuntimeExists();
|
||||
}
|
||||
|
||||
interface ElbV2ServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
@@ -12,6 +12,11 @@ import io.github.hectorvent.floci.services.eks.EksController;
|
||||
import io.github.hectorvent.floci.services.mwaa.MwaaController;
|
||||
import io.github.hectorvent.floci.services.iot.IotController;
|
||||
import io.github.hectorvent.floci.services.iot.IotDataController;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcore.BedrockAgentCoreController;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreControlController;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreGatewayController;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreIdentityController;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreMemoryController;
|
||||
import io.github.hectorvent.floci.services.pipes.PipesController;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaController;
|
||||
import io.github.hectorvent.floci.services.lambdamicrovms.LambdaMicrovmsController;
|
||||
@@ -296,6 +301,19 @@ public class ResolvedServiceCatalog {
|
||||
"pipes", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("pipes"), Set.of(), Set.of(PipesController.class)),
|
||||
descriptor("bedrock-agentcore-control", "bedrock-agentcore-control",
|
||||
config.services().bedrockAgentCoreControl().enabled(), true,
|
||||
"bedrockagentcore", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("bedrock-agentcore"), Set.of(),
|
||||
Set.of(BedrockAgentCoreControlController.class, BedrockAgentCoreIdentityController.class,
|
||||
BedrockAgentCoreGatewayController.class, BedrockAgentCoreMemoryController.class)),
|
||||
descriptor("bedrock-agentcore", "bedrock-agentcore",
|
||||
config.services().bedrockAgentCore().enabled(), true,
|
||||
null, null, 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of(), Set.of(),
|
||||
Set.of(BedrockAgentCoreController.class)),
|
||||
descriptor("elasticloadbalancing", "elbv2", config.services().elbv2().enabled(), true,
|
||||
"elbv2", config.storage().mode(), 5000L, AwsNamespaces.ELB_V2, ServiceProtocol.QUERY,
|
||||
protocols(ServiceProtocol.QUERY),
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcore;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.BedrockAgentCoreControlService;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
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.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* Amazon Bedrock AgentCore data-plane stub ({@code InvokeAgentRuntime}).
|
||||
*
|
||||
* <p>Real endpoint: {@code POST /runtimes/{agentRuntimeArn}/invocations}. The ARN is
|
||||
* URL-encoded in the path, so the template regex captures the remaining path segments.
|
||||
* The payload (opaque binary, up to 100MB) is never parsed. Returns a fixed canned
|
||||
* body and echoes the runtime session id. Streaming is not emulated.
|
||||
*
|
||||
* <p>By default any ARN is accepted (permissive). When
|
||||
* {@code floci.services.bedrock-agent-core.validate-runtime-exists=true}, an unknown
|
||||
* runtime ARN returns {@code ResourceNotFoundException} (404).
|
||||
*/
|
||||
@Path("/")
|
||||
public class BedrockAgentCoreController {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(BedrockAgentCoreController.class);
|
||||
private static final String SESSION_HEADER = "X-Amzn-Bedrock-AgentCore-Runtime-Session-Id";
|
||||
|
||||
private final BedrockAgentCoreService service;
|
||||
private final BedrockAgentCoreControlService controlService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final boolean validateRuntimeExists;
|
||||
|
||||
@Inject
|
||||
public BedrockAgentCoreController(BedrockAgentCoreService service,
|
||||
BedrockAgentCoreControlService controlService,
|
||||
RegionResolver regionResolver,
|
||||
EmulatorConfig config) {
|
||||
this.service = service;
|
||||
this.controlService = controlService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.validateRuntimeExists = config.services().bedrockAgentCore().validateRuntimeExists();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/runtimes/{agentRuntimeArn:.+}/invocations")
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response invokeAgentRuntime(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeArn") String agentRuntimeArn,
|
||||
@QueryParam("qualifier") String qualifier,
|
||||
@QueryParam("accountId") String accountId,
|
||||
byte[] payload) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
if (validateRuntimeExists && !controlService.runtimeArnExists(region, agentRuntimeArn)) {
|
||||
return Response.status(404)
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.header("X-Amzn-Errortype", "ResourceNotFoundException")
|
||||
.entity(new AwsErrorResponse("ResourceNotFoundException",
|
||||
"AgentCore runtime not found: " + agentRuntimeArn))
|
||||
.build();
|
||||
}
|
||||
|
||||
String sessionId = headers.getHeaderString(SESSION_HEADER);
|
||||
LOG.debugv("InvokeAgentRuntime: arn={0}, qualifier={1}, bytes={2}",
|
||||
agentRuntimeArn, qualifier, payload == null ? 0 : payload.length);
|
||||
|
||||
Response.ResponseBuilder builder = Response.ok(service.invoke(), MediaType.APPLICATION_JSON);
|
||||
if (sessionId != null) {
|
||||
builder.header(SESSION_HEADER, sessionId);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcore;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Data-plane stub for Amazon Bedrock AgentCore ({@code InvokeAgentRuntime}).
|
||||
*
|
||||
* <p>No real agent execution: returns a fixed, configurable response body for every
|
||||
* invocation. The payload is never parsed.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class BedrockAgentCoreService {
|
||||
|
||||
private final byte[] cannedResponse;
|
||||
|
||||
@Inject
|
||||
public BedrockAgentCoreService(EmulatorConfig config) {
|
||||
this.cannedResponse = config.services().bedrockAgentCore().invokeResponse()
|
||||
.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public byte[] invoke() {
|
||||
return cannedResponse;
|
||||
}
|
||||
}
|
||||
+442
@@ -0,0 +1,442 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
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.AwsErrorResponse;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntime;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntimeEndpoint;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntimeVersion;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.ListResult;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.PUT;
|
||||
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.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Amazon Bedrock AgentCore control-plane REST-JSON endpoints (runtime registry).
|
||||
*
|
||||
* <p>Real AgentCore control plane uses {@code PUT /runtimes/}, {@code POST /runtimes/}
|
||||
* (list), {@code GET|PUT|DELETE /runtimes/{id}/}, and {@code POST /runtimes/{id}/versions/}.
|
||||
* Mutations return HTTP 202; reads/lists return 200. No real agent execution.
|
||||
*/
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class BedrockAgentCoreControlController {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(BedrockAgentCoreControlController.class);
|
||||
|
||||
private final BedrockAgentCoreControlService service;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public BedrockAgentCoreControlController(BedrockAgentCoreControlService service,
|
||||
RegionResolver regionResolver,
|
||||
ObjectMapper objectMapper) {
|
||||
this.service = service;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/runtimes/")
|
||||
public Response createAgentRuntime(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode req = objectMapper.readTree(body != null && !body.isBlank() ? body : "{}");
|
||||
AgentRuntime runtime = service.createAgentRuntime(
|
||||
text(req, "agentRuntimeName"),
|
||||
obj(req, "agentRuntimeArtifact"),
|
||||
obj(req, "networkConfiguration"),
|
||||
text(req, "roleArn"),
|
||||
text(req, "description"),
|
||||
stringMap(req.get("environmentVariables")),
|
||||
obj(req, "authorizerConfiguration"),
|
||||
obj(req, "protocolConfiguration"),
|
||||
text(req, "clientToken"),
|
||||
region);
|
||||
Map<String, String> tags = stringMap(req.get("tags"));
|
||||
if (tags != null) {
|
||||
runtime.getTags().putAll(tags);
|
||||
}
|
||||
String version = String.valueOf(runtime.getLatestVersion());
|
||||
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
out.put("agentRuntimeArn", service.arn(runtime, version, region));
|
||||
out.put("agentRuntimeId", runtime.getAgentRuntimeId());
|
||||
out.put("agentRuntimeVersion", version);
|
||||
putInstant(out, "createdAt", runtime.getCreatedAt());
|
||||
out.put("status", runtime.getStatus());
|
||||
workloadIdentity(out, runtime);
|
||||
return Response.status(202).entity(out).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "creating runtime");
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/runtimes/")
|
||||
public Response listAgentRuntimes(@Context HttpHeaders headers,
|
||||
@QueryParam("maxResults") Integer maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
ListResult<AgentRuntime> result =
|
||||
service.listAgentRuntimes(maxResults != null ? maxResults : 0, nextToken, region);
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
ArrayNode arr = out.putArray("agentRuntimes");
|
||||
for (AgentRuntime runtime : result.items()) {
|
||||
arr.add(summary(runtime, String.valueOf(runtime.getLatestVersion()), region));
|
||||
}
|
||||
if (result.nextToken() != null) {
|
||||
out.put("nextToken", result.nextToken());
|
||||
}
|
||||
return Response.ok(out).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "listing runtimes");
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/runtimes/{agentRuntimeId}/")
|
||||
public Response getAgentRuntime(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
@QueryParam("version") String version) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
AgentRuntime runtime = service.getAgentRuntime(id, region);
|
||||
AgentRuntimeVersion snap = service.resolveVersion(runtime, version);
|
||||
String v = snap.getVersion();
|
||||
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
out.put("agentRuntimeArn", service.arn(runtime, v, region));
|
||||
out.put("agentRuntimeId", runtime.getAgentRuntimeId());
|
||||
out.put("agentRuntimeName", runtime.getAgentRuntimeName());
|
||||
out.put("agentRuntimeVersion", v);
|
||||
if (snap.getAgentRuntimeArtifact() != null) {
|
||||
out.set("agentRuntimeArtifact", snap.getAgentRuntimeArtifact());
|
||||
}
|
||||
if (snap.getNetworkConfiguration() != null) {
|
||||
out.set("networkConfiguration", snap.getNetworkConfiguration());
|
||||
}
|
||||
if (snap.getAuthorizerConfiguration() != null) {
|
||||
out.set("authorizerConfiguration", snap.getAuthorizerConfiguration());
|
||||
}
|
||||
if (snap.getProtocolConfiguration() != null) {
|
||||
out.set("protocolConfiguration", snap.getProtocolConfiguration());
|
||||
}
|
||||
if (snap.getRoleArn() != null) {
|
||||
out.put("roleArn", snap.getRoleArn());
|
||||
}
|
||||
if (snap.getDescription() != null) {
|
||||
out.put("description", snap.getDescription());
|
||||
}
|
||||
if (snap.getEnvironmentVariables() != null && !snap.getEnvironmentVariables().isEmpty()) {
|
||||
out.set("environmentVariables", objectMapper.valueToTree(snap.getEnvironmentVariables()));
|
||||
}
|
||||
putInstant(out, "createdAt", runtime.getCreatedAt());
|
||||
putInstant(out, "lastUpdatedAt", runtime.getLastUpdatedAt());
|
||||
out.put("status", runtime.getStatus());
|
||||
workloadIdentity(out, runtime);
|
||||
return Response.ok(out).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "getting runtime");
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/runtimes/{agentRuntimeId}/")
|
||||
public Response updateAgentRuntime(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode req = objectMapper.readTree(body != null && !body.isBlank() ? body : "{}");
|
||||
AgentRuntime runtime = service.updateAgentRuntime(
|
||||
id,
|
||||
obj(req, "agentRuntimeArtifact"),
|
||||
obj(req, "networkConfiguration"),
|
||||
text(req, "roleArn"),
|
||||
text(req, "description"),
|
||||
stringMap(req.get("environmentVariables")),
|
||||
obj(req, "authorizerConfiguration"),
|
||||
obj(req, "protocolConfiguration"),
|
||||
region);
|
||||
String version = String.valueOf(runtime.getLatestVersion());
|
||||
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
out.put("agentRuntimeArn", service.arn(runtime, version, region));
|
||||
out.put("agentRuntimeId", runtime.getAgentRuntimeId());
|
||||
out.put("agentRuntimeVersion", version);
|
||||
putInstant(out, "createdAt", runtime.getCreatedAt());
|
||||
putInstant(out, "lastUpdatedAt", runtime.getLastUpdatedAt());
|
||||
out.put("status", runtime.getStatus());
|
||||
workloadIdentity(out, runtime);
|
||||
return Response.status(202).entity(out).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "updating runtime");
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/runtimes/{agentRuntimeId}/versions/")
|
||||
public Response listAgentRuntimeVersions(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
@QueryParam("maxResults") Integer maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
AgentRuntime runtime = service.getAgentRuntime(id, region);
|
||||
ListResult<AgentRuntimeVersion> result =
|
||||
service.listAgentRuntimeVersions(id, maxResults != null ? maxResults : 0, nextToken, region);
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
ArrayNode arr = out.putArray("agentRuntimes");
|
||||
for (AgentRuntimeVersion snap : result.items()) {
|
||||
arr.add(versionSummary(runtime, snap, region));
|
||||
}
|
||||
if (result.nextToken() != null) {
|
||||
out.put("nextToken", result.nextToken());
|
||||
}
|
||||
return Response.ok(out).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "listing runtime versions");
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/runtimes/{agentRuntimeId}/")
|
||||
public Response deleteAgentRuntime(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
@QueryParam("clientToken") String clientToken) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
AgentRuntime runtime = service.deleteAgentRuntime(id, clientToken, region);
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
out.put("agentRuntimeId", runtime.getAgentRuntimeId());
|
||||
out.put("status", runtime.getStatus());
|
||||
return Response.status(202).entity(out).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "deleting runtime");
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────── Endpoints (Phase 2) ────────────────────────────
|
||||
|
||||
@PUT
|
||||
@Path("/runtimes/{agentRuntimeId}/runtime-endpoints/")
|
||||
public Response createEndpoint(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode req = objectMapper.readTree(body != null && !body.isBlank() ? body : "{}");
|
||||
AgentRuntimeEndpoint endpoint = service.createEndpoint(id, text(req, "name"),
|
||||
text(req, "agentRuntimeVersion"), text(req, "description"), text(req, "clientToken"), region);
|
||||
AgentRuntime runtime = service.getAgentRuntime(id, region);
|
||||
return Response.status(202).entity(endpointResponse(runtime, endpoint, region, false)).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "creating endpoint");
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/runtimes/{agentRuntimeId}/runtime-endpoints/{endpointName}/")
|
||||
public Response getEndpoint(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
@PathParam("endpointName") String name) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
AgentRuntime runtime = service.getAgentRuntime(id, region);
|
||||
AgentRuntimeEndpoint endpoint = service.getEndpoint(id, name, region);
|
||||
return Response.ok(endpointResponse(runtime, endpoint, region, true)).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "getting endpoint");
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/runtimes/{agentRuntimeId}/runtime-endpoints/{endpointName}/")
|
||||
public Response updateEndpoint(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
@PathParam("endpointName") String name,
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode req = objectMapper.readTree(body != null && !body.isBlank() ? body : "{}");
|
||||
AgentRuntimeEndpoint endpoint = service.updateEndpoint(id, name,
|
||||
text(req, "agentRuntimeVersion"), text(req, "description"), region);
|
||||
AgentRuntime runtime = service.getAgentRuntime(id, region);
|
||||
return Response.status(202).entity(endpointResponse(runtime, endpoint, region, true)).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "updating endpoint");
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/runtimes/{agentRuntimeId}/runtime-endpoints/{endpointName}/")
|
||||
public Response deleteEndpoint(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
@PathParam("endpointName") String name,
|
||||
@QueryParam("clientToken") String clientToken) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
AgentRuntimeEndpoint endpoint = service.deleteEndpoint(id, name, clientToken, region);
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
out.put("agentRuntimeId", id);
|
||||
out.put("endpointName", endpoint.getName());
|
||||
out.put("status", endpoint.getStatus());
|
||||
return Response.status(202).entity(out).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "deleting endpoint");
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/runtimes/{agentRuntimeId}/runtime-endpoints/")
|
||||
public Response listEndpoints(@Context HttpHeaders headers,
|
||||
@PathParam("agentRuntimeId") String id,
|
||||
@QueryParam("maxResults") Integer maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
AgentRuntime runtime = service.getAgentRuntime(id, region);
|
||||
ListResult<AgentRuntimeEndpoint> result =
|
||||
service.listEndpoints(id, maxResults != null ? maxResults : 0, nextToken, region);
|
||||
ObjectNode out = objectMapper.createObjectNode();
|
||||
ArrayNode arr = out.putArray("runtimeEndpoints");
|
||||
for (AgentRuntimeEndpoint endpoint : result.items()) {
|
||||
arr.add(endpointResponse(runtime, endpoint, region, true));
|
||||
}
|
||||
if (result.nextToken() != null) {
|
||||
out.put("nextToken", result.nextToken());
|
||||
}
|
||||
return Response.ok(out).build();
|
||||
} catch (Exception e) {
|
||||
return error(e, "listing endpoints");
|
||||
}
|
||||
}
|
||||
|
||||
private ObjectNode endpointResponse(AgentRuntime runtime, AgentRuntimeEndpoint endpoint,
|
||||
String region, boolean full) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("agentRuntimeArn", service.arn(runtime, endpoint.getTargetVersion(), region));
|
||||
node.put("agentRuntimeEndpointArn", service.endpointArn(endpoint, region));
|
||||
node.put("agentRuntimeId", runtime.getAgentRuntimeId());
|
||||
node.put("endpointName", endpoint.getName());
|
||||
node.put("status", endpoint.getStatus());
|
||||
node.put("targetVersion", endpoint.getTargetVersion());
|
||||
putInstant(node, "createdAt", endpoint.getCreatedAt());
|
||||
if (full) {
|
||||
node.put("id", endpoint.getUuid());
|
||||
node.put("name", endpoint.getName());
|
||||
if (endpoint.getLiveVersion() != null) {
|
||||
node.put("liveVersion", endpoint.getLiveVersion());
|
||||
}
|
||||
if (endpoint.getDescription() != null) {
|
||||
node.put("description", endpoint.getDescription());
|
||||
}
|
||||
putInstant(node, "lastUpdatedAt", endpoint.getLastUpdatedAt());
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
private ObjectNode summary(AgentRuntime runtime, String version, String region) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("agentRuntimeArn", service.arn(runtime, version, region));
|
||||
node.put("agentRuntimeId", runtime.getAgentRuntimeId());
|
||||
node.put("agentRuntimeName", runtime.getAgentRuntimeName());
|
||||
node.put("agentRuntimeVersion", version);
|
||||
if (runtime.getDescription() != null) {
|
||||
node.put("description", runtime.getDescription());
|
||||
}
|
||||
putInstant(node, "lastUpdatedAt", runtime.getLastUpdatedAt());
|
||||
node.put("status", runtime.getStatus());
|
||||
return node;
|
||||
}
|
||||
|
||||
private ObjectNode versionSummary(AgentRuntime runtime, AgentRuntimeVersion snap, String region) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("agentRuntimeArn", service.arn(runtime, snap.getVersion(), region));
|
||||
node.put("agentRuntimeId", runtime.getAgentRuntimeId());
|
||||
node.put("agentRuntimeName", runtime.getAgentRuntimeName());
|
||||
node.put("agentRuntimeVersion", snap.getVersion());
|
||||
if (snap.getDescription() != null) {
|
||||
node.put("description", snap.getDescription());
|
||||
}
|
||||
putInstant(node, "lastUpdatedAt", snap.getCreatedAt());
|
||||
node.put("status", runtime.getStatus());
|
||||
return node;
|
||||
}
|
||||
|
||||
private void workloadIdentity(ObjectNode out, AgentRuntime runtime) {
|
||||
if (runtime.getWorkloadIdentityArn() != null) {
|
||||
ObjectNode wi = out.putObject("workloadIdentityDetails");
|
||||
wi.put("workloadIdentityArn", runtime.getWorkloadIdentityArn());
|
||||
}
|
||||
}
|
||||
|
||||
private static void putInstant(ObjectNode node, String field, Instant instant) {
|
||||
if (instant != null) {
|
||||
// AgentCore models these as ISO-8601 strings; second precision stays within
|
||||
// AWS's 20-char timestamp limit.
|
||||
node.put(field, instant.truncatedTo(java.time.temporal.ChronoUnit.SECONDS).toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static String text(JsonNode node, String field) {
|
||||
JsonNode v = node.get(field);
|
||||
return (v == null || v.isNull()) ? null : v.asText();
|
||||
}
|
||||
|
||||
private static JsonNode obj(JsonNode node, String field) {
|
||||
JsonNode v = node.get(field);
|
||||
return (v == null || v.isNull() || v.isMissingNode()) ? null : v;
|
||||
}
|
||||
|
||||
private static Map<String, String> stringMap(JsonNode node) {
|
||||
if (node == null || !node.isObject()) {
|
||||
return null;
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
node.fields().forEachRemaining(e -> map.put(e.getKey(), e.getValue().asText()));
|
||||
return map;
|
||||
}
|
||||
|
||||
private Response error(Exception e, String action) {
|
||||
if (e instanceof AwsException aws) {
|
||||
return Response.status(aws.getHttpStatus())
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.header("X-Amzn-Errortype", aws.jsonType())
|
||||
.entity(new AwsErrorResponse(aws.jsonType(), aws.getMessage()))
|
||||
.build();
|
||||
}
|
||||
LOG.errorv(e, "Error {0}", action);
|
||||
return Response.status(400)
|
||||
.type(MediaType.APPLICATION_JSON)
|
||||
.header("X-Amzn-Errortype", "ValidationException")
|
||||
.entity(new AwsErrorResponse("ValidationException", e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+500
@@ -0,0 +1,500 @@
|
||||
package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntime;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntimeEndpoint;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.AgentRuntimeVersion;
|
||||
import io.github.hectorvent.floci.services.bedrockagentcorecontrol.model.ListResult;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.util.Base64;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Business logic for the Amazon Bedrock AgentCore control plane (runtime registry).
|
||||
*
|
||||
* <p>Stateful CRUD only: no real agent execution. Runtimes reach {@code READY}
|
||||
* immediately. Each {@code UpdateAgentRuntime} appends an immutable version snapshot.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class BedrockAgentCoreControlService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(BedrockAgentCoreControlService.class);
|
||||
|
||||
static final String STATUS_READY = "READY";
|
||||
static final String STATUS_DELETING = "DELETING";
|
||||
private static final String ARN_SERVICE = "bedrock-agentcore";
|
||||
private static final Pattern NAME_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9_]{0,47}");
|
||||
private static final String ID_ALPHABET =
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
private static final int MAX_PAGE = 100;
|
||||
private static final int DEFAULT_PAGE = 100;
|
||||
|
||||
private final StorageBackend<String, AgentRuntime> storage;
|
||||
private final RegionResolver regionResolver;
|
||||
private final BedrockAgentCoreIdentityService identityService;
|
||||
// clientToken idempotency: tokens of completed deletes, so a replayed delete succeeds
|
||||
// instead of 404ing. In-memory only (reset on restart) — sufficient for an emulator.
|
||||
private final Set<String> deletedRuntimeTokens = ConcurrentHashMap.newKeySet();
|
||||
private final Set<String> deletedEndpointTokens = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@Inject
|
||||
public BedrockAgentCoreControlService(StorageFactory storageFactory, RegionResolver regionResolver,
|
||||
BedrockAgentCoreIdentityService identityService) {
|
||||
this(storageFactory.create("bedrockagentcore", "bedrock-agentcore-runtimes.json",
|
||||
new TypeReference<Map<String, AgentRuntime>>() {}), regionResolver, identityService);
|
||||
}
|
||||
|
||||
BedrockAgentCoreControlService(StorageBackend<String, AgentRuntime> storage, RegionResolver regionResolver) {
|
||||
this(storage, regionResolver, null);
|
||||
}
|
||||
|
||||
BedrockAgentCoreControlService(StorageBackend<String, AgentRuntime> storage, RegionResolver regionResolver,
|
||||
BedrockAgentCoreIdentityService identityService) {
|
||||
this.storage = storage;
|
||||
this.regionResolver = regionResolver;
|
||||
this.identityService = identityService;
|
||||
}
|
||||
|
||||
public AgentRuntime createAgentRuntime(String name, JsonNode artifact, JsonNode networkConfiguration,
|
||||
String roleArn, String description, Map<String, String> environmentVariables,
|
||||
JsonNode authorizerConfiguration, JsonNode protocolConfiguration,
|
||||
String clientToken, String region) {
|
||||
if (clientToken != null) {
|
||||
Optional<AgentRuntime> replay = storage.scan(k -> k.startsWith(keyPrefix(region))).stream()
|
||||
.filter(r -> clientToken.equals(r.getClientToken()))
|
||||
.findFirst();
|
||||
if (replay.isPresent()) {
|
||||
return replay.get();
|
||||
}
|
||||
}
|
||||
if (name == null || !NAME_PATTERN.matcher(name).matches()) {
|
||||
throw new AwsException("ValidationException",
|
||||
"agentRuntimeName must match [a-zA-Z][a-zA-Z0-9_]{0,47}", 400);
|
||||
}
|
||||
if (artifact == null || artifact.isNull()) {
|
||||
throw new AwsException("ValidationException", "agentRuntimeArtifact is required", 400);
|
||||
}
|
||||
if (networkConfiguration == null || networkConfiguration.isNull()) {
|
||||
throw new AwsException("ValidationException", "networkConfiguration is required", 400);
|
||||
}
|
||||
if (roleArn == null || roleArn.isBlank()) {
|
||||
throw new AwsException("ValidationException", "roleArn is required", 400);
|
||||
}
|
||||
|
||||
Instant now = Instant.now();
|
||||
String id = name + "-" + randomId();
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
AgentRuntime runtime = new AgentRuntime();
|
||||
runtime.setAgentRuntimeId(id);
|
||||
runtime.setAgentRuntimeName(name);
|
||||
runtime.setUuid(uuid);
|
||||
runtime.setRoleArn(roleArn);
|
||||
runtime.setDescription(description);
|
||||
runtime.setStatus(STATUS_READY);
|
||||
runtime.setLatestVersion(1);
|
||||
runtime.setCreatedAt(now);
|
||||
runtime.setLastUpdatedAt(now);
|
||||
runtime.setAccountId(regionResolver.getAccountId());
|
||||
runtime.setAgentRuntimeArtifact(artifact);
|
||||
runtime.setNetworkConfiguration(networkConfiguration);
|
||||
runtime.setAuthorizerConfiguration(authorizerConfiguration);
|
||||
runtime.setProtocolConfiguration(protocolConfiguration);
|
||||
runtime.setEnvironmentVariables(environmentVariables != null ? new HashMap<>(environmentVariables) : new HashMap<>());
|
||||
runtime.setClientToken(clientToken);
|
||||
String workloadName = name + "-" + randomId();
|
||||
if (identityService != null) {
|
||||
runtime.setWorkloadIdentityArn(
|
||||
identityService.createForRuntime(workloadName, region).getWorkloadIdentityArn());
|
||||
} else {
|
||||
runtime.setWorkloadIdentityArn(regionResolver.buildArn(ARN_SERVICE, region,
|
||||
"workload-identity-directory/default/workload-identity/" + workloadName));
|
||||
}
|
||||
runtime.getVersions().add(snapshot(runtime, "1", now));
|
||||
runtime.getEndpoints().add(newEndpoint("DEFAULT", "1", null, now));
|
||||
|
||||
storage.put(key(region, id), runtime);
|
||||
LOG.infov("Created AgentCore runtime {0} (id={1})", name, id);
|
||||
return runtime;
|
||||
}
|
||||
|
||||
public AgentRuntime getAgentRuntime(String id, String region) {
|
||||
return storage.get(key(region, id))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"AgentCore runtime not found: " + id, 404));
|
||||
}
|
||||
|
||||
/** Returns the snapshot matching {@code version}, or the latest when {@code version} is null. */
|
||||
public AgentRuntimeVersion resolveVersion(AgentRuntime runtime, String version) {
|
||||
String wanted = version != null ? version : String.valueOf(runtime.getLatestVersion());
|
||||
return runtime.getVersions().stream()
|
||||
.filter(v -> wanted.equals(v.getVersion()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"AgentCore runtime version not found: " + wanted, 404));
|
||||
}
|
||||
|
||||
public AgentRuntime updateAgentRuntime(String id, JsonNode artifact, JsonNode networkConfiguration,
|
||||
String roleArn, String description, Map<String, String> environmentVariables,
|
||||
JsonNode authorizerConfiguration, JsonNode protocolConfiguration,
|
||||
String region) {
|
||||
if (artifact == null || artifact.isNull()) {
|
||||
throw new AwsException("ValidationException", "agentRuntimeArtifact is required", 400);
|
||||
}
|
||||
if (networkConfiguration == null || networkConfiguration.isNull()) {
|
||||
throw new AwsException("ValidationException", "networkConfiguration is required", 400);
|
||||
}
|
||||
if (roleArn == null || roleArn.isBlank()) {
|
||||
throw new AwsException("ValidationException", "roleArn is required", 400);
|
||||
}
|
||||
AgentRuntime runtime = getAgentRuntime(id, region);
|
||||
Instant now = Instant.now();
|
||||
|
||||
int newVersion = runtime.getLatestVersion() + 1;
|
||||
runtime.setLatestVersion(newVersion);
|
||||
runtime.setRoleArn(roleArn);
|
||||
runtime.setDescription(description);
|
||||
runtime.setAgentRuntimeArtifact(artifact);
|
||||
runtime.setNetworkConfiguration(networkConfiguration);
|
||||
if (authorizerConfiguration != null) {
|
||||
runtime.setAuthorizerConfiguration(authorizerConfiguration);
|
||||
}
|
||||
if (protocolConfiguration != null) {
|
||||
runtime.setProtocolConfiguration(protocolConfiguration);
|
||||
}
|
||||
if (environmentVariables != null) {
|
||||
runtime.setEnvironmentVariables(new HashMap<>(environmentVariables));
|
||||
}
|
||||
runtime.setLastUpdatedAt(now);
|
||||
runtime.getVersions().add(snapshot(runtime, String.valueOf(newVersion), now));
|
||||
|
||||
storage.put(key(region, id), runtime);
|
||||
LOG.infov("Updated AgentCore runtime {0} to version {1}", id, newVersion);
|
||||
return runtime;
|
||||
}
|
||||
|
||||
public AgentRuntime deleteAgentRuntime(String id, String clientToken, String region) {
|
||||
Optional<AgentRuntime> found = storage.get(key(region, id));
|
||||
if (found.isEmpty()) {
|
||||
if (clientToken != null && deletedRuntimeTokens.contains(tokenKey(region, clientToken))) {
|
||||
AgentRuntime marker = new AgentRuntime();
|
||||
marker.setAgentRuntimeId(id);
|
||||
marker.setStatus(STATUS_DELETING);
|
||||
return marker;
|
||||
}
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"AgentCore runtime not found: " + id, 404);
|
||||
}
|
||||
AgentRuntime runtime = found.get();
|
||||
storage.delete(key(region, id));
|
||||
if (clientToken != null) {
|
||||
deletedRuntimeTokens.add(tokenKey(region, clientToken));
|
||||
}
|
||||
runtime.setStatus(STATUS_DELETING);
|
||||
LOG.infov("Deleted AgentCore runtime {0}", id);
|
||||
return runtime;
|
||||
}
|
||||
|
||||
private static String tokenKey(String region, String clientToken) {
|
||||
return region + " | ||||