in server/src/main/java/com/epam/aidial/core/server/service/ApplicationService.java [516:568]
private Void launchApplication(ProxyContext context, ResourceDescriptor resource) {
// right now there is no lock watchdog mechanism
// this lock can expire before this operation is finished
// for extra safety the controller timeout is less than lock timeout
try (LockService.Lock lock = lockService.tryLock(deploymentLockKey(resource))) {
if (lock == null) {
throw new IllegalStateException("Application function is locked");
}
Application application = getApplication(resource).getValue();
Application.Function function = application.getFunction();
if (function == null) {
throw new IllegalStateException("Application has no function");
}
if (function.getStatus() != Application.Function.Status.DEPLOYING) {
throw new IllegalStateException("Application is not starting");
}
// for public/review application source folder is equal to target folder
// source files are copied to read-only deployment bucket for such applications
if (!isPublicOrReview(resource)) {
copyFolder(function.getSourceFolder(), function.getTargetFolder(), false);
}
controller.createApplicationImage(context, function);
String endpoint = controller.createApplicationDeployment(context, function);
resourceService.computeResource(resource, json -> {
Application existing = ProxyUtil.convertToObject(json, Application.class);
if (existing == null || !Objects.equals(existing.getFunction(), application.getFunction())) {
throw new IllegalStateException("Application function has been updated");
}
function.setStatus(Application.Function.Status.DEPLOYED);
existing.setFunction(function);
existing.setEndpoint(buildMapping(endpoint, function.getMapping().getChatCompletion()));
existing.getFeatures().setRateEndpoint(buildMapping(endpoint, function.getMapping().getRate()));
existing.getFeatures().setTokenizeEndpoint(buildMapping(endpoint, function.getMapping().getTokenize()));
existing.getFeatures().setTruncatePromptEndpoint(buildMapping(endpoint, function.getMapping().getTruncatePrompt()));
existing.getFeatures().setConfigurationEndpoint(buildMapping(endpoint, function.getMapping().getConfiguration()));
return ProxyUtil.convertToString(existing);
});
pendingApplications.remove(resource.getUrl());
return null;
} catch (Throwable error) {
log.warn("Failed to launch application: {}", resource.getUrl(), error);
throw error;
}
}