Java Code Examples for org.sonatype.nexus.repository.storage.StorageTx#deleteAsset()

The following examples show how to use org.sonatype.nexus.repository.storage.StorageTx#deleteAsset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelmComponentMaintenanceFacet.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class)
@Override
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAsset(assetId, bucket);

  if (asset == null) {
    return Collections.emptySet();
  }

  tx.deleteAsset(asset, deleteBlobs);

  if (asset.componentId() != null) {
    Component component = tx.findComponentInBucket(asset.componentId(), bucket);

    if (!tx.browseAssets(component).iterator().hasNext()) {
      log.debug("Deleting component: {}", component);
      tx.deleteComponent(component, deleteBlobs);
    }
  }
  return Collections.singleton(asset.name());
}
 
Example 2
Source File: CondaComponentMaintenanceFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class)
@Override
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAsset(assetId, bucket);

  if (asset == null) {
    return emptySet();
  }

  tx.deleteAsset(asset, deleteBlobs);

  if (asset.componentId() != null) {
    Component component = tx.findComponentInBucket(asset.componentId(), bucket);

    if (!tx.browseAssets(component).iterator().hasNext()) {
      log.debug("Deleting component: {}", component);
      tx.deleteComponent(component, deleteBlobs);
    }
  }
  return Collections.singleton(asset.name());
}
 
Example 3
Source File: NpmFacetUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Deletes the package root and all related tarballs too.
 */
static Set<String> deletePackageRoot(final StorageTx tx,
                                     final Repository repository,
                                     final NpmPackageId packageId,
                                     final boolean deleteBlobs)
{
  // find package asset -> delete
  Asset packageRootAsset = findPackageRootAsset(tx, tx.findBucket(repository), packageId);
  if (packageRootAsset == null) {
    return Collections.emptySet();
  }
  tx.deleteAsset(packageRootAsset, deleteBlobs);
  // find all tarball components -> delete
  Iterable<Component> npmTarballs = findPackageTarballComponents(tx, repository, packageId);
  Set<String> deletedAssetNames = new HashSet<>();
  for (Component npmTarball : npmTarballs) {
    deletedAssetNames.addAll(tx.deleteComponent(npmTarball, deleteBlobs));
  }
  return deletedAssetNames;
}
 
Example 4
Source File: OrientPyPiIndexFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@TransactionalDeleteBlob
public void deleteIndex(final String packageName)
{
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  String indexPath = PyPiPathUtils.indexPath(normalizeName(packageName));
  Asset cachedIndex = findAsset(tx, bucket, indexPath);
  
  /*
    There is a chance that the index wasn't found because of package name normalization. For example '.' 
    characters are normalized to '-' so jts.python would have an index at /simple/jts-python/. It is possible that 
    we could just check for the normalized name but we check for both just in case. Searching for an index with a
    normalized name first means that most, if not all, index deletions will only perform a single search.
    
    See https://issues.sonatype.org/browse/NEXUS-19303 for additional context. 
   */
  if (cachedIndex == null) {
    indexPath = PyPiPathUtils.indexPath(packageName);
    cachedIndex = findAsset(tx, bucket, indexPath);
  }
  
  if (cachedIndex != null) {
    tx.deleteAsset(cachedIndex);
  }
}
 
Example 5
Source File: HelmHostedFacetImpl.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalDeleteBlob
public boolean delete(final String path) {
  checkNotNull(path);

  StorageTx tx = UnitOfWork.currentTx();
  Optional<Asset> asset = helmFacet.findAsset(tx, path);
  if (!asset.isPresent()) {
    return false;
  }
  else {
    tx.deleteAsset(asset.get());
    return true;
  }
}
 
Example 6
Source File: AptFacetImpl.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalDeleteBlob
public boolean delete(String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAssetWithProperty(P_NAME, path, bucket);
  if (asset == null) {
    return false;
  }

  tx.deleteAsset(asset);
  return true;
}
 
Example 7
Source File: AptHostedFacet.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalStoreBlob
public Asset ingestAsset(ControlFile control, TempBlob body, long size, String contentType) throws IOException, PGPException {
  AptFacet aptFacet = getRepository().facet(AptFacet.class);
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  String name = control.getField("Package").map(f -> f.value).get();
  String version = control.getField("Version").map(f -> f.value).get();
  String architecture = control.getField("Architecture").map(f -> f.value).get();

  String assetPath = FacetHelper.buildAssetPath(name, version, architecture);

  Content content = aptFacet.put(assetPath, new StreamPayload(() -> body.get(), size, contentType));
  Asset asset = Content.findAsset(tx, bucket, content);
  String indexSection = buildIndexSection(control, asset.size(), asset.getChecksums(FacetHelper.hashAlgorithms), assetPath);
  asset.formatAttributes().set(P_ARCHITECTURE, architecture);
  asset.formatAttributes().set(P_PACKAGE_NAME, name);
  asset.formatAttributes().set(P_PACKAGE_VERSION, version);
  asset.formatAttributes().set(P_INDEX_SECTION, indexSection);
  asset.formatAttributes().set(P_ASSET_KIND, "DEB");
  tx.saveAsset(asset);

  List<AssetChange> changes = new ArrayList<>();
  changes.add(new AssetChange(AssetAction.ADDED, asset));

  for (Asset removed : selectOldPackagesToRemove(name, architecture)) {
    tx.deleteAsset(removed);
    changes.add(new AssetChange(AssetAction.REMOVED, removed));
  }

  rebuildIndexesInTransaction(tx, changes.stream().toArray(AssetChange[]::new));
  return asset;
}
 
Example 8
Source File: OrientNpmGroupFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional
protected void cleanupPackageRootAssetOnlyFromCache(final Asset packageRootAsset) {
  checkNotNull(packageRootAsset);

  StorageTx tx = UnitOfWork.currentTx();

  // Don't delete the blob because we already know it is missing
  tx.deleteAsset(packageRootAsset, false);
}
 
Example 9
Source File: NpmSearchIndexFacetCaching.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalDeleteBlob
protected void deleteAsset() throws IOException {
  log.debug("Invalidating cached npm index of {}", getRepository().getName());
  StorageTx tx = UnitOfWork.currentTx();
  Asset asset = NpmFacetUtils.findRepositoryRootAsset(tx, tx.findBucket(getRepository()));
  if (asset == null) {
    return;
  }
  tx.deleteAsset(asset);
  eventManager.post(new NpmSearchIndexInvalidatedEvent(getRepository()));
}
 
Example 10
Source File: OrientPyPiRepairIndexComponent.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void updateAsset(final Repository repository, final StorageTx tx, final Asset asset) {
  AssetKind assetKind = AssetKind.valueOf(asset.formatAttributes().get(P_ASSET_KIND, String.class));
  if (ROOT_INDEX.equals(assetKind) || INDEX.equals(assetKind)) {
    tx.deleteAsset(asset);
  }
}
 
Example 11
Source File: OrientPyPiIndexFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalDeleteBlob
public void deleteRootIndex() {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset rootIndex = findAsset(tx, bucket, INDEX_PATH_PREFIX);
  if (rootIndex != null) {
    tx.deleteAsset(rootIndex);
  }
}
 
Example 12
Source File: MavenFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private boolean deleteArtifact(final MavenPath path, final StorageTx tx) {
  final Component component = findComponent(tx, getRepository(), path);
  if (component == null) {
    return false;
  }
  final Asset asset = findAsset(tx, tx.findBucket(getRepository()), path);
  if (asset == null) {
    return false;
  }
  tx.deleteAsset(asset);
  if (!tx.browseAssets(component).iterator().hasNext()) {
    tx.deleteComponent(component);
  }
  return true;
}
 
Example 13
Source File: MavenFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private boolean deleteFile(final MavenPath path, final StorageTx tx) {
  final Asset asset = findAsset(tx, tx.findBucket(getRepository()), path);
  if (asset == null) {
    return false;
  }
  tx.deleteAsset(asset);
  return true;
}
 
Example 14
Source File: AptFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@TransactionalDeleteBlob
public boolean delete(final String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAssetWithProperty(P_NAME, path, bucket);
  if (asset == null) {
    return false;
  }

  tx.deleteAsset(asset);
  return true;
}
 
Example 15
Source File: BaseRestoreBlobStrategy.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@TransactionalDeleteBlob
protected void deleteAsset(final Repository repository, final String assetName) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Asset asset = findAsset(repository, assetName);
  if (asset != null) {
    tx.deleteAsset(asset, false);
  }
}
 
Example 16
Source File: PurgeUnusedFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Delete all unused assets.
 */
@TransactionalDeleteBlob
protected void deleteUnusedAssets(final Date olderThan) {
  StorageTx tx = UnitOfWork.currentTx();

  for (Asset asset : findUnusedAssets(tx, olderThan)) {
    checkCancellation();
    log.debug("Deleting unused asset {}", asset);
    tx.deleteAsset(asset); // TODO: commit in batches
  }
}