Search in sources :

Example 11 with DeviceChangeNotification

use of org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification 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));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) LifecycleChange(org.eclipse.hono.notification.deviceregistry.LifecycleChange) DeviceChangeNotification(org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification) Filter(org.eclipse.hono.service.management.Filter) LoggerFactory(org.slf4j.LoggerFactory) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Tags(io.opentracing.tag.Tags) DeviceManagementService(org.eclipse.hono.service.management.device.DeviceManagementService) Sort(org.eclipse.hono.service.management.Sort) SearchResult(org.eclipse.hono.service.management.SearchResult) Map(java.util.Map) Fields(io.opentracing.log.Fields) TenantInformationService(org.eclipse.hono.deviceregistry.service.tenant.TenantInformationService) AllDevicesOfTenantDeletedNotification(org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification) NoopTenantInformationService(org.eclipse.hono.deviceregistry.service.tenant.NoopTenantInformationService) Device(org.eclipse.hono.service.management.device.Device) DeviceWithId(org.eclipse.hono.service.management.device.DeviceWithId) Logger(org.slf4j.Logger) Vertx(io.vertx.core.Vertx) ServerErrorException(org.eclipse.hono.client.ServerErrorException) UUID(java.util.UUID) Instant(java.time.Instant) Result(org.eclipse.hono.service.management.Result) Future(io.vertx.core.Future) Objects(java.util.Objects) List(java.util.List) Optional(java.util.Optional) OperationResult(org.eclipse.hono.service.management.OperationResult) Span(io.opentracing.Span) NotificationEventBusSupport(org.eclipse.hono.notification.NotificationEventBusSupport) DeviceRegistryUtils(org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils) Id(org.eclipse.hono.service.management.Id) DeviceChangeNotification(org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification)

Aggregations

DeviceChangeNotification (org.eclipse.hono.notification.deviceregistry.DeviceChangeNotification)11 Instant (java.time.Instant)8 AllDevicesOfTenantDeletedNotification (org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification)8 Test (org.junit.jupiter.api.Test)8 Future (io.vertx.core.Future)7 Vertx (io.vertx.core.Vertx)7 LifecycleChange (org.eclipse.hono.notification.deviceregistry.LifecycleChange)7 Span (io.opentracing.Span)6 HttpURLConnection (java.net.HttpURLConnection)6 NotificationEventBusSupport (org.eclipse.hono.notification.NotificationEventBusSupport)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 Tracer (io.opentracing.Tracer)4 EventBus (io.vertx.core.eventbus.EventBus)4 JsonObject (io.vertx.core.json.JsonObject)4 Cache (com.github.benmanes.caffeine.cache.Cache)3 Tags (io.opentracing.tag.Tags)3 Handler (io.vertx.core.Handler)3 Timeout (io.vertx.junit5.Timeout)3 VertxExtension (io.vertx.junit5.VertxExtension)3 VertxTestContext (io.vertx.junit5.VertxTestContext)3