Search in sources :

Example 1 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method doPutPackages.

@TransactionalStoreBlob
protected Content doPutPackages(final String path, final TempBlob packagesContent, final Payload payload) throws IOException {
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());
    String assetPath = packagesPath(path);
    Asset asset = findAsset(tx, bucket, assetPath);
    if (asset == null) {
        asset = tx.createAsset(bucket, getRepository().getFormat());
        asset.name(assetPath);
        asset.formatAttributes().set(P_ASSET_KIND, PACKAGES.name());
    }
    return saveAsset(tx, asset, packagesContent, payload);
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Bucket(org.sonatype.nexus.repository.storage.Bucket) 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) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Example 2 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx 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 3 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RProxyFacetImpl method doPutArchive.

@TransactionalStoreBlob
protected Content doPutArchive(final String path, final String filename, final TempBlob archiveContent, final Payload payload) throws IOException {
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());
    String assetPath = path(path, filename);
    Map<String, String> attributes;
    try (InputStream is = archiveContent.get()) {
        attributes = extractDescriptionFromArchive(filename, is);
    }
    String name = attributes.get(P_PACKAGE);
    String version = attributes.get(P_VERSION);
    Component component = findComponent(tx, getRepository(), name, version);
    if (component == null) {
        component = tx.createComponent(bucket, getRepository().getFormat()).name(name).version(version);
    }
    tx.saveComponent(component);
    Asset asset = findAsset(tx, bucket, assetPath);
    if (asset == null) {
        asset = tx.createAsset(bucket, component);
        asset.name(assetPath);
        asset.formatAttributes().set(P_ASSET_KIND, ARCHIVE.name());
    }
    // TODO: Make this a bit more robust (could be problematic if keys are removed in later versions, or if keys clash)
    for (Entry<String, String> entry : attributes.entrySet()) {
        asset.formatAttributes().set(entry.getKey(), entry.getValue());
    }
    return saveAsset(tx, asset, archiveContent, payload);
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Bucket(org.sonatype.nexus.repository.storage.Bucket) InputStream(java.io.InputStream) 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) RFacetUtils.findComponent(org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent) Component(org.sonatype.nexus.repository.storage.Component) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Example 4 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RHostedFacetImpl method doPutArchive.

@TransactionalStoreBlob
protected void doPutArchive(final String path, final TempBlob archiveContent, final Payload payload) throws IOException {
    checkNotNull(path);
    checkNotNull(archiveContent);
    checkNotNull(payload);
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());
    Map<String, String> attributes;
    try (InputStream is = archiveContent.get()) {
        attributes = extractDescriptionFromArchive(path, is);
    }
    String name = attributes.get(P_PACKAGE);
    String version = attributes.get(P_VERSION);
    Component component = findComponent(tx, getRepository(), name, version);
    if (component == null) {
        component = tx.createComponent(bucket, getRepository().getFormat()).name(name).version(version);
    }
    tx.saveComponent(component);
    Asset asset = findAsset(tx, bucket, path);
    if (asset == null) {
        asset = tx.createAsset(bucket, component);
        asset.name(path);
        asset.formatAttributes().set(P_ASSET_KIND, ARCHIVE.name());
    }
    // TODO: Make this a bit more robust (could be problematic if keys are removed in later versions, or if keys clash)
    for (Entry<String, String> entry : attributes.entrySet()) {
        asset.formatAttributes().set(entry.getKey(), entry.getValue());
    }
    saveAsset(tx, asset, archiveContent, payload);
}
Also used : StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Bucket(org.sonatype.nexus.repository.storage.Bucket) InputStream(java.io.InputStream) 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) RFacetUtils.findComponent(org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent) Component(org.sonatype.nexus.repository.storage.Component) TransactionalStoreBlob(org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)

Example 5 with StorageTx

use of org.sonatype.nexus.repository.storage.StorageTx in project nexus-repository-r by sonatype-nexus-community.

the class RRestoreBlobIT method runBlobRestore.

private void runBlobRestore(final boolean isDryRun) {
    Asset asset;
    Blob blob;
    try (StorageTx tx = getStorageTx(proxyRepository)) {
        tx.begin();
        asset = tx.findAssetWithProperty(AssetEntityAdapter.P_NAME, AGRICOLAE_131_TARGZ.fullPath, tx.findBucket(proxyRepository));
        assertThat(asset, Matchers.notNullValue());
        blob = tx.getBlob(asset.blobRef());
    }
    testHelper.simulateAssetMetadataLoss();
    Properties properties = new Properties();
    properties.setProperty(HEADER_PREFIX + REPO_NAME_HEADER, proxyRepository.getName());
    properties.setProperty(HEADER_PREFIX + BLOB_NAME_HEADER, asset.name());
    properties.setProperty(HEADER_PREFIX + CONTENT_TYPE_HEADER, asset.contentType());
    rRestoreBlobStrategy.restore(properties, blob, BlobStoreManager.DEFAULT_BLOBSTORE_NAME, isDryRun);
}
Also used : Blob(org.sonatype.nexus.blobstore.api.Blob) StorageTx(org.sonatype.nexus.repository.storage.StorageTx) Asset(org.sonatype.nexus.repository.storage.Asset) Properties(java.util.Properties)

Aggregations

Asset (org.sonatype.nexus.repository.storage.Asset)17 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)17 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.findAsset)7 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.RFacetUtils.saveAsset)7 RFacetUtils.findAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.findAsset)7 RFacetUtils.saveAsset (org.sonatype.nexus.repository.r.internal.util.RFacetUtils.saveAsset)7 Component (org.sonatype.nexus.repository.storage.Component)7 TransactionalStoreBlob (org.sonatype.nexus.repository.transaction.TransactionalStoreBlob)7 InputStream (java.io.InputStream)6 TransactionalTouchBlob (org.sonatype.nexus.repository.transaction.TransactionalTouchBlob)6 RFacet (org.sonatype.nexus.repository.r.RFacet)5 TransactionalTouchMetadata (org.sonatype.nexus.repository.transaction.TransactionalTouchMetadata)4 Bucket (org.sonatype.nexus.repository.storage.Bucket)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Map (java.util.Map)2 RFacetUtils.findComponent (org.sonatype.nexus.repository.r.internal.RFacetUtils.findComponent)2 Content (org.sonatype.nexus.repository.view.Content)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1