Search in sources :

Example 96 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 97 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 98 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)

Example 99 with RemoteRepository

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

the class KojiContentManagerDecorator method retrieve.

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

Example 100 with RemoteRepository

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

the class KojiOriginMigrationAction 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("Koji build")) {
            repo.setMetadata(METADATA_ORIGIN, KOJI_ORIGIN);
            toStore.add(repo);
        }
    });
    final ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Adding Koji 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 Koji 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)

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