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);
}
}
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());
}
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);
}
}
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);
}
}
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);
}
}
Aggregations