-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
11 changed files
with
389 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
server/src/main/java/com/linecorp/centraldogma/server/command/AdministrativeCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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.server.command; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import com.linecorp.centraldogma.common.Author; | ||
|
||
abstract class AdministrativeCommand<T> extends RootCommand<T> { | ||
AdministrativeCommand(CommandType commandType, @Nullable Long timestamp, | ||
@Nullable Author author) { | ||
super(commandType, timestamp, author); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
server/src/main/java/com/linecorp/centraldogma/server/command/ForcePushCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.server.command; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.MoreObjects.ToStringHelper; | ||
|
||
/** | ||
* A {@link Command} which is used to force-push {@code delegate} even the server is in read-only mode. | ||
* This command is useful for migrating the repository content during maintenance mode. | ||
*/ | ||
public final class ForcePushCommand<T> extends AdministrativeCommand<T> { | ||
|
||
private final Command<T> delegate; | ||
|
||
@JsonCreator | ||
ForcePushCommand(@JsonProperty("delegate") Command<T> delegate) { | ||
super(CommandType.FORCE_PUSH, requireNonNull(delegate, "delegate").timestamp(), delegate.author()); | ||
this.delegate = delegate; | ||
} | ||
|
||
/** | ||
* Returns the {@link Command} to be force-pushed. | ||
*/ | ||
@JsonProperty("delegate") | ||
public Command<T> delegate() { | ||
return delegate; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof ForcePushCommand)) { | ||
return false; | ||
} | ||
final ForcePushCommand<?> that = (ForcePushCommand<?>) o; | ||
return super.equals(that) && delegate.equals(that.delegate); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return super.hashCode() * 31 + delegate.hashCode(); | ||
} | ||
|
||
@Override | ||
ToStringHelper toStringHelper() { | ||
return super.toStringHelper().add("delegate", delegate); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
server/src/main/java/com/linecorp/centraldogma/server/command/UpdateServerStatusCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* 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.server.command; | ||
|
||
import java.util.Objects; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.google.common.base.MoreObjects.ToStringHelper; | ||
|
||
import com.linecorp.centraldogma.common.Author; | ||
|
||
/** | ||
* A {@link Command} which is used to update the status of all servers in the cluster. | ||
*/ | ||
public final class UpdateServerStatusCommand extends AdministrativeCommand<Void> { | ||
|
||
private final boolean writable; | ||
|
||
@JsonCreator | ||
UpdateServerStatusCommand(@JsonProperty("timestamp") @Nullable Long timestamp, | ||
@JsonProperty("author") @Nullable Author author, | ||
@JsonProperty("writable") boolean writable) { | ||
super(CommandType.UPDATE_SERVER_STATUS, timestamp, author); | ||
this.writable = writable; | ||
} | ||
|
||
/** | ||
* Returns whether the cluster is writable. | ||
*/ | ||
@JsonProperty("writable") | ||
public boolean writable() { | ||
return writable; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof UpdateServerStatusCommand)) { | ||
return false; | ||
} | ||
final UpdateServerStatusCommand that = (UpdateServerStatusCommand) o; | ||
|
||
return super.equals(that) && writable == that.writable; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), writable); | ||
} | ||
|
||
@Override | ||
ToStringHelper toStringHelper() { | ||
return super.toStringHelper() | ||
.add("writable", writable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.