Search in sources :

Example 96 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class KojiMavenMetadataProvider method clearPaths.

private void clearPaths(final Set<Group> affected, final String path) {
    Logger logger = LoggerFactory.getLogger(getClass());
    affected.forEach(group -> {
        try {
            // delete so it'll be recomputed.
            final Transfer target = fileManager.getTransfer(group, path);
            if (target.exists()) {
                logger.debug("Deleting merged file: {}", target);
                target.delete(false);
                if (target.exists()) {
                    logger.error("\n\n\n\nDID NOT DELETE merged metadata file at: {} in group: {}\n\n\n\n", path, group.getName());
                }
                helper.deleteChecksumsAndMergeInfo(group, path);
            } else {
                ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(group), path);
                nfc.clearMissing(resource);
            }
            // make sure we delete these, even if they're left over.
            helper.deleteChecksumsAndMergeInfo(group, path);
        } catch (final IndyWorkflowException | IOException e) {
            logger.error("Failed to delete generated file (to allow re-generation on demand: {}/{}. Error: {}", e, group.getKey(), path, e.getMessage());
        }
    });
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) IOException(java.io.IOException) Logger(org.slf4j.Logger)

Example 97 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class KojiContentManagerDecorator method getTransfer.

@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation operation) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("KOJI: Delegating initial getTransfer() attempt for: {}/{}", store.getKey(), path);
    Transfer result = delegate.getTransfer(store, path, operation);
    if (result == null && kojiUtils.isVersionSignatureAllowedWithPath(path) && TransferOperation.DOWNLOAD == operation && StoreType.group == store.getKey().getType()) {
        logger.info("KOJI: Checking for Koji build matching: {}", path);
        Group group = (Group) store;
        RemoteRepository kojiProxy = findKojiBuildAnd(store, path, new EventMetadata(), null, this::createRemoteRepository);
        if (kojiProxy != null) {
            adjustTargetGroup(kojiProxy, group);
            EventMetadata eventMetadata = new EventMetadata().set(ContentManager.ENTRY_POINT_STORE, store.getKey());
            result = delegate.retrieve(kojiProxy, path, eventMetadata);
        }
        if (result != null && result.exists()) {
            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) EventMetadata(org.commonjava.maven.galley.event.EventMetadata)

Example 98 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class AbstractMergedContentGenerator method clearMergedFile.

protected void clearMergedFile(final Group group, final String path) {
    try {
        // delete so it'll be recomputed.
        final Transfer target = fileManager.getTransfer(group, path);
        if (target.exists()) {
            logger.debug("Deleting merged file: {}", target);
            target.delete(false);
            if (target.exists()) {
                logger.error("\n\n\n\nDID NOT DELETE merged metadata file at: {} in group: {}\n\n\n\n", path, group.getName());
            }
            helper.deleteChecksumsAndMergeInfo(group, path);
        } else {
            ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(group), path);
            nfc.clearMissing(resource);
        }
        // make sure we delete these, even if they're left over.
        helper.deleteChecksumsAndMergeInfo(group, path);
    } catch (final IndyWorkflowException | IOException e) {
        logger.error("Failed to delete generated file (to allow re-generation on demand: {}/{}. Error: {}", e, group.getKey(), path, e.getMessage());
    }
}
Also used : IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) IOException(java.io.IOException)

Example 99 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class DefaultContentManager method clearNFCEntries.

@Measure
protected void clearNFCEntries(final KeyedLocation kl, final String path, EventMetadata eventMetadata) {
    try {
        Set<Group> groups = storeManager.affectedBy(Arrays.asList(kl.getKey()), eventMetadata);
        groups.stream().map((g) -> new ConcreteResource(LocationUtils.toLocation(g), path)).forEach((cr) -> nfc.clearMissing(cr));
        nfc.clearMissing(new ConcreteResource(kl, path));
    } catch (IndyDataException e) {
        logger.error(String.format("Failed to clear NFC entries affected by upload of: %s to: %s. Reason: %s", path, kl.getKey(), e.getMessage()), e);
    }
}
Also used : Arrays(java.util.Arrays) HTTP_METADATA_EXT(org.commonjava.maven.galley.io.SpecialPathConstants.HTTP_METADATA_EXT) ContentDigester(org.commonjava.indy.content.ContentDigester) GroupRepositoryFilterManager(org.commonjava.indy.core.content.group.GroupRepositoryFilterManager) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CHECK_CACHE_ONLY(org.commonjava.indy.IndyContentConstants.CHECK_CACHE_ONLY) LoggerFactory(org.slf4j.LoggerFactory) ContentUtils.dedupeListing(org.commonjava.indy.util.ContentUtils.dedupeListing) StringUtils(org.apache.commons.lang3.StringUtils) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) TransferManager(org.commonjava.maven.galley.TransferManager) CASCADE(org.commonjava.indy.IndyContentConstants.CASCADE) DownloadManager(org.commonjava.indy.content.DownloadManager) ApplicationStatus(org.commonjava.indy.util.ApplicationStatus) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreType.group(org.commonjava.indy.model.core.StoreType.group) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyObjectMapper(org.commonjava.indy.model.core.io.IndyObjectMapper) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) IOException(java.io.IOException) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) Collectors(java.util.stream.Collectors) ContentManager(org.commonjava.indy.content.ContentManager) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IGNORE_READONLY(org.commonjava.indy.data.StoreDataManager.IGNORE_READONLY) IndyConfiguration(org.commonjava.indy.conf.IndyConfiguration) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreResource(org.commonjava.indy.content.StoreResource) StoreType.hosted(org.commonjava.indy.model.core.StoreType.hosted) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) HttpExchangeMetadata(org.commonjava.maven.galley.transport.htcli.model.HttpExchangeMetadata) InputStream(java.io.InputStream) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 100 with ConcreteResource

use of org.commonjava.maven.galley.model.ConcreteResource in project indy by Commonjava.

the class ContentController method renderListing.

/**
 * @deprecated directory listing has been moved to addons/content-browse
 */
@Deprecated
public String renderListing(final String acceptHeader, final StoreKey key, final String requestPath, final String serviceUrl, final UriFormatter uriFormatter, final EventMetadata eventMetadata) throws IndyWorkflowException {
    String path = requestPath;
    if (path.endsWith(LISTING_HTML_FILE)) {
        path = normalize(parentPath(path));
    }
    validatePath(key, path);
    final List<StoreResource> listed = getListing(key, path, eventMetadata);
    if (ApplicationContent.application_json.equals(acceptHeader)) {
        final DirectoryListingDTO dto = new DirectoryListingDTO(StoreResource.convertToEntries(listed));
        try {
            return mapper.writeValueAsString(dto);
        } catch (final JsonProcessingException e) {
            throw new IndyWorkflowException("Failed to render listing to JSON: %s. Reason: %s", e, dto, e.getMessage());
        }
    }
    final Map<String, Set<String>> listingUrls = new TreeMap<>();
    final String storeUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName());
    if (listed != null) {
        // second pass, process the remainder.
        for (int pass = 0; pass < 2; pass++) {
            for (final ConcreteResource res : listed) {
                String p = res.getPath();
                if (pass == 0 && !p.endsWith("/")) {
                    continue;
                }
                if (p.endsWith("-") || p.endsWith("-/")) {
                    // skip npm adduser path to avoid the sensitive info showing.
                    continue;
                } else if (pass == 1) {
                    if (!p.endsWith("/")) {
                        final String dirpath = p + "/";
                        if (listingUrls.containsKey(normalize(storeUrl, dirpath))) {
                            p = dirpath;
                        }
                    } else {
                        continue;
                    }
                }
                final String localUrl = normalize(storeUrl, p);
                Set<String> sources = listingUrls.get(localUrl);
                if (sources == null) {
                    sources = new HashSet<>();
                    listingUrls.put(localUrl, sources);
                }
                sources.add(normalize(res.getLocationUri(), res.getPath()));
            }
        }
    }
    final List<String> sources = new ArrayList<>();
    if (listed != null) {
        for (final ConcreteResource res : listed) {
            // KeyedLocation is all we use in Indy.
            logger.debug("Formatting sources URL for: {}", res);
            final KeyedLocation kl = (KeyedLocation) res.getLocation();
            final String uri = uriFormatter.formatAbsolutePathTo(serviceUrl, kl.getKey().getType().singularEndpointName(), kl.getKey().getName());
            if (!sources.contains(uri)) {
                logger.debug("adding source URI: '{}'", uri);
                sources.add(uri);
            }
        }
    }
    Collections.sort(sources);
    String parentPath = normalize(parentPath(path));
    if (!parentPath.endsWith("/")) {
        parentPath += "/";
    }
    final String parentUrl;
    if (parentPath.equals(path)) {
        parentPath = null;
        parentUrl = null;
    } else {
        parentUrl = uriFormatter.formatAbsolutePathTo(serviceUrl, key.getType().singularEndpointName(), key.getName(), parentPath);
    }
    final Map<String, Object> params = new HashMap<>();
    params.put("items", listingUrls);
    params.put("parentUrl", parentUrl);
    params.put("parentPath", parentPath);
    params.put("path", path);
    params.put("storeKey", key);
    params.put("storeUrl", storeUrl);
    params.put("baseUrl", serviceUrl);
    params.put("sources", sources);
    // render...
    try {
        return templates.render(acceptHeader, "directory-listing", params);
    } catch (final IndyGroovyException e) {
        throw new IndyWorkflowException(e.getMessage(), e);
    }
}
Also used : DirectoryListingDTO(org.commonjava.indy.model.core.dto.DirectoryListingDTO) HashSet(java.util.HashSet) Set(java.util.Set) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) IndyGroovyException(org.commonjava.indy.subsys.template.IndyGroovyException) StoreResource(org.commonjava.indy.content.StoreResource) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)206 Test (org.junit.Test)138 Transfer (org.commonjava.maven.galley.model.Transfer)92 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)55 Location (org.commonjava.maven.galley.model.Location)45 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)36 BMScript (org.jboss.byteman.contrib.bmunit.BMScript)33 OutputStream (java.io.OutputStream)30 InputStream (java.io.InputStream)26 Group (org.commonjava.indy.model.core.Group)25 ArrayList (java.util.ArrayList)23 HostedRepository (org.commonjava.indy.model.core.HostedRepository)23 TransferException (org.commonjava.maven.galley.TransferException)23 SimpleHttpLocation (org.commonjava.maven.galley.transport.htcli.model.SimpleHttpLocation)23 HashSet (java.util.HashSet)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)18 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)18 Logger (org.slf4j.Logger)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)16