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

Extract mirroring implementation from the server module #836

Merged
merged 13 commits into from
Aug 23, 2023

Conversation

minwoox
Copy link
Member

@minwoox minwoox commented Apr 14, 2023

Motivation:
Previously, the server module was using jgit5 and jgit6 libraries together. It's because jgit6 requires JDK 11 as a minimum, so we needed jgit5 for JDK 8 client.
However, that might cause a dependency conflict problem such as #835. If we extract jgit6 specific API and implementations to a new module, we can avoid this problem.

Modifications:

  • Add MirrorProvider interface that creates a Mirror.
    • MirrorProviders are discovered via SPI.
  • Created a new module called server-mirror-git and added GitMirrorProvider.
  • jgit6 is used if javaTestVersion is greater or equal to 11.
    • jgit5 is sued if javaTestVersion is 8.
  • Clean up dependencies in build.gradle.
  • (Breaking)
    • The type property, which was useless, in the mirroring configuration is now removed.
    • Removed server-git6 module.

Result:

  • The server module is now correctly built and tested with the proper JGit libraries depending on the JDK test version.

@codecov
Copy link

codecov bot commented Apr 14, 2023

Codecov Report

Patch coverage: 64.92% and project coverage change: +0.11% 🎉

Comparison is base (07a1fa6) 65.50% compared to head (0780b2d) 65.61%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #836      +/-   ##
============================================
+ Coverage     65.50%   65.61%   +0.11%     
- Complexity     3328     3350      +22     
============================================
  Files           356      358       +2     
  Lines         13962    13908      -54     
  Branches       1499     1494       -5     
============================================
- Hits           9146     9126      -20     
+ Misses         3964     3932      -32     
+ Partials        852      850       -2     
Files Changed Coverage Δ
...ntraldogma/server/command/AbstractPushCommand.java 46.66% <ø> (ø)
...inecorp/centraldogma/server/mirror/MirrorUtil.java 75.00% <ø> (-0.76%) ⬇️
...ntraldogma/server/internal/mirror/GitWithAuth.java 58.59% <46.15%> (ø)
...rver/internal/storage/repository/MirrorConfig.java 57.14% <57.14%> (ø)
...corp/centraldogma/server/mirror/MirrorContext.java 64.00% <64.00%> (ø)
...server/internal/storage/repository/MirrorUtil.java 75.00% <75.00%> (ø)
...ogma/server/internal/mirror/GitMirrorProvider.java 84.61% <84.61%> (ø)
...storage/repository/CentralDogmaMirrorProvider.java 89.47% <89.47%> (ø)
...centraldogma/server/internal/mirror/GitMirror.java 81.58% <100.00%> (ø)
...erver/internal/mirror/DefaultMirroringService.java 69.56% <100.00%> (+2.17%) ⬆️
... and 2 more

... and 8 files with indirect coverage changes

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

@minwoox minwoox changed the title [WIP] Extract mirroring implementation from the server module Extract mirroring implementation from the server module Apr 17, 2023
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it makes sense to move DefaultMetaRepository out of :server. How about introducing some SPI so :mirror can register itself as a handler for a certain set of URI schemes?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good suggestion. Addressed.

settings.gradle Outdated Show resolved Hide resolved
@Type(value = SingleMirrorConfig.class, name = "single"),
@Type(value = MultipleMirrorConfig.class, name = "multiple")
})
@JsonSubTypes(@Type(value = SingleMirrorConfig.class, name = "single"))
private abstract static class MirrorConfig {
Copy link
Member Author

Choose a reason for hiding this comment

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

Will combine MirrorConfig and SingleMirrorConfig together after @ikhoon's work for mirroring UI is done.

Copy link
Member Author

Choose a reason for hiding this comment

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

Combine them in this PR instead of waiting for @ikhoon's work. 😉

@minwoox minwoox added this to the 0.61.6 milestone Aug 18, 2023
import com.linecorp.centraldogma.server.mirror.MirrorContext;
import com.linecorp.centraldogma.server.mirror.MirrorProvider;

public final class DefaultMirrorProvider implements MirrorProvider {
Copy link
Member

Choose a reason for hiding this comment

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

GitMirrorProvider?


//noinspection EnhancedSwitchMigration
switch (scheme) {
case SCHEME_DOGMA: {
Copy link
Member

Choose a reason for hiding this comment

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

Could you file an issue about moving this back into the main server module and add a TODO comment that has the issue URL? This scheme doesn't belong to server-mirror-git.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added CentralDogmaMirrorProvider and moved it back to the server module. 😅

metaRepo.commit(Revision.HEAD, 0, Author.SYSTEM, "",
Change.ofJsonUpsert(
PATH_MIRRORS,
"[{" +
" \"enabled\": true," +
" \"type\": \"single\"," +
Copy link
Member

Choose a reason for hiding this comment

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

Can we at least keep one entry with "type:": "single" to ensure the backward compatibility?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -81,7 +81,7 @@ public String detail() {
}

/**
* Returns the {@link Markup} of the {@link #detail()}.
* Returns the {@link Markup} of the {@code detail()}.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe revert? This class still have #detail()

Copy link
Member Author

Choose a reason for hiding this comment

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

Revert and make AbstractPushCommand public so that Javadoc is correctly rendered.

Copy link
Member

@trustin trustin left a comment

Choose a reason for hiding this comment

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

👍

@minwoox
Copy link
Member Author

minwoox commented Aug 23, 2023

Let me merge this and continue to work on #830. Please leave a comment here if there's something I need to fix. I will fix it in #830 together. 😉

@minwoox minwoox merged commit 0fd267d into line:main Aug 23, 2023
8 of 10 checks passed
@minwoox minwoox deleted the extract_mirror branch August 23, 2023 02:33
implementation libs.jgit.ssh.jsch
// Hacky way to use different jGit versions depending on the test Java version.
// We will use jgit6 after we drop the support for Java 8 client.
if (project.ext.testJavaVersion >= 11) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the late review.
It is weird to change the target dependency which will be added to the POM file depending on testJavaVersion.
project.ext.targetJavaVersion should be a better choice.
If we want to test with jgit6, we can raise minimumJavaVersion to 11 or higher versions.
https://github.com/line/armeria/pull/4812/files#diff-79a2782078afe306b9bc1be1e6e5b3d1d94f9ef585741688c4d05bd4243569f5R4

Copy link
Member Author

Choose a reason for hiding this comment

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

If we use project.ext.targetJavaVersion, can we use jgit5 for testing the client module with testJavaVersion8?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it works.

# Use JGit 5 for testing.
~/src/centraldogma/client main* ⇣⇡
❯ gw clean :client:java-armeria:test -PtestJavaVersion=11

❯ ag "JGit version"                                      
java-armeria/build/test-results/test/TEST-com.linecorp.centraldogma.client.armeria.ArmeriaCentralDogmaTest.xml
57:2023-08-23 20:20:39.660 [INFO ](c.l.c.s.i.s.r.g.GitRepository) [repository-worker-6-1] JGit version: 5.13.0.202109080827-r

java-armeria/build/reports/tests/test/classes/com.linecorp.centraldogma.client.armeria.ArmeriaCentralDogmaTest.html
146:2023-08-23 20:20:39.660 [INFO ](c.l.c.s.i.s.r.g.GitRepository) [repository-worker-6-1] JGit version: 5.13.0.202109080827-r

# Use JGit 6 for testing
❯ gw clean :client:java-armeria:test -PtestJavaVersion=11 -PminimumJavaVersion=11
❯ ag "JGit version"                                                              
java-armeria/build/test-results/test/TEST-com.linecorp.centraldogma.client.armeria.ArmeriaCentralDogmaTest.xml
57:2023-08-23 20:20:08.281 [INFO ](c.l.c.s.i.s.r.g.GitRepository) [repository-worker-6-1] JGit version: 6.6.0.202305301015-r

java-armeria/build/reports/tests/test/classes/com.linecorp.centraldogma.client.armeria.ArmeriaCentralDogmaTest.html
146:2023-08-23 20:20:08.281 [INFO ](c.l.c.s.i.s.r.g.GitRepository) [repository-worker-6-1] JGit version: 6.6.0.202305301015-r

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, I thought, an info message for the current JGit version would be useful.

static {
    InputStream is = null;
    try {
        is = SystemReader.class.getClassLoader().getResourceAsStream("META-INF/maven/org.eclipse.jgit/org.eclipse.jgit/pom.properties");
        final Properties props = new Properties();
        props.load(is);
        final Object jgitVersion = props.get("version");
        if (jgitVersion != null) {
            logger.info("Using JGit: {}", jgitVersion);
        }
    } catch (IOException e) {
        logger.debug("Failed to read JGit version", e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}

Let me send a PR for that.

Copy link
Member Author

@minwoox minwoox Aug 23, 2023

Choose a reason for hiding this comment

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

Yes, it works.

Does it work when we specify -PtestJavaVersion=8? 🤔
Could you also share how did you implement the build.gradle?

Copy link
Member Author

Choose a reason for hiding this comment

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

Anyway, it's too late so let's keep discussing tomorrow. 😉

Copy link
Contributor

@ikhoon ikhoon Aug 23, 2023

Choose a reason for hiding this comment

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

We don’t need to set an extra properties since we publish the server module with JGit 5.
JGit 6 will be chosen only mininumJavaVersion is higher than 11.

When packing a tarball, JGit 5 is excluded and JGit 6 is added instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah ha, now I understand. Well actually, publishing the server module with JGit 6 was my intention but I guess I was wrong because users would still need the server module for testing. Let me make a change, then. Thanks!

Copy link
Member Author

@minwoox minwoox Aug 23, 2023

Choose a reason for hiding this comment

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

The change is pushed: 5118422
PTAL. 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks 👍!

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.

3 participants