Search in sources :

Example 1 with Storage

use of com.artipie.asto.Storage in project front by artipie.

the class YamlStorage method storage.

/**
 * Provides a storage.
 *
 * @return Storage instance.
 */
public Storage storage() {
    @SuppressWarnings("deprecation") final YamlMapping strict = new StrictYamlMapping(this.yaml);
    final String type = strict.string("type");
    final Storage storage;
    if ("fs".equals(type)) {
        storage = new FileStorage(Path.of(strict.string("path")));
    } else if ("s3".equals(type)) {
        storage = new S3Storage(this.s3Client(), strict.string("bucket"), !"false".equals(this.yaml.string("multipart")));
    } else if ("etcd".equals(type)) {
        storage = new EtcdStorage(YamlStorage.etcdClient(strict.yamlMapping("connection")));
    } else {
        throw new IllegalStateException(String.format("Unsupported storage type: '%s'", type));
    }
    return storage;
}
Also used : StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) S3Storage(com.artipie.asto.s3.S3Storage) FileStorage(com.artipie.asto.fs.FileStorage) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) S3Storage(com.artipie.asto.s3.S3Storage)

Example 2 with Storage

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

the class ConfigFileTest method valueFromStorageReturnsYamlWhenBothExist.

@Test
void valueFromStorageReturnsYamlWhenBothExist() {
    final Storage storage = new InMemoryStorage();
    final String yaml = String.join("", Arrays.toString(ConfigFileTest.CONTENT), "some");
    this.saveByKey(storage, ".yml");
    this.saveByKey(storage, ".yaml", yaml.getBytes());
    MatcherAssert.assertThat(new PublisherAs(new ConfigFile(new Key.From(ConfigFileTest.NAME)).valueFrom(storage).toCompletableFuture().join()).asciiString().toCompletableFuture().join(), new IsEqual<>(yaml));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) PublisherAs(com.artipie.asto.ext.PublisherAs) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) Storage(com.artipie.asto.Storage) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with Storage

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

the class CachedCredsTest method getsOriginForSameConfigurationButDifferentStorages.

@Test
void getsOriginForSameConfigurationButDifferentStorages() {
    final String path = "_credentials.yaml";
    final Key key = new Key.From(path);
    final CredsConfigCache configs = new CachedCreds(this.cache);
    final Storage another = new InMemoryStorage();
    new TestResource(path).saveTo(this.storage);
    new BlockingStorage(another).save(key, "credentials: another val".getBytes(StandardCharsets.UTF_8));
    final YamlMapping frst = configs.credentials(this.storage, key).toCompletableFuture().join();
    final YamlMapping scnd = configs.credentials(another, key).toCompletableFuture().join();
    MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
    MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
Also used : InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) TestResource(com.artipie.asto.test.TestResource) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Key(com.artipie.asto.Key) Test(org.junit.jupiter.api.Test)

Example 4 with Storage

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

the class VertxMain method startRepos.

/**
 * Start repository servers.
 *
 * @param settings Settings.
 * @param metrics Metrics.
 */
private void startRepos(final Settings settings, final Metrics metrics) {
    final Storage storage = settings.repoConfigsStorage();
    final Collection<RepoConfig> configs = storage.list(Key.ROOT).thenApply(keys -> keys.stream().map(key -> new ConfigFile(key)).filter(Predicate.not(ConfigFile::isSystem).and(ConfigFile::isYamlOrYml)).map(ConfigFile::name).map(name -> new RepositoriesFromStorage(this.http, storage).config(name)).map(stage -> stage.toCompletableFuture().join()).collect(Collectors.toList())).toCompletableFuture().join();
    for (final RepoConfig repo : configs) {
        try {
            repo.port().ifPresent(prt -> {
                final String name = new ConfigFile(repo.name()).name();
                this.listenOn(new ArtipieRepositories(this.http, settings).slice(new Key.From(name), true), metrics, prt);
                Logger.info(VertxMain.class, "Artipie repo '%s' was started on port %d", name, prt);
            });
        } catch (final IllegalStateException err) {
            Logger.error(this, "Invalid repo config file %s: %[exception]s", repo.name(), err);
        }
    }
    new QuartzScheduler(configs).start();
}
Also used : RepoConfig(com.artipie.repo.RepoConfig) Slice(com.artipie.http.Slice) Options(org.apache.commons.cli.Options) ArtipieRepositories(com.artipie.http.ArtipieRepositories) NopMetrics(com.artipie.metrics.nop.NopMetrics) ArrayList(java.util.ArrayList) DefaultParser(org.apache.commons.cli.DefaultParser) BaseSlice(com.artipie.http.BaseSlice) Metrics(com.artipie.metrics.Metrics) Vertx(io.vertx.reactivex.core.Vertx) Storage(com.artipie.asto.Storage) ConfigFile(com.artipie.repo.ConfigFile) VertxSliceServer(com.artipie.vertx.VertxSliceServer) CommandLine(org.apache.commons.cli.CommandLine) MetricsFromConfig(com.artipie.metrics.MetricsFromConfig) Path(java.nio.file.Path) CommandLineParser(org.apache.commons.cli.CommandLineParser) Predicate(java.util.function.Predicate) Collection(java.util.Collection) IOException(java.io.IOException) Key(com.artipie.asto.Key) Collectors(java.util.stream.Collectors) List(java.util.List) ClientSlices(com.artipie.http.client.ClientSlices) JettyClientSlices(com.artipie.http.client.jetty.JettyClientSlices) MainSlice(com.artipie.http.MainSlice) Optional(java.util.Optional) Logger(com.jcabi.log.Logger) ArtipieProperties(com.artipie.misc.ArtipieProperties) Storage(com.artipie.asto.Storage) RepoConfig(com.artipie.repo.RepoConfig) ConfigFile(com.artipie.repo.ConfigFile) ArtipieRepositories(com.artipie.http.ArtipieRepositories)

Example 5 with Storage

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

the class AstoMavenTest method addFilesToStorage.

private void addFilesToStorage(final Predicate<String> condition, final Key base) {
    final Storage resources = new FileStorage(new TestResource("com/artipie/asto").asPath());
    final BlockingStorage bsto = new BlockingStorage(resources);
    bsto.list(Key.ROOT).stream().map(Key::string).filter(condition).forEach(item -> new BlockingStorage(this.storage).save(new Key.From(base, item), bsto.value(new Key.From(item))));
}
Also used : BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) InMemoryStorage(com.artipie.asto.memory.InMemoryStorage) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) FileStorage(com.artipie.asto.fs.FileStorage) TestResource(com.artipie.asto.test.TestResource) Key(com.artipie.asto.Key)

Aggregations

Storage (com.artipie.asto.Storage)24 Key (com.artipie.asto.Key)17 InMemoryStorage (com.artipie.asto.memory.InMemoryStorage)15 Test (org.junit.jupiter.api.Test)15 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)10 RsHasStatus (com.artipie.http.hm.RsHasStatus)6 Content (com.artipie.asto.Content)4 PublisherAs (com.artipie.asto.ext.PublisherAs)4 FileStorage (com.artipie.asto.fs.FileStorage)4 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)3 TestResource (com.artipie.asto.test.TestResource)3 RsHasBody (com.artipie.http.hm.RsHasBody)3 Optional (java.util.Optional)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletionStage (java.util.concurrent.CompletionStage)3 StrictYamlMapping (com.amihaiemil.eoyaml.StrictYamlMapping)2 SubStorage (com.artipie.asto.SubStorage)2 EtcdStorage (com.artipie.asto.etcd.EtcdStorage)2 S3Storage (com.artipie.asto.s3.S3Storage)2 Slice (com.artipie.http.Slice)2