Search in sources :

Example 61 with Device

use of org.hl7.fhir.dstu3.model.Device in project udmi by faucetsdn.

the class CloudIotManager method listDevices.

Set<String> listDevices() {
    final String registryPath = String.format("projects/%s/locations/%s/registries/%s", projectId, iotConfig.cloud_region, iotConfig.registry_id);
    try {
        Set<String> deviceSet = new HashSet<>();
        String nextPageToken = null;
        do {
            LOG.info("Listing devices for " + registryPath);
            Devices.List listRequest = cloudIot.projects().locations().registries().devices().list(registryPath);
            if (nextPageToken != null) {
                listRequest.setPageToken(nextPageToken);
            }
            ListDevicesResponse listDevicesResponse = listRequest.execute();
            List<Device> devices = listDevicesResponse.getDevices();
            if (devices == null) {
                throw new RuntimeException("Devices list is empty");
            }
            devices.forEach(device -> deviceSet.add(device.getId()));
            nextPageToken = listDevicesResponse.getNextPageToken();
        } while (nextPageToken != null);
        return deviceSet;
    } catch (Exception e) {
        throw new RuntimeException("While fetching devices from " + registryPath, e);
    }
}
Also used : ListDevicesResponse(com.google.api.services.cloudiot.v1.model.ListDevicesResponse) Device(com.google.api.services.cloudiot.v1.model.Device) Devices(com.google.api.services.cloudiot.v1.CloudIot.Projects.Locations.Registries.Devices) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) HashSet(java.util.HashSet)

Example 62 with Device

use of org.hl7.fhir.dstu3.model.Device in project udmi by faucetsdn.

the class Registrar method updateCloudIoT.

private void updateCloudIoT(String localName, LocalDevice localDevice) {
    if (!updateCloudIoT) {
        return;
    }
    updateCloudIoT(localDevice);
    Device device = Preconditions.checkNotNull(fetchDevice(localName), "missing device " + localName);
    BigInteger numId = Preconditions.checkNotNull(device.getNumId(), "missing deviceNumId for " + localName);
    localDevice.setDeviceNumId(numId.toString());
}
Also used : Device(com.google.api.services.cloudiot.v1.model.Device) BigInteger(java.math.BigInteger)

Example 63 with Device

use of org.hl7.fhir.dstu3.model.Device in project udmi by faucetsdn.

the class CloudIotManager method registerDevice.

public boolean registerDevice(String deviceId, CloudDeviceSettings settings) {
    try {
        Preconditions.checkNotNull(cloudIotService, "CloudIoT service not initialized");
        Preconditions.checkNotNull(deviceMap, "deviceMap not initialized");
        Device device = deviceMap.get(deviceId);
        boolean isNewDevice = device == null;
        if (isNewDevice) {
            createDevice(deviceId, settings);
        } else {
            updateDevice(deviceId, settings, device);
        }
        writeDeviceConfig(deviceId, settings.config);
        return isNewDevice;
    } catch (Exception e) {
        throw new RuntimeException("While registering device " + deviceId, e);
    }
}
Also used : Device(com.google.api.services.cloudiot.v1.model.Device) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException)

Example 64 with Device

use of org.hl7.fhir.dstu3.model.Device in project udmi by faucetsdn.

the class CloudIotManager method blockDevice.

public void blockDevice(String deviceId, boolean blocked) {
    try {
        Device device = new Device();
        device.setBlocked(blocked);
        String path = getDevicePath(deviceId);
        cloudIotRegistries.devices().patch(path, device).setUpdateMask("blocked").execute();
    } catch (Exception e) {
        throw new RuntimeException(String.format("While (un)blocking device %s/%s=%s", registryId, deviceId, blocked), e);
    }
}
Also used : Device(com.google.api.services.cloudiot.v1.model.Device) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException)

Example 65 with Device

use of org.hl7.fhir.dstu3.model.Device in project udmi by faucetsdn.

the class CloudIotManager method updateDevice.

private void updateDevice(String deviceId, CloudDeviceSettings settings, Device oldDevice) {
    try {
        Device device = makeDevice(deviceId, settings, oldDevice).setId(null).setNumId(null);
        cloudIotRegistries.devices().patch(getDevicePath(deviceId), device).setUpdateMask(DEVICE_UPDATE_MASK).execute();
    } catch (Exception e) {
        throw new RuntimeException("Remote error patching device " + deviceId, e);
    }
}
Also used : Device(com.google.api.services.cloudiot.v1.model.Device) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException)

Aggregations

Device (com.google.api.services.cloudiot.v1.model.Device)21 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)13 JsonFactory (com.google.api.client.json.JsonFactory)13 CloudIot (com.google.api.services.cloudiot.v1.CloudIot)13 HttpCredentialsAdapter (com.google.auth.http.HttpCredentialsAdapter)13 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)13 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 Test (org.junit.jupiter.api.Test)9 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)7 Device (org.hl7.fhir.r4.model.Device)7 Practitioner (org.hl7.fhir.r4.model.Practitioner)7 Reference (org.hl7.fhir.r4.model.Reference)7 ArrayList (java.util.ArrayList)6 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)6 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)6 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 DeviceCredential (com.google.api.services.cloudiot.v1.model.DeviceCredential)5 PublicKeyCredential (com.google.api.services.cloudiot.v1.model.PublicKeyCredential)5 Coding (org.hl7.fhir.r4.model.Coding)5 Identifier (org.hl7.fhir.r4.model.Identifier)5