use of org.eclipse.hono.service.management.Id in project hono by eclipse.
the class AbstractDeviceManagementService method updateDevice.
@Override
public final Future<OperationResult<Id>> updateDevice(final String tenantId, final String deviceId, final Device device, final Optional<String> resourceVersion, final Span span) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(deviceId);
Objects.requireNonNull(device);
Objects.requireNonNull(resourceVersion);
Objects.requireNonNull(span);
return this.tenantInformationService.tenantExists(tenantId, span).compose(result -> result.isError() ? Future.failedFuture(ServiceInvocationException.create(tenantId, result.getStatus(), "tenant does not exist", null)) : processUpdateDevice(DeviceKey.from(result.getPayload(), deviceId), device, resourceVersion, span)).onSuccess(result -> NotificationEventBusSupport.sendNotification(vertx, new DeviceChangeNotification(LifecycleChange.UPDATE, tenantId, deviceId, Instant.now(), device.isEnabled()))).recover(t -> DeviceRegistryUtils.mapError(t, tenantId));
}
use of org.eclipse.hono.service.management.Id in project hono by eclipse.
the class AbstractDeviceManagementService method deleteDevicesOfTenant.
@Override
public final Future<Result<Void>> deleteDevicesOfTenant(final String tenantId, final Span span) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(span);
return this.tenantInformationService.tenantExists(tenantId, span).otherwise(t -> Result.from(ServiceInvocationException.extractStatusCode(t))).compose(result -> {
switch(result.getStatus()) {
case HttpURLConnection.HTTP_OK:
break;
case HttpURLConnection.HTTP_NOT_FOUND:
span.log("tenant does not exist (anymore)");
LOG.info("trying to delete devices of non-existing tenant [tenant-id: {}]", tenantId);
break;
default:
span.log(Map.of(Fields.EVENT, "could not determine tenant status", Tags.HTTP_STATUS.getKey(), result.getStatus()));
LOG.info("could not determine tenant status [tenant-id: {}, code: {}]", tenantId, result.getStatus());
}
return processDeleteDevicesOfTenant(tenantId, span);
}).onSuccess(result -> NotificationEventBusSupport.sendNotification(vertx, new AllDevicesOfTenantDeletedNotification(tenantId, Instant.now()))).recover(t -> DeviceRegistryUtils.mapError(t, tenantId));
}
Aggregations