mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(codeartifact): release a deleted repository's Maven storage (#4210)
DeleteRepository never cleaned up the Reposilite-side storage of a deleted repository; it was left behind, wasting space over a long-running process. Reposilite has no bulk-delete endpoint, but DELETE on a path recursively removes everything under it in one call, so this deletes each of the repository's top-level entries before removing it from the shared settings list, verified against a live instance. Order matters: the repository must stay registered while its files are deleted, since Reposilite 404s every path, including DELETE, for an id absent from its settings. Release is best-effort: the CodeArtifact-side metadata delete already committed by the time it runs, matching real CodeArtifact's own DeleteRepository (synchronous, always succeeds once the repository exists). A sidecar that is unreachable must not turn an already-successful delete into a 500, and must not leave the repository stuck, since a retry would just 404 against the already-deleted record. Introduces RepositorySidecarManager, a small interface every per-format sidecar can implement, and CodeArtifactSidecarRegistry, which discovers implementations via CDI. CodeArtifactService.deleteRepository releases storage generically over whatever formats a repository has sidecar ids for, so a future format's sidecar needs no change here. Reposilite is the first and only implementation for now; CodeArtifactRepository's mavenRepositoryId field becomes a sidecarContainerIds map for the same reason.
This commit is contained in:
1 parent
b986b95074
commit
94fc4c45bb
13 files changed
+561
-55
No files matched your search
@@ -87,7 +87,10 @@ on first use and reuses for every CodeArtifact repository; a CodeArtifact reposi
|
||||
own Reposilite repository, provisioned automatically the first time it is published to or fetched
|
||||
from, and identified internally by a fresh id generated at `CreateRepository` time rather than a
|
||||
name derived from the domain/repository, so a repository deleted and recreated under the same name
|
||||
never inherits the previous one's artifacts. Two config knobs,
|
||||
never inherits the previous one's artifacts. `DeleteRepository` also releases that storage:
|
||||
Reposilite has no bulk-delete endpoint, so this deletes each of the repository's top-level entries
|
||||
(DELETE recursively removes everything under a path in one call) before removing it from the
|
||||
shared settings list. Two config knobs,
|
||||
`FLOCI_SERVICES_CODEARTIFACT_MAVEN_IMAGE` and `FLOCI_SERVICES_CODEARTIFACT_MAVEN_URL`, pin the
|
||||
image version or point at an already-running instance and skip container management, matching the
|
||||
pattern used elsewhere in Floci for sidecars.
|
||||
@@ -132,16 +135,11 @@ state.
|
||||
runs. The rejection (`ServiceQuotaExceededException` from `PublishPackageVersion`, HTTP 413 from
|
||||
the Maven endpoint) is correct for anything that does fit in memory; it is not itself a streaming
|
||||
size limit.
|
||||
- **Deleting a CodeArtifact repository does not remove its Maven artifacts.** The backing
|
||||
Reposilite repository and everything published to it are left behind (though never reused: see
|
||||
above); only the CodeArtifact-side metadata is deleted. This wastes storage inside the sidecar
|
||||
container over a long-running Floci process but is otherwise inert, since a deleted repository's
|
||||
endpoint already returns 404 through the proxy regardless of what Reposilite still holds.
|
||||
- **Maven artifacts do not survive a Floci restart, even under persistent storage.** The Reposilite
|
||||
sidecar container has no volume attached and is removed on shutdown along with everything
|
||||
published to it. CodeArtifact repository/domain metadata (including the stored
|
||||
`mavenRepositoryId`) survives a restart the same way any other Floci state does under persistent
|
||||
storage mode; the artifacts themselves do not, so the first Maven request after a restart
|
||||
published to it. CodeArtifact repository/domain metadata (including the stored sidecar container
|
||||
id) survives a restart the same way any other Floci state does under persistent storage mode;
|
||||
the artifacts themselves do not, so the first Maven request after a restart
|
||||
re-provisions an empty Reposilite repository and returns 404 for anything published before the
|
||||
restart.
|
||||
- **`GetAuthorizationToken` tokens are not revocable and are not tied to any IAM identity.** Real
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ public class CodeArtifactMavenController {
|
||||
.orElseThrow(() -> new NotAuthorizedException("Basic realm=\"floci-codeartifact\""));
|
||||
String repoId;
|
||||
try {
|
||||
repoId = service.ensureMavenRepositoryId(scope.region(), domain, scope.owner(), repository);
|
||||
repoId = service.ensureFormatContainerId("maven", scope.region(), domain, scope.owner(), repository);
|
||||
} catch (AwsException e) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
+59
-17
@@ -64,6 +64,14 @@ public class CodeArtifactService implements Resettable {
|
||||
private static final Set<String> PACKAGE_FORMATS =
|
||||
Set.of("npm", "pypi", "maven", "nuget", "generic", "ruby", "swift", "cargo");
|
||||
private static final Set<String> ENDPOINT_TYPES = Set.of("dualstack", "ipv4");
|
||||
/**
|
||||
* Formats served by a real package-manager-protocol proxy backed by a per-format sidecar, and
|
||||
* so need an {@link #ensureFormatContainerId} entry assigned at creation. Adding the next
|
||||
* format's proxy only needs a new entry here; {@link CodeArtifactRepository#getSidecarContainerIds()}
|
||||
* and the backfill in {@link #ensureFormatContainerId} already handle it, including for
|
||||
* repositories created before that format's proxy existed.
|
||||
*/
|
||||
private static final List<String> CONTAINER_BACKED_FORMATS = List.of("maven");
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(CodeArtifactService.class);
|
||||
|
||||
@@ -101,6 +109,7 @@ public class CodeArtifactService implements Resettable {
|
||||
private final AccountAwareStorageBackend<CodeArtifactPackageVersion> packageVersions;
|
||||
private final RegionResolver regionResolver;
|
||||
private final EmulatorConfig config;
|
||||
private final CodeArtifactSidecarRegistry sidecarRegistry;
|
||||
// Asset bytes never go through the JSON/WAL-backed `packageVersions` store (see PackageAsset's
|
||||
// @JsonIgnore content field): they're kept here instead, on disk in persistent/hybrid/wal mode
|
||||
// or in this map in memory mode, so a publish only ever rewrites metadata.
|
||||
@@ -113,7 +122,7 @@ public class CodeArtifactService implements Resettable {
|
||||
|
||||
@Inject
|
||||
public CodeArtifactService(StorageFactory storageFactory, RegionResolver regionResolver, EmulatorConfig config,
|
||||
ServiceConfigAccess serviceConfigAccess) {
|
||||
ServiceConfigAccess serviceConfigAccess, CodeArtifactSidecarRegistry sidecarRegistry) {
|
||||
this(
|
||||
storageFactory.create("codeartifact", "codeartifact-domains.json",
|
||||
new TypeReference<Map<String, CodeArtifactDomain>>() {}),
|
||||
@@ -123,7 +132,8 @@ public class CodeArtifactService implements Resettable {
|
||||
new TypeReference<Map<String, CodeArtifactPackageVersion>>() {}),
|
||||
regionResolver, config,
|
||||
"memory".equals(serviceConfigAccess.storageMode("codeartifact")),
|
||||
Path.of(config.storage().persistentPath()).resolve(ASSET_STORAGE_DIR));
|
||||
Path.of(config.storage().persistentPath()).resolve(ASSET_STORAGE_DIR),
|
||||
sidecarRegistry);
|
||||
}
|
||||
|
||||
/** Package-private constructor for testing. */
|
||||
@@ -131,12 +141,13 @@ public class CodeArtifactService implements Resettable {
|
||||
AccountAwareStorageBackend<CodeArtifactRepository> repositories,
|
||||
AccountAwareStorageBackend<CodeArtifactPackageVersion> packageVersions,
|
||||
RegionResolver regionResolver, EmulatorConfig config,
|
||||
boolean inMemory, Path assetRoot) {
|
||||
boolean inMemory, Path assetRoot, CodeArtifactSidecarRegistry sidecarRegistry) {
|
||||
this.domains = domains;
|
||||
this.repositories = repositories;
|
||||
this.packageVersions = packageVersions;
|
||||
this.regionResolver = regionResolver;
|
||||
this.config = config;
|
||||
this.sidecarRegistry = sidecarRegistry;
|
||||
this.inMemory = inMemory;
|
||||
this.assetRoot = assetRoot;
|
||||
if (!inMemory) {
|
||||
@@ -280,11 +291,17 @@ public class CodeArtifactService implements Resettable {
|
||||
r.setUpstreams(upstreams != null ? new ArrayList<>(upstreams) : new ArrayList<>());
|
||||
r.setCreatedTime(Instant.now().getEpochSecond());
|
||||
r.setTags(validateTags(tags, Map.of(), repository, "repository"));
|
||||
// A bare UUID, not a domain/repository-derived name: Reposilite rejects any repository id
|
||||
// over 64 characters, and CodeArtifact domain (max 50) and repository (max 100) names can
|
||||
// easily exceed that combined. The id is purely internal and never surfaced by the public
|
||||
// API, so readability doesn't matter here, only fitting the limit and staying unique.
|
||||
r.setMavenRepositoryId(newRevision());
|
||||
// A bare UUID per container-backed format, not a domain/repository-derived name:
|
||||
// Reposilite rejects any repository id over 64 characters, and CodeArtifact domain (max
|
||||
// 50) and repository (max 100) names can easily exceed that combined. Each id is purely
|
||||
// internal and never surfaced by the public API, so readability doesn't matter here, only
|
||||
// fitting the limit and staying unique per creation, so a repository deleted and recreated
|
||||
// under the same name never inherits the previous one's sidecar-side content.
|
||||
Map<String, String> sidecarContainerIds = new LinkedHashMap<>();
|
||||
for (String format : CONTAINER_BACKED_FORMATS) {
|
||||
sidecarContainerIds.put(format, newRevision());
|
||||
}
|
||||
r.setSidecarContainerIds(sidecarContainerIds);
|
||||
repositories.putForAccount(owner, key, r);
|
||||
return r;
|
||||
}
|
||||
@@ -296,6 +313,25 @@ public class CodeArtifactService implements Resettable {
|
||||
String key = repositoryKey(region, domain, repository);
|
||||
CodeArtifactRepository r = requireRepository(owner, key, repository);
|
||||
repositories.deleteForAccount(owner, key);
|
||||
// Generic over whatever formats this repository actually has sidecar ids for: adding the
|
||||
// next format's sidecar needs no change here, only a new RepositorySidecarManager
|
||||
// implementation that CodeArtifactSidecarRegistry discovers.
|
||||
//
|
||||
// Best-effort: the metadata delete above already committed, matching real CodeArtifact's
|
||||
// own DeleteRepository (synchronous and always succeeds once the repository exists; actual
|
||||
// content cleanup is an internal detail never exposed to the caller). A sidecar that is
|
||||
// unreachable when this runs must not turn an already-successful delete into a 500, and
|
||||
// must not leave the repository stuck: a retry would just 404, since the record above is
|
||||
// already gone.
|
||||
r.getSidecarContainerIds().forEach((format, containerId) ->
|
||||
sidecarRegistry.forFormat(format).ifPresent(manager -> {
|
||||
try {
|
||||
manager.release(containerId);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv(e, "Failed to release {0} sidecar storage for repository {1}/{2}: {3}",
|
||||
format, domain, repository, e.getMessage());
|
||||
}
|
||||
}));
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -307,21 +343,27 @@ public class CodeArtifactService implements Resettable {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code mavenRepositoryId} is assigned at {@link #createRepository}, but a repository
|
||||
* persisted before that field existed has none; backfills it lazily on first Maven-format use
|
||||
* rather than leaving every caller of {@link CodeArtifactRepository#getMavenRepositoryId()} to
|
||||
* handle a null it can otherwise never see.
|
||||
* A sidecar container id for one format is assigned at {@link #createRepository}, but a
|
||||
* repository persisted before that format's proxy existed has none; backfills it lazily on
|
||||
* first use of that format rather than leaving every caller handle a missing entry it can
|
||||
* otherwise never see. {@code format} is expected to be one of
|
||||
* {@link #CONTAINER_BACKED_FORMATS}, though nothing here enforces that: an unlisted format
|
||||
* simply gets its own id assigned the same way.
|
||||
*/
|
||||
public synchronized String ensureMavenRepositoryId(String region, String domain, String domainOwner,
|
||||
String repository) {
|
||||
public synchronized String ensureFormatContainerId(String format, String region, String domain,
|
||||
String domainOwner, String repository) {
|
||||
String owner = effectiveOwner(domainOwner);
|
||||
String key = repositoryKey(region, domain, repository);
|
||||
CodeArtifactRepository r = requireRepository(owner, key, repository);
|
||||
if (r.getMavenRepositoryId() == null) {
|
||||
r.setMavenRepositoryId(newRevision());
|
||||
String id = r.getSidecarContainerIds().get(format);
|
||||
if (id == null) {
|
||||
id = newRevision();
|
||||
Map<String, String> sidecarContainerIds = new LinkedHashMap<>(r.getSidecarContainerIds());
|
||||
sidecarContainerIds.put(format, id);
|
||||
r.setSidecarContainerIds(sidecarContainerIds);
|
||||
repositories.putForAccount(owner, key, r);
|
||||
}
|
||||
return r.getMavenRepositoryId();
|
||||
return id;
|
||||
}
|
||||
|
||||
public synchronized CodeArtifactRepository updateRepository(String region, String domain, String domainOwner,
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package io.github.hectorvent.floci.services.codeartifact;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Maps a CodeArtifact package format to the {@link RepositorySidecarManager} that serves it.
|
||||
* {@link CodeArtifactService} consults this to clean up a deleted repository's sidecar containers
|
||||
* without knowing which formats exist or which sidecar backs any of them.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class CodeArtifactSidecarRegistry {
|
||||
|
||||
private final Map<String, RepositorySidecarManager> byFormat = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
public CodeArtifactSidecarRegistry(Instance<RepositorySidecarManager> managers) {
|
||||
managers.forEach(this::register);
|
||||
}
|
||||
|
||||
/** Factory constructor: build a registry from an explicit list, bypassing CDI (tests). */
|
||||
public CodeArtifactSidecarRegistry(Collection<RepositorySidecarManager> managers) {
|
||||
managers.forEach(this::register);
|
||||
}
|
||||
|
||||
private void register(RepositorySidecarManager manager) {
|
||||
RepositorySidecarManager existing = byFormat.put(manager.format(), manager);
|
||||
if (existing != null) {
|
||||
throw new IllegalStateException("Duplicate CodeArtifact sidecar manager for format "
|
||||
+ manager.format() + ": " + existing.getClass().getSimpleName() + " and "
|
||||
+ manager.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<RepositorySidecarManager> forFormat(String format) {
|
||||
return Optional.ofNullable(byFormat.get(format));
|
||||
}
|
||||
}
|
||||
+111
-2
@@ -21,10 +21,14 @@ import java.util.Optional;
|
||||
/**
|
||||
* HTTP client for the shared Reposilite sidecar. A CodeArtifact repository maps to a named
|
||||
* Reposilite repository ({@link #ensureRepository}), provisioned lazily via Reposilite's
|
||||
* {@code maven} settings domain, which hot-reloads without a restart.
|
||||
* {@code maven} settings domain, which hot-reloads without a restart. Implements
|
||||
* {@link RepositorySidecarManager} so {@code CodeArtifactService} can release a deleted
|
||||
* repository's Maven storage the same generic way it releases any other format's.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class ReposiliteSidecarClient {
|
||||
public class ReposiliteSidecarClient implements RepositorySidecarManager {
|
||||
|
||||
private static final String FORMAT = "maven";
|
||||
private static final Logger LOG = Logger.getLogger(ReposiliteSidecarClient.class);
|
||||
private static final String MAVEN_SETTINGS_PATH = "/api/settings/domain/maven";
|
||||
private static final int REPOSITORY_READY_POLL_MAX_MS = 3_000;
|
||||
@@ -54,6 +58,26 @@ public class ReposiliteSidecarClient {
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String format() {
|
||||
return FORMAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code publicUrl} is unused: unlike npm's package metadata, Maven's wire protocol has no
|
||||
* self-referential URLs to rewrite, so there is nothing here for it to do.
|
||||
*/
|
||||
@Override
|
||||
public String ensureReady(String repositoryContainerId, String publicUrl) {
|
||||
ensureRepository(repositoryContainerId);
|
||||
return manager.ensureReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release(String repositoryContainerId) {
|
||||
releaseRepository(repositoryContainerId);
|
||||
}
|
||||
|
||||
/** Ensures a Reposilite repository named {@code repoId} exists, creating it if not. */
|
||||
public void ensureRepository(String repoId) {
|
||||
String baseUrl = manager.ensureReady();
|
||||
@@ -124,6 +148,91 @@ public class ReposiliteSidecarClient {
|
||||
return !message.startsWith("Repository ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes every file {@code repoId} holds, then removes it from the shared settings list.
|
||||
* Reposilite has no bulk-delete endpoint (checked against its documented REST API); DELETE on
|
||||
* a path recursively removes everything under it in one call, though, so this only needs one
|
||||
* DELETE per top-level entry (a repository's group-id first segments, typically a handful)
|
||||
* rather than walking the whole artifact tree. A repository never used through Maven has
|
||||
* nothing registered on the Reposilite side at all; that is a no-op here, not an error.
|
||||
*
|
||||
* <p>Order matters: the repository must still be registered while its files are deleted,
|
||||
* since Reposilite 404s every path, including DELETE, for a repository ID absent from its
|
||||
* settings (confirmed against a live instance). Removing it from settings first would leave
|
||||
* its files permanently unreachable instead of actually freeing the storage.
|
||||
*
|
||||
* <p>Checks {@link ReposiliteSidecarManager#isStarted()} first: every CodeArtifact repository
|
||||
* gets a Maven sidecar id at creation regardless of whether it is ever actually used through
|
||||
* Maven, so without this check, deleting any repository at all would start the shared
|
||||
* container just to look for content that was never there. Reposilite keeps no volume, so a
|
||||
* sidecar that was never started could not possibly hold anything for {@code repoId} to
|
||||
* release.
|
||||
*/
|
||||
public void releaseRepository(String repoId) {
|
||||
if (!manager.isStarted()) {
|
||||
return;
|
||||
}
|
||||
String baseUrl = manager.ensureReady();
|
||||
synchronized (provisioningLock) {
|
||||
for (JsonNode entry : topLevelEntries(baseUrl, repoId)) {
|
||||
deleteEntry(baseUrl, repoId, entry.path("name").asText());
|
||||
}
|
||||
ArrayNode repositories = currentRepositories(baseUrl);
|
||||
ArrayNode remaining = mapper.createArrayNode();
|
||||
for (JsonNode repository : repositories) {
|
||||
if (!repoId.equals(repository.path("id").asText())) {
|
||||
remaining.add(repository);
|
||||
}
|
||||
}
|
||||
if (remaining.size() != repositories.size()) {
|
||||
putMavenSettings(baseUrl, remaining);
|
||||
LOG.infov("Released Reposilite repository {0}", repoId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayNode topLevelEntries(String baseUrl, String repoId) {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(baseUrl + "/api/maven/details/" + repoId))
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.header("Authorization", manager.basicAuthHeader())
|
||||
.GET()
|
||||
.build();
|
||||
HttpResponse<String> response = send(request, BodyHandlers.ofString());
|
||||
if (response.statusCode() == 404) {
|
||||
// Never provisioned (no Maven use before this CodeArtifact repository was deleted):
|
||||
// nothing on the Reposilite side to clean up.
|
||||
return mapper.createArrayNode();
|
||||
}
|
||||
if (response.statusCode() != 200) {
|
||||
// Anything other than a clean 404 means the repository's actual state here is
|
||||
// unknown, not "nothing to clean up": proceeding to remove the settings entry anyway
|
||||
// would orphan whatever this call never got to see, unreachable through the API
|
||||
// afterward the same way the 404-ordering bug this method exists to avoid would.
|
||||
// Propagating lets the caller's best-effort handling decide, rather than silently
|
||||
// treating an error as an empty repository.
|
||||
throw new IllegalStateException("Failed to list " + repoId + " on Reposilite before release: HTTP "
|
||||
+ response.statusCode());
|
||||
}
|
||||
JsonNode details = readTree(response.body());
|
||||
return details.path("files").isArray() ? ((ArrayNode) details.path("files")).deepCopy()
|
||||
: mapper.createArrayNode();
|
||||
}
|
||||
|
||||
private void deleteEntry(String baseUrl, String repoId, String entryName) {
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(baseUrl + "/" + repoId + "/" + entryName))
|
||||
.timeout(Duration.ofSeconds(30))
|
||||
.header("Authorization", manager.basicAuthHeader())
|
||||
.DELETE()
|
||||
.build();
|
||||
HttpResponse<Void> response = send(request, BodyHandlers.discarding());
|
||||
if (response.statusCode() != 200) {
|
||||
throw new IllegalStateException("Failed to delete " + repoId + "/" + entryName
|
||||
+ " from Reposilite: HTTP " + response.statusCode());
|
||||
}
|
||||
}
|
||||
|
||||
/** Deploys {@code content} to {@code repoId}'s {@code gav} path, returning the HTTP status. */
|
||||
public int deployArtifact(String repoId, String gav, byte[] content) {
|
||||
String baseUrl = manager.ensureReady();
|
||||
|
||||
+20
@@ -70,6 +70,26 @@ public class ReposiliteSidecarManager {
|
||||
this.managedSecret = managedSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether there could possibly be anything on the Reposilite side to release: either
|
||||
* {@link #ensureReady()} has already resolved an endpoint in this process, or
|
||||
* {@code FLOCI_SERVICES_CODEARTIFACT_MAVEN_URL} names an external instance this process has
|
||||
* simply not talked to yet. Never starts anything itself, unlike {@link #ensureReady()}.
|
||||
*
|
||||
* <p>The two cases are not the same guarantee. A managed container keeps no volume, so one
|
||||
* that was never started this process could not hold anything, full stop. An external,
|
||||
* pre-configured instance's lifecycle is independent of this process's {@code resolvedUrl}: it
|
||||
* may already hold real data from an earlier Floci run, so "this process has not resolved it
|
||||
* yet" must not be read as "nothing is there" the way it can for the managed case.
|
||||
*/
|
||||
public boolean isStarted() {
|
||||
if (resolvedUrl != null) {
|
||||
return true;
|
||||
}
|
||||
Optional<String> configuredUrl = config.services().codeartifact().mavenUrl();
|
||||
return configuredUrl.isPresent() && !configuredUrl.get().isBlank();
|
||||
}
|
||||
|
||||
/** Base URL of a ready Reposilite instance, starting the managed container if needed. */
|
||||
public synchronized String ensureReady() {
|
||||
if (resolvedUrl != null) {
|
||||
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package io.github.hectorvent.floci.services.codeartifact;
|
||||
|
||||
/**
|
||||
* Common contract for a CodeArtifact sidecar backing one package format: get one repository ready
|
||||
* to serve that format, and release whatever backing storage it holds once the repository is
|
||||
* deleted. Implementations are discovered via CDI by {@link CodeArtifactSidecarRegistry}, so
|
||||
* adding the next format's sidecar (npm, pypi, nuget) needs no change to
|
||||
* {@link CodeArtifactService} or any other format's manager.
|
||||
*
|
||||
* <p>Named around the effect ("release this repository's backing storage"), not the mechanism,
|
||||
* because the mechanism is expected to differ per sidecar. {@code ReposiliteSidecarClient}, the
|
||||
* first implementation, deletes files and removes one entry from a settings list shared by every
|
||||
* maven repository in a single Reposilite instance; a future format whose sidecar runs one
|
||||
* container per repository would instead stop and remove that container. Both are legitimate
|
||||
* implementations of the same contract even though neither necessarily "stops a container" the
|
||||
* way the other might.
|
||||
*/
|
||||
public interface RepositorySidecarManager {
|
||||
|
||||
/** The CodeArtifact package format this sidecar backs, e.g. {@code "maven"}. */
|
||||
String format();
|
||||
|
||||
/**
|
||||
* Base URL of a ready backend for {@code repositoryContainerId}, provisioning it if this is
|
||||
* the first use.
|
||||
*
|
||||
* @param publicUrl the externally reachable proxy URL for this specific repository, passed
|
||||
* through so any self-referential URLs the sidecar returns in its own
|
||||
* protocol responses point back through Floci instead of an internal,
|
||||
* client-unreachable address. Not every sidecar's protocol has this problem
|
||||
* (Maven's does not); an implementation that doesn't need it ignores it.
|
||||
*/
|
||||
String ensureReady(String repositoryContainerId, String publicUrl);
|
||||
|
||||
/**
|
||||
* Releases the backing storage for one repository (deletes its files, edits a shared settings
|
||||
* list, stops a container, whatever this sidecar's own shape requires) so a later repository
|
||||
* created under the same name never inherits it. A repository that never actually used this
|
||||
* format is a no-op, not an error.
|
||||
*/
|
||||
void release(String repositoryContainerId);
|
||||
}
|
||||
+11
-8
@@ -26,11 +26,14 @@ public class CodeArtifactRepository {
|
||||
private String policyDocument;
|
||||
private String policyRevision;
|
||||
/**
|
||||
* The Reposilite repository backing this repository's {@code maven} format, unique per
|
||||
* creation so a deleted-and-recreated repository of the same name never inherits a previous
|
||||
* repository's leftover artifacts. Internal; never surfaced in the public API response.
|
||||
* The sidecar-backed id for each package format this repository has been used through (keyed
|
||||
* by format name, e.g. {@code "maven"}), unique per creation so a deleted-and-recreated
|
||||
* repository of the same name never inherits a previous repository's leftover artifacts for
|
||||
* that format. What the id actually names depends on the format's sidecar shape: a Reposilite
|
||||
* repository name for {@code maven} (one shared container, many named repositories inside
|
||||
* it). Internal; never surfaced in the public API response.
|
||||
*/
|
||||
private String mavenRepositoryId;
|
||||
private Map<String, String> sidecarContainerIds = new LinkedHashMap<>();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
@@ -136,11 +139,11 @@ public class CodeArtifactRepository {
|
||||
this.policyRevision = policyRevision;
|
||||
}
|
||||
|
||||
public String getMavenRepositoryId() {
|
||||
return mavenRepositoryId;
|
||||
public Map<String, String> getSidecarContainerIds() {
|
||||
return Collections.unmodifiableMap(sidecarContainerIds);
|
||||
}
|
||||
|
||||
public void setMavenRepositoryId(String mavenRepositoryId) {
|
||||
this.mavenRepositoryId = mavenRepositoryId;
|
||||
public void setSidecarContainerIds(Map<String, String> sidecarContainerIds) {
|
||||
this.sidecarContainerIds = sidecarContainerIds;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -111,7 +111,7 @@ class CodeArtifactAssetPersistenceTest {
|
||||
when(config.effectiveBaseUrl()).thenReturn("http://localhost:4566");
|
||||
|
||||
return new CodeArtifactService(domainStore, repoStore, packageVersionStore, regionResolver, config,
|
||||
false, dir.resolve("codeartifact-assets"));
|
||||
false, dir.resolve("codeartifact-assets"), new CodeArtifactSidecarRegistry(List.of()));
|
||||
}
|
||||
|
||||
private <V> AccountAwareStorageBackend<V> accountAware(Path dir, String fileName, TypeReference<Map<String, V>> type) {
|
||||
|
||||
+46
@@ -1,14 +1,20 @@
|
||||
package io.github.hectorvent.floci.services.codeartifact;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -282,4 +288,44 @@ class CodeArtifactMavenDockerIntegrationTest {
|
||||
.extract().asByteArray();
|
||||
assertEquals(new String(content, StandardCharsets.UTF_8), new String(fetched, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void deletingARepositoryReleasesItsStorageFromTheSharedReposiliteInstance() throws Exception {
|
||||
given().contentType("application/json").header("Authorization", AUTH).body("{}")
|
||||
.post("/v1/repository?domain=" + DOMAIN + "&repository=released-repo")
|
||||
.then().statusCode(200);
|
||||
given().header("Authorization", "Bearer " + bearerToken).body("to-be-released".getBytes(StandardCharsets.UTF_8))
|
||||
.put("/codeartifact/maven/" + DOMAIN + "/released-repo/" + GAV)
|
||||
.then().statusCode(200);
|
||||
int repositoryCountBeforeDelete = reposiliteSettingsRepositoryCount();
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.delete("/v1/repository?domain=" + DOMAIN + "&repository=released-repo")
|
||||
.then().statusCode(200);
|
||||
|
||||
// The mavenRepositoryId is internal (never in the API response), so identity isn't
|
||||
// checkable directly; a count drop of exactly one is enough to confirm this repository's
|
||||
// entry, specifically, is what disappeared from the real shared instance's own settings
|
||||
// list, not just that Floci stopped tracking the CodeArtifact-side metadata.
|
||||
assertEquals(repositoryCountBeforeDelete - 1, reposiliteSettingsRepositoryCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the real Reposilite instance's own {@code maven} settings domain directly (the same
|
||||
* shared container {@link ReposiliteSidecarManager} started for every test in this class).
|
||||
*/
|
||||
private int reposiliteSettingsRepositoryCount() throws Exception {
|
||||
HttpClient httpClient = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(reposiliteManager.ensureReady() + "/api/settings/domain/maven"))
|
||||
.header("Authorization", reposiliteManager.basicAuthHeader())
|
||||
.GET()
|
||||
.build();
|
||||
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
return new ObjectMapper().readTree(response.body()).path("repositories").size();
|
||||
}
|
||||
|
||||
@Inject
|
||||
ReposiliteSidecarManager reposiliteManager;
|
||||
}
|
||||
+59
-16
@@ -24,6 +24,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -35,7 +36,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class CodeArtifactServiceTest {
|
||||
@@ -46,6 +49,7 @@ class CodeArtifactServiceTest {
|
||||
private CodeArtifactService service;
|
||||
private RegionResolver regionResolver;
|
||||
private AccountAwareStorageBackend<CodeArtifactRepository> repoStore;
|
||||
private ReposiliteSidecarClient reposiliteClient;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -63,8 +67,10 @@ class CodeArtifactServiceTest {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
when(config.effectiveBaseUrl()).thenReturn("http://localhost:4566");
|
||||
|
||||
reposiliteClient = mock(ReposiliteSidecarClient.class);
|
||||
when(reposiliteClient.format()).thenReturn("maven");
|
||||
service = new CodeArtifactService(domainStore, repoStore, packageVersionStore, regionResolver, config,
|
||||
true, null);
|
||||
true, null, new CodeArtifactSidecarRegistry(List.of(reposiliteClient)));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- domains
|
||||
@@ -287,49 +293,86 @@ class CodeArtifactServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRepositoryAssignsAFreshMavenRepositoryIdEvenAfterDeleteAndRecreate() {
|
||||
void createRepositoryAssignsFreshContainerIdsForEveryContainerBackedFormat() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
assertEquals(Set.of("maven"), created.getSidecarContainerIds().keySet());
|
||||
created.getSidecarContainerIds().values()
|
||||
.forEach(id -> assertTrue(id != null && !id.isBlank()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createRepositoryAssignsFreshContainerIdsEvenAfterDeleteAndRecreate() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository first = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
assertTrue(first.getMavenRepositoryId() != null && !first.getMavenRepositoryId().isBlank());
|
||||
|
||||
service.deleteRepository(REGION, "dom", null, "repo");
|
||||
CodeArtifactRepository recreated = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
assertTrue(!first.getMavenRepositoryId().equals(recreated.getMavenRepositoryId()),
|
||||
"a recreated repository must never reuse the previous one's Maven repository id, "
|
||||
assertTrue(!first.getSidecarContainerIds().get("maven").equals(recreated.getSidecarContainerIds().get("maven")),
|
||||
"a recreated repository must never reuse the previous one's container id for a format, "
|
||||
+ "or it would inherit its leftover artifacts");
|
||||
}
|
||||
|
||||
@Test
|
||||
void ensureMavenRepositoryIdBackfillsALegacyRepositoryMissingOne() {
|
||||
void ensureFormatContainerIdBackfillsALegacyRepositoryMissingOneFormat() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
// Simulates a repository persisted before mavenRepositoryId existed: Jackson would
|
||||
// deserialize the missing field as null exactly like this.
|
||||
created.setMavenRepositoryId(null);
|
||||
// Simulates a repository persisted before the maven format's proxy existed: Jackson would
|
||||
// deserialize a missing map entry exactly like this.
|
||||
created.setSidecarContainerIds(new HashMap<>());
|
||||
repoStore.putForAccount(ACCOUNT_ID, REGION + "::dom::repo", created);
|
||||
|
||||
String backfilled = service.ensureMavenRepositoryId(REGION, "dom", null, "repo");
|
||||
String backfilled = service.ensureFormatContainerId("maven", REGION, "dom", null, "repo");
|
||||
|
||||
assertTrue(backfilled != null && !backfilled.isBlank());
|
||||
assertEquals(backfilled, service.describeRepository(REGION, "dom", null, "repo").getMavenRepositoryId());
|
||||
assertEquals(backfilled,
|
||||
service.describeRepository(REGION, "dom", null, "repo").getSidecarContainerIds().get("maven"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ensureMavenRepositoryIdIsIdempotentForAnAlreadyAssignedRepository() {
|
||||
void ensureFormatContainerIdIsIdempotentForAnAlreadyAssignedFormat() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
String result = service.ensureMavenRepositoryId(REGION, "dom", null, "repo");
|
||||
String result = service.ensureFormatContainerId("maven", REGION, "dom", null, "repo");
|
||||
|
||||
assertEquals(created.getMavenRepositoryId(), result);
|
||||
assertEquals(created.getSidecarContainerIds().get("maven"), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void ensureMavenRepositoryIdRequiresExistingRepository() {
|
||||
void ensureFormatContainerIdRequiresExistingRepository() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.ensureMavenRepositoryId(REGION, "dom", null, "missing-repo"));
|
||||
() -> service.ensureFormatContainerId("maven", REGION, "dom", null, "missing-repo"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRepositoryReleasesEveryFormatsSidecarStorage() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
service.deleteRepository(REGION, "dom", null, "repo");
|
||||
|
||||
verify(reposiliteClient).release(created.getSidecarContainerIds().get("maven"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRepositorySucceedsEvenWhenSidecarReleaseFails() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
doThrow(new IllegalStateException("Reposilite unreachable")).when(reposiliteClient).release(anyString());
|
||||
|
||||
// The metadata delete already committed; a sidecar failure must not turn that into a
|
||||
// caller-visible error, and must not leave the caller unable to ever get a clean response
|
||||
// for this repository (a retry would just 404, since the record is already gone).
|
||||
CodeArtifactRepository deleted = service.deleteRepository(REGION, "dom", null, "repo");
|
||||
|
||||
assertEquals("repo", deleted.getName());
|
||||
AwsException e = assertThrows(AwsException.class,
|
||||
() -> service.describeRepository(REGION, "dom", null, "repo"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
|
||||
+136
-1
@@ -12,6 +12,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
@@ -27,6 +28,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@@ -40,15 +43,19 @@ class ReposiliteSidecarClientTest {
|
||||
private final List<String> requestedPaths = new CopyOnWriteArrayList<>();
|
||||
private final AtomicReference<String> settingsBody = new AtomicReference<>("{\"repositories\":[]}");
|
||||
private HttpServer server;
|
||||
private ReposiliteSidecarManager manager;
|
||||
private ReposiliteSidecarClient client;
|
||||
|
||||
@BeforeEach
|
||||
void startServer() throws IOException {
|
||||
server = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
server.start();
|
||||
ReposiliteSidecarManager manager = mock(ReposiliteSidecarManager.class);
|
||||
manager = mock(ReposiliteSidecarManager.class);
|
||||
when(manager.ensureReady()).thenReturn("http://127.0.0.1:" + server.getAddress().getPort());
|
||||
when(manager.basicAuthHeader()).thenReturn("Basic dGVzdDp0ZXN0");
|
||||
// Most tests here exercise a sidecar that is already up; the one test for the opposite
|
||||
// case (never started) overrides this back to false itself.
|
||||
when(manager.isStarted()).thenReturn(true);
|
||||
client = new ReposiliteSidecarClient(manager, mapper);
|
||||
}
|
||||
|
||||
@@ -114,6 +121,134 @@ class ReposiliteSidecarClientTest {
|
||||
assertThat(lastMethod.get(), equalTo("GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void interfaceEnsureReadyProvisionsTheRepositoryAndReturnsTheSidecarBaseUrl() throws Exception {
|
||||
server.createContext("/api/settings/domain/maven", exchange -> {
|
||||
if ("PUT".equals(exchange.getRequestMethod())) {
|
||||
exchange.getRequestBody().readAllBytes();
|
||||
respond(exchange, 200, "{}");
|
||||
} else {
|
||||
respond(exchange, 200, settingsBody.get());
|
||||
}
|
||||
});
|
||||
server.createContext("/api/maven/details/dom--repo/.floci-repository-ready-probe",
|
||||
exchange -> respond(exchange, 404, "{\"status\":404,\"message\":\"File not found\"}"));
|
||||
|
||||
// publicUrl is unused for Maven (no self-referential URLs to rewrite); passing a value
|
||||
// anyway to prove it is accepted without error, not just null.
|
||||
String baseUrl = client.ensureReady("dom--repo", "http://localhost:4566/codeartifact/maven/dom/repo/");
|
||||
|
||||
assertThat(baseUrl, equalTo("http://127.0.0.1:" + server.getAddress().getPort()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void releaseRepositoryDeletesTopLevelEntriesThenRemovesTheSettingsEntry() throws Exception {
|
||||
settingsBody.set("{\"repositories\":["
|
||||
+ "{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false},"
|
||||
+ "{\"id\":\"other--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
List<String> deletedEntries = new CopyOnWriteArrayList<>();
|
||||
server.createContext("/api/maven/details/dom--repo", exchange ->
|
||||
respond(exchange, 200, "{\"name\":\"dom--repo\",\"type\":\"DIRECTORY\",\"files\":["
|
||||
+ "{\"name\":\"com\",\"type\":\"DIRECTORY\"},"
|
||||
+ "{\"name\":\"org\",\"type\":\"DIRECTORY\"}]}"));
|
||||
server.createContext("/dom--repo/com", exchange -> {
|
||||
deletedEntries.add("com");
|
||||
respond(exchange, 200, "");
|
||||
});
|
||||
server.createContext("/dom--repo/org", exchange -> {
|
||||
deletedEntries.add("org");
|
||||
respond(exchange, 200, "");
|
||||
});
|
||||
AtomicReference<JsonNode> putBody = new AtomicReference<>();
|
||||
server.createContext("/api/settings/domain/maven", exchange -> {
|
||||
if ("PUT".equals(exchange.getRequestMethod())) {
|
||||
putBody.set(mapper.readTree(exchange.getRequestBody()));
|
||||
respond(exchange, 200, "{}");
|
||||
} else {
|
||||
respond(exchange, 200, settingsBody.get());
|
||||
}
|
||||
});
|
||||
|
||||
client.releaseRepository("dom--repo");
|
||||
|
||||
assertThat(deletedEntries, hasSize(2));
|
||||
assertTrue(deletedEntries.contains("com"));
|
||||
assertTrue(deletedEntries.contains("org"));
|
||||
List<String> remainingIds = new ArrayList<>();
|
||||
putBody.get().path("repositories").forEach(node -> remainingIds.add(node.path("id").asText()));
|
||||
assertThat(remainingIds, equalTo(List.of("other--repo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void releaseRepositoryRemovesTheSettingsEntryForARegisteredButNeverPublishedToRepository() throws Exception {
|
||||
// Distinct from "never provisioned" (404): this repository is registered but has zero
|
||||
// files, the real shape Reposilite returns for one nobody ever published to.
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/api/maven/details/dom--repo",
|
||||
exchange -> respond(exchange, 200, "{\"name\":\"dom--repo\",\"type\":\"DIRECTORY\",\"files\":[]}"));
|
||||
AtomicReference<JsonNode> putBody = new AtomicReference<>();
|
||||
server.createContext("/api/settings/domain/maven", exchange -> {
|
||||
if ("PUT".equals(exchange.getRequestMethod())) {
|
||||
putBody.set(mapper.readTree(exchange.getRequestBody()));
|
||||
respond(exchange, 200, "{}");
|
||||
} else {
|
||||
respond(exchange, 200, settingsBody.get());
|
||||
}
|
||||
});
|
||||
|
||||
client.releaseRepository("dom--repo");
|
||||
|
||||
assertThat(putBody.get().path("repositories").size(), is(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void releaseRepositoryIsANoOpForANeverProvisionedRepository() {
|
||||
server.createContext("/api/maven/details/never-repo",
|
||||
exchange -> respond(exchange, 404, "{\"status\":404,\"message\":\"Repository never-repo not found\"}"));
|
||||
AtomicReference<String> settingsMethod = new AtomicReference<>();
|
||||
server.createContext("/api/settings/domain/maven", exchange -> {
|
||||
settingsMethod.set(exchange.getRequestMethod());
|
||||
respond(exchange, 200, settingsBody.get());
|
||||
});
|
||||
|
||||
client.releaseRepository("never-repo");
|
||||
|
||||
// Only ever GETs the current list to check membership; never PUTs a settings change for a
|
||||
// repository that was never in it.
|
||||
assertThat(settingsMethod.get(), equalTo("GET"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void releaseRepositoryDoesNotStartTheSidecarWhenItWasNeverStarted() {
|
||||
// Every CodeArtifact repository gets a Maven sidecar id at creation regardless of whether
|
||||
// it is ever used through Maven, so DeleteRepository calls this unconditionally; without
|
||||
// this guard, deleting any repository at all would start the shared Reposilite container
|
||||
// just to look for content that was never there.
|
||||
when(manager.isStarted()).thenReturn(false);
|
||||
|
||||
client.releaseRepository("never-repo");
|
||||
|
||||
verify(manager, never()).ensureReady();
|
||||
}
|
||||
|
||||
@Test
|
||||
void releaseRepositoryDoesNotUnregisterTheRepositoryWhenListingItsFilesFails() {
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/api/maven/details/dom--repo",
|
||||
exchange -> respond(exchange, 500, "{\"status\":500,\"message\":\"internal error\"}"));
|
||||
AtomicReference<String> settingsMethod = new AtomicReference<>();
|
||||
server.createContext("/api/settings/domain/maven", exchange -> {
|
||||
settingsMethod.set(exchange.getRequestMethod());
|
||||
respond(exchange, 200, settingsBody.get());
|
||||
});
|
||||
|
||||
// A non-404 failure while listing means the repository's real content is unknown, not
|
||||
// empty: proceeding to remove it from settings anyway would orphan whatever was never
|
||||
// listed, unreachable afterward, the same failure shape release exists to prevent.
|
||||
assertThrows(IllegalStateException.class, () -> client.releaseRepository("dom--repo"));
|
||||
assertThat(settingsMethod.get() == null || "GET".equals(settingsMethod.get()), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deployArtifactPutsTheBytesAndReturnsTheStatus() throws Exception {
|
||||
AtomicReference<byte[]> received = new AtomicReference<>();
|
||||
|
||||
+24
@@ -18,8 +18,10 @@ import java.util.Optional;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
@@ -82,6 +84,28 @@ class ReposiliteSidecarManagerTest {
|
||||
verifyNoInteractions(containerBuilder);
|
||||
}
|
||||
|
||||
@Test
|
||||
void isStartedIsFalseForAManagedContainerThatWasNeverStartedAndNeverStartsOneItself() {
|
||||
when(codeArtifact.mavenUrl()).thenReturn(Optional.empty());
|
||||
ReposiliteSidecarManager manager = manager();
|
||||
|
||||
assertFalse(manager.isStarted());
|
||||
verifyNoInteractions(containerBuilder, lifecycleManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
void isStartedIsTrueForAConfiguredUrlEvenBeforeThisProcessEverResolvesIt() {
|
||||
// A managed container keeps no volume, so "never started" really does mean "nothing to
|
||||
// release." An external, pre-configured instance's lifecycle is independent of this
|
||||
// process: it may already hold real data from an earlier Floci run, so this process not
|
||||
// having resolved it yet must not be read the same way.
|
||||
when(codeArtifact.mavenUrl()).thenReturn(Optional.of("http://reposilite.internal:8080"));
|
||||
ReposiliteSidecarManager manager = manager();
|
||||
|
||||
assertTrue(manager.isStarted());
|
||||
verifyNoInteractions(containerBuilder, lifecycleManager);
|
||||
}
|
||||
|
||||
private ReposiliteSidecarManager manager() {
|
||||
return new ReposiliteSidecarManager(containerBuilder, lifecycleManager, config, "unused-managed-secret");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user