mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(iot) Feature/issue 1038 iot core (#1359)
* feat: add IoT endpoint and thing registry * feat: add IoT thing tagging * feat: add IoT certificates and shadows * feat: add IoT MQTT broker * feat: upgrade IoT MQTT broker to Moquette 0.18 * feat: restore IoT reserved MQTT topics * feat: add IoT topic rules engine * feat: improve IoT thing registry compatibility * feat: complete IoT MVP 1 compatibility * feat: complete IoT MVP 2 compatibility * feat: finish IoT MVP 2 coverage * fix: disable IoT MQTT broker persistence * fix(docker): include vendored Maven artifacts in source builds * fix(iot): stabilize MQTT integration test sockets * fix(iot): verify MQTT test connections * fix(iot): use Paho for MQTT integration tests * fix(iot): use Vert.x MQTT broker --------- Co-authored-by: nathan <nathan@debian-dev-small.localdomain>
This commit is contained in:
1 parent
54ba15c218
commit
326b495496
47 files changed
+8602
-19
No files matched your search
@@ -458,6 +458,34 @@ public interface EmulatorConfig {
|
||||
BatchServiceConfig batch();
|
||||
UiServiceConfig ui();
|
||||
S3VectorsServiceConfig s3vectors();
|
||||
IotServiceConfig iot();
|
||||
IotDataServiceConfig iotdata();
|
||||
}
|
||||
|
||||
interface IotServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
MqttConfig mqtt();
|
||||
}
|
||||
|
||||
interface MqttConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
@WithDefault("false")
|
||||
boolean autoStart();
|
||||
|
||||
@WithDefault("0.0.0.0")
|
||||
String host();
|
||||
|
||||
@WithDefault("1883")
|
||||
int port();
|
||||
}
|
||||
|
||||
interface IotDataServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface CloudTrailServiceConfig {
|
||||
|
||||
@@ -9,6 +9,8 @@ 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.iot.IotController;
|
||||
import io.github.hectorvent.floci.services.iot.IotDataController;
|
||||
import io.github.hectorvent.floci.services.pipes.PipesController;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaController;
|
||||
import io.github.hectorvent.floci.services.opensearch.OpenSearchController;
|
||||
@@ -347,7 +349,15 @@ public class ResolvedServiceCatalog {
|
||||
"s3vectors", storageMode(config.storage().services().s3vectors().mode(), config.storage().mode()),
|
||||
config.storage().services().s3vectors().flushIntervalMs(), null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("s3vectors"), Set.of(), Set.of(S3VectorsController.class))
|
||||
Set.of(), Set.of("s3vectors"), Set.of(), Set.of(S3VectorsController.class)),
|
||||
descriptor("iot", "iot", config.services().iot().enabled(), true,
|
||||
"iot", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("iot", "execute-api"), Set.of(), Set.of(IotController.class)),
|
||||
descriptor("iotdata", "iotdata", config.services().iotdata().enabled(), true,
|
||||
"iot", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("iotdata"), Set.of(), Set.of(IotDataController.class))
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,12 @@ public class ServiceEnabledFilter implements ContainerRequestFilter {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
var resourceMatch = catalog.byResourceClass(resourceClass());
|
||||
if (resourceMatch.isPresent()) {
|
||||
ServiceDescriptor descriptor = resourceMatch.get();
|
||||
return new ResolvedRequest(descriptor.externalKey(), descriptor.defaultProtocol());
|
||||
}
|
||||
|
||||
String auth = ctx.getHeaderString("Authorization");
|
||||
if (auth != null) {
|
||||
Matcher m = AUTH_SERVICE_PATTERN.matcher(auth);
|
||||
@@ -66,9 +72,7 @@ public class ServiceEnabledFilter implements ContainerRequestFilter {
|
||||
}
|
||||
}
|
||||
|
||||
return catalog.byResourceClass(resourceClass())
|
||||
.map(descriptor -> new ResolvedRequest(descriptor.externalKey(), descriptor.defaultProtocol()))
|
||||
.orElse(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
private Class<?> resourceClass() {
|
||||
|
||||
@@ -14,6 +14,7 @@ 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;
|
||||
@@ -63,8 +64,18 @@ public class SharedTagsController {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{arn: .*}")
|
||||
public Response listTagsByQuery(@Context HttpHeaders headers,
|
||||
@QueryParam("resourceArn") String arn) {
|
||||
return listTagsForArn(headers, arn);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{arn: .+}")
|
||||
public Response listTags(@Context HttpHeaders headers, @PathParam("arn") String arn) {
|
||||
return listTagsForArn(headers, arn);
|
||||
}
|
||||
|
||||
private Response listTagsForArn(HttpHeaders headers, String arn) {
|
||||
TagHandler handler = resolveHandler(arn);
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
Map<String, String> tags = handler.listTags(region, arn);
|
||||
@@ -72,7 +83,15 @@ public class SharedTagsController {
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{arn: .*}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourceByBody(@Context HttpHeaders headers, String body) {
|
||||
String arn = readResourceArn(body);
|
||||
TagHandler handler = resolveHandler(arn);
|
||||
return doTagResource(headers, handler, arn, body, Response.ok(objectMapper.createObjectNode()).build());
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/{arn: .+}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourcePost(@Context HttpHeaders headers,
|
||||
@PathParam("arn") String arn,
|
||||
@@ -82,11 +101,11 @@ public class SharedTagsController {
|
||||
throw new AwsException("MethodNotAllowedException",
|
||||
"POST is not supported for " + handler.serviceKey() + " tag resources; use PUT.", 405);
|
||||
}
|
||||
return doTagResource(headers, handler, arn, body);
|
||||
return doTagResource(headers, handler, arn, body, Response.noContent().build());
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("/{arn: .*}")
|
||||
@Path("/{arn: .+}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response tagResourcePut(@Context HttpHeaders headers,
|
||||
@PathParam("arn") String arn,
|
||||
@@ -96,17 +115,17 @@ public class SharedTagsController {
|
||||
throw new AwsException("MethodNotAllowedException",
|
||||
"PUT is not supported for " + handler.serviceKey() + " tag resources; use POST.", 405);
|
||||
}
|
||||
return doTagResource(headers, handler, arn, body);
|
||||
return doTagResource(headers, handler, arn, body, Response.noContent().build());
|
||||
}
|
||||
|
||||
private Response doTagResource(HttpHeaders headers, TagHandler handler, String arn, String body) {
|
||||
private Response doTagResource(HttpHeaders headers, TagHandler handler, String arn, String body, Response successResponse) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
String effectiveBody = (body == null || body.isBlank()) ? "{}" : body;
|
||||
try {
|
||||
JsonNode node = objectMapper.readTree(effectiveBody);
|
||||
Map<String, String> tags = parseTags(handler, node);
|
||||
handler.tagResource(region, arn, tags);
|
||||
return Response.noContent().build();
|
||||
return successResponse;
|
||||
} catch (AwsException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
@@ -116,15 +135,26 @@ public class SharedTagsController {
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{arn: .*}")
|
||||
public Response untagResourceByQuery(@Context HttpHeaders headers,
|
||||
@Context UriInfo uriInfo,
|
||||
@QueryParam("resourceArn") String arn) {
|
||||
return untagResourceForArn(headers, uriInfo, arn, Response.ok(objectMapper.createObjectNode()).build());
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/{arn: .+}")
|
||||
public Response untagResource(@Context HttpHeaders headers,
|
||||
@Context UriInfo uriInfo,
|
||||
@PathParam("arn") String arn) {
|
||||
@Context UriInfo uriInfo,
|
||||
@PathParam("arn") String arn) {
|
||||
return untagResourceForArn(headers, uriInfo, arn, Response.noContent().build());
|
||||
}
|
||||
|
||||
private Response untagResourceForArn(HttpHeaders headers, UriInfo uriInfo, String arn, Response successResponse) {
|
||||
TagHandler handler = resolveHandler(arn);
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<String> tagKeys = readTagKeys(handler, uriInfo);
|
||||
handler.untagResource(region, arn, tagKeys);
|
||||
return Response.noContent().build();
|
||||
return successResponse;
|
||||
}
|
||||
|
||||
private ObjectNode buildListResponse(TagHandler handler, Map<String, String> tags) {
|
||||
@@ -202,6 +232,15 @@ public class SharedTagsController {
|
||||
return (values == null) ? List.of() : List.copyOf(values);
|
||||
}
|
||||
|
||||
private String readResourceArn(String body) {
|
||||
try {
|
||||
JsonNode node = objectMapper.readTree((body == null || body.isBlank()) ? "{}" : body);
|
||||
return node.path("resourceArn").asText(null);
|
||||
} catch (Exception e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
private TagHandler resolveHandler(String arn) {
|
||||
// arn:aws:<service>:<region>:<account>:<resource>
|
||||
String[] parts = arn.split(":", 6);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,191 @@
|
||||
package io.github.hectorvent.floci.services.iot;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.iot.model.IotRetainedMessage;
|
||||
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.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 java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public class IotDataController {
|
||||
|
||||
private final IotService iotService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public IotDataController(IotService iotService, RegionResolver regionResolver, ObjectMapper objectMapper) {
|
||||
this.iotService = iotService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/things/{thingName}/shadow")
|
||||
public Response getThingShadow(@Context HttpHeaders headers,
|
||||
@PathParam("thingName") String thingName,
|
||||
@QueryParam("name") String shadowName) {
|
||||
return Response.ok(iotService.getThingShadow(thingName, shadowName, regionResolver.resolveRegion(headers))).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/things/{thingName}/shadow")
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
public Response updateThingShadow(@Context HttpHeaders headers,
|
||||
@PathParam("thingName") String thingName,
|
||||
@QueryParam("name") String shadowName,
|
||||
String body) {
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body == null || body.isBlank() ? "{}" : body);
|
||||
return Response.ok(iotService.updateThingShadow(thingName, shadowName, request, regionResolver.resolveRegion(headers))).build();
|
||||
} catch (AwsException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new AwsException("InvalidRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/things/{thingName}/shadow")
|
||||
public Response deleteThingShadow(@Context HttpHeaders headers,
|
||||
@PathParam("thingName") String thingName,
|
||||
@QueryParam("name") String shadowName) {
|
||||
return Response.ok(iotService.deleteThingShadow(thingName, shadowName, regionResolver.resolveRegion(headers))).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/api/things/shadow/ListNamedShadowsForThing/{thingName}")
|
||||
public Response listNamedShadowsForThing(@Context HttpHeaders headers,
|
||||
@PathParam("thingName") String thingName) {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
var results = response.putArray("results");
|
||||
iotService.listNamedShadowsForThing(thingName, regionResolver.resolveRegion(headers)).forEach(results::add);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/topics/{topic: .+}")
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
public Response publish(@PathParam("topic") String topic,
|
||||
@QueryParam("retain") Boolean retain,
|
||||
@QueryParam("qos") Integer qos,
|
||||
byte[] payload) {
|
||||
iotService.publish(topic, payload == null ? new byte[0] : payload, Boolean.TRUE.equals(retain), qos == null ? 0 : qos);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/connections/{clientId: .+}")
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
public Response deleteConnection(@PathParam("clientId") String clientId,
|
||||
@QueryParam("cleanSession") Boolean cleanSession,
|
||||
@QueryParam("preventWillMessage") Boolean preventWillMessage) {
|
||||
iotService.deleteConnection(clientId, Boolean.TRUE.equals(cleanSession));
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/connections/{clientId: .+}/subscriptions")
|
||||
public Response listSubscriptions(@PathParam("clientId") String clientId,
|
||||
@QueryParam("maxResults") Integer maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
IotService.Page<String> page = iotService.listSubscriptions(clientId, maxResults, nextToken);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
var subscriptions = response.putArray("subscriptions");
|
||||
for (String topicFilter : page.items()) {
|
||||
ObjectNode subscription = subscriptions.addObject();
|
||||
subscription.put("topicFilter", topicFilter);
|
||||
subscription.put("qos", 0);
|
||||
}
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/connections/{clientId: .+}")
|
||||
public Response getConnection(@PathParam("clientId") String clientId,
|
||||
@QueryParam("includeSocketInformation") Boolean includeSocketInformation) {
|
||||
IotMqttBrokerService.ConnectionInfo connection = iotService.getConnection(clientId);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("clientId", connection.clientId());
|
||||
response.put("connected", true);
|
||||
response.put("cleanSession", true);
|
||||
if (Boolean.TRUE.equals(includeSocketInformation)) {
|
||||
response.put("sourceIp", connection.address());
|
||||
response.put("sourcePort", connection.port());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/connections/{clientId: .+}/messages")
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
public Response sendDirectMessage(@PathParam("clientId") String clientId,
|
||||
@QueryParam("topic") String topic,
|
||||
@QueryParam("confirmation") Boolean confirmation,
|
||||
byte[] payload) {
|
||||
iotService.sendDirectMessage(clientId, topic, payload);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("message", "OK");
|
||||
response.put("traceId", UUID.randomUUID().toString());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/retainedMessage/{topic: .+}")
|
||||
public Response getRetainedMessage(@PathParam("topic") String topic) {
|
||||
IotRetainedMessage retained = iotService.getRetainedMessage(topic);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("topic", retained.getTopic());
|
||||
response.put("payload", retained.getPayload());
|
||||
response.put("qos", retained.getQos());
|
||||
putEpoch(response, "lastModifiedTime", retained.getLastModifiedTime());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/retainedMessage")
|
||||
public Response listRetainedMessages(@QueryParam("maxResults") Integer maxResults,
|
||||
@QueryParam("nextToken") String nextToken) {
|
||||
IotService.Page<IotRetainedMessage> page = iotService.listRetainedMessages(maxResults, nextToken);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
var topics = response.putArray("retainedTopics");
|
||||
for (IotRetainedMessage retained : page.items()) {
|
||||
ObjectNode item = topics.addObject();
|
||||
item.put("topic", retained.getTopic());
|
||||
item.put("payloadSize", Base64.getDecoder().decode(retained.getPayload()).length);
|
||||
item.put("qos", retained.getQos());
|
||||
putEpoch(item, "lastModifiedTime", retained.getLastModifiedTime());
|
||||
}
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private void putEpoch(ObjectNode node, String field, java.time.Instant instant) {
|
||||
if (instant != null) {
|
||||
node.put(field, instant.toEpochMilli() / 1000.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
package io.github.hectorvent.floci.services.iot;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.services.iot.model.IotRetainedMessage;
|
||||
import io.netty.handler.codec.mqtt.MqttQoS;
|
||||
import io.quarkus.runtime.ShutdownEvent;
|
||||
import io.quarkus.runtime.StartupEvent;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.net.SocketAddress;
|
||||
import io.vertx.mqtt.MqttEndpoint;
|
||||
import io.vertx.mqtt.MqttServer;
|
||||
import io.vertx.mqtt.MqttServerOptions;
|
||||
import io.vertx.mqtt.messages.MqttPublishMessage;
|
||||
import io.vertx.mqtt.messages.MqttSubscribeMessage;
|
||||
import io.vertx.mqtt.messages.MqttUnsubscribeMessage;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.enterprise.event.Observes;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@ApplicationScoped
|
||||
public class IotMqttBrokerService {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(IotMqttBrokerService.class);
|
||||
|
||||
private final EmulatorConfig config;
|
||||
private final Vertx vertx;
|
||||
private final Instance<IotService> iotService;
|
||||
private final Map<String, ClientSession> sessionsByClient = new ConcurrentHashMap<>();
|
||||
private final Map<String, Map<String, Subscription>> subscriptionsByClient = new ConcurrentHashMap<>();
|
||||
private MqttServer server;
|
||||
|
||||
@Inject
|
||||
public IotMqttBrokerService(EmulatorConfig config, Vertx vertx, Instance<IotService> iotService) {
|
||||
this.config = config;
|
||||
this.vertx = vertx;
|
||||
this.iotService = iotService;
|
||||
}
|
||||
|
||||
void onStart(@Observes StartupEvent ignored) {
|
||||
if (!config.services().iot().enabled() || !config.services().iot().mqtt().enabled()) {
|
||||
LOG.info("IoT MQTT broker disabled by configuration");
|
||||
return;
|
||||
}
|
||||
if (!config.services().iot().mqtt().autoStart()) {
|
||||
LOG.info("IoT MQTT broker auto-start disabled by configuration");
|
||||
return;
|
||||
}
|
||||
startIfEnabled();
|
||||
}
|
||||
|
||||
void onStop(@Observes ShutdownEvent ignored) {
|
||||
stop();
|
||||
}
|
||||
|
||||
synchronized void startIfEnabled() {
|
||||
if (!config.services().iot().enabled() || !config.services().iot().mqtt().enabled()) {
|
||||
return;
|
||||
}
|
||||
if (server != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MqttServer mqttServer = MqttServer.create(vertx, new MqttServerOptions()
|
||||
.setHost(config.services().iot().mqtt().host())
|
||||
.setPort(config.services().iot().mqtt().port()));
|
||||
mqttServer.endpointHandler(this::handleEndpoint);
|
||||
mqttServer.exceptionHandler(error -> LOG.warnv("IoT MQTT broker error: {0}", error.getMessage()));
|
||||
|
||||
try {
|
||||
mqttServer.listen().toCompletionStage().toCompletableFuture().join();
|
||||
server = mqttServer;
|
||||
LOG.infov("IoT MQTT broker started on {0}:{1}",
|
||||
config.services().iot().mqtt().host(), config.services().iot().mqtt().port());
|
||||
} catch (Exception e) {
|
||||
mqttServer.close();
|
||||
throw new IllegalStateException("Failed to start IoT MQTT broker", e);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void stop() {
|
||||
MqttServer mqttServer = server;
|
||||
if (mqttServer == null) {
|
||||
return;
|
||||
}
|
||||
server = null;
|
||||
sessionsByClient.values().forEach(session -> session.endpoint().close());
|
||||
sessionsByClient.clear();
|
||||
subscriptionsByClient.clear();
|
||||
mqttServer.close().toCompletionStage().toCompletableFuture().join();
|
||||
LOG.info("IoT MQTT broker stopped");
|
||||
}
|
||||
|
||||
public synchronized boolean isRunning() {
|
||||
return server != null;
|
||||
}
|
||||
|
||||
void publish(String topic, byte[] payload) {
|
||||
if (server == null) {
|
||||
return;
|
||||
}
|
||||
fanOut(topic, payload == null ? new byte[0] : payload, false);
|
||||
}
|
||||
|
||||
boolean disconnectClient(String clientId, boolean cleanSession) {
|
||||
ClientSession session = sessionsByClient.remove(clientId);
|
||||
if (session == null) {
|
||||
return false;
|
||||
}
|
||||
if (cleanSession) {
|
||||
subscriptionsByClient.remove(clientId);
|
||||
}
|
||||
session.endpoint().close();
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<ConnectionInfo> getConnection(String clientId) {
|
||||
if (server == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
ClientSession session = sessionsByClient.get(clientId);
|
||||
if (session == null || !session.endpoint().isConnected()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new ConnectionInfo(session.clientId(), session.sourceIp(), session.sourcePort()));
|
||||
}
|
||||
|
||||
List<String> listSubscriptions(String clientId) {
|
||||
return subscriptionsByClient.getOrDefault(clientId, Map.of()).keySet().stream()
|
||||
.sorted()
|
||||
.toList();
|
||||
}
|
||||
|
||||
private void handleEndpoint(MqttEndpoint endpoint) {
|
||||
String clientId = endpoint.clientIdentifier();
|
||||
SocketAddress remoteAddress = endpoint.remoteAddress();
|
||||
ClientSession session = new ClientSession(
|
||||
clientId,
|
||||
endpoint,
|
||||
remoteAddress == null ? null : remoteAddress.host(),
|
||||
remoteAddress == null ? -1 : remoteAddress.port(),
|
||||
endpoint.isCleanSession());
|
||||
|
||||
endpoint.subscriptionAutoAck(false);
|
||||
endpoint.publishAutoAck(false);
|
||||
endpoint.exceptionHandler(error -> LOG.warnv("IoT MQTT client {0} error: {1}", clientId, error.getMessage()));
|
||||
endpoint.subscribeHandler(message -> handleSubscribe(session, message));
|
||||
endpoint.unsubscribeHandler(message -> handleUnsubscribe(session, message));
|
||||
endpoint.publishHandler(message -> handlePublish(session, message));
|
||||
endpoint.disconnectHandler(ignored -> removeSession(session));
|
||||
endpoint.closeHandler(ignored -> removeSession(session));
|
||||
|
||||
ClientSession previous = sessionsByClient.put(clientId, session);
|
||||
if (previous != null && previous.endpoint() != endpoint) {
|
||||
previous.endpoint().close();
|
||||
}
|
||||
|
||||
endpoint.accept();
|
||||
}
|
||||
|
||||
private void handleSubscribe(ClientSession session, MqttSubscribeMessage message) {
|
||||
Map<String, Subscription> clientSubscriptions = subscriptionsByClient.computeIfAbsent(
|
||||
session.clientId(), ignored -> new ConcurrentHashMap<>());
|
||||
List<MqttQoS> grantedQos = new ArrayList<>();
|
||||
List<Subscription> accepted = new ArrayList<>();
|
||||
|
||||
for (io.vertx.mqtt.MqttTopicSubscription requested : message.topicSubscriptions()) {
|
||||
String topicFilter = requested.topicName();
|
||||
MqttQoS qos = requested.qualityOfService();
|
||||
if (!isValidTopicFilter(topicFilter) || qos == MqttQoS.EXACTLY_ONCE) {
|
||||
grantedQos.add(MqttQoS.FAILURE);
|
||||
continue;
|
||||
}
|
||||
|
||||
int granted = qos == MqttQoS.AT_LEAST_ONCE ? 1 : 0;
|
||||
Subscription subscription = new Subscription(topicFilter, granted);
|
||||
clientSubscriptions.put(topicFilter, subscription);
|
||||
accepted.add(subscription);
|
||||
grantedQos.add(granted == 1 ? MqttQoS.AT_LEAST_ONCE : MqttQoS.AT_MOST_ONCE);
|
||||
}
|
||||
|
||||
session.endpoint().subscribeAcknowledge(message.messageId(), grantedQos);
|
||||
deliverRetained(session, accepted);
|
||||
}
|
||||
|
||||
private void handleUnsubscribe(ClientSession session, MqttUnsubscribeMessage message) {
|
||||
Map<String, Subscription> clientSubscriptions = subscriptionsByClient.get(session.clientId());
|
||||
if (clientSubscriptions != null) {
|
||||
for (String topic : message.topics()) {
|
||||
clientSubscriptions.remove(topic);
|
||||
}
|
||||
if (clientSubscriptions.isEmpty()) {
|
||||
subscriptionsByClient.remove(session.clientId(), clientSubscriptions);
|
||||
}
|
||||
}
|
||||
session.endpoint().unsubscribeAcknowledge(message.messageId());
|
||||
}
|
||||
|
||||
private void handlePublish(ClientSession session, MqttPublishMessage message) {
|
||||
byte[] payload = message.payload().getBytes();
|
||||
if (message.qosLevel() == MqttQoS.EXACTLY_ONCE) {
|
||||
session.endpoint().close();
|
||||
return;
|
||||
}
|
||||
if (message.qosLevel() == MqttQoS.AT_LEAST_ONCE) {
|
||||
session.endpoint().publishAcknowledge(message.messageId());
|
||||
}
|
||||
|
||||
String topic = message.topicName();
|
||||
if (topic.startsWith("$aws/")) {
|
||||
iotService.get().handleReservedMqttPublish(topic, payload, this::publish);
|
||||
return;
|
||||
}
|
||||
|
||||
iotService.get().publish(topic, payload, message.isRetain(), message.qosLevel().value());
|
||||
fanOut(topic, payload, false);
|
||||
}
|
||||
|
||||
private void fanOut(String topic, byte[] payload, boolean retained) {
|
||||
byte[] safePayload = payload == null ? new byte[0] : payload.clone();
|
||||
for (ClientSession session : sessionsByClient.values()) {
|
||||
if (!session.endpoint().isConnected() || !hasMatchingSubscription(session.clientId(), topic)) {
|
||||
continue;
|
||||
}
|
||||
session.endpoint().publish(topic, Buffer.buffer(safePayload), MqttQoS.AT_MOST_ONCE, false, retained);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasMatchingSubscription(String clientId, String topic) {
|
||||
Map<String, Subscription> subscriptions = subscriptionsByClient.get(clientId);
|
||||
if (subscriptions == null) {
|
||||
return false;
|
||||
}
|
||||
return subscriptions.values().stream().anyMatch(subscription -> topicMatches(subscription.topicFilter(), topic));
|
||||
}
|
||||
|
||||
private void deliverRetained(ClientSession session, List<Subscription> subscriptions) {
|
||||
if (subscriptions.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<String> deliveredTopics = new HashSet<>();
|
||||
for (IotRetainedMessage retained : iotService.get().listRetainedMessages(null, null).items()) {
|
||||
if (!deliveredTopics.add(retained.getTopic())) {
|
||||
continue;
|
||||
}
|
||||
boolean matches = subscriptions.stream()
|
||||
.anyMatch(subscription -> topicMatches(subscription.topicFilter(), retained.getTopic()));
|
||||
if (!matches) {
|
||||
continue;
|
||||
}
|
||||
byte[] payload = Base64.getDecoder().decode(retained.getPayload());
|
||||
session.endpoint().publish(retained.getTopic(), Buffer.buffer(payload), MqttQoS.AT_MOST_ONCE, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeSession(ClientSession session) {
|
||||
sessionsByClient.remove(session.clientId(), session);
|
||||
if (session.cleanSession()) {
|
||||
subscriptionsByClient.remove(session.clientId());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isValidTopicFilter(String topicFilter) {
|
||||
if (topicFilter == null || topicFilter.isBlank()) {
|
||||
return false;
|
||||
}
|
||||
String[] levels = topicFilter.split("/", -1);
|
||||
for (int i = 0; i < levels.length; i++) {
|
||||
String level = levels[i];
|
||||
if (level.contains("#") && (!"#".equals(level) || i != levels.length - 1)) {
|
||||
return false;
|
||||
}
|
||||
if (level.contains("+") && !"+".equals(level)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean topicMatches(String topicFilter, String topic) {
|
||||
if (topicFilter.equals(topic)) {
|
||||
return true;
|
||||
}
|
||||
String[] filterLevels = topicFilter.split("/", -1);
|
||||
String[] topicLevels = topic.split("/", -1);
|
||||
for (int i = 0; i < filterLevels.length; i++) {
|
||||
String filterLevel = filterLevels[i];
|
||||
if ("#".equals(filterLevel)) {
|
||||
return i == filterLevels.length - 1;
|
||||
}
|
||||
if (i >= topicLevels.length) {
|
||||
return false;
|
||||
}
|
||||
if (!"+".equals(filterLevel) && !filterLevel.equals(topicLevels[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return filterLevels.length == topicLevels.length;
|
||||
}
|
||||
|
||||
private record ClientSession(
|
||||
String clientId,
|
||||
MqttEndpoint endpoint,
|
||||
String sourceIp,
|
||||
int sourcePort,
|
||||
boolean cleanSession) {
|
||||
}
|
||||
|
||||
private record Subscription(String topicFilter, int qos) {
|
||||
}
|
||||
|
||||
record ConnectionInfo(String clientId, String address, int port) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package io.github.hectorvent.floci.services.iot;
|
||||
|
||||
public record IotPublishEvent(String topic, byte[] payload) {
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package io.github.hectorvent.floci.services.iot;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ApplicationScoped
|
||||
public class IotPublishEventRecorder {
|
||||
|
||||
private final List<IotPublishEvent> events = new ArrayList<>();
|
||||
|
||||
public synchronized void record(String topic, byte[] payload) {
|
||||
events.add(new IotPublishEvent(topic, payload == null ? new byte[0] : payload.clone()));
|
||||
}
|
||||
|
||||
public synchronized List<IotPublishEvent> recentEvents() {
|
||||
return List.copyOf(events);
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
events.clear();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,44 @@
|
||||
package io.github.hectorvent.floci.services.iot;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.TagHandler;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
public class IotTagHandler implements TagHandler {
|
||||
|
||||
private final IotService iotService;
|
||||
|
||||
@Inject
|
||||
public IotTagHandler(IotService iotService) {
|
||||
this.iotService = iotService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serviceKey() {
|
||||
return "iot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tagsBodyIsList() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> listTags(String region, String arn) {
|
||||
return iotService.listTagsForResource(arn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tagResource(String region, String arn, Map<String, String> tags) {
|
||||
iotService.tagResource(arn, tags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untagResource(String region, String arn, List<String> tagKeys) {
|
||||
iotService.untagResource(arn, tagKeys);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class IotCertificate {
|
||||
private String certificateId;
|
||||
private String certificateArn;
|
||||
private String certificatePem;
|
||||
private String publicKey;
|
||||
private String privateKey;
|
||||
private String status;
|
||||
private Instant creationDate;
|
||||
private Map<String, String> tags = new TreeMap<>();
|
||||
|
||||
public String getCertificateId() { return certificateId; }
|
||||
public void setCertificateId(String certificateId) { this.certificateId = certificateId; }
|
||||
public String getCertificateArn() { return certificateArn; }
|
||||
public void setCertificateArn(String certificateArn) { this.certificateArn = certificateArn; }
|
||||
public String getCertificatePem() { return certificatePem; }
|
||||
public void setCertificatePem(String certificatePem) { this.certificatePem = certificatePem; }
|
||||
public String getPublicKey() { return publicKey; }
|
||||
public void setPublicKey(String publicKey) { this.publicKey = publicKey; }
|
||||
public String getPrivateKey() { return privateKey; }
|
||||
public void setPrivateKey(String privateKey) { this.privateKey = privateKey; }
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
public Instant getCreationDate() { return creationDate; }
|
||||
public void setCreationDate(Instant creationDate) { this.creationDate = creationDate; }
|
||||
public Map<String, String> getTags() { return tags == null ? Map.of() : tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags == null ? new TreeMap<>() : new TreeMap<>(tags); }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class IotJob {
|
||||
|
||||
private String jobId;
|
||||
private String jobArn;
|
||||
private String document;
|
||||
private String documentSource;
|
||||
private String description;
|
||||
private String targetSelection = "SNAPSHOT";
|
||||
private String status = "IN_PROGRESS";
|
||||
private List<String> targets = new ArrayList<>();
|
||||
private Instant createdAt;
|
||||
private Instant lastUpdatedAt;
|
||||
|
||||
public String getJobId() { return jobId; }
|
||||
public void setJobId(String jobId) { this.jobId = jobId; }
|
||||
|
||||
public String getJobArn() { return jobArn; }
|
||||
public void setJobArn(String jobArn) { this.jobArn = jobArn; }
|
||||
|
||||
public String getDocument() { return document; }
|
||||
public void setDocument(String document) { this.document = document; }
|
||||
|
||||
public String getDocumentSource() { return documentSource; }
|
||||
public void setDocumentSource(String documentSource) { this.documentSource = documentSource; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public String getTargetSelection() { return targetSelection; }
|
||||
public void setTargetSelection(String targetSelection) { this.targetSelection = targetSelection; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
|
||||
public List<String> getTargets() { return targets; }
|
||||
public void setTargets(List<String> targets) { this.targets = targets == null ? new ArrayList<>() : new ArrayList<>(targets); }
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public Instant getLastUpdatedAt() { return lastUpdatedAt; }
|
||||
public void setLastUpdatedAt(Instant lastUpdatedAt) { this.lastUpdatedAt = lastUpdatedAt; }
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class IotJobExecution {
|
||||
|
||||
private String jobId;
|
||||
private String thingName;
|
||||
private String thingArn;
|
||||
private String status = "QUEUED";
|
||||
private Map<String, String> statusDetails = new HashMap<>();
|
||||
private Instant queuedAt;
|
||||
private Instant startedAt;
|
||||
private Instant lastUpdatedAt;
|
||||
private long executionNumber = 1L;
|
||||
private long versionNumber = 1L;
|
||||
|
||||
public String getJobId() { return jobId; }
|
||||
public void setJobId(String jobId) { this.jobId = jobId; }
|
||||
|
||||
public String getThingName() { return thingName; }
|
||||
public void setThingName(String thingName) { this.thingName = thingName; }
|
||||
|
||||
public String getThingArn() { return thingArn; }
|
||||
public void setThingArn(String thingArn) { this.thingArn = thingArn; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
|
||||
public Map<String, String> getStatusDetails() { return statusDetails; }
|
||||
public void setStatusDetails(Map<String, String> statusDetails) { this.statusDetails = statusDetails == null ? new HashMap<>() : new HashMap<>(statusDetails); }
|
||||
|
||||
public Instant getQueuedAt() { return queuedAt; }
|
||||
public void setQueuedAt(Instant queuedAt) { this.queuedAt = queuedAt; }
|
||||
|
||||
public Instant getStartedAt() { return startedAt; }
|
||||
public void setStartedAt(Instant startedAt) { this.startedAt = startedAt; }
|
||||
|
||||
public Instant getLastUpdatedAt() { return lastUpdatedAt; }
|
||||
public void setLastUpdatedAt(Instant lastUpdatedAt) { this.lastUpdatedAt = lastUpdatedAt; }
|
||||
|
||||
public long getExecutionNumber() { return executionNumber; }
|
||||
public void setExecutionNumber(long executionNumber) { this.executionNumber = executionNumber; }
|
||||
|
||||
public long getVersionNumber() { return versionNumber; }
|
||||
public void setVersionNumber(long versionNumber) { this.versionNumber = versionNumber; }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class IotPolicy {
|
||||
private String policyName;
|
||||
private String policyArn;
|
||||
private String policyDocument;
|
||||
private String defaultVersionId;
|
||||
private Instant creationDate;
|
||||
private List<PolicyVersion> versions = new ArrayList<>();
|
||||
private Map<String, String> tags = new TreeMap<>();
|
||||
|
||||
public String getPolicyName() { return policyName; }
|
||||
public void setPolicyName(String policyName) { this.policyName = policyName; }
|
||||
public String getPolicyArn() { return policyArn; }
|
||||
public void setPolicyArn(String policyArn) { this.policyArn = policyArn; }
|
||||
public String getPolicyDocument() { return policyDocument; }
|
||||
public void setPolicyDocument(String policyDocument) { this.policyDocument = policyDocument; }
|
||||
public String getDefaultVersionId() { return defaultVersionId; }
|
||||
public void setDefaultVersionId(String defaultVersionId) { this.defaultVersionId = defaultVersionId; }
|
||||
public Instant getCreationDate() { return creationDate; }
|
||||
public void setCreationDate(Instant creationDate) { this.creationDate = creationDate; }
|
||||
public List<PolicyVersion> getVersions() { return versions == null ? List.of() : versions; }
|
||||
public void setVersions(List<PolicyVersion> versions) { this.versions = versions == null ? new ArrayList<>() : new ArrayList<>(versions); }
|
||||
public Map<String, String> getTags() { return tags == null ? Map.of() : tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags == null ? new TreeMap<>() : new TreeMap<>(tags); }
|
||||
|
||||
public static class PolicyVersion {
|
||||
private String versionId;
|
||||
private String document;
|
||||
private Instant createDate;
|
||||
|
||||
public String getVersionId() { return versionId; }
|
||||
public void setVersionId(String versionId) { this.versionId = versionId; }
|
||||
public String getDocument() { return document; }
|
||||
public void setDocument(String document) { this.document = document; }
|
||||
public Instant getCreateDate() { return createDate; }
|
||||
public void setCreateDate(Instant createDate) { this.createDate = createDate; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class IotRetainedMessage {
|
||||
private String topic;
|
||||
private String payload;
|
||||
private int qos;
|
||||
private Instant lastModifiedTime;
|
||||
|
||||
public String getTopic() { return topic; }
|
||||
public void setTopic(String topic) { this.topic = topic; }
|
||||
public String getPayload() { return payload; }
|
||||
public void setPayload(String payload) { this.payload = payload; }
|
||||
public int getQos() { return qos; }
|
||||
public void setQos(int qos) { this.qos = qos; }
|
||||
public Instant getLastModifiedTime() { return lastModifiedTime; }
|
||||
public void setLastModifiedTime(Instant lastModifiedTime) { this.lastModifiedTime = lastModifiedTime; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
public class IotShadow {
|
||||
private String thingName;
|
||||
private String shadowName;
|
||||
private String document;
|
||||
private long version;
|
||||
|
||||
public String getThingName() { return thingName; }
|
||||
public void setThingName(String thingName) { this.thingName = thingName; }
|
||||
public String getShadowName() { return shadowName; }
|
||||
public void setShadowName(String shadowName) { this.shadowName = shadowName; }
|
||||
public String getDocument() { return document; }
|
||||
public void setDocument(String document) { this.document = document; }
|
||||
public long getVersion() { return version; }
|
||||
public void setVersion(long version) { this.version = version; }
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class IotThingGroup {
|
||||
|
||||
private String thingGroupName;
|
||||
private String thingGroupArn;
|
||||
private String thingGroupId;
|
||||
private String description;
|
||||
private Map<String, String> attributes = new HashMap<>();
|
||||
private long version = 1L;
|
||||
private Instant creationDate;
|
||||
|
||||
public String getThingGroupName() { return thingGroupName; }
|
||||
public void setThingGroupName(String thingGroupName) { this.thingGroupName = thingGroupName; }
|
||||
|
||||
public String getThingGroupArn() { return thingGroupArn; }
|
||||
public void setThingGroupArn(String thingGroupArn) { this.thingGroupArn = thingGroupArn; }
|
||||
|
||||
public String getThingGroupId() { return thingGroupId; }
|
||||
public void setThingGroupId(String thingGroupId) { this.thingGroupId = thingGroupId; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public Map<String, String> getAttributes() { return attributes; }
|
||||
public void setAttributes(Map<String, String> attributes) { this.attributes = attributes == null ? new HashMap<>() : new HashMap<>(attributes); }
|
||||
|
||||
public long getVersion() { return version; }
|
||||
public void setVersion(long version) { this.version = version; }
|
||||
|
||||
public Instant getCreationDate() { return creationDate; }
|
||||
public void setCreationDate(Instant creationDate) { this.creationDate = creationDate; }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class IotThingType {
|
||||
|
||||
private String thingTypeName;
|
||||
private String thingTypeArn;
|
||||
private String thingTypeId;
|
||||
private String description;
|
||||
private List<String> searchableAttributes = new ArrayList<>();
|
||||
private boolean deprecated;
|
||||
private Instant creationDate;
|
||||
private Instant deprecatedDate;
|
||||
|
||||
public String getThingTypeName() { return thingTypeName; }
|
||||
public void setThingTypeName(String thingTypeName) { this.thingTypeName = thingTypeName; }
|
||||
|
||||
public String getThingTypeArn() { return thingTypeArn; }
|
||||
public void setThingTypeArn(String thingTypeArn) { this.thingTypeArn = thingTypeArn; }
|
||||
|
||||
public String getThingTypeId() { return thingTypeId; }
|
||||
public void setThingTypeId(String thingTypeId) { this.thingTypeId = thingTypeId; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public List<String> getSearchableAttributes() { return searchableAttributes; }
|
||||
public void setSearchableAttributes(List<String> searchableAttributes) { this.searchableAttributes = searchableAttributes == null ? new ArrayList<>() : new ArrayList<>(searchableAttributes); }
|
||||
|
||||
public boolean isDeprecated() { return deprecated; }
|
||||
public void setDeprecated(boolean deprecated) { this.deprecated = deprecated; }
|
||||
|
||||
public Instant getCreationDate() { return creationDate; }
|
||||
public void setCreationDate(Instant creationDate) { this.creationDate = creationDate; }
|
||||
|
||||
public Instant getDeprecatedDate() { return deprecatedDate; }
|
||||
public void setDeprecatedDate(Instant deprecatedDate) { this.deprecatedDate = deprecatedDate; }
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class IotTopicRule {
|
||||
private String ruleName;
|
||||
private String ruleArn;
|
||||
private String sql;
|
||||
private String description;
|
||||
private boolean ruleDisabled;
|
||||
private String actionsJson = "[]";
|
||||
private Instant createdAt;
|
||||
private Map<String, String> tags = new TreeMap<>();
|
||||
|
||||
public String getRuleName() {
|
||||
return ruleName;
|
||||
}
|
||||
|
||||
public void setRuleName(String ruleName) {
|
||||
this.ruleName = ruleName;
|
||||
}
|
||||
|
||||
public String getRuleArn() {
|
||||
return ruleArn;
|
||||
}
|
||||
|
||||
public void setRuleArn(String ruleArn) {
|
||||
this.ruleArn = ruleArn;
|
||||
}
|
||||
|
||||
public String getSql() {
|
||||
return sql;
|
||||
}
|
||||
|
||||
public void setSql(String sql) {
|
||||
this.sql = sql;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isRuleDisabled() {
|
||||
return ruleDisabled;
|
||||
}
|
||||
|
||||
public void setRuleDisabled(boolean ruleDisabled) {
|
||||
this.ruleDisabled = ruleDisabled;
|
||||
}
|
||||
|
||||
public String getActionsJson() {
|
||||
return actionsJson;
|
||||
}
|
||||
|
||||
public void setActionsJson(String actionsJson) {
|
||||
this.actionsJson = actionsJson;
|
||||
}
|
||||
|
||||
public Instant getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(Instant createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
return tags == null ? Map.of() : tags;
|
||||
}
|
||||
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags == null ? new TreeMap<>() : new TreeMap<>(tags);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package io.github.hectorvent.floci.services.iot.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Thing {
|
||||
|
||||
private String thingName;
|
||||
private String thingArn;
|
||||
private String thingId;
|
||||
private String thingTypeName;
|
||||
private Map<String, String> attributes = new HashMap<>();
|
||||
private Map<String, String> tags = new HashMap<>();
|
||||
private long version;
|
||||
private Instant creationDate;
|
||||
private Instant lastModifiedDate;
|
||||
|
||||
public String getThingName() {
|
||||
return thingName;
|
||||
}
|
||||
|
||||
public void setThingName(String thingName) {
|
||||
this.thingName = thingName;
|
||||
}
|
||||
|
||||
public String getThingArn() {
|
||||
return thingArn;
|
||||
}
|
||||
|
||||
public void setThingArn(String thingArn) {
|
||||
this.thingArn = thingArn;
|
||||
}
|
||||
|
||||
public String getThingId() {
|
||||
return thingId;
|
||||
}
|
||||
|
||||
public void setThingId(String thingId) {
|
||||
this.thingId = thingId;
|
||||
}
|
||||
|
||||
public String getThingTypeName() {
|
||||
return thingTypeName;
|
||||
}
|
||||
|
||||
public void setThingTypeName(String thingTypeName) {
|
||||
this.thingTypeName = thingTypeName;
|
||||
}
|
||||
|
||||
public Map<String, String> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
public void setAttributes(Map<String, String> attributes) {
|
||||
this.attributes = attributes != null ? new HashMap<>(attributes) : new HashMap<>();
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags != null ? new HashMap<>(tags) : new HashMap<>();
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Instant getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void setCreationDate(Instant creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public Instant getLastModifiedDate() {
|
||||
return lastModifiedDate;
|
||||
}
|
||||
|
||||
public void setLastModifiedDate(Instant lastModifiedDate) {
|
||||
this.lastModifiedDate = lastModifiedDate;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user