Search in sources :

Example 16 with Result

use of org.eclipse.hono.service.management.Result in project hono by eclipse.

the class AbstractTenantManagementService method deleteTenant.

@Override
public final Future<Result<Void>> deleteTenant(final String tenantId, final Optional<String> resourceVersion, final Span span) {
    Objects.requireNonNull(tenantId);
    Objects.requireNonNull(resourceVersion);
    Objects.requireNonNull(span);
    return processDeleteTenant(tenantId, resourceVersion, span).onSuccess(result -> NotificationEventBusSupport.sendNotification(vertx, new TenantChangeNotification(LifecycleChange.DELETE, tenantId, Instant.now(), false))).recover(t -> DeviceRegistryUtils.mapError(t, tenantId));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) LifecycleChange(org.eclipse.hono.notification.deviceregistry.LifecycleChange) Filter(org.eclipse.hono.service.management.Filter) LoggerFactory(org.slf4j.LoggerFactory) ClientErrorException(org.eclipse.hono.client.ClientErrorException) Tenant(org.eclipse.hono.service.management.tenant.Tenant) Sort(org.eclipse.hono.service.management.Sort) SearchResult(org.eclipse.hono.service.management.SearchResult) TenantManagementService(org.eclipse.hono.service.management.tenant.TenantManagementService) TracingHelper(org.eclipse.hono.tracing.TracingHelper) TenantChangeNotification(org.eclipse.hono.notification.deviceregistry.TenantChangeNotification) Logger(org.slf4j.Logger) Promise(io.vertx.core.Promise) TenantWithId(org.eclipse.hono.service.management.tenant.TenantWithId) Vertx(io.vertx.core.Vertx) ServerErrorException(org.eclipse.hono.client.ServerErrorException) 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) TenantChangeNotification(org.eclipse.hono.notification.deviceregistry.TenantChangeNotification)

Example 17 with Result

use of org.eclipse.hono.service.management.Result 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)

Example 18 with Result

use of org.eclipse.hono.service.management.Result 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));
}
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) AllDevicesOfTenantDeletedNotification(org.eclipse.hono.notification.deviceregistry.AllDevicesOfTenantDeletedNotification)

Aggregations

Future (io.vertx.core.Future)18 HttpURLConnection (java.net.HttpURLConnection)18 Optional (java.util.Optional)18 OperationResult (org.eclipse.hono.service.management.OperationResult)18 Result (org.eclipse.hono.service.management.Result)18 Vertx (io.vertx.core.Vertx)17 Id (org.eclipse.hono.service.management.Id)17 Span (io.opentracing.Span)15 NotificationEventBusSupport (org.eclipse.hono.notification.NotificationEventBusSupport)14 LifecycleChange (org.eclipse.hono.notification.deviceregistry.LifecycleChange)14 Truth.assertThat (com.google.common.truth.Truth.assertThat)11 VertxExtension (io.vertx.junit5.VertxExtension)11 VertxTestContext (io.vertx.junit5.VertxTestContext)11 List (java.util.List)11 BeforeEach (org.junit.jupiter.api.BeforeEach)11 Test (org.junit.jupiter.api.Test)11 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)11 ArgumentCaptor (org.mockito.ArgumentCaptor)11 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)11 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)11