use of io.opentracing.Span in project hono by eclipse.
the class AbstractTenantManagementServiceTest method testNotificationOnDeleteTenant.
/**
* Verifies that {@link AbstractTenantManagementService#deleteTenant(String, Optional, Span)} publishes the expected
* notification.
*
* @param context The vert.x test context.
*/
@Test
public void testNotificationOnDeleteTenant(final VertxTestContext context) {
final var notificationArgumentCaptor = ArgumentCaptor.forClass(TenantChangeNotification.class);
tenantManagementService.createTenant(Optional.of(DEFAULT_TENANT_ID), new Tenant(), SPAN).compose(result -> tenantManagementService.deleteTenant(DEFAULT_TENANT_ID, Optional.empty(), SPAN)).onComplete(context.succeeding(result -> {
context.verify(() -> {
verify(eventBus, times(2)).publish(eq(NotificationEventBusSupport.getEventBusAddress(TenantChangeNotification.TYPE)), notificationArgumentCaptor.capture(), any());
assertThat(notificationArgumentCaptor.getAllValues().size()).isEqualTo(2);
final var notification = notificationArgumentCaptor.getValue();
assertThat(notification).isNotNull();
assertThat(notification.getChange()).isEqualTo(LifecycleChange.DELETE);
assertThat(notification.getTenantId()).isEqualTo(DEFAULT_TENANT_ID);
assertThat(notification.getCreationTime()).isNotNull();
assertThat(notification.isEnabled()).isFalse();
});
context.completeNow();
}));
}
use of io.opentracing.Span in project hono by eclipse.
the class DelegatingDeviceManagementHttpEndpoint method doSearchDevices.
private void doSearchDevices(final RoutingContext ctx) {
final Span span = TracingHelper.buildServerChildSpan(tracer, TracingHandler.serverSpanContext(ctx), SPAN_NAME_SEARCH_DEVICES, getClass().getSimpleName()).start();
final String tenantId = getTenantParam(ctx);
final Future<Integer> pageSize = getRequestParameter(ctx, RegistryManagementConstants.PARAM_PAGE_SIZE, DEFAULT_PAGE_SIZE, CONVERTER_INT, value -> value >= MIN_PAGE_SIZE && value <= MAX_PAGE_SIZE);
final Future<Integer> pageOffset = getRequestParameter(ctx, RegistryManagementConstants.PARAM_PAGE_OFFSET, DEFAULT_PAGE_OFFSET, CONVERTER_INT, value -> value >= MIN_PAGE_OFFSET);
final Future<List<Filter>> filters = decodeJsonFromRequestParameter(ctx, RegistryManagementConstants.PARAM_FILTER_JSON, Filter.class);
final Future<List<Sort>> sortOptions = decodeJsonFromRequestParameter(ctx, RegistryManagementConstants.PARAM_SORT_JSON, Sort.class);
CompositeFuture.all(pageSize, pageOffset, filters, sortOptions).onSuccess(ok -> TracingHelper.TAG_TENANT_ID.set(span, tenantId)).compose(ok -> getService().searchDevices(tenantId, pageSize.result(), pageOffset.result(), filters.result(), sortOptions.result(), span)).onSuccess(operationResult -> writeResponse(ctx, operationResult, span)).onFailure(t -> failRequest(ctx, t, span)).onComplete(s -> span.finish());
}
use of io.opentracing.Span in project hono by eclipse.
the class DelegatingDeviceManagementHttpEndpoint method doCreateDevice.
private void doCreateDevice(final RoutingContext ctx) {
final Span span = TracingHelper.buildServerChildSpan(tracer, TracingHandler.serverSpanContext(ctx), SPAN_NAME_CREATE_DEVICE, getClass().getSimpleName()).start();
final Future<String> tenantId = getRequestParameter(ctx, PARAM_TENANT_ID, getPredicate(config.getTenantIdPattern(), false));
final Future<String> deviceId = getRequestParameter(ctx, PARAM_DEVICE_ID, getPredicate(config.getDeviceIdPattern(), true));
final Future<Device> device = fromPayload(ctx);
CompositeFuture.all(tenantId, deviceId, device).compose(ok -> {
final Optional<String> did = Optional.ofNullable(deviceId.result());
TracingHelper.TAG_TENANT_ID.set(span, tenantId.result());
did.ifPresent(s -> TracingHelper.TAG_DEVICE_ID.set(span, s));
logger.debug("creating device [tenant: {}, device-id: {}]", tenantId.result(), did.orElse("<auto>"));
return getService().createDevice(tenantId.result(), did, device.result(), span);
}).onSuccess(operationResult -> writeResponse(ctx, operationResult, (responseHeaders, status) -> {
Optional.ofNullable(operationResult.getPayload()).map(Id::getId).ifPresent(id -> responseHeaders.set(HttpHeaders.LOCATION, String.format("/%s/%s/%s", getName(), tenantId.result(), id)));
}, span)).onFailure(t -> failRequest(ctx, t, span)).onComplete(s -> span.finish());
}
use of io.opentracing.Span in project hono by eclipse.
the class DelegatingCredentialsManagementHttpEndpoint method updateCredentials.
private void updateCredentials(final RoutingContext ctx) {
final Span span = TracingHelper.buildServerChildSpan(tracer, TracingHandler.serverSpanContext(ctx), SPAN_NAME_UPDATE_CREDENTIALS, getClass().getSimpleName()).start();
final Future<String> tenantId = getRequestParameter(ctx, PARAM_TENANT_ID, getPredicate(config.getTenantIdPattern(), false));
final Future<String> deviceId = getRequestParameter(ctx, PARAM_DEVICE_ID, getPredicate(config.getDeviceIdPattern(), false));
final Future<List<CommonCredential>> updatedCredentials = fromPayload(ctx);
CompositeFuture.all(tenantId, deviceId, updatedCredentials).compose(ok -> {
TracingHelper.setDeviceTags(span, tenantId.result(), deviceId.result());
logger.debug("updating {} credentials [tenant: {}, device-id: {}]", updatedCredentials.result().size(), tenantId.result(), deviceId.result());
final Optional<String> resourceVersion = Optional.ofNullable(ctx.get(KEY_RESOURCE_VERSION));
return getService().updateCredentials(tenantId.result(), deviceId.result(), updatedCredentials.result(), resourceVersion, span);
}).onSuccess(operationResult -> writeResponse(ctx, operationResult, span)).onFailure(t -> failRequest(ctx, t, span)).onComplete(s -> span.finish());
}
use of io.opentracing.Span in project hono by eclipse.
the class AbstractDeviceManagementService method deleteDevice.
@Override
public final Future<Result<Void>> deleteDevice(final String tenantId, final String deviceId, final Optional<String> resourceVersion, final Span span) {
Objects.requireNonNull(tenantId);
Objects.requireNonNull(deviceId);
Objects.requireNonNull(resourceVersion);
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 device of non-existing tenant [tenant-id: {}, device-id: {}]", tenantId, deviceId);
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 processDeleteDevice(DeviceKey.from(tenantId, deviceId), resourceVersion, span);
}).onSuccess(result -> NotificationEventBusSupport.sendNotification(vertx, new DeviceChangeNotification(LifecycleChange.DELETE, tenantId, deviceId, Instant.now(), false))).recover(t -> DeviceRegistryUtils.mapError(t, tenantId));
}
Aggregations