Skip to content

Commit

Permalink
Address comments from @trustin
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoox committed Nov 27, 2024
1 parent 0937af6 commit da93378
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,16 +40,20 @@ public abstract class AbstractPushCommand<T> extends RepositoryCommand<T> {
private final String summary;
private final String detail;
private final Markup markup;
private final List<Change<?>> 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<Change<?>> 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);
}

/**
Expand Down Expand Up @@ -81,6 +88,14 @@ public Markup markup() {
return markup;
}

/**
* Returns the {@link Change}s of the commit.
*/
@JsonProperty
public List<Change<?>> changes() {
return changes;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand All @@ -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
Expand All @@ -110,6 +126,7 @@ ToStringHelper toStringHelper() {
.add("baseRevision", baseRevision)
.add("summary", summary)
.add("detail", detail)
.add("markup", markup);
.add("markup", markup)
.add("changes", changes);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ static Command<CommitResult> 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<CommitResult> 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<CommitResult> 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommitResult> {
public final class NormalizingPushCommand extends AbstractPushCommand<CommitResult> {

@JsonCreator
NormalizingPushCommand(@JsonProperty("timestamp") @Nullable Long timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Revision> {
public final class PushAsIsCommand extends AbstractPushCommand<Revision> {

/**
* Creates a new instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ protected <T> CompletableFuture<T> doExecute(Command<T> command) throws Exceptio
.thenApply(CommitResult::revision);
}

if (command instanceof TransformingContentPushCommand) {
return (CompletableFuture<T>) push((TransformingContentPushCommand) command, true);
if (command instanceof TransformCommand) {
return (CompletableFuture<T>) push((TransformCommand) command, true);
}

if (command instanceof CreateSessionCommand) {
Expand Down Expand Up @@ -292,7 +292,7 @@ private CompletableFuture<Void> purgeRepository(PurgeRepositoryCommand c) {
}, repositoryWorker);
}

private CompletableFuture<CommitResult> push(AbstractPushCommand<?> c, boolean normalizing) {
private CompletableFuture<CommitResult> push(RepositoryCommand<?> c, boolean normalizing) {
if (c.projectName().equals(INTERNAL_PROJECT_DOGMA) || c.repositoryName().equals(Project.REPO_DOGMA) ||
!writeQuotaEnabled()) {
return push0(c, normalizing);
Expand All @@ -309,7 +309,7 @@ private CompletableFuture<CommitResult> push(AbstractPushCommand<?> c, boolean n
}

private CompletableFuture<CommitResult> 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 {
Expand All @@ -318,14 +318,19 @@ private CompletableFuture<CommitResult> tryPush(
}
}

private CompletableFuture<CommitResult> 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<CommitResult> 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<RateLimiter> getRateLimiter(String projectName, String repoName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CommitResult> {
public final class TransformCommand extends RepositoryCommand<CommitResult> {

/**
* 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.
*/
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1326,12 +1326,11 @@ private <T> T blockingExecute(Command<T> command) throws Exception {
final Command<Revision> 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<Revision> pushAsIsCommand = transformingContentPushCommand.asIs(commitResult);
final Command<Revision> pushAsIsCommand = transformCommand.asIs(commitResult);
log = new ReplicationLog<>(replicaId(),
maybeWrap(command, pushAsIsCommand), commitResult.revision());
} else {
Expand Down
Loading

0 comments on commit da93378

Please sign in to comment.