Skip to content

Commit

Permalink
Add add-deprecations API endpoint
Browse files Browse the repository at this point in the history
Refers to CLOUDDST-23446
  • Loading branch information
yashvardhannanavati committed Jul 30, 2024
1 parent 95c03a0 commit 7449aff
Show file tree
Hide file tree
Showing 6 changed files with 420 additions and 1 deletion.
26 changes: 26 additions & 0 deletions iib/web/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Operator,
Request,
RequestAdd,
RequestAddDeprecations,
RequestFbcOperations,
RequestMergeIndexImage,
RequestRecursiveRelatedBundles,
Expand Down Expand Up @@ -53,6 +54,7 @@
from iib.workers.tasks.build_create_empty_index import handle_create_empty_index_request
from iib.workers.tasks.general import failed_request_callback
from iib.web.iib_static_types import (
AddDeprecationRequestPayload,
AddRequestPayload,
AddRmBatchPayload,
CreateEmptyIndexPayload,
Expand Down Expand Up @@ -1321,3 +1323,27 @@ def fbc_operations() -> Tuple[flask.Response, int]:

flask.current_app.logger.debug('Successfully scheduled request %d', request.id)
return flask.jsonify(request.to_json()), 201


@api_v1.route('/builds/add-deprecations', methods=['POST'])
@login_required
@instrument_tracing(span_name="web.api_v1.add_deprecations")
def add_deprecations() -> Tuple[flask.Response, int]:
"""
Submit a request to add operator deprecations to an index image.
:rtype: flask.Response
:raise ValidationError: if required parameters are not supplied
"""
payload: AddDeprecationRequestPayload = cast(
AddDeprecationRequestPayload, flask.request.get_json()
)
if not isinstance(payload, dict):
raise ValidationError('The input data must be a JSON object')

request = RequestAddDeprecations.from_json(payload)
db.session.add(request)
db.session.commit()

flask.current_app.logger.debug('Successfully validated request %d', request.id)
return flask.jsonify({'msg': 'This API endpoint hasn not been implemented yet'}), 501
15 changes: 15 additions & 0 deletions iib/web/iib_static_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RelatedBundlesMetadata(TypedDict):
# try inheritance from other payloads

PayloadTags = Literal[
'AddDeprecationRequestPayload',
'AddRequestPayload',
'RmRequestPayload',
'RegenerateBundlePayload',
Expand All @@ -63,12 +64,14 @@ class RelatedBundlesMetadata(TypedDict):
'cnr_token',
'check_related_images',
'deprecation_list',
'deprecation_schema',
'distribution_scope',
'force_backport',
'from_bundle_image',
'from_index',
'graph_update_mode',
'labels',
'operator_package',
'operators',
'organization',
'output_fbc',
Expand All @@ -83,6 +86,17 @@ class RelatedBundlesMetadata(TypedDict):
]


class AddDeprecationRequestPayload(TypedDict):
"""Data structure of the request to /builds/add-deprecations API endpoint."""

binary_image: NotRequired[str]
deprecation_schema: str
from_index: str
operator_package: str
overwrite_from_index: NotRequired[bool]
overwrite_from_index_token: NotRequired[str]


class AddRequestPayload(TypedDict):
"""Datastructure of the request to /builds/add API point."""

Expand Down Expand Up @@ -226,6 +240,7 @@ class RequestPayload(TypedDict):


PayloadTypesUnion = Union[
AddDeprecationRequestPayload,
AddRequestPayload,
CreateEmptyIndexPayload,
FbcOperationRequestPayload,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
"""Add add-deprecations API endpoint.
Revision ID: 49d13af4b328
Revises: 1920ad83d0ab
Create Date: 2024-07-26 00:17:44.283197
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '49d13af4b328'
down_revision = '1920ad83d0ab'
branch_labels = None
depends_on = None


def upgrade():
op.create_table(
'deprecation_schema',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('schema', sa.Text(), nullable=False),
sa.PrimaryKeyConstraint('id'),
)
with op.batch_alter_table('deprecation_schema', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_deprecation_schema_schema'), ['schema'], unique=True)

op.create_table(
'request_add_deprecations',
sa.Column('id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('binary_image_id', sa.Integer(), nullable=True),
sa.Column('binary_image_resolved_id', sa.Integer(), nullable=True),
sa.Column('from_index_id', sa.Integer(), nullable=True),
sa.Column('from_index_resolved_id', sa.Integer(), nullable=True),
sa.Column('index_image_id', sa.Integer(), nullable=True),
sa.Column('index_image_resolved_id', sa.Integer(), nullable=True),
sa.Column('internal_index_image_copy_id', sa.Integer(), nullable=True),
sa.Column('internal_index_image_copy_resolved_id', sa.Integer(), nullable=True),
sa.Column('distribution_scope', sa.String(), nullable=True),
sa.ForeignKeyConstraint(
['binary_image_id'],
['image.id'],
),
sa.ForeignKeyConstraint(
['binary_image_resolved_id'],
['image.id'],
),
sa.ForeignKeyConstraint(
['from_index_id'],
['image.id'],
),
sa.ForeignKeyConstraint(
['from_index_resolved_id'],
['image.id'],
),
sa.ForeignKeyConstraint(
['id'],
['request.id'],
),
sa.ForeignKeyConstraint(
['index_image_id'],
['image.id'],
),
sa.ForeignKeyConstraint(
['index_image_resolved_id'],
['image.id'],
),
sa.ForeignKeyConstraint(
['internal_index_image_copy_id'],
['image.id'],
),
sa.ForeignKeyConstraint(
['internal_index_image_copy_resolved_id'],
['image.id'],
),
sa.PrimaryKeyConstraint('id'),
)
op.create_table(
'request_add_deprecations_deprecation_schema',
sa.Column('request_add_deprecations_id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('deprecation_schema_id', sa.Integer(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(
['deprecation_schema_id'],
['deprecation_schema.id'],
),
sa.ForeignKeyConstraint(
['request_add_deprecations_id'],
['request_add_deprecations.id'],
),
sa.PrimaryKeyConstraint('request_add_deprecations_id', 'deprecation_schema_id'),
sa.UniqueConstraint('request_add_deprecations_id', 'deprecation_schema_id'),
)
with op.batch_alter_table(
'request_add_deprecations_deprecation_schema', schema=None
) as batch_op:
batch_op.create_index(
batch_op.f('ix_request_add_deprecations_deprecation_schema_deprecation_schema_id'),
['deprecation_schema_id'],
unique=False,
)
batch_op.create_index(
batch_op.f(
'ix_request_add_deprecations_deprecation_schema_request_add_deprecations_id'
),
['request_add_deprecations_id'],
unique=False,
)

op.create_table(
'request_add_deprecations_operator',
sa.Column('request_add_deprecations_id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('operator_id', sa.Integer(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(
['operator_id'],
['operator.id'],
),
sa.ForeignKeyConstraint(
['request_add_deprecations_id'],
['request_add_deprecations.id'],
),
sa.PrimaryKeyConstraint('request_add_deprecations_id', 'operator_id'),
sa.UniqueConstraint('request_add_deprecations_id', 'operator_id'),
)
with op.batch_alter_table('request_add_deprecations_operator', schema=None) as batch_op:
batch_op.create_index(
batch_op.f('ix_request_add_deprecations_operator_operator_id'),
['operator_id'],
unique=False,
)
batch_op.create_index(
batch_op.f('ix_request_add_deprecations_operator_request_add_deprecations_id'),
['request_add_deprecations_id'],
unique=False,
)


def downgrade():
with op.batch_alter_table('request_add_deprecations_operator', schema=None) as batch_op:
batch_op.drop_index(
batch_op.f('ix_request_add_deprecations_operator_request_add_deprecations_id')
)
batch_op.drop_index(batch_op.f('ix_request_add_deprecations_operator_operator_id'))

op.drop_table('request_add_deprecations_operator')
with op.batch_alter_table(
'request_add_deprecations_deprecation_schema', schema=None
) as batch_op:
batch_op.drop_index(
batch_op.f('ix_request_add_deprecations_deprecation_schema_request_add_deprecations_id')
)
batch_op.drop_index(
batch_op.f('ix_request_add_deprecations_deprecation_schema_deprecation_schema_id')
)

op.drop_table('request_add_deprecations_deprecation_schema')
op.drop_table('request_add_deprecations')
with op.batch_alter_table('deprecation_schema', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_deprecation_schema_schema'))

op.drop_table('deprecation_schema')
Loading

0 comments on commit 7449aff

Please sign in to comment.