Search in sources :

Example 1 with ProxyCreationResult

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

the class ProxyResponseHelper method createRepo.

/**
 * Create repositories (group, remote, hosted) when trackingId is present. Otherwise create normal remote
 * repository with specified name.
 *
 * @param trackingId
 * @param url
 * @param name distinct remote repository name. null if trackingId is given
 */
private ProxyCreationResult createRepo(String trackingId, URL url, String name) throws IndyDataException {
    UrlInfo info = new UrlInfo(url.toExternalForm());
    UserPass up = UserPass.parse(ApplicationHeader.authorization, httpRequest, url.getAuthority());
    String baseUrl = getBaseUrl(url, false);
    logger.debug(">>>> Create repo: trackingId=" + trackingId + ", name=" + name);
    ProxyCreationResult result = repoCreator.create(trackingId, name, baseUrl, info, up, LoggerFactory.getLogger(repoCreator.getClass()));
    ChangeSummary changeSummary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Creating HTTProx proxy for: " + info.getUrl());
    RemoteRepository remote = result.getRemote();
    if (remote != null) {
        storeManager.storeArtifactStore(remote, changeSummary, false, true, new EventMetadata());
    }
    HostedRepository hosted = result.getHosted();
    if (hosted != null) {
        storeManager.storeArtifactStore(hosted, changeSummary, false, true, new EventMetadata());
    }
    Group group = result.getGroup();
    if (group != null) {
        storeManager.storeArtifactStore(group, changeSummary, false, true, new EventMetadata());
    }
    return result;
}
Also used : Group(org.commonjava.indy.model.core.Group) UrlInfo(org.commonjava.indy.util.UrlInfo) ProxyCreationResult(org.commonjava.indy.httprox.handler.ProxyCreationResult) UserPass(org.commonjava.indy.subsys.http.util.UserPass) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) HostedRepository(org.commonjava.indy.model.core.HostedRepository)

Example 2 with ProxyCreationResult

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

the class ProxyResponseHelper method doGetArtifactStore.

private ArtifactStore doGetArtifactStore(String trackingId, final URL url) throws IndyDataException {
    int port = getPort(url);
    if (trackingId != null) {
        String groupName = repoCreator.formatId(url.getHost(), port, 0, trackingId, StoreType.group);
        ArtifactStoreQuery<Group> query = storeManager.query().storeType(Group.class);
        Group group = query.getGroup(GENERIC_PKG_KEY, groupName);
        logger.debug("Get httproxy group, group: {}", group);
        if (group == null) {
            logger.debug("Creating repositories (group, hosted, remote) for HTTProx request: {}, trackingId: {}", url, trackingId);
            ProxyCreationResult result = createRepo(trackingId, url, null);
            group = result.getGroup();
        }
        return group;
    } else {
        RemoteRepository remote;
        final String baseUrl = getBaseUrl(url, false);
        ArtifactStoreQuery<RemoteRepository> query = storeManager.query().storeType(RemoteRepository.class);
        remote = query.getAllRemoteRepositories(GENERIC_PKG_KEY).stream().filter(store -> store.getUrl().equals(baseUrl) && store.getMetadata(TRACKING_ID) == null).findFirst().orElse(null);
        logger.debug("Get httproxy remote, remote: {}", remote);
        if (remote == null) {
            logger.debug("Creating remote repository for HTTProx request: {}", url);
            String name = getRemoteRepositoryName(url);
            ProxyCreationResult result = createRepo(null, url, name);
            remote = result.getRemote();
        }
        return remote;
    }
}
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) Group(org.commonjava.indy.model.core.Group) ProxyCreationResult(org.commonjava.indy.httprox.handler.ProxyCreationResult) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository)

Aggregations

ChangeSummary (org.commonjava.indy.audit.ChangeSummary)2 ProxyCreationResult (org.commonjava.indy.httprox.handler.ProxyCreationResult)2 Group (org.commonjava.indy.model.core.Group)2 HostedRepository (org.commonjava.indy.model.core.HostedRepository)2 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)2 UserPass (org.commonjava.indy.subsys.http.util.UserPass)2 UrlInfo (org.commonjava.indy.util.UrlInfo)2 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)2 IOException (java.io.IOException)1 URL (java.net.URL)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 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