Search in sources :

Example 1 with TransactionalTouchMetadata

use of org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method setCacheInfo.

@TransactionalTouchMetadata
public void setCacheInfo(final Content content, final CacheInfo cacheInfo) throws IOException {
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content);
    if (asset == null) {
        log.debug("Attempting to set cache info for non-existent R asset {}", content.getAttributes().require(Asset.class));
        return;
    }
    log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo);
    CacheInfo.applyToAsset(asset, cacheInfo);
    tx.saveAsset(asset);
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Example 2 with TransactionalTouchMetadata

use of org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method buildAndPutPackagesGz.

@Override
@TransactionalTouchMetadata
public Content buildAndPutPackagesGz(final String basePath) throws IOException {
    checkNotNull(basePath);
    StorageTx tx = UnitOfWork.currentTx();
    RPackagesBuilder packagesBuilder = new RPackagesBuilder();
    Iterable<Asset> archiveAssets = browseAllAssetsByKind(tx, tx.findBucket(getRepository()), ARCHIVE);
    // packageInfoBuilder doesn't support multithreading
    StreamSupport.stream(archiveAssets.spliterator(), false).filter(asset -> basePath.equals(getBasePath(asset.name()))).forEach(packagesBuilder::append);
    byte[] packagesBytes = packagesBuilder.buildPackagesGz();
    StorageFacet storageFacet = getRepository().facet(StorageFacet.class);
    try (InputStream is = new ByteArrayInputStream(packagesBytes)) {
        TempBlob tempPackagesGz = storageFacet.createTempBlob(is, RFacetUtils.HASH_ALGORITHMS);
        return doPutPackagesGz(tx, basePath, tempPackagesGz);
    }
}
Also used : StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) ARCHIVE(org.sonatype.nexus.repository.r.internal.AssetKind.ARCHIVE) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacet(org.sonatype.nexus.repository.r.RFacet) RFacetUtils(org.sonatype.nexus.repository.r.internal.util.RFacetUtils) RFacetUtils.toContent(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.toContent) Component(org.sonatype.nexus.repository.storage.Component) UnitOfWork(org.sonatype.nexus.transaction.UnitOfWork) ByteArrayInputStream(java.io.ByteArrayInputStream) RHostedFacet(org.sonatype.nexus.repository.r.RHostedFacet) Map(java.util.Map) Payload(org.sonatype.nexus.repository.view.Payload) StreamSupport(java.util.stream.StreamSupport) PACKAGES_GZ_FILENAME(org.sonatype.nexus.repository.r.internal.util.RPathUtils.PACKAGES_GZ_FILENAME) Named(javax.inject.Named) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob) RDescriptionUtils.extractDescriptionFromArchive(org.sonatype.nexus.repository.r.internal.util.RDescriptionUtils.extractDescriptionFromArchive) TempBlob(org.sonatype.nexus.repository.storage.TempBlob) RPathUtils.getBasePath(org.sonatype.nexus.repository.r.internal.util.RPathUtils.getBasePath) TransactionalTouchBlob(org.sonatype.nexus.repository.transaction.TransactionalTouchBlob) FacetSupport(org.sonatype.nexus.repository.FacetSupport) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) IOException(java.io.IOException) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Asset(org.sonatype.nexus.repository.storage.Asset) Content(org.sonatype.nexus.repository.view.Content) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata) RFacetUtils.browseAllAssetsByKind(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.browseAllAssetsByKind) RPathUtils.buildPath(org.sonatype.nexus.repository.r.internal.util.RPathUtils.buildPath) InputStream(java.io.InputStream) TempBlob(org.sonatype.nexus.repository.storage.TempBlob) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) StorageFacet(org.sonatype.nexus.repository.storage.StorageFacet) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Example 3 with TransactionalTouchMetadata

use of org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method setCacheInfo.

@TransactionalTouchMetadata
public void setCacheInfo(final Content content, final CacheInfo cacheInfo) {
    StorageTx tx = UnitOfWork.currentTx();
    Asset asset = Content.findAsset(tx, tx.findBucket(getRepository()), content);
    if (asset == null) {
        log.debug("Attempting to set cache info for non-existent R asset {}", content.getAttributes().require(Asset.class));
        return;
    }
    log.debug("Updating cacheInfo of {} to {}", asset, cacheInfo);
    CacheInfo.applyToAsset(asset, cacheInfo);
    tx.saveAsset(asset);
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset) Asset(org.sonatype.nexus.repository.storage.Asset) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Example 4 with TransactionalTouchMetadata

use of org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method getPackages.

@Override
@TransactionalTouchMetadata
public Content getPackages(final String packagesPath) {
    checkNotNull(packagesPath);
    try {
        // TODO: Do NOT do this on each request as there is at least some overhead, and memory usage is proportional to
        // the number of packages contained in a particular path. We should be able to generate this when something has
        // changed or via a scheduled task using an approach similar to the Yum implementation rather than this method.
        StorageTx tx = UnitOfWork.currentTx();
        RPackagesBuilder packagesBuilder = new RPackagesBuilder(packagesPath);
        for (Asset asset : tx.browseAssets(tx.findBucket(getRepository()))) {
            packagesBuilder.append(asset);
        }
        CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
            try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
                for (Entry<String, Map<String, String>> eachPackage : packagesBuilder.getPackageInformation().entrySet()) {
                    Map<String, String> packageInfo = eachPackage.getValue();
                    InternetHeaders headers = new InternetHeaders();
                    headers.addHeader(P_PACKAGE, packageInfo.get(P_PACKAGE));
                    headers.addHeader(P_VERSION, packageInfo.get(P_VERSION));
                    headers.addHeader(P_DEPENDS, packageInfo.get(P_DEPENDS));
                    headers.addHeader(P_IMPORTS, packageInfo.get(P_IMPORTS));
                    headers.addHeader(P_SUGGESTS, packageInfo.get(P_SUGGESTS));
                    headers.addHeader(P_LICENSE, packageInfo.get(P_LICENSE));
                    headers.addHeader(P_NEEDS_COMPILATION, packageInfo.get(P_NEEDS_COMPILATION));
                    Enumeration<String> headerLines = headers.getAllHeaderLines();
                    while (headerLines.hasMoreElements()) {
                        String line = headerLines.nextElement();
                        writer.write(line, 0, line.length());
                        writer.write('\n');
                    }
                    writer.write('\n');
                }
            }
        }
        return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
    } catch (CompressorException | IOException e) {
        throw new RException(packagesPath, e);
    }
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) InternetHeaders(javax.mail.internet.InternetHeaders) BytesPayload(org.sonatype.nexus.repository.view.payloads.BytesPayload) CompressorOutputStream(org.apache.commons.compress.compressors.CompressorOutputStream) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RFacetUtils.toContent(org.sonatype.nexus.repository.r.internal.RFacetUtils.toContent) Content(org.sonatype.nexus.repository.view.Content) CompressorException(org.apache.commons.compress.compressors.CompressorException) RFacetUtils.findAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset) RFacetUtils.saveAsset(org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset) Asset(org.sonatype.nexus.repository.storage.Asset) OutputStreamWriter(java.io.OutputStreamWriter) Map(java.util.Map) TransactionalTouchMetadata(org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)

Aggregations

Asset (org.sonatype.nexus.repository.storage.Asset)4 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)4 TransactionalTouchMetadata (org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)4 IOException (java.io.IOException)2 Map (java.util.Map)2 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)2 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)2 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)2 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset)2 Content (org.sonatype.nexus.repository.view.Content)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StreamSupport (java.util.stream.StreamSupport)1 Named (javax.inject.Named)1 InternetHeaders (javax.mail.internet.InternetHeaders)1 CompressorException (org.apache.commons.compress.compressors.CompressorException)1 CompressorOutputStream (org.apache.commons.compress.compressors.CompressorOutputStream)1