mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(pipes): add EventBridge Pipes service skeleton with CRUD API (#539)
This commit is contained in:
1 parent
59c1d727fc
commit
9f231afc3b
11 files changed
+1124
-2
No files matched your search
@@ -239,6 +239,7 @@ public interface EmulatorConfig {
|
||||
ResourceGroupsTaggingServiceConfig tagging();
|
||||
BedrockRuntimeServiceConfig bedrockRuntime();
|
||||
EksServiceConfig eks();
|
||||
PipesServiceConfig pipes();
|
||||
}
|
||||
|
||||
interface SsmServiceConfig {
|
||||
@@ -600,6 +601,11 @@ public interface EmulatorConfig {
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface PipesServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface EksServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.services.bedrockruntime.BedrockRuntimeControll
|
||||
import io.github.hectorvent.floci.services.cognito.CognitoOAuthController;
|
||||
import io.github.hectorvent.floci.services.cognito.CognitoWellKnownController;
|
||||
import io.github.hectorvent.floci.services.eks.EksController;
|
||||
import io.github.hectorvent.floci.services.pipes.PipesController;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaController;
|
||||
import io.github.hectorvent.floci.services.opensearch.OpenSearchController;
|
||||
import io.github.hectorvent.floci.services.ses.SesController;
|
||||
@@ -198,7 +199,11 @@ public class ResolvedServiceCatalog {
|
||||
descriptor("eks", "eks", config.services().eks().enabled(), true,
|
||||
"eks", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("eks"), Set.of(), Set.of(EksController.class))
|
||||
Set.of(), Set.of("eks"), Set.of(), Set.of(EksController.class)),
|
||||
descriptor("pipes", "pipes", config.services().pipes().enabled(), true,
|
||||
"pipes", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("pipes"), Set.of(), Set.of(PipesController.class))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
package io.github.hectorvent.floci.services.pipes;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.pipes.model.DesiredState;
|
||||
import io.github.hectorvent.floci.services.pipes.model.Pipe;
|
||||
import io.github.hectorvent.floci.services.pipes.model.PipeState;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
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.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* EventBridge Pipes REST-JSON controller.
|
||||
*
|
||||
* <p>Pipes uses standard HTTP verbs with JSON bodies — not JSON 1.1 (X-Amz-Target) or Query protocol.
|
||||
*/
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class PipesController {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PipesController.class);
|
||||
|
||||
private final PipesService pipesService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public PipesController(PipesService pipesService, RegionResolver regionResolver, ObjectMapper objectMapper) {
|
||||
this.pipesService = pipesService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/v1/pipes/{name}")
|
||||
public Response createPipe(@PathParam("name") String name,
|
||||
@Context HttpHeaders headers,
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
String source = textOrNull(request, "Source");
|
||||
String target = textOrNull(request, "Target");
|
||||
String roleArn = textOrNull(request, "RoleArn");
|
||||
String description = textOrNull(request, "Description");
|
||||
String enrichment = textOrNull(request, "Enrichment");
|
||||
DesiredState desiredState = parseDesiredState(textOrNull(request, "DesiredState"));
|
||||
JsonNode sourceParameters = request.path("SourceParameters").isMissingNode() ? null : request.get("SourceParameters");
|
||||
JsonNode targetParameters = request.path("TargetParameters").isMissingNode() ? null : request.get("TargetParameters");
|
||||
JsonNode enrichmentParameters = request.path("EnrichmentParameters").isMissingNode() ? null : request.get("EnrichmentParameters");
|
||||
Map<String, String> tags = parseTags(request.get("Tags"));
|
||||
|
||||
Pipe pipe = pipesService.createPipe(name, source, target, roleArn, description,
|
||||
desiredState, enrichment, sourceParameters, targetParameters,
|
||||
enrichmentParameters, tags, region);
|
||||
|
||||
return Response.ok(buildPipeResponse(pipe)).build();
|
||||
} catch (AwsException e) {
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorv("Error creating pipe: {0}", e.getMessage());
|
||||
return Response.status(500)
|
||||
.entity(new AwsErrorResponse("InternalException", e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/v1/pipes/{name}")
|
||||
public Response describePipe(@PathParam("name") String name,
|
||||
@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
Pipe pipe = pipesService.describePipe(name, region);
|
||||
return Response.ok(pipe).build();
|
||||
} catch (AwsException e) {
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/v1/pipes/{name}")
|
||||
public Response updatePipe(@PathParam("name") String name,
|
||||
@Context HttpHeaders headers,
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
String target = textOrNull(request, "Target");
|
||||
String roleArn = textOrNull(request, "RoleArn");
|
||||
String description = textOrNull(request, "Description");
|
||||
String enrichment = textOrNull(request, "Enrichment");
|
||||
DesiredState desiredState = parseDesiredState(textOrNull(request, "DesiredState"));
|
||||
JsonNode sourceParameters = request.path("SourceParameters").isMissingNode() ? null : request.get("SourceParameters");
|
||||
JsonNode targetParameters = request.path("TargetParameters").isMissingNode() ? null : request.get("TargetParameters");
|
||||
JsonNode enrichmentParameters = request.path("EnrichmentParameters").isMissingNode() ? null : request.get("EnrichmentParameters");
|
||||
|
||||
Pipe pipe = pipesService.updatePipe(name, target, roleArn, description,
|
||||
desiredState, enrichment, sourceParameters, targetParameters,
|
||||
enrichmentParameters, region);
|
||||
|
||||
return Response.ok(buildPipeResponse(pipe)).build();
|
||||
} catch (AwsException e) {
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
LOG.errorv("Error updating pipe: {0}", e.getMessage());
|
||||
return Response.status(500)
|
||||
.entity(new AwsErrorResponse("InternalException", e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/v1/pipes/{name}")
|
||||
public Response deletePipe(@PathParam("name") String name,
|
||||
@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
pipesService.deletePipe(name, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/v1/pipes")
|
||||
public Response listPipes(@QueryParam("NamePrefix") String namePrefix,
|
||||
@QueryParam("SourcePrefix") String sourcePrefix,
|
||||
@QueryParam("TargetPrefix") String targetPrefix,
|
||||
@QueryParam("DesiredState") String desiredStateStr,
|
||||
@QueryParam("CurrentState") String currentStateStr,
|
||||
@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
DesiredState desiredState = parseDesiredState(desiredStateStr);
|
||||
PipeState currentState = parsePipeState(currentStateStr);
|
||||
List<Pipe> pipes = pipesService.listPipes(namePrefix, sourcePrefix, targetPrefix,
|
||||
desiredState, currentState, region);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
var pipesArray = response.putArray("Pipes");
|
||||
for (Pipe pipe : pipes) {
|
||||
pipesArray.add(buildPipeListEntry(pipe));
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
} catch (AwsException e) {
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/v1/pipes/{name}/start")
|
||||
public Response startPipe(@PathParam("name") String name,
|
||||
@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
Pipe pipe = pipesService.startPipe(name, region);
|
||||
return Response.ok(buildPipeResponse(pipe)).build();
|
||||
} catch (AwsException e) {
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/v1/pipes/{name}/stop")
|
||||
public Response stopPipe(@PathParam("name") String name,
|
||||
@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
Pipe pipe = pipesService.stopPipe(name, region);
|
||||
return Response.ok(buildPipeResponse(pipe)).build();
|
||||
} catch (AwsException e) {
|
||||
return Response.status(e.getHttpStatus())
|
||||
.entity(new AwsErrorResponse(e.getErrorCode(), e.getMessage()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────── Helpers ────────────────────────────
|
||||
|
||||
private ObjectNode buildPipeResponse(Pipe pipe) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("Arn", pipe.getArn());
|
||||
node.put("Name", pipe.getName());
|
||||
node.put("Source", pipe.getSource());
|
||||
node.put("Target", pipe.getTarget());
|
||||
node.put("RoleArn", pipe.getRoleArn());
|
||||
node.put("DesiredState", pipe.getDesiredState().name());
|
||||
node.put("CurrentState", pipe.getCurrentState().name());
|
||||
if (pipe.getDescription() != null) node.put("Description", pipe.getDescription());
|
||||
if (pipe.getEnrichment() != null) node.put("Enrichment", pipe.getEnrichment());
|
||||
if (pipe.getCreationTime() != null) node.put("CreationTime", pipe.getCreationTime().getEpochSecond());
|
||||
if (pipe.getLastModifiedTime() != null) node.put("LastModifiedTime", pipe.getLastModifiedTime().getEpochSecond());
|
||||
if (pipe.getStateReason() != null) node.put("StateReason", pipe.getStateReason());
|
||||
return node;
|
||||
}
|
||||
|
||||
private ObjectNode buildPipeListEntry(Pipe pipe) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("Arn", pipe.getArn());
|
||||
node.put("Name", pipe.getName());
|
||||
node.put("Source", pipe.getSource());
|
||||
node.put("Target", pipe.getTarget());
|
||||
node.put("DesiredState", pipe.getDesiredState().name());
|
||||
node.put("CurrentState", pipe.getCurrentState().name());
|
||||
if (pipe.getCreationTime() != null) node.put("CreationTime", pipe.getCreationTime().getEpochSecond());
|
||||
if (pipe.getLastModifiedTime() != null) node.put("LastModifiedTime", pipe.getLastModifiedTime().getEpochSecond());
|
||||
return node;
|
||||
}
|
||||
|
||||
private String textOrNull(JsonNode node, String field) {
|
||||
JsonNode value = node.get(field);
|
||||
if (value == null || value.isNull() || value.isMissingNode()) return null;
|
||||
return value.asText();
|
||||
}
|
||||
|
||||
private DesiredState parseDesiredState(String state) {
|
||||
if (state == null || state.isBlank()) return null;
|
||||
try {
|
||||
return DesiredState.valueOf(state.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private PipeState parsePipeState(String state) {
|
||||
if (state == null || state.isBlank()) return null;
|
||||
try {
|
||||
return PipeState.valueOf(state.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> parseTags(JsonNode tagsNode) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
if (tagsNode != null && tagsNode.isObject()) {
|
||||
tagsNode.fields().forEachRemaining(e -> tags.put(e.getKey(), e.getValue().asText()));
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package io.github.hectorvent.floci.services.pipes;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.TagHandler;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.pipes.model.DesiredState;
|
||||
import io.github.hectorvent.floci.services.pipes.model.Pipe;
|
||||
import io.github.hectorvent.floci.services.pipes.model.PipeState;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ApplicationScoped
|
||||
public class PipesService implements TagHandler {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PipesService.class);
|
||||
|
||||
private final StorageBackend<String, Pipe> storage;
|
||||
private final EmulatorConfig config;
|
||||
|
||||
@Inject
|
||||
public PipesService(StorageFactory storageFactory, EmulatorConfig config) {
|
||||
this.storage = storageFactory.create("pipes", "pipes.json",
|
||||
new TypeReference<Map<String, Pipe>>() {});
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public Pipe createPipe(String name, String source, String target, String roleArn,
|
||||
String description, DesiredState desiredState, String enrichment,
|
||||
JsonNode sourceParameters, JsonNode targetParameters,
|
||||
JsonNode enrichmentParameters, Map<String, String> tags,
|
||||
String region) {
|
||||
if (name == null || name.isBlank()) {
|
||||
throw new AwsException("ValidationException", "Name is required", 400);
|
||||
}
|
||||
if (source == null || source.isBlank()) {
|
||||
throw new AwsException("ValidationException", "Source is required", 400);
|
||||
}
|
||||
if (target == null || target.isBlank()) {
|
||||
throw new AwsException("ValidationException", "Target is required", 400);
|
||||
}
|
||||
if (roleArn == null || roleArn.isBlank()) {
|
||||
throw new AwsException("ValidationException", "RoleArn is required", 400);
|
||||
}
|
||||
|
||||
String key = region + "::" + name;
|
||||
if (storage.get(key).isPresent()) {
|
||||
throw new AwsException("ConflictException",
|
||||
"Pipe " + name + " already exists.", 409);
|
||||
}
|
||||
|
||||
String accountId = config.defaultAccountId();
|
||||
String arn = "arn:aws:pipes:" + region + ":" + accountId + ":pipe/" + name;
|
||||
Instant now = Instant.now();
|
||||
|
||||
Pipe pipe = new Pipe();
|
||||
pipe.setName(name);
|
||||
pipe.setArn(arn);
|
||||
pipe.setSource(source);
|
||||
pipe.setTarget(target);
|
||||
pipe.setRoleArn(roleArn);
|
||||
pipe.setDescription(description);
|
||||
DesiredState effectiveDesiredState = desiredState != null ? desiredState : DesiredState.RUNNING;
|
||||
pipe.setDesiredState(effectiveDesiredState);
|
||||
pipe.setCurrentState(effectiveDesiredState == DesiredState.RUNNING ? PipeState.RUNNING : PipeState.STOPPED);
|
||||
pipe.setEnrichment(enrichment);
|
||||
pipe.setSourceParameters(sourceParameters);
|
||||
pipe.setTargetParameters(targetParameters);
|
||||
pipe.setEnrichmentParameters(enrichmentParameters);
|
||||
pipe.setTags(tags != null ? new HashMap<>(tags) : new HashMap<>());
|
||||
pipe.setCreationTime(now);
|
||||
pipe.setLastModifiedTime(now);
|
||||
|
||||
storage.put(key, pipe);
|
||||
LOG.infov("Created pipe: {0}", name);
|
||||
return pipe;
|
||||
}
|
||||
|
||||
public Pipe describePipe(String name, String region) {
|
||||
String key = region + "::" + name;
|
||||
return storage.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"Pipe " + name + " does not exist.", 404));
|
||||
}
|
||||
|
||||
public Pipe updatePipe(String name, String target, String roleArn, String description,
|
||||
DesiredState desiredState, String enrichment,
|
||||
JsonNode sourceParameters, JsonNode targetParameters,
|
||||
JsonNode enrichmentParameters, String region) {
|
||||
String key = region + "::" + name;
|
||||
Pipe pipe = storage.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"Pipe " + name + " does not exist.", 404));
|
||||
|
||||
if (target != null) pipe.setTarget(target);
|
||||
if (roleArn != null) pipe.setRoleArn(roleArn);
|
||||
if (description != null) pipe.setDescription(description);
|
||||
if (desiredState != null) {
|
||||
pipe.setDesiredState(desiredState);
|
||||
pipe.setCurrentState(desiredState == DesiredState.RUNNING ? PipeState.RUNNING : PipeState.STOPPED);
|
||||
}
|
||||
if (enrichment != null) pipe.setEnrichment(enrichment);
|
||||
if (sourceParameters != null) pipe.setSourceParameters(sourceParameters);
|
||||
if (targetParameters != null) pipe.setTargetParameters(targetParameters);
|
||||
if (enrichmentParameters != null) pipe.setEnrichmentParameters(enrichmentParameters);
|
||||
|
||||
pipe.setLastModifiedTime(Instant.now());
|
||||
storage.put(key, pipe);
|
||||
LOG.infov("Updated pipe: {0}", name);
|
||||
return pipe;
|
||||
}
|
||||
|
||||
public void deletePipe(String name, String region) {
|
||||
String key = region + "::" + name;
|
||||
if (storage.get(key).isEmpty()) {
|
||||
throw new AwsException("NotFoundException",
|
||||
"Pipe " + name + " does not exist.", 404);
|
||||
}
|
||||
storage.delete(key);
|
||||
LOG.infov("Deleted pipe: {0}", name);
|
||||
}
|
||||
|
||||
public List<Pipe> listPipes(String namePrefix, String sourcePrefix, String targetPrefix,
|
||||
DesiredState desiredState, PipeState currentState, String region) {
|
||||
String regionPrefix = region + "::";
|
||||
return storage.scan(key -> key.startsWith(regionPrefix)).stream()
|
||||
.filter(pipe -> namePrefix == null || pipe.getName().startsWith(namePrefix))
|
||||
.filter(pipe -> sourcePrefix == null || pipe.getSource().startsWith(sourcePrefix))
|
||||
.filter(pipe -> targetPrefix == null || pipe.getTarget().startsWith(targetPrefix))
|
||||
.filter(pipe -> desiredState == null || pipe.getDesiredState() == desiredState)
|
||||
.filter(pipe -> currentState == null || pipe.getCurrentState() == currentState)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Pipe startPipe(String name, String region) {
|
||||
String key = region + "::" + name;
|
||||
Pipe pipe = storage.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"Pipe " + name + " does not exist.", 404));
|
||||
|
||||
pipe.setDesiredState(DesiredState.RUNNING);
|
||||
pipe.setCurrentState(PipeState.RUNNING);
|
||||
pipe.setLastModifiedTime(Instant.now());
|
||||
storage.put(key, pipe);
|
||||
LOG.infov("Started pipe: {0}", name);
|
||||
return pipe;
|
||||
}
|
||||
|
||||
public Pipe stopPipe(String name, String region) {
|
||||
String key = region + "::" + name;
|
||||
Pipe pipe = storage.get(key)
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"Pipe " + name + " does not exist.", 404));
|
||||
|
||||
pipe.setDesiredState(DesiredState.STOPPED);
|
||||
pipe.setCurrentState(PipeState.STOPPED);
|
||||
pipe.setLastModifiedTime(Instant.now());
|
||||
storage.put(key, pipe);
|
||||
LOG.infov("Stopped pipe: {0}", name);
|
||||
return pipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serviceKey() {
|
||||
return "pipes";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tagResource(String region, String arn, Map<String, String> tags) {
|
||||
Pipe pipe = findByArn(arn, region);
|
||||
if (pipe.getTags() == null) {
|
||||
pipe.setTags(new HashMap<>());
|
||||
}
|
||||
pipe.getTags().putAll(tags);
|
||||
String key = region + "::" + pipe.getName();
|
||||
storage.put(key, pipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untagResource(String region, String arn, List<String> tagKeys) {
|
||||
Pipe pipe = findByArn(arn, region);
|
||||
if (pipe.getTags() != null && tagKeys != null) {
|
||||
tagKeys.forEach(pipe.getTags()::remove);
|
||||
}
|
||||
String key = region + "::" + pipe.getName();
|
||||
storage.put(key, pipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> listTags(String region, String arn) {
|
||||
Pipe pipe = findByArn(arn, region);
|
||||
return pipe.getTags() != null ? pipe.getTags() : Map.of();
|
||||
}
|
||||
|
||||
private Pipe findByArn(String arn, String region) {
|
||||
String regionPrefix = region + "::";
|
||||
return storage.scan(key -> key.startsWith(regionPrefix)).stream()
|
||||
.filter(pipe -> arn.equals(pipe.getArn()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AwsException("NotFoundException",
|
||||
"Resource " + arn + " does not exist.", 404));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.pipes.model;
|
||||
|
||||
public enum DesiredState {
|
||||
RUNNING,
|
||||
STOPPED
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package io.github.hectorvent.floci.services.pipes.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Pipe {
|
||||
|
||||
@JsonProperty("Name")
|
||||
private String name;
|
||||
|
||||
@JsonProperty("Arn")
|
||||
private String arn;
|
||||
|
||||
@JsonProperty("Source")
|
||||
private String source;
|
||||
|
||||
@JsonProperty("Target")
|
||||
private String target;
|
||||
|
||||
@JsonProperty("RoleArn")
|
||||
private String roleArn;
|
||||
|
||||
@JsonProperty("Description")
|
||||
private String description;
|
||||
|
||||
@JsonProperty("DesiredState")
|
||||
private DesiredState desiredState;
|
||||
|
||||
@JsonProperty("CurrentState")
|
||||
private PipeState currentState;
|
||||
|
||||
@JsonProperty("Enrichment")
|
||||
private String enrichment;
|
||||
|
||||
@JsonProperty("SourceParameters")
|
||||
private JsonNode sourceParameters;
|
||||
|
||||
@JsonProperty("TargetParameters")
|
||||
private JsonNode targetParameters;
|
||||
|
||||
@JsonProperty("EnrichmentParameters")
|
||||
private JsonNode enrichmentParameters;
|
||||
|
||||
@JsonProperty("Tags")
|
||||
private Map<String, String> tags;
|
||||
|
||||
@JsonProperty("CreationTime")
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant creationTime;
|
||||
|
||||
@JsonProperty("LastModifiedTime")
|
||||
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
|
||||
private Instant lastModifiedTime;
|
||||
|
||||
@JsonProperty("StateReason")
|
||||
private String stateReason;
|
||||
|
||||
public Pipe() {}
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
|
||||
public String getSource() { return source; }
|
||||
public void setSource(String source) { this.source = source; }
|
||||
|
||||
public String getTarget() { return target; }
|
||||
public void setTarget(String target) { this.target = target; }
|
||||
|
||||
public String getRoleArn() { return roleArn; }
|
||||
public void setRoleArn(String roleArn) { this.roleArn = roleArn; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public DesiredState getDesiredState() { return desiredState; }
|
||||
public void setDesiredState(DesiredState desiredState) { this.desiredState = desiredState; }
|
||||
|
||||
public PipeState getCurrentState() { return currentState; }
|
||||
public void setCurrentState(PipeState currentState) { this.currentState = currentState; }
|
||||
|
||||
public String getEnrichment() { return enrichment; }
|
||||
public void setEnrichment(String enrichment) { this.enrichment = enrichment; }
|
||||
|
||||
public JsonNode getSourceParameters() { return sourceParameters; }
|
||||
public void setSourceParameters(JsonNode sourceParameters) { this.sourceParameters = sourceParameters; }
|
||||
|
||||
public JsonNode getTargetParameters() { return targetParameters; }
|
||||
public void setTargetParameters(JsonNode targetParameters) { this.targetParameters = targetParameters; }
|
||||
|
||||
public JsonNode getEnrichmentParameters() { return enrichmentParameters; }
|
||||
public void setEnrichmentParameters(JsonNode enrichmentParameters) { this.enrichmentParameters = enrichmentParameters; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags; }
|
||||
|
||||
public Instant getCreationTime() { return creationTime; }
|
||||
public void setCreationTime(Instant creationTime) { this.creationTime = creationTime; }
|
||||
|
||||
public Instant getLastModifiedTime() { return lastModifiedTime; }
|
||||
public void setLastModifiedTime(Instant lastModifiedTime) { this.lastModifiedTime = lastModifiedTime; }
|
||||
|
||||
public String getStateReason() { return stateReason; }
|
||||
public void setStateReason(String stateReason) { this.stateReason = stateReason; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.github.hectorvent.floci.services.pipes.model;
|
||||
|
||||
public enum PipeState {
|
||||
RUNNING,
|
||||
STOPPED,
|
||||
CREATING,
|
||||
UPDATING,
|
||||
DELETING,
|
||||
STARTING,
|
||||
STOPPING,
|
||||
CREATE_FAILED,
|
||||
UPDATE_FAILED,
|
||||
START_FAILED,
|
||||
STOP_FAILED,
|
||||
DELETE_FAILED
|
||||
}
|
||||
Reference in new issue
Block a user