Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-11-06 06:12:13 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-11-06 06:12:13 +0300
commitae4e6f370a477782f19008717449047b2d0fb254 (patch)
treea3dda41879e8a5c070592b52fc0a7250ec9b307b /lib
parent9cc2aa99c032c8b813ab1bfc439a56d39d83e679 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities/ml/mlflow/model_versions/responses/get.rb17
-rw-r--r--lib/api/entities/ml/mlflow/model_versions/types/model_version.rb85
-rw-r--r--lib/api/entities/ml/mlflow/model_versions/types/model_version_tag.rb18
-rw-r--r--lib/api/helpers.rb8
-rw-r--r--lib/api/ml/mlflow/api_helpers.rb4
-rw-r--r--lib/api/ml/mlflow/entrypoint.rb1
-rw-r--r--lib/api/ml/mlflow/model_versions.rb32
-rw-r--r--lib/api/project_repository_storage_moves.rb10
-rw-r--r--lib/api/projects.rb1
-rw-r--r--lib/api/users.rb10
10 files changed, 182 insertions, 4 deletions
diff --git a/lib/api/entities/ml/mlflow/model_versions/responses/get.rb b/lib/api/entities/ml/mlflow/model_versions/responses/get.rb
new file mode 100644
index 00000000000..14baae03644
--- /dev/null
+++ b/lib/api/entities/ml/mlflow/model_versions/responses/get.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ module Ml
+ module Mlflow
+ module ModelVersions
+ module Responses
+ class Get < Grape::Entity
+ expose :model_version, with: Types::ModelVersion
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/entities/ml/mlflow/model_versions/types/model_version.rb b/lib/api/entities/ml/mlflow/model_versions/types/model_version.rb
new file mode 100644
index 00000000000..407158521f7
--- /dev/null
+++ b/lib/api/entities/ml/mlflow/model_versions/types/model_version.rb
@@ -0,0 +1,85 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ module Ml
+ module Mlflow
+ module ModelVersions
+ module Types
+ class ModelVersion < Grape::Entity
+ expose :name
+ expose :version
+ expose :creation_timestamp, documentation: { type: Integer }
+ expose :last_updated_timestamp, documentation: { type: Integer }
+ expose :user_id
+ expose :current_stage
+ expose :description
+ expose :source
+ expose :run_id
+ expose :status
+ expose :status_message
+ expose :metadata
+ expose :run_link
+ expose :aliases, documentation: { is_array: true, type: String }
+
+ private
+
+ def name
+ object.model.name
+ end
+
+ def creation_timestamp
+ object.created_at.to_i
+ end
+
+ def last_updated_timestamp
+ object.updated_at.to_i
+ end
+
+ def user_id
+ nil
+ end
+
+ def current_stage
+ "development"
+ end
+
+ def description
+ ""
+ end
+
+ def source
+ model_name = object.model.name
+ "api/v4/projects/(id)/packages/ml_models/#{model_name}/model_version/"
+ end
+
+ def run_id
+ ""
+ end
+
+ def status
+ "READY"
+ end
+
+ def status_message
+ ""
+ end
+
+ def metadata
+ []
+ end
+
+ def run_link
+ ""
+ end
+
+ def aliases
+ []
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/entities/ml/mlflow/model_versions/types/model_version_tag.rb b/lib/api/entities/ml/mlflow/model_versions/types/model_version_tag.rb
new file mode 100644
index 00000000000..f5ad3bf3fb9
--- /dev/null
+++ b/lib/api/entities/ml/mlflow/model_versions/types/model_version_tag.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ module Ml
+ module Mlflow
+ module ModelVersions
+ module Types
+ class ModelVersionTag < Grape::Entity
+ expose :key
+ expose :value
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index f17474394e2..bb94d5d14d0 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -141,7 +141,7 @@ module API
def find_project(id)
return unless id
- projects = Project.without_deleted.not_hidden
+ projects = find_project_scopes
if id.is_a?(Integer) || id =~ INTEGER_ID_REGEX
projects.find_by(id: id)
@@ -151,6 +151,11 @@ module API
end
# rubocop: enable CodeReuse/ActiveRecord
+ # Can be overriden by API endpoints
+ def find_project_scopes
+ Project.without_deleted.not_hidden
+ end
+
def find_project!(id)
project = find_project(id)
@@ -768,6 +773,7 @@ module API
finder_params[:id_before] = sanitize_id_param(params[:id_before]) if params[:id_before]
finder_params[:updated_after] = declared_params[:updated_after] if declared_params[:updated_after]
finder_params[:updated_before] = declared_params[:updated_before] if declared_params[:updated_before]
+ finder_params[:include_pending_delete] = declared_params[:include_pending_delete] if declared_params[:include_pending_delete]
finder_params
end
diff --git a/lib/api/ml/mlflow/api_helpers.rb b/lib/api/ml/mlflow/api_helpers.rb
index 19ac0dbba1b..a180f87929b 100644
--- a/lib/api/ml/mlflow/api_helpers.rb
+++ b/lib/api/ml/mlflow/api_helpers.rb
@@ -12,6 +12,10 @@ module API
unauthorized! unless can?(current_user, :write_model_experiments, user_project)
end
+ def check_api_model_registry_read!
+ not_found! unless can?(current_user, :read_model_registry, user_project)
+ end
+
def resource_not_found!
render_structured_api_error!({ error_code: 'RESOURCE_DOES_NOT_EXIST' }, 404)
end
diff --git a/lib/api/ml/mlflow/entrypoint.rb b/lib/api/ml/mlflow/entrypoint.rb
index 9eaef90b7ac..7157d2a03f6 100644
--- a/lib/api/ml/mlflow/entrypoint.rb
+++ b/lib/api/ml/mlflow/entrypoint.rb
@@ -41,6 +41,7 @@ module API
end
namespace MLFLOW_API_PREFIX do
mount ::API::Ml::Mlflow::Experiments
+ mount ::API::Ml::Mlflow::ModelVersions
mount ::API::Ml::Mlflow::Runs
mount ::API::Ml::Mlflow::RegisteredModels
end
diff --git a/lib/api/ml/mlflow/model_versions.rb b/lib/api/ml/mlflow/model_versions.rb
new file mode 100644
index 00000000000..989b79e5774
--- /dev/null
+++ b/lib/api/ml/mlflow/model_versions.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module API
+ module Ml
+ module Mlflow
+ class ModelVersions < ::API::Base
+ feature_category :mlops
+
+ resource :model_versions do
+ desc 'Fetch model version by name and version' do
+ success Entities::Ml::Mlflow::ModelVersions::Responses::Get
+ detail 'https://mlflow.org/docs/2.6.0/rest-api.html#get-modelversion'
+ end
+ params do
+ requires :name, type: String, desc: 'Model version name'
+ requires :version, type: String, desc: 'Model version number'
+ end
+ get 'get', urgency: :low do
+ check_api_model_registry_read!
+ resource_not_found! unless params[:name] && params[:version]
+ model_version = ::Ml::ModelVersions::GetModelVersionService.new(
+ user_project, params[:name], params[:version]
+ ).execute
+ resource_not_found! unless model_version
+ response = { model_version: model_version }
+ present response, with: Entities::Ml::Mlflow::ModelVersions::Responses::Get
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/project_repository_storage_moves.rb b/lib/api/project_repository_storage_moves.rb
index 5777b8754e7..b79348c87bf 100644
--- a/lib/api/project_repository_storage_moves.rb
+++ b/lib/api/project_repository_storage_moves.rb
@@ -8,6 +8,16 @@ module API
feature_category :gitaly
+ helpers do
+ extend ::Gitlab::Utils::Override
+
+ # Allow to move projects in hidden/pending_delete state
+ override :find_project_scopes
+ def find_project_scopes
+ Project
+ end
+ end
+
resource :project_repository_storage_moves do
desc 'Get a list of all project repository storage moves' do
detail 'This feature was introduced in GitLab 13.0.'
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index d2e297f4213..3b80fd125ca 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -159,6 +159,7 @@ module API
optional :topic_id, type: Integer, desc: 'Limit results to projects with the assigned topic given by the topic ID'
optional :updated_before, type: DateTime, desc: 'Return projects updated before the specified datetime. Format: ISO 8601 YYYY-MM-DDTHH:MM:SSZ'
optional :updated_after, type: DateTime, desc: 'Return projects updated after the specified datetime. Format: ISO 8601 YYYY-MM-DDTHH:MM:SSZ'
+ optional :include_pending_delete, type: Boolean, desc: 'Include projects in pending delete state. Can only be set by admins'
use :optional_filter_params_ee
end
diff --git a/lib/api/users.rb b/lib/api/users.rb
index dd9cb2ee019..5fa6d50581b 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -34,10 +34,14 @@ module API
helpers do
# rubocop: disable CodeReuse/ActiveRecord
def reorder_users(users)
- if params[:order_by] && params[:sort]
- users.reorder(order_options_with_tie_breaker)
- else
+ # Users#search orders by exact matches and handles pagination,
+ # so we should prioritize that.
+ if params[:search]
users
+ else
+ # Note that params[:order_by] and params[:sort] will always be present and
+ # default to "id" and "desc" as defined in `sort_params`.
+ users.reorder(order_options_with_tie_breaker)
end
end
# rubocop: enable CodeReuse/ActiveRecord