Search in sources :

Example 1 with Metadata

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));
}
Also used : Metadata(udmi.schema.Metadata)

Example 2 with Metadata

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);
    }
}
Also used : Device(com.google.api.services.cloudiot.v1.model.Device) Metadata(udmi.schema.Metadata)

Example 3 with Metadata

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);
    }
}
Also used : PointPointsetMetadata(udmi.schema.PointPointsetMetadata) Metadata(udmi.schema.Metadata) File(java.io.File) PublisherException(daq.pubber.MqttPublisher.PublisherException) ConnectionClosedException(org.apache.http.ConnectionClosedException)

Example 4 with Metadata

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);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) PointPointsetMetadata(udmi.schema.PointPointsetMetadata) Metadata(udmi.schema.Metadata) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) File(java.io.File) Date(java.util.Date) ProcessingException(com.github.fge.jsonschema.core.exceptions.ProcessingException) ValidationException(com.google.daq.mqtt.util.ValidationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Aggregations

Metadata (udmi.schema.Metadata)4 File (java.io.File)2 PointPointsetMetadata (udmi.schema.PointPointsetMetadata)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ProcessingException (com.github.fge.jsonschema.core.exceptions.ProcessingException)1 Device (com.google.api.services.cloudiot.v1.model.Device)1 ValidationException (com.google.daq.mqtt.util.ValidationException)1 PublisherException (daq.pubber.MqttPublisher.PublisherException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 ConnectionClosedException (org.apache.http.ConnectionClosedException)1