in server/src/main/java/com/epam/aidial/core/server/AiDial.java [94:160]
void start() throws Exception {
System.setProperty("io.opentelemetry.context.contextStorageProvider", "io.vertx.tracing.opentelemetry.VertxContextStorageProvider");
try {
settings = (settings == null) ? settings() : settings;
VertxOptions vertxOptions = new VertxOptions(settings("vertx"));
setupMetrics(vertxOptions);
setupTracing(vertxOptions);
vertx = Vertx.vertx(vertxOptions);
client = vertx.createHttpClient(new HttpClientOptions(settings("client")));
LogStore logStore = new GfLogStore(vertx);
UpstreamRouteProvider upstreamRouteProvider = new UpstreamRouteProvider(vertx, Random::new);
if (accessTokenValidator == null) {
accessTokenValidator = new AccessTokenValidator(settings("identityProviders"), vertx, client);
}
if (storage == null) {
Storage storageConfig = Json.decodeValue(settings("storage").toBuffer(), Storage.class);
storage = new BlobStorage(storageConfig);
}
EncryptionService encryptionService = new EncryptionService(settings("encryption"));
redis = CacheClientFactory.create(toJsonNode(settings("redis")));
LockService lockService = new LockService(redis, storage.getPrefix());
TimerService timerService = new VertxTimerService(vertx);
ResourceService.Settings resourceServiceSettings = Json.decodeValue(settings("resources").toBuffer(), ResourceService.Settings.class);
resourceService = new ResourceService(timerService, redis, storage, lockService, resourceServiceSettings, storage.getPrefix());
InvitationService invitationService = new InvitationService(resourceService, encryptionService, settings("invitations"));
ApiKeyStore apiKeyStore = new ApiKeyStore(resourceService, vertx);
ConfigStore configStore = new FileConfigStore(vertx, settings("config"), apiKeyStore);
ApplicationOperatorService operatorService = new ApplicationOperatorService(client, settings("applications"));
ApplicationService applicationService = new ApplicationService(vertx, redis, encryptionService,
resourceService, lockService, operatorService, generator, settings("applications"));
ShareService shareService = new ShareService(resourceService, invitationService, encryptionService, applicationService, configStore);
RuleService ruleService = new RuleService(resourceService);
AccessService accessService = new AccessService(encryptionService, shareService, ruleService, settings("access"));
NotificationService notificationService = new NotificationService(resourceService, encryptionService);
ResourceOperationService resourceOperationService = new ResourceOperationService(applicationService,
resourceService, invitationService, shareService, lockService);
PublicationService publicationService = new PublicationService(encryptionService, resourceService, accessService,
ruleService, notificationService, applicationService, resourceOperationService, generator, clock);
RateLimiter rateLimiter = new RateLimiter(vertx, resourceService);
CodeInterpreterService codeInterpreterService = new CodeInterpreterService(vertx, redis, resourceService,
accessService, encryptionService, operatorService, generator, settings("codeInterpreter"));
TokenStatsTracker tokenStatsTracker = new TokenStatsTracker(vertx, resourceService);
HeartbeatService heartbeatService = new HeartbeatService(
vertx, settings("resources").getLong("heartbeatPeriod"));
proxy = new Proxy(vertx, client, configStore, logStore,
rateLimiter, upstreamRouteProvider, accessTokenValidator,
storage, encryptionService, apiKeyStore, tokenStatsTracker, resourceService, invitationService,
shareService, publicationService, accessService, lockService, resourceOperationService, ruleService,
notificationService, applicationService, codeInterpreterService, heartbeatService, version());
server = vertx.createHttpServer(new HttpServerOptions(settings("server"))).requestHandler(proxy);
open(server, HttpServer::listen);
log.info("Proxy started on {}", server.actualPort());
} catch (Throwable e) {
log.error("Proxy failed to start:", e);
stop();
throw e;
}
}