Skip to content

Commit

Permalink
Adding metadata extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
grafnu committed Sep 20, 2024
1 parent 3c153d3 commit cfa710e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 2 additions & 3 deletions common/src/main/java/com/google/udmi/util/GeneralUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ public class GeneralUtils {
.enable(SerializationFeature.INDENT_OUTPUT)
.setDateFormat(new ISO8601DateFormat())
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
.setSerializationInclusion(Include.NON_NULL);
public static final ObjectMapper OBJECT_MAPPER_RAW =
OBJECT_MAPPER.copy()
.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS)
.enable(Feature.ALLOW_TRAILING_COMMA)
.enable(Feature.STRICT_DUPLICATE_DETECTION)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.setSerializationInclusion(Include.NON_NULL);
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
public static final ObjectMapper OBJECT_MAPPER_STRICT =
OBJECT_MAPPER_RAW.copy()
.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
Expand Down
6 changes: 2 additions & 4 deletions common/src/main/java/com/google/udmi/util/SiteModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import com.google.common.collect.ImmutableList;

import com.google.daq.mqtt.util.ExceptionMap;
import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -71,8 +70,8 @@ public class SiteModel {
public static final String DEVICES_DIR = "devices";
public static final String REFLECTOR_DIR = "reflector";
public static final String METADATA_JSON = "metadata.json";
public static final String EXTRA_DEVICES_BASE = "extras";
public static final String EXTRA_DEVICES_FORMAT = EXTRA_DEVICES_BASE + "/%s";
public static final String EXTRAS_DIR = "extras";
public static final String EXTRA_DEVICES_FORMAT = EXTRAS_DIR + "/%s";
public static final String NORMALIZED_JSON = "metadata_norm.json";
public static final String SITE_DEFAULTS_FILE = "site_defaults.json";
public static final String REGISTRATION_SUMMARY_BASE = "out/registration_summary";
Expand All @@ -89,7 +88,6 @@ public class SiteModel {
private static final Pattern IOT_CORE_PATTERN = Pattern.compile(
"projects/(.*)/locations/(.*)/registries/(.*)/devices/(.*)");
private static final Pattern MQTT_PATTERN = Pattern.compile("/r/(.*)/d/(.*)");
private static final String EXTRAS_DIR = "extras";
private static final String CLOUD_IOT_CONFIG_JSON = "cloud_iot_config.json";
private static final Pattern SPEC_PATTERN = Pattern.compile(
"(//([a-z]+)/)?([a-z-]+)(/([a-z0-9]+))?");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import static com.google.udmi.util.GeneralUtils.ifNullThen;
import static com.google.udmi.util.GeneralUtils.ifTrueThen;
import static com.google.udmi.util.GeneralUtils.isNullOrNotEmpty;
import static com.google.udmi.util.GeneralUtils.requireNull;
import static com.google.udmi.util.JsonUtil.asMap;
import static com.google.udmi.util.JsonUtil.isoConvert;
import static com.google.udmi.util.JsonUtil.stringify;
import static com.google.udmi.util.JsonUtil.stringifyTerse;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
import static java.util.Optional.ofNullable;
Expand Down Expand Up @@ -201,6 +203,8 @@ private Map<String, String> toDeviceMap(CloudModel cloudModel, String createdAt)
ifNotNullThen(createdAt, x -> properties.put(CREATED_AT_PROPERTY, createdAt));
properties.put(RESOURCE_TYPE_PROPERTY,
ofNullable(cloudModel.resource_type).orElse(DEVICE).toString());
requireNull(cloudModel.metadata_str, "unexpected metadata_str content");
properties.put(METADATA_STR_KEY, stringifyTerse(cloudModel.metadata));
properties.put(BLOCKED_PROPERTY, booleanString(cloudModel.blocked));
ifNotNullThen(cloudModel.num_id, id -> properties.put(NUM_ID_PROPERTY, id));
ifTrueThen(!cloudModel.credentials.isEmpty(), () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ private CloudModel processExtra(String extraName, AtomicInteger alreadyBlocked)
}

private void reapExtraDevices(Set<String> current) {
File extrasDir = new File(siteDir, SiteModel.EXTRA_DEVICES_BASE);
File extrasDir = new File(siteDir, SiteModel.EXTRAS_DIR);
String[] existing = ofNullable(extrasDir.list()).orElse(new String[0]);
Set<String> previous = Arrays.stream(existing).collect(Collectors.toSet());
difference(previous, current).forEach(expired -> {
Expand Down

0 comments on commit cfa710e

Please sign in to comment.