use of org.eclipse.hono.deviceregistry.service.tenant.TenantInformationService in project hono by eclipse.
the class AbstractJdbcRegistryTest method startDevices.
@BeforeEach
void startDevices(final Vertx vertx) throws IOException, SQLException {
final var jdbc = resolveJdbcProperties();
try (var connection = DriverManager.getConnection(jdbc.getUrl(), jdbc.getUsername(), jdbc.getPassword());
var script = Files.newBufferedReader(EXAMPLE_SQL_BASE.resolve("02-create.devices.sql"))) {
// pre-create database
RunScript.execute(connection, script);
}
properties = new DeviceServiceProperties();
this.credentialsAdapter = new CredentialsServiceImpl(DeviceStores.adapterStoreFactory().createTable(vertx, TRACER, jdbc, Optional.empty(), Optional.empty(), Optional.empty()), properties);
this.registrationAdapter = new RegistrationServiceImpl(DeviceStores.adapterStoreFactory().createTable(vertx, TRACER, jdbc, Optional.empty(), Optional.empty(), Optional.empty()), new NoOpSchemaCreator());
this.credentialsManagement = new CredentialsManagementServiceImpl(vertx, new SpringBasedHonoPasswordEncoder(properties.getMaxBcryptCostfactor()), DeviceStores.managementStoreFactory().createTable(vertx, TRACER, jdbc, Optional.empty(), Optional.empty(), Optional.empty()), properties);
this.registrationManagement = new DeviceManagementServiceImpl(vertx, DeviceStores.managementStoreFactory().createTable(vertx, TRACER, jdbc, Optional.empty(), Optional.empty(), Optional.empty()), properties);
tenantInformationService = mock(TenantInformationService.class);
when(tenantInformationService.getTenant(anyString(), any())).thenReturn(Future.succeededFuture(new Tenant()));
when(tenantInformationService.tenantExists(anyString(), any())).thenAnswer(invocation -> {
return Future.succeededFuture(OperationResult.ok(HttpURLConnection.HTTP_OK, TenantKey.from(invocation.getArgument(0)), Optional.empty(), Optional.empty()));
});
registrationManagement.setTenantInformationService(tenantInformationService);
credentialsManagement.setTenantInformationService(tenantInformationService);
}
use of org.eclipse.hono.deviceregistry.service.tenant.TenantInformationService in project hono by eclipse.
the class ApplicationConfig method amqpServer.
/**
* Creates a new server for exposing the device registry's AMQP 1.0 based
* endpoints.
*
* @param tenantService The tenant service instance.
* @param registrationService The device registration service instance.
* @param credentialsService The credentials service instance.
* @param tenantManagementService The tenant management service instance.
* @param deviceManagementService The device management service instance.
* @param credentialsManagementService The credentials management service instance.
* @return The server.
*/
@Bean(name = BEAN_NAME_AMQP_SERVER)
@Scope("prototype")
@Profile(Profiles.PROFILE_REGISTRY_ADAPTER)
public DeviceRegistryAmqpServer amqpServer(@Autowired(required = false) final TenantService tenantService, final RegistrationServiceImpl registrationService, final CredentialsServiceImpl credentialsService, @Autowired(required = false) final TenantManagementService tenantManagementService, @Autowired(required = false) final DeviceManagementService deviceManagementService, @Autowired(required = false) final CredentialsManagementService credentialsManagementService) {
final DeviceRegistryAmqpServer amqpServer = new DeviceRegistryAmqpServer();
final TenantInformationService tenantInformationService = createAndApplyTenantInformationService(tenantManagementService, deviceManagementService, credentialsManagementService);
if (deviceManagementService != null) {
final var eventSenderProvider = eventSenderProvider();
final EdgeDeviceAutoProvisioner edgeDeviceAutoProvisioner = new EdgeDeviceAutoProvisioner(vertx(), deviceManagementService, eventSenderProvider, autoProvisionerConfigProperties(), tracer());
registrationService.setEdgeDeviceAutoProvisioner(edgeDeviceAutoProvisioner);
if (credentialsManagementService != null) {
final DeviceAndGatewayAutoProvisioner deviceAndGatewayAutoProvisioner = new DeviceAndGatewayAutoProvisioner(vertx(), deviceManagementService, credentialsManagementService, eventSenderProvider);
credentialsService.setDeviceAndGatewayAutoProvisioner(deviceAndGatewayAutoProvisioner);
}
}
registrationService.setTenantInformationService(tenantInformationService);
credentialsService.setTenantInformationService(tenantInformationService);
// add endpoints
final List<AbstractAmqpEndpoint<ServiceConfigProperties>> endpoints = new ArrayList<>();
Optional.ofNullable(tenantService).ifPresent(svc -> endpoints.add(new DelegatingTenantAmqpEndpoint<>(vertx(), svc)));
endpoints.add(new DelegatingRegistrationAmqpEndpoint<>(vertx(), registrationService));
endpoints.add(new DelegatingCredentialsAmqpEndpoint<>(vertx(), credentialsService));
endpoints.forEach(ep -> {
ep.setTracer(tracer());
ep.setConfiguration(amqpServerProperties());
amqpServer.addEndpoint(ep);
});
return amqpServer;
}
Aggregations