Search in sources :

Example 1 with AbstractProxyRepositoryCreator

use of org.commonjava.indy.httprox.handler.AbstractProxyRepositoryCreator in project indy by Commonjava.

the class ProxyResponseHelper method getRemoteRepositoryName.

/**
 * if repo with this name already exists, we need to use a different name
 */
private String getRemoteRepositoryName(URL url) throws IndyDataException {
    final String name = repoCreator.formatId(url.getHost(), getPort(url), 0, null, StoreType.remote);
    logger.debug("Looking for remote repo starts with name: {}", name);
    AbstractProxyRepositoryCreator abstractProxyRepositoryCreator = null;
    if (repoCreator instanceof AbstractProxyRepositoryCreator) {
        abstractProxyRepositoryCreator = (AbstractProxyRepositoryCreator) repoCreator;
    }
    if (abstractProxyRepositoryCreator == null) {
        return name;
    }
    Predicate<ArtifactStore> filter = abstractProxyRepositoryCreator.getNameFilter(name);
    List<String> l = storeManager.query().getAllRemoteRepositories(GENERIC_PKG_KEY).stream().filter(filter).map(repository -> repository.getName()).collect(Collectors.toList());
    if (l.isEmpty()) {
        return name;
    }
    return abstractProxyRepositoryCreator.getNextName(l);
}
Also used : ProxyCreationResult(org.commonjava.indy.httprox.handler.ProxyCreationResult) URL(java.net.URL) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) LoggerFactory(org.slf4j.LoggerFactory) PATH(org.commonjava.indy.util.RequestContextHelper.PATH) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StringUtils(org.apache.commons.lang3.StringUtils) PACKAGE_TYPE(org.commonjava.indy.util.RequestContextHelper.PACKAGE_TYPE) Group(org.commonjava.indy.model.core.Group) Transfer(org.commonjava.maven.galley.model.Transfer) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) NameUtils.name(org.commonjava.o11yphant.metrics.util.NameUtils.name) TraceManager.addFieldToActiveSpan(org.commonjava.o11yphant.trace.TraceManager.addFieldToActiveSpan) FoloConstants(org.commonjava.indy.folo.ctl.FoloConstants) AbstractProxyRepositoryCreator(org.commonjava.indy.httprox.handler.AbstractProxyRepositoryCreator) ApplicationHeader(org.commonjava.indy.util.ApplicationHeader) MetricsManager(org.commonjava.o11yphant.metrics.MetricsManager) GENERIC_PKG_KEY(org.commonjava.indy.model.core.GenericPackageTypeDescriptor.GENERIC_PKG_KEY) ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) TRACKING_ID(org.commonjava.indy.model.core.ArtifactStore.TRACKING_ID) ArtifactStoreQuery(org.commonjava.indy.data.ArtifactStoreQuery) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ProxyRepositoryCreator(org.commonjava.indy.httprox.handler.ProxyRepositoryCreator) Predicate(java.util.function.Predicate) TraceManager(org.commonjava.o11yphant.trace.TraceManager) StoreType(org.commonjava.indy.model.core.StoreType) AccessChannel(org.commonjava.indy.model.core.AccessChannel) IOException(java.io.IOException) CONTENT_ENTRY_POINT(org.commonjava.indy.util.RequestContextHelper.CONTENT_ENTRY_POINT) METADATA_CONTENT(org.commonjava.indy.util.RequestContextHelper.METADATA_CONTENT) HttpRequest(org.apache.http.HttpRequest) IndyMetricsConfig(org.commonjava.indy.subsys.metrics.conf.IndyMetricsConfig) Collectors(java.util.stream.Collectors) PKG_TYPE_GENERIC_HTTP(org.commonjava.maven.galley.io.SpecialPathConstants.PKG_TYPE_GENERIC_HTTP) RequestContextHelper.setContext(org.commonjava.indy.util.RequestContextHelper.setContext) Timer(org.commonjava.o11yphant.metrics.api.Timer) List(java.util.List) HttproxConfig(org.commonjava.indy.httprox.conf.HttproxConfig) ContentController(org.commonjava.indy.core.ctl.ContentController) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) UserPass(org.commonjava.indy.subsys.http.util.UserPass) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) UrlInfo(org.commonjava.indy.util.UrlInfo) TransferException(org.commonjava.maven.galley.TransferException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) AbstractProxyRepositoryCreator(org.commonjava.indy.httprox.handler.AbstractProxyRepositoryCreator)

Example 2 with AbstractProxyRepositoryCreator

use of org.commonjava.indy.httprox.handler.AbstractProxyRepositoryCreator in project indy by Commonjava.

the class AbstractProxyRepositoryCreatorTest method testGetDistinctName.

@Ignore
@Test
public void testGetDistinctName() {
    AbstractProxyRepositoryCreator creator = new AbstractProxyRepositoryCreator() {

        @Override
        public ProxyCreationResult create(String trackingID, String name, String baseUrl, UrlInfo urlInfo, UserPass userPass, Logger logger) {
            return null;
        }
    };
    String host = "127-0-0-1";
    String port = "80";
    List<String> names = new ArrayList<>();
    String name_0 = "httprox_" + host + "_" + port;
    String name_1 = name_0 + "_1";
    String name_2 = name_0 + "_2";
    String name_3 = name_0 + "_3";
    String name_4 = name_0 + "_4";
    names.add(name_0);
    String name = creator.getNextName(names);
    assertThat(name, equalTo(name_1));
    names.add(name_2);
    names.add(name_1);
    names.add(name_3);
    name = creator.getNextName(names);
    assertThat(name, equalTo(name_4));
}
Also used : UrlInfo(org.commonjava.indy.util.UrlInfo) ArrayList(java.util.ArrayList) UserPass(org.commonjava.indy.subsys.http.util.UserPass) Logger(org.slf4j.Logger) AbstractProxyRepositoryCreator(org.commonjava.indy.httprox.handler.AbstractProxyRepositoryCreator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

AbstractProxyRepositoryCreator (org.commonjava.indy.httprox.handler.AbstractProxyRepositoryCreator)2 UserPass (org.commonjava.indy.subsys.http.util.UserPass)2 UrlInfo (org.commonjava.indy.util.UrlInfo)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 HttpRequest (org.apache.http.HttpRequest)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 ChangeSummary (org.commonjava.indy.audit.ChangeSummary)1 ContentController (org.commonjava.indy.core.ctl.ContentController)1 ArtifactStoreQuery (org.commonjava.indy.data.ArtifactStoreQuery)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 StoreDataManager (org.commonjava.indy.data.StoreDataManager)1 FoloConstants (org.commonjava.indy.folo.ctl.FoloConstants)1 TrackingKey (org.commonjava.indy.folo.model.TrackingKey)1 HttproxConfig (org.commonjava.indy.httprox.conf.HttproxConfig)1