Search in sources :

Example 31 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class LocalMavenSlice method response.

@Override
public Response response(final String line, final Iterable<Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
    final RequestLineFrom rline = new RequestLineFrom(line);
    final Key key = new KeyFromPath(rline.uri().getPath());
    final Matcher match = LocalMavenSlice.PTN_ARTIFACT.matcher(new KeyLastPart(key).get());
    final Response response;
    if (match.matches()) {
        response = this.artifactResponse(rline.method(), key);
    } else {
        response = this.plainResponse(rline.method(), key);
    }
    return response;
}
Also used : Response(com.artipie.http.Response) AsyncResponse(com.artipie.http.async.AsyncResponse) KeyFromPath(com.artipie.http.slice.KeyFromPath) Matcher(java.util.regex.Matcher) KeyLastPart(com.artipie.asto.ext.KeyLastPart) RequestLineFrom(com.artipie.http.rq.RequestLineFrom) Key(com.artipie.asto.Key)

Example 32 with Key

use of com.artipie.asto.Key in project maven-adapter by artipie.

the class AstoMaven method moveToTheRepository.

/**
 * Moves artifacts from temp location to repository.
 * @param upload Upload temp location
 * @param target Repository
 * @param artifact Artifact repository location
 * @return Completion action
 */
private CompletableFuture<Void> moveToTheRepository(final Key upload, final Storage target, final Key artifact) {
    final Storage sub = new SubStorage(new Key.From(upload, PutMetadataSlice.SUB_META), this.storage);
    final Storage subversion = new SubStorage(upload.parent().get(), this.storage);
    return sub.list(Key.ROOT).thenCompose(list -> new Copy(sub, list.stream().filter(key -> key.string().contains(AstoMaven.MAVEN_META)).collect(Collectors.toList())).copy(new SubStorage(artifact, target))).thenCompose(nothing -> subversion.list(Key.ROOT).thenCompose(list -> new Copy(subversion, list.stream().filter(key -> !key.string().contains(String.format("/%s/", PutMetadataSlice.SUB_META))).collect(Collectors.toList())).copy(new SubStorage(artifact, target))));
}
Also used : Copy(com.artipie.asto.Copy) Maven(com.artipie.maven.Maven) SubStorage(com.artipie.asto.SubStorage) XMLDocument(com.jcabi.xml.XMLDocument) Collection(java.util.Collection) KeyLastPart(com.artipie.asto.ext.KeyLastPart) Directives(org.xembly.Directives) PutMetadataSlice(com.artipie.maven.http.PutMetadataSlice) CompletableFuture(java.util.concurrent.CompletableFuture) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) PublisherAs(com.artipie.asto.ext.PublisherAs) CompletionStage(java.util.concurrent.CompletionStage) Storage(com.artipie.asto.Storage) MavenMetadata(com.artipie.maven.metadata.MavenMetadata) SubStorage(com.artipie.asto.SubStorage) Storage(com.artipie.asto.Storage) Copy(com.artipie.asto.Copy) SubStorage(com.artipie.asto.SubStorage) Key(com.artipie.asto.Key)

Example 33 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class RepositoriesFromStorageCacheTest method readConfigFromCacheAfterSavingNewValueInStorage.

@Test
void readConfigFromCacheAfterSavingNewValueInStorage() {
    final Key key = new Key.From("some-repo.yaml");
    final byte[] old = "some: data".getBytes();
    final byte[] upd = "some: new data".getBytes();
    new BlockingStorage(this.storage).save(key, old);
    final ClientSlices http = new JettyClientSlices();
    new RepositoriesFromStorage(http, this.storage).config(key.string()).toCompletableFuture().join();
    new BlockingStorage(this.storage).save(key, upd);
    MatcherAssert.assertThat(new RepositoriesFromStorage(http, this.storage).config(key.string()).toCompletableFuture().join().toString(), new IsEqual<>(new String(old)));
}
Also used : BlockingStorage(com.artipie.asto.blocking.BlockingStorage) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) Key(com.artipie.asto.Key) ClientSlices(com.artipie.http.client.ClientSlices) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) Test(org.junit.jupiter.api.Test)

Example 34 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class MetricSliceTest method shouldReturnMetricsInJsonArray.

@Test
void shouldReturnMetricsInJsonArray() {
    final String keyone = "one";
    final String keytwo = "two";
    final String json = "[{\"key\":\"%s\",\"value\":%s},{\"key\":\"%s\",\"value\":%s}]";
    final long valone = 1;
    final long valtwo = 2;
    final String dirorder = String.format(json, keyone, valone, keytwo, valtwo);
    final String revorder = String.format(json, keytwo, valtwo, keyone, valone);
    final Storage storage = new InMemoryStorage();
    storage.save(new Key.From(keyone), this.getContent(valone));
    storage.save(new Key.From(keytwo), this.getContent(valtwo));
    MatcherAssert.assertThat(new MetricSlice(storage), new SliceHasResponse(new AllOf<>(Arrays.asList(new RsHasStatus(RsStatus.OK), new AnyOf<>(Arrays.asList(new RsHasBody(dirorder, StandardCharsets.UTF_8), new RsHasBody(revorder, StandardCharsets.UTF_8))))), new RequestLine(RqMethod.GET, "/api/repositories/")));
}
Also used : SliceHasResponse(com.artipie.http.hm.SliceHasResponse) RsHasStatus(com.artipie.http.hm.RsHasStatus) AnyOf(org.hamcrest.core.AnyOf) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) RequestLine(com.artipie.http.rq.RequestLine) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Storage(com.artipie.asto.Storage) RsHasBody(com.artipie.http.hm.RsHasBody) Key(com.artipie.asto.Key) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 35 with Key

use of com.artipie.asto.Key in project artipie by artipie.

the class ConfigFile method valueFrom.

/**
 * Obtains contents from the specified storage. If files with both extensions
 * exists, the file with `.yaml` extension will be obtained.
 * @param storage Storage from which the file is obtained
 * @return Content of the file.
 */
public CompletionStage<Content> valueFrom(final Storage storage) {
    if (!(this.isYamlOrYml() || this.extension().isEmpty())) {
        throw new IllegalStateException(String.format("Filename `%s` should have `.yaml` or `.yml` extension or be without extension", this.filename));
    }
    final String name = this.name();
    final Key yaml = Extension.YAML.key(name);
    return storage.exists(yaml).thenCompose(exists -> {
        final CompletionStage<Content> result;
        if (exists) {
            result = storage.value(yaml);
        } else {
            final Key yml = Extension.YML.key(name);
            result = storage.value(yml);
        }
        return result;
    });
}
Also used : Content(com.artipie.asto.Content) Key(com.artipie.asto.Key)

Aggregations

Key (com.artipie.asto.Key)37 Test (org.junit.jupiter.api.Test)17 Storage (com.artipie.asto.Storage)16 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)13 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)9 Content (com.artipie.asto.Content)8 Optional (java.util.Optional)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)6 PublisherAs (com.artipie.asto.ext.PublisherAs)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Matcher (java.util.regex.Matcher)6 Pattern (java.util.regex.Pattern)6 Collectors (java.util.stream.Collectors)5 TestResource (com.artipie.asto.test.TestResource)4 Response (com.artipie.http.Response)4 Slice (com.artipie.http.Slice)4 AsyncResponse (com.artipie.http.async.AsyncResponse)4 RequestLineFrom (com.artipie.http.rq.RequestLineFrom)4 CompletionStage (java.util.concurrent.CompletionStage)4