Examples of RepositoryItemUidLock


Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

  }

  public boolean deleteAttributes(final RepositoryItemUid uid)
      throws IOException
  {
    final RepositoryItemUidLock uidLock = uid.getLock();

    uidLock.lock(Action.delete);

    try {
      if (log.isDebugEnabled()) {
        log.debug("Deleting attributes on UID=" + uid.toString());
      }

      try {
        final Repository repository = uid.getRepository();

        final ResourceStoreRequest request =
            new ResourceStoreRequest(getAttributePath(repository, uid.getPath()));

        repository.getLocalStorage().deleteItem(repository, request);

        return true;
      }
      catch (ItemNotFoundException e) {
        // ignore it
      }
      catch (UnsupportedStorageOperationException e) {
        // ignore it
      }

      return false;
    }
    finally {
      uidLock.unlock();
    }
  }
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

  }

  public Attributes getAttributes(final RepositoryItemUid uid)
      throws IOException
  {
    final RepositoryItemUidLock uidLock = uid.getLock();

    uidLock.lock(Action.read);

    try {
      if (log.isDebugEnabled()) {
        log.debug("Loading attributes on UID=" + uid.toString());
      }

      return doGetAttributes(uid);
    }
    finally {
      uidLock.unlock();
    }
  }
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

  }

  public void putAttributes(final RepositoryItemUid uid, Attributes attributes)
      throws IOException
  {
    final RepositoryItemUidLock uidLock = uid.getLock();

    uidLock.lock(Action.create);

    try {
      if (log.isDebugEnabled()) {
        log.debug("Storing attributes on UID=" + uid.toString());
      }

      try {
        Attributes onDisk = doGetAttributes(uid);

        if (onDisk != null && (onDisk.getGeneration() > attributes.getGeneration())) {
          // change detected, overlay the to be saved onto the newer one and swap
          onDisk.overlayAttributes(attributes);

          // and overlay other things too
          onDisk.setRepositoryId(uid.getRepository().getId());
          onDisk.setPath(uid.getPath());
          onDisk.setReadable(attributes.isReadable());
          onDisk.setWritable(attributes.isWritable());

          attributes = onDisk;
        }

        attributes.incrementGeneration();

        final ByteArrayOutputStream bos = new ByteArrayOutputStream();

        marshaller.marshal(attributes, bos);

        final Repository repository = uid.getRepository();

        final DefaultStorageFileItem attributeItem =
            new DefaultStorageFileItem(repository, new ResourceStoreRequest(getAttributePath(repository,
                uid.getPath())), true, true, new ByteArrayContentLocator(bos.toByteArray(), "text/xml"));

        repository.getLocalStorage().storeItem(repository, attributeItem);
      }
      catch (UnsupportedStorageOperationException ex) {
        // TODO: what here? Is local storage unsuitable for storing attributes?
        log.error("Got UnsupportedStorageOperationException during store of UID=" + uid.toString(), ex);
      }
    }
    finally {
      uidLock.unlock();
    }
  }
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

      // In case of error cleaning up both files
      // Locking is needed, AbstractRepository got shared lock only for destination

      // NEXUS-4550: FSPeer is the one that handles the rename in case of FS LS,
      // so we need here to claim exclusive lock on actual UID to perform the rename
      final RepositoryItemUidLock uidLock = item.getRepositoryItemUid().getLock();
      uidLock.lock(Action.create);

      try {
        handleRenameOperation(hiddenTarget, target);
        target.setLastModified(item.getModified());
      }
      catch (IOException e) {
        // if we ARE NOT handling attributes, do proper cleanup in case of IOEx
        // if we ARE handling attributes, leave backups in case of IOEx
        final boolean isCleanupNeeded =
            !item.getRepositoryItemUid().getBooleanAttributeValue(IsItemAttributeMetacontentAttribute.class);

        if (target != null && (isCleanupNeeded ||
            // NEXUS-4871 prevent zero length/corrupt files
            target.length() == 0)) {
          try {
            Files.delete(target.toPath());
          }
          catch (IOException e1) {
            log.warn("Could not delete file: " + target.getAbsolutePath(), e);
          }
        }

        if (hiddenTarget != null && (isCleanupNeeded ||
            // NEXUS-4871 prevent zero length/corrupt files
            hiddenTarget.length() == 0)) {
          try {
            Files.delete(hiddenTarget.toPath());
          }
          catch (IOException e1) {
            log.warn("Could not delete file: " + target.getAbsolutePath(), e);
          }
        }

        if (!isCleanupNeeded) {
          log.warn(
              "No cleanup done for error that happened while trying to save attibutes of item {}, the backup is left as {}!",
              item.getRepositoryItemUid().toString(), hiddenTarget.getAbsolutePath());
        }

        throw new LocalStorageException(String.format(
            "Got exception during storing on path \"%s\" (while moving to final destination)",
            item.getRepositoryItemUid().toString()), e);
      }
      finally {
        uidLock.unlock();
      }
    }
    else {
      // we have no content, we talk about directory
      try {
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

        // neglect completely out of service members
        if (member.getLocalStatus().shouldServiceRequest()) {
          final FilePrefixSource memberEntrySource =
              getPrefixSourceFor(member.adaptToFacet(MavenRepository.class));
          // lock to prevent file being deleted between exists check and reading it up
          final RepositoryItemUidLock lock = memberEntrySource.getRepositoryItemUid().getLock();
          lock.lock(Action.read);
          try {
            if (!memberEntrySource.supported()) {
              allMembersHavePublished = false;
              break;
            }
            entries.addAll(memberEntrySource.readEntries());
          }
          finally {
            lock.unlock();
          }
        }
      }
    }
    if (allMembersHavePublished) {
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

      // and it will be overwritten when initial autorouting configuration completes
      // although not 100% bulletproof, this logic reduces the risk of this happening
      return false;
    }
    final FilePrefixSource prefixSource = getPrefixSourceFor(mavenHostedRepository);
    final RepositoryItemUidLock lock = prefixSource.getRepositoryItemUid().getLock();
    lock.lock(Action.read);
    try {
      if (!prefixSource.supported()) {
        return false;
      }
      final String entry;
      if (item.getPathDepth() == 0) {
        entry = item.getPath();
      } else {
        entry = item.getParentPath();
      }
      final WritablePrefixSourceModifier wesm =
          new WritablePrefixSourceModifier(prefixSource, config.getLocalScrapeDepth());
      wesm.offerEntry(entry);
      if (wesm.hasChanges()) {
        boolean changed = false;
        lock.lock(Action.update);
        try {
          wesm.reset();
          wesm.offerEntry(entry);
          changed = wesm.apply();
          if (changed) {
            publish(mavenHostedRepository, prefixSource);
          }
        }
        finally {
          lock.unlock();
        }
        return changed;
      }
    }
    finally {
      lock.unlock();
    }
    return false;
  }
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

      // and it will be overwritten when initial autorouting configuration completes
      // although not 100% bulletproof, this logic reduces the risk of this happening
      return false;
    }
    final FilePrefixSource prefixSource = getPrefixSourceFor(mavenHostedRepository);
    final RepositoryItemUidLock lock = prefixSource.getRepositoryItemUid().getLock();
    lock.lock(Action.read);
    try {
      if (!prefixSource.supported()) {
        return false;
      }
      final WritablePrefixSourceModifier wesm =
          new WritablePrefixSourceModifier(prefixSource, config.getLocalScrapeDepth());
      wesm.revokeEntry(item.getPath());
      if (wesm.hasChanges()) {
        boolean changed = false;
        lock.lock(Action.update);
        try {
          wesm.reset();
          wesm.revokeEntry(item.getPath());
          changed = wesm.apply();
          if (changed) {
            publish(mavenHostedRepository, prefixSource);
          }
        }
        finally {
          lock.unlock();
        }
        return changed;
      }
    }
    finally {
      lock.unlock();
    }
    return false;
  }
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

    maintainNotFoundCache(request);

    final RepositoryItemUid uid = createUid(request.getRequestPath());

    final RepositoryItemUidLock uidLock = uid.getLock();

    uidLock.lock(Action.read);

    try {
      StorageItem item = doRetrieveItem(request);

      // file with generated content?
      if (item instanceof StorageFileItem && ((StorageFileItem) item).isContentGenerated()) {
        StorageFileItem file = (StorageFileItem) item;

        String key = file.getContentGeneratorId();

        if (getContentGenerators().containsKey(key)) {
          ContentGenerator generator = getContentGenerators().get(key);

          try {
            file.setContentLocator(generator.generateContent(this, uid.getPath(), file));
          }
          catch (Exception e) {
            throw new LocalStorageException("Could not generate content:", e);
          }
        }
        else {
          log.info(
              String.format(
                  "The file in repository %s on path=\"%s\" should be generated by ContentGeneratorId=%s, but component does not exists!",
                  RepositoryStringUtils.getHumanizedNameString(this), uid.getPath(), key));

          throw new ItemNotFoundException(reasonFor(request, this,
              "The generator for generated path %s with key %s not found in %s", request.getRequestPath(),
              key, this));
        }
      }

      eventBus().post(new RepositoryItemEventRetrieve(this, item));

      if (log.isDebugEnabled()) {
        log.debug(getId() + " retrieveItem() :: FOUND " + uid.toString());
      }

      return item;
    }
    catch (ItemNotFoundException ex) {
      if (log.isDebugEnabled()) {
        log.debug(getId() + " retrieveItem() :: NOT FOUND " + uid.toString());
      }

      if (shouldAddToNotFoundCache(request)) {
        addToNotFoundCache(request);
      }

      throw ex;
    }
    finally {
      uidLock.unlock();
    }
  }
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

    final RepositoryItemUid fromUid = createUid(from.getRequestPath());

    final RepositoryItemUid toUid = createUid(to.getRequestPath());

    final RepositoryItemUidLock fromUidLock = fromUid.getLock();

    final RepositoryItemUidLock toUidLock = toUid.getLock();

    fromUidLock.lock(Action.read);
    toUidLock.lock(Action.create);

    try {
      StorageItem item = retrieveItem(fromTask, from);

      if (StorageFileItem.class.isAssignableFrom(item.getClass())) {
        try {
          DefaultStorageFileItem target =
              new DefaultStorageFileItem(this, to, true, true, ((StorageFileItem) item).getContentLocator());

          storeItem(fromTask, target);

          // remove the "to" item from n-cache if there
          removeFromNotFoundCache(to);
        }
        catch (IOException e) {
          throw new LocalStorageException("Could not get the content of source file (is it file?)!", e);
        }
      }
    }
    finally {
      toUidLock.unlock();

      fromUidLock.unlock();
    }
  }
View Full Code Here

Examples of org.sonatype.nexus.proxy.item.RepositoryItemUidLock

    maintainNotFoundCache(request);

    final RepositoryItemUid uid = createUid(request.getRequestPath());

    final RepositoryItemUidLock uidLock = uid.getLock();

    uidLock.lock(Action.delete);

    try {
      StorageItem item = null;
      try {
        // determine is the thing to be deleted a collection or not
        item = getLocalStorage().retrieveItem(this, request);
      }
      catch (ItemNotFoundException ex) {
        if (shouldNeglectItemNotFoundExOnDelete(request, ex)) {
          item = null;
        }
        else {
          throw ex;
        }
      }

      if (item != null) {
        // fire the event for file being deleted
        eventBus().post(new RepositoryItemEventDeleteRoot(this, item));

        // if we are deleting a collection, perform recursive notification about this too
        if (item instanceof StorageCollectionItem) {
          log.debug("deleting a collection '{}'", item.getPath());

          // NEXUS-7628: If collection is being deleted, purge all of it's children from NFC
          if (isNotFoundCacheActive()) {
            getNotFoundCache().removeWithChildren(request.getRequestPath());
          }

          // it is collection, walk it and below and fire events for all files
          DeletionNotifierWalker dnw = new DeletionNotifierWalker(eventBus(), request);

          DefaultWalkerContext ctx = new DefaultWalkerContext(this, request);

          ctx.getProcessors().add(dnw);

          try {
            getWalker().walk(ctx);
          }
          catch (WalkerException e) {
            if (!(e.getWalkerContext().getStopCause() instanceof ItemNotFoundException)) {
              // everything that is not ItemNotFound should be reported,
              // otherwise just neglect it
              throw e;
            }
          }
        }

        doDeleteItem(request);
      }
    }
    finally {
      uidLock.unlock();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.