forked from line/centraldogma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a way to pin a mirror to a zone (line#1062)
Motivation: I propose running the mirror in a zone close to the git server or only in zones that are allowed access. Modifications: - Add `zone` as an optional property to mirror configurations. - Add `GET /api/v1/mirror/config` API to provide zone-related configurations. - The API is used to select a pinned zone on the mirror form. - Add `zonePinned` flag to `MirroringServicePluginConfig` to enable zone-pinned mirroring. - The option is disabled by default. - `DefaultMirroringServicePlugin.target()` returns `PluginTarget.ZONE_LEADER_ONLY` if `zonePinned == true` - Fixed `MirrorSchedulingService` to only run a pinned zone if `zonePinned == true` - Add `ZoneConfig` to replace `zone: string` configuration. - `allZones` is newly added to specify the list of zone names. - Breaking) Make `Plugin.target()` take `CentralDogmaConfig` as an argument. Result: You can now specify a zone where you want to perform mirroring.
- Loading branch information
Showing
57 changed files
with
985 additions
and
169 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
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
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
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
78 changes: 78 additions & 0 deletions
78
...or/src/test/java/com/linecorp/centraldogma/it/mirror/git/TestZoneAwareMirrorListener.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,78 @@ | ||
/* | ||
* 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.it.mirror.git; | ||
|
||
import static com.google.common.base.MoreObjects.firstNonNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.linecorp.centraldogma.server.mirror.MirrorListener; | ||
import com.linecorp.centraldogma.server.mirror.MirrorResult; | ||
import com.linecorp.centraldogma.server.mirror.MirrorTask; | ||
|
||
public class TestZoneAwareMirrorListener implements MirrorListener { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(TestZoneAwareMirrorListener.class); | ||
|
||
static final Map<String, Integer> startCount = new ConcurrentHashMap<>(); | ||
static final Map<String, List<MirrorResult>> completions = new ConcurrentHashMap<>(); | ||
static final Map<String, List<Throwable>> errors = new ConcurrentHashMap<>(); | ||
|
||
static void reset() { | ||
startCount.clear(); | ||
completions.clear(); | ||
errors.clear(); | ||
} | ||
|
||
private static String key(MirrorTask task) { | ||
return firstNonNull(task.currentZone(), "default"); | ||
} | ||
|
||
@Override | ||
public void onStart(MirrorTask mirror) { | ||
logger.debug("onStart: {}", mirror); | ||
startCount.merge(key(mirror), 1, Integer::sum); | ||
} | ||
|
||
@Override | ||
public void onComplete(MirrorTask mirror, MirrorResult result) { | ||
logger.debug("onComplete: {} -> {}", mirror, result); | ||
final List<MirrorResult> results = new ArrayList<>(); | ||
results.add(result); | ||
completions.merge(key(mirror), results, (oldValue, newValue) -> { | ||
oldValue.addAll(newValue); | ||
return oldValue; | ||
}); | ||
} | ||
|
||
@Override | ||
public void onError(MirrorTask mirror, Throwable cause) { | ||
logger.debug("onError: {}", mirror, cause); | ||
final List<Throwable> exceptions = new ArrayList<>(); | ||
exceptions.add(cause); | ||
errors.merge(key(mirror), exceptions, (oldValue, newValue) -> { | ||
oldValue.addAll(newValue); | ||
return oldValue; | ||
}); | ||
} | ||
} |
Oops, something went wrong.