use of udmi.schema.Metadata in project udmi by faucetsdn.
the class ProxyTarget method getMqttPublisher.
public MessagePublisher getMqttPublisher(String deviceId) {
Metadata udmi = getUdmiMetadata(deviceId);
String gatewayId = extractGateway(udmi);
if (gatewayId != null) {
if (shouldIgnoreTarget(gatewayId)) {
info("Ignoring proxy message for gateway " + gatewayId);
return null;
}
return getMqttPublisher(gatewayId);
}
return messagePublishers.computeIfAbsent(deviceId, deviceKey -> newMqttPublisher(deviceId));
}
use of udmi.schema.Metadata in project udmi by faucetsdn.
the class ProxyTarget method parseUdmiMetadta.
private Metadata parseUdmiMetadta(String deviceId) {
try {
Device device = cloudIotManager.fetchDevice(deviceId);
Map<String, String> metadata = device.getMetadata();
if (metadata == null) {
return new Metadata();
}
String udmi_metadata = metadata.get(UDMI_METADATA);
if (udmi_metadata == null) {
return new Metadata();
}
return OBJECT_MAPPER.readValue(udmi_metadata, Metadata.class);
} catch (Exception e) {
throw new RuntimeException("While loading device udmi metadata for " + deviceId, e);
}
}
use of udmi.schema.Metadata in project udmi by faucetsdn.
the class Pubber method loadDeviceMetadata.
private void loadDeviceMetadata() {
Preconditions.checkState(configuration.sitePath != null, "sitePath not defined");
Preconditions.checkState(configuration.deviceId != null, "deviceId not defined");
File devicesFile = new File(new File(configuration.sitePath), "devices");
File deviceDir = new File(devicesFile, configuration.deviceId);
File deviceMetadataFile = new File(deviceDir, "metadata.json");
try {
Metadata metadata = OBJECT_MAPPER.readValue(deviceMetadataFile, Metadata.class);
processDeviceMetadata(metadata);
} catch (Exception e) {
throw new RuntimeException("While reading metadata file " + deviceMetadataFile.getAbsolutePath(), e);
}
}
use of udmi.schema.Metadata in project udmi by faucetsdn.
the class LocalDevice method writeNormalized.
void writeNormalized() {
File metadataFile = new File(outDir, NORMALIZED_JSON);
if (metadata == null) {
System.err.println("Deleting (invalid) " + metadataFile.getAbsolutePath());
metadataFile.delete();
return;
}
Metadata normalized = readNormalized();
String writeHash = metadataHash();
if (normalized.hash != null && normalized.hash.equals(writeHash)) {
metadata.timestamp = normalized.timestamp;
return;
}
metadata.timestamp = new Date();
metadata.hash = writeHash;
System.err.println("Writing normalized " + metadataFile.getAbsolutePath());
try (OutputStream outputStream = new FileOutputStream(metadataFile)) {
// Super annoying, but can't set this on the global static instance.
JsonGenerator generator = OBJECT_MAPPER.getFactory().createGenerator(outputStream).setPrettyPrinter(PROPER_PRETTY_PRINTER_POLICY);
OBJECT_MAPPER.writeValue(generator, metadata);
} catch (Exception e) {
exceptionMap.put(EXCEPTION_WRITING, e);
}
}
Aggregations