Commit ee618868 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Rémy Coutable

Separate geo, subs and npm entities into own class files

parent 9b144771
---
title: Separate npm, subs and geo entities into own class file
merge_request: 26674
author: Rajendra Kadam
type: added
......@@ -492,198 +492,6 @@ module EE
end
end
class GeoNodeStatus < Grape::Entity
include ::API::Helpers::RelatedResourcesHelpers
include ActionView::Helpers::NumberHelper
expose :geo_node_id
expose :healthy?, as: :healthy
expose :health do |node|
node.healthy? ? 'Healthy' : node.health
end
expose :health_status
expose :missing_oauth_application
expose :attachments_count
expose :attachments_synced_count
expose :attachments_failed_count
expose :attachments_synced_missing_on_primary_count
expose :attachments_synced_in_percentage do |node|
number_to_percentage(node.attachments_synced_in_percentage, precision: 2)
end
expose :db_replication_lag_seconds
expose :lfs_objects_count
expose :lfs_objects_synced_count
expose :lfs_objects_failed_count
expose :lfs_objects_synced_missing_on_primary_count
expose :lfs_objects_synced_in_percentage do |node|
number_to_percentage(node.lfs_objects_synced_in_percentage, precision: 2)
end
expose :job_artifacts_count
expose :job_artifacts_synced_count
expose :job_artifacts_failed_count
expose :job_artifacts_synced_missing_on_primary_count
expose :job_artifacts_synced_in_percentage do |node|
number_to_percentage(node.job_artifacts_synced_in_percentage, precision: 2)
end
expose :container_repositories_count
expose :container_repositories_synced_count
expose :container_repositories_failed_count
expose :container_repositories_synced_in_percentage do |node|
number_to_percentage(node.container_repositories_synced_in_percentage, precision: 2)
end
expose :design_repositories_count
expose :design_repositories_synced_count
expose :design_repositories_failed_count
expose :design_repositories_synced_in_percentage do |node|
number_to_percentage(node.design_repositories_synced_in_percentage, precision: 2)
end
expose :projects_count
expose :repositories_failed_count
expose :repositories_synced_count
expose :repositories_synced_in_percentage do |node|
number_to_percentage(node.repositories_synced_in_percentage, precision: 2)
end
expose :wikis_failed_count
expose :wikis_synced_count
expose :wikis_synced_in_percentage do |node|
number_to_percentage(node.wikis_synced_in_percentage, precision: 2)
end
expose :repository_verification_enabled
expose :repositories_checksummed_count
expose :repositories_checksum_failed_count
expose :repositories_checksummed_in_percentage do |node|
number_to_percentage(node.repositories_checksummed_in_percentage, precision: 2)
end
expose :wikis_checksummed_count
expose :wikis_checksum_failed_count
expose :wikis_checksummed_in_percentage do |node|
number_to_percentage(node.wikis_checksummed_in_percentage, precision: 2)
end
expose :repositories_verification_failed_count
expose :repositories_verified_count
expose :repositories_verified_in_percentage do |node|
number_to_percentage(node.repositories_verified_in_percentage, precision: 2)
end
expose :repositories_checksum_mismatch_count
expose :wikis_verification_failed_count
expose :wikis_verified_count
expose :wikis_verified_in_percentage do |node|
number_to_percentage(node.wikis_verified_in_percentage, precision: 2)
end
expose :wikis_checksum_mismatch_count
expose :repositories_retrying_verification_count
expose :wikis_retrying_verification_count
expose :replication_slots_count
expose :replication_slots_used_count
expose :replication_slots_used_in_percentage do |node|
number_to_percentage(node.replication_slots_used_in_percentage, precision: 2)
end
expose :replication_slots_max_retained_wal_bytes
expose :repositories_checked_count
expose :repositories_checked_failed_count
expose :repositories_checked_in_percentage do |node|
number_to_percentage(node.repositories_checked_in_percentage, precision: 2)
end
expose :last_event_id
expose :last_event_timestamp
expose :cursor_last_event_id
expose :cursor_last_event_timestamp
expose :last_successful_status_check_timestamp
expose :version
expose :revision
expose :selective_sync_type
# Deprecated: remove in API v5. We use selective_sync_type instead now.
expose :namespaces, using: ::API::Entities::NamespaceBasic
expose :updated_at
# We load GeoNodeStatus data in two ways:
#
# 1. Directly by asking a Geo node via an API call
# 2. Via cached state in the database
#
# We don't yet cached the state of the shard information in the database, so if
# we don't have this information omit from the serialization entirely.
expose :storage_shards, using: StorageShardEntity, if: ->(status, options) do
status.storage_shards.present?
end
expose :storage_shards_match?, as: :storage_shards_match
expose :_links do
expose :self do |geo_node_status|
expose_url api_v4_geo_nodes_status_path(id: geo_node_status.geo_node_id)
end
expose :node do |geo_node_status|
expose_url api_v4_geo_nodes_path(id: geo_node_status.geo_node_id)
end
end
private
def namespaces
object.geo_node.namespaces
end
def missing_oauth_application
object.geo_node.missing_oauth_application?
end
end
class UnleashFeature < Grape::Entity
expose :name
expose :description, unless: ->(feature) { feature.description.nil? }
expose :active, as: :enabled
expose :strategies
end
class GitlabSubscription < Grape::Entity
expose :plan do
expose :plan_name, as: :code
expose :plan_title, as: :name
expose :trial
expose :auto_renew
expose :upgradable?, as: :upgradable
end
expose :usage do
expose :seats, as: :seats_in_subscription
expose :seats_in_use
expose :max_seats_used
expose :seats_owed
end
expose :billing do
expose :start_date, as: :subscription_start_date
expose :end_date, as: :subscription_end_date
expose :trial_ends_on
end
end
module ConanPackage
class ConanPackageManifest < Grape::Entity
expose :package_urls, merge: true
......@@ -769,16 +577,6 @@ module EE
end
end
class NpmPackage < Grape::Entity
expose :name
expose :versions
expose :dist_tags, as: 'dist-tags'
end
class NpmPackageTag < Grape::Entity
expose :dist_tags, merge: true
end
module Analytics
module CodeReview
class MergeRequest < ::API::Entities::MergeRequestSimple
......
# frozen_string_literal: true
module EE
module API
module Entities
class GeoNodeStatus < Grape::Entity
include ::API::Helpers::RelatedResourcesHelpers
include ActionView::Helpers::NumberHelper
expose :geo_node_id
expose :healthy?, as: :healthy
expose :health do |node|
node.healthy? ? 'Healthy' : node.health
end
expose :health_status
expose :missing_oauth_application
expose :attachments_count
expose :attachments_synced_count
expose :attachments_failed_count
expose :attachments_synced_missing_on_primary_count
expose :attachments_synced_in_percentage do |node|
number_to_percentage(node.attachments_synced_in_percentage, precision: 2)
end
expose :db_replication_lag_seconds
expose :lfs_objects_count
expose :lfs_objects_synced_count
expose :lfs_objects_failed_count
expose :lfs_objects_synced_missing_on_primary_count
expose :lfs_objects_synced_in_percentage do |node|
number_to_percentage(node.lfs_objects_synced_in_percentage, precision: 2)
end
expose :job_artifacts_count
expose :job_artifacts_synced_count
expose :job_artifacts_failed_count
expose :job_artifacts_synced_missing_on_primary_count
expose :job_artifacts_synced_in_percentage do |node|
number_to_percentage(node.job_artifacts_synced_in_percentage, precision: 2)
end
expose :container_repositories_count
expose :container_repositories_synced_count
expose :container_repositories_failed_count
expose :container_repositories_synced_in_percentage do |node|
number_to_percentage(node.container_repositories_synced_in_percentage, precision: 2)
end
expose :design_repositories_count
expose :design_repositories_synced_count
expose :design_repositories_failed_count
expose :design_repositories_synced_in_percentage do |node|
number_to_percentage(node.design_repositories_synced_in_percentage, precision: 2)
end
expose :projects_count
expose :repositories_failed_count
expose :repositories_synced_count
expose :repositories_synced_in_percentage do |node|
number_to_percentage(node.repositories_synced_in_percentage, precision: 2)
end
expose :wikis_failed_count
expose :wikis_synced_count
expose :wikis_synced_in_percentage do |node|
number_to_percentage(node.wikis_synced_in_percentage, precision: 2)
end
expose :repository_verification_enabled
expose :repositories_checksummed_count
expose :repositories_checksum_failed_count
expose :repositories_checksummed_in_percentage do |node|
number_to_percentage(node.repositories_checksummed_in_percentage, precision: 2)
end
expose :wikis_checksummed_count
expose :wikis_checksum_failed_count
expose :wikis_checksummed_in_percentage do |node|
number_to_percentage(node.wikis_checksummed_in_percentage, precision: 2)
end
expose :repositories_verification_failed_count
expose :repositories_verified_count
expose :repositories_verified_in_percentage do |node|
number_to_percentage(node.repositories_verified_in_percentage, precision: 2)
end
expose :repositories_checksum_mismatch_count
expose :wikis_verification_failed_count
expose :wikis_verified_count
expose :wikis_verified_in_percentage do |node|
number_to_percentage(node.wikis_verified_in_percentage, precision: 2)
end
expose :wikis_checksum_mismatch_count
expose :repositories_retrying_verification_count
expose :wikis_retrying_verification_count
expose :replication_slots_count
expose :replication_slots_used_count
expose :replication_slots_used_in_percentage do |node|
number_to_percentage(node.replication_slots_used_in_percentage, precision: 2)
end
expose :replication_slots_max_retained_wal_bytes
expose :repositories_checked_count
expose :repositories_checked_failed_count
expose :repositories_checked_in_percentage do |node|
number_to_percentage(node.repositories_checked_in_percentage, precision: 2)
end
expose :last_event_id
expose :last_event_timestamp
expose :cursor_last_event_id
expose :cursor_last_event_timestamp
expose :last_successful_status_check_timestamp
expose :version
expose :revision
expose :selective_sync_type
# Deprecated: remove in API v5. We use selective_sync_type instead now.
expose :namespaces, using: ::API::Entities::NamespaceBasic
expose :updated_at
# We load GeoNodeStatus data in two ways:
#
# 1. Directly by asking a Geo node via an API call
# 2. Via cached state in the database
#
# We don't yet cached the state of the shard information in the database, so if
# we don't have this information omit from the serialization entirely.
expose :storage_shards, using: StorageShardEntity, if: ->(status, options) do
status.storage_shards.present?
end
expose :storage_shards_match?, as: :storage_shards_match
expose :_links do
expose :self do |geo_node_status|
expose_url api_v4_geo_nodes_status_path(id: geo_node_status.geo_node_id)
end
expose :node do |geo_node_status|
expose_url api_v4_geo_nodes_path(id: geo_node_status.geo_node_id)
end
end
private
def namespaces
object.geo_node.namespaces
end
def missing_oauth_application
object.geo_node.missing_oauth_application?
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class GitlabSubscription < Grape::Entity
expose :plan do
expose :plan_name, as: :code
expose :plan_title, as: :name
expose :trial
expose :auto_renew
expose :upgradable?, as: :upgradable
end
expose :usage do
expose :seats, as: :seats_in_subscription
expose :seats_in_use
expose :max_seats_used
expose :seats_owed
end
expose :billing do
expose :start_date, as: :subscription_start_date
expose :end_date, as: :subscription_end_date
expose :trial_ends_on
end
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class NpmPackage < Grape::Entity
expose :name
expose :versions
expose :dist_tags, as: 'dist-tags'
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class NpmPackageTag < Grape::Entity
expose :dist_tags, merge: true
end
end
end
end
# frozen_string_literal: true
module EE
module API
module Entities
class UnleashFeature < Grape::Entity
expose :name
expose :description, unless: ->(feature) { feature.description.nil? }
expose :active, as: :enabled
expose :strategies
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment