Search in sources :

Example 1 with EventConstants

use of org.eclipse.hono.util.EventConstants in project hono by eclipse.

the class AbstractAutoProvisioningEventSender method sendAutoProvisioningEvent.

/**
 * Send an auto-provisioning event with content type
 * {@value EventConstants#CONTENT_TYPE_DEVICE_PROVISIONING_NOTIFICATION}.
 *
 * @param tenantId The tenant identifier.
 * @param tenant The tenant information.
 * @param deviceId The device identifier.
 * @param gatewayId The gateway identifier if an edge device is being auto-provisioned.
 * @param span The active OpenTracing span for this operation. It is not to be closed in this method! An
 *            implementation should log (error) events on this span and it may set tags and use this span as the
 *            parent for any spans created in this method.
 * @return A future indicating the outcome of the operation. The future will be succeeded if the auto-provisioning
 *         event is sent successfully.
 * @throws NullPointerException if any of the parameters except gateway id is {@code null}.
 * @see "https://www.eclipse.org/hono/docs/api/event/#device-provisioning-notification"
 */
protected Future<Void> sendAutoProvisioningEvent(final String tenantId, final Tenant tenant, final String deviceId, final String gatewayId, final Span span) {
    Objects.requireNonNull(tenantId);
    Objects.requireNonNull(deviceId);
    Objects.requireNonNull(span);
    // TODO to remove once able to send events without providing an argument of type TenantObject
    final TenantObject tenantConfig = DeviceRegistryUtils.convertTenant(tenantId, tenant).mapTo(TenantObject.class);
    final EventSender eventSender = eventSenderProvider.getClient(tenantConfig);
    return eventSender.sendEvent(tenantConfig, new RegistrationAssertion(deviceId), EventConstants.CONTENT_TYPE_DEVICE_PROVISIONING_NOTIFICATION, null, assembleAutoProvisioningEventProperties(tenantId, gatewayId), span.context()).onSuccess(ok -> {
        span.log("sent auto-provisioning notification");
        LOG.debug("sent auto-provisioning notification [tenant-id: {}, device-id: {}, gateway-id: {}]", tenantId, deviceId, gatewayId);
    }).onFailure(t -> {
        TracingHelper.logError(span, "error sending auto-provisioning notification", t);
        LOG.warn("error sending auto-provisioning notification [tenant-id: {}, device-id: {}, gateway-id: {}]", tenantId, deviceId, gatewayId);
    });
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Lifecycle(org.eclipse.hono.util.Lifecycle) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ServiceInvocationException(org.eclipse.hono.client.ServiceInvocationException) Constants(org.eclipse.hono.util.Constants) Tags(io.opentracing.tag.Tags) Tenant(org.eclipse.hono.service.management.tenant.Tenant) DeviceManagementService(org.eclipse.hono.service.management.device.DeviceManagementService) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) TracingHelper(org.eclipse.hono.tracing.TracingHelper) Device(org.eclipse.hono.service.management.device.Device) Logger(org.slf4j.Logger) EventSender(org.eclipse.hono.client.telemetry.EventSender) MessagingClientProvider(org.eclipse.hono.client.util.MessagingClientProvider) Vertx(io.vertx.core.Vertx) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) DeviceStatus(org.eclipse.hono.service.management.device.DeviceStatus) MessageHelper(org.eclipse.hono.util.MessageHelper) EventConstants(org.eclipse.hono.util.EventConstants) Future(io.vertx.core.Future) TenantObject(org.eclipse.hono.util.TenantObject) Objects(java.util.Objects) Optional(java.util.Optional) Span(io.opentracing.Span) DeviceRegistryUtils(org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils) TenantObject(org.eclipse.hono.util.TenantObject) RegistrationAssertion(org.eclipse.hono.util.RegistrationAssertion) EventSender(org.eclipse.hono.client.telemetry.EventSender)

Aggregations

Span (io.opentracing.Span)1 Tags (io.opentracing.tag.Tags)1 Future (io.vertx.core.Future)1 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 HttpURLConnection (java.net.HttpURLConnection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ServiceInvocationException (org.eclipse.hono.client.ServiceInvocationException)1 EventSender (org.eclipse.hono.client.telemetry.EventSender)1 MessagingClientProvider (org.eclipse.hono.client.util.MessagingClientProvider)1 DeviceRegistryUtils (org.eclipse.hono.deviceregistry.util.DeviceRegistryUtils)1 Device (org.eclipse.hono.service.management.device.Device)1 DeviceManagementService (org.eclipse.hono.service.management.device.DeviceManagementService)1 DeviceStatus (org.eclipse.hono.service.management.device.DeviceStatus)1 Tenant (org.eclipse.hono.service.management.tenant.Tenant)1 TracingHelper (org.eclipse.hono.tracing.TracingHelper)1