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

Merged
merged 43 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8b51e01
Add Mirroring and Credential REST API
ikhoon Mar 6, 2023
eabb4d1
Merge branch 'main' into mirror-api
ikhoon Sep 6, 2023
eb28015
fix compile errors
ikhoon Sep 6, 2023
785e8dc
clean up
ikhoon Sep 6, 2023
1de0159
Migrate the legacy single file format to directory based format
ikhoon Sep 6, 2023
9444f37
Fix broken mirror and credential tests
ikhoon Sep 7, 2023
62533e4
Fix the wrong package name and update documentation
ikhoon Sep 8, 2023
3b644b3
Remove redundant validation
ikhoon Sep 8, 2023
ad000b7
Address comments by @minwoox
ikhoon Sep 18, 2023
2abe5c4
--wip-- [skip ci]
ikhoon Oct 12, 2023
ed4da7d
Merge branch 'main' into mirror-api
ikhoon Nov 15, 2023
62c6851
Use MIRROR_PROVIDERS to check if Git mirror is enabled
ikhoon Nov 15, 2023
2083cdb
Address all comments
ikhoon Nov 16, 2023
9ae68a0
lint
ikhoon Nov 16, 2023
a7cb15d
clean up
ikhoon Nov 16, 2023
bfefa1a
javadoc
ikhoon Nov 16, 2023
157d3a6
Add TODO
ikhoon Nov 16, 2023
280c82e
Add integration tests with ZooKeeper cluster
ikhoon Nov 17, 2023
52af015
Add validation
ikhoon Nov 28, 2023
92ecae9
Merge branch 'main' into mirror-api
ikhoon Feb 14, 2024
faf081e
Read backup files to check if mirror migration was performed
ikhoon Feb 14, 2024
4ce5319
Follow up after merging
ikhoon Feb 14, 2024
a9213fb
Add rollback logic
ikhoon Feb 14, 2024
f3da444
fix compile error
ikhoon Feb 14, 2024
bc200ef
Fix flakyness
ikhoon Feb 14, 2024
3399bfb
lint
ikhoon Feb 14, 2024
f8091ae
Merge branch 'main' into mirror-api
ikhoon May 10, 2024
2611954
Merge branch 'main' into mirror-api
ikhoon Jun 11, 2024
28e1023
handle flakiness
ikhoon Jun 11, 2024
6dee7fb
lint
ikhoon Jun 11, 2024
069841e
reject legacy file formats in ContentServiceV1
ikhoon Jun 11, 2024
b6189ed
clean up and bug in rolback file names
ikhoon Jun 11, 2024
621ec19
Add more tests
ikhoon Jun 11, 2024
ca95ef6
lint and fix a bug
ikhoon Jun 12, 2024
c80bd88
lint again
ikhoon Jun 12, 2024
f0184f0
Merge remote-tracking branch 'origin/main' into mirror-api
jrhee17 Jun 13, 2024
e5adacd
pushedAt
ikhoon Jun 13, 2024
a80425c
remove class level annotation
ikhoon Jun 13, 2024
b44ba6b
Address comments by @jrhee17
ikhoon Jun 13, 2024
c7686ae
fix the test failure
ikhoon Jun 14, 2024
bc5bb2e
Address comments by @minwoox
ikhoon Jun 18, 2024
8acab6c
remove jdk8
ikhoon Jun 21, 2024
c128bf5
fix a test failure
ikhoon Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ typings/

# next.js build output
.next
.swc

# macOS folder meta-data
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void pushMirrorsJsonFileToMetaRepository() throws UnknownHostException {
.build();

final PushResult result = client.forRepo("foo", "meta")
.commit("summary", Change.ofJsonUpsert("/mirrors.json", "[]"))
.commit("summary", Change.ofJsonUpsert("/mirrors/foo.json", "{}"))
.push()
.join();
assertThat(result.revision().major()).isPositive();
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies {
implementation libs.jackson.core
implementation libs.jackson.databind
implementation libs.jackson.datatype.jsr310
implementation libs.jackson.datatype.jdk8
Copy link
Member

Choose a reason for hiding this comment

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

We also need to remove this line.


// Guava
implementation libs.guava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.deser.InstantDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.InstantSerializer;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -77,7 +79,8 @@ public final class Jackson {
compactMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
prettyMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);

registerModules(new SimpleModule().addSerializer(Instant.class, InstantSerializer.INSTANCE)
registerModules(new Jdk8Module(),
ikhoon marked this conversation as resolved.
Show resolved Hide resolved
new SimpleModule().addSerializer(Instant.class, InstantSerializer.INSTANCE)
.addDeserializer(Instant.class, InstantDeserializer.INSTANT));
}

Expand Down Expand Up @@ -367,6 +370,10 @@ private static JsonNode traverse(JsonNode base, JsonNode update, StringBuilder f
return update;
}

public static ArrayNode newArrayNode() {
return compactMapper.createArrayNode();
}

private Jackson() {}

private static class PrettyPrinterImpl extends DefaultPrettyPrinter {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
* Copyright 2023 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/

package com.linecorp.centraldogma.internal.api.v1;

import static com.google.common.base.MoreObjects.firstNonNull;
import static java.util.Objects.requireNonNull;

import java.util.Objects;

import javax.annotation.Nullable;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;

@JsonInclude(Include.NON_NULL)
public final class MirrorDto {

private final String id;
private final boolean enabled;
private final String projectName;
private final String schedule;
private final String direction;
private final String localRepo;
private final String localPath;
private final String remoteScheme;
private final String remoteUrl;
private final String remotePath;
private final String remoteBranch;
@Nullable
private final String gitignore;
private final String credentialId;

@JsonCreator
public MirrorDto(@JsonProperty("id") String id,
@JsonProperty("enabled") @Nullable Boolean enabled,
@JsonProperty("projectName") String projectName,
@JsonProperty("schedule") String schedule,
@JsonProperty("direction") String direction,
@JsonProperty("localRepo") String localRepo,
@JsonProperty("localPath") String localPath,
@JsonProperty("remoteScheme") String remoteScheme,
@JsonProperty("remoteUrl") String remoteUrl,
@JsonProperty("remotePath") String remotePath,
@JsonProperty("remoteBranch") String remoteBranch,
@JsonProperty("gitignore") @Nullable String gitignore,
@JsonProperty("credentialId") String credentialId) {
this.id = id;
ikhoon marked this conversation as resolved.
Show resolved Hide resolved
this.enabled = firstNonNull(enabled, true);
this.projectName = requireNonNull(projectName, "projectName");
this.schedule = requireNonNull(schedule, "schedule");
this.direction = requireNonNull(direction, "direction");
this.localRepo = requireNonNull(localRepo, "localRepo");
this.localPath = requireNonNull(localPath, "localPath");
this.remoteScheme = requireNonNull(remoteScheme, "remoteScheme");
this.remoteUrl = requireNonNull(remoteUrl, "remoteUrl");
this.remotePath = requireNonNull(remotePath, "remotePath");
this.remoteBranch = requireNonNull(remoteBranch, "remoteBranch");
this.gitignore = gitignore;
this.credentialId = requireNonNull(credentialId, "credentialId");
}

@JsonProperty("id")
public String id() {
return id;
}

@JsonProperty("enabled")
public boolean enabled() {
return enabled;
}

@JsonProperty("projectName")
public String projectName() {
return projectName;
}

@JsonProperty("schedule")
public String schedule() {
return schedule;
}

@JsonProperty("direction")
public String direction() {
return direction;
}

@JsonProperty("localRepo")
public String localRepo() {
return localRepo;
}

@JsonProperty("localPath")
public String localPath() {
return localPath;
}

@JsonProperty("remoteScheme")
public String remoteScheme() {
return remoteScheme;
}

@JsonProperty("remoteUrl")
public String remoteUrl() {
return remoteUrl;
}

@JsonProperty("remotePath")
public String remotePath() {
return remotePath;
}

@JsonProperty("remoteBranch")
public String remoteBranch() {
return remoteBranch;
}

@Nullable
@JsonProperty("gitignore")
public String gitignore() {
return gitignore;
}

@JsonProperty("credentialId")
public String credentialId() {
return credentialId;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MirrorDto)) {
return false;
}
final MirrorDto mirrorDto = (MirrorDto) o;
return id.equals(mirrorDto.id) &&
enabled == mirrorDto.enabled &&
projectName.equals(mirrorDto.projectName) &&
schedule.equals(mirrorDto.schedule) &&
direction.equals(mirrorDto.direction) &&
localRepo.equals(mirrorDto.localRepo) &&
localPath.equals(mirrorDto.localPath) &&
remoteScheme.equals(mirrorDto.remoteScheme) &&
remoteUrl.equals(mirrorDto.remoteUrl) &&
remotePath.equals(mirrorDto.remotePath) &&
remoteBranch.equals(mirrorDto.remoteBranch) &&
Objects.equals(gitignore, mirrorDto.gitignore) &&
credentialId.equals(mirrorDto.credentialId);
}

@Override
public int hashCode() {
return Objects.hash(id, projectName, schedule, direction, localRepo, localPath, remoteScheme,
remoteUrl, remotePath, remoteBranch, gitignore, credentialId, enabled);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.omitNullValues()
.add("id", id)
.add("enabled", enabled)
.add("projectName", projectName)
.add("schedule", schedule)
.add("direction", direction)
.add("localRepo", localRepo)
.add("localPath", localPath)
.add("remoteScheme", remoteScheme)
.add("remoteUrl", remoteUrl)
.add("remotePath", remotePath)
.add("gitignore", gitignore)
.add("credentialId", credentialId)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.time.Instant;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -34,9 +35,15 @@ public class PushResultDto {
private final Revision revision;
private final String pushedAt;

public PushResultDto(Revision revision, long commitTimeMillis) {
@JsonCreator
public PushResultDto(@JsonProperty("revision") Revision revision,
@JsonProperty("pushedAt") Instant pushedAt) {
this.revision = requireNonNull(revision, "revision");
pushedAt = ISO_INSTANT.format(Instant.ofEpochMilli(commitTimeMillis));
this.pushedAt = ISO_INSTANT.format(pushedAt);
}

public PushResultDto(Revision revision, long commitTimeMillis) {
ikhoon marked this conversation as resolved.
Show resolved Hide resolved
this(revision, Instant.ofEpochMilli(commitTimeMillis));
}

@JsonProperty("revision")
Expand Down
8 changes: 8 additions & 0 deletions dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cron-utils = "9.2.0"
diffutils = "1.3.0"
docker = "9.3.5"
download = "5.5.0"
dropwizard-metrics = "4.2.21"
eddsa = "0.3.0"
findbugs = "3.0.2"
futures-completable = "0.3.5"
Expand Down Expand Up @@ -130,6 +131,11 @@ module = "com.googlecode.java-diff-utils:diffutils"
version.ref = "diffutils"
relocations = { from = "difflib", to = "com.linecorp.centraldogma.internal.shaded.difflib" }

# Used for testing only.
[libraries.dropwizard-metrics-core]
module = "io.dropwizard.metrics:metrics-core"
version.ref = "dropwizard-metrics"

[libraries.eddsa]
module = "net.i2p.crypto:eddsa"
version.ref = "eddsa"
Expand Down Expand Up @@ -185,6 +191,8 @@ module = "com.fasterxml.jackson.core:jackson-databind"
javadocs = "https://fasterxml.github.io/jackson-databind/javadoc/2.13/"
[libraries.jackson-datatype-jsr310]
module = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
[libraries.jackson-datatype-jdk8]
module = "com.fasterxml.jackson.datatype:jackson-datatype-jdk8"

[libraries.javassist]
module = "org.javassist:javassist"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ void afterEach() {
dogma.client()
.forRepo(projName, Project.REPO_META)
.commit("cleanup",
Change.ofRemoval("/credentials.json"),
Change.ofRemoval("/mirrors.json"))
Change.ofRemoval("/credentials/public-key-id.json"),
Change.ofRemoval("/mirrors/foo.json"))
.push().join();
}

Expand Down Expand Up @@ -200,29 +200,32 @@ private static void assertRevisionAndContent(String expectedRevision,
private void pushCredentials(String pubKey, String privKey) {
dogma.client().forRepo(projName, Project.REPO_META)
.commit("Add a mirror",
Change.ofJsonUpsert("/credentials.json",
"[{" +
Change.ofJsonUpsert("/credentials/public-key-id.json",
'{' +
" \"id\": \"public-key-id\"," +
" \"type\": \"public_key\"," +
" \"hostnamePatterns\": [ \"^.*$\" ]," +
" \"username\": \"" + "git" + "\"," +
" \"publicKey\": \"" + pubKey + "\"," +
" \"privateKey\": \"" + privKey + '"' +
"}]")
'}')
).push().join();
}

private void pushMirror(String gitUri, MirrorDirection mirrorDirection) {
dogma.client().forRepo(projName, Project.REPO_META)
.commit("Add a mirror",
Change.ofJsonUpsert("/mirrors.json",
"[{" +
Change.ofJsonUpsert("/mirrors/foo.json",
'{' +
" \"id\": \"foo\"," +
" \"enabled\": true," +
" \"type\": \"single\"," +
" \"direction\": \"" + mirrorDirection.name() + "\"," +
" \"localRepo\": \"" + REPO_FOO + "\"," +
" \"localPath\": \"/\"," +
" \"remoteUri\": \"" + gitUri + "\"," +
" \"schedule\": \"0 0 0 1 1 ? 2099\"" +
"}]"))
'}'))
.push().join();
}
}
Loading