Search in sources :

Example 91 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class PomWithRepoAddsRepoToGroupTest method skimPomForRepoAndAddIt.

@Test
public void skimPomForRepoAndAddIt() throws Exception {
    final PomRef ref = loadPom("one-repo", Collections.singletonMap("one-repo.url", server.formatUrl(REPO)));
    server.expect(server.formatUrl(TEST_REPO, ref.path), 200, ref.pom);
    final InputStream stream = client.content().get(StoreType.group, PUBLIC, ref.path);
    final String downloaded = IOUtils.toString(stream);
    IOUtils.closeQuietly(stream);
    assertThat("SANITY: downloaded POM is wrong!", downloaded, equalTo(ref.pom));
    // sleep while event observer runs...
    System.out.println("Waiting 5s for events to run.");
    Thread.sleep(5000);
    final Group g = client.stores().load(StoreType.group, PUBLIC, Group.class);
    assertThat("Group membership does not contain implied repository", g.getConstituents().contains(new StoreKey(StoreType.remote, REPO)), equalTo(true));
    RemoteRepository r = client.stores().load(StoreType.remote, TEST_REPO, RemoteRepository.class);
    String metadata = r.getMetadata(ImpliedRepoMetadataManager.IMPLIED_STORES);
    assertThat("Reference to repositories implied by POMs in this repo is missing from metadata.", metadata.contains("remote:" + REPO), equalTo(true));
    r = client.stores().load(StoreType.remote, REPO, RemoteRepository.class);
    metadata = r.getMetadata(ImpliedRepoMetadataManager.IMPLIED_BY_STORES);
    assertThat("Backref to repo with pom that implies this repo is missing from metadata.", metadata.contains("remote:" + TEST_REPO), equalTo(true));
}
Also used : Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test)

Example 92 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class KojiMavenMetadataProviderTest method initKojiClient.

private void initKojiClient(String exchangeName, boolean verifyArtifacts) throws BindException, IOException, GalleyInitException, IndyDataException {
    StoreDataManager storeDataManager = new MemoryStoreDataManager(true);
    if (verifyArtifacts) {
        RemoteRepository verifyRepo = new RemoteRepository(MAVEN_PKG_KEY, VERIFY_REPO, server.formatUrl(VERIFY_BASEPATH));
        storeDataManager.storeArtifactStore(verifyRepo, new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding verification repo"), false, true, new EventMetadata());
        kojiConfig.setArtifactAuthorityStore(new StoreKey(MAVEN_PKG_KEY, remote, VERIFY_REPO).toString());
    }
    String resourceBase = "koji-metadata/" + exchangeName;
    configureKojiServer(server, KOJI_BASEPATH, counter, resourceBase, verifyArtifacts, VERIFY_BASEPATH);
    kojiClient = new KojiClient(kojiConfig, new MemoryPasswordManager(), Executors.newCachedThreadPool());
    GalleyCore galley = new GalleyCoreBuilder(new FileCacheProviderFactory(temp.newFolder("cache"))).withEnabledTransports(new HttpClientTransport(new HttpImpl(new org.commonjava.maven.galley.auth.MemoryPasswordManager()), new IndyObjectMapper(true), new GlobalHttpConfiguration())).build();
    DownloadManager downloadManager = new DefaultDownloadManager(storeDataManager, galley.getTransferManager(), new IndyLocationExpander(storeDataManager));
    DirectContentAccess directContentAccess = new DefaultDirectContentAccess(downloadManager, Executors.newCachedThreadPool());
    DirectContentAccess dca = new DefaultDirectContentAccess(downloadManager, Executors.newSingleThreadExecutor());
    ContentDigester contentDigester = new DefaultContentDigester(dca, new CacheHandle<String, TransferMetadata>("content-metadata", contentMetadata));
    KojiBuildAuthority buildAuthority = new KojiBuildAuthority(kojiConfig, new StandardTypeMapper(), kojiClient, storeDataManager, contentDigester, directContentAccess);
    provider = new KojiMavenMetadataProvider(this.cache, kojiClient, buildAuthority, kojiConfig);
}
Also used : GalleyCoreBuilder(org.commonjava.maven.galley.GalleyCoreBuilder) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) DownloadManager(org.commonjava.indy.content.DownloadManager) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) HttpImpl(org.commonjava.maven.galley.transport.htcli.HttpImpl) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) DefaultDirectContentAccess(org.commonjava.indy.core.content.DefaultDirectContentAccess) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) MemoryStoreDataManager(org.commonjava.indy.mem.data.MemoryStoreDataManager) IndyLocationExpander(org.commonjava.indy.content.IndyLocationExpander) MemoryStoreDataManager(org.commonjava.indy.mem.data.MemoryStoreDataManager) StoreDataManager(org.commonjava.indy.data.StoreDataManager) DefaultDownloadManager(org.commonjava.indy.core.content.DefaultDownloadManager) StandardTypeMapper(org.commonjava.maven.galley.maven.internal.type.StandardTypeMapper) ContentDigester(org.commonjava.indy.content.ContentDigester) DefaultContentDigester(org.commonjava.indy.core.content.DefaultContentDigester) GalleyCore(org.commonjava.maven.galley.GalleyCore) DefaultContentDigester(org.commonjava.indy.core.content.DefaultContentDigester) FileCacheProviderFactory(org.commonjava.maven.galley.cache.FileCacheProviderFactory) MemoryPasswordManager(org.commonjava.util.jhttpc.auth.MemoryPasswordManager) StoreKey(org.commonjava.indy.model.core.StoreKey) HttpClientTransport(org.commonjava.maven.galley.transport.htcli.HttpClientTransport) GlobalHttpConfiguration(org.commonjava.maven.galley.transport.htcli.conf.GlobalHttpConfiguration) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) KojiClient(com.redhat.red.build.koji.KojiClient) DefaultDirectContentAccess(org.commonjava.indy.core.content.DefaultDirectContentAccess)

Example 93 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class HttProxOriginMigrationAction method migrate.

@Override
public boolean migrate() throws IndyLifecycleException {
    List<RemoteRepository> repos;
    try {
        repos = storeDataManager.query().noPackageType().getAllRemoteRepositories();
    } catch (IndyDataException e) {
        throw new IndyLifecycleException("Cannot retrieve all remote repositories. Reason: %s", e, e.getMessage());
    }
    List<RemoteRepository> toStore = new ArrayList<>();
    repos.forEach((repo) -> {
        if (repo.getDescription() != null && repo.getDescription().contains("HTTProx proxy")) {
            repo.setMetadata(ArtifactStore.METADATA_ORIGIN, ProxyAcceptHandler.HTTPROX_ORIGIN);
            RemoteRepository store = repo.copyOf(GENERIC_PKG_KEY, repo.getName());
            toStore.add(store);
        }
    });
    final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding HttProx origin metadata");
    for (RemoteRepository repo : toStore) {
        try {
            storeDataManager.storeArtifactStore(repo, changeSummary, false, true, new EventMetadata());
        } catch (IndyDataException e) {
            throw new IndyLifecycleException("Failed to store %s with HttProx origin metadata. Reason: %s", e, repo == null ? "NULL REPO" : repo.getKey(), e.getMessage());
        }
    }
    return !toStore.isEmpty();
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 94 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class ProxyResponseWriter method getRepository.

private RemoteRepository getRepository(final URL url) throws IndyDataException {
    int port = url.getPort();
    if (port < 1) {
        port = url.getDefaultPort();
    }
    String name = PROXY_REPO_PREFIX + url.getHost().replace('.', '-') + '_' + port;
    final String baseUrl = String.format("%s://%s:%s/", url.getProtocol(), url.getHost(), port);
    ArtifactStoreQuery<RemoteRepository> query = storeManager.query().packageType(GENERIC_PKG_KEY).storeType(RemoteRepository.class);
    RemoteRepository remote = query.getRemoteRepositoryByUrl(baseUrl);
    if (remote == null) {
        logger.debug("Looking for remote repo with name: {}", name);
        remote = query.getByName(name);
        // if repo with this name already exists, it has a different url, so we need to use a different name
        int i = 1;
        while (remote != null) {
            name = PROXY_REPO_PREFIX + url.getHost().replace('.', '-') + "_" + i++;
            logger.debug("Looking for remote repo with name: {}", name);
            remote = query.getByName(name);
        }
    }
    if (remote == null) {
        logger.debug("Creating remote repository for HTTProx request: {}", url);
        final UrlInfo info = new UrlInfo(url.toExternalForm());
        if (repoCreator == null) {
            throw new IndyDataException("No valid instance of ProxyRepositoryCreator. Cannot auto-create remote proxy to: '{}'", baseUrl);
        }
        final UserPass up = UserPass.parse(ApplicationHeader.authorization, httpRequest, url.getAuthority());
        remote = repoCreator.create(name, baseUrl, info, up, LoggerFactory.getLogger(repoCreator.getClass()));
        remote.setMetadata(ArtifactStore.METADATA_ORIGIN, ProxyAcceptHandler.HTTPROX_ORIGIN);
        final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating HTTProx proxy for: " + info.getUrl());
        storeManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata());
    }
    return remote;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) UrlInfo(org.commonjava.indy.util.UrlInfo) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) UserPass(org.commonjava.indy.subsys.http.util.UserPass) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 95 with RemoteRepository

use of org.commonjava.indy.model.core.RemoteRepository in project indy by Commonjava.

the class KojiContentManagerDecorator method exists.

@Override
@IndyMetrics(measure = @Measure(timers = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_EXISTS + IndyMetricsNames.TIMER), meters = @MetricNamed(name = IndyMetricsKojiNames.METHOD_CONTENTMANAGER_EXISTS + IndyMetricsNames.METER)))
public boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.info("KOJI: Delegating initial existence check for: {}/{}", store.getKey(), path);
    boolean result = delegate.exists(store, path);
    if (!result && StoreType.group == store.getKey().getType()) {
        Group group = (Group) store;
        logger.info("KOJI: Checking whether Koji contains a build matching: {}", path);
        RemoteRepository kojiProxy = findKojiBuildAnd(store, path, new EventMetadata(), null, this::createRemoteRepository);
        if (kojiProxy != null) {
            adjustTargetGroup(kojiProxy, group);
            result = delegate.exists(kojiProxy, path);
        }
        if (result) {
            nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
        }
    }
    return result;
}
Also used : Group(org.commonjava.indy.model.core.Group) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Logger(org.slf4j.Logger) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyMetrics(org.commonjava.indy.measure.annotation.IndyMetrics)

Aggregations

RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)149 Test (org.junit.Test)99 InputStream (java.io.InputStream)52 Group (org.commonjava.indy.model.core.Group)48 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)32 StoreKey (org.commonjava.indy.model.core.StoreKey)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)27 ByteArrayInputStream (java.io.ByteArrayInputStream)22 File (java.io.File)17 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)17 HostedRepository (org.commonjava.indy.model.core.HostedRepository)17 PathInfo (org.commonjava.indy.client.core.helper.PathInfo)16 IndyDataException (org.commonjava.indy.data.IndyDataException)14 Before (org.junit.Before)13 Category (org.junit.experimental.categories.Category)12 Date (java.util.Date)10 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)10 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)9 HttpGet (org.apache.http.client.methods.HttpGet)9