public static StatusResponse handleRegister()

in frontend/server/src/main/java/org/pytorch/serve/util/ApiUtils.java [151:214]


    public static StatusResponse handleRegister(
            String modelUrl,
            String modelName,
            Manifest.RuntimeType runtimeType,
            String handler,
            int batchSize,
            int maxBatchDelay,
            int responseTimeout,
            int initialWorkers,
            boolean isSync,
            boolean isWorkflowModel,
            boolean s3SseKms)
            throws ModelException, ExecutionException, InterruptedException,
                    DownloadArchiveException {

        ModelManager modelManager = ModelManager.getInstance();
        final ModelArchive archive;
        try {
            archive =
                    modelManager.registerModel(
                            modelUrl,
                            modelName,
                            runtimeType,
                            handler,
                            batchSize,
                            maxBatchDelay,
                            responseTimeout,
                            null,
                            false,
                            isWorkflowModel,
                            s3SseKms);
        } catch (FileAlreadyExistsException e) {
            throw new InternalServerException(
                    "Model file already exists " + FilenameUtils.getName(modelUrl), e);
        } catch (IOException | InterruptedException e) {
            throw new InternalServerException("Failed to save model: " + modelUrl, e);
        }

        modelName = archive.getModelName();
        if (initialWorkers <= 0) {
            final String msg =
                    "Model \""
                            + modelName
                            + "\" Version: "
                            + archive.getModelVersion()
                            + " registered with 0 initial workers. Use scale workers API to add workers for the model.";
            if (!isWorkflowModel) {
                SnapshotManager.getInstance().saveSnapshot();
            }
            return new StatusResponse(msg, HttpURLConnection.HTTP_OK);
        }

        return ApiUtils.updateModelWorkers(
                modelName,
                archive.getModelVersion(),
                initialWorkers,
                initialWorkers,
                isSync,
                true,
                f -> {
                    modelManager.unregisterModel(archive.getModelName(), archive.getModelVersion());
                    return null;
                });
    }