From da93378af1ed79c3dcef586495e122b7ad60f7e3 Mon Sep 17 00:00:00 2001 From: minwoox Date: Wed, 27 Nov 2024 17:53:50 +0900 Subject: [PATCH] Address comments from @trustin --- .../server/command/AbstractPushCommand.java | 25 +++++- .../server/command/ChangesPushCommand.java | 80 ------------------- .../centraldogma/server/command/Command.java | 14 ++-- .../server/command/CommandType.java | 2 +- .../command/NormalizingPushCommand.java | 2 +- .../server/command/PushAsIsCommand.java | 2 +- .../command/StandaloneCommandExecutor.java | 27 ++++--- ...PushCommand.java => TransformCommand.java} | 73 +++++++++++++---- .../replication/ZooKeeperCommandExecutor.java | 9 +-- .../git/AbstractCommitExecutor.java | 2 +- ...pplier.java => DefaultChangesApplier.java} | 4 +- ...ecutor.java => DefaultCommitExecutor.java} | 12 +-- .../storage/repository/git/GitRepository.java | 23 +++--- .../StandaloneCommandExecutorTest.java | 6 +- .../ZooKeeperCommandExecutorTest.java | 24 +++--- 15 files changed, 146 insertions(+), 159 deletions(-) delete mode 100644 server/src/main/java/com/linecorp/centraldogma/server/command/ChangesPushCommand.java rename server/src/main/java/com/linecorp/centraldogma/server/command/{TransformingContentPushCommand.java => TransformCommand.java} (52%) rename server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/{ChangesApplier.java => DefaultChangesApplier.java} (99%) rename server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/{CommitExecutor.java => DefaultCommitExecutor.java} (79%) diff --git a/server/src/main/java/com/linecorp/centraldogma/server/command/AbstractPushCommand.java b/server/src/main/java/com/linecorp/centraldogma/server/command/AbstractPushCommand.java index a8481aade6..b7f83c3a13 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/command/AbstractPushCommand.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/command/AbstractPushCommand.java @@ -17,14 +17,17 @@ import static java.util.Objects.requireNonNull; +import java.util.List; import java.util.Objects; import javax.annotation.Nullable; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.MoreObjects.ToStringHelper; +import com.google.common.collect.ImmutableList; import com.linecorp.centraldogma.common.Author; +import com.linecorp.centraldogma.common.Change; import com.linecorp.centraldogma.common.Markup; import com.linecorp.centraldogma.common.Revision; @@ -37,16 +40,20 @@ public abstract class AbstractPushCommand extends RepositoryCommand { private final String summary; private final String detail; private final Markup markup; + private final List> changes; AbstractPushCommand(CommandType type, @Nullable Long timestamp, @Nullable Author author, String projectName, String repositoryName, Revision baseRevision, - String summary, String detail, Markup markup) { + String summary, String detail, Markup markup, Iterable> changes) { super(type, timestamp, author, projectName, repositoryName); this.baseRevision = requireNonNull(baseRevision, "baseRevision"); this.summary = requireNonNull(summary, "summary"); this.detail = requireNonNull(detail, "detail"); this.markup = requireNonNull(markup, "markup"); + + requireNonNull(changes, "changes"); + this.changes = ImmutableList.copyOf(changes); } /** @@ -81,6 +88,14 @@ public Markup markup() { return markup; } + /** + * Returns the {@link Change}s of the commit. + */ + @JsonProperty + public List> changes() { + return changes; + } + @Override public boolean equals(Object obj) { if (this == obj) { @@ -96,12 +111,13 @@ public boolean equals(Object obj) { baseRevision.equals(that.baseRevision) && summary.equals(that.summary) && detail.equals(that.detail) && - markup == that.markup; + markup == that.markup && + changes.equals(that.changes); } @Override public int hashCode() { - return Objects.hash(baseRevision, summary, detail, markup) * 31 + super.hashCode(); + return Objects.hash(baseRevision, summary, detail, markup, changes) * 31 + super.hashCode(); } @Override @@ -110,6 +126,7 @@ ToStringHelper toStringHelper() { .add("baseRevision", baseRevision) .add("summary", summary) .add("detail", detail) - .add("markup", markup); + .add("markup", markup) + .add("changes", changes); } } diff --git a/server/src/main/java/com/linecorp/centraldogma/server/command/ChangesPushCommand.java b/server/src/main/java/com/linecorp/centraldogma/server/command/ChangesPushCommand.java deleted file mode 100644 index 4a16e21b91..0000000000 --- a/server/src/main/java/com/linecorp/centraldogma/server/command/ChangesPushCommand.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2024 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.server.command; - -import static java.util.Objects.requireNonNull; - -import java.util.List; -import java.util.Objects; - -import javax.annotation.Nullable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.common.base.MoreObjects.ToStringHelper; -import com.google.common.collect.ImmutableList; - -import com.linecorp.centraldogma.common.Author; -import com.linecorp.centraldogma.common.Change; -import com.linecorp.centraldogma.common.Markup; -import com.linecorp.centraldogma.common.Revision; - -/** - * A {@link Command} which is used for pushing changes to the repository. - */ -public abstract class ChangesPushCommand extends AbstractPushCommand { - - private final List> changes; - - ChangesPushCommand(CommandType type, @Nullable Long timestamp, @Nullable Author author, - String projectName, String repositoryName, Revision baseRevision, - String summary, String detail, Markup markup, - Iterable> changes) { - super(type, timestamp, author, projectName, repositoryName, baseRevision, summary, detail, markup); - this.changes = ImmutableList.copyOf(requireNonNull(changes, "changes")); - } - - /** - * Returns the {@link Change}s of the commit. - */ - @JsonProperty - public List> changes() { - return changes; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (!(obj instanceof ChangesPushCommand)) { - return false; - } - - final ChangesPushCommand that = (ChangesPushCommand) obj; - return super.equals(that) && changes.equals(that.changes); - } - - @Override - public int hashCode() { - return Objects.hash(changes) * 31 + super.hashCode(); - } - - @Override - ToStringHelper toStringHelper() { - return super.toStringHelper().add("changes", changes); - } -} diff --git a/server/src/main/java/com/linecorp/centraldogma/server/command/Command.java b/server/src/main/java/com/linecorp/centraldogma/server/command/Command.java index 00e9c9a9c4..930cc2bd6f 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/command/Command.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/command/Command.java @@ -347,13 +347,13 @@ static Command push(@Nullable Long timestamp, Author author, * You can find the normalized changes from the {@link CommitResult#changes()} that is the result of * {@link CommandExecutor#execute(Command)}. */ - static Command transformingContentPush(@Nullable Long timestamp, Author author, - String projectName, String repositoryName, - Revision baseRevision, String summary, - String detail, Markup markup, - ContentTransformer transformer) { - return TransformingContentPushCommand.of(timestamp, author, projectName, repositoryName, - baseRevision, summary, detail, markup, transformer); + static Command transform(@Nullable Long timestamp, Author author, + String projectName, String repositoryName, + Revision baseRevision, String summary, + String detail, Markup markup, + ContentTransformer transformer) { + return TransformCommand.of(timestamp, author, projectName, repositoryName, + baseRevision, summary, detail, markup, transformer); } /** diff --git a/server/src/main/java/com/linecorp/centraldogma/server/command/CommandType.java b/server/src/main/java/com/linecorp/centraldogma/server/command/CommandType.java index ddbb5fb9da..f9a599cf9a 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/command/CommandType.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/command/CommandType.java @@ -29,7 +29,7 @@ public enum CommandType { REMOVE_REPOSITORY(Void.class), UNREMOVE_REPOSITORY(Void.class), NORMALIZING_PUSH(CommitResult.class), - TRANSFORMING_CONTENT_PUSH(CommitResult.class), + TRANSFORM(CommitResult.class), PUSH(Revision.class), SAVE_NAMED_QUERY(Void.class), REMOVE_NAMED_QUERY(Void.class), diff --git a/server/src/main/java/com/linecorp/centraldogma/server/command/NormalizingPushCommand.java b/server/src/main/java/com/linecorp/centraldogma/server/command/NormalizingPushCommand.java index 976c23ac27..33756196bc 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/command/NormalizingPushCommand.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/command/NormalizingPushCommand.java @@ -34,7 +34,7 @@ * You can find the normalized changes from the {@link CommitResult#changes()} that is the result of * {@link CommandExecutor#execute(Command)}. */ -public final class NormalizingPushCommand extends ChangesPushCommand { +public final class NormalizingPushCommand extends AbstractPushCommand { @JsonCreator NormalizingPushCommand(@JsonProperty("timestamp") @Nullable Long timestamp, diff --git a/server/src/main/java/com/linecorp/centraldogma/server/command/PushAsIsCommand.java b/server/src/main/java/com/linecorp/centraldogma/server/command/PushAsIsCommand.java index 4725e9e51c..3ac1352a0a 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/command/PushAsIsCommand.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/command/PushAsIsCommand.java @@ -30,7 +30,7 @@ * Unlike {@link NormalizingPushCommand}, the changes of this {@link Command} * are not normalized and applied as they are. */ -public final class PushAsIsCommand extends ChangesPushCommand { +public final class PushAsIsCommand extends AbstractPushCommand { /** * Creates a new instance. diff --git a/server/src/main/java/com/linecorp/centraldogma/server/command/StandaloneCommandExecutor.java b/server/src/main/java/com/linecorp/centraldogma/server/command/StandaloneCommandExecutor.java index be5ca6af78..b1cd02f3ec 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/command/StandaloneCommandExecutor.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/command/StandaloneCommandExecutor.java @@ -205,8 +205,8 @@ protected CompletableFuture doExecute(Command command) throws Exceptio .thenApply(CommitResult::revision); } - if (command instanceof TransformingContentPushCommand) { - return (CompletableFuture) push((TransformingContentPushCommand) command, true); + if (command instanceof TransformCommand) { + return (CompletableFuture) push((TransformCommand) command, true); } if (command instanceof CreateSessionCommand) { @@ -292,7 +292,7 @@ private CompletableFuture purgeRepository(PurgeRepositoryCommand c) { }, repositoryWorker); } - private CompletableFuture push(AbstractPushCommand c, boolean normalizing) { + private CompletableFuture push(RepositoryCommand c, boolean normalizing) { if (c.projectName().equals(INTERNAL_PROJECT_DOGMA) || c.repositoryName().equals(Project.REPO_DOGMA) || !writeQuotaEnabled()) { return push0(c, normalizing); @@ -309,7 +309,7 @@ private CompletableFuture push(AbstractPushCommand c, boolean n } private CompletableFuture tryPush( - AbstractPushCommand c, boolean normalizing, @Nullable RateLimiter rateLimiter) { + RepositoryCommand c, boolean normalizing, @Nullable RateLimiter rateLimiter) { if (rateLimiter == null || rateLimiter == UNLIMITED || rateLimiter.tryAcquire()) { return push0(c, normalizing); } else { @@ -318,14 +318,19 @@ private CompletableFuture tryPush( } } - private CompletableFuture push0(AbstractPushCommand c, boolean normalizing) { - if (c instanceof ChangesPushCommand) { - return repo(c).commit(c.baseRevision(), c.timestamp(), c.author(), c.summary(), c.detail(), - c.markup(), ((ChangesPushCommand) c).changes(), normalizing); + private CompletableFuture push0(RepositoryCommand c, boolean normalizing) { + if (c instanceof TransformCommand) { + final TransformCommand transformCommand = (TransformCommand) c; + return repo(c).commit(transformCommand.baseRevision(), transformCommand.timestamp(), + transformCommand.author(), transformCommand.summary(), + transformCommand.detail(), transformCommand.markup(), + transformCommand.transformer()); } - assert c instanceof TransformingContentPushCommand; - return repo(c).commit(c.baseRevision(), c.timestamp(), c.author(), c.summary(), c.detail(), c.markup(), - ((TransformingContentPushCommand) c).transformer()); + assert c instanceof AbstractPushCommand; + final AbstractPushCommand pushCommand = (AbstractPushCommand) c; + return repo(c).commit(pushCommand.baseRevision(), pushCommand.timestamp(), pushCommand.author(), + pushCommand.summary(), pushCommand.detail(), pushCommand.markup(), + pushCommand.changes(), normalizing); } private CompletableFuture getRateLimiter(String projectName, String repoName) { diff --git a/server/src/main/java/com/linecorp/centraldogma/server/command/TransformingContentPushCommand.java b/server/src/main/java/com/linecorp/centraldogma/server/command/TransformCommand.java similarity index 52% rename from server/src/main/java/com/linecorp/centraldogma/server/command/TransformingContentPushCommand.java rename to server/src/main/java/com/linecorp/centraldogma/server/command/TransformCommand.java index b6bf3a4ed4..73803fc3fb 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/command/TransformingContentPushCommand.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/command/TransformCommand.java @@ -19,6 +19,8 @@ import javax.annotation.Nullable; +import com.fasterxml.jackson.annotation.JsonProperty; + import com.linecorp.centraldogma.common.Author; import com.linecorp.centraldogma.common.Markup; import com.linecorp.centraldogma.common.Revision; @@ -29,31 +31,70 @@ * You can find the normalized changes from the {@link CommitResult#changes()} that is the result of * {@link CommandExecutor#execute(Command)}. Note that this command is not serialized and deserialized. */ -public final class TransformingContentPushCommand extends AbstractPushCommand { +public final class TransformCommand extends RepositoryCommand { /** * Creates a new instance. */ - public static TransformingContentPushCommand of(@Nullable Long timestamp, - @Nullable Author author, String projectName, - String repositoryName, Revision baseRevision, - String summary, String detail, Markup markup, - ContentTransformer transformer) { - return new TransformingContentPushCommand(timestamp, author, projectName, repositoryName, - baseRevision, summary, detail, markup, transformer); + public static TransformCommand of(@Nullable Long timestamp, + @Nullable Author author, String projectName, + String repositoryName, Revision baseRevision, + String summary, String detail, Markup markup, + ContentTransformer transformer) { + return new TransformCommand(timestamp, author, projectName, repositoryName, + baseRevision, summary, detail, markup, transformer); } + private final Revision baseRevision; + private final String summary; + private final String detail; + private final Markup markup; private final ContentTransformer transformer; - private TransformingContentPushCommand(@Nullable Long timestamp, @Nullable Author author, - String projectName, String repositoryName, Revision baseRevision, - String summary, String detail, Markup markup, - ContentTransformer transformer) { - super(CommandType.TRANSFORMING_CONTENT_PUSH, timestamp, author, - projectName, repositoryName, baseRevision, summary, detail, markup); + private TransformCommand(@Nullable Long timestamp, @Nullable Author author, + String projectName, String repositoryName, Revision baseRevision, + String summary, String detail, Markup markup, + ContentTransformer transformer) { + super(CommandType.TRANSFORM, timestamp, author, projectName, repositoryName); + this.baseRevision = baseRevision; + this.summary = summary; + this.detail = detail; + this.markup = markup; this.transformer = transformer; } + /** + * Returns the base {@link Revision}. + */ + @JsonProperty + public Revision baseRevision() { + return baseRevision; + } + + /** + * Returns the human-readable summary of the commit. + */ + @JsonProperty + public String summary() { + return summary; + } + + /** + * Returns the human-readable detail of the commit. + */ + @JsonProperty + public String detail() { + return detail; + } + + /** + * Returns the {@link Markup} of the {@link #detail()}. + */ + @JsonProperty + public Markup markup() { + return markup; + } + /** * Returns the {@link ContentTransformer} which is used for transforming the content. */ @@ -62,8 +103,8 @@ public ContentTransformer transformer() { } /** - * Returns a new {@link PushAsIsCommand} which is converted from this {@link TransformingContentPushCommand} - * for replicating to other replicas. Unlike the {@link TransformingContentPushCommand}, + * Returns a new {@link PushAsIsCommand} which is converted from this {@link TransformCommand} + * for replicating to other replicas. Unlike the {@link TransformCommand}, * the changes of this {@link Command} are not normalized and applied as they are. */ public PushAsIsCommand asIs(CommitResult commitResult) { diff --git a/server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java b/server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java index f0a8d4a37d..145407e772 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java @@ -106,7 +106,7 @@ import com.linecorp.centraldogma.server.command.ForcePushCommand; import com.linecorp.centraldogma.server.command.NormalizingPushCommand; import com.linecorp.centraldogma.server.command.RemoveRepositoryCommand; -import com.linecorp.centraldogma.server.command.TransformingContentPushCommand; +import com.linecorp.centraldogma.server.command.TransformCommand; import com.linecorp.centraldogma.server.command.UpdateServerStatusCommand; import com.linecorp.centraldogma.server.metadata.MetadataService; import com.linecorp.centraldogma.server.metadata.RepositoryMetadata; @@ -1326,12 +1326,11 @@ private T blockingExecute(Command command) throws Exception { final Command pushAsIsCommand = normalizingPushCommand.asIs(commitResult); log = new ReplicationLog<>(replicaId(), maybeWrap(command, pushAsIsCommand), commitResult.revision()); - } else if (maybeUnwrapped.type() == CommandType.TRANSFORMING_CONTENT_PUSH) { - final TransformingContentPushCommand transformingContentPushCommand = - (TransformingContentPushCommand) maybeUnwrapped; + } else if (maybeUnwrapped.type() == CommandType.TRANSFORM) { + final TransformCommand transformCommand = (TransformCommand) maybeUnwrapped; assert result instanceof CommitResult : result; final CommitResult commitResult = (CommitResult) result; - final Command pushAsIsCommand = transformingContentPushCommand.asIs(commitResult); + final Command pushAsIsCommand = transformCommand.asIs(commitResult); log = new ReplicationLog<>(replicaId(), maybeWrap(command, pushAsIsCommand), commitResult.revision()); } else { diff --git a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/AbstractCommitExecutor.java b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/AbstractCommitExecutor.java index cad00da11e..19e029a558 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/AbstractCommitExecutor.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/AbstractCommitExecutor.java @@ -133,7 +133,7 @@ RevisionAndEntries commit(@Nullable Revision prevRevision, Revision nextRevision final DirCache dirCache = DirCache.newInCore(); // Apply the changes and retrieve the list of the affected files. - final int numEdits = new ChangesApplier(changes) + final int numEdits = new DefaultChangesApplier(changes) .apply(jGitRepository, prevRevision, prevTreeId, dirCache); // Reject empty commit if necessary. diff --git a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/ChangesApplier.java b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/DefaultChangesApplier.java similarity index 99% rename from server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/ChangesApplier.java rename to server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/DefaultChangesApplier.java index 5f32beea66..269f7a66f6 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/ChangesApplier.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/DefaultChangesApplier.java @@ -49,11 +49,11 @@ import difflib.DiffUtils; import difflib.Patch; -final class ChangesApplier extends AbstractChangesApplier { +final class DefaultChangesApplier extends AbstractChangesApplier { private final Iterable> changes; - ChangesApplier(Iterable> changes) { + DefaultChangesApplier(Iterable> changes) { this.changes = changes; } diff --git a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/CommitExecutor.java b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/DefaultCommitExecutor.java similarity index 79% rename from server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/CommitExecutor.java rename to server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/DefaultCommitExecutor.java index f3d03e2ef0..e836731907 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/CommitExecutor.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/DefaultCommitExecutor.java @@ -20,14 +20,14 @@ import com.linecorp.centraldogma.common.Markup; import com.linecorp.centraldogma.common.Revision; -final class CommitExecutor extends AbstractCommitExecutor { +final class DefaultCommitExecutor extends AbstractCommitExecutor { private final boolean directExecution; private final Iterable> changes; - CommitExecutor(GitRepository gitRepository, long commitTimeMillis, - Author author, String summary, String detail, - Markup markup, boolean allowEmptyCommit, - boolean directExecution, Iterable> changes) { + DefaultCommitExecutor(GitRepository gitRepository, long commitTimeMillis, + Author author, String summary, String detail, + Markup markup, boolean allowEmptyCommit, + boolean directExecution, Iterable> changes) { super(gitRepository, commitTimeMillis, author, summary, detail, markup, allowEmptyCommit); this.directExecution = directExecution; this.changes = changes; @@ -42,7 +42,7 @@ Iterable> getOrCreateApplyingChanges(Revision normBaseRevision) { if (!directExecution) { return changes; } - return gitRepository.blockingPreviewDiff(normBaseRevision, new ChangesApplier(changes)) + return gitRepository.blockingPreviewDiff(normBaseRevision, new DefaultChangesApplier(changes)) .values(); } } diff --git a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java index d2ea00609d..04f8a9e9fb 100644 --- a/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java +++ b/server/src/main/java/com/linecorp/centraldogma/server/internal/storage/repository/git/GitRepository.java @@ -246,8 +246,9 @@ class GitRepository implements Repository { // Initialize the commit ID database. commitIdDatabase = new CommitIdDatabase(jGitRepository); - new CommitExecutor(this, creationTimeMillis, author,"Create a new repository", "", Markup.PLAINTEXT, - true, false, Collections.emptyList()).executeInitialCommit(); + new DefaultCommitExecutor(this, creationTimeMillis, author, "Create a new repository", "", + Markup.PLAINTEXT, true, false, Collections.emptyList()) + .executeInitialCommit(); headRevision = Revision.INIT; success = true; @@ -712,7 +713,7 @@ public CompletableFuture>> previewDiff(Revision baseRevisi final ServiceRequestContext ctx = context(); return CompletableFuture.supplyAsync(() -> { failFastIfTimedOut(this, logger, ctx, "previewDiff", baseRevision); - return blockingPreviewDiff(baseRevision, new ChangesApplier(changes)); + return blockingPreviewDiff(baseRevision, new DefaultChangesApplier(changes)); }, repositoryWorker); } @@ -852,9 +853,9 @@ public CompletableFuture commit( requireNonNull(detail, "detail"); requireNonNull(markup, "markup"); requireNonNull(changes, "changes"); - final CommitExecutor commitExecutor = - new CommitExecutor(this, commitTimeMillis, author, summary, detail, - markup, false, directExecution, changes); + final DefaultCommitExecutor commitExecutor = + new DefaultCommitExecutor(this, commitTimeMillis, author, summary, detail, + markup, false, directExecution, changes); return commit(baseRevision, commitExecutor); } @@ -1305,14 +1306,16 @@ public void cloneTo(File newRepoDir, BiConsumer progressListen diff(previousNonEmptyRevision, revision, ALL_PATH).join().values(); try { - new CommitExecutor(newRepo, c.when(), c.author(), c.summary(), c.detail(), c.markup(), - false, false, changes).execute(baseRevision); + new DefaultCommitExecutor(newRepo, c.when(), c.author(), c.summary(), + c.detail(), c.markup(), false, false, changes) + .execute(baseRevision); previousNonEmptyRevision = revision; } catch (RedundantChangeException e) { // NB: We allow an empty commit here because an old version of Central Dogma had a bug // which allowed the creation of an empty commit. - new CommitExecutor(newRepo, c.when(), c.author(), c.summary(), c.detail(), c.markup(), - true, false, changes).execute(baseRevision); + new DefaultCommitExecutor(newRepo, c.when(), c.author(), c.summary(), + c.detail(), c.markup(), true, false, changes) + .execute(baseRevision); } progressListener.accept(i, endRevision.major()); diff --git a/server/src/test/java/com/linecorp/centraldogma/server/command/StandaloneCommandExecutorTest.java b/server/src/test/java/com/linecorp/centraldogma/server/command/StandaloneCommandExecutorTest.java index 7b42b97362..6c913bf9e2 100644 --- a/server/src/test/java/com/linecorp/centraldogma/server/command/StandaloneCommandExecutorTest.java +++ b/server/src/test/java/com/linecorp/centraldogma/server/command/StandaloneCommandExecutorTest.java @@ -151,6 +151,8 @@ void shouldPerformAdministrativeCommandWithReadOnly() throws JsonParseException .join() .contentAsJson(); assertThat(json.get("a").asText()).isEqualTo("b"); + executor.execute(Command.updateServerStatus(ServerStatus.WRITABLE)).join(); + assertThat(executor.isWritable()).isTrue(); } @Test @@ -174,7 +176,7 @@ void createInternalProject() { } @Test - void transformingContentPushCommandConvertedIntoJsonPatch() { + void transformCommandConvertedIntoJsonPatch() { final StandaloneCommandExecutor executor = (StandaloneCommandExecutor) extension.executor(); // Initial commit. @@ -198,7 +200,7 @@ void transformingContentPushCommandConvertedIntoJsonPatch() { new ContentTransformer<>("/bar.json", EntryType.JSON, transformer); commitResult = - executor.execute(Command.transformingContentPush( + executor.execute(Command.transform( null, Author.SYSTEM, TEST_PRJ, TEST_REPO2, Revision.HEAD, "", "", Markup.PLAINTEXT, contentTransformer)).join(); diff --git a/server/src/test/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutorTest.java b/server/src/test/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutorTest.java index 512b19b418..e3f10e9ac5 100644 --- a/server/src/test/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutorTest.java +++ b/server/src/test/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutorTest.java @@ -76,7 +76,7 @@ import com.linecorp.centraldogma.server.command.ForcePushCommand; import com.linecorp.centraldogma.server.command.NormalizingPushCommand; import com.linecorp.centraldogma.server.command.PushAsIsCommand; -import com.linecorp.centraldogma.server.command.TransformingContentPushCommand; +import com.linecorp.centraldogma.server.command.TransformCommand; import com.linecorp.centraldogma.server.management.ServerStatus; import com.linecorp.centraldogma.testing.internal.FlakyTest; @@ -384,17 +384,17 @@ private static PushAsIsCommand executeCommand(Replica replica1, boolean normaliz }; final ContentTransformer contentTransformer = new ContentTransformer<>( pushChange.path(), EntryType.JSON, transformer); - final Command transformingContentPushCommand = - Command.transformingContentPush(0L, Author.SYSTEM, "project", "repo1", new Revision(1), - "summary", "detail", - Markup.PLAINTEXT, contentTransformer); + final Command transformCommand = + Command.transform(0L, Author.SYSTEM, "project", "repo1", new Revision(1), + "summary", "detail", + Markup.PLAINTEXT, contentTransformer); - assert transformingContentPushCommand instanceof TransformingContentPushCommand; + assert transformCommand instanceof TransformCommand; final PushAsIsCommand asIsCommand = - ((TransformingContentPushCommand) transformingContentPushCommand).asIs( + ((TransformCommand) transformCommand).asIs( CommitResult.of(new Revision(2), ImmutableList.of(normalizedChange))); - assertThat(replica1.commandExecutor().execute(transformingContentPushCommand).join().revision()) + assertThat(replica1.commandExecutor().execute(transformCommand).join().revision()) .isEqualTo(new Revision(2)); return asIsCommand; } @@ -679,10 +679,10 @@ static Function, CompletableFuture> newMockDelegate() { } } - if (argument instanceof TransformingContentPushCommand) { - final TransformingContentPushCommand pushCommand = - (TransformingContentPushCommand) argument; - assertThat(pushCommand.type()).isSameAs(CommandType.TRANSFORMING_CONTENT_PUSH); + if (argument instanceof TransformCommand) { + final TransformCommand pushCommand = + (TransformCommand) argument; + assertThat(pushCommand.type()).isSameAs(CommandType.TRANSFORM); final Function transformer = (Function) pushCommand.transformer().transformer(); final JsonNode applied = transformer.apply(pushChange.content());