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);
});
}
Aggregations