Skip to content

Add API endpoint to update Maven virtual registry upstream position

Context

In Support virtual registries multiple upstreams m... (!185986 - merged), a new column position was added to the virtual_registries_packages_maven_registry_upstreams database table to support a listable functionality. With this position, users can rank the upstreams to indicate which has higher priority than others when fetching the artifacts.

In this MR, we add a rest API endpoint to update this column: PATCH /api/v4/virtual_registries/packages/maven/registry_upstreams/:id.

Because the position column is in the join table virtual_registries_packages_maven_registry_upstreams, we need to expose its ID so that users can use it with the new endpoint to update the position. We expose it when accessing GET /api/v4/virtual_registries/packages/maven/registries/:id/upstreams.

What does this MR do and why?

  • Add a new PATCH rest API endpoint to update the position column in the virtual_registries_packages_maven_registry_upstreams table.
  • Add a public instance method #update_position to the VirtualRegistries::Packages::Maven::RegistryUpstream model to handle the update of the position of all upstreams that belongs to a registry and make sure all stay in sync.
  • Expose the id and position in the response of GET /api/v4/virtual_registries/packages/maven/registries/:id/upstreams endpoint. This would allow users to know the position of the upstream, and send a position update request (if needed) using the registry_upstream#id to the new endpoint added in this MR.
  • Convert the unique index on registry_id & position columns in virtual_registries_packages_maven_registry_upstreams to a unique deferrable constraint. The unique index will prevent updating the position for multiple rows in one SQL query because it enforces the uniqueness inside the transaction. The deferrable constraint would defer enforcing the uniqueness till the end of the transaction.
  • Add the needed specs.

References

Screenshots or screen recordings

N/A

How to set up and validate locally

  • Enable the feature flag: Feature.enable(:virtual_registry_maven)

  • Have a top level group, a PAT (scope api) and a GitLab instance with an EE licence ready.

  • Let's create a registry:

$ curl -X POST --header "Private-Token: <PAT>" "http://gdk.test:3000/api/v4/groups/<group_id>/-/virtual_registries/packages/maven/registries" | jq
  • Let's create multiple upstreams (we need the id of the registry we just created):
$ curl -i -H "PRIVATE-TOKEN: <PAT>" --data-urlencode 'url=https://repo.maven.apache.org/maven/' -X POST http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams

$ curl -i -H "PRIVATE-TOKEN: <PAT>" --data-urlencode 'url=https://repo.maven.apache.org/maven1/' -X POST http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams

$ curl -i -H "PRIVATE-TOKEN: <PAT>" --data-urlencode 'url=https://repo.maven.apache.org/maven2/' -X POST http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams

$ curl -i -H "PRIVATE-TOKEN: <PAT>" --data-urlencode 'url=https://repo.maven.apache.org/maven3/' -X POST http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams

$ curl -i -H "PRIVATE-TOKEN: <PAT>" --data-urlencode 'url=https://repo.maven.apache.org/maven4/' -X POST http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams
  • Let's fetch the list of all upstreams (notice the registry_upstream.id & registry_upstream.position attributes returned in the response):
curl -H 'PRIVATE-TOKEN: <PAT>' http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registries/<registry_id>/upstreams | jq
  • Pick one upstream from the list and update its position:
curl -v -i \
  -H "PRIVATE-TOKEN: <PAT>" \
  -H "Content-Type: application/json" \
  -d '{"position": <new_value>}' \
  -X PATCH \
  "http://gdk.test:3000/api/v4/virtual_registries/packages/maven/registry_upstreams/<registry_upstream_id>"
  • List the upstreams again and make sure all positions have been updated correctly and in sync.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #525112 (closed)

Edited by Moaz Khalifa

Merge request reports

Loading