Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new mirroring and credential settings format and REST API #880

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

ikhoon
Copy link
Contributor

@ikhoon ikhoon commented Sep 6, 2023

Motivation:

The ID for mirroring and credential configurations is optional, so I found it difficult to safely update a configuration with REST API. If a user updates a file manually on UI or commit API, the REST API may update a wrong configuration without a unique ID.

@trustin suggested changing the directory layout to store a configuration to a file with a unique ID. #838 (review)

This PR has three major changes:

  • Migrate the old mirror and credential settings to the new layout.
    - mirrors
      - <mirror-id>.json
      - ...
    - credentials
      - <credentials-id>.json
      - ...
    
  • Add a migration job to automatically migrate the old settings to the new format when a server starts. The old files are renamed by adding .bak suffix. e,g. mirrors.json -> mirrors.json.bak, credentials.json -> credentials.json.bak.
  • Add REST API for mirroring and credential configurations. This is a necessary task to add mirror UI. Add Mirroring and Credential UI #838

Modifications:

  • Add MirroringMigrationService that is executed when a server starts and scan all /mirrors.json and /credentials.json in the meta repo of projects and migrate them to the new format.
    • "id" is a required property in each configuration. Human-readable random words are used to create a unique ID.
      • Mirror ID format: mirror-<projectName>-<localRepo>-<shortWord>
      • Credential ID format: credential-<projectName>-<shortWord>
      • short_wordlist.txt is used as the word database.
  • Change Mirror and related classes to have id, enabled as required fields.
  • Add CredentailServiceV1 and MirrorServiceV1 to serve REST API for CRU.
    • Create, read, and update operations are implemented in DefaultMetaRepository.
  • Add RepositoryUri to represent a repository-specific URI such as a Git repository URL.
  • Add MirrorDto to serialize a mirroring configuration. Mirror represents a mirroring task, so Mirror is not suitable for serialization.
    • MirrorCredential is used as is instead of creating a new DTO.
  • Migrated all mirroring tests to use the new configuration format.
  • Updated site documentation with the new format.

Result:

  • Mirroring and credential settings have been updated to the new formats.
  • You can now access and modify mirroring and credential resources using the REST API.

@ikhoon ikhoon changed the title Add Mirroring and Credential REST API Introduce new mirroring and credential settings format and REST API Sep 8, 2023
@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Attention: Patch coverage is 75.76792% with 142 lines in your changes are missing coverage. Please review.

Project coverage is 70.60%. Comparing base (aae194c) to head (4ce5319).
Report is 11 commits behind head on main.

❗ Current head 4ce5319 differs from pull request most recent head f8091ae. Consider uploading reports for the commit f8091ae to get more accurate results

Files Patch % Lines
...necorp/centraldogma/internal/api/v1/MirrorDto.java 46.77% 19 Missing and 14 partials ⚠️
...rnal/storage/repository/DefaultMetaRepository.java 73.55% 20 Missing and 12 partials ⚠️
...ver/internal/mirror/MirroringMigrationService.java 80.76% 22 Missing and 8 partials ⚠️
...ver/internal/storage/repository/RepositoryUri.java 39.13% 14 Missing ⚠️
...erver/internal/mirror/DefaultMirroringService.java 50.00% 10 Missing ⚠️
...er/storage/project/InternalProjectInitializer.java 72.72% 3 Missing and 3 partials ⚠️
...ldogma/server/internal/api/MirroringServiceV1.java 85.71% 4 Missing ⚠️
...com/linecorp/centraldogma/server/CentralDogma.java 91.66% 1 Missing and 2 partials ⚠️
...ecorp/centraldogma/server/CentralDogmaBuilder.java 0.00% 3 Missing ⚠️
...corp/centraldogma/server/mirror/MirrorContext.java 71.42% 2 Missing ⚠️
... and 5 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #880      +/-   ##
============================================
+ Coverage     66.86%   70.60%   +3.74%     
- Complexity     3529     3748     +219     
============================================
  Files           370      375       +5     
  Lines         14531    14917     +386     
  Branches       1563     1597      +34     
============================================
+ Hits           9716    10532     +816     
+ Misses         3936     3436     -500     
- Partials        879      949      +70     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ikhoon ikhoon added this to the 0.62.2 milestone Sep 8, 2023
@ikhoon ikhoon marked this pull request as ready for review September 8, 2023 07:54
Copy link
Member

@minwoox minwoox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great all in all. 👍 👍 👍

Copy link
Contributor

@jrhee17 jrhee17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get a chance to look at the services, but overall looks nice. Left some questions 🙇

Comment on lines +141 to +142
final JsonNode credentialId = mirror.get("credentialId");
if (credentialId != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have no idea how to prevent JSON upsert operation. We may need to stop replication just before rolling updates.

Instead of the current approach of updating from a Leader directly, would it be possible to issue a custom command (i.e. MigrateMirrorCommand) ?

If we take a write lock while migrating, I guess there will be minimal issues regarding inconsistency.

@ikhoon ikhoon removed this from the 0.63.0 milestone Oct 30, 2023
@ikhoon ikhoon marked this pull request as draft October 30, 2023 03:03
ikhoon added a commit to ikhoon/centraldogma that referenced this pull request Nov 28, 2023
Motivation:

While mirroring migration job is implemeted line#880, read-only mode is
necessary to safely migrate the legacy `mirrors.json` and
`credentials.json` the HEAD revision. As the current read-only mode
rejects all commands, the migration job is also unable to push commits.

A new command type is required to rejects only users requests but allows
administrative cases. I propose to introduce two new command types for
the smooth migration job.

Modifications:

- Add `UpdateServerStatusCommand` so as to toggle the read-only mode for
  the cluster.
- Add `ForcePush` so as to wrap a push `Command` to be executed even in the
  read-only mode.

Result:

`UpdateServerStatusCommand` and `ForcePush` have been added as new
commands to update the cluster status and forcibly push commits in the
read-only mode.
minwoox pushed a commit that referenced this pull request Feb 2, 2024
Motivation:

While mirroring migration job is implemeted #880, read-only mode is necessary to safely migrate the legacy `mirrors.json` and `credentials.json` the HEAD revision. As the current read-only mode rejects all commands, the migration job is also unable to push commits.

A new command type is required to rejects only users requests but allows administrative cases. I propose to introduce two new command types for the smooth migration job.

Modifications:

- Add `UpdateServerStatusCommand` so as to toggle the read-only mode for the cluster.
- Add `ForcePush` so as to wrap a push `Command` to be executed even in the read-only mode.

Result:

`UpdateServerStatusCommand` and `ForcePush` have been added as new commands to update the cluster status and forcibly push commits in the read-only mode.
@ikhoon ikhoon marked this pull request as ready for review February 14, 2024 09:32
@ikhoon ikhoon added this to the 0.65.0 milestone Feb 14, 2024
@ikhoon ikhoon marked this pull request as draft February 14, 2024 11:56
@ikhoon
Copy link
Contributor Author

ikhoon commented Feb 14, 2024

I found a bug in updating server's status during rolling restart. Let me send a separate PR to handle it first.

@ikhoon
Copy link
Contributor Author

ikhoon commented Feb 21, 2024

I will proceed with this PR after #921 is merged.

@minwoox minwoox modified the milestones: 0.65.0, 0.66.0 Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants